libcouchbase 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libcouchbase/.gitignore +2 -0
- data/ext/libcouchbase/CMakeLists.txt +5 -7
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +49 -0
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +2 -1
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
- data/ext/libcouchbase/cmake/defs.mk.in +0 -2
- data/ext/libcouchbase/cmake/source_files.cmake +34 -14
- data/ext/libcouchbase/configure.pl +1 -1
- data/ext/libcouchbase/contrib/genhash/genhash.h +6 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +10 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +10 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +7 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +13 -1
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +9 -0
- data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
- data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +21 -1132
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
- data/ext/libcouchbase/src/README.md +0 -2
- data/ext/libcouchbase/src/auth-priv.h +1 -0
- data/ext/libcouchbase/src/auth.cc +10 -0
- data/ext/libcouchbase/src/bootstrap.cc +216 -0
- data/ext/libcouchbase/src/bootstrap.h +50 -39
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +455 -0
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +528 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +115 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +407 -386
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +378 -0
- data/ext/libcouchbase/src/cbft.cc +22 -27
- data/ext/libcouchbase/src/cntl.cc +24 -24
- data/ext/libcouchbase/src/connspec.cc +30 -1
- data/ext/libcouchbase/src/connspec.h +17 -0
- data/ext/libcouchbase/src/dns-srv.cc +143 -0
- data/ext/libcouchbase/src/{dump.c → dump.cc} +8 -11
- data/ext/libcouchbase/src/getconfig.cc +73 -0
- data/ext/libcouchbase/src/handler.cc +84 -85
- data/ext/libcouchbase/src/hostlist.cc +0 -1
- data/ext/libcouchbase/src/hostlist.h +6 -1
- data/ext/libcouchbase/src/http/http-priv.h +125 -112
- data/ext/libcouchbase/src/http/http.cc +9 -29
- data/ext/libcouchbase/src/http/http.h +1 -34
- data/ext/libcouchbase/src/http/http_io.cc +22 -26
- data/ext/libcouchbase/src/instance.cc +102 -28
- data/ext/libcouchbase/src/internal.h +47 -29
- data/ext/libcouchbase/src/jsparse/parser.cc +146 -202
- data/ext/libcouchbase/src/jsparse/parser.h +91 -98
- data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
- data/ext/libcouchbase/src/lcbio/connect.cc +562 -0
- data/ext/libcouchbase/src/lcbio/connect.h +9 -2
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +61 -16
- data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
- data/ext/libcouchbase/src/lcbio/manager.c +2 -2
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
- data/ext/libcouchbase/src/mc/mcreq.h +9 -2
- data/ext/libcouchbase/src/mcserver/mcserver.cc +723 -0
- data/ext/libcouchbase/src/mcserver/mcserver.h +160 -70
- data/ext/libcouchbase/src/mcserver/negotiate.cc +118 -152
- data/ext/libcouchbase/src/mcserver/negotiate.h +85 -74
- data/ext/libcouchbase/src/mctx-helper.h +51 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
- data/ext/libcouchbase/src/n1ql/n1ql.cc +56 -32
- data/ext/libcouchbase/src/{newconfig.c → newconfig.cc} +42 -70
- data/ext/libcouchbase/src/nodeinfo.cc +4 -8
- data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
- data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
- data/ext/libcouchbase/src/operations/{durability-cas.c → durability-cas.cc} +92 -76
- data/ext/libcouchbase/src/operations/{durability-seqno.c → durability-seqno.cc} +55 -49
- data/ext/libcouchbase/src/operations/durability.cc +643 -0
- data/ext/libcouchbase/src/operations/durability_internal.h +212 -124
- data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
- data/ext/libcouchbase/src/operations/{observe-seqno.c → observe-seqno.cc} +5 -8
- data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +69 -94
- data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
- data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
- data/ext/libcouchbase/src/operations/{stats.c → stats.cc} +66 -78
- data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
- data/ext/libcouchbase/src/operations/subdoc.cc +38 -18
- data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
- data/ext/libcouchbase/src/packetutils.h +200 -137
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +3 -4
- data/ext/libcouchbase/src/retryq.cc +394 -0
- data/ext/libcouchbase/src/retryq.h +116 -104
- data/ext/libcouchbase/src/settings.h +2 -1
- data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
- data/ext/libcouchbase/src/trace.h +8 -8
- data/ext/libcouchbase/src/vbucket/vbucket.c +0 -1
- data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
- data/ext/libcouchbase/src/views/docreq.h +24 -30
- data/ext/libcouchbase/src/views/viewreq.cc +318 -0
- data/ext/libcouchbase/src/views/viewreq.h +43 -13
- data/ext/libcouchbase/src/{wait.c → wait.cc} +12 -17
- data/ext/libcouchbase/tests/basic/t_connstr.cc +89 -50
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -78
- data/ext/libcouchbase/tests/basic/t_packet.cc +35 -42
- data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +94 -111
- data/ext/libcouchbase/tests/iotests/t_sched.cc +1 -2
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
- data/lib/libcouchbase/version.rb +1 -1
- metadata +36 -39
- data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
- data/ext/libcouchbase/src/bootstrap.c +0 -269
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +0 -495
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
- data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
- data/ext/libcouchbase/src/getconfig.c +0 -100
- data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
- data/ext/libcouchbase/src/lcbio/connect.c +0 -557
- data/ext/libcouchbase/src/mcserver/mcserver.c +0 -784
- data/ext/libcouchbase/src/operations/durability.c +0 -668
- data/ext/libcouchbase/src/packetutils.c +0 -60
- data/ext/libcouchbase/src/retryq.c +0 -424
- data/ext/libcouchbase/src/simplestring.c +0 -211
- data/ext/libcouchbase/src/simplestring.h +0 -228
- data/ext/libcouchbase/src/ssobuf.h +0 -82
- data/ext/libcouchbase/src/views/viewreq.c +0 -358
- data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -70,7 +70,7 @@ lcb_get_node(lcb_t instance, lcb_GETNODETYPE type, unsigned ix)
|
|
70
70
|
|
71
71
|
if (type & LCB_NODE_HTCONFIG) {
|
72
72
|
if (type & LCB_NODE_CONNECTED) {
|
73
|
-
const lcb_host_t *host =
|
73
|
+
const lcb_host_t *host = lcb::clconfig::http_get_host(instance->confmon);
|
74
74
|
if (host) {
|
75
75
|
return mk_scratch_host(instance, host);
|
76
76
|
} else {
|
@@ -101,20 +101,16 @@ lcb_get_node(lcb_t instance, lcb_GETNODETYPE type, unsigned ix)
|
|
101
101
|
return ensure_scratch(instance).append(hp).c_str();
|
102
102
|
}
|
103
103
|
} else if (type & (LCB_NODE_DATA|LCB_NODE_VIEWS)) {
|
104
|
-
const mc_SERVER *server;
|
105
104
|
ix %= LCBT_NSERVERS(instance);
|
106
|
-
server =
|
105
|
+
const lcb::Server *server = instance->get_server(ix);
|
107
106
|
|
108
|
-
if ((type & LCB_NODE_CONNECTED) && server->
|
109
|
-
return return_badhost(type);
|
110
|
-
}
|
111
|
-
if (server->curhost == NULL) {
|
107
|
+
if ((type & LCB_NODE_CONNECTED) && !server->is_connected()) {
|
112
108
|
return return_badhost(type);
|
113
109
|
}
|
114
110
|
|
115
111
|
/* otherwise, return the actual host:port of the server */
|
116
112
|
if (type & LCB_NODE_DATA) {
|
117
|
-
return mk_scratch_host(instance, server->
|
113
|
+
return mk_scratch_host(instance, &server->get_host());
|
118
114
|
} else {
|
119
115
|
return lcbvb_get_hostport(vbc, ix, LCBVB_SVCTYPE_VIEWS, mode);
|
120
116
|
}
|
@@ -15,11 +15,10 @@
|
|
15
15
|
*/
|
16
16
|
|
17
17
|
#include "internal.h"
|
18
|
-
#include "simplestring.h"
|
19
18
|
#include <http/http.h>
|
20
19
|
|
21
20
|
static void
|
22
|
-
flush_cb(lcb_t instance, int
|
21
|
+
flush_cb(lcb_t instance, int, const lcb_RESPBASE *rb)
|
23
22
|
{
|
24
23
|
const lcb_RESPHTTP *resp = (const lcb_RESPHTTP *)rb;
|
25
24
|
lcb_RESPCBFLUSH fresp = { 0 };
|
@@ -35,37 +34,30 @@ flush_cb(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
|
|
35
34
|
if (callback) {
|
36
35
|
callback(instance, LCB_CALLBACK_CBFLUSH, (lcb_RESPBASE*)&fresp);
|
37
36
|
}
|
38
|
-
(void)cbtype;
|
39
37
|
}
|
40
38
|
|
41
39
|
LIBCOUCHBASE_API
|
42
40
|
lcb_error_t
|
43
|
-
lcb_cbflush3(lcb_t instance, const void *cookie, const lcb_CMDBASE *
|
41
|
+
lcb_cbflush3(lcb_t instance, const void *cookie, const lcb_CMDBASE *)
|
44
42
|
{
|
45
43
|
lcb_http_request_t htr;
|
46
44
|
lcb_CMDHTTP htcmd = { 0 };
|
47
|
-
lcb_string urlpath;
|
48
45
|
lcb_error_t rc;
|
49
46
|
|
50
|
-
(
|
51
|
-
|
52
|
-
|
53
|
-
lcb_string_appendz(&urlpath, "/pools/default/buckets/");
|
54
|
-
lcb_string_appendz(&urlpath, LCBT_SETTING(instance, bucket));
|
55
|
-
lcb_string_appendz(&urlpath, "/controller/doFlush");
|
56
|
-
|
47
|
+
std::string urlpath("/pools/default/buckets/");
|
48
|
+
urlpath.append(LCBT_SETTING(instance, bucket));
|
49
|
+
urlpath.append("/controller/doFlush");
|
57
50
|
|
58
51
|
htcmd.type = LCB_HTTP_TYPE_MANAGEMENT;
|
59
52
|
htcmd.method = LCB_HTTP_METHOD_POST;
|
60
53
|
htcmd.reqhandle = &htr;
|
61
|
-
LCB_CMD_SET_KEY(&htcmd, urlpath.
|
54
|
+
LCB_CMD_SET_KEY(&htcmd, urlpath.c_str(), urlpath.size());
|
62
55
|
|
63
56
|
rc = lcb_http3(instance, cookie, &htcmd);
|
64
|
-
lcb_string_release(&urlpath);
|
65
57
|
|
66
58
|
if (rc != LCB_SUCCESS) {
|
67
59
|
return rc;
|
68
60
|
}
|
69
|
-
|
61
|
+
htr->set_callback(flush_cb);
|
70
62
|
return LCB_SUCCESS;
|
71
63
|
}
|
File without changes
|
@@ -16,16 +16,50 @@
|
|
16
16
|
*/
|
17
17
|
|
18
18
|
#define LCBDUR_PRIV_SYMS
|
19
|
+
|
19
20
|
#include <libcouchbase/couchbase.h>
|
20
21
|
#include <libcouchbase/api3.h>
|
21
22
|
#include "internal.h"
|
22
23
|
#include "durability_internal.h"
|
23
24
|
|
24
|
-
|
25
|
+
using namespace lcb::durability;
|
26
|
+
|
27
|
+
namespace {
|
28
|
+
struct CasDurset : public Durset {
|
29
|
+
CasDurset(lcb_t instance_, const lcb_durability_opts_t *options)
|
30
|
+
: Durset(instance_, options), ht(NULL) {
|
31
|
+
}
|
32
|
+
|
33
|
+
virtual ~CasDurset();
|
34
|
+
|
35
|
+
void update(lcb_error_t err, const lcb_RESPOBSERVE *resp);
|
36
|
+
Item& find(const char *s, size_t n) {
|
37
|
+
if (entries.size() == 1) {
|
38
|
+
return entries.back();
|
39
|
+
} else {
|
40
|
+
return *reinterpret_cast<Item*>(genhash_find(ht, s, n));
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
// Override
|
45
|
+
lcb_error_t prepare_schedule();
|
46
|
+
lcb_error_t poll_impl();
|
47
|
+
|
48
|
+
genhash_t *ht;
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
Durset*
|
54
|
+
Durset::createCasDurset(lcb_t instance, const lcb_durability_opts_t *options) {
|
55
|
+
return new CasDurset(instance, options);
|
56
|
+
}
|
57
|
+
|
58
|
+
|
25
59
|
|
26
60
|
/* Called when the criteria is to ensure the key exists somewhow */
|
27
61
|
static int
|
28
|
-
check_positive_durability(
|
62
|
+
check_positive_durability(Item& ent, const lcb_RESPOBSERVE *res)
|
29
63
|
{
|
30
64
|
switch (res->status) {
|
31
65
|
case LCB_OBSERVE_NOT_FOUND:
|
@@ -33,131 +67,122 @@ check_positive_durability(lcb_DURITEM *ent, const lcb_RESPOBSERVE *res)
|
|
33
67
|
/* If we get NOT_FOUND from the master, this means the key
|
34
68
|
* simply does not exists (and we don't have to continue polling) */
|
35
69
|
if (res->ismaster) {
|
36
|
-
|
37
|
-
lcbdur_ent_finish(ent);
|
70
|
+
ent.finish(LCB_KEY_ENOENT);
|
38
71
|
}
|
39
|
-
return
|
72
|
+
return Item::NO_CHANGES;
|
40
73
|
|
41
74
|
case LCB_OBSERVE_PERSISTED:
|
42
|
-
return
|
75
|
+
return Item::UPDATE_PERSISTED | Item::UPDATE_REPLICATED;
|
43
76
|
|
44
77
|
case LCB_OBSERVE_FOUND:
|
45
|
-
return
|
78
|
+
return Item::UPDATE_REPLICATED;
|
46
79
|
|
47
80
|
default:
|
48
|
-
|
49
|
-
|
50
|
-
return 0;
|
81
|
+
ent.finish(LCB_EINTERNAL);
|
82
|
+
return Item::NO_CHANGES;
|
51
83
|
}
|
52
84
|
}
|
53
85
|
|
54
86
|
/* Called when the criteria is to ensure that the key is deleted somehow */
|
55
87
|
static int
|
56
|
-
check_negative_durability(
|
88
|
+
check_negative_durability(Item& ent, const lcb_RESPOBSERVE *res)
|
57
89
|
{
|
58
90
|
switch (res->status) {
|
59
91
|
case LCB_OBSERVE_PERSISTED:
|
60
92
|
case LCB_OBSERVE_FOUND:
|
61
93
|
/* Still there! */
|
62
|
-
return
|
94
|
+
return Item::NO_CHANGES;
|
63
95
|
|
64
96
|
case LCB_OBSERVE_LOGICALLY_DELETED:
|
65
97
|
/* removed from cache, but not actually deleted from disk */
|
66
|
-
return
|
98
|
+
return Item::UPDATE_REPLICATED;
|
67
99
|
|
68
100
|
case LCB_OBSERVE_NOT_FOUND:
|
69
101
|
/* No knowledge of key. */
|
70
|
-
return
|
102
|
+
return Item::UPDATE_PERSISTED | Item::UPDATE_REPLICATED;
|
71
103
|
|
72
104
|
default:
|
73
|
-
|
74
|
-
|
75
|
-
return 0;
|
105
|
+
ent.finish(LCB_EINTERNAL);
|
106
|
+
return Item::NO_CHANGES;
|
76
107
|
}
|
77
108
|
}
|
78
109
|
|
110
|
+
void lcbdur_cas_update(lcb_t, void *dset, lcb_error_t err,
|
111
|
+
const lcb_RESPOBSERVE *resp)
|
112
|
+
{
|
113
|
+
reinterpret_cast<CasDurset*>(dset)->update(err, resp);
|
114
|
+
}
|
115
|
+
|
79
116
|
/* Observe callback. Called internally by observe.c */
|
80
117
|
void
|
81
|
-
|
82
|
-
lcb_DURSET *dset, lcb_error_t err, const lcb_RESPOBSERVE *resp)
|
118
|
+
CasDurset::update(lcb_error_t err, const lcb_RESPOBSERVE *resp)
|
83
119
|
{
|
84
|
-
lcb_DURITEM *ent;
|
85
|
-
int flags;
|
86
|
-
|
87
120
|
if (resp->key == NULL) {
|
88
121
|
/* Last observe response for requests. Start polling after interval */
|
89
|
-
|
122
|
+
on_poll_done();
|
90
123
|
return;
|
91
124
|
}
|
92
125
|
|
93
|
-
|
94
|
-
ent = DSET_ENTRIES(dset);
|
95
|
-
} else {
|
96
|
-
ent = genhash_find(DSET_HT(dset), resp->key, resp->nkey);
|
97
|
-
}
|
126
|
+
Item& ent = find(reinterpret_cast<const char *>(resp->key), resp->nkey);
|
98
127
|
|
99
|
-
if (ent
|
128
|
+
if (ent.done) {
|
100
129
|
/* ignore subsequent errors */
|
101
130
|
return;
|
102
131
|
}
|
103
132
|
|
104
133
|
if (err != LCB_SUCCESS) {
|
105
|
-
|
134
|
+
ent.res().rc = err;
|
106
135
|
return;
|
107
136
|
}
|
108
137
|
|
109
|
-
|
138
|
+
ent.res().nresponses++;
|
110
139
|
if (resp->cas && resp->ismaster) {
|
111
|
-
|
140
|
+
ent.res().cas = resp->cas;
|
112
141
|
|
113
|
-
if (ent
|
114
|
-
|
115
|
-
lcbdur_ent_finish(ent);
|
142
|
+
if (ent.reqcas && ent.reqcas != resp->cas) {
|
143
|
+
ent.finish(LCB_KEY_EEXISTS);
|
116
144
|
return;
|
117
145
|
}
|
118
146
|
}
|
119
147
|
|
120
|
-
|
148
|
+
int flags;
|
149
|
+
if (opts.check_delete) {
|
121
150
|
flags = check_negative_durability(ent, resp);
|
122
151
|
} else {
|
123
152
|
flags = check_positive_durability(ent, resp);
|
124
153
|
}
|
125
154
|
|
126
|
-
|
127
|
-
(void)instance;
|
155
|
+
ent.update(flags, resp->ttp);
|
128
156
|
}
|
129
157
|
|
130
|
-
|
131
|
-
|
158
|
+
lcb_error_t
|
159
|
+
CasDurset::poll_impl()
|
132
160
|
{
|
133
161
|
lcb_MULTICMD_CTX *mctx;
|
134
|
-
size_t ii;
|
135
162
|
lcb_error_t err;
|
136
|
-
lcb_t instance = dset->instance;
|
137
163
|
|
138
|
-
mctx = lcb_observe_ctx_dur_new(
|
164
|
+
mctx = lcb_observe_ctx_dur_new(instance);
|
139
165
|
if (!mctx) {
|
140
166
|
return LCB_CLIENT_ENOMEM;
|
141
167
|
}
|
142
168
|
|
143
|
-
for (ii = 0; ii <
|
169
|
+
for (size_t ii = 0; ii < entries.size(); ii++) {
|
144
170
|
lcb_CMDOBSERVE cmd = { 0 };
|
145
|
-
|
146
|
-
size_t nservers = 0;
|
171
|
+
uint16_t servers[4];
|
147
172
|
|
148
|
-
|
149
|
-
if (ent
|
173
|
+
Item& ent = entries[ii];
|
174
|
+
if (ent.done) {
|
150
175
|
continue;
|
151
176
|
}
|
152
177
|
|
153
|
-
|
178
|
+
size_t nservers = ent.prepare(servers);
|
154
179
|
if (nservers == 0) {
|
155
|
-
|
180
|
+
ent.res().rc = LCB_NO_MATCHING_SERVER;
|
156
181
|
continue;
|
157
182
|
}
|
158
183
|
|
159
|
-
LCB_KREQ_SIMPLE(&cmd.key,
|
160
|
-
LCB_CMD__SETVBID(&cmd, ent
|
184
|
+
LCB_KREQ_SIMPLE(&cmd.key, ent.res().key, ent.res().nkey);
|
185
|
+
LCB_CMD__SETVBID(&cmd, ent.vbid);
|
161
186
|
cmd.servers_ = servers;
|
162
187
|
cmd.nservers_ = nservers;
|
163
188
|
|
@@ -169,38 +194,36 @@ cas_poll(lcb_DURSET *dset)
|
|
169
194
|
}
|
170
195
|
|
171
196
|
lcb_sched_enter(instance);
|
172
|
-
err = mctx->done(mctx,
|
197
|
+
err = mctx->done(mctx, this);
|
173
198
|
mctx = NULL;
|
174
199
|
|
175
200
|
if (err == LCB_SUCCESS) {
|
176
201
|
lcb_sched_leave(instance);
|
177
|
-
|
202
|
+
waiting = 1;
|
178
203
|
} else {
|
179
204
|
lcb_sched_fail(instance);
|
180
205
|
}
|
181
206
|
return err;
|
182
207
|
}
|
183
208
|
|
184
|
-
|
185
|
-
|
209
|
+
lcb_error_t
|
210
|
+
CasDurset::prepare_schedule()
|
186
211
|
{
|
187
|
-
|
188
|
-
|
189
|
-
if (DSET_COUNT(dset) < 2) {
|
212
|
+
Durset::prepare_schedule();
|
213
|
+
if (entries.size() < 2) {
|
190
214
|
return LCB_SUCCESS;
|
191
215
|
}
|
192
216
|
|
193
|
-
|
194
|
-
if (!
|
217
|
+
ht = lcb_hashtable_nc_new(entries.size());
|
218
|
+
if (!ht) {
|
195
219
|
return LCB_CLIENT_ENOMEM;
|
196
220
|
}
|
197
221
|
|
198
|
-
for (ii = 0; ii <
|
222
|
+
for (size_t ii = 0; ii < entries.size(); ++ii) {
|
199
223
|
int mt;
|
200
|
-
|
224
|
+
Item &ent = entries[ii];
|
201
225
|
|
202
|
-
mt = genhash_update(
|
203
|
-
RESFLD(ent, key), RESFLD(ent, nkey), ent, 0);
|
226
|
+
mt = genhash_update(ht, ent.res().key, ent.res().nkey, &ent, 0);
|
204
227
|
if (mt != NEW) {
|
205
228
|
return LCB_DUPLICATE_COMMANDS;
|
206
229
|
}
|
@@ -208,17 +231,10 @@ cas_schedule(lcb_DURSET *dset)
|
|
208
231
|
return LCB_SUCCESS;
|
209
232
|
}
|
210
233
|
|
211
|
-
|
212
|
-
cas_clean(lcb_DURSET *dset)
|
234
|
+
CasDurset::~CasDurset()
|
213
235
|
{
|
214
|
-
if (
|
215
|
-
genhash_free(
|
236
|
+
if (ht) {
|
237
|
+
genhash_free(ht);
|
238
|
+
ht = NULL;
|
216
239
|
}
|
217
240
|
}
|
218
|
-
|
219
|
-
lcbdur_PROCS lcbdur_cas_procs = {
|
220
|
-
cas_poll,
|
221
|
-
NULL, /* ent_add */
|
222
|
-
cas_schedule,
|
223
|
-
cas_clean
|
224
|
-
};
|
@@ -20,32 +20,51 @@
|
|
20
20
|
#include <libcouchbase/api3.h>
|
21
21
|
#include "durability_internal.h"
|
22
22
|
|
23
|
+
using namespace lcb::durability;
|
24
|
+
|
25
|
+
namespace {
|
26
|
+
class SeqnoDurset : public Durset {
|
27
|
+
public:
|
28
|
+
SeqnoDurset(lcb_t instance_, const lcb_durability_opts_t *options)
|
29
|
+
: Durset(instance_, options) {
|
30
|
+
}
|
31
|
+
|
32
|
+
// Override
|
33
|
+
lcb_error_t poll_impl();
|
34
|
+
|
35
|
+
// Override
|
36
|
+
lcb_error_t after_add(Item& item, const lcb_CMDENDURE *cmd);
|
37
|
+
|
38
|
+
void update(const lcb_RESPOBSEQNO *resp);
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
Durset *
|
43
|
+
Durset::createSeqnoDurset(lcb_t instance, const lcb_durability_opts_t *options) {
|
44
|
+
return new SeqnoDurset(instance, options);
|
45
|
+
}
|
46
|
+
|
23
47
|
#define ENT_SEQNO(ent) (ent)->reqseqno
|
24
48
|
|
25
49
|
static void
|
26
|
-
seqno_callback(lcb_t
|
50
|
+
seqno_callback(lcb_t, int, const lcb_RESPBASE *rb)
|
27
51
|
{
|
28
52
|
const lcb_RESPOBSEQNO *resp = (const lcb_RESPOBSEQNO*)rb;
|
29
|
-
char *pp = resp->cookie;
|
30
|
-
lcb_DURITEM *ent;
|
31
53
|
int flags = 0;
|
32
|
-
|
54
|
+
Item *ent = static_cast<Item*>(reinterpret_cast<CallbackCookie*>(resp->cookie));
|
33
55
|
|
34
|
-
pp -= offsetof(lcb_DURITEM, callback);
|
35
|
-
ent = (lcb_DURITEM *)pp;
|
36
56
|
/* Now, process the response */
|
37
|
-
|
38
57
|
if (resp->rc != LCB_SUCCESS) {
|
39
|
-
|
58
|
+
ent->res().rc = resp->rc;
|
40
59
|
goto GT_TALLY;
|
41
60
|
}
|
42
61
|
|
62
|
+
lcb_U64 seqno_mem, seqno_disk;
|
43
63
|
if (resp->old_uuid) {
|
44
64
|
/* Failover! */
|
45
65
|
seqno_mem = seqno_disk = resp->old_seqno;
|
46
66
|
if (seqno_mem < ENT_SEQNO(ent)) {
|
47
|
-
|
48
|
-
lcbdur_ent_finish(ent);
|
67
|
+
ent->finish(LCB_MUTATION_LOST);
|
49
68
|
goto GT_TALLY;
|
50
69
|
}
|
51
70
|
} else {
|
@@ -57,57 +76,52 @@ seqno_callback(lcb_t instance, int ign, const lcb_RESPBASE *rb)
|
|
57
76
|
goto GT_TALLY;
|
58
77
|
}
|
59
78
|
|
60
|
-
flags =
|
79
|
+
flags = Item::UPDATE_REPLICATED;
|
61
80
|
if (seqno_disk >= ENT_SEQNO(ent)) {
|
62
|
-
flags |=
|
81
|
+
flags |= Item::UPDATE_PERSISTED;
|
63
82
|
}
|
64
83
|
|
65
|
-
|
84
|
+
ent->update(flags, resp->server_index);
|
66
85
|
|
67
86
|
GT_TALLY:
|
68
87
|
if (!--ent->parent->waiting) {
|
69
88
|
/* avoid ssertion (wait==0)! */
|
70
89
|
ent->parent->waiting = 1;
|
71
|
-
|
90
|
+
ent->parent->on_poll_done();
|
72
91
|
}
|
73
|
-
|
74
|
-
(void)ign; (void)instance;
|
75
92
|
}
|
76
93
|
|
77
|
-
|
78
|
-
|
94
|
+
lcb_error_t
|
95
|
+
SeqnoDurset::poll_impl()
|
79
96
|
{
|
80
97
|
lcb_error_t ret_err = LCB_EINTERNAL; /* This should never be returned */
|
81
|
-
|
82
|
-
int has_ops = 0;
|
83
|
-
lcb_t instance = dset->instance;
|
98
|
+
bool has_ops = false;
|
84
99
|
|
85
100
|
lcb_sched_enter(instance);
|
86
|
-
for (ii = 0; ii <
|
87
|
-
|
88
|
-
size_t jj, nservers = 0;
|
101
|
+
for (size_t ii = 0; ii < entries.size(); ii++) {
|
102
|
+
Item& ent = entries[ii];
|
89
103
|
lcb_U16 servers[4];
|
90
104
|
lcb_CMDOBSEQNO cmd = { 0 };
|
91
105
|
|
92
|
-
if (ent
|
106
|
+
if (ent.done) {
|
93
107
|
continue;
|
94
108
|
}
|
95
109
|
|
96
|
-
cmd.uuid = ent
|
97
|
-
cmd.vbid = ent
|
110
|
+
cmd.uuid = ent.uuid;
|
111
|
+
cmd.vbid = ent.vbid;
|
98
112
|
cmd.cmdflags = LCB_CMD_F_INTERNAL_CALLBACK;
|
99
|
-
ent
|
113
|
+
ent.callback = seqno_callback;
|
100
114
|
|
101
|
-
|
102
|
-
for (jj = 0; jj < nservers; jj++) {
|
115
|
+
size_t nservers = ent.prepare(servers);
|
116
|
+
for (size_t jj = 0; jj < nservers; jj++) {
|
103
117
|
lcb_error_t err;
|
104
118
|
cmd.server_index = servers[jj];
|
105
|
-
err = lcb_observe_seqno3(instance, &ent
|
119
|
+
err = lcb_observe_seqno3(instance, &ent.callback, &cmd);
|
106
120
|
if (err == LCB_SUCCESS) {
|
107
|
-
|
108
|
-
has_ops =
|
121
|
+
waiting++;
|
122
|
+
has_ops = true;
|
109
123
|
} else {
|
110
|
-
|
124
|
+
ent.res().rc = ret_err = err;
|
111
125
|
}
|
112
126
|
}
|
113
127
|
}
|
@@ -119,8 +133,8 @@ seqno_poll(lcb_DURSET *dset)
|
|
119
133
|
}
|
120
134
|
}
|
121
135
|
|
122
|
-
|
123
|
-
|
136
|
+
lcb_error_t
|
137
|
+
SeqnoDurset::after_add(Item &item, const lcb_CMDENDURE *cmd)
|
124
138
|
{
|
125
139
|
const lcb_MUTATION_TOKEN *stok = NULL;
|
126
140
|
|
@@ -129,29 +143,21 @@ seqno_ent_add(lcb_DURSET *dset, lcb_DURITEM *item, const lcb_CMDENDURE *cmd)
|
|
129
143
|
}
|
130
144
|
|
131
145
|
if (stok == NULL) {
|
132
|
-
lcb_t instance = dset->instance;
|
133
146
|
if (!instance->dcpinfo) {
|
134
147
|
return LCB_DURABILITY_NO_MUTATION_TOKENS;
|
135
148
|
}
|
136
|
-
if (item
|
149
|
+
if (item.vbid >= LCBT_VBCONFIG(instance)->nvb) {
|
137
150
|
return LCB_EINVAL;
|
138
151
|
}
|
139
|
-
stok = instance->dcpinfo + item
|
152
|
+
stok = instance->dcpinfo + item.vbid;
|
140
153
|
if (LCB_MUTATION_TOKEN_ID(stok) == 0) {
|
141
154
|
return LCB_DURABILITY_NO_MUTATION_TOKENS;
|
142
155
|
}
|
143
156
|
}
|
144
157
|
|
145
158
|
/* Set the fields */
|
146
|
-
memset(item
|
147
|
-
item
|
148
|
-
ENT_SEQNO(item) = LCB_MUTATION_TOKEN_SEQ(stok);
|
159
|
+
memset(item.sinfo, 0, sizeof(item.sinfo[0]) * 4);
|
160
|
+
item.uuid = LCB_MUTATION_TOKEN_ID(stok);
|
161
|
+
ENT_SEQNO(&item) = LCB_MUTATION_TOKEN_SEQ(stok);
|
149
162
|
return LCB_SUCCESS;
|
150
163
|
}
|
151
|
-
|
152
|
-
lcbdur_PROCS lcbdur_seqno_procs = {
|
153
|
-
seqno_poll,
|
154
|
-
seqno_ent_add,
|
155
|
-
NULL, /*schedule*/
|
156
|
-
NULL /*clean*/
|
157
|
-
};
|