libcouchbase 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/.gitignore +2 -0
  3. data/ext/libcouchbase/CMakeLists.txt +5 -7
  4. data/ext/libcouchbase/README.markdown +2 -2
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +49 -0
  6. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  7. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
  8. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +2 -1
  9. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  10. data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
  11. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  12. data/ext/libcouchbase/cmake/source_files.cmake +34 -14
  13. data/ext/libcouchbase/configure.pl +1 -1
  14. data/ext/libcouchbase/contrib/genhash/genhash.h +6 -0
  15. data/ext/libcouchbase/include/libcouchbase/auth.h +10 -0
  16. data/ext/libcouchbase/include/libcouchbase/couchbase.h +10 -0
  17. data/ext/libcouchbase/include/libcouchbase/error.h +7 -0
  18. data/ext/libcouchbase/include/libcouchbase/n1ql.h +13 -1
  19. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  20. data/ext/libcouchbase/include/libcouchbase/subdoc.h +9 -0
  21. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  22. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  23. data/ext/libcouchbase/include/memcached/protocol_binary.h +21 -1132
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  26. data/ext/libcouchbase/src/README.md +0 -2
  27. data/ext/libcouchbase/src/auth-priv.h +1 -0
  28. data/ext/libcouchbase/src/auth.cc +10 -0
  29. data/ext/libcouchbase/src/bootstrap.cc +216 -0
  30. data/ext/libcouchbase/src/bootstrap.h +50 -39
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +455 -0
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +528 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +115 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +407 -386
  37. data/ext/libcouchbase/src/bucketconfig/confmon.cc +378 -0
  38. data/ext/libcouchbase/src/cbft.cc +22 -27
  39. data/ext/libcouchbase/src/cntl.cc +24 -24
  40. data/ext/libcouchbase/src/connspec.cc +30 -1
  41. data/ext/libcouchbase/src/connspec.h +17 -0
  42. data/ext/libcouchbase/src/dns-srv.cc +143 -0
  43. data/ext/libcouchbase/src/{dump.c → dump.cc} +8 -11
  44. data/ext/libcouchbase/src/getconfig.cc +73 -0
  45. data/ext/libcouchbase/src/handler.cc +84 -85
  46. data/ext/libcouchbase/src/hostlist.cc +0 -1
  47. data/ext/libcouchbase/src/hostlist.h +6 -1
  48. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  49. data/ext/libcouchbase/src/http/http.cc +9 -29
  50. data/ext/libcouchbase/src/http/http.h +1 -34
  51. data/ext/libcouchbase/src/http/http_io.cc +22 -26
  52. data/ext/libcouchbase/src/instance.cc +102 -28
  53. data/ext/libcouchbase/src/internal.h +47 -29
  54. data/ext/libcouchbase/src/jsparse/parser.cc +146 -202
  55. data/ext/libcouchbase/src/jsparse/parser.h +91 -98
  56. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  57. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  58. data/ext/libcouchbase/src/lcbio/connect.cc +562 -0
  59. data/ext/libcouchbase/src/lcbio/connect.h +9 -2
  60. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  61. data/ext/libcouchbase/src/lcbio/iotable.h +61 -16
  62. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  63. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  64. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  65. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  66. data/ext/libcouchbase/src/mcserver/mcserver.cc +723 -0
  67. data/ext/libcouchbase/src/mcserver/mcserver.h +160 -70
  68. data/ext/libcouchbase/src/mcserver/negotiate.cc +118 -152
  69. data/ext/libcouchbase/src/mcserver/negotiate.h +85 -74
  70. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  71. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  72. data/ext/libcouchbase/src/n1ql/n1ql.cc +56 -32
  73. data/ext/libcouchbase/src/{newconfig.c → newconfig.cc} +42 -70
  74. data/ext/libcouchbase/src/nodeinfo.cc +4 -8
  75. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  76. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  77. data/ext/libcouchbase/src/operations/{durability-cas.c → durability-cas.cc} +92 -76
  78. data/ext/libcouchbase/src/operations/{durability-seqno.c → durability-seqno.cc} +55 -49
  79. data/ext/libcouchbase/src/operations/durability.cc +643 -0
  80. data/ext/libcouchbase/src/operations/durability_internal.h +212 -124
  81. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  82. data/ext/libcouchbase/src/operations/{observe-seqno.c → observe-seqno.cc} +5 -8
  83. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +69 -94
  84. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  85. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  86. data/ext/libcouchbase/src/operations/{stats.c → stats.cc} +66 -78
  87. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  88. data/ext/libcouchbase/src/operations/subdoc.cc +38 -18
  89. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  90. data/ext/libcouchbase/src/packetutils.h +200 -137
  91. data/ext/libcouchbase/src/probes.d +1 -1
  92. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +3 -4
  93. data/ext/libcouchbase/src/retryq.cc +394 -0
  94. data/ext/libcouchbase/src/retryq.h +116 -104
  95. data/ext/libcouchbase/src/settings.h +2 -1
  96. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  97. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  98. data/ext/libcouchbase/src/trace.h +8 -8
  99. data/ext/libcouchbase/src/vbucket/vbucket.c +0 -1
  100. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  101. data/ext/libcouchbase/src/views/docreq.h +24 -30
  102. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  103. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  104. data/ext/libcouchbase/src/{wait.c → wait.cc} +12 -17
  105. data/ext/libcouchbase/tests/basic/t_connstr.cc +89 -50
  106. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -78
  107. data/ext/libcouchbase/tests/basic/t_packet.cc +35 -42
  108. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  109. data/ext/libcouchbase/tests/iotests/t_confmon.cc +94 -111
  110. data/ext/libcouchbase/tests/iotests/t_sched.cc +1 -2
  111. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  112. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  113. data/lib/libcouchbase/version.rb +1 -1
  114. metadata +36 -39
  115. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  116. data/ext/libcouchbase/src/bootstrap.c +0 -269
  117. data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +0 -495
  118. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  119. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  120. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  121. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  122. data/ext/libcouchbase/src/getconfig.c +0 -100
  123. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  124. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  125. data/ext/libcouchbase/src/mcserver/mcserver.c +0 -784
  126. data/ext/libcouchbase/src/operations/durability.c +0 -668
  127. data/ext/libcouchbase/src/packetutils.c +0 -60
  128. data/ext/libcouchbase/src/retryq.c +0 -424
  129. data/ext/libcouchbase/src/simplestring.c +0 -211
  130. data/ext/libcouchbase/src/simplestring.h +0 -228
  131. data/ext/libcouchbase/src/ssobuf.h +0 -82
  132. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  133. data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -18,12 +18,52 @@
18
18
  #ifndef LCB_DURABILITY_INTERNAL_H
19
19
  #define LCB_DURABILITY_INTERNAL_H
20
20
 
21
- #include "simplestring.h"
22
- #include "ssobuf.h"
23
21
  #ifdef __cplusplus
22
+ #include "mctx-helper.h"
23
+
24
24
  extern "C" {
25
25
  #endif
26
26
 
27
+ /**
28
+ * @name internal durability functions
29
+ * These functions are used internally beyond the durability module.
30
+ * @{
31
+ */
32
+
33
+ /**
34
+ * Called from the OBSERVE codebase to update an item's status for CAS-based
35
+ * observe
36
+ */
37
+ void lcbdur_cas_update(lcb_t, void *dset, lcb_error_t, const lcb_RESPOBSERVE *);
38
+
39
+ /**
40
+ * Called from the OBSERVE codebase to update an item's status for seqno-based
41
+ * observe
42
+ */
43
+ void lcbdur_update_seqno(lcb_t, void *dset, const lcb_RESPOBSEQNO*);
44
+
45
+ /** Indicate that this durability command context is for an original storage op */
46
+ void lcbdurctx_set_durstore(lcb_MULTICMD_CTX *ctx, int enabled);
47
+
48
+ void lcbdur_destroy(void *dset);
49
+
50
+ /** Called from durability-cas to request an OBSERVE with a special callback */
51
+ lcb_MULTICMD_CTX *lcb_observe_ctx_dur_new(lcb_t instance);
52
+
53
+ /**@}
54
+ *
55
+ * The rest of this file is internal to the various durability operations and
56
+ * is not accessed by the rest of the codebase
57
+ */
58
+
59
+ #ifdef __cplusplus
60
+ }
61
+ #endif
62
+
63
+ #ifdef LCBDUR_PRIV_SYMS
64
+ namespace lcb {
65
+ namespace durability {
66
+
27
67
  /**
28
68
  * Here is the internal API for the durability functions.
29
69
  *
@@ -42,158 +82,206 @@ extern "C" {
42
82
  * persisted to or replicated to. This is tied to a given mc_SERVER
43
83
  * instance.
44
84
  */
45
- typedef struct {
46
- const mc_SERVER *server; /**< Server pointer (for comparison only) */
85
+ struct ServerInfo {
86
+ const lcb::Server *server; /**< Server pointer (for comparison only) */
47
87
  lcb_U16 persisted; /**< Exists on server */
48
88
  lcb_U16 exists; /**< Persisted to server */
49
- } lcbdur_SERVINFO;
89
+
90
+ ServerInfo() : server(NULL), persisted(0), exists(0) {
91
+ }
92
+
93
+ void clear() {
94
+ server = NULL;
95
+ persisted = 0;
96
+ exists = 0;
97
+ }
98
+ };
99
+
100
+ struct Durset;
101
+
102
+ // For use in conjunction with MCREQ_F_PRIVCALLBACK
103
+ struct CallbackCookie {
104
+ lcb_RESPCALLBACK callback;
105
+ };
50
106
 
51
107
  /**Information a single entry in a durability set. Each entry contains a single
52
108
  * key */
53
- typedef struct lcb_DURITEM_st {
109
+ struct Item : public CallbackCookie {
110
+ /**
111
+ * Returns true if the entry is complete, false otherwise. This only assumes
112
+ * successful entries.
113
+ */
114
+ bool is_all_done() const;
115
+
116
+ /**
117
+ * Determine if this item has been satisfied on a specific server. This
118
+ * function is used to determine if a probe should be sent to the server.
119
+ *
120
+ * If there are no items "tied" to the server (because they have all been
121
+ * completed) then we employ a bandwidth saving optimization by not sending
122
+ * additional probes to it.
123
+ *
124
+ * @param info Server to check against
125
+ * @param is_master If this server is the master for the item's vbucket
126
+ *
127
+ * @return true if the item is both persisted and replicated on the server,
128
+ * OR if the item has been replicated, but replication is not
129
+ * required for the item.
130
+ */
131
+ bool is_server_done(const ServerInfo& info, bool is_master) const;
132
+
133
+ /**
134
+ * Updates the state of the given entry and synchronizes it with the
135
+ * current server list.
136
+ *
137
+ * Specifically this function will return a list of
138
+ * servers which still need to be contacted, and will increment internal
139
+ * counters on behalf of those (still active) servers which the item has
140
+ * already been replicated to (and persisted to, if requested).
141
+ *
142
+ * This will invalidate any cached information of the cluster configuration
143
+ * in respect to this item has changed -- this includes things like servers
144
+ * moving indices or being recreated entirely.
145
+ *
146
+ * This function should be called during poll().
147
+ * @param[out] ixarray An array of server indices which should be queried
148
+ * @return the number of effective entries in the array.
149
+ */
150
+ size_t prepare(uint16_t ixarray[4]);
151
+
152
+ enum UpdateFlags {
153
+ NO_CHANGES = 0x00,
154
+ UPDATE_PERSISTED = 0x01,
155
+ UPDATE_REPLICATED = 0x02
156
+ };
157
+
158
+ /**
159
+ * Update an item's status.
160
+ * @param flags OR'd set of UPDATE_PERSISTED and UPDATE_REPLICATED
161
+ * @param ix The server index
162
+ */
163
+ void update(int flags, int srvix);
164
+
165
+ /**
166
+ * Set the logical state of the entry to done, and invoke the callback.
167
+ * It is safe to call this multiple times
168
+ */
169
+ void finish();
170
+
171
+ void finish(lcb_error_t err) {
172
+ result.rc = err;
173
+ finish();
174
+ }
175
+
176
+ lcb_RESPENDURE& res() { return result; }
177
+ const lcb_RESPENDURE& res() const { return result; }
178
+ ServerInfo* get_server_info(int index);
179
+
54
180
  lcb_U64 reqcas; /**< Last known CAS for the user */
55
181
  lcb_U64 reqseqno; /**< Last known seqno for the user */
56
182
  lcb_U64 uuid;
57
183
  lcb_RESPENDURE result; /**< Result to be passed to user */
58
- struct lcb_DURSET_st *parent;
59
- lcb_RESPCALLBACK callback; /**< For F_INTERNAL_CALLBACK */
184
+ Durset *parent;
60
185
  lcb_U16 vbid; /**< vBucket ID (computed via hashkey) */
61
186
  lcb_U8 done; /**< Whether we have a conclusive result for this entry */
62
187
 
63
188
  /** Array of servers which have satisfied constraints */
64
- lcbdur_SERVINFO sinfo[4];
65
- } lcb_DURITEM;
66
-
67
- struct lcbdur_PROCS_st;
68
-
69
- enum {
70
- LCBDUR_STATE_OBSPOLL = 0,
71
- LCBDUR_STATE_INIT,
72
- LCBDUR_STATE_TIMEOUT,
73
- LCBDUR_STATE_IGNORE
189
+ ServerInfo sinfo[4];
74
190
  };
75
191
 
76
192
  /**
77
193
  * A collection encompassing one or more entries which are to be checked for
78
194
  * persistence
79
195
  */
80
- typedef struct lcb_DURSET_st {
81
- lcb_MULTICMD_CTX mctx; /**< Base class returned to user for scheduling */
82
- lcb_DURABILITYOPTSv0 opts; /**< Sanitized user options */
83
- LCB_SSOBUF_DECLARE(lcb_DURITEM) entries_;
84
- unsigned nremaining; /**< Number of entries remaining to poll for */
85
- int waiting; /**< Set if currently awaiting an observe callback */
86
- unsigned refcnt; /**< Reference count */
87
- unsigned next_state; /**< Internal state */
88
- lcb_error_t lasterr;
89
- int is_durstore; /** Whether the callback should be DURSTORE */
90
- lcb_string kvbufs; /**< Backing storage for key buffers */
91
- const void *cookie; /**< User cookie */
92
- hrtime_t ns_timeout; /**< Timestamp of next timeout */
93
- void *timer;
94
- lcb_t instance;
95
- void *impldata;
96
- } lcb_DURSET;
97
-
98
- typedef struct lcbdur_PROCS_st {
99
- lcb_error_t (*poll)(lcb_DURSET *dset);
100
- lcb_error_t (*ent_add)(lcb_DURSET*,lcb_DURITEM*,const lcb_CMDENDURE*);
101
- lcb_error_t (*schedule)(lcb_DURSET*);
102
- void (*clean)(lcb_DURSET*);
103
- } lcbdur_PROCS;
104
-
105
- void
106
- lcbdur_cas_update(lcb_t instance, lcb_DURSET *dset, lcb_error_t err,
107
- const lcb_RESPOBSERVE *resp);
108
- void
109
- lcbdur_update_seqno(lcb_t instance, lcb_DURSET *dset,
110
- const lcb_RESPOBSEQNO *resp);
111
-
112
- /** Indicate that this durability command context is for an original storage op */
113
- void
114
- lcbdurctx_set_durstore(lcb_MULTICMD_CTX *ctx, int enabled);
196
+ struct Durset : public MultiCmdContext {
197
+ /**
198
+ * Call this when the polling method (poll_impl()) has completed. This will
199
+ * trigger a new poll after the interval.
200
+ */
201
+ void on_poll_done();
115
202
 
116
- lcb_MULTICMD_CTX *
117
- lcb_observe_ctx_dur_new(lcb_t instance);
203
+ void incref() { refcnt++; }
118
204
 
119
- #ifdef LCBDUR_PRIV_SYMS
205
+ /**
206
+ * Decrement the refcount for the 'dset'. When it hits zero then the dset is
207
+ * freed
208
+ */
209
+ void decref() { if (!--refcnt) { delete this; } }
120
210
 
121
- extern lcbdur_PROCS lcbdur_cas_procs;
122
- extern lcbdur_PROCS lcbdur_seqno_procs;
211
+ enum State {
212
+ STATE_OBSPOLL,
213
+ STATE_INIT,
214
+ STATE_TIMEOUT,
215
+ STATE_IGNORE
216
+ };
123
217
 
124
- #define RESFLD(e, f) (e)->result.f
125
- #define ENT_CAS(e) (e)->request.options.cas
126
- #define DSET_OPTFLD(ds, opt) (ds)->opts.opt
127
- #define DSET_COUNT(ds) (ds)->entries_.count
128
- #define DSET_ENTRIES(ds) LCB_SSOBUF_ARRAY(&(ds)->entries_, lcb_DURITEM)
129
- #define DSET_PROCS(ds) ((ds)->opts.pollopts == LCB_DURABILITY_MODE_CAS \
130
- ? (&lcbdur_cas_procs) : (&lcbdur_seqno_procs))
131
- #define ENT_NUMINFO(ent) 4
218
+ /**
219
+ * Schedules us to be notified with the given state within a particular amount
220
+ * of time. This is used both for the timeout and for the interval
221
+ */
222
+ void switch_state(State state);
132
223
 
133
- /**
134
- * Returns true if the entry is complete, false otherwise. This only assumes
135
- * successful entries.
136
- */
137
- int lcbdur_ent_check_done(lcb_DURITEM *ent);
224
+ /**
225
+ * Called from mctx_schedule(). This allows implementations to do any
226
+ * additional bookeeping, having guaranteed that all items are now
227
+ * added.
228
+ */
229
+ virtual lcb_error_t prepare_schedule() {
230
+ return LCB_SUCCESS;
231
+ }
138
232
 
139
- /**
140
- * Set the logical state of the entry to done, and invoke the callback.
141
- * It is safe to call this multiple times
142
- */
143
- void lcbdur_ent_finish(lcb_DURITEM *ent);
233
+ /**
234
+ * Called from mctx_add. Called to register any item-specific data (i.e.
235
+ * to associate item data with internal structures)
236
+ * @param itm the newly added item
237
+ * @param the original command, for more context
238
+ */
239
+ virtual lcb_error_t after_add(Item&, const lcb_CMDENDURE*) {
240
+ return LCB_SUCCESS;
241
+ }
144
242
 
145
- /**
146
- * Called when the last (primitive) OBSERVE response is received for the entry.
147
- */
148
- void lcbdur_reqs_done(lcb_DURSET *dset);
243
+ /**
244
+ * Called to actually check for persistence/replication. This must be
245
+ * implemented.
246
+ */
247
+ virtual lcb_error_t poll_impl() = 0;
149
248
 
150
- /**
151
- * Updates the state of the given entry and synchronizes it with the
152
- * current server list.
153
- *
154
- * Specifically this function will return a list of
155
- * servers which still need to be contacted, and will increment internal
156
- * counters on behalf of those (still active) servers which the item has
157
- * already been replicated to (and persisted to, if requested).
158
- *
159
- * This will invalidate any cached information of the cluster configuration
160
- * in respect to this item has changed -- this includes things like servers
161
- * moving indices or being recreated entirely.
162
- *
163
- * This function should be called during poll().
164
- * @param item The item to update
165
- * @param[out] ixarray An array of server indices which should be queried
166
- * @param[out] nitems the number of effective entries in the array.
167
- */
168
- void
169
- lcbdur_prepare_item(lcb_DURITEM *item, lcb_U16 *ixarray, size_t *nitems);
249
+ virtual ~Durset();
250
+ Durset(lcb_t instance, const lcb_durability_opts_t* options);
170
251
 
171
- #define LCBDUR_UPDATE_PERSISTED 1
172
- #define LCBDUR_UPDATE_REPLICATED 2
173
- /**
174
- * Update an item's status.
175
- * @param item The item to update
176
- * @param flags OR'd set of UPDATE_PERSISTED and UPDATE_REPLICATED
177
- * @param ix The server index
178
- */
179
- void
180
- lcbdur_update_item(lcb_DURITEM *item, int flags, int ix);
252
+ // Implementation for MULTICMD_CTX
253
+ lcb_error_t MCTX_done(const void *cookie);
254
+ lcb_error_t MCTX_addcmd(const lcb_CMDBASE *cmd);
255
+ void MCTX_fail();
181
256
 
182
- lcbdur_SERVINFO *
183
- lcbdur_ent_getinfo(lcb_DURITEM *item, int srvix);
257
+ /**
258
+ * This function calls poll_impl(). The implementation should then call
259
+ * on_poll_done() once the polling is finished
260
+ */
261
+ inline void poll();
184
262
 
185
- /**
186
- * Schedules us to be notified with the given state within a particular amount
187
- * of time. This is used both for the timeout and for the interval
188
- */
189
- void lcbdur_switch_state(lcb_DURSET *dset, unsigned int state);
190
- #define lcbdur_ref(dset) (dset)->refcnt++;
191
- void lcbdur_unref(lcb_DURSET *dset);
263
+ /** Called after timeouts and intervals. */
264
+ inline void tick();
192
265
 
193
- #endif /* PRIV_SYMS */
266
+ static Durset* createCasDurset(lcb_t, const lcb_durability_opts_t*);
267
+ static Durset* createSeqnoDurset(lcb_t, const lcb_durability_opts_t*);
194
268
 
195
- #ifdef __cplusplus
196
- }
197
- #endif
269
+ lcb_DURABILITYOPTSv0 opts; /**< Sanitized user options */
270
+ std::vector<Item> entries;
271
+ unsigned nremaining; /**< Number of entries remaining to poll for */
272
+ int waiting; /**< Set if currently awaiting an observe callback */
273
+ unsigned refcnt; /**< Reference count */
274
+ State next_state; /**< Internal state */
275
+ lcb_error_t lasterr;
276
+ bool is_durstore; /** Whether the callback should be DURSTORE */
277
+ std::string kvbufs; /**< Backing storage for key buffers */
278
+ const void *cookie; /**< User cookie */
279
+ hrtime_t ns_timeout; /**< Timestamp of next timeout */
280
+ void *timer;
281
+ lcb_t instance;
282
+ };
198
283
 
199
- #endif
284
+ } // namespace durability
285
+ } // namespace lcb
286
+ #endif // __cplusplus
287
+ #endif // LCB_DURABILITY_INTERNAL_H
@@ -181,28 +181,31 @@ lcb_unlock(lcb_t instance, const void *cookie, lcb_size_t num,
181
181
  }
182
182
  }
183
183
 
184
- typedef struct {
185
- mc_REQDATAEX base;
184
+ struct RGetCookie : mc_REQDATAEX {
185
+ RGetCookie(const void *cookie, lcb_t instance, lcb_replica_t, int vb);
186
+ void decref() {
187
+ if (!--remaining) {
188
+ delete this;
189
+ }
190
+ }
191
+
186
192
  unsigned r_cur;
187
193
  unsigned r_max;
188
194
  int remaining;
189
195
  int vbucket;
190
196
  lcb_replica_t strategy;
191
197
  lcb_t instance;
192
- } rget_cookie;
198
+ };
193
199
 
194
200
  static void rget_dtor(mc_PACKET *pkt) {
195
- rget_cookie *rck = (rget_cookie *)pkt->u_rdata.exdata;
196
- if (! --rck->remaining) {
197
- free(rck);
198
- }
201
+ static_cast<RGetCookie*>(pkt->u_rdata.exdata)->decref();
199
202
  }
200
203
 
201
204
  static void
202
- rget_callback(mc_PIPELINE *pl, mc_PACKET *pkt, lcb_error_t err, const void *arg)
205
+ rget_callback(mc_PIPELINE *, mc_PACKET *pkt, lcb_error_t err, const void *arg)
203
206
  {
204
- rget_cookie *rck = (rget_cookie *)pkt->u_rdata.exdata;
205
- lcb_RESPGET *resp = (void *)arg;
207
+ RGetCookie *rck = static_cast<RGetCookie*>(pkt->u_rdata.exdata);
208
+ lcb_RESPGET *resp = reinterpret_cast<lcb_RESPGET*>(const_cast<void*>(arg));
206
209
  lcb_RESPCALLBACK callback;
207
210
  lcb_t instance = rck->instance;
208
211
 
@@ -247,11 +250,7 @@ rget_callback(mc_PIPELINE *pl, mc_PACKET *pkt, lcb_error_t err, const void *arg)
247
250
  rck->remaining = 2;
248
251
  }
249
252
  }
250
-
251
- if (!--rck->remaining) {
252
- free(rck);
253
- }
254
- (void)pl;
253
+ rck->decref();
255
254
  }
256
255
 
257
256
  static mc_REQDATAPROCS rget_procs = {
@@ -259,6 +258,13 @@ static mc_REQDATAPROCS rget_procs = {
259
258
  rget_dtor
260
259
  };
261
260
 
261
+ RGetCookie::RGetCookie(const void *cookie_, lcb_t instance_,
262
+ lcb_replica_t strategy_, int vbucket_)
263
+ : mc_REQDATAEX(cookie_, rget_procs, gethrtime()),
264
+ r_cur(0), r_max(LCBT_NREPLICAS(instance_)), remaining(0),
265
+ vbucket(vbucket_), strategy(strategy_), instance(instance_) {
266
+ }
267
+
262
268
  LIBCOUCHBASE_API
263
269
  lcb_error_t
264
270
  lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
@@ -271,7 +277,6 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
271
277
  int vbid, ixtmp;
272
278
  protocol_binary_request_header req;
273
279
  unsigned r0, r1 = 0;
274
- rget_cookie *rck = NULL;
275
280
 
276
281
  if (LCB_KEYBUF_IS_EMPTY(&cmd->key)) {
277
282
  return LCB_EMPTY_KEY;
@@ -323,15 +328,7 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
323
328
  }
324
329
 
325
330
  /* Initialize the cookie */
326
- rck = calloc(1, sizeof(*rck));
327
- rck->base.cookie = cookie;
328
- rck->base.start = gethrtime();
329
- rck->base.procs = &rget_procs;
330
- rck->strategy = cmd->strategy;
331
- rck->r_cur = r0;
332
- rck->r_max = LCBT_NREPLICAS(instance);
333
- rck->instance = instance;
334
- rck->vbucket = vbid;
331
+ RGetCookie *rck = new RGetCookie(cookie, instance, cmd->strategy, vbid);
335
332
 
336
333
  /* Initialize the packet */
337
334
  req.request.magic = PROTOCOL_BINARY_REQ;
@@ -343,6 +340,7 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
343
340
  req.request.keylen = htons((lcb_uint16_t)cmd->key.contig.nbytes);
344
341
  req.request.bodylen = htonl((lcb_uint32_t)cmd->key.contig.nbytes);
345
342
 
343
+ rck->r_cur = r0;
346
344
  do {
347
345
  int curix;
348
346
  mc_PIPELINE *pl;
@@ -359,7 +357,7 @@ lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
359
357
  return LCB_CLIENT_ENOMEM;
360
358
  }
361
359
 
362
- pkt->u_rdata.exdata = &rck->base;
360
+ pkt->u_rdata.exdata = rck;
363
361
  pkt->flags |= MCREQ_F_REQEXT;
364
362
 
365
363
  mcreq_reserve_key(pl, pkt, sizeof(req.bytes), &cmd->key);