]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
7c673cae FG |
21 | using ceph::bufferlist; |
22 | ||
23 | class KeyValueStructure; | |
24 | ||
25 | /**An injection_t is a function that is called before every | |
26 | * ObjectWriteOperation to test concurrency issues. For example, | |
27 | * one injection_t might cause the client to have a greater chance of dying | |
28 | * mid-split/merge. | |
29 | */ | |
30 | typedef int (KeyValueStructure::*injection_t)(); | |
31 | ||
32 | /** | |
33 | * Passed to aio methods to be called when the operation completes | |
34 | */ | |
35 | typedef void (*callback)(int * err, void *arg); | |
36 | ||
37 | class KeyValueStructure{ | |
38 | public: | |
20effc67 | 39 | std::map<char, int> opmap; |
7c673cae FG |
40 | |
41 | //these are injection methods. By default, nothing is called at each | |
42 | //interruption point. | |
43 | /** | |
44 | * returns 0 | |
45 | */ | |
46 | virtual int nothing() = 0; | |
47 | /** | |
48 | * 10% chance of waiting wait_ms seconds | |
49 | */ | |
50 | virtual int wait() = 0; | |
51 | /** | |
52 | * 10% chance of killing the client. | |
53 | */ | |
54 | virtual int suicide() = 0; | |
55 | ||
56 | ////////////////DESTRUCTOR///////////////// | |
57 | virtual ~KeyValueStructure() {} | |
58 | ||
59 | ////////////////UPDATERS/////////////////// | |
60 | ||
61 | /** | |
62 | * set up the KeyValueStructure (i.e., initialize rados/io_ctx, etc.) | |
63 | */ | |
64 | virtual int setup(int argc, const char** argv) = 0; | |
65 | ||
66 | /** | |
67 | * set the method that gets called before each ObjectWriteOperation. | |
68 | * If waite_time is set and the method passed involves waiting, it will wait | |
11fdf7f2 | 69 | * for that many milliseconds. |
7c673cae FG |
70 | */ |
71 | virtual void set_inject(injection_t inject, int wait_time) = 0; | |
72 | ||
73 | /** | |
74 | * if update_on_existing is false, returns an error if | |
75 | * key already exists in the structure | |
76 | */ | |
20effc67 | 77 | virtual int set(const std::string &key, const bufferlist &val, |
7c673cae FG |
78 | bool update_on_existing) = 0; |
79 | ||
80 | /** | |
81 | * efficiently insert the contents of in_map into the structure | |
82 | */ | |
20effc67 | 83 | virtual int set_many(const std::map<std::string, bufferlist> &in_map) = 0; |
7c673cae FG |
84 | |
85 | /** | |
86 | * removes the key-value for key. returns an error if key does not exist | |
87 | */ | |
20effc67 | 88 | virtual int remove(const std::string &key) = 0; |
7c673cae FG |
89 | |
90 | /** | |
91 | * removes all keys and values | |
92 | */ | |
93 | virtual int remove_all() = 0; | |
94 | ||
95 | ||
96 | /** | |
97 | * launches a thread to get the value of key. When complete, calls cb(cb_args) | |
98 | */ | |
20effc67 | 99 | virtual void aio_get(const std::string &key, bufferlist *val, callback cb, |
7c673cae FG |
100 | void *cb_args, int * err) = 0; |
101 | ||
102 | /** | |
103 | * launches a thread to set key to val. When complete, calls cb(cb_args) | |
104 | */ | |
20effc67 | 105 | virtual void aio_set(const std::string &key, const bufferlist &val, bool exclusive, |
7c673cae FG |
106 | callback cb, void * cb_args, int * err) = 0; |
107 | ||
108 | /** | |
109 | * launches a thread to remove key. When complete, calls cb(cb_args) | |
110 | */ | |
20effc67 | 111 | virtual void aio_remove(const std::string &key, callback cb, void *cb_args, |
7c673cae FG |
112 | int * err) = 0; |
113 | ||
114 | ////////////////READERS//////////////////// | |
115 | /** | |
116 | * gets the val associated with key. | |
117 | * | |
118 | * @param key the key to get | |
119 | * @param val the value is stored in this | |
120 | * @return error code | |
121 | */ | |
20effc67 | 122 | virtual int get(const std::string &key, bufferlist *val) = 0; |
7c673cae FG |
123 | |
124 | /** | |
125 | * stores all keys in keys. set should put them in order by key. | |
126 | */ | |
20effc67 | 127 | virtual int get_all_keys(std::set<std::string> *keys) = 0; |
7c673cae FG |
128 | |
129 | /** | |
130 | * stores all keys and values in kv_map. map should put them in order by key. | |
131 | */ | |
20effc67 | 132 | virtual int get_all_keys_and_values(std::map<std::string,bufferlist> *kv_map) = 0; |
7c673cae FG |
133 | |
134 | /** | |
135 | * True if the structure meets its own requirements for consistency. | |
136 | */ | |
137 | virtual bool is_consistent() = 0; | |
138 | ||
139 | /** | |
140 | * prints a string representation of the structure | |
141 | */ | |
20effc67 | 142 | virtual std::string str() = 0; |
7c673cae FG |
143 | }; |
144 | ||
145 | ||
146 | #endif /* KEY_VALUE_STRUCTURE_HPP_ */ |