Skip to content

Commit

Permalink
RCBC-50 Allow to read keys from replica
Browse files Browse the repository at this point in the history
Change-Id: I7577dd23d368b7733b4050cf6c5776d5c9a866fd
Reviewed-on: http://review.couchbase.org/18590
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Chris Anderson <jchris@couchbase.com>
  • Loading branch information
avsej authored and Chris Anderson committed Jul 19, 2012
1 parent 7f77989 commit 60b245b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ext/couchbase_ext/couchbase_ext.c
Expand Up @@ -119,6 +119,7 @@ struct key_traits_st
int is_array;
int assemble_hash;
int lock;
int replica;
struct bucket_st *bucket;
VALUE force_format;
};
Expand Down Expand Up @@ -178,6 +179,7 @@ static ID sym_add,
sym_put,
sym_quiet,
sym_replace,
sym_replica,
sym_send_threshold,
sym_set,
sym_stats,
Expand Down Expand Up @@ -665,6 +667,7 @@ cb_args_scan_keys(long argc, VALUE argv, struct key_traits_st *traits)
traits->mgat = 0;
traits->assemble_hash = 0;
traits->lock = 0;
traits->replica = 0;

if (argc > 0) {
/* keys with custom options */
Expand All @@ -673,6 +676,7 @@ cb_args_scan_keys(long argc, VALUE argv, struct key_traits_st *traits)
ext = Qfalse;
if (argc > 1 && TYPE(opts) == T_HASH) {
(void)rb_ary_pop(argv);
traits->replica = RTEST(rb_hash_aref(opts, sym_replica));
if (RTEST(rb_funcall(opts, id_has_key_p, 1, sym_quiet))) {
traits->quiet = RTEST(rb_hash_aref(opts, sym_quiet));
}
Expand Down Expand Up @@ -2503,6 +2507,8 @@ cb_bucket_decr(int argc, VALUE *argv, VALUE self)
* @option options [true, false] :assemble_hash (false) Assemble Hash for
* results. Hash assembled automatically if +:extended+ option is true
* or in case of "get and touch" multimple keys.
* @option options [true, false] :replica (false) Read key from replica
* node. Options +:ttl+ and +:lock+ are not compatible with +:replica+.
*
* @yieldparam ret [Result] the result of operation in asynchronous mode
* (valid attributes: +error+, +operation+, +key+, +value+, +flags+,
Expand Down Expand Up @@ -2642,6 +2648,10 @@ cb_bucket_get(int argc, VALUE *argv, VALUE self)
break;
}
}
} else if (traits->replica) {
err = libcouchbase_get_replica(bucket->handle, (const void *)ctx,
traits->nkeys, (const void * const *)traits->keys,
traits->lens);
} else {
err = libcouchbase_mget(bucket->handle, (const void *)ctx,
traits->nkeys, (const void * const *)traits->keys,
Expand Down Expand Up @@ -4788,6 +4798,7 @@ Init_couchbase_ext(void)
sym_put = ID2SYM(rb_intern("put"));
sym_quiet = ID2SYM(rb_intern("quiet"));
sym_replace = ID2SYM(rb_intern("replace"));
sym_replica = ID2SYM(rb_intern("replica"));
sym_send_threshold = ID2SYM(rb_intern("send_threshold"));
sym_set = ID2SYM(rb_intern("set"));
sym_stats = ID2SYM(rb_intern("stats"));
Expand Down

0 comments on commit 60b245b

Please sign in to comment.