View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.backup;
19  
20  import java.io.FileNotFoundException;
21  import java.io.IOException;
22  import java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.Collection;
25  import java.util.Collections;
26  import java.util.List;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.apache.hadoop.conf.Configuration;
31  import org.apache.hadoop.fs.FileStatus;
32  import org.apache.hadoop.fs.FileSystem;
33  import org.apache.hadoop.fs.Path;
34  import org.apache.hadoop.fs.PathFilter;
35  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
36  import org.apache.hadoop.hbase.HRegionInfo;
37  import org.apache.hadoop.hbase.classification.InterfaceAudience;
38  import org.apache.hadoop.hbase.regionserver.HRegion;
39  import org.apache.hadoop.hbase.regionserver.StoreFile;
40  import org.apache.hadoop.hbase.util.Bytes;
41  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
42  import org.apache.hadoop.hbase.util.FSUtils;
43  import org.apache.hadoop.hbase.util.HFileArchiveUtil;
44  import org.apache.hadoop.io.MultipleIOException;
45  
46  import com.google.common.base.Function;
47  import com.google.common.base.Preconditions;
48  import com.google.common.collect.Collections2;
49  import com.google.common.collect.Lists;
50  
51  /**
52   * Utility class to handle the removal of HFiles (or the respective {@link StoreFile StoreFiles})
53   * for a HRegion from the {@link FileSystem}. The hfiles will be archived or deleted, depending on
54   * the state of the system. 
55   */
56  @InterfaceAudience.Private
57  public class HFileArchiver {
58    private static final Log LOG = LogFactory.getLog(HFileArchiver.class);
59    private static final String SEPARATOR = ".";
60  
61    /** Number of retries in case of fs operation failure */
62    private static final int DEFAULT_RETRIES_NUMBER = 3;
63  
64    private static final Function<File, Path> FUNC_FILE_TO_PATH =
65        new Function<File, Path>() {
66          @Override
67          public Path apply(File file) {
68            return file == null ? null : file.getPath();
69          }
70        };
71  
72    private HFileArchiver() {
73      // hidden ctor since this is just a util
74    }
75  
76    /**
77     * Cleans up all the files for a HRegion by archiving the HFiles to the
78     * archive directory
79     * @param conf the configuration to use
80     * @param fs the file system object
81     * @param info HRegionInfo for region to be deleted
82     * @throws IOException
83     */
84    public static void archiveRegion(Configuration conf, FileSystem fs, HRegionInfo info)
85        throws IOException {
86      Path rootDir = FSUtils.getRootDir(conf);
87      archiveRegion(fs, rootDir, FSUtils.getTableDir(rootDir, info.getTable()),
88        HRegion.getRegionDir(rootDir, info));
89    }
90  
91    /**
92     * Remove an entire region from the table directory via archiving the region's hfiles.
93     * @param fs {@link FileSystem} from which to remove the region
94     * @param rootdir {@link Path} to the root directory where hbase files are stored (for building
95     *          the archive path)
96     * @param tableDir {@link Path} to where the table is being stored (for building the archive path)
97     * @param regionDir {@link Path} to where a region is being stored (for building the archive path)
98     * @return <tt>true</tt> if the region was sucessfully deleted. <tt>false</tt> if the filesystem
99     *         operations could not complete.
100    * @throws IOException if the request cannot be completed
101    */
102   public static boolean archiveRegion(FileSystem fs, Path rootdir, Path tableDir, Path regionDir)
103       throws IOException {
104     if (LOG.isDebugEnabled()) {
105       LOG.debug("ARCHIVING " + regionDir.toString());
106     }
107 
108     // otherwise, we archive the files
109     // make sure we can archive
110     if (tableDir == null || regionDir == null) {
111       LOG.error("No archive directory could be found because tabledir (" + tableDir
112           + ") or regiondir (" + regionDir + "was null. Deleting files instead.");
113       deleteRegionWithoutArchiving(fs, regionDir);
114       // we should have archived, but failed to. Doesn't matter if we deleted
115       // the archived files correctly or not.
116       return false;
117     }
118 
119     // make sure the regiondir lives under the tabledir
120     Preconditions.checkArgument(regionDir.toString().startsWith(tableDir.toString()));
121     Path regionArchiveDir = HFileArchiveUtil.getRegionArchiveDir(rootdir,
122         FSUtils.getTableName(tableDir),
123         regionDir.getName());
124 
125     FileStatusConverter getAsFile = new FileStatusConverter(fs);
126     // otherwise, we attempt to archive the store files
127 
128     // build collection of just the store directories to archive
129     Collection<File> toArchive = new ArrayList<File>();
130     final PathFilter dirFilter = new FSUtils.DirFilter(fs);
131     PathFilter nonHidden = new PathFilter() {
132       @Override
133       public boolean accept(Path file) {
134         return dirFilter.accept(file) && !file.getName().toString().startsWith(".");
135       }
136     };
137     FileStatus[] storeDirs = FSUtils.listStatus(fs, regionDir, nonHidden);
138     // if there no files, we can just delete the directory and return;
139     if (storeDirs == null) {
140       LOG.debug("Region directory (" + regionDir + ") was empty, just deleting and returning!");
141       return deleteRegionWithoutArchiving(fs, regionDir);
142     }
143 
144     // convert the files in the region to a File
145     toArchive.addAll(Lists.transform(Arrays.asList(storeDirs), getAsFile));
146     LOG.debug("Archiving " + toArchive);
147     List<File> failedArchive = resolveAndArchive(fs, regionArchiveDir, toArchive,
148         EnvironmentEdgeManager.currentTime());
149     if (!failedArchive.isEmpty()) {
150       throw new FailedArchiveException("Failed to archive/delete all the files for region:"
151           + regionDir.getName() + " into " + regionArchiveDir
152           + ". Something is probably awry on the filesystem.",
153           Collections2.transform(failedArchive, FUNC_FILE_TO_PATH));
154     }
155     // if that was successful, then we delete the region
156     return deleteRegionWithoutArchiving(fs, regionDir);
157   }
158 
159   /**
160    * Remove from the specified region the store files of the specified column family,
161    * either by archiving them or outright deletion
162    * @param fs the filesystem where the store files live
163    * @param conf {@link Configuration} to examine to determine the archive directory
164    * @param parent Parent region hosting the store files
165    * @param tableDir {@link Path} to where the table is being stored (for building the archive path)
166    * @param family the family hosting the store files
167    * @throws IOException if the files could not be correctly disposed.
168    */
169   public static void archiveFamily(FileSystem fs, Configuration conf,
170       HRegionInfo parent, Path tableDir, byte[] family) throws IOException {
171     Path familyDir = new Path(tableDir, new Path(parent.getEncodedName(), Bytes.toString(family)));
172     FileStatus[] storeFiles = FSUtils.listStatus(fs, familyDir);
173     if (storeFiles == null) {
174       LOG.debug("No store files to dispose for region=" + parent.getRegionNameAsString() +
175           ", family=" + Bytes.toString(family));
176       return;
177     }
178 
179     FileStatusConverter getAsFile = new FileStatusConverter(fs);
180     Collection<File> toArchive = Lists.transform(Arrays.asList(storeFiles), getAsFile);
181     Path storeArchiveDir = HFileArchiveUtil.getStoreArchivePath(conf, parent, tableDir, family);
182 
183     // do the actual archive
184     List<File> failedArchive = resolveAndArchive(fs, storeArchiveDir, toArchive,
185         EnvironmentEdgeManager.currentTime());
186     if (!failedArchive.isEmpty()){
187       throw new FailedArchiveException("Failed to archive/delete all the files for region:"
188           + Bytes.toString(parent.getRegionName()) + ", family:" + Bytes.toString(family)
189           + " into " + storeArchiveDir + ". Something is probably awry on the filesystem.",
190           Collections2.transform(failedArchive, FUNC_FILE_TO_PATH));
191     }
192   }
193 
194   /**
195    * Remove the store files, either by archiving them or outright deletion
196    * @param conf {@link Configuration} to examine to determine the archive directory
197    * @param fs the filesystem where the store files live
198    * @param regionInfo {@link HRegionInfo} of the region hosting the store files
199    * @param family the family hosting the store files
200    * @param compactedFiles files to be disposed of. No further reading of these files should be
201    *          attempted; otherwise likely to cause an {@link IOException}
202    * @throws IOException if the files could not be correctly disposed.
203    */
204   public static void archiveStoreFiles(Configuration conf, FileSystem fs, HRegionInfo regionInfo,
205       Path tableDir, byte[] family, Collection<StoreFile> compactedFiles)
206       throws IOException, FailedArchiveException {
207 
208     // sometimes in testing, we don't have rss, so we need to check for that
209     if (fs == null) {
210       LOG.warn("Passed filesystem is null, so just deleting the files without archiving for region:"
211           + Bytes.toString(regionInfo.getRegionName()) + ", family:" + Bytes.toString(family));
212       deleteStoreFilesWithoutArchiving(compactedFiles);
213       return;
214     }
215 
216     // short circuit if we don't have any files to delete
217     if (compactedFiles.size() == 0) {
218       LOG.debug("No store files to dispose, done!");
219       return;
220     }
221 
222     // build the archive path
223     if (regionInfo == null || family == null) throw new IOException(
224         "Need to have a region and a family to archive from.");
225 
226     Path storeArchiveDir = HFileArchiveUtil.getStoreArchivePath(conf, regionInfo, tableDir, family);
227 
228     // make sure we don't archive if we can't and that the archive dir exists
229     if (!fs.mkdirs(storeArchiveDir)) {
230       throw new IOException("Could not make archive directory (" + storeArchiveDir + ") for store:"
231           + Bytes.toString(family) + ", deleting compacted files instead.");
232     }
233 
234     // otherwise we attempt to archive the store files
235     if (LOG.isDebugEnabled()) LOG.debug("Archiving compacted store files.");
236 
237     // Wrap the storefile into a File
238     StoreToFile getStorePath = new StoreToFile(fs);
239     Collection<File> storeFiles = Collections2.transform(compactedFiles, getStorePath);
240 
241     // do the actual archive
242     List<File> failedArchive = resolveAndArchive(fs, storeArchiveDir, storeFiles,
243         EnvironmentEdgeManager.currentTime());
244 
245     if (!failedArchive.isEmpty()){
246       throw new FailedArchiveException("Failed to archive/delete all the files for region:"
247           + Bytes.toString(regionInfo.getRegionName()) + ", family:" + Bytes.toString(family)
248           + " into " + storeArchiveDir + ". Something is probably awry on the filesystem.",
249           Collections2.transform(failedArchive, FUNC_FILE_TO_PATH));
250     }
251   }
252 
253   /**
254    * Archive the store file
255    * @param fs the filesystem where the store files live
256    * @param regionInfo region hosting the store files
257    * @param conf {@link Configuration} to examine to determine the archive directory
258    * @param tableDir {@link Path} to where the table is being stored (for building the archive path)
259    * @param family the family hosting the store files
260    * @param storeFile file to be archived
261    * @throws IOException if the files could not be correctly disposed.
262    */
263   public static void archiveStoreFile(Configuration conf, FileSystem fs, HRegionInfo regionInfo,
264       Path tableDir, byte[] family, Path storeFile) throws IOException {
265     Path storeArchiveDir = HFileArchiveUtil.getStoreArchivePath(conf, regionInfo, tableDir, family);
266     // make sure we don't archive if we can't and that the archive dir exists
267     if (!fs.mkdirs(storeArchiveDir)) {
268       throw new IOException("Could not make archive directory (" + storeArchiveDir + ") for store:"
269           + Bytes.toString(family) + ", deleting compacted files instead.");
270     }
271 
272     // do the actual archive
273     long start = EnvironmentEdgeManager.currentTime();
274     File file = new FileablePath(fs, storeFile);
275     if (!resolveAndArchiveFile(storeArchiveDir, file, Long.toString(start))) {
276       throw new IOException("Failed to archive/delete the file for region:"
277           + regionInfo.getRegionNameAsString() + ", family:" + Bytes.toString(family)
278           + " into " + storeArchiveDir + ". Something is probably awry on the filesystem.");
279     }
280   }
281 
282   /**
283    * Resolve any conflict with an existing archive file via timestamp-append
284    * renaming of the existing file and then archive the passed in files.
285    * @param fs {@link FileSystem} on which to archive the files
286    * @param baseArchiveDir base archive directory to store the files. If any of
287    *          the files to archive are directories, will append the name of the
288    *          directory to the base archive directory name, creating a parallel
289    *          structure.
290    * @param toArchive files/directories that need to be archvied
291    * @param start time the archiving started - used for resolving archive
292    *          conflicts.
293    * @return the list of failed to archive files.
294    * @throws IOException if an unexpected file operation exception occured
295    */
296   private static List<File> resolveAndArchive(FileSystem fs, Path baseArchiveDir,
297       Collection<File> toArchive, long start) throws IOException {
298     // short circuit if no files to move
299     if (toArchive.size() == 0) return Collections.emptyList();
300 
301     if (LOG.isTraceEnabled()) LOG.trace("moving files to the archive directory: " + baseArchiveDir);
302 
303     // make sure the archive directory exists
304     if (!fs.exists(baseArchiveDir)) {
305       if (!fs.mkdirs(baseArchiveDir)) {
306         throw new IOException("Failed to create the archive directory:" + baseArchiveDir
307             + ", quitting archive attempt.");
308       }
309       if (LOG.isTraceEnabled()) LOG.trace("Created archive directory:" + baseArchiveDir);
310     }
311 
312     List<File> failures = new ArrayList<File>();
313     String startTime = Long.toString(start);
314     for (File file : toArchive) {
315       // if its a file archive it
316       try {
317         if (LOG.isTraceEnabled()) LOG.trace("Archiving: " + file);
318         if (file.isFile()) {
319           // attempt to archive the file
320           if (!resolveAndArchiveFile(baseArchiveDir, file, startTime)) {
321             LOG.warn("Couldn't archive " + file + " into backup directory: " + baseArchiveDir);
322             failures.add(file);
323           }
324         } else {
325           // otherwise its a directory and we need to archive all files
326           if (LOG.isTraceEnabled()) LOG.trace(file + " is a directory, archiving children files");
327           // so we add the directory name to the one base archive
328           Path parentArchiveDir = new Path(baseArchiveDir, file.getName());
329           // and then get all the files from that directory and attempt to
330           // archive those too
331           Collection<File> children = file.getChildren();
332           failures.addAll(resolveAndArchive(fs, parentArchiveDir, children, start));
333         }
334       } catch (IOException e) {
335         LOG.warn("Failed to archive " + file, e);
336         failures.add(file);
337       }
338     }
339     return failures;
340   }
341 
342   /**
343    * Attempt to archive the passed in file to the archive directory.
344    * <p>
345    * If the same file already exists in the archive, it is moved to a timestamped directory under
346    * the archive directory and the new file is put in its place.
347    * @param archiveDir {@link Path} to the directory that stores the archives of the hfiles
348    * @param currentFile {@link Path} to the original HFile that will be archived
349    * @param archiveStartTime time the archiving started, to resolve naming conflicts
350    * @return <tt>true</tt> if the file is successfully archived. <tt>false</tt> if there was a
351    *         problem, but the operation still completed.
352    * @throws IOException on failure to complete {@link FileSystem} operations.
353    */
354   private static boolean resolveAndArchiveFile(Path archiveDir, File currentFile,
355       String archiveStartTime) throws IOException {
356     // build path as it should be in the archive
357     String filename = currentFile.getName();
358     Path archiveFile = new Path(archiveDir, filename);
359     FileSystem fs = currentFile.getFileSystem();
360 
361     // if the file already exists in the archive, move that one to a timestamped backup. This is a
362     // really, really unlikely situtation, where we get the same name for the existing file, but
363     // is included just for that 1 in trillion chance.
364     if (fs.exists(archiveFile)) {
365       if (LOG.isDebugEnabled()) {
366         LOG.debug("File:" + archiveFile + " already exists in archive, moving to "
367             + "timestamped backup and overwriting current.");
368       }
369 
370       // move the archive file to the stamped backup
371       Path backedupArchiveFile = new Path(archiveDir, filename + SEPARATOR + archiveStartTime);
372       if (!fs.rename(archiveFile, backedupArchiveFile)) {
373         LOG.error("Could not rename archive file to backup: " + backedupArchiveFile
374             + ", deleting existing file in favor of newer.");
375         // try to delete the exisiting file, if we can't rename it
376         if (!fs.delete(archiveFile, false)) {
377           throw new IOException("Couldn't delete existing archive file (" + archiveFile
378               + ") or rename it to the backup file (" + backedupArchiveFile
379               + ") to make room for similarly named file.");
380         }
381       }
382       LOG.debug("Backed up archive file from " + archiveFile);
383     }
384 
385     if (LOG.isTraceEnabled()) {
386       LOG.trace("No existing file in archive for: " + archiveFile +
387         ", free to archive original file.");
388     }
389 
390     // at this point, we should have a free spot for the archive file
391     boolean success = false;
392     for (int i = 0; !success && i < DEFAULT_RETRIES_NUMBER; ++i) {
393       if (i > 0) {
394         // Ensure that the archive directory exists.
395         // The previous "move to archive" operation has failed probably because
396         // the cleaner has removed our archive directory (HBASE-7643).
397         // (we're in a retry loop, so don't worry too much about the exception)
398         try {
399           if (!fs.exists(archiveDir)) {
400             if (fs.mkdirs(archiveDir)) {
401               LOG.debug("Created archive directory:" + archiveDir);
402             }
403           }
404         } catch (IOException e) {
405           LOG.warn("Failed to create directory: " + archiveDir, e);
406         }
407       }
408 
409       try {
410         success = currentFile.moveAndClose(archiveFile);
411       } catch (FileNotFoundException fnfe) {
412         LOG.warn("Failed to archive " + currentFile +
413             " because it does not exist! Skipping and continuing on.", fnfe);
414         success = true;
415       } catch (IOException e) {
416         LOG.warn("Failed to archive " + currentFile + " on try #" + i, e);
417         success = false;
418       }
419     }
420 
421     if (!success) {
422       LOG.error("Failed to archive " + currentFile);
423       return false;
424     }
425 
426     if (LOG.isDebugEnabled()) {
427       LOG.debug("Finished archiving from " + currentFile + ", to " + archiveFile);
428     }
429     return true;
430   }
431 
432   /**
433    * Without regard for backup, delete a region. Should be used with caution.
434    * @param regionDir {@link Path} to the region to be deleted.
435    * @param fs FileSystem from which to delete the region
436    * @return <tt>true</tt> on successful deletion, <tt>false</tt> otherwise
437    * @throws IOException on filesystem operation failure
438    */
439   private static boolean deleteRegionWithoutArchiving(FileSystem fs, Path regionDir)
440       throws IOException {
441     if (fs.delete(regionDir, true)) {
442       LOG.debug("Deleted all region files in: " + regionDir);
443       return true;
444     }
445     LOG.debug("Failed to delete region directory:" + regionDir);
446     return false;
447   }
448 
449   /**
450    * Just do a simple delete of the given store files
451    * <p>
452    * A best effort is made to delete each of the files, rather than bailing on the first failure.
453    * <p>
454    * This method is preferable to {@link #deleteFilesWithoutArchiving(Collection)} since it consumes
455    * less resources, but is limited in terms of usefulness
456    * @param compactedFiles store files to delete from the file system.
457    * @throws IOException if a file cannot be deleted. All files will be attempted to deleted before
458    *           throwing the exception, rather than failing at the first file.
459    */
460   private static void deleteStoreFilesWithoutArchiving(Collection<StoreFile> compactedFiles)
461       throws IOException {
462     LOG.debug("Deleting store files without archiving.");
463     List<IOException> errors = new ArrayList<IOException>(0);
464     for (StoreFile hsf : compactedFiles) {
465       try {
466         hsf.deleteReader();
467       } catch (IOException e) {
468         LOG.error("Failed to delete store file:" + hsf.getPath());
469         errors.add(e);
470       }
471     }
472     if (errors.size() > 0) {
473       throw MultipleIOException.createIOException(errors);
474     }
475   }
476 
477   /**
478    * Adapt a type to match the {@link File} interface, which is used internally for handling
479    * archival/removal of files
480    * @param <T> type to adapt to the {@link File} interface
481    */
482   private static abstract class FileConverter<T> implements Function<T, File> {
483     protected final FileSystem fs;
484 
485     public FileConverter(FileSystem fs) {
486       this.fs = fs;
487     }
488   }
489 
490   /**
491    * Convert a FileStatus to something we can manage in the archiving
492    */
493   private static class FileStatusConverter extends FileConverter<FileStatus> {
494     public FileStatusConverter(FileSystem fs) {
495       super(fs);
496     }
497 
498     @Override
499     public File apply(FileStatus input) {
500       return new FileablePath(fs, input.getPath());
501     }
502   }
503 
504   /**
505    * Convert the {@link StoreFile} into something we can manage in the archive
506    * methods
507    */
508   private static class StoreToFile extends FileConverter<StoreFile> {
509     public StoreToFile(FileSystem fs) {
510       super(fs);
511     }
512 
513     @Override
514     public File apply(StoreFile input) {
515       return new FileableStoreFile(fs, input);
516     }
517   }
518 
519   /**
520    * Wrapper to handle file operations uniformly
521    */
522   private static abstract class File {
523     protected final FileSystem fs;
524 
525     public File(FileSystem fs) {
526       this.fs = fs;
527     }
528 
529     /**
530      * Delete the file
531      * @throws IOException on failure
532      */
533     abstract void delete() throws IOException;
534 
535     /**
536      * Check to see if this is a file or a directory
537      * @return <tt>true</tt> if it is a file, <tt>false</tt> otherwise
538      * @throws IOException on {@link FileSystem} connection error
539      */
540     abstract boolean isFile() throws IOException;
541 
542     /**
543      * @return if this is a directory, returns all the children in the
544      *         directory, otherwise returns an empty list
545      * @throws IOException
546      */
547     abstract Collection<File> getChildren() throws IOException;
548 
549     /**
550      * close any outside readers of the file
551      * @throws IOException
552      */
553     abstract void close() throws IOException;
554 
555     /**
556      * @return the name of the file (not the full fs path, just the individual
557      *         file name)
558      */
559     abstract String getName();
560 
561     /**
562      * @return the path to this file
563      */
564     abstract Path getPath();
565 
566     /**
567      * Move the file to the given destination
568      * @param dest
569      * @return <tt>true</tt> on success
570      * @throws IOException
571      */
572     public boolean moveAndClose(Path dest) throws IOException {
573       this.close();
574       Path p = this.getPath();
575       return FSUtils.renameAndSetModifyTime(fs, p, dest);
576     }
577 
578     /**
579      * @return the {@link FileSystem} on which this file resides
580      */
581     public FileSystem getFileSystem() {
582       return this.fs;
583     }
584 
585     @Override
586     public String toString() {
587       return this.getClass() + ", file:" + getPath().toString();
588     }
589   }
590 
591   /**
592    * A {@link File} that wraps a simple {@link Path} on a {@link FileSystem}.
593    */
594   private static class FileablePath extends File {
595     private final Path file;
596     private final FileStatusConverter getAsFile;
597 
598     public FileablePath(FileSystem fs, Path file) {
599       super(fs);
600       this.file = file;
601       this.getAsFile = new FileStatusConverter(fs);
602     }
603 
604     @Override
605     public void delete() throws IOException {
606       if (!fs.delete(file, true)) throw new IOException("Failed to delete:" + this.file);
607     }
608 
609     @Override
610     public String getName() {
611       return file.getName();
612     }
613 
614     @Override
615     public Collection<File> getChildren() throws IOException {
616       if (fs.isFile(file)) return Collections.emptyList();
617       return Collections2.transform(Arrays.asList(fs.listStatus(file)), getAsFile);
618     }
619 
620     @Override
621     public boolean isFile() throws IOException {
622       return fs.isFile(file);
623     }
624 
625     @Override
626     public void close() throws IOException {
627       // NOOP - files are implicitly closed on removal
628     }
629 
630     @Override
631     Path getPath() {
632       return file;
633     }
634   }
635 
636   /**
637    * {@link File} adapter for a {@link StoreFile} living on a {@link FileSystem}
638    * .
639    */
640   private static class FileableStoreFile extends File {
641     StoreFile file;
642 
643     public FileableStoreFile(FileSystem fs, StoreFile store) {
644       super(fs);
645       this.file = store;
646     }
647 
648     @Override
649     public void delete() throws IOException {
650       file.deleteReader();
651     }
652 
653     @Override
654     public String getName() {
655       return file.getPath().getName();
656     }
657 
658     @Override
659     public boolean isFile() {
660       return true;
661     }
662 
663     @Override
664     public Collection<File> getChildren() throws IOException {
665       // storefiles don't have children
666       return Collections.emptyList();
667     }
668 
669     @Override
670     public void close() throws IOException {
671       file.closeReader(true);
672     }
673 
674     @Override
675     Path getPath() {
676       return file.getPath();
677     }
678   }
679 }