]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools/ceph-kvstore-tool: open DB in read-only whenever sufficient
authorIgor Fedotov <igor.fedotov@croit.io>
Sat, 13 Jan 2024 15:37:14 +0000 (18:37 +0300)
committerIgor Fedotov <igor.fedotov@croit.io>
Wed, 5 Mar 2025 18:42:36 +0000 (21:42 +0300)
Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
(cherry picked from commit 410d4748f9de94261d421576ed5433d2d0b0d4b3)

src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/bluestore_tool.cc
src/tools/ceph_kvstore_tool.cc
src/tools/kvstore_tool.cc
src/tools/kvstore_tool.h

index 32cfa23d9756cc8a00ff5644d34a9f938d12c1ed..635ae13cf3b7e7544d93a029f1ed20875a3bd951 100644 (file)
@@ -7785,10 +7785,10 @@ void BlueStore::_close_around_db()
   _close_path();
 }
 
-int BlueStore::open_db_environment(KeyValueDB **pdb, bool to_repair)
+int BlueStore::open_db_environment(KeyValueDB **pdb, bool read_only, bool to_repair)
 {
   _kv_only = true;
-  int r = _open_db_and_around(false, to_repair);
+  int r = _open_db_and_around(read_only, to_repair);
   if (r == 0) {
     *pdb = db;
   } else {
index c085c8c3e60202d7aaca7dfdfe73376dfcfac76e..91653f30b19394a4a703e3655cc07d7085ac058e 100644 (file)
@@ -3014,7 +3014,7 @@ public:
   }
   int umount() override;
 
-  int open_db_environment(KeyValueDB **pdb, bool to_repair);
+  int open_db_environment(KeyValueDB **pdb, bool read_only, bool to_repair);
   int close_db_environment();
   BlueFS* get_bluefs();
 
index b3636b5b5c2731eb04a6306d5daa9703e3ec0a17..2126c436d17d08a5e0579bbb62cf817f8caefe12 100644 (file)
@@ -242,7 +242,7 @@ static void bluefs_import(
   }
   BlueStore bluestore(cct, path);
   KeyValueDB *db_ptr;
-  r = bluestore.open_db_environment(&db_ptr, false);
+  r = bluestore.open_db_environment(&db_ptr, false, false);
   if (r < 0) {
     cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
     exit(EXIT_FAILURE);
@@ -1173,7 +1173,7 @@ int main(int argc, char **argv)
        exit(EXIT_FAILURE);
       }
     }
-    int r = bluestore.open_db_environment(&db_ptr, true);
+    int r = bluestore.open_db_environment(&db_ptr, false, true);
     if (r < 0) {
       cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
       exit(EXIT_FAILURE);
@@ -1191,7 +1191,7 @@ int main(int argc, char **argv)
   } else if (action == "show-sharding") {
     BlueStore bluestore(cct.get(), path);
     KeyValueDB *db_ptr;
-    int r = bluestore.open_db_environment(&db_ptr, false);
+    int r = bluestore.open_db_environment(&db_ptr, false, false);
     if (r < 0) {
       cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
       exit(EXIT_FAILURE);
index d009069de714fe4a50e314442019f175e3ad30d3..bcb90c8fe4639d0e7eefffad3609cc3eb4fdf5e9 100644 (file)
@@ -98,9 +98,20 @@ int main(int argc, const char *argv[])
     return 1;
   }
 
+  bool read_only =
+    cmd == "list" ||
+    cmd == "list-crc" ||
+    cmd == "dump" ||
+    cmd == "exists" ||
+    cmd == "get" ||
+    cmd == "crc" ||
+    cmd == "get-size" ||
+    cmd == "store-crc" ||
+    cmd == "stats" ||
+    cmd == "histogram";
   bool to_repair = (cmd == "destructive-repair");
   bool need_stats = (cmd == "stats");
-  StoreTool st(type, path, to_repair, need_stats);
+  StoreTool st(type, path, read_only, to_repair, need_stats);
 
   if (cmd == "destructive-repair") {
     int ret = st.destructive_repair();
index b426d73f47f26f364ce09974772ca479897b5713..720d1150650e5987378fc0c348105fa3d9037a0f 100644 (file)
@@ -16,6 +16,7 @@ using namespace std;
 
 StoreTool::StoreTool(const string& type,
                     const string& path,
+                     bool read_only,
                     bool to_repair,
                     bool need_stats)
   : store_path(path)
@@ -28,7 +29,7 @@ StoreTool::StoreTool(const string& type,
 
   if (type == "bluestore-kv") {
 #ifdef WITH_BLUESTORE
-    if (load_bluestore(path, to_repair) != 0)
+    if (load_bluestore(path, read_only, to_repair) != 0)
       exit(1);
 #else
     cerr << "bluestore not compiled in" << std::endl;
@@ -37,7 +38,8 @@ StoreTool::StoreTool(const string& type,
   } else {
     auto db_ptr = KeyValueDB::create(g_ceph_context, type, path);
     if (!to_repair) {
-      if (int r = db_ptr->open(std::cerr); r < 0) {
+      int r = read_only ? db_ptr->open_read_only(std::cerr) : db_ptr->open(std::cerr);
+      if (r < 0) {
         cerr << "failed to open type " << type << " path " << path << ": "
              << cpp_strerror(r) << std::endl;
         exit(1);
@@ -47,11 +49,11 @@ StoreTool::StoreTool(const string& type,
   }
 }
 
-int StoreTool::load_bluestore(const string& path, bool to_repair)
+int StoreTool::load_bluestore(const string& path, bool read_only, bool to_repair)
 {
     auto bluestore = new BlueStore(g_ceph_context, path);
     KeyValueDB *db_ptr;
-    int r = bluestore->open_db_environment(&db_ptr, to_repair);
+    int r = bluestore->open_db_environment(&db_ptr, read_only, to_repair);
     if (r < 0) {
      return -EINVAL;
     }
index 330cba7c98dbd53ad9f3f931c57cd37531f5e53e..a0b906e96588a74bd69cf6fe4777871e4ebfaa15 100644 (file)
@@ -43,9 +43,10 @@ class StoreTool
 public:
   StoreTool(const std::string& type,
            const std::string& path,
+            bool read_only,
            bool need_open_db = true,
            bool need_stats = false);
-  int load_bluestore(const std::string& path, bool need_open_db);
+  int load_bluestore(const std::string& path, bool read_only, bool need_open_db);
   uint32_t traverse(const std::string& prefix,
                     const bool do_crc,
                     const bool do_value_dump,