Skip to content

Commit 410d474

Browse files
committed
tools/ceph-kvstore-tool: open DB in read-only whenever sufficient
Signed-off-by: Igor Fedotov <[email protected]>
1 parent d05d0c8 commit 410d474

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

src/os/bluestore/BlueStore.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7465,10 +7465,10 @@ void BlueStore::_close_around_db()
74657465
_close_path();
74667466
}
74677467

7468-
int BlueStore::open_db_environment(KeyValueDB **pdb, bool to_repair)
7468+
int BlueStore::open_db_environment(KeyValueDB **pdb, bool read_only, bool to_repair)
74697469
{
74707470
_kv_only = true;
7471-
int r = _open_db_and_around(false, to_repair);
7471+
int r = _open_db_and_around(read_only, to_repair);
74727472
if (r == 0) {
74737473
*pdb = db;
74747474
} else {

src/os/bluestore/BlueStore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2960,7 +2960,7 @@ class BlueStore : public ObjectStore,
29602960
}
29612961
int umount() override;
29622962

2963-
int open_db_environment(KeyValueDB **pdb, bool to_repair);
2963+
int open_db_environment(KeyValueDB **pdb, bool read_only, bool to_repair);
29642964
int close_db_environment();
29652965
BlueFS* get_bluefs();
29662966

src/os/bluestore/bluestore_tool.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void bluefs_import(
242242
}
243243
BlueStore bluestore(cct, path);
244244
KeyValueDB *db_ptr;
245-
r = bluestore.open_db_environment(&db_ptr, false);
245+
r = bluestore.open_db_environment(&db_ptr, false, false);
246246
if (r < 0) {
247247
cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
248248
exit(EXIT_FAILURE);
@@ -1117,7 +1117,7 @@ int main(int argc, char **argv)
11171117
exit(EXIT_FAILURE);
11181118
}
11191119
}
1120-
int r = bluestore.open_db_environment(&db_ptr, true);
1120+
int r = bluestore.open_db_environment(&db_ptr, false, true);
11211121
if (r < 0) {
11221122
cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
11231123
exit(EXIT_FAILURE);
@@ -1135,7 +1135,7 @@ int main(int argc, char **argv)
11351135
} else if (action == "show-sharding") {
11361136
BlueStore bluestore(cct.get(), path);
11371137
KeyValueDB *db_ptr;
1138-
int r = bluestore.open_db_environment(&db_ptr, false);
1138+
int r = bluestore.open_db_environment(&db_ptr, false, false);
11391139
if (r < 0) {
11401140
cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
11411141
exit(EXIT_FAILURE);

src/tools/ceph_kvstore_tool.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,20 @@ int main(int argc, const char *argv[])
9898
return 1;
9999
}
100100

101+
bool read_only =
102+
cmd == "list" ||
103+
cmd == "list-crc" ||
104+
cmd == "dump" ||
105+
cmd == "exists" ||
106+
cmd == "get" ||
107+
cmd == "crc" ||
108+
cmd == "get-size" ||
109+
cmd == "store-crc" ||
110+
cmd == "stats" ||
111+
cmd == "histogram";
101112
bool to_repair = (cmd == "destructive-repair");
102113
bool need_stats = (cmd == "stats");
103-
StoreTool st(type, path, to_repair, need_stats);
114+
StoreTool st(type, path, read_only, to_repair, need_stats);
104115

105116
if (cmd == "destructive-repair") {
106117
int ret = st.destructive_repair();

src/tools/kvstore_tool.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using namespace std;
1616

1717
StoreTool::StoreTool(const string& type,
1818
const string& path,
19+
bool read_only,
1920
bool to_repair,
2021
bool need_stats)
2122
: store_path(path)
@@ -28,7 +29,7 @@ StoreTool::StoreTool(const string& type,
2829

2930
if (type == "bluestore-kv") {
3031
#ifdef WITH_BLUESTORE
31-
if (load_bluestore(path, to_repair) != 0)
32+
if (load_bluestore(path, read_only, to_repair) != 0)
3233
exit(1);
3334
#else
3435
cerr << "bluestore not compiled in" << std::endl;
@@ -37,7 +38,8 @@ StoreTool::StoreTool(const string& type,
3738
} else {
3839
auto db_ptr = KeyValueDB::create(g_ceph_context, type, path);
3940
if (!to_repair) {
40-
if (int r = db_ptr->open(std::cerr); r < 0) {
41+
int r = read_only ? db_ptr->open_read_only(std::cerr) : db_ptr->open(std::cerr);
42+
if (r < 0) {
4143
cerr << "failed to open type " << type << " path " << path << ": "
4244
<< cpp_strerror(r) << std::endl;
4345
exit(1);
@@ -47,11 +49,11 @@ StoreTool::StoreTool(const string& type,
4749
}
4850
}
4951

50-
int StoreTool::load_bluestore(const string& path, bool to_repair)
52+
int StoreTool::load_bluestore(const string& path, bool read_only, bool to_repair)
5153
{
5254
auto bluestore = new BlueStore(g_ceph_context, path);
5355
KeyValueDB *db_ptr;
54-
int r = bluestore->open_db_environment(&db_ptr, to_repair);
56+
int r = bluestore->open_db_environment(&db_ptr, read_only, to_repair);
5557
if (r < 0) {
5658
return -EINVAL;
5759
}

src/tools/kvstore_tool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class StoreTool
4343
public:
4444
StoreTool(const std::string& type,
4545
const std::string& path,
46+
bool read_only,
4647
bool need_open_db = true,
4748
bool need_stats = false);
48-
int load_bluestore(const std::string& path, bool need_open_db);
49+
int load_bluestore(const std::string& path, bool read_only, bool need_open_db);
4950
uint32_t traverse(const std::string& prefix,
5051
const bool do_crc,
5152
const bool do_value_dump,

0 commit comments

Comments
 (0)