diff options
author | Joao Eduardo Luis <joao.luis@inktank.com> | 2012-07-24 03:23:01 +0200 |
---|---|---|
committer | Joao Eduardo Luis <joao.luis@inktank.com> | 2012-07-24 03:30:14 +0200 |
commit | a16d9c64dab3c24d5522417f91d4e47df5a3e11c (patch) | |
tree | b7717cb92d06bd8ec3afb6759f32d6fd984dba1a /src/test/ObjectMap/KeyValueDBMemory.h | |
parent | doc: Fixed heading text. (diff) | |
download | ceph-a16d9c64dab3c24d5522417f91d4e47df5a3e11c.tar.xz ceph-a16d9c64dab3c24d5522417f91d4e47df5a3e11c.zip |
os: KeyValueDB: allow finer-grained control of transaction operations
This patch introduces the possibility of using single key/value
modification operations into the transaction interface.
Until now, any 'set' or 'rmkeys' operations required a map of keys to be
provided to the function, which made the task of removing or setting a
bunch of keys easier. Doing these same operations for a single key,
however, would entail creating a map with a single key.
Instead, this patch adds two new virtual abstract functions, to be
implemented by derivative classes, which set or remove one single
key/value, and we then implement the map-based, existing functions in
terms of these new functions.
We also update the derivative classes of KeyValueDB in order to reflect
these changes (i.e., LevelDBStore and KeyValueDBMemory).
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
Diffstat (limited to 'src/test/ObjectMap/KeyValueDBMemory.h')
-rw-r--r-- | src/test/ObjectMap/KeyValueDBMemory.h | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/test/ObjectMap/KeyValueDBMemory.h b/src/test/ObjectMap/KeyValueDBMemory.h index e2ce32ad5ee..5cee0527030 100644 --- a/src/test/ObjectMap/KeyValueDBMemory.h +++ b/src/test/ObjectMap/KeyValueDBMemory.h @@ -1,4 +1,5 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab #include <map> #include <set> #include <string> @@ -28,12 +29,13 @@ public: int set( const string &prefix, - const std::map<string, bufferlist> &to_set + const string &key, + const bufferlist &bl ); - int rmkeys( + int rmkey( const string &prefix, - const std::set<string> &keys + const string &key ); int rmkeys_by_prefix( @@ -51,33 +53,37 @@ public: struct SetOp : public Context { KeyValueDBMemory *db; string prefix; - std::map<string, bufferlist> to_set; + string key; + bufferlist value; SetOp(KeyValueDBMemory *db, const string &prefix, - const std::map<string, bufferlist> &to_set) - : db(db), prefix(prefix), to_set(to_set) {} + const string &key, + const bufferlist &value) + : db(db), prefix(prefix), key(key), value(value) {} void finish(int r) { - db->set(prefix, to_set); + db->set(prefix, key, value); } }; - void set(const string &prefix, const std::map<string, bufferlist> &to_set) { - on_commit.push_back(new SetOp(db, prefix, to_set)); + + void set(const string &prefix, const string &k, const bufferlist& bl) { + on_commit.push_back(new SetOp(db, prefix, k, bl)); } struct RmKeysOp : public Context { KeyValueDBMemory *db; string prefix; - std::set<string> keys; + string key; RmKeysOp(KeyValueDBMemory *db, const string &prefix, - const std::set<string> &keys) - : db(db), prefix(prefix), keys(keys) {} + const string &key) + : db(db), prefix(prefix), key(key) {} void finish(int r) { - db->rmkeys(prefix, keys); + db->rmkey(prefix, key); } }; - void rmkeys(const string &prefix, const std::set<string> &to_remove) { - on_commit.push_back(new RmKeysOp(db, prefix, to_remove)); + + void rmkey(const string &prefix, const string &key) { + on_commit.push_back(new RmKeysOp(db, prefix, key)); } struct RmKeysByPrefixOp : public Context { |