You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2022/06/06 11:03:09 UTC

[incubator-kvrocks] branch unstable updated: Fix don't swallow the error when creating column families failed (#620)

This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 537ad45  Fix don't swallow the error when creating column families failed (#620)
537ad45 is described below

commit 537ad451d70fc78d041a3659c37b969644229e88
Author: hulk <hu...@gmail.com>
AuthorDate: Mon Jun 6 19:03:04 2022 +0800

    Fix don't swallow the error when creating column families failed (#620)
    
    We expected to ignore the column families not opened error
    opened error, but we ignored all errors without checking the
    error type and message. This may cause other errors being ignored
    as well.
---
 src/storage.cc | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/storage.cc b/src/storage.cc
index bac1c81..4e474e7 100644
--- a/src/storage.cc
+++ b/src/storage.cc
@@ -209,8 +209,19 @@ Status Storage::CreateColumnFamilies(const rocksdb::Options &options) {
     tmp_db->Close();
     delete tmp_db;
   }
-  // Open db would be failed if the column families have already exists,
-  // so we return ok here.
+
+  if (!s.ok()) {
+    // We try to create families by opening the db without column families.
+    // If it's ok means we didn't create column families(cannot open without column families if created).
+    // When goes wrong, we need to check whether it's caused by column families NOT being opened or not.
+    // If the status message contains `Column families not opened` means that we have created the column
+    // families, let's ignore the error.
+    std::string notOpenedPrefix = "Column families not opened";
+    if (s.IsInvalidArgument() && s.ToString().find(notOpenedPrefix) != std::string::npos) {
+      return Status::OK();
+    }
+    return Status(Status::NotOK, s.ToString());
+  }
   return Status::OK();
 }