]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Handle "NotSupported" status by default implementation of Close() in … (#10127)
authorzczhu <>
Tue, 7 Jun 2022 16:49:31 +0000 (09:49 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 7 Jun 2022 16:49:31 +0000 (09:49 -0700)
Summary:
The default implementation of Close() function in Directory/FSDirectory classes returns `NotSupported` status. However, we don't want operations that worked in older versions to begin failing after upgrading when run on FileSystems that have not implemented Directory::Close() yet. So we require the upper level that calls Close() function should properly handle "NotSupported" status instead of treating it as an error status.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10127

Reviewed By: ajkr

Differential Revision: D36971112

Pulled By: littlepig2013

fbshipit-source-id: 100f0e6ad1191e1acc1ba6458c566a11724cf466

db/column_family.cc
db/db_impl/db_impl.cc
db/db_impl/db_impl.h
file/filename.cc

index bac4c21a6652cfc382261b2d3ca3aeccd0ae5dc4..90c0f3e251d8c20273d81f12217c3d95ab00b1d0 100644 (file)
@@ -683,8 +683,6 @@ ColumnFamilyData::~ColumnFamilyData() {
         s = data_dir_ptr->Close(IOOptions(), nullptr);
         if (!s.ok()) {
           // TODO(zichen): add `Status Close()` and `CloseDirectories()
-          ROCKS_LOG_WARN(ioptions_.logger, "Ignoring error %s",
-                         s.ToString().c_str());
           s.PermitUncheckedError();
         }
       }
index 4dbf89a4344c3bc67a86b7b72140d85dc2bcacc5..872c6e7a199d460ee87b434d9967eef340c62d34 100644 (file)
@@ -4408,7 +4408,17 @@ Status DBImpl::RenameTempFileToOptionsFile(const std::string& file_name) {
                                        DirFsyncOptions(options_file_name));
     }
     if (s.ok()) {
-      s = dir_obj->Close(IOOptions(), nullptr);
+      Status temp_s = dir_obj->Close(IOOptions(), nullptr);
+      // The default Close() could return "NotSupproted" and we bypass it
+      // if it is not impelmented. Detailed explanations can be found in
+      // db/db_impl/db_impl.h
+      if (!temp_s.ok()) {
+        if (temp_s.IsNotSupported()) {
+          temp_s.PermitUncheckedError();
+        } else {
+          s = temp_s;
+        }
+      }
     }
   }
   if (s.ok()) {
index 4e192e8316449a1e30399b74758b1692c9bf8ae2..721c73c3787757cce05a36d8d334e060ae773675 100644 (file)
@@ -116,8 +116,23 @@ class Directories {
   IOStatus Close(const IOOptions& options, IODebugContext* dbg) {
     // close all directories for all database paths
     IOStatus s = IOStatus::OK();
+    IOStatus temp_s = IOStatus::OK();
+
+    // The default implementation for Close() in Directory/FSDirectory class
+    // "NotSupported" status, the upper level interface should be able to
+    // handle this error so that Close() does not fail after upgrading when
+    // run on FileSystems that have not implemented `Directory::Close()` or
+    // `FSDirectory::Close()` yet
+
     if (db_dir_) {
-      s = db_dir_->Close(options, dbg);
+      temp_s = db_dir_->Close(options, dbg);
+      if (!temp_s.ok()) {
+        if (temp_s.IsNotSupported()) {
+          temp_s.PermitUncheckedError();
+        } else {
+          s = temp_s;
+        }
+      }
     }
 
     if (!s.ok()) {
@@ -126,6 +141,13 @@ class Directories {
 
     if (wal_dir_) {
       s = wal_dir_->Close(options, dbg);
+      if (!temp_s.ok()) {
+        if (temp_s.IsNotSupported()) {
+          temp_s.PermitUncheckedError();
+        } else {
+          s = temp_s;
+        }
+      }
     }
 
     if (!s.ok()) {
@@ -135,14 +157,21 @@ class Directories {
     if (data_dirs_.size() > 0 && s.ok()) {
       for (auto& data_dir_ptr : data_dirs_) {
         if (data_dir_ptr) {
-          s = data_dir_ptr->Close(options, dbg);
-          if (!s.ok()) {
-            return s;
+          temp_s = data_dir_ptr->Close(options, dbg);
+          if (!temp_s.ok()) {
+            if (temp_s.IsNotSupported()) {
+              temp_s.PermitUncheckedError();
+            } else {
+              return temp_s;
+            }
           }
         }
       }
     }
 
+    // Mark temp_s as checked when temp_s is still the initial status
+    // (IOStatus::OK(), not checked yet)
+    temp_s.PermitUncheckedError();
     return s;
   }
 
index e31dbb6812d13b37c2a85581f0df55135df4c24b..703167c8825fef5799e2d6121142f0116ea254d1 100644 (file)
@@ -443,8 +443,19 @@ Status SetIdentityFile(Env* env, const std::string& dbname,
     s = dir_obj->FsyncWithDirOptions(IOOptions(), nullptr,
                                      DirFsyncOptions(identify_file_name));
   }
+
+  // The default Close() could return "NotSupported" and we bypass it
+  // if it is not impelmented. Detailed explanations can be found in
+  // db/db_impl/db_impl.h
   if (s.ok()) {
-    s = dir_obj->Close(IOOptions(), nullptr);
+    Status temp_s = dir_obj->Close(IOOptions(), nullptr);
+    if (!temp_s.ok()) {
+      if (temp_s.IsNotSupported()) {
+        temp_s.PermitUncheckedError();
+      } else {
+        s = temp_s;
+      }
+    }
   }
   if (!s.ok()) {
     env->DeleteFile(tmp).PermitUncheckedError();