]>
git.proxmox.com Git - ceph.git/blob - ceph/src/key_value_store/key_value_structure.h
2 * Interface for key-value store using librados
6 * eleanor.cawthon@inktank.com
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #ifndef KEY_VALUE_STRUCTURE_HPP_
15 #define KEY_VALUE_STRUCTURE_HPP_
17 #include "include/rados/librados.hpp"
18 #include "include/utime.h"
24 using ceph::bufferlist
;
26 class KeyValueStructure
;
28 /**An injection_t is a function that is called before every
29 * ObjectWriteOperation to test concurrency issues. For example,
30 * one injection_t might cause the client to have a greater chance of dying
33 typedef int (KeyValueStructure::*injection_t
)();
36 * Passed to aio methods to be called when the operation completes
38 typedef void (*callback
)(int * err
, void *arg
);
40 class KeyValueStructure
{
44 //these are injection methods. By default, nothing is called at each
49 virtual int nothing() = 0;
51 * 10% chance of waiting wait_ms seconds
53 virtual int wait() = 0;
55 * 10% chance of killing the client.
57 virtual int suicide() = 0;
59 ////////////////DESTRUCTOR/////////////////
60 virtual ~KeyValueStructure() {}
62 ////////////////UPDATERS///////////////////
65 * set up the KeyValueStructure (i.e., initialize rados/io_ctx, etc.)
67 virtual int setup(int argc
, const char** argv
) = 0;
70 * set the method that gets called before each ObjectWriteOperation.
71 * If waite_time is set and the method passed involves waiting, it will wait
72 * for that many milliseconds.
74 virtual void set_inject(injection_t inject
, int wait_time
) = 0;
77 * if update_on_existing is false, returns an error if
78 * key already exists in the structure
80 virtual int set(const string
&key
, const bufferlist
&val
,
81 bool update_on_existing
) = 0;
84 * efficiently insert the contents of in_map into the structure
86 virtual int set_many(const map
<string
, bufferlist
> &in_map
) = 0;
89 * removes the key-value for key. returns an error if key does not exist
91 virtual int remove(const string
&key
) = 0;
94 * removes all keys and values
96 virtual int remove_all() = 0;
100 * launches a thread to get the value of key. When complete, calls cb(cb_args)
102 virtual void aio_get(const string
&key
, bufferlist
*val
, callback cb
,
103 void *cb_args
, int * err
) = 0;
106 * launches a thread to set key to val. When complete, calls cb(cb_args)
108 virtual void aio_set(const string
&key
, const bufferlist
&val
, bool exclusive
,
109 callback cb
, void * cb_args
, int * err
) = 0;
112 * launches a thread to remove key. When complete, calls cb(cb_args)
114 virtual void aio_remove(const string
&key
, callback cb
, void *cb_args
,
117 ////////////////READERS////////////////////
119 * gets the val associated with key.
121 * @param key the key to get
122 * @param val the value is stored in this
125 virtual int get(const string
&key
, bufferlist
*val
) = 0;
128 * stores all keys in keys. set should put them in order by key.
130 virtual int get_all_keys(std::set
<string
> *keys
) = 0;
133 * stores all keys and values in kv_map. map should put them in order by key.
135 virtual int get_all_keys_and_values(map
<string
,bufferlist
> *kv_map
) = 0;
138 * True if the structure meets its own requirements for consistency.
140 virtual bool is_consistent() = 0;
143 * prints a string representation of the structure
145 virtual string
str() = 0;
149 #endif /* KEY_VALUE_STRUCTURE_HPP_ */