2 * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
21 #include <elliptics/typedefs.h>
22 #include <elliptics/packet.h>
23 #include <elliptics/interface.h>
33 namespace ioremap
{ namespace elliptics
{
35 class elliptics_error
: public std::runtime_error
{
37 explicit elliptics_error(int err
);
38 int error_code() const;
40 static std::string
convert(int err
);
44 class not_found_error
: public elliptics_error
{
46 explicit not_found_error();
49 class timeout_error
: public elliptics_error
{
51 explicit timeout_error();
54 void throw_exception(int err
);
57 addr_tuple(const std::string
&l_host
, const int l_port
, const int l_family
= AF_INET
) :
58 host(l_host
), port(l_port
), family(l_family
) {}
67 logger(const int level
= DNET_LOG_INFO
) {
69 ll
.log
= logger::real_logger
;
70 ll
.log_private
= this;
74 virtual void log(const int level
, const char *msg
) = 0;
77 * Clone is used instead of 'virtual' copy constructor, since we have to
78 * hold a reference to object outside of our scope, namely python created
79 * logger. This is also a reason we return 'unsigned long' instead of
80 * 'logger *' - python does not have pointer.
82 virtual unsigned long clone(void) = 0;
84 static void real_logger(void *priv
, const int level
, const char *msg
);
85 int get_log_level(void) { return ll
.log_level
; };
86 struct dnet_log
*get_dnet_log(void) { return &ll
; };
91 class log_file
: public logger
{
93 log_file(const char *file
, const int level
= DNET_LOG_INFO
);
96 virtual unsigned long clone(void);
97 virtual void log(const int level
, const char *msg
);
102 * Oh shi, I put pointer here to avoid boost::python compiler issues,
103 * when it tries to copy stream, which is not allowed
105 std::ofstream
*stream
;
113 virtual int handle(struct dnet_net_state
*state
, struct dnet_cmd
*cmd
);
115 static int complete_callback(struct dnet_net_state
*st
, struct dnet_cmd
*cmd
, void *priv
) {
116 callback
*c
= reinterpret_cast<callback
*>(priv
);
118 return c
->handle(st
, cmd
);
121 std::string
wait(int completed
= 1);
125 pthread_cond_t wait_cond
;
126 pthread_mutex_t lock
;
132 /* we shold use logger and proper copy constructor here, but not this time */
134 node(logger
&l
, struct dnet_config
&cfg
);
135 node(logger
&l
, const std::string
&config_path
);
138 void parse_config(const std::string
&path
, struct dnet_config
&cfg
,
139 std::list
<addr_tuple
> &remotes
,
140 std::vector
<int> &groups
,
143 void add_remote(const char *addr
, const int port
, const int family
= AF_INET
);
145 void set_timeouts(const int wait_timeout
, const int check_timeout
);
148 int write_data_ll(struct dnet_id
*id
, void *remote
, unsigned int remote_len
,
149 void *data
, unsigned int size
, callback
&c
,
150 uint64_t cflags
, unsigned int ioflags
, int type
);
151 struct dnet_node
*m_node
;
154 friend class session
;
162 void transform(const std::string
&data
, struct dnet_id
&id
);
164 void add_groups(std::vector
<int> &groups
);
165 std::vector
<int> get_groups() {return groups
;};
167 void read_file(struct dnet_id
&id
, const std::string
&file
, uint64_t offset
, uint64_t size
);
168 void read_file(const std::string
&remote
, const std::string
&file
,
169 uint64_t offset
, uint64_t size
, int type
);
171 void write_file(struct dnet_id
&id
, const std::string
&file
, uint64_t local_offset
,
172 uint64_t offset
, uint64_t size
, uint64_t cflags
, unsigned int ioflags
);
173 void write_file(const std::string
&remote
, const std::string
&file
,
174 uint64_t local_offset
, uint64_t offset
, uint64_t size
,
175 uint64_t cflags
, unsigned int ioflags
, int type
);
177 std::string
read_data_wait(struct dnet_id
&id
, uint64_t offset
, uint64_t size
,
178 uint64_t cflags
, uint32_t ioflags
);
179 std::string
read_data_wait(const std::string
&remote
, uint64_t offset
, uint64_t size
,
180 uint64_t cflags
, uint32_t ioflags
, int type
);
182 void prepare_latest(struct dnet_id
&id
, uint64_t cflags
, std::vector
<int> &groups
);
184 std::string
read_latest(struct dnet_id
&id
, uint64_t offset
, uint64_t size
,
185 uint64_t cflags
, uint32_t ioflags
);
186 std::string
read_latest(const std::string
&remote
, uint64_t offset
, uint64_t size
,
187 uint64_t cflags
, uint32_t ioflags
, int type
);
189 std::string
write_compare_and_swap(const struct dnet_id
&id
, const std::string
&str
,
190 const struct dnet_id
&old_csum
, uint64_t remote_offset
, uint64_t cflags
, unsigned int ioflags
);
191 std::string
write_compare_and_swap(const std::string
&remote
, const std::string
&str
,
192 const struct dnet_id
&old_csum
, uint64_t remote_offset
, uint64_t cflags
, unsigned int ioflags
, int type
);
194 std::string
write_data_wait(struct dnet_id
&id
, const std::string
&str
,
195 uint64_t remote_offset
, uint64_t cflags
, unsigned int ioflags
);
196 std::string
write_data_wait(const std::string
&remote
, const std::string
&str
,
197 uint64_t remote_offset
, uint64_t cflags
, unsigned int ioflags
, int type
);
199 std::string
write_prepare(const std::string
&remote
, const std::string
&str
, uint64_t remote_offset
,
200 uint64_t psize
, uint64_t cflags
, unsigned int ioflags
, int type
);
201 std::string
write_commit(const std::string
&remote
, const std::string
&str
, uint64_t remote_offset
,
202 uint64_t csize
, uint64_t cflags
, unsigned int ioflags
, int type
);
203 std::string
write_plain(const std::string
&remote
, const std::string
&str
, uint64_t remote_offset
,
204 uint64_t cflags
, unsigned int ioflags
, int type
);
206 std::string
write_prepare(const struct dnet_id
&id
, const std::string
&str
, uint64_t remote_offset
,
207 uint64_t psize
, uint64_t cflags
, unsigned int ioflags
);
208 std::string
write_commit(const struct dnet_id
&id
, const std::string
&str
, uint64_t remote_offset
,
209 uint64_t csize
, uint64_t cflags
, unsigned int ioflags
);
210 std::string
write_plain(const struct dnet_id
&id
, const std::string
&str
, uint64_t remote_offset
,
211 uint64_t cflags
, unsigned int ioflags
);
213 std::string
write_cache(struct dnet_id
&id
, const std::string
&str
,
214 uint64_t cflags
, unsigned int ioflags
, long timeout
);
215 std::string
write_cache(const std::string
&key
, const std::string
&str
,
216 uint64_t cflags
, unsigned int ioflags
, long timeout
);
220 std::string
lookup_addr(const std::string
&remote
, const int group_id
);
221 std::string
lookup_addr(const struct dnet_id
&id
);
223 std::string
create_metadata(const struct dnet_id
&id
, const std::string
&obj
,
224 const std::vector
<int> &groups
, const struct timespec
&ts
);
225 int write_metadata(const struct dnet_id
&id
, const std::string
&obj
,
226 const std::vector
<int> &groups
, const struct timespec
&ts
, uint64_t cflags
);
228 void lookup(const std::string
&data
, const callback
&c
);
229 void lookup(const struct dnet_id
&id
, const callback
&c
);
230 std::string
lookup(const std::string
&data
);
231 std::string
lookup(const struct dnet_id
&id
);
233 void remove_raw(struct dnet_id
&id
, uint64_t cflags
, uint64_t ioflags
);
234 void remove_raw(const std::string
&data
, int type
, uint64_t cflags
, uint64_t ioflags
);
235 void remove(struct dnet_id
&id
);
236 void remove(const std::string
&data
, int type
= EBLOB_TYPE_DATA
);
238 std::string
stat_log();
242 int request_cmd(struct dnet_trans_control
&ctl
);
244 std::string
read_metadata(struct dnet_id
&id
);
246 void update_status(const char *addr
, const int port
, const int family
, struct dnet_node_status
*status
);
247 void update_status(struct dnet_id
&id
, struct dnet_node_status
*status
);
249 std::vector
<std::string
> read_data_range(struct dnet_io_attr
&io
, int group_id
, uint64_t cflags
= 0);
251 std::vector
<struct dnet_io_attr
> remove_data_range(struct dnet_io_attr
&io
, int group_id
, uint64_t cflags
= 0);
253 std::vector
<std::pair
<struct dnet_id
, struct dnet_addr
> > get_routes();
256 * start execution of the given event
258 std::string
exec_locked(struct dnet_id
*id
, const std::string
&event
, const std::string
&data
,
259 const std::string
&binary
);
260 std::string
exec_unlocked(struct dnet_id
*id
, const std::string
&event
, const std::string
&data
,
261 const std::string
&binary
);
264 * execution with saving ID of the original (blocked) caller
266 std::string
push_locked(struct dnet_id
*id
, const struct sph
&sph
,
267 const std::string
&event
, const std::string
&data
, const std::string
&binary
);
268 std::string
push_unlocked(struct dnet_id
*id
, const struct sph
&sph
,
269 const std::string
&event
, const std::string
&data
, const std::string
&binary
);
271 /* send reply back to blocked execution client */
272 void reply(const struct sph
&sph
, const std::string
&event
, const std::string
&data
,
273 const std::string
&binary
);
275 std::vector
<std::string
> bulk_read(const std::vector
<struct dnet_io_attr
> &ios
, uint64_t cflags
= 0);
276 std::vector
<std::string
> bulk_read(const std::vector
<std::string
> &keys
, uint64_t cflags
= 0);
278 std::string
bulk_write(const std::vector
<struct dnet_io_attr
> &ios
,
279 const std::vector
<std::string
> &data
, uint64_t cflags
);
281 struct dnet_node
* get_node();
284 struct dnet_session
*m_session
;
287 std::vector
<int> groups
;
289 std::string
raw_exec(struct dnet_id
*id
,
290 const struct sph
*sph
,
291 const std::string
&event
,
292 const std::string
&data
,
293 const std::string
&binary
,
295 std::string
request(struct dnet_id
*id
, struct sph
*sph
, bool lock
);
299 }}; /* namespace ioremap::elliptics */
301 #endif /* __EDEF_H */