libcouchbase 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -23,16 +23,7 @@
23
23
  #include "settings.h"
24
24
  #include "hostlist.h"
25
25
  #ifdef __cplusplus
26
- namespace lcb {
27
- namespace io {
28
- struct Connstart;
29
- }
30
- }
31
- typedef lcb::io::Connstart* lcbio_pCONNSTART;
32
26
  extern "C" {
33
- #else
34
- struct lcbio_CONNSTART;
35
- typedef struct lcbio_CONNSTART* lcbio_pCONNSTART;
36
27
  #endif
37
28
 
38
29
  /**
@@ -48,9 +39,11 @@ typedef struct lcbio_CONNSTART* lcbio_pCONNSTART;
48
39
  * @{
49
40
  */
50
41
 
42
+ struct lcbio_CONNSTART;
51
43
  struct lcbio_MGRREQ;
52
44
 
53
45
  /** @brief Pending connection request */
46
+ typedef struct lcbio_CONNSTART *lcbio_pCONNSTART;
54
47
  typedef struct lcbio_MGRREQ *lcbio_pMGRREQ;
55
48
  typedef struct lcbio_TABLE *lcbio_pTABLE;
56
49
  typedef struct lcbio_TIMER *lcbio_pTIMER, *lcbio_pASYNC;
@@ -148,7 +148,7 @@ lcbio_ctx_close_ex(lcbio_CTX *ctx, lcbio_CTXCLOSE_cb cb, void *arg,
148
148
  }
149
149
 
150
150
  oldrc = ctx->sock->refcount;
151
- lcb_log(LOGARGS(ctx, DEBUG), CTX_LOGFMT "Destroying context. Pending Writes=%d, Entered=%s, Socket Refcount=%d", CTX_LOGID(ctx), (int)ctx->npending, (int)ctx->entered ? "true": "false", oldrc);
151
+ lcb_log(LOGARGS(ctx, DEBUG), CTX_LOGFMT "Destroying. PND=%d,ENT=%d,SORC=%d", CTX_LOGID(ctx), (int)ctx->npending, (int)ctx->entered, oldrc);
152
152
 
153
153
  if (cb) {
154
154
  int reusable =
@@ -37,6 +37,22 @@
37
37
  extern "C" {
38
38
  #endif
39
39
 
40
+ typedef struct lcbio_TABLE {
41
+ lcb_io_opt_t p;
42
+ lcb_iomodel_t model;
43
+ lcb_timer_procs timer;
44
+ lcb_loop_procs loop;
45
+
46
+ union {
47
+ struct {
48
+ lcb_ev_procs ev;
49
+ lcb_bsd_procs io;
50
+ } v0;
51
+ lcb_completion_procs completion;
52
+ } u_io;
53
+ unsigned refcount;
54
+ void (*dtor)(void *);
55
+ } lcbio_TABLE;
40
56
 
41
57
  /** Whether the underlying model is event-based */
42
58
  #define IOT_IS_EVENT(iot) ((iot)->model == LCB_IOMODEL_EVENT)
@@ -62,67 +78,6 @@ extern "C" {
62
78
  /** First argument to IO Table */
63
79
  #define IOT_ARG(iot) (iot)->p
64
80
 
65
- typedef struct lcbio_TABLE {
66
- lcb_io_opt_t p;
67
- lcb_iomodel_t model;
68
- lcb_timer_procs timer;
69
- lcb_loop_procs loop;
70
-
71
- union {
72
- struct {
73
- lcb_ev_procs ev;
74
- lcb_bsd_procs io;
75
- } v0;
76
- lcb_completion_procs completion;
77
- } u_io;
78
- unsigned refcount;
79
- void (*dtor)(void *);
80
-
81
- #ifdef __cplusplus
82
- bool is_E() const { return IOT_IS_EVENT(this); }
83
- bool is_C() const { return !is_E(); }
84
- int get_errno() const { return IOT_ERRNO(this); }
85
-
86
- void run_loop() { IOT_START(this); }
87
- void stop_loop() { IOT_STOP(this); }
88
-
89
- int E_connect(lcb_socket_t sock, const sockaddr* saddr, unsigned addrlen) {
90
- return IOT_V0IO(this).connect0(p, sock, saddr, addrlen);
91
- }
92
-
93
- void E_close(lcb_socket_t sock) {
94
- IOT_V0IO(this).close(p, sock);
95
- }
96
-
97
- void *E_event_create() {
98
- return IOT_V0EV(this).create(p);
99
- }
100
-
101
- void E_event_watch(lcb_socket_t fd, void *event, short mask, void *arg,
102
- lcb_ioE_callback cb) {
103
- IOT_V0EV(this).watch(p, fd, event, mask, arg, cb);
104
- }
105
-
106
- void E_event_destroy(void *event) {
107
- IOT_V0EV(this).destroy(p, event);
108
- }
109
-
110
- void E_event_cancel(lcb_socket_t fd, void *event) {
111
- IOT_V0EV(this).cancel(p, fd, event);
112
- }
113
-
114
- void C_close(lcb_sockdata_t *sd) {
115
- IOT_V1(this).close(p, sd);
116
- }
117
-
118
- int C_connect(lcb_sockdata_t *sd, const sockaddr *addr, unsigned addrlen,
119
- lcb_io_connect_cb callback) {
120
- return IOT_V1(this).connect(p, sd, addr, addrlen, callback);
121
- }
122
- #endif
123
-
124
- } lcbio_TABLE;
125
-
126
81
  #ifdef __cplusplus
127
82
  }
128
83
  #endif
@@ -142,7 +142,7 @@ typedef struct {
142
142
  #define LCBIO_CONNREQ_POOLED 2
143
143
  #define LCBIO_CONNREQ_GENERIC 3
144
144
  union {
145
- lcbio_pCONNSTART cs; /**< from lcbio_connect() */
145
+ struct lcbio_CONNSTART *cs; /**< from lcbio_connect() */
146
146
  struct lcbio_MGRREQ *preq; /**< from lcbio_mgr_get() */
147
147
  void *p_generic; /**< Generic pointer. Destroyed via the dtor field */
148
148
  } u;
@@ -314,11 +314,11 @@ start_new_connection(mgr_HOST *he, uint32_t tmo)
314
314
 
315
315
  err = lcb_host_parsez(&tmphost, he->key, 80);
316
316
  if (err != LCB_SUCCESS) {
317
- lcb_log(LOGARGS(he->parent, ERROR), HE_LOGFMT "Could not parse host! Will supply dummy host (I=%p)", HE_LOGID(he), (void*)info);
317
+ lcb_log(LOGARGS(he->parent, ERROR), HE_LOGFMT "Could not parse host! Will supply dummy host", HE_LOGID(he));
318
318
  strcpy(tmphost.host, "BADHOST");
319
319
  strcpy(tmphost.port, "BADPORT");
320
320
  }
321
- lcb_log(LOGARGS(he->parent, TRACE), HE_LOGFMT "New pool entry: I=%p", HE_LOGID(he), (void*)info);
321
+ lcb_log(LOGARGS(he->parent, DEBUG), HE_LOGFMT "Starting connection on I=%p", HE_LOGID(he), (void*)info);
322
322
 
323
323
  info->cs = lcbio_connect(he->parent->io, he->parent->settings, &tmphost,
324
324
  tmo, on_connected, info);
@@ -179,17 +179,10 @@ typedef struct {
179
179
  * packets, or when the packet itself is generated internally rather than
180
180
  * on behalf of an API request.
181
181
  */
182
- typedef struct mc_REQDATAEX {
182
+ typedef struct {
183
183
  const void *cookie; /**< User data */
184
184
  hrtime_t start; /**< Start time */
185
- const mc_REQDATAPROCS *procs; /**< Common routines for the packet */
186
-
187
- #ifdef __cplusplus
188
- mc_REQDATAEX(const void *cookie_,
189
- const mc_REQDATAPROCS &procs_, hrtime_t start_)
190
- : cookie(cookie_), start(start_), procs(&procs_) {
191
- }
192
- #endif
185
+ mc_REQDATAPROCS *procs; /**< Common routines for the packet */
193
186
  } mc_REQDATAEX;
194
187
 
195
188
  /**
@@ -29,8 +29,6 @@
29
29
  #define LOGARGS_T(lvl) LOGARGS(this, lvl)
30
30
 
31
31
  #define LOGFMT "<%s:%s> (SRV=%p,IX=%d) "
32
- #define PKTFMT "OP=0x%x, RC=0x%x, SEQ=%u"
33
- #define PKTARGS(pkt) (pkt).opcode(), (pkt).status(), (pkt).opaque()
34
32
 
35
33
  #define LOGID(server) get_ctx_host(server->connctx), get_ctx_port(server->connctx), (void*)server, server->index
36
34
  #define LOGID_T() LOGID(this)
@@ -99,7 +97,7 @@ void
99
97
  lcb_sched_flush(lcb_t instance)
100
98
  {
101
99
  for (size_t ii = 0; ii < LCBT_NSERVERS(instance); ii++) {
102
- Server *server = instance->get_server(ii);
100
+ Server *server = LCBT_GET_SERVER(instance, ii);
103
101
 
104
102
  if (!server->has_pending()) {
105
103
  continue;
@@ -122,8 +120,8 @@ Server::handle_nmv(MemcachedResponse& resinfo, mc_PACKET *oldpkt)
122
120
  protocol_binary_request_header hdr;
123
121
  lcb_error_t err = LCB_ERROR;
124
122
  lcb_U16 vbid;
125
- lcb::clconfig::Provider *cccp =
126
- instance->confmon->get_provider(lcb::clconfig::CLCONFIG_CCCP);
123
+ clconfig_provider *cccp = lcb_confmon_get_provider(instance->confmon,
124
+ LCB_CLCONFIG_CCCP);
127
125
 
128
126
  mcreq_read_hdr(oldpkt, &hdr);
129
127
  vbid = ntohs(hdr.request.vbucket);
@@ -134,12 +132,12 @@ Server::handle_nmv(MemcachedResponse& resinfo, mc_PACKET *oldpkt)
134
132
 
135
133
  if (resinfo.bodylen() && cccp->enabled) {
136
134
  std::string s(resinfo.body<const char*>(), resinfo.vallen());
137
- err = lcb::clconfig::cccp_update(cccp, curhost->host, s.c_str());
135
+ err = lcb_cccp_update(cccp, curhost->host, s.c_str());
138
136
  }
139
137
 
140
138
  if (err != LCB_SUCCESS) {
141
139
  int bs_options;
142
- if (instance->cur_configinfo->get_origin() == lcb::clconfig::CLCONFIG_CCCP) {
140
+ if (instance->cur_configinfo->origin == LCB_CLCONFIG_CCCP) {
143
141
  /**
144
142
  * XXX: Not enough to see if cccp was enabled, since cccp might
145
143
  * be requested by a user, but would still not actually be active
@@ -148,11 +146,11 @@ Server::handle_nmv(MemcachedResponse& resinfo, mc_PACKET *oldpkt)
148
146
  *
149
147
  * For this reason, we don't use if (cccp->enabled) {...}
150
148
  */
151
- bs_options = BS_REFRESH_THROTTLE;
149
+ bs_options = LCB_BS_REFRESH_THROTTLE;
152
150
  } else {
153
- bs_options = BS_REFRESH_ALWAYS;
151
+ bs_options = LCB_BS_REFRESH_ALWAYS;
154
152
  }
155
- instance->bootstrap(bs_options);
153
+ lcb_bootstrap_common(instance, bs_options);
156
154
  }
157
155
 
158
156
  if (!lcb_should_retry(settings, oldpkt, LCB_NOT_MY_VBUCKET)) {
@@ -166,107 +164,6 @@ Server::handle_nmv(MemcachedResponse& resinfo, mc_PACKET *oldpkt)
166
164
  return true;
167
165
  }
168
166
 
169
- /**
170
- * Determine if this is an error code that we can pass to the user, or can
171
- * otherwise handle "innately"
172
- */
173
- static bool is_fastpath_error(uint16_t rc) {
174
- switch (rc) {
175
- case PROTOCOL_BINARY_RESPONSE_SUCCESS:
176
- case PROTOCOL_BINARY_RESPONSE_KEY_ENOENT:
177
- case PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS:
178
- case PROTOCOL_BINARY_RESPONSE_E2BIG:
179
- case PROTOCOL_BINARY_RESPONSE_NOT_STORED:
180
- case PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL:
181
- case PROTOCOL_BINARY_RESPONSE_ERANGE:
182
- case PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED:
183
- case PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND:
184
- case PROTOCOL_BINARY_RESPONSE_ETMPFAIL:
185
- case PROTOCOL_BINARY_RESPONSE_ENOMEM:
186
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_PATH_ENOENT:
187
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_PATH_EEXISTS:
188
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_PATH_MISMATCH:
189
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_PATH_EINVAL:
190
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_PATH_E2BIG:
191
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_VALUE_CANTINSERT:
192
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_VALUE_ETOODEEP:
193
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_DOC_NOTJSON:
194
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_NUM_ERANGE:
195
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_DELTA_ERANGE:
196
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_INVALID_COMBO:
197
- case PROTOCOL_BINARY_RESPONSE_SUBDOC_MULTI_PATH_FAILURE:
198
- return true;
199
- default:
200
- if (rc >= 0xc0 && rc <= 0xcc) {
201
- // other subdoc?
202
- return true;
203
- } else {
204
- return false;
205
- }
206
- break;
207
- }
208
- }
209
-
210
- /**
211
- * Handle an unknown memcached error
212
- *
213
- * @param mcresp Response which contains the unknown error
214
- * @param[out] newerr more user-friendly based on error map attributes
215
- *
216
- * @return true if this function handled the error specially (by disconnecting)
217
- * or false if normal handling should continue.
218
- */
219
- bool Server::handle_unknown_error(const MemcachedResponse& mcresp,
220
- lcb_error_t& newerr) {
221
-
222
- if (!settings->errmap->isLoaded() || !settings->use_errmap) {
223
- // If there's no error map, just return false
224
- return false;
225
- }
226
-
227
- // Look up the error map definition for this error
228
- const errmap::Error& err = settings->errmap->getError(mcresp.status());
229
-
230
- if (!err.isValid() || err.hasAttribute(errmap::SPECIAL_HANDLING)) {
231
- lcb_log(LOGARGS_T(ERR), LOGFMT "Received error not in error map or requires special handling! " PKTFMT, LOGID_T(), PKTARGS(mcresp));
232
- lcbio_ctx_senderr(connctx, LCB_PROTOCOL_ERROR);
233
- return true;
234
- } else {
235
- lcb_log(LOGARGS_T(WARN), LOGFMT "Received server error %s (0x%x) on packet: " PKTFMT, LOGID_T(), err.shortname.c_str(), err.code, PKTARGS(mcresp));
236
- }
237
-
238
- if (err.hasAttribute(errmap::FETCH_CONFIG)) {
239
- instance->bootstrap(BS_REFRESH_THROTTLE);
240
- }
241
-
242
- if (err.hasAttribute(errmap::TEMPORARY)) {
243
- newerr = LCB_GENERIC_TMPERR;
244
- }
245
-
246
- if (err.hasAttribute(errmap::CONSTRAINT_FAILURE)) {
247
- newerr = LCB_GENERIC_CONSTRAINT_ERR;
248
- }
249
-
250
- if (err.hasAttribute(errmap::AUTH)) {
251
- newerr = LCB_AUTH_ERROR;
252
- }
253
-
254
- if (err.hasAttribute(errmap::SUBDOC) && newerr == LCB_SUCCESS) {
255
- newerr = LCB_GENERIC_SUBDOCERR;
256
- }
257
-
258
- if (err.hasAttribute(errmap::CONN_STATE_INVALIDATED)) {
259
- if (newerr != LCB_SUCCESS) {
260
- newerr = LCB_ERROR;
261
- }
262
- lcbio_ctx_senderr(connctx, newerr);
263
- return true;
264
- }
265
-
266
- return false;
267
-
268
- }
269
-
270
167
  /* This function is called within a loop to process a single packet.
271
168
  *
272
169
  * If a full packet is available, it will process the packet and return
@@ -322,19 +219,12 @@ Server::try_read(lcbio_CTX *ctx, rdb_IOROPE *ior)
322
219
  }
323
220
 
324
221
  if (!request) {
325
- lcb_log(LOGARGS_T(WARN), LOGFMT "Server sent us reply for a timed-out command. (OP=0x%x, RC=0x%x, SEQ=%u)", LOGID_T(), mcresp.opcode(), mcresp.status(), mcresp.opaque());
222
+ lcb_log(LOGARGS_T(WARN), LOGFMT "Found stale packet (OP=0x%x, RC=0x%x, SEQ=%u)", LOGID_T(), mcresp.opcode(), mcresp.status(), mcresp.opaque());
326
223
  rdb_consumed(ior, pktsize);
327
224
  return PKT_READ_COMPLETE;
328
225
  }
329
226
 
330
- lcb_error_t err_override = LCB_SUCCESS;
331
- ReadState rdstate = PKT_READ_COMPLETE;
332
-
333
- /* Check if the status code is one which must be handled carefully by the
334
- * client */
335
- if (is_fastpath_error(mcresp.status())) {
336
- // Nothing here!
337
- } else if (mcresp.status() == PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET) {
227
+ if (mcresp.status() == PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET) {
338
228
  /* consume the header */
339
229
  DO_ASSIGN_PAYLOAD()
340
230
  if (!handle_nmv(mcresp, request)) {
@@ -342,19 +232,13 @@ Server::try_read(lcbio_CTX *ctx, rdb_IOROPE *ior)
342
232
  }
343
233
  DO_SWALLOW_PAYLOAD()
344
234
  goto GT_DONE;
345
- } else if (handle_unknown_error(mcresp, err_override)) {
346
- DO_ASSIGN_PAYLOAD()
347
- mcreq_dispatch_response(this, request, &mcresp, err_override);
348
- DO_SWALLOW_PAYLOAD()
349
- rdstate = PKT_READ_ABORT;
350
- goto GT_DONE;
351
235
  }
352
236
 
353
237
  /* Figure out if the request is 'ufwd' or not */
354
238
  if (!(request->flags & MCREQ_F_UFWD)) {
355
239
  DO_ASSIGN_PAYLOAD();
356
240
  mcresp.bufh = rdb_get_first_segment(ior);
357
- mcreq_dispatch_response(this, request, &mcresp, err_override);
241
+ mcreq_dispatch_response(this, request, &mcresp, LCB_SUCCESS);
358
242
  DO_SWALLOW_PAYLOAD()
359
243
 
360
244
  } else {
@@ -381,7 +265,7 @@ Server::try_read(lcbio_CTX *ctx, rdb_IOROPE *ior)
381
265
  if (is_last) {
382
266
  mcreq_packet_handled(this, request);
383
267
  }
384
- return rdstate;
268
+ return PKT_READ_COMPLETE;
385
269
  }
386
270
 
387
271
  static void
@@ -456,7 +340,7 @@ void Server::purge_single(mc_PACKET *pkt, lcb_error_t err) {
456
340
  hdr.request.opaque,
457
341
  PROTOCOL_BINARY_RESPONSE_EINVAL);
458
342
 
459
- lcb_log(LOGARGS_T(WARN), LOGFMT "Failing command (pkt=%p, opaque=%lu, opcode=0x%x) with error %s", LOGID_T(), (void*)pkt, (unsigned long)pkt->opaque, hdr.request.opcode, lcb_strerror_short(err));
343
+ lcb_log(LOGARGS_T(WARN), LOGFMT "Failing command (pkt=%p, opaque=%lu, opcode=0x%x) with error 0x%x", LOGID_T(), (void*)pkt, (unsigned long)pkt->opaque, hdr.request.opcode, err);
460
344
  int rv = mcreq_dispatch_response(this, pkt, &resp, err);
461
345
  lcb_assert(rv == 0);
462
346
  }
@@ -481,7 +365,8 @@ Server::purge(lcb_error_t error, hrtime_t thresh, hrtime_t *next,
481
365
  }
482
366
 
483
367
  if (affected || policy == REFRESH_ALWAYS) {
484
- instance->bootstrap(BS_REFRESH_THROTTLE|BS_REFRESH_INCRERR);
368
+ lcb_bootstrap_common(instance,
369
+ LCB_BS_REFRESH_THROTTLE|LCB_BS_REFRESH_INCRERR);
485
370
  }
486
371
  return affected;
487
372
  }
@@ -535,7 +420,7 @@ void Server::io_timeout()
535
420
  }
536
421
 
537
422
  uint32_t next_us = next_timeout();
538
- lcb_log(LOGARGS_T(TRACE), LOGFMT "Scheduling next timeout for %u ms. This is not an error", LOGID_T(), next_us / 1000);
423
+ lcb_log(LOGARGS_T(DEBUG), LOGFMT "Scheduling next timeout for %u ms", LOGID_T(), next_us / 1000);
539
424
  lcbio_timer_rearm(io_timer, next_us);
540
425
  lcb_maybe_breakout(instance);
541
426
  }
@@ -580,7 +465,7 @@ Server::handle_connected(lcbio_SOCKET *sock, lcb_error_t err, lcbio_OSERR syserr
580
465
  LCBIO_CONNREQ_CLEAR(&connreq);
581
466
 
582
467
  if (err != LCB_SUCCESS) {
583
- lcb_log(LOGARGS_T(ERR), LOGFMT "Connection attempt failed. Received %s from libcouchbase, received %d from operating system", LOGID_T(), lcb_strerror_short(err), syserr);
468
+ lcb_log(LOGARGS_T(ERR), LOGFMT "Got error for connection! (OS=%d)", LOGID_T(), syserr);
584
469
  if (!maybe_reconnect_on_fake_timeout(err)) {
585
470
  socket_failed(err);
586
471
  }
@@ -609,9 +494,10 @@ Server::handle_connected(lcbio_SOCKET *sock, lcb_error_t err, lcbio_OSERR syserr
609
494
  procs.cb_flush_ready = on_flush_ready;
610
495
  connctx = lcbio_ctx_new(sock, this, &procs);
611
496
  connctx->subsys = "memcached";
612
- flush_start = (mcreq_flushstart_fn)mcserver_flush;
497
+ mc_PIPELINE::flush_start = (mcreq_flushstart_fn)mcserver_flush;
613
498
 
614
499
  uint32_t tmo = next_timeout();
500
+ lcb_log(LOGARGS_T(DEBUG), LOGFMT "Setting initial timeout=%ums", LOGID_T(), tmo/1000);
615
501
  lcbio_timer_rearm(io_timer, tmo);
616
502
  flush();
617
503
  }
@@ -622,7 +508,7 @@ Server::connect()
622
508
  lcbio_pMGRREQ mr = lcbio_mgr_get(instance->memd_sockpool, curhost,
623
509
  default_timeout(), on_connected, this);
624
510
  LCBIO_CONNREQ_MKPOOLED(&connreq, mr);
625
- flush_start = flush_noop;
511
+ mc_PIPELINE::flush_start = flush_noop;
626
512
  state = Server::S_CLEAN;
627
513
  }
628
514
 
@@ -634,7 +520,7 @@ buf_done_cb(mc_PIPELINE *pl, const void *cookie, void *, void *)
634
520
  }
635
521
 
636
522
  Server::Server(lcb_t instance_, int ix)
637
- : mc_PIPELINE(), state(S_CLEAN),
523
+ : state(S_CLEAN),
638
524
  io_timer(lcbio_timer_new(instance_->iotable, this, timeout_server)),
639
525
  instance(instance_),
640
526
  settings(lcb_settings_ref2(instance_->settings)),
@@ -643,10 +529,11 @@ Server::Server(lcb_t instance_, int ix)
643
529
  connctx(NULL),
644
530
  curhost(new lcb_host_t())
645
531
  {
532
+ std::memset(static_cast<mc_PIPELINE*>(this), 0, sizeof(mc_PIPELINE));
646
533
  mcreq_pipeline_init(this);
647
- flush_start = (mcreq_flushstart_fn)server_connect;
648
- buf_done_callback = buf_done_cb;
649
- index = ix;
534
+ mc_PIPELINE::flush_start = (mcreq_flushstart_fn)server_connect;
535
+ mc_PIPELINE::buf_done_callback = buf_done_cb;
536
+ mc_PIPELINE::index = ix;
650
537
 
651
538
  std::memset(&connreq, 0, sizeof connreq);
652
539
  std::memset(curhost, 0, sizeof *curhost);
@@ -693,7 +580,7 @@ static void
693
580
  on_error(lcbio_CTX *ctx, lcb_error_t err)
694
581
  {
695
582
  Server *server = Server::get(ctx);
696
- lcb_log(LOGARGS(server, WARN), LOGFMT "Got socket error %s", LOGID(server), lcb_strerror_short(err));
583
+ lcb_log(LOGARGS(server, WARN), LOGFMT "Got socket error 0x%x", LOGID(server), err);
697
584
  if (server->check_closed()) {
698
585
  return;
699
586
  }
@@ -749,15 +636,13 @@ Server::start_errored_ctx(State next_state)
749
636
  return;
750
637
  } else {
751
638
  /* Not closed but don't have a current context */
639
+ mc_PIPELINE::flush_start = (mcreq_flushstart_fn)server_connect;
752
640
  if (has_pending()) {
753
641
  if (!lcbio_timer_armed(io_timer)) {
754
642
  /* TODO: Maybe throttle reconnection attempts? */
755
643
  lcbio_timer_rearm(io_timer, default_timeout());
756
644
  }
757
645
  connect();
758
- } else {
759
- // Connect once someone actually wants a connection.
760
- flush_start = (mcreq_flushstart_fn)server_connect;
761
646
  }
762
647
  }
763
648
 
@@ -771,7 +656,7 @@ Server::start_errored_ctx(State next_state)
771
656
  /* Close the socket not to leak resources */
772
657
  lcbio_shutdown(lcbio_ctx_sock(ctx));
773
658
  if (next_state == Server::S_ERRDRAIN) {
774
- flush_start = (mcreq_flushstart_fn)flush_errdrain;
659
+ mc_PIPELINE::flush_start = (mcreq_flushstart_fn)flush_errdrain;
775
660
  }
776
661
  } else {
777
662
  finalize_errored_ctx();
@@ -816,6 +701,7 @@ Server::finalize_errored_ctx()
816
701
  /* Otherwise, cycle the state back to CLEAN and reinit
817
702
  * the connection */
818
703
  state = Server::S_CLEAN;
704
+ mc_PIPELINE::flush_start = (mcreq_flushstart_fn)server_connect;
819
705
  connect();
820
706
  }
821
707
  }
@@ -837,3 +723,8 @@ Server::check_closed()
837
723
  finalize_errored_ctx();
838
724
  return 1;
839
725
  }
726
+
727
+ int
728
+ mcserver_supports_compression(mc_SERVER *server) {
729
+ return server->compsupport;
730
+ }