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;
}
int DBObjectMap::init(bool do_upgrade)
int DBObjectMap::get_state()
{
map<string, bufferlist> result;
set<string> to_get;
@ -1040,29 +1040,37 @@ int DBObjectMap::init(bool do_upgrade)
if (!result.empty()) {
bufferlist::iterator bliter = result.begin()->second.begin();
state.decode(bliter);
if (state.v < 1) {
dout(1) << "DBObjectMap is *very* old; upgrade to an older version first"
<< dendl;
return -ENOTSUP;
}
if (state.v < 2) { // Needs upgrade
if (!do_upgrade) {
dout(1) << "DOBjbectMap requires an upgrade,"
<< " set filestore_update_to"
<< dendl;
return -ENOTSUP;
} else {
r = upgrade_to_v2();
if (r < 0)
return r;
}
}
} 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) {
dout(1) << "DBObjectMap is *very* old; upgrade to an older version first"
<< dendl;
return -ENOTSUP;
}
if (state.v < 2) { // Needs upgrade
if (!do_upgrade) {
dout(1) << "DOBjbectMap requires an upgrade,"
<< " set filestore_update_to"
<< dendl;
return -ENOTSUP;
} else {
int r = upgrade_to_v2();
if (r < 0)
return r;
}
}
ostringstream ss;
int errors = check(ss, true);
if (errors) {

View File

@ -219,6 +219,8 @@ public:
);
/// Read initial state from backing store
int get_state();
/// Read initial state and upgrade or initialize state
int init(bool upgrade = false);
/// 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
// 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") {
KeyValueDB::WholeSpaceIterator i = store->get_iterator();
for (i->seek_to_first(); i->valid(); i->next()) {