Home | History | Annotate | Download | only in cloud
      1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #ifndef TENSORFLOW_CORE_PLATFORM_RETRYING_FILE_SYSTEM_H_
     17 #define TENSORFLOW_CORE_PLATFORM_RETRYING_FILE_SYSTEM_H_
     18 
     19 #include <string>
     20 #include <vector>
     21 #include "tensorflow/core/lib/core/status.h"
     22 #include "tensorflow/core/platform/file_system.h"
     23 
     24 namespace tensorflow {
     25 
     26 /// A wrapper to add retry logic to another file system.
     27 class RetryingFileSystem : public FileSystem {
     28  public:
     29   RetryingFileSystem(std::unique_ptr<FileSystem> base_file_system,
     30                      int64 delay_microseconds = 1000000)
     31       : base_file_system_(std::move(base_file_system)),
     32         initial_delay_microseconds_(delay_microseconds) {}
     33 
     34   Status NewRandomAccessFile(
     35       const string& filename,
     36       std::unique_ptr<RandomAccessFile>* result) override;
     37 
     38   Status NewWritableFile(const string& fname,
     39                          std::unique_ptr<WritableFile>* result) override;
     40 
     41   Status NewAppendableFile(const string& fname,
     42                            std::unique_ptr<WritableFile>* result) override;
     43 
     44   Status NewReadOnlyMemoryRegionFromFile(
     45       const string& filename,
     46       std::unique_ptr<ReadOnlyMemoryRegion>* result) override;
     47 
     48   Status FileExists(const string& fname) override;
     49 
     50   Status GetChildren(const string& dir, std::vector<string>* result) override;
     51 
     52   Status GetMatchingPaths(const string& dir,
     53                           std::vector<string>* result) override;
     54 
     55   Status Stat(const string& fname, FileStatistics* stat) override;
     56 
     57   Status DeleteFile(const string& fname) override;
     58 
     59   Status CreateDir(const string& dirname) override;
     60 
     61   Status DeleteDir(const string& dirname) override;
     62 
     63   Status GetFileSize(const string& fname, uint64* file_size) override;
     64 
     65   Status RenameFile(const string& src, const string& target) override;
     66 
     67   Status IsDirectory(const string& dir) override;
     68 
     69   Status DeleteRecursively(const string& dirname, int64* undeleted_files,
     70                            int64* undeleted_dirs) override;
     71 
     72   void FlushCaches() override;
     73 
     74  private:
     75   std::unique_ptr<FileSystem> base_file_system_;
     76   const int64 initial_delay_microseconds_;
     77 
     78   TF_DISALLOW_COPY_AND_ASSIGN(RetryingFileSystem);
     79 };
     80 
     81 }  // namespace tensorflow
     82 
     83 #endif  // TENSORFLOW_CORE_PLATFORM_RETRYING_FILE_SYSTEM_H_
     84