]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: Split _open_db function
authorAdam Kupczyk <akupczyk@redhat.com>
Tue, 21 Apr 2020 09:43:28 +0000 (11:43 +0200)
committerAdam Kupczyk <akupczyk@redhat.com>
Thu, 14 May 2020 16:06:38 +0000 (18:06 +0200)
Created function that prepares environment for _open_db.
Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 8e10a4476927746a1b8b8d79d08e9a303c7ecb58..2cf70b5847d858c9831d64d45c81b2a54b0e41ec 100644 (file)
@@ -5613,19 +5613,16 @@ void BlueStore::_sync_bluefs_and_fm()
   }
 }
 
-int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only)
+int BlueStore::_prepare_db_environment(bool create, bool read_only,
+                                      std::string* _fn, std::string* _kv_backend)
 {
   int r;
   ceph_assert(!db);
-  ceph_assert(!(create && read_only));
-  string fn = path + "/db";
-  string options;
-  stringstream err;
+  std::string& fn=*_fn;
+  std::string& kv_backend=*_kv_backend;
+  fn = path + "/db";
   std::shared_ptr<Int64ArrayMergeOperator> merge_op(new Int64ArrayMergeOperator);
 
-  string kv_backend;
-  std::string sharding_def;
-
   if (create) {
     kv_backend = cct->_conf->bluestore_kvbackend;
   } else {
@@ -5765,7 +5762,23 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only)
   FreelistManager::setup_merge_operators(db);
   db->set_merge_operator(PREFIX_STAT, merge_op);
   db->set_cache_size(cache_kv_ratio * cache_size);
+  return 0;
+}
 
+int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only)
+{
+  int r;
+  ceph_assert(!(create && read_only));
+  string options;
+  stringstream err;
+  string kv_dir_fn;
+  string kv_backend;
+  std::string sharding_def;
+  r = _prepare_db_environment(create, read_only, &kv_dir_fn, &kv_backend);
+  if (r < 0) {
+    derr << __func__ << " failed to prepare db environment: " << err.str() << dendl;
+    return -EIO;
+  }
   if (kv_backend == "rocksdb") {
     options = cct->_conf->bluestore_rocksdb_options;
     if (cct->_conf.get_val<bool>("bluestore_rocksdb_cf")) {
@@ -5791,7 +5804,7 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only)
     return -EIO;
   }
   dout(1) << __func__ << " opened " << kv_backend
-         << " path " << fn << " options " << options << dendl;
+         << " path " << kv_dir_fn << " options " << options << dendl;
   return 0;
 }
 
index 4ae14fa5c60d36d21eaa04d082abffa68f320a3f..44a3cfc538f9a9789f8bb8828fcb77dbaaeed42e 100644 (file)
@@ -2281,6 +2281,8 @@ private:
   */
   int _open_db_and_around(bool read_only);
   void _close_db_and_around(bool read_only);
+  int _prepare_db_environment(bool create, bool read_only,
+                             std::string* kv_dir, std::string* kv_backend);
 
   // updates legacy bluefs related recs in DB to a state valid for
   // downgrades from nautilus.