1717 */
1818package org .apache .hadoop .hbase .io .hfile ;
1919
20- import java .io .File ;
21- import java .io .FileInputStream ;
22- import java .io .FileOutputStream ;
23- import java .io .IOException ;
24- import java .util .HashMap ;
2520import java .util .Map ;
2621import java .util .concurrent .ConcurrentSkipListMap ;
2722import java .util .concurrent .Future ;
4237import org .slf4j .Logger ;
4338import org .slf4j .LoggerFactory ;
4439
45- import org .apache .hadoop .hbase .shaded .protobuf .generated .PersistentPrefetchProtos ;
46-
4740@ InterfaceAudience .Private
4841public final class PrefetchExecutor {
4942
5043 private static final Logger LOG = LoggerFactory .getLogger (PrefetchExecutor .class );
5144
5245 /** Futures for tracking block prefetch activity */
5346 private static final Map <Path , Future <?>> prefetchFutures = new ConcurrentSkipListMap <>();
54- /** Set of files for which prefetch is completed */
55- @ edu .umd .cs .findbugs .annotations .SuppressWarnings (value = "MS_SHOULD_BE_FINAL" )
56- private static HashMap <String , Boolean > prefetchCompleted = new HashMap <>();
5747 /** Executor pool shared among all HFiles for block prefetch */
5848 private static final ScheduledExecutorService prefetchExecutorPool ;
5949 /** Delay before beginning prefetch */
6050 private static final int prefetchDelayMillis ;
6151 /** Variation in prefetch delay times, to mitigate stampedes */
6252 private static final float prefetchDelayVariation ;
63- static String prefetchedFileListPath ;
6453 static {
6554 // Consider doing this on demand with a configuration passed in rather
6655 // than in a static initializer.
@@ -90,13 +79,6 @@ public Thread newThread(Runnable r) {
9079 + HConstants .HREGION_COMPACTIONDIR_NAME .replace ("." , "\\ ." ) + Path .SEPARATOR_CHAR + ")" );
9180
9281 public static void request (Path path , Runnable runnable ) {
93- if (prefetchCompleted != null ) {
94- if (isFilePrefetched (path .getName ())) {
95- LOG .info (
96- "File has already been prefetched before the restart, so skipping prefetch : " + path );
97- return ;
98- }
99- }
10082 if (!prefetchPathExclude .matcher (path .toString ()).find ()) {
10183 long delay ;
10284 if (prefetchDelayMillis > 0 ) {
@@ -122,8 +104,9 @@ public static void request(Path path, Runnable runnable) {
122104
123105 public static void complete (Path path ) {
124106 prefetchFutures .remove (path );
125- prefetchCompleted .put (path .getName (), true );
126- LOG .debug ("Prefetch completed for {}" , path .getName ());
107+ if (LOG .isDebugEnabled ()) {
108+ LOG .debug ("Prefetch completed for {}" , path .getName ());
109+ }
127110 }
128111
129112 public static void cancel (Path path ) {
@@ -134,8 +117,6 @@ public static void cancel(Path path) {
134117 prefetchFutures .remove (path );
135118 LOG .debug ("Prefetch cancelled for {}" , path );
136119 }
137- LOG .debug ("Removing filename from the prefetched persistence list: {}" , path .getName ());
138- removePrefetchedFileWhileEvict (path .getName ());
139120 }
140121
141122 public static boolean isCompleted (Path path ) {
@@ -146,70 +127,6 @@ public static boolean isCompleted(Path path) {
146127 return true ;
147128 }
148129
149- @ edu .umd .cs .findbugs .annotations .SuppressWarnings (value = "OBL_UNSATISFIED_OBLIGATION" ,
150- justification = "false positive, try-with-resources ensures close is called." )
151- public static void persistToFile (String path ) throws IOException {
152- prefetchedFileListPath = path ;
153- if (prefetchedFileListPath == null ) {
154- LOG .info ("Exception while persisting prefetch!" );
155- throw new IOException ("Error persisting prefetched HFiles set!" );
156- }
157- if (!prefetchCompleted .isEmpty ()) {
158- try (FileOutputStream fos = new FileOutputStream (prefetchedFileListPath , false )) {
159- PrefetchProtoUtils .toPB (prefetchCompleted ).writeDelimitedTo (fos );
160- }
161- }
162- }
163-
164- public static void retrieveFromFile (String path ) throws IOException {
165- prefetchedFileListPath = path ;
166- File prefetchPersistenceFile = new File (prefetchedFileListPath );
167- if (!prefetchPersistenceFile .exists ()) {
168- LOG .warn ("Prefetch persistence file does not exist!" );
169- return ;
170- }
171- LOG .info ("Retrieving from prefetch persistence file " + path );
172- assert (prefetchedFileListPath != null );
173- try (FileInputStream fis = deleteFileOnClose (prefetchPersistenceFile )) {
174- PersistentPrefetchProtos .PrefetchedHfileName proto =
175- PersistentPrefetchProtos .PrefetchedHfileName .parseDelimitedFrom (fis );
176- Map <String , Boolean > protoPrefetchedFilesMap = proto .getPrefetchedFilesMap ();
177- prefetchCompleted .putAll (protoPrefetchedFilesMap );
178- }
179- }
180-
181- private static FileInputStream deleteFileOnClose (final File file ) throws IOException {
182- return new FileInputStream (file ) {
183- private File myFile ;
184-
185- private FileInputStream init (File file ) {
186- myFile = file ;
187- return this ;
188- }
189-
190- @ Override
191- public void close () throws IOException {
192- if (myFile == null ) {
193- return ;
194- }
195-
196- super .close ();
197- if (!myFile .delete ()) {
198- throw new IOException ("Failed deleting persistence file " + myFile .getAbsolutePath ());
199- }
200- myFile = null ;
201- }
202- }.init (file );
203- }
204-
205- public static void removePrefetchedFileWhileEvict (String hfileName ) {
206- prefetchCompleted .remove (hfileName );
207- }
208-
209- public static boolean isFilePrefetched (String hfileName ) {
210- return prefetchCompleted .containsKey (hfileName );
211- }
212-
213130 private PrefetchExecutor () {
214131 }
215132}
0 commit comments