couchbase 1.2.0.z.beta4 → 1.2.0.z.beta5
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.markdown +9 -0
- data/ext/couchbase_ext/arguments.c +132 -128
- data/ext/couchbase_ext/arithmetic.c +25 -22
- data/ext/couchbase_ext/bucket.c +147 -114
- data/ext/couchbase_ext/couchbase_ext.c +419 -399
- data/ext/couchbase_ext/couchbase_ext.h +195 -189
- data/ext/couchbase_ext/delete.c +22 -19
- data/ext/couchbase_ext/extconf.rb +9 -2
- data/ext/couchbase_ext/get.c +32 -29
- data/ext/couchbase_ext/http.c +73 -59
- data/ext/couchbase_ext/observe.c +30 -27
- data/ext/couchbase_ext/result.c +13 -13
- data/ext/couchbase_ext/stats.c +22 -20
- data/ext/couchbase_ext/store.c +37 -30
- data/ext/couchbase_ext/timer.c +10 -10
- data/ext/couchbase_ext/touch.c +22 -19
- data/ext/couchbase_ext/unlock.c +22 -19
- data/ext/couchbase_ext/utils.c +78 -78
- data/ext/couchbase_ext/version.c +21 -18
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +18 -0
- data/tasks/compile.rake +1 -1
- data/tasks/test.rake +40 -33
- data/test/setup.rb +4 -0
- data/test/test_arithmetic.rb +37 -0
- metadata +6 -26
@@ -18,23 +18,23 @@
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
20
|
void
|
21
|
-
|
21
|
+
cb_arithmetic_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_arithmetic_resp_t *resp)
|
22
22
|
{
|
23
|
-
struct
|
24
|
-
struct
|
23
|
+
struct cb_context_st *ctx = (struct cb_context_st *)cookie;
|
24
|
+
struct cb_bucket_st *bucket = ctx->bucket;
|
25
25
|
VALUE cas, key, val, *rv = ctx->rv, exc, res;
|
26
26
|
ID o;
|
27
27
|
|
28
28
|
ctx->nqueries--;
|
29
29
|
key = STR_NEW((const char*)resp->v.v0.key, resp->v.v0.nkey);
|
30
|
-
|
30
|
+
cb_strip_key_prefix(bucket, key);
|
31
31
|
|
32
32
|
cas = resp->v.v0.cas > 0 ? ULL2NUM(resp->v.v0.cas) : Qnil;
|
33
|
-
o = ctx->arith > 0 ?
|
33
|
+
o = ctx->arith > 0 ? cb_sym_increment : cb_sym_decrement;
|
34
34
|
exc = cb_check_error(error, "failed to perform arithmetic operation", key);
|
35
35
|
if (exc != Qnil) {
|
36
|
-
rb_ivar_set(exc,
|
37
|
-
rb_ivar_set(exc,
|
36
|
+
rb_ivar_set(exc, cb_id_iv_cas, cas);
|
37
|
+
rb_ivar_set(exc, cb_id_iv_operation, o);
|
38
38
|
if (bucket->async) {
|
39
39
|
if (bucket->on_error_proc != Qnil) {
|
40
40
|
cb_proc_call(bucket->on_error_proc, 3, o, key, exc);
|
@@ -51,12 +51,12 @@ arithmetic_callback(lcb_t handle, const void *cookie, lcb_error_t error, const l
|
|
51
51
|
val = ULL2NUM(resp->v.v0.value);
|
52
52
|
if (bucket->async) { /* asynchronous */
|
53
53
|
if (ctx->proc != Qnil) {
|
54
|
-
res = rb_class_new_instance(0, NULL,
|
55
|
-
rb_ivar_set(res,
|
56
|
-
rb_ivar_set(res,
|
57
|
-
rb_ivar_set(res,
|
58
|
-
rb_ivar_set(res,
|
59
|
-
rb_ivar_set(res,
|
54
|
+
res = rb_class_new_instance(0, NULL, cb_cResult);
|
55
|
+
rb_ivar_set(res, cb_id_iv_error, exc);
|
56
|
+
rb_ivar_set(res, cb_id_iv_operation, o);
|
57
|
+
rb_ivar_set(res, cb_id_iv_key, key);
|
58
|
+
rb_ivar_set(res, cb_id_iv_value, val);
|
59
|
+
rb_ivar_set(res, cb_id_iv_cas, cas);
|
60
60
|
cb_proc_call(ctx->proc, 1, res);
|
61
61
|
}
|
62
62
|
} else { /* synchronous */
|
@@ -70,6 +70,9 @@ arithmetic_callback(lcb_t handle, const void *cookie, lcb_error_t error, const l
|
|
70
70
|
}
|
71
71
|
if (ctx->nqueries == 0) {
|
72
72
|
cb_gc_unprotect(bucket, ctx->proc);
|
73
|
+
if (bucket->async) {
|
74
|
+
xfree(ctx);
|
75
|
+
}
|
73
76
|
}
|
74
77
|
(void)handle;
|
75
78
|
}
|
@@ -77,27 +80,27 @@ arithmetic_callback(lcb_t handle, const void *cookie, lcb_error_t error, const l
|
|
77
80
|
static inline VALUE
|
78
81
|
cb_bucket_arithmetic(int sign, int argc, VALUE *argv, VALUE self)
|
79
82
|
{
|
80
|
-
struct
|
81
|
-
struct
|
83
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
84
|
+
struct cb_context_st *ctx;
|
82
85
|
VALUE args, rv, proc, exc;
|
83
86
|
lcb_error_t err;
|
84
|
-
struct
|
87
|
+
struct cb_params_st params;
|
85
88
|
|
86
89
|
if (bucket->handle == NULL) {
|
87
|
-
rb_raise(
|
90
|
+
rb_raise(cb_eConnectError, "closed connection");
|
88
91
|
}
|
89
92
|
rb_scan_args(argc, argv, "0*&", &args, &proc);
|
90
93
|
if (!bucket->async && proc != Qnil) {
|
91
94
|
rb_raise(rb_eArgError, "synchronous mode doesn't support callbacks");
|
92
95
|
}
|
93
|
-
memset(¶ms, 0, sizeof(struct
|
94
|
-
params.type =
|
96
|
+
memset(¶ms, 0, sizeof(struct cb_params_st));
|
97
|
+
params.type = cb_cmd_arith;
|
95
98
|
params.bucket = bucket;
|
96
99
|
params.cmd.arith.sign = sign;
|
97
100
|
cb_params_build(¶ms, RARRAY_LEN(args), args);
|
98
|
-
ctx = xcalloc(1, sizeof(struct
|
101
|
+
ctx = xcalloc(1, sizeof(struct cb_context_st));
|
99
102
|
if (ctx == NULL) {
|
100
|
-
rb_raise(
|
103
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for context");
|
101
104
|
}
|
102
105
|
rv = rb_hash_new();
|
103
106
|
ctx->rv = &rv;
|
@@ -115,7 +118,7 @@ cb_bucket_arithmetic(int sign, int argc, VALUE *argv, VALUE self)
|
|
115
118
|
}
|
116
119
|
bucket->nbytes += params.npayload;
|
117
120
|
if (bucket->async) {
|
118
|
-
|
121
|
+
cb_maybe_do_loop(bucket);
|
119
122
|
return Qnil;
|
120
123
|
} else {
|
121
124
|
if (ctx->nqueries > 0) {
|
data/ext/couchbase_ext/bucket.c
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
static void
|
21
21
|
error_callback(lcb_t handle, lcb_error_t error, const char *errinfo)
|
22
22
|
{
|
23
|
-
struct
|
23
|
+
struct cb_bucket_st *bucket = (struct cb_bucket_st *)lcb_get_cookie(handle);
|
24
24
|
|
25
25
|
lcb_breakout(handle);
|
26
26
|
bucket->exception = cb_check_error(error, errinfo, Qnil);
|
@@ -29,7 +29,7 @@ error_callback(lcb_t handle, lcb_error_t error, const char *errinfo)
|
|
29
29
|
void
|
30
30
|
cb_bucket_free(void *ptr)
|
31
31
|
{
|
32
|
-
struct
|
32
|
+
struct cb_bucket_st *bucket = ptr;
|
33
33
|
|
34
34
|
if (bucket) {
|
35
35
|
if (bucket->handle) {
|
@@ -50,7 +50,7 @@ cb_bucket_free(void *ptr)
|
|
50
50
|
void
|
51
51
|
cb_bucket_mark(void *ptr)
|
52
52
|
{
|
53
|
-
struct
|
53
|
+
struct cb_bucket_st *bucket = ptr;
|
54
54
|
|
55
55
|
if (bucket) {
|
56
56
|
rb_gc_mark(bucket->exception);
|
@@ -61,7 +61,7 @@ cb_bucket_mark(void *ptr)
|
|
61
61
|
}
|
62
62
|
|
63
63
|
static void
|
64
|
-
do_scan_connection_options(struct
|
64
|
+
do_scan_connection_options(struct cb_bucket_st *bucket, int argc, VALUE *argv)
|
65
65
|
{
|
66
66
|
VALUE uri, opts, arg;
|
67
67
|
size_t len;
|
@@ -76,47 +76,47 @@ do_scan_connection_options(struct bucket_st *bucket, int argc, VALUE *argv)
|
|
76
76
|
VALUE match, uri_obj, re;
|
77
77
|
|
78
78
|
Check_Type(uri, T_STRING);
|
79
|
-
uri_obj = rb_funcall(
|
79
|
+
uri_obj = rb_funcall(cb_mURI, cb_id_parse, 1, uri);
|
80
80
|
|
81
|
-
arg = rb_funcall(uri_obj,
|
81
|
+
arg = rb_funcall(uri_obj, cb_id_scheme, 0);
|
82
82
|
if (arg == Qnil || rb_str_cmp(arg, STR_NEW_CSTR("http"))) {
|
83
83
|
rb_raise(rb_eArgError, "invalid URI: invalid scheme");
|
84
84
|
}
|
85
85
|
|
86
|
-
arg = rb_funcall(uri_obj,
|
86
|
+
arg = rb_funcall(uri_obj, cb_id_user, 0);
|
87
87
|
if (arg != Qnil) {
|
88
88
|
xfree(bucket->username);
|
89
89
|
bucket->username = strdup(RSTRING_PTR(arg));
|
90
90
|
if (bucket->username == NULL) {
|
91
|
-
rb_raise(
|
91
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for Bucket");
|
92
92
|
}
|
93
93
|
}
|
94
94
|
|
95
|
-
arg = rb_funcall(uri_obj,
|
95
|
+
arg = rb_funcall(uri_obj, cb_id_password, 0);
|
96
96
|
if (arg != Qnil) {
|
97
97
|
xfree(bucket->password);
|
98
98
|
bucket->password = strdup(RSTRING_PTR(arg));
|
99
99
|
if (bucket->password == NULL) {
|
100
|
-
rb_raise(
|
100
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for Bucket");
|
101
101
|
}
|
102
102
|
}
|
103
|
-
arg = rb_funcall(uri_obj,
|
103
|
+
arg = rb_funcall(uri_obj, cb_id_host, 0);
|
104
104
|
if (arg != Qnil) {
|
105
105
|
xfree(bucket->hostname);
|
106
106
|
bucket->hostname = strdup(RSTRING_PTR(arg));
|
107
107
|
if (bucket->hostname == NULL) {
|
108
|
-
rb_raise(
|
108
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for Bucket");
|
109
109
|
}
|
110
110
|
} else {
|
111
111
|
rb_raise(rb_eArgError, "invalid URI: missing hostname");
|
112
112
|
}
|
113
113
|
|
114
|
-
arg = rb_funcall(uri_obj,
|
114
|
+
arg = rb_funcall(uri_obj, cb_id_port, 0);
|
115
115
|
bucket->port = NIL_P(arg) ? 8091 : (uint16_t)NUM2UINT(arg);
|
116
116
|
|
117
|
-
arg = rb_funcall(uri_obj,
|
117
|
+
arg = rb_funcall(uri_obj, cb_id_path, 0);
|
118
118
|
re = rb_reg_new(path_re, sizeof(path_re) - 1, 0);
|
119
|
-
match = rb_funcall(re,
|
119
|
+
match = rb_funcall(re, cb_id_match, 1, arg);
|
120
120
|
arg = rb_reg_nth_match(2, match);
|
121
121
|
xfree(bucket->pool);
|
122
122
|
bucket->pool = strdup(NIL_P(arg) ? "default" : RSTRING_PTR(arg));
|
@@ -125,15 +125,15 @@ do_scan_connection_options(struct bucket_st *bucket, int argc, VALUE *argv)
|
|
125
125
|
bucket->bucket = strdup(NIL_P(arg) ? "default" : RSTRING_PTR(arg));
|
126
126
|
}
|
127
127
|
if (TYPE(opts) == T_HASH) {
|
128
|
-
arg = rb_hash_aref(opts,
|
128
|
+
arg = rb_hash_aref(opts, cb_sym_type);
|
129
129
|
if (arg != Qnil) {
|
130
|
-
if (arg ==
|
130
|
+
if (arg == cb_sym_cluster) {
|
131
131
|
bucket->type = LCB_TYPE_CLUSTER;
|
132
132
|
} else {
|
133
133
|
bucket->type = LCB_TYPE_BUCKET;
|
134
134
|
}
|
135
135
|
}
|
136
|
-
arg = rb_hash_aref(opts,
|
136
|
+
arg = rb_hash_aref(opts, cb_sym_node_list);
|
137
137
|
if (arg != Qnil) {
|
138
138
|
VALUE tt;
|
139
139
|
xfree(bucket->node_list);
|
@@ -141,86 +141,93 @@ do_scan_connection_options(struct bucket_st *bucket, int argc, VALUE *argv)
|
|
141
141
|
tt = rb_ary_join(arg, STR_NEW_CSTR(";"));
|
142
142
|
bucket->node_list = strdup(StringValueCStr(tt));
|
143
143
|
}
|
144
|
-
arg = rb_hash_aref(opts,
|
144
|
+
arg = rb_hash_aref(opts, cb_sym_hostname);
|
145
145
|
if (arg != Qnil) {
|
146
146
|
xfree(bucket->hostname);
|
147
147
|
bucket->hostname = strdup(StringValueCStr(arg));
|
148
148
|
}
|
149
|
-
arg = rb_hash_aref(opts,
|
149
|
+
arg = rb_hash_aref(opts, cb_sym_pool);
|
150
150
|
if (arg != Qnil) {
|
151
151
|
xfree(bucket->pool);
|
152
152
|
bucket->pool = strdup(StringValueCStr(arg));
|
153
153
|
}
|
154
|
-
arg = rb_hash_aref(opts,
|
154
|
+
arg = rb_hash_aref(opts, cb_sym_bucket);
|
155
155
|
if (arg != Qnil) {
|
156
156
|
xfree(bucket->bucket);
|
157
157
|
bucket->bucket = strdup(StringValueCStr(arg));
|
158
158
|
}
|
159
|
-
arg = rb_hash_aref(opts,
|
159
|
+
arg = rb_hash_aref(opts, cb_sym_username);
|
160
160
|
if (arg != Qnil) {
|
161
161
|
xfree(bucket->username);
|
162
162
|
bucket->username = strdup(StringValueCStr(arg));
|
163
163
|
}
|
164
|
-
arg = rb_hash_aref(opts,
|
164
|
+
arg = rb_hash_aref(opts, cb_sym_password);
|
165
165
|
if (arg != Qnil) {
|
166
166
|
xfree(bucket->password);
|
167
167
|
bucket->password = strdup(StringValueCStr(arg));
|
168
168
|
}
|
169
|
-
arg = rb_hash_aref(opts,
|
169
|
+
arg = rb_hash_aref(opts, cb_sym_port);
|
170
170
|
if (arg != Qnil) {
|
171
171
|
bucket->port = (uint16_t)NUM2UINT(arg);
|
172
172
|
}
|
173
|
-
if (RTEST(rb_funcall(opts,
|
174
|
-
bucket->quiet = RTEST(rb_hash_aref(opts,
|
173
|
+
if (RTEST(rb_funcall(opts, cb_id_has_key_p, 1, cb_sym_quiet))) {
|
174
|
+
bucket->quiet = RTEST(rb_hash_aref(opts, cb_sym_quiet));
|
175
175
|
}
|
176
|
-
arg = rb_hash_aref(opts,
|
176
|
+
arg = rb_hash_aref(opts, cb_sym_timeout);
|
177
177
|
if (arg != Qnil) {
|
178
178
|
bucket->timeout = (uint32_t)NUM2ULONG(arg);
|
179
179
|
}
|
180
|
-
arg = rb_hash_aref(opts,
|
180
|
+
arg = rb_hash_aref(opts, cb_sym_default_ttl);
|
181
181
|
if (arg != Qnil) {
|
182
182
|
bucket->default_ttl = (uint32_t)NUM2ULONG(arg);
|
183
183
|
}
|
184
|
-
arg = rb_hash_aref(opts,
|
184
|
+
arg = rb_hash_aref(opts, cb_sym_default_observe_timeout);
|
185
185
|
if (arg != Qnil) {
|
186
186
|
bucket->default_observe_timeout = (uint32_t)NUM2ULONG(arg);
|
187
187
|
}
|
188
|
-
arg = rb_hash_aref(opts,
|
188
|
+
arg = rb_hash_aref(opts, cb_sym_default_flags);
|
189
189
|
if (arg != Qnil) {
|
190
190
|
bucket->default_flags = (uint32_t)NUM2ULONG(arg);
|
191
191
|
}
|
192
|
-
arg = rb_hash_aref(opts,
|
192
|
+
arg = rb_hash_aref(opts, cb_sym_default_format);
|
193
193
|
if (arg != Qnil) {
|
194
194
|
if (TYPE(arg) == T_FIXNUM) {
|
195
195
|
switch (FIX2INT(arg)) {
|
196
|
-
case
|
197
|
-
arg =
|
196
|
+
case CB_FMT_DOCUMENT:
|
197
|
+
arg = cb_sym_document;
|
198
198
|
break;
|
199
|
-
case
|
200
|
-
arg =
|
199
|
+
case CB_FMT_MARSHAL:
|
200
|
+
arg = cb_sym_marshal;
|
201
201
|
break;
|
202
|
-
case
|
203
|
-
arg =
|
202
|
+
case CB_FMT_PLAIN:
|
203
|
+
arg = cb_sym_plain;
|
204
204
|
break;
|
205
205
|
}
|
206
206
|
}
|
207
|
-
if (arg ==
|
207
|
+
if (arg == cb_sym_document || arg == cb_sym_marshal || arg == cb_sym_plain) {
|
208
208
|
bucket->default_format = arg;
|
209
|
-
bucket->default_flags =
|
209
|
+
bucket->default_flags = cb_flags_set_format(bucket->default_flags, arg);
|
210
210
|
}
|
211
211
|
}
|
212
|
-
arg = rb_hash_aref(opts,
|
212
|
+
arg = rb_hash_aref(opts, cb_sym_environment);
|
213
213
|
if (arg != Qnil) {
|
214
|
-
if (arg ==
|
214
|
+
if (arg == cb_sym_production || arg == cb_sym_development) {
|
215
215
|
bucket->environment = arg;
|
216
216
|
}
|
217
217
|
}
|
218
|
-
arg = rb_hash_aref(opts,
|
218
|
+
arg = rb_hash_aref(opts, cb_sym_key_prefix);
|
219
219
|
if (arg != Qnil) {
|
220
220
|
xfree(bucket->key_prefix);
|
221
221
|
bucket->key_prefix = strdup(StringValueCStr(arg));
|
222
222
|
bucket->key_prefix_val = STR_NEW_CSTR(bucket->key_prefix);
|
223
223
|
}
|
224
|
+
arg = rb_hash_aref(opts, cb_sym_default_arithmetic_init);
|
225
|
+
if (arg != Qnil) {
|
226
|
+
bucket->default_arith_create = RTEST(arg);
|
227
|
+
if (TYPE(arg) == T_FIXNUM) {
|
228
|
+
bucket->default_arith_init = NUM2ULL(arg);
|
229
|
+
}
|
230
|
+
}
|
224
231
|
} else {
|
225
232
|
opts = Qnil;
|
226
233
|
}
|
@@ -235,13 +242,13 @@ do_scan_connection_options(struct bucket_st *bucket, int argc, VALUE *argv)
|
|
235
242
|
xfree(bucket->authority);
|
236
243
|
bucket->authority = xcalloc(len, sizeof(char));
|
237
244
|
if (bucket->authority == NULL) {
|
238
|
-
rb_raise(
|
245
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for Bucket");
|
239
246
|
}
|
240
247
|
snprintf(bucket->authority, len, "%s:%u", bucket->hostname, bucket->port);
|
241
248
|
}
|
242
249
|
|
243
250
|
static void
|
244
|
-
do_connect(struct
|
251
|
+
do_connect(struct cb_bucket_st *bucket)
|
245
252
|
{
|
246
253
|
lcb_error_t err;
|
247
254
|
struct lcb_create_st create_opts;
|
@@ -271,17 +278,17 @@ do_connect(struct bucket_st *bucket)
|
|
271
278
|
}
|
272
279
|
lcb_set_cookie(bucket->handle, bucket);
|
273
280
|
(void)lcb_set_error_callback(bucket->handle, error_callback);
|
274
|
-
(void)lcb_set_store_callback(bucket->handle,
|
275
|
-
(void)lcb_set_get_callback(bucket->handle,
|
276
|
-
(void)lcb_set_touch_callback(bucket->handle,
|
277
|
-
(void)lcb_set_remove_callback(bucket->handle,
|
278
|
-
(void)lcb_set_stat_callback(bucket->handle,
|
279
|
-
(void)lcb_set_arithmetic_callback(bucket->handle,
|
280
|
-
(void)lcb_set_version_callback(bucket->handle,
|
281
|
-
(void)lcb_set_http_complete_callback(bucket->handle,
|
282
|
-
(void)lcb_set_http_data_callback(bucket->handle,
|
283
|
-
(void)lcb_set_observe_callback(bucket->handle,
|
284
|
-
(void)lcb_set_unlock_callback(bucket->handle,
|
281
|
+
(void)lcb_set_store_callback(bucket->handle, cb_storage_callback);
|
282
|
+
(void)lcb_set_get_callback(bucket->handle, cb_get_callback);
|
283
|
+
(void)lcb_set_touch_callback(bucket->handle, cb_touch_callback);
|
284
|
+
(void)lcb_set_remove_callback(bucket->handle, cb_delete_callback);
|
285
|
+
(void)lcb_set_stat_callback(bucket->handle, cb_stat_callback);
|
286
|
+
(void)lcb_set_arithmetic_callback(bucket->handle, cb_arithmetic_callback);
|
287
|
+
(void)lcb_set_version_callback(bucket->handle, cb_version_callback);
|
288
|
+
(void)lcb_set_http_complete_callback(bucket->handle, cb_http_complete_callback);
|
289
|
+
(void)lcb_set_http_data_callback(bucket->handle, cb_http_data_callback);
|
290
|
+
(void)lcb_set_observe_callback(bucket->handle, cb_observe_callback);
|
291
|
+
(void)lcb_set_unlock_callback(bucket->handle, cb_unlock_callback);
|
285
292
|
|
286
293
|
if (bucket->timeout > 0) {
|
287
294
|
lcb_set_timeout(bucket->handle, bucket->timeout);
|
@@ -311,10 +318,10 @@ do_connect(struct bucket_st *bucket)
|
|
311
318
|
cb_bucket_alloc(VALUE klass)
|
312
319
|
{
|
313
320
|
VALUE obj;
|
314
|
-
struct
|
321
|
+
struct cb_bucket_st *bucket;
|
315
322
|
|
316
323
|
/* allocate new bucket struct and set it to zero */
|
317
|
-
obj = Data_Make_Struct(klass, struct
|
324
|
+
obj = Data_Make_Struct(klass, struct cb_bucket_st, cb_bucket_mark, cb_bucket_free,
|
318
325
|
bucket);
|
319
326
|
return obj;
|
320
327
|
}
|
@@ -372,6 +379,11 @@ cb_bucket_alloc(VALUE klass)
|
|
372
379
|
* returning back to the application.
|
373
380
|
* @option options [Fixnum] :timeout (2500000) the timeout for IO
|
374
381
|
* operations (in microseconds)
|
382
|
+
* @option options [Fixnum, true] :default_arithmetic_init (0) the default
|
383
|
+
* initial value for arithmetic operations. Setting this option to any
|
384
|
+
* non positive number forces creation missing keys with given default
|
385
|
+
* value. Setting it to +true+ will use zero as initial value. (see
|
386
|
+
* {Bucket#incr} and {Bucket#decr}).
|
375
387
|
*
|
376
388
|
* @example Initialize connection using default options
|
377
389
|
* Couchbase.new
|
@@ -399,7 +411,7 @@ cb_bucket_alloc(VALUE klass)
|
|
399
411
|
VALUE
|
400
412
|
cb_bucket_init(int argc, VALUE *argv, VALUE self)
|
401
413
|
{
|
402
|
-
struct
|
414
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
403
415
|
|
404
416
|
bucket->self = self;
|
405
417
|
bucket->exception = Qnil;
|
@@ -412,11 +424,11 @@ cb_bucket_init(int argc, VALUE *argv, VALUE self)
|
|
412
424
|
bucket->quiet = 0;
|
413
425
|
bucket->default_ttl = 0;
|
414
426
|
bucket->default_flags = 0;
|
415
|
-
bucket->default_format =
|
427
|
+
bucket->default_format = cb_sym_document;
|
416
428
|
bucket->default_observe_timeout = 2500000;
|
417
429
|
bucket->on_error_proc = Qnil;
|
418
430
|
bucket->timeout = 0;
|
419
|
-
bucket->environment =
|
431
|
+
bucket->environment = cb_sym_production;
|
420
432
|
bucket->key_prefix = NULL;
|
421
433
|
bucket->key_prefix_val = Qnil;
|
422
434
|
bucket->node_list = NULL;
|
@@ -441,8 +453,8 @@ cb_bucket_init(int argc, VALUE *argv, VALUE self)
|
|
441
453
|
VALUE
|
442
454
|
cb_bucket_init_copy(VALUE copy, VALUE orig)
|
443
455
|
{
|
444
|
-
struct
|
445
|
-
struct
|
456
|
+
struct cb_bucket_st *copy_b;
|
457
|
+
struct cb_bucket_st *orig_b;
|
446
458
|
|
447
459
|
if (copy == orig)
|
448
460
|
return copy;
|
@@ -479,10 +491,10 @@ cb_bucket_init_copy(VALUE copy, VALUE orig)
|
|
479
491
|
copy_b->timeout = orig_b->timeout;
|
480
492
|
copy_b->exception = Qnil;
|
481
493
|
if (orig_b->on_error_proc != Qnil) {
|
482
|
-
copy_b->on_error_proc = rb_funcall(orig_b->on_error_proc,
|
494
|
+
copy_b->on_error_proc = rb_funcall(orig_b->on_error_proc, cb_id_dup, 0);
|
483
495
|
}
|
484
496
|
if (orig_b->key_prefix_val != Qnil) {
|
485
|
-
copy_b->key_prefix_val = rb_funcall(orig_b->key_prefix_val,
|
497
|
+
copy_b->key_prefix_val = rb_funcall(orig_b->key_prefix_val, cb_id_dup, 0);
|
486
498
|
}
|
487
499
|
|
488
500
|
do_connect(copy_b);
|
@@ -515,7 +527,7 @@ cb_bucket_init_copy(VALUE copy, VALUE orig)
|
|
515
527
|
VALUE
|
516
528
|
cb_bucket_reconnect(int argc, VALUE *argv, VALUE self)
|
517
529
|
{
|
518
|
-
struct
|
530
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
519
531
|
|
520
532
|
do_scan_connection_options(bucket, argc, argv);
|
521
533
|
do_connect(bucket);
|
@@ -533,7 +545,7 @@ cb_bucket_reconnect(int argc, VALUE *argv, VALUE self)
|
|
533
545
|
VALUE
|
534
546
|
cb_bucket_connected_p(VALUE self)
|
535
547
|
{
|
536
|
-
struct
|
548
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
537
549
|
return bucket->handle ? Qtrue : Qfalse;
|
538
550
|
}
|
539
551
|
|
@@ -561,21 +573,21 @@ cb_bucket_connected_p(VALUE self)
|
|
561
573
|
VALUE
|
562
574
|
cb_bucket_async_p(VALUE self)
|
563
575
|
{
|
564
|
-
struct
|
576
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
565
577
|
return bucket->async ? Qtrue : Qfalse;
|
566
578
|
}
|
567
579
|
|
568
580
|
VALUE
|
569
581
|
cb_bucket_quiet_get(VALUE self)
|
570
582
|
{
|
571
|
-
struct
|
583
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
572
584
|
return bucket->quiet ? Qtrue : Qfalse;
|
573
585
|
}
|
574
586
|
|
575
587
|
VALUE
|
576
588
|
cb_bucket_quiet_set(VALUE self, VALUE val)
|
577
589
|
{
|
578
|
-
struct
|
590
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
579
591
|
VALUE new;
|
580
592
|
|
581
593
|
bucket->quiet = RTEST(val);
|
@@ -586,48 +598,48 @@ cb_bucket_quiet_set(VALUE self, VALUE val)
|
|
586
598
|
VALUE
|
587
599
|
cb_bucket_default_flags_get(VALUE self)
|
588
600
|
{
|
589
|
-
struct
|
601
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
590
602
|
return ULONG2NUM(bucket->default_flags);
|
591
603
|
}
|
592
604
|
|
593
605
|
VALUE
|
594
606
|
cb_bucket_default_flags_set(VALUE self, VALUE val)
|
595
607
|
{
|
596
|
-
struct
|
608
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
597
609
|
|
598
610
|
bucket->default_flags = (uint32_t)NUM2ULONG(val);
|
599
|
-
bucket->default_format =
|
611
|
+
bucket->default_format = cb_flags_get_format(bucket->default_flags);
|
600
612
|
return val;
|
601
613
|
}
|
602
614
|
|
603
615
|
VALUE
|
604
616
|
cb_bucket_default_format_get(VALUE self)
|
605
617
|
{
|
606
|
-
struct
|
618
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
607
619
|
return bucket->default_format;
|
608
620
|
}
|
609
621
|
|
610
622
|
VALUE
|
611
623
|
cb_bucket_default_format_set(VALUE self, VALUE val)
|
612
624
|
{
|
613
|
-
struct
|
625
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
614
626
|
|
615
627
|
if (TYPE(val) == T_FIXNUM) {
|
616
628
|
switch (FIX2INT(val)) {
|
617
|
-
case
|
618
|
-
val =
|
629
|
+
case CB_FMT_DOCUMENT:
|
630
|
+
val = cb_sym_document;
|
619
631
|
break;
|
620
|
-
case
|
621
|
-
val =
|
632
|
+
case CB_FMT_MARSHAL:
|
633
|
+
val = cb_sym_marshal;
|
622
634
|
break;
|
623
|
-
case
|
624
|
-
val =
|
635
|
+
case CB_FMT_PLAIN:
|
636
|
+
val = cb_sym_plain;
|
625
637
|
break;
|
626
638
|
}
|
627
639
|
}
|
628
|
-
if (val ==
|
640
|
+
if (val == cb_sym_document || val == cb_sym_marshal || val == cb_sym_plain) {
|
629
641
|
bucket->default_format = val;
|
630
|
-
bucket->default_flags =
|
642
|
+
bucket->default_flags = cb_flags_set_format(bucket->default_flags, val);
|
631
643
|
}
|
632
644
|
|
633
645
|
return val;
|
@@ -636,9 +648,9 @@ cb_bucket_default_format_set(VALUE self, VALUE val)
|
|
636
648
|
VALUE
|
637
649
|
cb_bucket_on_error_set(VALUE self, VALUE val)
|
638
650
|
{
|
639
|
-
struct
|
651
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
640
652
|
|
641
|
-
if (rb_respond_to(val,
|
653
|
+
if (rb_respond_to(val, cb_id_call)) {
|
642
654
|
bucket->on_error_proc = val;
|
643
655
|
} else {
|
644
656
|
bucket->on_error_proc = Qnil;
|
@@ -650,7 +662,7 @@ cb_bucket_on_error_set(VALUE self, VALUE val)
|
|
650
662
|
VALUE
|
651
663
|
cb_bucket_on_error_get(VALUE self)
|
652
664
|
{
|
653
|
-
struct
|
665
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
654
666
|
|
655
667
|
if (rb_block_given_p()) {
|
656
668
|
return cb_bucket_on_error_set(self, rb_block_proc());
|
@@ -662,14 +674,14 @@ cb_bucket_on_error_get(VALUE self)
|
|
662
674
|
VALUE
|
663
675
|
cb_bucket_timeout_get(VALUE self)
|
664
676
|
{
|
665
|
-
struct
|
677
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
666
678
|
return ULONG2NUM(bucket->timeout);
|
667
679
|
}
|
668
680
|
|
669
681
|
VALUE
|
670
682
|
cb_bucket_timeout_set(VALUE self, VALUE val)
|
671
683
|
{
|
672
|
-
struct
|
684
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
673
685
|
VALUE tmval;
|
674
686
|
|
675
687
|
bucket->timeout = (uint32_t)NUM2ULONG(val);
|
@@ -679,17 +691,38 @@ cb_bucket_timeout_set(VALUE self, VALUE val)
|
|
679
691
|
return tmval;
|
680
692
|
}
|
681
693
|
|
694
|
+
VALUE
|
695
|
+
cb_bucket_default_arithmetic_init_get(VALUE self)
|
696
|
+
{
|
697
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
698
|
+
return ULL2NUM(bucket->default_arith_init);
|
699
|
+
}
|
700
|
+
|
701
|
+
VALUE
|
702
|
+
cb_bucket_default_arithmetic_init_set(VALUE self, VALUE val)
|
703
|
+
{
|
704
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
705
|
+
|
706
|
+
bucket->default_arith_create = RTEST(val);
|
707
|
+
if (bucket->default_arith_create) {
|
708
|
+
bucket->default_arith_init = NUM2ULL(val);
|
709
|
+
} else {
|
710
|
+
bucket->default_arith_init = 0;
|
711
|
+
}
|
712
|
+
return ULL2NUM(bucket->default_arith_init);
|
713
|
+
}
|
714
|
+
|
682
715
|
VALUE
|
683
716
|
cb_bucket_key_prefix_get(VALUE self)
|
684
717
|
{
|
685
|
-
struct
|
718
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
686
719
|
return bucket->key_prefix_val;
|
687
720
|
}
|
688
721
|
|
689
722
|
VALUE
|
690
723
|
cb_bucket_key_prefix_set(VALUE self, VALUE val)
|
691
724
|
{
|
692
|
-
struct
|
725
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
693
726
|
|
694
727
|
bucket->key_prefix = strdup(StringValueCStr(val));
|
695
728
|
bucket->key_prefix_val = STR_NEW_CSTR(bucket->key_prefix);
|
@@ -706,12 +739,12 @@ cb_bucket_key_prefix_set(VALUE self, VALUE val)
|
|
706
739
|
VALUE
|
707
740
|
cb_bucket_hostname_get(VALUE self)
|
708
741
|
{
|
709
|
-
struct
|
742
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
710
743
|
if (bucket->handle) {
|
711
744
|
xfree(bucket->hostname);
|
712
745
|
bucket->hostname = strdup(lcb_get_host(bucket->handle));
|
713
746
|
if (bucket->hostname == NULL) {
|
714
|
-
rb_raise(
|
747
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for Bucket");
|
715
748
|
}
|
716
749
|
}
|
717
750
|
return STR_NEW_CSTR(bucket->hostname);
|
@@ -726,7 +759,7 @@ cb_bucket_hostname_get(VALUE self)
|
|
726
759
|
VALUE
|
727
760
|
cb_bucket_port_get(VALUE self)
|
728
761
|
{
|
729
|
-
struct
|
762
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
730
763
|
if (bucket->handle) {
|
731
764
|
bucket->port = atoi(lcb_get_port(bucket->handle));
|
732
765
|
}
|
@@ -742,7 +775,7 @@ cb_bucket_port_get(VALUE self)
|
|
742
775
|
VALUE
|
743
776
|
cb_bucket_authority_get(VALUE self)
|
744
777
|
{
|
745
|
-
struct
|
778
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
746
779
|
size_t len;
|
747
780
|
|
748
781
|
(void)cb_bucket_hostname_get(self);
|
@@ -750,7 +783,7 @@ cb_bucket_authority_get(VALUE self)
|
|
750
783
|
len = strlen(bucket->hostname) + 10;
|
751
784
|
bucket->authority = xcalloc(len, sizeof(char));
|
752
785
|
if (bucket->authority == NULL) {
|
753
|
-
rb_raise(
|
786
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for Bucket");
|
754
787
|
}
|
755
788
|
snprintf(bucket->authority, len, "%s:%u", bucket->hostname, bucket->port);
|
756
789
|
return STR_NEW_CSTR(bucket->authority);
|
@@ -765,7 +798,7 @@ cb_bucket_authority_get(VALUE self)
|
|
765
798
|
VALUE
|
766
799
|
cb_bucket_bucket_get(VALUE self)
|
767
800
|
{
|
768
|
-
struct
|
801
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
769
802
|
return STR_NEW_CSTR(bucket->bucket);
|
770
803
|
}
|
771
804
|
|
@@ -778,7 +811,7 @@ cb_bucket_bucket_get(VALUE self)
|
|
778
811
|
VALUE
|
779
812
|
cb_bucket_pool_get(VALUE self)
|
780
813
|
{
|
781
|
-
struct
|
814
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
782
815
|
return STR_NEW_CSTR(bucket->pool);
|
783
816
|
}
|
784
817
|
|
@@ -792,7 +825,7 @@ cb_bucket_pool_get(VALUE self)
|
|
792
825
|
VALUE
|
793
826
|
cb_bucket_username_get(VALUE self)
|
794
827
|
{
|
795
|
-
struct
|
828
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
796
829
|
return STR_NEW_CSTR(bucket->username);
|
797
830
|
}
|
798
831
|
|
@@ -805,7 +838,7 @@ cb_bucket_username_get(VALUE self)
|
|
805
838
|
VALUE
|
806
839
|
cb_bucket_password_get(VALUE self)
|
807
840
|
{
|
808
|
-
struct
|
841
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
809
842
|
return STR_NEW_CSTR(bucket->password);
|
810
843
|
}
|
811
844
|
|
@@ -820,7 +853,7 @@ cb_bucket_password_get(VALUE self)
|
|
820
853
|
VALUE
|
821
854
|
cb_bucket_environment_get(VALUE self)
|
822
855
|
{
|
823
|
-
struct
|
856
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
824
857
|
return bucket->environment;
|
825
858
|
}
|
826
859
|
/* Document-method: num_replicas
|
@@ -834,7 +867,7 @@ cb_bucket_environment_get(VALUE self)
|
|
834
867
|
VALUE
|
835
868
|
cb_bucket_num_replicas_get(VALUE self)
|
836
869
|
{
|
837
|
-
struct
|
870
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
838
871
|
int32_t nr = lcb_get_num_replicas(bucket->handle);
|
839
872
|
if (nr < 0) {
|
840
873
|
return Qnil;
|
@@ -854,7 +887,7 @@ cb_bucket_num_replicas_get(VALUE self)
|
|
854
887
|
VALUE
|
855
888
|
cb_bucket_default_observe_timeout_get(VALUE self)
|
856
889
|
{
|
857
|
-
struct
|
890
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
858
891
|
return INT2FIX(bucket->default_observe_timeout);
|
859
892
|
}
|
860
893
|
|
@@ -870,7 +903,7 @@ cb_bucket_default_observe_timeout_get(VALUE self)
|
|
870
903
|
VALUE
|
871
904
|
cb_bucket_default_observe_timeout_set(VALUE self, VALUE val)
|
872
905
|
{
|
873
|
-
struct
|
906
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
874
907
|
bucket->default_observe_timeout = FIX2INT(val);
|
875
908
|
return val;
|
876
909
|
}
|
@@ -883,7 +916,7 @@ cb_bucket_default_observe_timeout_set(VALUE self, VALUE val)
|
|
883
916
|
VALUE
|
884
917
|
cb_bucket_url_get(VALUE self)
|
885
918
|
{
|
886
|
-
struct
|
919
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
887
920
|
VALUE str;
|
888
921
|
|
889
922
|
(void)cb_bucket_authority_get(self);
|
@@ -909,7 +942,7 @@ cb_bucket_url_get(VALUE self)
|
|
909
942
|
cb_bucket_inspect(VALUE self)
|
910
943
|
{
|
911
944
|
VALUE str;
|
912
|
-
struct
|
945
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
913
946
|
char buf[200];
|
914
947
|
|
915
948
|
str = rb_str_buf_new2("#<");
|
@@ -941,14 +974,14 @@ cb_bucket_inspect(VALUE self)
|
|
941
974
|
}
|
942
975
|
|
943
976
|
static void
|
944
|
-
do_loop(struct
|
977
|
+
do_loop(struct cb_bucket_st *bucket)
|
945
978
|
{
|
946
979
|
lcb_wait(bucket->handle);
|
947
980
|
bucket->nbytes = 0;
|
948
981
|
}
|
949
982
|
|
950
983
|
void
|
951
|
-
|
984
|
+
cb_maybe_do_loop(struct cb_bucket_st *bucket)
|
952
985
|
{
|
953
986
|
if (bucket->threshold != 0 && bucket->nbytes > bucket->threshold) {
|
954
987
|
do_loop(bucket);
|
@@ -959,19 +992,19 @@ maybe_do_loop(struct bucket_st *bucket)
|
|
959
992
|
do_run(VALUE *args)
|
960
993
|
{
|
961
994
|
VALUE self = args[0], opts = args[1], proc = args[2], exc;
|
962
|
-
struct
|
995
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
963
996
|
|
964
997
|
if (bucket->handle == NULL) {
|
965
|
-
rb_raise(
|
998
|
+
rb_raise(cb_eConnectError, "closed connection");
|
966
999
|
}
|
967
1000
|
if (bucket->async) {
|
968
|
-
rb_raise(
|
1001
|
+
rb_raise(cb_eInvalidError, "nested #run");
|
969
1002
|
}
|
970
1003
|
bucket->threshold = 0;
|
971
1004
|
if (opts != Qnil) {
|
972
1005
|
VALUE arg;
|
973
1006
|
Check_Type(opts, T_HASH);
|
974
|
-
arg = rb_hash_aref(opts,
|
1007
|
+
arg = rb_hash_aref(opts, cb_sym_send_threshold);
|
975
1008
|
if (arg != Qnil) {
|
976
1009
|
bucket->threshold = (uint32_t)NUM2ULONG(arg);
|
977
1010
|
}
|
@@ -991,7 +1024,7 @@ do_run(VALUE *args)
|
|
991
1024
|
ensure_run(VALUE *args)
|
992
1025
|
{
|
993
1026
|
VALUE self = args[0];
|
994
|
-
struct
|
1027
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
995
1028
|
|
996
1029
|
bucket->async = 0;
|
997
1030
|
return Qnil;
|
@@ -1072,7 +1105,7 @@ cb_bucket_run(int argc, VALUE *argv, VALUE self)
|
|
1072
1105
|
VALUE
|
1073
1106
|
cb_bucket_stop(VALUE self)
|
1074
1107
|
{
|
1075
|
-
struct
|
1108
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
1076
1109
|
lcb_breakout(bucket->handle);
|
1077
1110
|
return Qnil;
|
1078
1111
|
}
|
@@ -1089,7 +1122,7 @@ cb_bucket_stop(VALUE self)
|
|
1089
1122
|
VALUE
|
1090
1123
|
cb_bucket_disconnect(VALUE self)
|
1091
1124
|
{
|
1092
|
-
struct
|
1125
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
1093
1126
|
|
1094
1127
|
if (bucket->handle) {
|
1095
1128
|
lcb_destroy(bucket->handle);
|
@@ -1098,7 +1131,7 @@ cb_bucket_disconnect(VALUE self)
|
|
1098
1131
|
bucket->io = NULL;
|
1099
1132
|
return Qtrue;
|
1100
1133
|
} else {
|
1101
|
-
rb_raise(
|
1134
|
+
rb_raise(cb_eConnectError, "closed connection");
|
1102
1135
|
return Qfalse;
|
1103
1136
|
}
|
1104
1137
|
}
|