couchbase 1.2.0.beta-x86-mingw32 → 1.2.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/Makefile +3 -0
- data/README.markdown +15 -4
- data/RELEASE_NOTES.markdown +513 -0
- data/couchbase.gemspec +0 -1
- data/ext/couchbase_ext/arguments.c +161 -244
- data/ext/couchbase_ext/arithmetic.c +29 -37
- data/ext/couchbase_ext/bucket.c +252 -219
- data/ext/couchbase_ext/couchbase_ext.c +540 -417
- data/ext/couchbase_ext/couchbase_ext.h +218 -191
- data/ext/couchbase_ext/delete.c +30 -27
- data/ext/couchbase_ext/extconf.rb +15 -3
- data/ext/couchbase_ext/get.c +45 -37
- data/ext/couchbase_ext/http.c +95 -74
- data/ext/couchbase_ext/multithread_plugin.c +1201 -0
- data/ext/couchbase_ext/observe.c +42 -37
- data/ext/couchbase_ext/result.c +17 -20
- data/ext/couchbase_ext/stats.c +30 -28
- data/ext/couchbase_ext/store.c +46 -39
- data/ext/couchbase_ext/timer.c +11 -11
- data/ext/couchbase_ext/touch.c +30 -27
- data/ext/couchbase_ext/unlock.c +30 -27
- data/ext/couchbase_ext/utils.c +166 -89
- data/ext/couchbase_ext/version.c +29 -26
- data/lib/action_dispatch/middleware/session/couchbase_store.rb +2 -2
- data/lib/active_support/cache/couchbase_store.rb +6 -6
- data/lib/couchbase.rb +1 -0
- data/lib/couchbase/bucket.rb +6 -11
- data/lib/couchbase/cluster.rb +105 -0
- data/lib/couchbase/utils.rb +8 -5
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +51 -5
- data/lib/couchbase/view_row.rb +1 -1
- data/lib/ext/multi_json_fix.rb +13 -9
- data/lib/rack/session/couchbase.rb +11 -7
- data/tasks/compile.rake +1 -1
- data/tasks/test.rake +40 -34
- data/tasks/util.rake +1 -1
- data/test/setup.rb +9 -2
- data/test/test_arithmetic.rb +37 -0
- data/test/test_async.rb +22 -18
- data/test/test_unlock.rb +0 -1
- data/test/test_utils.rb +32 -0
- metadata +13 -23
- data/HISTORY.markdown +0 -215
data/couchbase.gemspec
CHANGED
@@ -46,6 +46,5 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_development_dependency 'yard-xml'
|
47
47
|
s.add_development_dependency 'mini_portile'
|
48
48
|
s.add_development_dependency 'yajl-ruby', '~> 1.1.0'
|
49
|
-
s.add_development_dependency RUBY_VERSION =~ /^1\.9/ ? 'debugger' : 'ruby-debug'
|
50
49
|
s.add_development_dependency 'active_support'
|
51
50
|
end
|
@@ -17,32 +17,45 @@
|
|
17
17
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
|
-
|
21
20
|
/* TOUCH */
|
22
21
|
|
22
|
+
#define _alloc_data_for_s(type, _type, size, items, ptr) do {\
|
23
|
+
lcb_size_t ii; \
|
24
|
+
\
|
25
|
+
params->cmd.type.num = size; \
|
26
|
+
params->cmd.type.items = calloc(size, sizeof(_type)); \
|
27
|
+
if (params->cmd.type.items == NULL) { \
|
28
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments"); \
|
29
|
+
} \
|
30
|
+
params->cmd.type.ptr = calloc(size, sizeof(_type *)); \
|
31
|
+
if (params->cmd.type.ptr == NULL) { \
|
32
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments"); \
|
33
|
+
} \
|
34
|
+
for (ii = 0; ii < size; ++ii) { \
|
35
|
+
params->cmd.type.ptr[ii] = params->cmd.type.items + ii; \
|
36
|
+
} \
|
37
|
+
} while(0)
|
38
|
+
|
39
|
+
#define _alloc_data_for(type, _type) _alloc_data_for_s(type, _type, size, items, ptr)
|
40
|
+
|
41
|
+
|
42
|
+
#define _release_data_for_s(type, items, ptr) \
|
43
|
+
free(params->cmd.type.items); \
|
44
|
+
free(params->cmd.type.ptr);
|
45
|
+
|
46
|
+
#define _release_data_for(type) _release_data_for_s(type, items, ptr)
|
47
|
+
|
48
|
+
|
23
49
|
static void
|
24
|
-
cb_params_touch_alloc(struct
|
50
|
+
cb_params_touch_alloc(struct cb_params_st *params, lcb_size_t size)
|
25
51
|
{
|
26
|
-
|
27
|
-
|
28
|
-
params->cmd.touch.num = size;
|
29
|
-
params->cmd.touch.items = xcalloc(size, sizeof(lcb_touch_cmd_t));
|
30
|
-
if (params->cmd.touch.items == NULL) {
|
31
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
32
|
-
}
|
33
|
-
params->cmd.touch.ptr = xcalloc(size, sizeof(lcb_touch_cmd_t *));
|
34
|
-
if (params->cmd.touch.ptr == NULL) {
|
35
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
36
|
-
}
|
37
|
-
for (ii = 0; ii < size; ++ii) {
|
38
|
-
params->cmd.touch.ptr[ii] = params->cmd.touch.items + ii;
|
39
|
-
}
|
52
|
+
_alloc_data_for(touch, lcb_touch_cmd_t);
|
40
53
|
}
|
41
54
|
|
42
55
|
static void
|
43
|
-
cb_params_touch_init_item(struct
|
56
|
+
cb_params_touch_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj, lcb_time_t exptime)
|
44
57
|
{
|
45
|
-
key_obj =
|
58
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
46
59
|
params->cmd.touch.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
47
60
|
params->cmd.touch.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
48
61
|
params->cmd.touch.items[idx].v.v0.exptime = exptime;
|
@@ -52,30 +65,31 @@ cb_params_touch_init_item(struct params_st *params, lcb_size_t idx, VALUE key_ob
|
|
52
65
|
static int
|
53
66
|
cb_params_touch_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
54
67
|
{
|
55
|
-
struct
|
68
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
56
69
|
cb_params_touch_init_item(params, params->idx++, key, NUM2ULONG(value));
|
57
70
|
return ST_CONTINUE;
|
58
71
|
}
|
59
72
|
|
60
73
|
static void
|
61
|
-
cb_params_touch_parse_options(struct
|
74
|
+
cb_params_touch_parse_options(struct cb_params_st *params, VALUE options)
|
62
75
|
{
|
63
76
|
VALUE tmp;
|
64
77
|
|
65
78
|
if (NIL_P(options)) {
|
66
79
|
return;
|
67
80
|
}
|
68
|
-
tmp = rb_hash_aref(options,
|
81
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
69
82
|
if (tmp != Qnil) {
|
70
83
|
params->cmd.touch.ttl = NUM2ULONG(tmp);
|
71
84
|
}
|
72
|
-
|
73
|
-
|
85
|
+
tmp = rb_hash_lookup2(options, cb_sym_quiet, Qundef);
|
86
|
+
if (tmp != Qundef) {
|
87
|
+
params->cmd.touch.quiet = RTEST(tmp);
|
74
88
|
}
|
75
89
|
}
|
76
90
|
|
77
91
|
static void
|
78
|
-
cb_params_touch_parse_arguments(struct
|
92
|
+
cb_params_touch_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
79
93
|
{
|
80
94
|
lcb_size_t ii;
|
81
95
|
|
@@ -117,28 +131,15 @@ cb_params_touch_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
117
131
|
/* REMOVE */
|
118
132
|
|
119
133
|
static void
|
120
|
-
cb_params_remove_alloc(struct
|
134
|
+
cb_params_remove_alloc(struct cb_params_st *params, lcb_size_t size)
|
121
135
|
{
|
122
|
-
|
123
|
-
|
124
|
-
params->cmd.remove.num = size;
|
125
|
-
params->cmd.remove.items = xcalloc(size, sizeof(lcb_remove_cmd_t));
|
126
|
-
if (params->cmd.remove.items == NULL) {
|
127
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
128
|
-
}
|
129
|
-
params->cmd.remove.ptr = xcalloc(size, sizeof(lcb_remove_cmd_t *));
|
130
|
-
if (params->cmd.remove.ptr == NULL) {
|
131
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
132
|
-
}
|
133
|
-
for (ii = 0; ii < size; ++ii) {
|
134
|
-
params->cmd.remove.ptr[ii] = params->cmd.remove.items + ii;
|
135
|
-
}
|
136
|
+
_alloc_data_for(remove, lcb_remove_cmd_t);
|
136
137
|
}
|
137
138
|
|
138
139
|
static void
|
139
|
-
cb_params_remove_init_item(struct
|
140
|
+
cb_params_remove_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj, lcb_cas_t cas)
|
140
141
|
{
|
141
|
-
key_obj =
|
142
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
142
143
|
params->cmd.remove.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
143
144
|
params->cmd.remove.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
144
145
|
params->cmd.remove.items[idx].v.v0.cas = cas;
|
@@ -148,30 +149,31 @@ cb_params_remove_init_item(struct params_st *params, lcb_size_t idx, VALUE key_o
|
|
148
149
|
static int
|
149
150
|
cb_params_remove_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
150
151
|
{
|
151
|
-
struct
|
152
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
152
153
|
cb_params_remove_init_item(params, params->idx++, key, NUM2ULL(value));
|
153
154
|
return ST_CONTINUE;
|
154
155
|
}
|
155
156
|
|
156
157
|
static void
|
157
|
-
cb_params_remove_parse_options(struct
|
158
|
+
cb_params_remove_parse_options(struct cb_params_st *params, VALUE options)
|
158
159
|
{
|
159
160
|
VALUE tmp;
|
160
161
|
|
161
162
|
if (NIL_P(options)) {
|
162
163
|
return;
|
163
164
|
}
|
164
|
-
|
165
|
-
|
165
|
+
tmp = rb_hash_lookup2(options, cb_sym_quiet, Qundef);
|
166
|
+
if (tmp != Qundef) {
|
167
|
+
params->cmd.remove.quiet = RTEST(tmp);
|
166
168
|
}
|
167
|
-
tmp = rb_hash_aref(options,
|
169
|
+
tmp = rb_hash_aref(options, cb_sym_cas);
|
168
170
|
if (tmp != Qnil) {
|
169
171
|
params->cmd.remove.cas = NUM2ULL(tmp);
|
170
172
|
}
|
171
173
|
}
|
172
174
|
|
173
175
|
static void
|
174
|
-
cb_params_remove_parse_arguments(struct
|
176
|
+
cb_params_remove_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
175
177
|
{
|
176
178
|
lcb_size_t ii;
|
177
179
|
|
@@ -212,33 +214,30 @@ cb_params_remove_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
212
214
|
|
213
215
|
/* STORE */
|
214
216
|
static void
|
215
|
-
cb_params_store_alloc(struct
|
217
|
+
cb_params_store_alloc(struct cb_params_st *params, lcb_size_t size)
|
216
218
|
{
|
217
|
-
|
218
|
-
|
219
|
-
params->cmd.store.num = size;
|
220
|
-
params->cmd.store.items = xcalloc(size, sizeof(lcb_store_cmd_t));
|
221
|
-
if (params->cmd.store.items == NULL) {
|
222
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
223
|
-
}
|
224
|
-
params->cmd.store.ptr = xcalloc(size, sizeof(lcb_store_cmd_t *));
|
225
|
-
if (params->cmd.store.ptr == NULL) {
|
226
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
227
|
-
}
|
228
|
-
for (ii = 0; ii < size; ++ii) {
|
229
|
-
params->cmd.store.ptr[ii] = params->cmd.store.items + ii;
|
230
|
-
}
|
219
|
+
_alloc_data_for(store, lcb_store_cmd_t);
|
231
220
|
}
|
232
221
|
|
233
222
|
static void
|
234
|
-
cb_params_store_init_item(struct
|
223
|
+
cb_params_store_init_item(struct cb_params_st *params, lcb_size_t idx,
|
235
224
|
VALUE key_obj, VALUE value_obj, lcb_uint32_t flags, lcb_cas_t cas,
|
236
225
|
lcb_time_t exptime)
|
237
226
|
{
|
238
|
-
key_obj =
|
239
|
-
value_obj =
|
240
|
-
if (value_obj
|
241
|
-
|
227
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
228
|
+
value_obj = cb_encode_value(value_obj, params->cmd.store.flags);
|
229
|
+
if (rb_obj_is_kind_of(value_obj, rb_eStandardError)) {
|
230
|
+
VALUE exc_str = rb_funcall(value_obj, cb_id_to_s, 0);
|
231
|
+
VALUE msg = rb_funcall(rb_mKernel, cb_id_sprintf, 3,
|
232
|
+
rb_str_new2("unable to convert value for key '%s': %s"), key_obj, exc_str);
|
233
|
+
VALUE exc = rb_exc_new3(cb_eValueFormatError, msg);
|
234
|
+
rb_ivar_set(exc, cb_id_iv_inner_exception, value_obj);
|
235
|
+
rb_exc_raise(exc);
|
236
|
+
}
|
237
|
+
/* the value must be string after conversion */
|
238
|
+
if (TYPE(value_obj) != T_STRING) {
|
239
|
+
VALUE val = rb_any_to_s(value_obj);
|
240
|
+
rb_raise(cb_eValueFormatError, "unable to convert value for key '%s' to string: %s", RSTRING_PTR(key_obj), RSTRING_PTR(val));
|
242
241
|
}
|
243
242
|
params->cmd.store.items[idx].v.v0.datatype = params->cmd.store.datatype;
|
244
243
|
params->cmd.store.items[idx].v.v0.operation = params->cmd.store.operation;
|
@@ -255,50 +254,50 @@ cb_params_store_init_item(struct params_st *params, lcb_size_t idx,
|
|
255
254
|
static int
|
256
255
|
cb_params_store_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
257
256
|
{
|
258
|
-
struct
|
257
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
259
258
|
cb_params_store_init_item(params, params->idx++, key, value,
|
260
259
|
params->cmd.store.flags, 0, params->cmd.store.ttl);
|
261
260
|
return ST_CONTINUE;
|
262
261
|
}
|
263
262
|
|
264
263
|
static void
|
265
|
-
cb_params_store_parse_options(struct
|
264
|
+
cb_params_store_parse_options(struct cb_params_st *params, VALUE options)
|
266
265
|
{
|
267
266
|
VALUE tmp;
|
268
267
|
|
269
268
|
if (NIL_P(options)) {
|
270
269
|
return;
|
271
270
|
}
|
272
|
-
tmp = rb_hash_aref(options,
|
271
|
+
tmp = rb_hash_aref(options, cb_sym_flags);
|
273
272
|
if (tmp != Qnil) {
|
274
273
|
params->cmd.store.flags = (lcb_uint32_t)NUM2ULONG(tmp);
|
275
274
|
}
|
276
|
-
tmp = rb_hash_aref(options,
|
275
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
277
276
|
if (tmp != Qnil) { /* rewrite format bits */
|
278
|
-
params->cmd.store.flags =
|
277
|
+
params->cmd.store.flags = cb_flags_set_format(params->cmd.store.flags, tmp);
|
279
278
|
}
|
280
|
-
tmp = rb_hash_aref(options,
|
279
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
281
280
|
if (tmp != Qnil) {
|
282
281
|
params->cmd.store.ttl = NUM2ULONG(tmp);
|
283
282
|
}
|
284
|
-
tmp = rb_hash_aref(options,
|
283
|
+
tmp = rb_hash_aref(options, cb_sym_cas);
|
285
284
|
if (tmp != Qnil) {
|
286
285
|
params->cmd.store.cas = NUM2ULL(tmp);
|
287
286
|
}
|
288
|
-
tmp = rb_hash_aref(options,
|
287
|
+
tmp = rb_hash_aref(options, cb_sym_observe);
|
289
288
|
if (tmp != Qnil) {
|
290
289
|
Check_Type(tmp, T_HASH);
|
291
|
-
rb_funcall(params->bucket->self,
|
290
|
+
rb_funcall(params->bucket->self, cb_id_verify_observe_options, 1, tmp);
|
292
291
|
params->cmd.store.observe = tmp;
|
293
292
|
}
|
294
|
-
if (
|
293
|
+
if (cb_flags_get_format(params->cmd.store.flags) == cb_sym_document) {
|
295
294
|
/* just amend datatype for now */
|
296
295
|
params->cmd.store.datatype = 0x01;
|
297
296
|
}
|
298
297
|
}
|
299
298
|
|
300
299
|
static void
|
301
|
-
cb_params_store_parse_arguments(struct
|
300
|
+
cb_params_store_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
302
301
|
{
|
303
302
|
VALUE keys;
|
304
303
|
|
@@ -334,43 +333,20 @@ cb_params_store_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
334
333
|
|
335
334
|
/* GET */
|
336
335
|
static void
|
337
|
-
cb_params_get_alloc(struct
|
336
|
+
cb_params_get_alloc(struct cb_params_st *params, lcb_size_t size)
|
338
337
|
{
|
339
|
-
lcb_size_t ii;
|
340
|
-
|
341
|
-
params->cmd.get.num = size;
|
342
338
|
if (params->cmd.get.replica) {
|
343
|
-
|
344
|
-
if (params->cmd.get.items_gr == NULL) {
|
345
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
346
|
-
}
|
347
|
-
params->cmd.get.ptr = xcalloc(size, sizeof(lcb_get_replica_cmd_t *));
|
348
|
-
if (params->cmd.get.ptr_gr == NULL) {
|
349
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
350
|
-
}
|
351
|
-
for (ii = 0; ii < size; ++ii) {
|
352
|
-
params->cmd.get.ptr_gr[ii] = params->cmd.get.items_gr + ii;
|
353
|
-
}
|
339
|
+
_alloc_data_for_s(get, lcb_get_replica_cmd_t, size, items_gr, ptr_gr);
|
354
340
|
} else {
|
355
|
-
|
356
|
-
if (params->cmd.get.items == NULL) {
|
357
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
358
|
-
}
|
359
|
-
params->cmd.get.ptr = xcalloc(size, sizeof(lcb_get_cmd_t *));
|
360
|
-
if (params->cmd.get.ptr == NULL) {
|
361
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
362
|
-
}
|
363
|
-
for (ii = 0; ii < size; ++ii) {
|
364
|
-
params->cmd.get.ptr[ii] = params->cmd.get.items + ii;
|
365
|
-
}
|
341
|
+
_alloc_data_for(get, lcb_get_cmd_t);
|
366
342
|
}
|
367
343
|
}
|
368
344
|
|
369
345
|
static void
|
370
|
-
cb_params_get_init_item(struct
|
346
|
+
cb_params_get_init_item(struct cb_params_st *params, lcb_size_t idx,
|
371
347
|
VALUE key_obj, lcb_time_t exptime)
|
372
348
|
{
|
373
|
-
key_obj =
|
349
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
374
350
|
if (params->cmd.get.replica) {
|
375
351
|
params->cmd.get.items_gr[idx].v.v0.key = RSTRING_PTR(key_obj);
|
376
352
|
params->cmd.get.items_gr[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
@@ -387,37 +363,38 @@ cb_params_get_init_item(struct params_st *params, lcb_size_t idx,
|
|
387
363
|
static int
|
388
364
|
cb_params_get_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
389
365
|
{
|
390
|
-
struct
|
366
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
391
367
|
rb_ary_push(params->cmd.get.keys_ary, key);
|
392
368
|
cb_params_get_init_item(params, params->idx++, key, NUM2ULONG(value));
|
393
369
|
return ST_CONTINUE;
|
394
370
|
}
|
395
371
|
|
396
372
|
static void
|
397
|
-
cb_params_get_parse_options(struct
|
373
|
+
cb_params_get_parse_options(struct cb_params_st *params, VALUE options)
|
398
374
|
{
|
399
375
|
VALUE tmp;
|
400
376
|
|
401
377
|
if (NIL_P(options)) {
|
402
378
|
return;
|
403
379
|
}
|
404
|
-
params->cmd.get.replica = RTEST(rb_hash_aref(options,
|
405
|
-
params->cmd.get.extended = RTEST(rb_hash_aref(options,
|
406
|
-
params->cmd.get.assemble_hash = RTEST(rb_hash_aref(options,
|
407
|
-
|
408
|
-
|
380
|
+
params->cmd.get.replica = RTEST(rb_hash_aref(options, cb_sym_replica));
|
381
|
+
params->cmd.get.extended = RTEST(rb_hash_aref(options, cb_sym_extended));
|
382
|
+
params->cmd.get.assemble_hash = RTEST(rb_hash_aref(options, cb_sym_assemble_hash));
|
383
|
+
tmp = rb_hash_lookup2(options, cb_sym_quiet, Qundef);
|
384
|
+
if (tmp != Qundef) {
|
385
|
+
params->cmd.get.quiet = RTEST(tmp);
|
409
386
|
}
|
410
|
-
tmp = rb_hash_aref(options,
|
387
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
411
388
|
if (tmp != Qnil) {
|
412
389
|
Check_Type(tmp, T_SYMBOL);
|
413
390
|
params->cmd.get.forced_format = tmp;
|
414
391
|
}
|
415
|
-
tmp = rb_hash_aref(options,
|
392
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
416
393
|
if (tmp != Qnil) {
|
417
394
|
params->cmd.get.ttl = NUM2ULONG(tmp);
|
418
395
|
}
|
419
396
|
/* boolean or number of seconds to lock */
|
420
|
-
tmp = rb_hash_aref(options,
|
397
|
+
tmp = rb_hash_aref(options, cb_sym_lock);
|
421
398
|
if (tmp != Qnil) {
|
422
399
|
params->cmd.get.lock = RTEST(tmp);
|
423
400
|
if (TYPE(tmp) == T_FIXNUM) {
|
@@ -427,7 +404,7 @@ cb_params_get_parse_options(struct params_st *params, VALUE options)
|
|
427
404
|
}
|
428
405
|
|
429
406
|
static void
|
430
|
-
cb_params_get_parse_arguments(struct
|
407
|
+
cb_params_get_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
431
408
|
{
|
432
409
|
lcb_size_t ii;
|
433
410
|
|
@@ -474,29 +451,16 @@ cb_params_get_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
474
451
|
|
475
452
|
/* ARITH */
|
476
453
|
static void
|
477
|
-
cb_params_arith_alloc(struct
|
454
|
+
cb_params_arith_alloc(struct cb_params_st *params, lcb_size_t size)
|
478
455
|
{
|
479
|
-
|
480
|
-
|
481
|
-
params->cmd.arith.num = size;
|
482
|
-
params->cmd.arith.items = xcalloc(size, sizeof(lcb_arithmetic_cmd_t));
|
483
|
-
if (params->cmd.arith.items == NULL) {
|
484
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
485
|
-
}
|
486
|
-
params->cmd.arith.ptr = xcalloc(size, sizeof(lcb_arithmetic_cmd_t *));
|
487
|
-
if (params->cmd.arith.ptr == NULL) {
|
488
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
489
|
-
}
|
490
|
-
for (ii = 0; ii < size; ++ii) {
|
491
|
-
params->cmd.arith.ptr[ii] = params->cmd.arith.items + ii;
|
492
|
-
}
|
456
|
+
_alloc_data_for(arith, lcb_arithmetic_cmd_t);
|
493
457
|
}
|
494
458
|
|
495
459
|
static void
|
496
|
-
cb_params_arith_init_item(struct
|
460
|
+
cb_params_arith_init_item(struct cb_params_st *params, lcb_size_t idx,
|
497
461
|
VALUE key_obj, lcb_int64_t delta)
|
498
462
|
{
|
499
|
-
key_obj =
|
463
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
500
464
|
params->cmd.arith.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
501
465
|
params->cmd.arith.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
502
466
|
params->cmd.arith.items[idx].v.v0.delta = delta * params->cmd.arith.sign;
|
@@ -509,46 +473,49 @@ cb_params_arith_init_item(struct params_st *params, lcb_size_t idx,
|
|
509
473
|
static int
|
510
474
|
cb_params_arith_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
511
475
|
{
|
512
|
-
struct
|
476
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
513
477
|
cb_params_arith_init_item(params, params->idx++, key, NUM2ULONG(value) & INT64_MAX);
|
514
478
|
return ST_CONTINUE;
|
515
479
|
}
|
516
480
|
|
517
481
|
static void
|
518
|
-
cb_params_arith_parse_options(struct
|
482
|
+
cb_params_arith_parse_options(struct cb_params_st *params, VALUE options)
|
519
483
|
{
|
520
484
|
VALUE tmp;
|
521
485
|
|
522
486
|
if (NIL_P(options)) {
|
523
487
|
return;
|
524
488
|
}
|
525
|
-
|
526
|
-
|
527
|
-
|
489
|
+
tmp = rb_hash_aref(options, cb_sym_create);
|
490
|
+
if (tmp != Qnil) {
|
491
|
+
params->cmd.arith.create = RTEST(tmp);
|
492
|
+
}
|
493
|
+
params->cmd.arith.extended = RTEST(rb_hash_aref(options, cb_sym_extended));
|
494
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
528
495
|
if (tmp != Qnil) {
|
529
496
|
params->cmd.arith.ttl = NUM2ULONG(tmp);
|
530
497
|
}
|
531
|
-
tmp = rb_hash_aref(options,
|
498
|
+
tmp = rb_hash_aref(options, cb_sym_initial);
|
532
499
|
if (tmp != Qnil) {
|
533
500
|
params->cmd.arith.initial = NUM2ULL(tmp);
|
534
501
|
params->cmd.arith.create = 1;
|
535
502
|
}
|
536
|
-
tmp = rb_hash_aref(options,
|
503
|
+
tmp = rb_hash_aref(options, cb_sym_delta);
|
537
504
|
if (tmp != Qnil) {
|
538
505
|
params->cmd.arith.delta = NUM2ULL(tmp) & INT64_MAX;
|
539
506
|
}
|
540
|
-
tmp = rb_hash_aref(options,
|
507
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
541
508
|
if (tmp != Qnil) { /* rewrite format bits */
|
542
509
|
params->cmd.arith.format = tmp;
|
543
510
|
}
|
544
|
-
if (params->cmd.arith.format ==
|
511
|
+
if (params->cmd.arith.format == cb_sym_document) {
|
545
512
|
/* just amend datatype for now */
|
546
513
|
params->cmd.arith.datatype = 0x01;
|
547
514
|
}
|
548
515
|
}
|
549
516
|
|
550
517
|
static void
|
551
|
-
cb_params_arith_parse_arguments(struct
|
518
|
+
cb_params_arith_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
552
519
|
{
|
553
520
|
lcb_size_t ii;
|
554
521
|
|
@@ -588,36 +555,23 @@ cb_params_arith_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
588
555
|
|
589
556
|
/* STATS */
|
590
557
|
static void
|
591
|
-
cb_params_stats_alloc(struct
|
558
|
+
cb_params_stats_alloc(struct cb_params_st *params, lcb_size_t size)
|
592
559
|
{
|
593
|
-
|
594
|
-
|
595
|
-
params->cmd.stats.num = size;
|
596
|
-
params->cmd.stats.items = xcalloc(size, sizeof(lcb_server_stats_cmd_t));
|
597
|
-
if (params->cmd.stats.items == NULL) {
|
598
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
599
|
-
}
|
600
|
-
params->cmd.stats.ptr = xcalloc(size, sizeof(lcb_server_stats_cmd_t *));
|
601
|
-
if (params->cmd.stats.ptr == NULL) {
|
602
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
603
|
-
}
|
604
|
-
for (ii = 0; ii < size; ++ii) {
|
605
|
-
params->cmd.stats.ptr[ii] = params->cmd.stats.items + ii;
|
606
|
-
}
|
560
|
+
_alloc_data_for(stats, lcb_server_stats_cmd_t);
|
607
561
|
}
|
608
562
|
|
609
563
|
static void
|
610
|
-
cb_params_stats_init_item(struct
|
564
|
+
cb_params_stats_init_item(struct cb_params_st *params, lcb_size_t idx,
|
611
565
|
VALUE key_obj)
|
612
566
|
{
|
613
|
-
key_obj =
|
567
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
614
568
|
params->cmd.stats.items[idx].v.v0.name = RSTRING_PTR(key_obj);
|
615
569
|
params->cmd.stats.items[idx].v.v0.nname = RSTRING_LEN(key_obj);
|
616
570
|
params->npayload += RSTRING_LEN(key_obj);
|
617
571
|
}
|
618
572
|
|
619
573
|
static void
|
620
|
-
cb_params_stats_parse_arguments(struct
|
574
|
+
cb_params_stats_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
621
575
|
{
|
622
576
|
lcb_size_t ii;
|
623
577
|
|
@@ -653,35 +607,22 @@ cb_params_stats_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
653
607
|
/* REMOVE */
|
654
608
|
|
655
609
|
static void
|
656
|
-
cb_params_observe_alloc(struct
|
610
|
+
cb_params_observe_alloc(struct cb_params_st *params, lcb_size_t size)
|
657
611
|
{
|
658
|
-
|
659
|
-
|
660
|
-
params->cmd.observe.num = size;
|
661
|
-
params->cmd.observe.items = xcalloc(size, sizeof(lcb_observe_cmd_t));
|
662
|
-
if (params->cmd.observe.items == NULL) {
|
663
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
664
|
-
}
|
665
|
-
params->cmd.observe.ptr = xcalloc(size, sizeof(lcb_observe_cmd_t *));
|
666
|
-
if (params->cmd.observe.ptr == NULL) {
|
667
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
668
|
-
}
|
669
|
-
for (ii = 0; ii < size; ++ii) {
|
670
|
-
params->cmd.observe.ptr[ii] = params->cmd.observe.items + ii;
|
671
|
-
}
|
612
|
+
_alloc_data_for(observe, lcb_observe_cmd_t);
|
672
613
|
}
|
673
614
|
|
674
615
|
static void
|
675
|
-
cb_params_observe_init_item(struct
|
616
|
+
cb_params_observe_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj)
|
676
617
|
{
|
677
|
-
key_obj =
|
618
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
678
619
|
params->cmd.observe.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
679
620
|
params->cmd.observe.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
680
621
|
params->npayload += RSTRING_LEN(key_obj);
|
681
622
|
}
|
682
623
|
|
683
624
|
static void
|
684
|
-
cb_params_observe_parse_arguments(struct
|
625
|
+
cb_params_observe_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
685
626
|
{
|
686
627
|
lcb_size_t ii;
|
687
628
|
|
@@ -716,28 +657,15 @@ cb_params_observe_parse_arguments(struct params_st *params, int argc, VALUE argv
|
|
716
657
|
|
717
658
|
/* UNLOCK */
|
718
659
|
static void
|
719
|
-
cb_params_unlock_alloc(struct
|
660
|
+
cb_params_unlock_alloc(struct cb_params_st *params, lcb_size_t size)
|
720
661
|
{
|
721
|
-
|
722
|
-
|
723
|
-
params->cmd.unlock.num = size;
|
724
|
-
params->cmd.unlock.items = xcalloc(size, sizeof(lcb_unlock_cmd_t));
|
725
|
-
if (params->cmd.unlock.items == NULL) {
|
726
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
727
|
-
}
|
728
|
-
params->cmd.unlock.ptr = xcalloc(size, sizeof(lcb_unlock_cmd_t *));
|
729
|
-
if (params->cmd.unlock.ptr == NULL) {
|
730
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
731
|
-
}
|
732
|
-
for (ii = 0; ii < size; ++ii) {
|
733
|
-
params->cmd.unlock.ptr[ii] = params->cmd.unlock.items + ii;
|
734
|
-
}
|
662
|
+
_alloc_data_for(unlock, lcb_unlock_cmd_t);
|
735
663
|
}
|
736
664
|
|
737
665
|
static void
|
738
|
-
cb_params_unlock_init_item(struct
|
666
|
+
cb_params_unlock_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj, lcb_cas_t cas)
|
739
667
|
{
|
740
|
-
key_obj =
|
668
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
741
669
|
params->cmd.unlock.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
742
670
|
params->cmd.unlock.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
743
671
|
params->cmd.unlock.items[idx].v.v0.cas = cas;
|
@@ -747,30 +675,31 @@ cb_params_unlock_init_item(struct params_st *params, lcb_size_t idx, VALUE key_o
|
|
747
675
|
static int
|
748
676
|
cb_params_unlock_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
749
677
|
{
|
750
|
-
struct
|
678
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
751
679
|
cb_params_unlock_init_item(params, params->idx++, key, NUM2ULL(value));
|
752
680
|
return ST_CONTINUE;
|
753
681
|
}
|
754
682
|
|
755
683
|
static void
|
756
|
-
cb_params_unlock_parse_options(struct
|
684
|
+
cb_params_unlock_parse_options(struct cb_params_st *params, VALUE options)
|
757
685
|
{
|
758
686
|
VALUE tmp;
|
759
687
|
|
760
688
|
if (NIL_P(options)) {
|
761
689
|
return;
|
762
690
|
}
|
763
|
-
tmp = rb_hash_aref(options,
|
691
|
+
tmp = rb_hash_aref(options, cb_sym_cas);
|
764
692
|
if (tmp != Qnil) {
|
765
693
|
params->cmd.unlock.cas = NUM2ULL(tmp);
|
766
694
|
}
|
767
|
-
|
768
|
-
|
695
|
+
tmp = rb_hash_lookup2(options, cb_sym_quiet, Qundef);
|
696
|
+
if (tmp != Qundef) {
|
697
|
+
params->cmd.unlock.quiet = RTEST(tmp);
|
769
698
|
}
|
770
699
|
}
|
771
700
|
|
772
701
|
static void
|
773
|
-
cb_params_unlock_parse_arguments(struct
|
702
|
+
cb_params_unlock_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
774
703
|
{
|
775
704
|
if (argc == 1) {
|
776
705
|
VALUE keys = RARRAY_PTR(argv)[0];
|
@@ -793,66 +722,52 @@ cb_params_unlock_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
793
722
|
|
794
723
|
/* VERSION */
|
795
724
|
static void
|
796
|
-
cb_params_version_alloc(struct
|
725
|
+
cb_params_version_alloc(struct cb_params_st *params)
|
797
726
|
{
|
798
727
|
params->cmd.version.num = 1;
|
799
|
-
|
800
|
-
if (params->cmd.version.items == NULL) {
|
801
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
802
|
-
}
|
803
|
-
params->cmd.version.ptr = xcalloc(1, sizeof(lcb_server_version_cmd_t *));
|
804
|
-
if (params->cmd.version.ptr == NULL) {
|
805
|
-
rb_raise(eClientNoMemoryError, "failed to allocate memory for arguments");
|
806
|
-
}
|
807
|
-
params->cmd.version.ptr[0] = params->cmd.version.items;
|
728
|
+
_alloc_data_for_s(version, lcb_server_version_cmd_t, 1, items, ptr);
|
808
729
|
}
|
809
730
|
|
810
731
|
|
811
732
|
/* common stuff */
|
812
733
|
void
|
813
|
-
cb_params_destroy(struct
|
734
|
+
cb_params_destroy(struct cb_params_st *params)
|
814
735
|
{
|
815
|
-
#define _release_data_for(type) \
|
816
|
-
xfree(params->cmd.type.items); \
|
817
|
-
xfree(params->cmd.type.ptr);
|
818
|
-
|
819
736
|
switch (params->type) {
|
820
|
-
case
|
737
|
+
case cb_cmd_get:
|
821
738
|
_release_data_for(get);
|
822
|
-
|
823
|
-
xfree(params->cmd.get.ptr_gr);
|
739
|
+
_release_data_for_s(get, items_gr, ptr_gr);
|
824
740
|
break;
|
825
|
-
case
|
741
|
+
case cb_cmd_touch:
|
826
742
|
_release_data_for(touch);
|
827
743
|
break;
|
828
|
-
case
|
744
|
+
case cb_cmd_arith:
|
829
745
|
_release_data_for(arith);
|
830
746
|
break;
|
831
|
-
case
|
747
|
+
case cb_cmd_remove:
|
832
748
|
_release_data_for(remove);
|
833
749
|
break;
|
834
|
-
case
|
750
|
+
case cb_cmd_store:
|
835
751
|
_release_data_for(store);
|
836
752
|
break;
|
837
|
-
case
|
753
|
+
case cb_cmd_stats:
|
838
754
|
_release_data_for(stats);
|
839
755
|
break;
|
840
|
-
case
|
756
|
+
case cb_cmd_version:
|
841
757
|
_release_data_for(version);
|
842
758
|
break;
|
843
|
-
case
|
759
|
+
case cb_cmd_observe:
|
844
760
|
_release_data_for(observe);
|
845
761
|
break;
|
846
|
-
case
|
762
|
+
case cb_cmd_unlock:
|
847
763
|
_release_data_for(unlock);
|
848
764
|
break;
|
849
765
|
}
|
850
|
-
#undef _release_data_for
|
851
766
|
}
|
852
767
|
|
853
768
|
struct build_params_st
|
854
769
|
{
|
855
|
-
struct
|
770
|
+
struct cb_params_st *params;
|
856
771
|
int argc;
|
857
772
|
VALUE argv;
|
858
773
|
};
|
@@ -863,7 +778,7 @@ do_params_build(VALUE ptr)
|
|
863
778
|
VALUE opts;
|
864
779
|
/* unpack arguments */
|
865
780
|
struct build_params_st *p = (struct build_params_st *)ptr;
|
866
|
-
struct
|
781
|
+
struct cb_params_st *params = p->params;
|
867
782
|
int argc = p->argc;
|
868
783
|
VALUE argv = p->argv;
|
869
784
|
|
@@ -875,15 +790,15 @@ do_params_build(VALUE ptr)
|
|
875
790
|
opts = Qnil;
|
876
791
|
}
|
877
792
|
|
878
|
-
params->npayload =
|
793
|
+
params->npayload = CB_PACKET_HEADER_SIZE; /* size of packet header */
|
879
794
|
switch (params->type) {
|
880
|
-
case
|
795
|
+
case cb_cmd_touch:
|
881
796
|
params->cmd.touch.quiet = params->bucket->quiet;
|
882
797
|
params->cmd.touch.ttl = params->bucket->default_ttl;
|
883
798
|
cb_params_touch_parse_options(params, opts);
|
884
799
|
cb_params_touch_parse_arguments(params, argc, argv);
|
885
800
|
break;
|
886
|
-
case
|
801
|
+
case cb_cmd_remove:
|
887
802
|
params->cmd.remove.quiet = params->bucket->quiet;
|
888
803
|
if (argc == 2) {
|
889
804
|
int type = TYPE(RARRAY_PTR(argv)[1]);
|
@@ -896,7 +811,7 @@ do_params_build(VALUE ptr)
|
|
896
811
|
cb_params_remove_parse_options(params, opts);
|
897
812
|
cb_params_remove_parse_arguments(params, argc, argv);
|
898
813
|
break;
|
899
|
-
case
|
814
|
+
case cb_cmd_store:
|
900
815
|
if (argc == 1 && opts != Qnil) {
|
901
816
|
/* put last hash back because it is the value */
|
902
817
|
rb_ary_push(argv, opts);
|
@@ -905,18 +820,20 @@ do_params_build(VALUE ptr)
|
|
905
820
|
}
|
906
821
|
params->cmd.store.datatype = 0x00;
|
907
822
|
params->cmd.store.ttl = params->bucket->default_ttl;
|
908
|
-
params->cmd.store.flags =
|
823
|
+
params->cmd.store.flags = cb_flags_set_format(params->bucket->default_flags,
|
909
824
|
params->bucket->default_format);
|
910
825
|
params->cmd.store.observe = Qnil;
|
911
826
|
cb_params_store_parse_options(params, opts);
|
912
827
|
cb_params_store_parse_arguments(params, argc, argv);
|
913
828
|
break;
|
914
|
-
case
|
829
|
+
case cb_cmd_get:
|
915
830
|
params->cmd.get.quiet = params->bucket->quiet;
|
916
831
|
cb_params_get_parse_options(params, opts);
|
917
832
|
cb_params_get_parse_arguments(params, argc, argv);
|
918
833
|
break;
|
919
|
-
case
|
834
|
+
case cb_cmd_arith:
|
835
|
+
params->cmd.arith.create = params->bucket->default_arith_create;
|
836
|
+
params->cmd.arith.initial = params->bucket->default_arith_init;
|
920
837
|
params->cmd.arith.delta = 1;
|
921
838
|
params->cmd.arith.format = params->bucket->default_format;
|
922
839
|
params->cmd.arith.ttl = params->bucket->default_ttl;
|
@@ -928,16 +845,16 @@ do_params_build(VALUE ptr)
|
|
928
845
|
cb_params_arith_parse_options(params, opts);
|
929
846
|
cb_params_arith_parse_arguments(params, argc, argv);
|
930
847
|
break;
|
931
|
-
case
|
848
|
+
case cb_cmd_stats:
|
932
849
|
cb_params_stats_parse_arguments(params, argc, argv);
|
933
850
|
break;
|
934
|
-
case
|
851
|
+
case cb_cmd_version:
|
935
852
|
cb_params_version_alloc(params);
|
936
853
|
break;
|
937
|
-
case
|
854
|
+
case cb_cmd_observe:
|
938
855
|
cb_params_observe_parse_arguments(params, argc, argv);
|
939
856
|
break;
|
940
|
-
case
|
857
|
+
case cb_cmd_unlock:
|
941
858
|
params->cmd.unlock.quiet = params->bucket->quiet;
|
942
859
|
if (argc == 2) {
|
943
860
|
int type = TYPE(RARRAY_PTR(argv)[1]);
|
@@ -956,7 +873,7 @@ do_params_build(VALUE ptr)
|
|
956
873
|
}
|
957
874
|
|
958
875
|
void
|
959
|
-
cb_params_build(struct
|
876
|
+
cb_params_build(struct cb_params_st *params, int argc, VALUE argv)
|
960
877
|
{
|
961
878
|
int fail = 0;
|
962
879
|
struct build_params_st args;
|