os: extend the key/value DB interface for finer-grained usage.

Also updates the implementers of the KeyValueDB class and their users.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
os: KeyValueDB: add prefix-independent virtual get_iterator() function

It will be useful to iterate over the whole set of keys on a K/V store
such as the LevelDBStore.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
os: KeyValueDB: Add virtual raw_key() function to return (prefix,key) pair

In certain cases, such as when we are iterating over the whole key space,
it is useful to obtain the (prefix, key) pair. We could easily obtain the
key as is, but given that each implementation may deal with prefixes and
keys differently (for instance, the LevelDBStore will use '\0' as the
separator for the 'prefix' and 'key' components), we would rather have a
function responsible for returning a pair instead.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
os: LevelDBStore: implement the KeyValueDB's raw_key() function

If we were to use solely the key() function, whenever we had a key with,
say, prefix 'Foo' and key 'Bar', the key() function would return something
similar to 'FooBar'. Since the separator used on the LevelDBStore is '\0',
but considering that different implementations of KeyValueDB may use
different separators, anyone using a K/V implementation would have to be
aware of the separator and parse the prefix and the key if they so wanted
to do it during an iteration over the whole store's key space.

As such, implement the raw_key() function which will be responsible for
returning a pair (prefix,key), leaving the parsing and all the
implementation-specific details for the implementation itself.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
os: KeyValueDB: create whole-space iterator and read-only iterator

In-a-nutshell-version:
  1) Create a whole-space iterator interface, and implement the already
     existing, prefix-based iterator in terms of the new whole-space
     iterator;
  2) Add support for read-only iterators.

This patch introduces a significant change on the architecture of
KeyValueDB's iterator, although its interface remains the same.

Before this patch, the KeyValueDB simply defined an interface for a
prefix-based interface, to be implemented by derivative classes. Being
constrained by a prefix-based approach to iterate over the store only makes
sense when we know which prefixes we want to iterate over, but for that we
must know about the prefixes beforehand. This approach didn't work when one
wanted to iterate over the whole key space, without any previous awareness
about the keys and their prefixes.

This patch introduces a new interface for a whole-space iterator, to be
implemented by derivative classes, which is prefix-independent. We also
define an abstract function to obtain this iterator, which must also be
implemented by the derivative class. With this interface in place, we are
then able to implement a prefix-dependent iterator in terms of the
whole-space iterator, which will be offered by the KeyValueDB class itself.

Furthermore, we also introduce support for a read-only iterator. The task
of implementing such iterator is delegated to any derivative class.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
os: LevelDBStore: Implement whole-space and read-only iterators

Following the changes to KeyValueDB, we get rid of the previous,
prefix-dependent iterator implementation, and we create a whole-space
iterator for a leveldb k/v store. We also add a read-only iterator that
relies on the said whole-space iterator.

This read-only iterator relies on leveldb's snapshots, and is intended as
a thread-safe iterator for those occasions when preventing concurrent
modification is not an option.

For instance, we need to iterate over a known, consistent store state
during monitor synchronization, while allowing updates to be performed for
Paxos sake -- and that means both insertion and removal of keys, which
could be, at best, problematic or simply bear unforeseen issues that could
ultimately only be seen during full-fledged concurrent accesses to the
store.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
test: KeyValueDBMemory: implement whole-space and read-only iterators

Following the changes in KeyValueDB, this patch removes the in-memory,
prefix-dependent iterator and make it a whole-space iterator instead. We
also add a read-only iterator based on the said whole-space iterator.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
test: KeyValueDBMemory: remove prefix when it runs out of keys

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
test: test_keyvaluedb_iterators: Test KeyValueDB implementations iterators

Such as KeyValueDBMemory's and LevelDBStore's whole-space iterators,
along with the read-only version of each one.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>