tools: Show DB state information

Signed-off-by: David Zafman <dzafman@redhat.com>
This commit is contained in:
David Zafman 2017-09-12 22:12:52 -07:00
parent de43493990
commit 3214882a95
3 changed files with 32 additions and 18 deletions

View File

@ -1029,7 +1029,7 @@ int DBObjectMap::upgrade_to_v2()
return 0; return 0;
} }
int DBObjectMap::init(bool do_upgrade) int DBObjectMap::get_state()
{ {
map<string, bufferlist> result; map<string, bufferlist> result;
set<string> to_get; set<string> to_get;
@ -1040,6 +1040,20 @@ int DBObjectMap::init(bool do_upgrade)
if (!result.empty()) { if (!result.empty()) {
bufferlist::iterator bliter = result.begin()->second.begin(); bufferlist::iterator bliter = result.begin()->second.begin();
state.decode(bliter); state.decode(bliter);
} else {
// New store
// Version 3 means that complete regions never used
state.v = 3;
state.seq = 1;
}
return 0;
}
int DBObjectMap::init(bool do_upgrade)
{
int ret = get_state();
if (ret < 0)
return ret;
if (state.v < 1) { if (state.v < 1) {
dout(1) << "DBObjectMap is *very* old; upgrade to an older version first" dout(1) << "DBObjectMap is *very* old; upgrade to an older version first"
<< dendl; << dendl;
@ -1052,17 +1066,11 @@ int DBObjectMap::init(bool do_upgrade)
<< dendl; << dendl;
return -ENOTSUP; return -ENOTSUP;
} else { } else {
r = upgrade_to_v2(); int r = upgrade_to_v2();
if (r < 0) if (r < 0)
return r; return r;
} }
} }
} else {
// New store
// Version 3 means that complete regions never used
state.v = 3;
state.seq = 1;
}
ostringstream ss; ostringstream ss;
int errors = check(ss, true); int errors = check(ss, true);
if (errors) { if (errors) {

View File

@ -219,6 +219,8 @@ public:
); );
/// Read initial state from backing store /// Read initial state from backing store
int get_state();
/// Read initial state and upgrade or initialize state
int init(bool upgrade = false); int init(bool upgrade = false);
/// Upgrade store to current version /// Upgrade store to current version

View File

@ -123,6 +123,10 @@ int main(int argc, char **argv) {
// the DBObjectMap which we might want to examine for diagnostic // the DBObjectMap which we might want to examine for diagnostic
// reasons. Instead use --command repair. // reasons. Instead use --command repair.
omap.get_state();
std::cout << "Version: " << (int)omap.state.v << std::endl;
std::cout << "Seq: " << omap.state.seq << std::endl;
if (cmd == "dump-raw-keys") { if (cmd == "dump-raw-keys") {
KeyValueDB::WholeSpaceIterator i = store->get_iterator(); KeyValueDB::WholeSpaceIterator i = store->get_iterator();
for (i->seek_to_first(); i->valid(); i->next()) { for (i->seek_to_first(); i->valid(); i->next()) {