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 snapshot 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 snapshot 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 snapshot 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 snapshot 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 snapshot iterator that
relies on the said whole-space iterator.

This snapshot 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 snapshot 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 snapshot 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 snapshot version of each one.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
Makefile.am: add test_keyvaluedb_iterators to the build

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
auth: cephx: KeyServer: add 'has_secrets()' function

We need this in the AuthMonitor to assess if we should encode a full version
of the KeyServer and submit it to the Paxos along with the incrementals.

Not performing such a check will lead us to an erroneous version, from which
we won't be able to recover.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: Do some aesthetic reformatting on the Paxos class.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: Do some aesthetic reformatting on the Elector class.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: MonitorDBStore: Add a key/value store to be used in the monitor

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: Monitor: keyring always on mon_data/keyring by default

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: Paxos: Single-paxos support

We are converting the monitor subsystem to a Single-Paxos architecture,
backed by a key/value store. The previous architecture used a Paxos
instance for each Paxos Service, backed by a nasty Monitor Store that
provided few to no consistency guarantees whatsoever, which led to a fair
amount of workarounds.

Changes:
  - Add k/v store support
  - Add documentation describing the new Paxos storage layout and behavior
  - Get rid of the stashing code, which was used as a consistency point
    mechanism (we no longer need it, because of our k/v store)

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: PaxosService: Single-paxos support

Changes:
  - Add k/v store support, by creating wrappers to be used by the services
  - Add documentation
  - Support single-paxos behavior by creating wrappers to be used by the
    services and service-specific version
  - Rearrange variables so they are neatly organized in the beginning of
    the class
  - Add a trim_to() function to be used by the services, instead of letting
    them rely on Paxos::trim_to(), which is no longer adequate to the job
    at hand

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: Monitor: Single-paxos support

Changes:
  - Add k/v store support
  - Use only one Paxos instance and pass it down to each service instance

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: OSDMonitor: Single-Paxos support

Changes:
  - Add k/v store support
  - Add single-paxos support

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
mon: Elector: Single-Paxos support

Changes:
  - Add k/v store support
  - Add single-paxos support

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