Skip to content

Commit

Permalink
kv: unify {create_and_,}open() methods
Browse files Browse the repository at this point in the history
this silences the warning of "-Woverloaded-virtual" where create() and
create_and_open() from KeyValueDB are hidden from the ones defined in
derived classes.

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Oct 9, 2017
1 parent d8227f4 commit 385786b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 40 deletions.
12 changes: 3 additions & 9 deletions src/kv/KeyValueDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,11 @@ class KeyValueDB {
/// test whether we can successfully initialize; may have side effects (e.g., create)
static int test_init(const std::string& type, const std::string& dir);
virtual int init(string option_str="") = 0;
virtual int open(std::ostream &out) = 0;
virtual int open(std::ostream &out, const vector<ColumnFamily>& cfs) {
assert(0 == "Not implemented");
}
virtual int create_and_open(std::ostream &out) = 0;
virtual void close() { }
virtual int open(std::ostream &out, const vector<ColumnFamily>& cfs = {}) = 0;
// vector cfs contains column families to be created when db is created.
virtual int create_and_open(std::ostream &out,
const vector<ColumnFamily>& cfs) {
assert(0 == "Not implemented");
}
const vector<ColumnFamily>& cfs = {}) = 0;
virtual void close() { }

virtual Transaction get_transaction() = 0;
virtual int submit_transaction(Transaction) = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/kv/KineticStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ int KineticStore::_test_init(CephContext *c)
return status.ok() ? 0 : -EIO;
}

int KineticStore::open(ostream &out, const vector<ColumnFamily>& cfs)
{
if (!cfs.empty()) {
assert(0 == "Not implemented");
}
return do_open(out, false);
}

int KineticStore::create_and_open(ostream &out, const vector<ColumnFamily>& cfs)
{
if (!cfs.empty()) {
assert(0 == "Not implemented");
}
return do_open(out, true);
}

int KineticStore::do_open(ostream &out, bool create_if_missing)
{
kinetic::KineticConnectionFactory conn_factory =
Expand Down
8 changes: 2 additions & 6 deletions src/kv/KineticStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ class KineticStore : public KeyValueDB {
int init();

/// Opens underlying db
int open(ostream &out) {
return do_open(out, false);
}
int open(ostream &out, const std::vector<ColumnFamily>& = {}) override;
/// Creates underlying db if missing and opens it
int create_and_open(ostream &out) override {
return do_open(out, true);
}
int create_and_open(ostream &out, const std::vector<ColumnFamily>& = {}) override;

void close();

Expand Down
14 changes: 14 additions & 0 deletions src/kv/LevelDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ int LevelDBStore::init(string option_str)
return 0;
}

int LevelDBStore::open(ostream &out, const vector<ColumnFamily>& cfs) {
if (!cfs.empty()) {
assert(0 == "Not implemented");
}
return do_open(out, false);
}

int LevelDBStore::create_and_open(ostream &out, const vector<ColumnFamily>& cfs) {
if (!cfs.empty()) {
assert(0 == "Not implemented");
}
return do_open(out, true);
}

int LevelDBStore::do_open(ostream &out, bool create_if_missing)
{
leveldb::Options ldoptions;
Expand Down
8 changes: 2 additions & 6 deletions src/kv/LevelDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,9 @@ class LevelDBStore : public KeyValueDB {
int init(string option_str="") override;

/// Opens underlying db
int open(ostream &out) override {
return do_open(out, false);
}
int open(ostream &out, const std::vector<ColumnFamily>& = {}) override;
/// Creates underlying db if missing and opens it
int create_and_open(ostream &out) override {
return do_open(out, true);
}
int create_and_open(ostream &out, const std::vector<ColumnFamily>& = {}) override;

void close() override;

Expand Down
14 changes: 14 additions & 0 deletions src/kv/MemDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ int MemDB::do_open(ostream &out, bool create)
return _init(create);
}

int MemDB::open(ostream &out, const vector<ColumnFamily>& cfs) {
if (!cfs.empty()) {
assert(0 == "Not implemented");
}
return do_open(out, false);
}

int MemDB::create_and_open(ostream &out, const vector<ColumnFamily>& cfs) {
if (!cfs.empty()) {
assert(0 == "Not implemented");
}
return do_open(out, true);
}

MemDB::~MemDB()
{
close();
Expand Down
5 changes: 3 additions & 2 deletions src/kv/MemDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ class MemDB : public KeyValueDB
int _init(bool format);

int do_open(ostream &out, bool create);
int open(ostream &out) override { return do_open(out, false); }
int create_and_open(ostream &out) override { return do_open(out, true); }
int open(ostream &out, const std::vector<ColumnFamily>&) override;
int create_and_open(ostream &out, const std::vector<ColumnFamily>&) override;
using KeyValueDB::create_and_open;

KeyValueDB::Transaction get_transaction() override {
return std::shared_ptr<MDBTransactionImpl>(new MDBTransactionImpl(this));
Expand Down
14 changes: 5 additions & 9 deletions src/kv/RocksDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,17 @@ int RocksDBStore::install_cf_mergeop(
return 0;
}

int RocksDBStore::create_and_open(ostream &out)
{
int r = create_db_dir();
if (r < 0)
return r;
return do_open(out, true);
}

int RocksDBStore::create_and_open(ostream &out,
const vector<ColumnFamily>& cfs)
{
int r = create_db_dir();
if (r < 0)
return r;
return do_open(out, true, &cfs);
if (cfs.empty()) {
return do_open(out, true, nullptr);
} else {
return do_open(out, true, &cfs);
}
}

int RocksDBStore::do_open(ostream &out, bool create_if_missing,
Expand Down
8 changes: 2 additions & 6 deletions src/kv/RocksDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,12 @@ class RocksDBStore : public KeyValueDB {

static bool check_omap_dir(string &omap_dir);
/// Opens underlying db
int open(ostream &out) override {
return do_open(out, false);
}
int open(ostream &out, const vector<ColumnFamily>& cfs) override {
int open(ostream &out, const vector<ColumnFamily>& cfs = {}) override {
return do_open(out, false, &cfs);
}
/// Creates underlying db if missing and opens it
int create_and_open(ostream &out) override;
int create_and_open(ostream &out,
const vector<ColumnFamily>& cfs) override;
const vector<ColumnFamily>& cfs = {}) override;

void close() override;

Expand Down
4 changes: 2 additions & 2 deletions src/test/ObjectMap/KeyValueDBMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class KeyValueDBMemory : public KeyValueDB {
int init(string _opt) override {
return 0;
}
int open(ostream &out) override {
int open(std::ostream &out, const vector<ColumnFamily>& cfs = {}) override {
return 0;
}
int create_and_open(ostream &out) override {
int create_and_open(ostream &out, const vector<ColumnFamily>& cfs = {}) override {
return 0;
}

Expand Down

0 comments on commit 385786b

Please sign in to comment.