Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / key_value_store / key_value_structure.h
1 /*
2  * Interface for key-value store using librados
3  *
4  * September 2, 2012
5  * Eleanor Cawthon
6  * eleanor.cawthon@inktank.com
7  *
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.
12  */
13
14 #ifndef KEY_VALUE_STRUCTURE_HPP_
15 #define KEY_VALUE_STRUCTURE_HPP_
16
17 #include "include/rados/librados.hpp"
18 #include "include/utime.h"
19 #include <vector>
20
21 using std::string;
22 using std::map;
23 using std::set;
24 using ceph::bufferlist;
25
26 class KeyValueStructure;
27
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
31  * mid-split/merge.
32  */
33 typedef int (KeyValueStructure::*injection_t)();
34
35 /**
36  * Passed to aio methods to be called when the operation completes
37  */
38 typedef void (*callback)(int * err, void *arg);
39
40 class KeyValueStructure{
41 public:
42   map<char, int> opmap;
43
44   //these are injection methods. By default, nothing is called at each
45   //interruption point.
46   /**
47    * returns 0
48    */
49   virtual int nothing() = 0;
50   /**
51    * 10% chance of waiting wait_ms seconds
52    */
53   virtual int wait() = 0;
54   /**
55    * 10% chance of killing the client.
56    */
57   virtual int suicide() = 0;
58
59   ////////////////DESTRUCTOR/////////////////
60   virtual ~KeyValueStructure() {}
61
62   ////////////////UPDATERS///////////////////
63
64   /**
65    * set up the KeyValueStructure (i.e., initialize rados/io_ctx, etc.)
66    */
67   virtual int setup(int argc, const char** argv) = 0;
68
69   /**
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 miliseconds.
73    */
74   virtual void set_inject(injection_t inject, int wait_time) = 0;
75
76   /**
77    * if update_on_existing is false, returns an error if
78    * key already exists in the structure
79    */
80   virtual int set(const string &key, const bufferlist &val,
81       bool update_on_existing) = 0;
82
83   /**
84    * efficiently insert the contents of in_map into the structure
85    */
86   virtual int set_many(const map<string, bufferlist> &in_map) = 0;
87
88   /**
89    * removes the key-value for key. returns an error if key does not exist
90    */
91   virtual int remove(const string &key) = 0;
92
93   /**
94    * removes all keys and values
95    */
96   virtual int remove_all() = 0;
97
98
99   /**
100    * launches a thread to get the value of key. When complete, calls cb(cb_args)
101    */
102   virtual void aio_get(const string &key, bufferlist *val, callback cb,
103       void *cb_args, int * err) = 0;
104
105   /**
106    * launches a thread to set key to val. When complete, calls cb(cb_args)
107    */
108   virtual void aio_set(const string &key, const bufferlist &val, bool exclusive,
109       callback cb, void * cb_args, int * err) = 0;
110
111   /**
112    * launches a thread to remove key. When complete, calls cb(cb_args)
113    */
114   virtual void aio_remove(const string &key, callback cb, void *cb_args,
115       int * err) = 0;
116
117   ////////////////READERS////////////////////
118   /**
119    * gets the val associated with key.
120    *
121    * @param key the key to get
122    * @param val the value is stored in this
123    * @return error code
124    */
125   virtual int get(const string &key, bufferlist *val) = 0;
126
127   /**
128    * stores all keys in keys. set should put them in order by key.
129    */
130   virtual int get_all_keys(std::set<string> *keys) = 0;
131
132   /**
133    * stores all keys and values in kv_map. map should put them in order by key.
134    */
135   virtual int get_all_keys_and_values(map<string,bufferlist> *kv_map) = 0;
136
137   /**
138    * True if the structure meets its own requirements for consistency.
139    */
140   virtual bool is_consistent() = 0;
141
142   /**
143    * prints a string representation of the structure
144    */
145   virtual string str() = 0;
146 };
147
148
149 #endif /* KEY_VALUE_STRUCTURE_HPP_ */