Skip to content

Commit aee4914

Browse files
tensorflower-gardenerJonathan Hseu
authored andcommitted
Retrying FileExists errors in case of errors to overcome intermittent GCS errors.
Change: 149038920
1 parent d4fd3b1 commit aee4914

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

tensorflow/core/platform/cloud/retrying_file_system.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ Status RetryingFileSystem::NewReadOnlyMemoryRegionFromFile(
131131
}
132132

133133
Status RetryingFileSystem::FileExists(const string& fname) {
134-
// No status -- no retries.
135-
return base_file_system_->FileExists(fname);
134+
return RetryingUtils::CallWithRetries(
135+
std::bind(&FileSystem::FileExists, base_file_system_.get(), fname),
136+
initial_delay_microseconds_);
137+
;
136138
}
137139

138140
Status RetryingFileSystem::Stat(const string& fname, FileStatistics* stat) {

tensorflow/core/platform/cloud/retrying_file_system_test.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ class MockFileSystem : public FileSystem {
109109
return calls_.ConsumeNextCall("NewReadOnlyMemoryRegionFromFile");
110110
}
111111

112-
Status FileExists(const string& fname) override { return Status::OK(); }
112+
Status FileExists(const string& fname) override {
113+
return calls_.ConsumeNextCall("FileExists");
114+
}
113115

114116
Status GetChildren(const string& dir, std::vector<string>* result) override {
115117
return calls_.ConsumeNextCall("GetChildren");
@@ -619,6 +621,26 @@ TEST(RetryingFileSystemTest, FileExists_SuccessWith2ndTry) {
619621
TF_EXPECT_OK(fs.FileExists("gs://path/dir"));
620622
}
621623

624+
TEST(RetryingFileSystemTest, FileExists_AllRetriesFailed) {
625+
ExpectedCalls expected_fs_calls = CreateRetriableErrors("FileExists", 6);
626+
std::unique_ptr<MockFileSystem> base_fs(
627+
new MockFileSystem(expected_fs_calls));
628+
RetryingFileSystem fs(std::move(base_fs), 0);
629+
630+
EXPECT_EQ("Retriable error #5", fs.FileExists("file_name").error_message());
631+
}
632+
633+
TEST(RetryingFileSystemTest, FileExists_SuccessWith2ndTry) {
634+
ExpectedCalls expected_fs_calls(
635+
{std::make_tuple("FileExists", errors::Unavailable("Something is wrong")),
636+
std::make_tuple("FileExists", Status::OK())});
637+
std::unique_ptr<MockFileSystem> base_fs(
638+
new MockFileSystem(expected_fs_calls));
639+
RetryingFileSystem fs(std::move(base_fs), 0);
640+
641+
TF_EXPECT_OK(fs.FileExists("gs://path/dir"));
642+
}
643+
622644
TEST(RetryingFileSystemTest, IsDirectory_SuccessWith2ndTry) {
623645
ExpectedCalls expected_fs_calls(
624646
{std::make_tuple("IsDirectory",

0 commit comments

Comments
 (0)