couchbase 3.2.0 → 3.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +24 -18
- package/binding.gyp +88 -85
- package/deps/lcb/CMakeLists.txt +1 -1
- package/deps/lcb/CONTRIBUTING.md +1 -1
- package/deps/lcb/README.markdown +2 -2
- package/deps/lcb/RELEASE_NOTES.markdown +99 -14
- package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
- package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
- package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -7
- package/deps/lcb/doc/Doxyfile +1 -1
- package/deps/lcb/example/CMakeLists.txt +4 -4
- package/deps/lcb/example/libuvdirect/main.c +39 -12
- package/deps/lcb/example/minimal/durability.cc +149 -0
- package/deps/lcb/example/minimal/query.c +11 -9
- package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
- package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
- package/deps/lcb/include/libcouchbase/couchbase.h +80 -5
- package/deps/lcb/include/libcouchbase/error.h +2 -0
- package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
- package/deps/lcb/include/libcouchbase/tracing.h +2 -2
- package/deps/lcb/include/memcached/protocol_binary.h +21 -0
- package/deps/lcb/libcouchbase.gyp +347 -349
- package/deps/lcb/packaging/deb/control +1 -1
- package/deps/lcb/src/analytics/analytics_handle.cc +13 -5
- package/deps/lcb/src/analytics/analytics_handle.hh +29 -0
- package/deps/lcb/src/bootstrap.cc +6 -3
- package/deps/lcb/src/capi/cmd_analytics.cc +12 -1
- package/deps/lcb/src/capi/cmd_analytics.hh +30 -0
- package/deps/lcb/src/capi/cmd_counter.hh +23 -0
- package/deps/lcb/src/capi/cmd_exists.hh +24 -1
- package/deps/lcb/src/capi/cmd_get.hh +22 -0
- package/deps/lcb/src/capi/cmd_get_replica.hh +23 -0
- package/deps/lcb/src/capi/cmd_http.hh +7 -0
- package/deps/lcb/src/capi/cmd_query.cc +11 -1
- package/deps/lcb/src/capi/cmd_query.hh +31 -0
- package/deps/lcb/src/capi/cmd_remove.hh +23 -0
- package/deps/lcb/src/capi/cmd_search.cc +6 -0
- package/deps/lcb/src/capi/cmd_search.hh +23 -0
- package/deps/lcb/src/capi/cmd_store.hh +33 -21
- package/deps/lcb/src/capi/cmd_subdoc.hh +35 -0
- package/deps/lcb/src/capi/cmd_touch.hh +23 -0
- package/deps/lcb/src/capi/cmd_unlock.hh +23 -0
- package/deps/lcb/src/capi/cmd_view.hh +6 -0
- package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
- package/deps/lcb/src/cntl.cc +45 -11
- package/deps/lcb/src/crypto.cc +2 -2
- package/deps/lcb/src/dns-srv.cc +5 -3
- package/deps/lcb/src/errmap.cc +5 -9
- package/deps/lcb/src/errmap.h +7 -3
- package/deps/lcb/src/handler.cc +24 -18
- package/deps/lcb/src/hostlist.h +2 -2
- package/deps/lcb/src/http/http-priv.h +2 -2
- package/deps/lcb/src/http/http.cc +5 -2
- package/deps/lcb/src/instance.cc +20 -11
- package/deps/lcb/src/internal.h +9 -0
- package/deps/lcb/src/lcbio/connect.cc +14 -2
- package/deps/lcb/src/lcbio/connect.h +2 -2
- package/deps/lcb/src/lcbio/ctx.cc +4 -2
- package/deps/lcb/src/lcbio/ioutils.cc +9 -10
- package/deps/lcb/src/lcbio/manager.cc +1 -1
- package/deps/lcb/src/mcserver/mcserver.cc +9 -6
- package/deps/lcb/src/mcserver/negotiate.cc +39 -17
- package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
- package/deps/lcb/src/n1ql/query_handle.cc +41 -19
- package/deps/lcb/src/n1ql/query_handle.hh +28 -1
- package/deps/lcb/src/operations/counter.cc +18 -5
- package/deps/lcb/src/operations/exists.cc +25 -4
- package/deps/lcb/src/operations/get.cc +39 -19
- package/deps/lcb/src/operations/get_replica.cc +28 -8
- package/deps/lcb/src/operations/observe.cc +1 -1
- package/deps/lcb/src/operations/ping.cc +8 -8
- package/deps/lcb/src/operations/pktfwd.cc +2 -1
- package/deps/lcb/src/operations/remove.cc +39 -22
- package/deps/lcb/src/operations/store.cc +18 -5
- package/deps/lcb/src/operations/subdoc.cc +18 -6
- package/deps/lcb/src/operations/touch.cc +34 -16
- package/deps/lcb/src/operations/unlock.cc +24 -5
- package/deps/lcb/src/packetutils.h +3 -2
- package/deps/lcb/src/retryq.cc +24 -5
- package/deps/lcb/src/search/search.cc +1 -0
- package/deps/lcb/src/search/search_handle.cc +30 -8
- package/deps/lcb/src/search/search_handle.hh +29 -0
- package/deps/lcb/src/settings.cc +1 -1
- package/deps/lcb/src/ssl/ssl_common.c +6 -7
- package/deps/lcb/src/tracing/span.cc +47 -14
- package/deps/lcb/src/tracing/tracer.cc +11 -2
- package/deps/lcb/src/tracing/tracing-internal.h +105 -93
- package/deps/lcb/src/utilities.cc +43 -0
- package/deps/lcb/src/utilities.h +53 -0
- package/deps/lcb/src/vbucket/vbucket.c +34 -33
- package/deps/lcb/src/views/view_handle.cc +13 -5
- package/deps/lcb/src/views/view_handle.hh +29 -0
- package/deps/lcb/tests/CMakeLists.txt +21 -0
- package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
- package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
- package/deps/lcb/tests/basic/t_n1qlstrings.cc +73 -0
- package/deps/lcb/tests/iotests/mock-environment.cc +30 -1
- package/deps/lcb/tests/iotests/mock-environment.h +49 -0
- package/deps/lcb/tests/iotests/mock-unit-test.cc +104 -6
- package/deps/lcb/tests/iotests/mock-unit-test.h +34 -0
- package/deps/lcb/tests/iotests/t_collections.cc +1 -1
- package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
- package/deps/lcb/tests/iotests/t_get.cc +109 -7
- package/deps/lcb/tests/iotests/t_http.cc +9 -4
- package/deps/lcb/tests/iotests/t_lock.cc +18 -0
- package/deps/lcb/tests/iotests/t_mutate.cc +157 -63
- package/deps/lcb/tests/iotests/t_n1ql.cc +330 -33
- package/deps/lcb/tests/iotests/t_views.cc +1 -0
- package/deps/lcb/tests/iotests/testutil.cc +168 -0
- package/deps/lcb/tests/iotests/testutil.h +116 -0
- package/deps/lcb/tests/mocksupport/procutil.c +32 -28
- package/deps/lcb/tests/mocksupport/server.c +0 -1
- package/deps/lcb/tests/mocksupport/timeout.c +2 -2
- package/deps/lcb/tools/cbc.cc +7 -0
- package/dist/analyticsindexmanager.js +512 -524
- package/dist/binding.d.ts +3 -0
- package/dist/bindingutilities.js +4 -0
- package/dist/bucket.js +1 -1
- package/dist/bucketmanager.d.ts +31 -1
- package/dist/bucketmanager.js +194 -186
- package/dist/cluster.d.ts +7 -0
- package/dist/cluster.js +48 -38
- package/dist/collection.js +11 -17
- package/dist/collectionmanager.js +181 -197
- package/dist/connection.d.ts +3 -1
- package/dist/connection.js +27 -16
- package/dist/couchbase.d.ts +1 -0
- package/dist/couchbase.js +3 -13
- package/dist/datastructures.js +239 -310
- package/dist/diagnosticsexecutor.js +70 -85
- package/dist/errors.d.ts +70 -0
- package/dist/errors.js +96 -2
- package/dist/eventingfunctionmanager.d.ts +804 -0
- package/dist/eventingfunctionmanager.js +993 -0
- package/dist/httpexecutor.d.ts +2 -1
- package/dist/httpexecutor.js +30 -37
- package/dist/queryindexmanager.js +240 -266
- package/dist/scope.js +10 -4
- package/dist/sdspecs.d.ts +1 -1
- package/dist/searchexecutor.js +3 -0
- package/dist/searchindexmanager.js +240 -271
- package/dist/searchquery.d.ts +17 -0
- package/dist/searchquery.js +22 -1
- package/dist/searchtypes.d.ts +7 -2
- package/dist/searchtypes.js +2 -2
- package/dist/usermanager.js +251 -264
- package/dist/utilities.d.ts +2 -0
- package/dist/utilities.js +7 -2
- package/dist/viewexecutor.js +1 -1
- package/dist/viewindexmanager.js +131 -150
- package/package.json +1 -1
- package/src/addondata.cpp +58 -0
- package/src/addondata.h +40 -0
- package/src/binding.cpp +3 -1
- package/src/cas.h +2 -2
- package/src/connection.cpp +25 -178
- package/src/connection.h +8 -65
- package/src/connection_ops.cpp +57 -34
- package/src/constants.cpp +3 -0
- package/src/instance.cpp +235 -0
- package/src/instance.h +102 -0
- package/src/{connection_callbacks.cpp → instance_callbacks.cpp} +34 -34
- package/src/logger.cpp +11 -1
- package/src/logger.h +3 -0
- package/src/metrics.cpp +10 -0
- package/src/metrics.h +3 -0
- package/src/mutationtoken.h +2 -2
- package/src/opbuilder.h +13 -15
- package/src/respreader.cpp +1 -0
- package/src/respreader.h +6 -4
- package/src/tracespan.h +11 -11
- package/src/tracing.cpp +11 -0
- package/src/tracing.h +3 -0
- package/src/valueparser.h +5 -0
- package/deps/lcb/example/observe/durability.c +0 -110
package/src/constants.cpp
CHANGED
@@ -67,6 +67,8 @@ NAN_MODULE_INIT(Init)
|
|
67
67
|
X(LCB_ERR_SCOPE_NOT_FOUND)
|
68
68
|
X(LCB_ERR_INDEX_NOT_FOUND)
|
69
69
|
X(LCB_ERR_INDEX_EXISTS)
|
70
|
+
X(LCB_ERR_RATE_LIMITED)
|
71
|
+
X(LCB_ERR_QUOTA_LIMITED)
|
70
72
|
X(LCB_ERR_DOCUMENT_NOT_FOUND)
|
71
73
|
X(LCB_ERR_DOCUMENT_UNRETRIEVABLE)
|
72
74
|
X(LCB_ERR_DOCUMENT_LOCKED)
|
@@ -183,6 +185,7 @@ NAN_MODULE_INIT(Init)
|
|
183
185
|
X(LCB_HTTP_TYPE_QUERY)
|
184
186
|
X(LCB_HTTP_TYPE_SEARCH)
|
185
187
|
X(LCB_HTTP_TYPE_ANALYTICS)
|
188
|
+
X(LCB_HTTP_TYPE_EVENTING)
|
186
189
|
|
187
190
|
X(LCB_HTTP_METHOD_GET)
|
188
191
|
X(LCB_HTTP_METHOD_POST)
|
package/src/instance.cpp
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
#include "instance.h"
|
2
|
+
#include "connection.h"
|
3
|
+
|
4
|
+
#include "error.h"
|
5
|
+
#include "logger.h"
|
6
|
+
|
7
|
+
namespace couchnode
|
8
|
+
{
|
9
|
+
|
10
|
+
Instance::Instance(lcb_INSTANCE *instance, Logger *logger,
|
11
|
+
RequestTracer *tracer, Meter *meter)
|
12
|
+
: _connection(nullptr)
|
13
|
+
, _instance(instance)
|
14
|
+
, _logger(logger)
|
15
|
+
, _tracer(tracer)
|
16
|
+
, _meter(meter)
|
17
|
+
, _clientStringCache(nullptr)
|
18
|
+
, _bootstrapCookie(nullptr)
|
19
|
+
, _openCookie(nullptr)
|
20
|
+
{
|
21
|
+
_parent = addondata::Get();
|
22
|
+
_parent->add_instance(this);
|
23
|
+
|
24
|
+
_flushWatch = new uv_prepare_t();
|
25
|
+
uv_prepare_init(Nan::GetCurrentEventLoop(), _flushWatch);
|
26
|
+
_flushWatch->data = this;
|
27
|
+
|
28
|
+
_shutdownProc = new uv_check_t();
|
29
|
+
uv_check_init(Nan::GetCurrentEventLoop(), _shutdownProc);
|
30
|
+
_shutdownProc->data = this;
|
31
|
+
|
32
|
+
lcb_set_cookie(instance, reinterpret_cast<void *>(this));
|
33
|
+
lcb_set_bootstrap_callback(instance, &lcbBootstapHandler);
|
34
|
+
lcb_set_open_callback(instance, &lcbOpenHandler);
|
35
|
+
lcb_install_callback(
|
36
|
+
instance, LCB_CALLBACK_GET,
|
37
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbGetRespHandler));
|
38
|
+
lcb_install_callback(
|
39
|
+
instance, LCB_CALLBACK_EXISTS,
|
40
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbExistsRespHandler));
|
41
|
+
lcb_install_callback(
|
42
|
+
instance, LCB_CALLBACK_GETREPLICA,
|
43
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbGetReplicaRespHandler));
|
44
|
+
lcb_install_callback(
|
45
|
+
instance, LCB_CALLBACK_STORE,
|
46
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbStoreRespHandler));
|
47
|
+
lcb_install_callback(
|
48
|
+
instance, LCB_CALLBACK_COUNTER,
|
49
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbCounterRespHandler));
|
50
|
+
lcb_install_callback(
|
51
|
+
instance, LCB_CALLBACK_REMOVE,
|
52
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbRemoveRespHandler));
|
53
|
+
lcb_install_callback(
|
54
|
+
instance, LCB_CALLBACK_TOUCH,
|
55
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbTouchRespHandler));
|
56
|
+
lcb_install_callback(
|
57
|
+
instance, LCB_CALLBACK_UNLOCK,
|
58
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbUnlockRespHandler));
|
59
|
+
lcb_install_callback(
|
60
|
+
instance, LCB_CALLBACK_SDLOOKUP,
|
61
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbLookupRespHandler));
|
62
|
+
lcb_install_callback(
|
63
|
+
instance, LCB_CALLBACK_SDMUTATE,
|
64
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbMutateRespHandler));
|
65
|
+
lcb_install_callback(
|
66
|
+
instance, LCB_CALLBACK_PING,
|
67
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbPingRespHandler));
|
68
|
+
lcb_install_callback(
|
69
|
+
instance, LCB_CALLBACK_DIAG,
|
70
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbDiagRespHandler));
|
71
|
+
lcb_install_callback(
|
72
|
+
instance, LCB_CALLBACK_HTTP,
|
73
|
+
reinterpret_cast<lcb_RESPCALLBACK>(&lcbHttpDataHandler));
|
74
|
+
}
|
75
|
+
|
76
|
+
Instance::~Instance()
|
77
|
+
{
|
78
|
+
if (_connection) {
|
79
|
+
_connection->_instance = nullptr;
|
80
|
+
_connection = nullptr;
|
81
|
+
}
|
82
|
+
|
83
|
+
if (_parent) {
|
84
|
+
_parent->remove_instance(this);
|
85
|
+
_parent = nullptr;
|
86
|
+
}
|
87
|
+
|
88
|
+
if (_flushWatch) {
|
89
|
+
uv_prepare_stop(_flushWatch);
|
90
|
+
uv_close(reinterpret_cast<uv_handle_t *>(_flushWatch),
|
91
|
+
[](uv_handle_t *handle) { delete handle; });
|
92
|
+
_flushWatch = nullptr;
|
93
|
+
}
|
94
|
+
|
95
|
+
if (_shutdownProc) {
|
96
|
+
uv_check_stop(_shutdownProc);
|
97
|
+
uv_close(reinterpret_cast<uv_handle_t *>(_shutdownProc),
|
98
|
+
[](uv_handle_t *handle) { delete handle; });
|
99
|
+
_shutdownProc = nullptr;
|
100
|
+
}
|
101
|
+
|
102
|
+
if (_instance) {
|
103
|
+
lcb_destroy(_instance);
|
104
|
+
_instance = nullptr;
|
105
|
+
}
|
106
|
+
|
107
|
+
// If there is a custom hooks registered, we need to deactivate them here
|
108
|
+
// since the GC might be the one invoking us, which will cause problems
|
109
|
+
// as we can't call into v8 during garbage collection.
|
110
|
+
if (_logger) {
|
111
|
+
_logger->disconnect();
|
112
|
+
}
|
113
|
+
if (_tracer) {
|
114
|
+
_tracer->disconnect();
|
115
|
+
}
|
116
|
+
if (_meter) {
|
117
|
+
_meter->disconnect();
|
118
|
+
}
|
119
|
+
|
120
|
+
if (_logger) {
|
121
|
+
delete _logger;
|
122
|
+
_logger = nullptr;
|
123
|
+
}
|
124
|
+
// tracer is destroyed by libcouchbase
|
125
|
+
// meter is destroyed by libcouchbase
|
126
|
+
|
127
|
+
if (_clientStringCache) {
|
128
|
+
delete[] _clientStringCache;
|
129
|
+
_clientStringCache = nullptr;
|
130
|
+
}
|
131
|
+
if (_bootstrapCookie) {
|
132
|
+
delete _bootstrapCookie;
|
133
|
+
_bootstrapCookie = nullptr;
|
134
|
+
}
|
135
|
+
if (_openCookie) {
|
136
|
+
delete _openCookie;
|
137
|
+
_openCookie = nullptr;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
void Instance::uvShutdownHandler(uv_check_t *handle)
|
142
|
+
{
|
143
|
+
delete reinterpret_cast<Instance *>(handle->data);
|
144
|
+
}
|
145
|
+
|
146
|
+
void Instance::shutdown()
|
147
|
+
{
|
148
|
+
uv_check_start(_shutdownProc, &uvShutdownHandler);
|
149
|
+
}
|
150
|
+
|
151
|
+
const char *Instance::bucketName()
|
152
|
+
{
|
153
|
+
const char *value = nullptr;
|
154
|
+
lcb_cntl(_instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &value);
|
155
|
+
return value;
|
156
|
+
}
|
157
|
+
|
158
|
+
const char *Instance::clientString()
|
159
|
+
{
|
160
|
+
// Check to see if our cache is already populated
|
161
|
+
if (_clientStringCache) {
|
162
|
+
return _clientStringCache;
|
163
|
+
}
|
164
|
+
|
165
|
+
// Fetch from libcouchbase if we have not done that yet.
|
166
|
+
const char *lcbClientString;
|
167
|
+
lcb_cntl(_instance, LCB_CNTL_GET, LCB_CNTL_CLIENT_STRING, &lcbClientString);
|
168
|
+
if (!lcbClientString) {
|
169
|
+
// Backup string in case something goes wrong
|
170
|
+
lcbClientString = "couchbase-nodejs-sdk";
|
171
|
+
}
|
172
|
+
|
173
|
+
// Copy it to memory we own.
|
174
|
+
int lcbClientStringLen = strlen(lcbClientString);
|
175
|
+
char *allocString = new char[lcbClientStringLen + 1];
|
176
|
+
memcpy(allocString, lcbClientString, lcbClientStringLen + 1);
|
177
|
+
|
178
|
+
if (_clientStringCache) {
|
179
|
+
delete[] _clientStringCache;
|
180
|
+
_clientStringCache = nullptr;
|
181
|
+
}
|
182
|
+
_clientStringCache = allocString;
|
183
|
+
|
184
|
+
return _clientStringCache;
|
185
|
+
}
|
186
|
+
|
187
|
+
void Instance::uvFlushHandler(uv_prepare_t *handle)
|
188
|
+
{
|
189
|
+
Instance *me = reinterpret_cast<Instance *>(handle->data);
|
190
|
+
lcb_sched_flush(me->_instance);
|
191
|
+
}
|
192
|
+
|
193
|
+
void Instance::lcbBootstapHandler(lcb_INSTANCE *instance, lcb_STATUS err)
|
194
|
+
{
|
195
|
+
Instance *me = Instance::fromLcbInst(instance);
|
196
|
+
|
197
|
+
if (err != 0) {
|
198
|
+
lcb_set_bootstrap_callback(instance, [](lcb_INSTANCE *, lcb_STATUS) {});
|
199
|
+
lcb_destroy_async(instance, NULL);
|
200
|
+
me->_instance = nullptr;
|
201
|
+
} else {
|
202
|
+
uv_prepare_start(me->_flushWatch, &uvFlushHandler);
|
203
|
+
|
204
|
+
int flushMode = 0;
|
205
|
+
lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_SCHED_IMPLICIT_FLUSH,
|
206
|
+
&flushMode);
|
207
|
+
}
|
208
|
+
|
209
|
+
if (me->_bootstrapCookie) {
|
210
|
+
Nan::HandleScope scope;
|
211
|
+
|
212
|
+
Local<Value> args[] = {Error::create(err)};
|
213
|
+
me->_bootstrapCookie->Call(1, args);
|
214
|
+
|
215
|
+
delete me->_bootstrapCookie;
|
216
|
+
me->_bootstrapCookie = nullptr;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
void Instance::lcbOpenHandler(lcb_INSTANCE *instance, lcb_STATUS err)
|
221
|
+
{
|
222
|
+
Instance *me = Instance::fromLcbInst(instance);
|
223
|
+
|
224
|
+
if (me->_openCookie) {
|
225
|
+
Nan::HandleScope scope;
|
226
|
+
|
227
|
+
Local<Value> args[] = {Error::create(err)};
|
228
|
+
me->_openCookie->Call(1, args);
|
229
|
+
|
230
|
+
delete me->_openCookie;
|
231
|
+
me->_openCookie = nullptr;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
} // namespace couchnode
|
package/src/instance.h
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#pragma once
|
2
|
+
#ifndef INSTANCE_H
|
3
|
+
#define INSTANCE_H
|
4
|
+
|
5
|
+
#include "addondata.h"
|
6
|
+
#include "cookie.h"
|
7
|
+
#include "logger.h"
|
8
|
+
#include "metrics.h"
|
9
|
+
#include "tracing.h"
|
10
|
+
#include "valueparser.h"
|
11
|
+
|
12
|
+
#include <libcouchbase/couchbase.h>
|
13
|
+
#include <libcouchbase/libuv_io_opts.h>
|
14
|
+
#include <nan.h>
|
15
|
+
#include <node.h>
|
16
|
+
|
17
|
+
namespace couchnode
|
18
|
+
{
|
19
|
+
|
20
|
+
using namespace v8;
|
21
|
+
|
22
|
+
class Instance
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
static inline Instance *fromLcbInst(lcb_INSTANCE *instance)
|
26
|
+
{
|
27
|
+
void *cookie = const_cast<void *>(lcb_get_cookie(instance));
|
28
|
+
Instance *inst = reinterpret_cast<Instance *>(cookie);
|
29
|
+
return inst;
|
30
|
+
}
|
31
|
+
|
32
|
+
Instance(lcb_INSTANCE *instance, Logger *logger, RequestTracer *tracer,
|
33
|
+
Meter *meter);
|
34
|
+
~Instance();
|
35
|
+
|
36
|
+
lcb_INSTANCE *lcbHandle() const
|
37
|
+
{
|
38
|
+
return _instance;
|
39
|
+
}
|
40
|
+
|
41
|
+
void shutdown();
|
42
|
+
|
43
|
+
const char *bucketName();
|
44
|
+
const char *clientString();
|
45
|
+
|
46
|
+
static void uvFlushHandler(uv_prepare_t *handle);
|
47
|
+
static void uvShutdownHandler(uv_check_t *handle);
|
48
|
+
static void lcbRegisterCallbacks(lcb_INSTANCE *instance);
|
49
|
+
static void lcbBootstapHandler(lcb_INSTANCE *instance, lcb_STATUS err);
|
50
|
+
static void lcbOpenHandler(lcb_INSTANCE *instance, lcb_STATUS err);
|
51
|
+
static void lcbGetRespHandler(lcb_INSTANCE *instance, int cbtype,
|
52
|
+
const lcb_RESPGET *resp);
|
53
|
+
static void lcbExistsRespHandler(lcb_INSTANCE *instance, int cbtype,
|
54
|
+
const lcb_RESPEXISTS *resp);
|
55
|
+
static void lcbGetReplicaRespHandler(lcb_INSTANCE *instance, int cbtype,
|
56
|
+
const lcb_RESPGETREPLICA *resp);
|
57
|
+
static void lcbUnlockRespHandler(lcb_INSTANCE *instance, int cbtype,
|
58
|
+
const lcb_RESPUNLOCK *resp);
|
59
|
+
static void lcbRemoveRespHandler(lcb_INSTANCE *instance, int cbtype,
|
60
|
+
const lcb_RESPREMOVE *resp);
|
61
|
+
static void lcbTouchRespHandler(lcb_INSTANCE *instance, int cbtype,
|
62
|
+
const lcb_RESPTOUCH *resp);
|
63
|
+
static void lcbStoreRespHandler(lcb_INSTANCE *instance, int cbtype,
|
64
|
+
const lcb_RESPSTORE *resp);
|
65
|
+
static void lcbCounterRespHandler(lcb_INSTANCE *instance, int cbtype,
|
66
|
+
const lcb_RESPCOUNTER *resp);
|
67
|
+
static void lcbLookupRespHandler(lcb_INSTANCE *instance, int cbtype,
|
68
|
+
const lcb_RESPSUBDOC *resp);
|
69
|
+
static void lcbMutateRespHandler(lcb_INSTANCE *instance, int cbtype,
|
70
|
+
const lcb_RESPSUBDOC *resp);
|
71
|
+
static void lcbViewDataHandler(lcb_INSTANCE *instance, int cbtype,
|
72
|
+
const lcb_RESPVIEW *resp);
|
73
|
+
static void lcbQueryDataHandler(lcb_INSTANCE *instance, int cbtype,
|
74
|
+
const lcb_RESPQUERY *resp);
|
75
|
+
static void lcbAnalyticsDataHandler(lcb_INSTANCE *instance, int cbtype,
|
76
|
+
const lcb_RESPANALYTICS *resp);
|
77
|
+
static void lcbSearchDataHandler(lcb_INSTANCE *instance, int cbtype,
|
78
|
+
const lcb_RESPSEARCH *resp);
|
79
|
+
static void lcbPingRespHandler(lcb_INSTANCE *instance, int cbtype,
|
80
|
+
const lcb_RESPPING *resp);
|
81
|
+
static void lcbDiagRespHandler(lcb_INSTANCE *instance, int cbtype,
|
82
|
+
const lcb_RESPDIAG *resp);
|
83
|
+
static void lcbHttpDataHandler(lcb_INSTANCE *instance, int cbtype,
|
84
|
+
const lcb_RESPHTTP *resp);
|
85
|
+
|
86
|
+
AddonData *_parent;
|
87
|
+
class Connection *_connection;
|
88
|
+
lcb_INSTANCE *_instance;
|
89
|
+
Logger *_logger;
|
90
|
+
RequestTracer *_tracer;
|
91
|
+
Meter *_meter;
|
92
|
+
uv_prepare_t *_flushWatch;
|
93
|
+
uv_check_t *_shutdownProc;
|
94
|
+
const char *_clientStringCache;
|
95
|
+
|
96
|
+
Cookie *_bootstrapCookie;
|
97
|
+
Cookie *_openCookie;
|
98
|
+
};
|
99
|
+
|
100
|
+
} // namespace couchnode
|
101
|
+
|
102
|
+
#endif // CONNECTION_H
|
@@ -8,8 +8,8 @@
|
|
8
8
|
namespace couchnode
|
9
9
|
{
|
10
10
|
|
11
|
-
void
|
12
|
-
|
11
|
+
void Instance::lcbGetRespHandler(lcb_INSTANCE *instance, int cbtype,
|
12
|
+
const lcb_RESPGET *resp)
|
13
13
|
{
|
14
14
|
Nan::HandleScope scope;
|
15
15
|
RespReader<lcb_RESPGET, &lcb_respget_cookie> rdr(instance, resp);
|
@@ -37,8 +37,8 @@ void Connection::lcbGetRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
37
37
|
rdr.invokeCallback(errVal, casVal, valueVal);
|
38
38
|
}
|
39
39
|
|
40
|
-
void
|
41
|
-
|
40
|
+
void Instance::lcbExistsRespHandler(lcb_INSTANCE *instance, int cbtype,
|
41
|
+
const lcb_RESPEXISTS *resp)
|
42
42
|
{
|
43
43
|
Nan::HandleScope scope;
|
44
44
|
RespReader<lcb_RESPEXISTS, &lcb_respexists_cookie> rdr(instance, resp);
|
@@ -64,8 +64,8 @@ void Connection::lcbExistsRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
64
64
|
rdr.invokeCallback(errVal, casVal, existsVal);
|
65
65
|
}
|
66
66
|
|
67
|
-
void
|
68
|
-
|
67
|
+
void Instance::lcbGetReplicaRespHandler(lcb_INSTANCE *instance, int cbtype,
|
68
|
+
const lcb_RESPGETREPLICA *resp)
|
69
69
|
{
|
70
70
|
Nan::HandleScope scope;
|
71
71
|
RespReader<lcb_RESPGETREPLICA, &lcb_respgetreplica_cookie> rdr(instance,
|
@@ -106,8 +106,8 @@ void Connection::lcbGetReplicaRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
106
106
|
}
|
107
107
|
}
|
108
108
|
|
109
|
-
void
|
110
|
-
|
109
|
+
void Instance::lcbUnlockRespHandler(lcb_INSTANCE *instance, int cbtype,
|
110
|
+
const lcb_RESPUNLOCK *resp)
|
111
111
|
{
|
112
112
|
Nan::HandleScope scope;
|
113
113
|
RespReader<lcb_RESPUNLOCK, &lcb_respunlock_cookie> rdr(instance, resp);
|
@@ -118,8 +118,8 @@ void Connection::lcbUnlockRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
118
118
|
rdr.invokeCallback(errVal);
|
119
119
|
}
|
120
120
|
|
121
|
-
void
|
122
|
-
|
121
|
+
void Instance::lcbRemoveRespHandler(lcb_INSTANCE *instance, int cbtype,
|
122
|
+
const lcb_RESPREMOVE *resp)
|
123
123
|
{
|
124
124
|
Nan::HandleScope scope;
|
125
125
|
RespReader<lcb_RESPREMOVE, &lcb_respremove_cookie> rdr(instance, resp);
|
@@ -137,8 +137,8 @@ void Connection::lcbRemoveRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
137
137
|
rdr.invokeCallback(errVal, casVal);
|
138
138
|
}
|
139
139
|
|
140
|
-
void
|
141
|
-
|
140
|
+
void Instance::lcbTouchRespHandler(lcb_INSTANCE *instance, int cbtype,
|
141
|
+
const lcb_RESPTOUCH *resp)
|
142
142
|
{
|
143
143
|
Nan::HandleScope scope;
|
144
144
|
RespReader<lcb_RESPTOUCH, &lcb_resptouch_cookie> rdr(instance, resp);
|
@@ -156,8 +156,8 @@ void Connection::lcbTouchRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
156
156
|
rdr.invokeCallback(errVal, casVal);
|
157
157
|
}
|
158
158
|
|
159
|
-
void
|
160
|
-
|
159
|
+
void Instance::lcbStoreRespHandler(lcb_INSTANCE *instance, int cbtype,
|
160
|
+
const lcb_RESPSTORE *resp)
|
161
161
|
{
|
162
162
|
Nan::HandleScope scope;
|
163
163
|
RespReader<lcb_RESPSTORE, &lcb_respstore_cookie> rdr(instance, resp);
|
@@ -177,8 +177,8 @@ void Connection::lcbStoreRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
177
177
|
rdr.invokeCallback(errVal, casVal, tokenVal);
|
178
178
|
}
|
179
179
|
|
180
|
-
void
|
181
|
-
|
180
|
+
void Instance::lcbCounterRespHandler(lcb_INSTANCE *instance, int cbtype,
|
181
|
+
const lcb_RESPCOUNTER *resp)
|
182
182
|
{
|
183
183
|
Nan::HandleScope scope;
|
184
184
|
RespReader<lcb_RESPCOUNTER, &lcb_respcounter_cookie> rdr(instance, resp);
|
@@ -200,8 +200,8 @@ void Connection::lcbCounterRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
200
200
|
rdr.invokeCallback(errVal, casVal, tokenVal, valueVal);
|
201
201
|
}
|
202
202
|
|
203
|
-
void
|
204
|
-
|
203
|
+
void Instance::lcbLookupRespHandler(lcb_INSTANCE *instance, int cbtype,
|
204
|
+
const lcb_RESPSUBDOC *resp)
|
205
205
|
{
|
206
206
|
Nan::HandleScope scope;
|
207
207
|
RespReader<lcb_RESPSUBDOC, &lcb_respsubdoc_cookie> rdr(instance, resp);
|
@@ -245,8 +245,8 @@ void Connection::lcbLookupRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
245
245
|
rdr.invokeCallback(errVal, resVal);
|
246
246
|
}
|
247
247
|
|
248
|
-
void
|
249
|
-
|
248
|
+
void Instance::lcbMutateRespHandler(lcb_INSTANCE *instance, int cbtype,
|
249
|
+
const lcb_RESPSUBDOC *resp)
|
250
250
|
{
|
251
251
|
Nan::HandleScope scope;
|
252
252
|
RespReader<lcb_RESPSUBDOC, &lcb_respsubdoc_cookie> rdr(instance, resp);
|
@@ -300,8 +300,8 @@ void Connection::lcbMutateRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
300
300
|
rdr.invokeCallback(errVal, resVal);
|
301
301
|
}
|
302
302
|
|
303
|
-
void
|
304
|
-
|
303
|
+
void Instance::lcbViewDataHandler(lcb_INSTANCE *instance, int cbtype,
|
304
|
+
const lcb_RESPVIEW *resp)
|
305
305
|
{
|
306
306
|
Nan::HandleScope scope;
|
307
307
|
RespReader<lcb_RESPVIEW, &lcb_respview_cookie> rdr(instance, resp);
|
@@ -326,8 +326,8 @@ void Connection::lcbViewDataHandler(lcb_INSTANCE *instance, int cbtype,
|
|
326
326
|
}
|
327
327
|
}
|
328
328
|
|
329
|
-
void
|
330
|
-
|
329
|
+
void Instance::lcbQueryDataHandler(lcb_INSTANCE *instance, int cbtype,
|
330
|
+
const lcb_RESPQUERY *resp)
|
331
331
|
{
|
332
332
|
Nan::HandleScope scope;
|
333
333
|
RespReader<lcb_RESPQUERY, &lcb_respquery_cookie> rdr(instance, resp);
|
@@ -350,8 +350,8 @@ void Connection::lcbQueryDataHandler(lcb_INSTANCE *instance, int cbtype,
|
|
350
350
|
}
|
351
351
|
}
|
352
352
|
|
353
|
-
void
|
354
|
-
|
353
|
+
void Instance::lcbAnalyticsDataHandler(lcb_INSTANCE *instance, int cbtype,
|
354
|
+
const lcb_RESPANALYTICS *resp)
|
355
355
|
{
|
356
356
|
Nan::HandleScope scope;
|
357
357
|
RespReader<lcb_RESPANALYTICS, &lcb_respanalytics_cookie> rdr(instance,
|
@@ -375,8 +375,8 @@ void Connection::lcbAnalyticsDataHandler(lcb_INSTANCE *instance, int cbtype,
|
|
375
375
|
}
|
376
376
|
}
|
377
377
|
|
378
|
-
void
|
379
|
-
|
378
|
+
void Instance::lcbSearchDataHandler(lcb_INSTANCE *instance, int cbtype,
|
379
|
+
const lcb_RESPSEARCH *resp)
|
380
380
|
{
|
381
381
|
Nan::HandleScope scope;
|
382
382
|
RespReader<lcb_RESPSEARCH, &lcb_respsearch_cookie> rdr(instance, resp);
|
@@ -399,8 +399,8 @@ void Connection::lcbSearchDataHandler(lcb_INSTANCE *instance, int cbtype,
|
|
399
399
|
}
|
400
400
|
}
|
401
401
|
|
402
|
-
void
|
403
|
-
|
402
|
+
void Instance::lcbHttpDataHandler(lcb_INSTANCE *instance, int cbtype,
|
403
|
+
const lcb_RESPHTTP *resp)
|
404
404
|
{
|
405
405
|
Nan::HandleScope scope;
|
406
406
|
RespReader<lcb_RESPHTTP, &lcb_resphttp_cookie> rdr(instance, resp);
|
@@ -445,8 +445,8 @@ void Connection::lcbHttpDataHandler(lcb_INSTANCE *instance, int cbtype,
|
|
445
445
|
}
|
446
446
|
}
|
447
447
|
|
448
|
-
void
|
449
|
-
|
448
|
+
void Instance::lcbPingRespHandler(lcb_INSTANCE *instance, int cbtype,
|
449
|
+
const lcb_RESPPING *resp)
|
450
450
|
{
|
451
451
|
Nan::HandleScope scope;
|
452
452
|
RespReader<lcb_RESPPING, &lcb_respping_cookie> rdr(instance, resp);
|
@@ -464,8 +464,8 @@ void Connection::lcbPingRespHandler(lcb_INSTANCE *instance, int cbtype,
|
|
464
464
|
rdr.invokeCallback(errVal, dataVal);
|
465
465
|
}
|
466
466
|
|
467
|
-
void
|
468
|
-
|
467
|
+
void Instance::lcbDiagRespHandler(lcb_INSTANCE *instance, int cbtype,
|
468
|
+
const lcb_RESPDIAG *resp)
|
469
469
|
{
|
470
470
|
Nan::HandleScope scope;
|
471
471
|
RespReader<lcb_RESPDIAG, &lcb_respdiag_cookie> rdr(instance, resp);
|
package/src/logger.cpp
CHANGED
@@ -4,7 +4,8 @@ namespace couchnode
|
|
4
4
|
{
|
5
5
|
|
6
6
|
Logger::Logger(Local<Function> callback)
|
7
|
-
:
|
7
|
+
: _enabled(true)
|
8
|
+
, _callback(callback)
|
8
9
|
, _logBuffer(nullptr)
|
9
10
|
, _logBufferLen(0)
|
10
11
|
{
|
@@ -23,10 +24,19 @@ const lcb_LOGGER *Logger::lcbProcs() const
|
|
23
24
|
return _lcbLogger;
|
24
25
|
}
|
25
26
|
|
27
|
+
void Logger::disconnect()
|
28
|
+
{
|
29
|
+
_enabled = false;
|
30
|
+
}
|
31
|
+
|
26
32
|
void Logger::handler(unsigned int iid, const char *subsys, int severity,
|
27
33
|
const char *srcfile, int srcline, const char *fmt,
|
28
34
|
va_list ap)
|
29
35
|
{
|
36
|
+
if (!_enabled) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
|
30
40
|
Nan::HandleScope scope;
|
31
41
|
va_list apCopy;
|
32
42
|
|
package/src/logger.h
CHANGED
@@ -19,6 +19,8 @@ public:
|
|
19
19
|
|
20
20
|
const lcb_LOGGER *lcbProcs() const;
|
21
21
|
|
22
|
+
void disconnect();
|
23
|
+
|
22
24
|
private:
|
23
25
|
void handler(unsigned int iid, const char *subsys, int severity,
|
24
26
|
const char *srcfile, int srcline, const char *fmt, va_list ap);
|
@@ -28,6 +30,7 @@ private:
|
|
28
30
|
const char *srcfile, int srcline, const char *fmt,
|
29
31
|
va_list ap);
|
30
32
|
|
33
|
+
bool _enabled;
|
31
34
|
lcb_LOGGER *_lcbLogger;
|
32
35
|
Nan::Callback _callback;
|
33
36
|
char *_logBuffer;
|
package/src/metrics.cpp
CHANGED
@@ -59,6 +59,7 @@ void lcbValueRecorderRecordValue(const lcbmetrics_VALUERECORDER *procs,
|
|
59
59
|
}
|
60
60
|
|
61
61
|
Meter::Meter(Local<Object> impl)
|
62
|
+
: _enabled(true)
|
62
63
|
{
|
63
64
|
lcbmetrics_meter_create(&_lcbMeter, this);
|
64
65
|
lcbmetrics_meter_dtor_callback(_lcbMeter, &lcbMeterDtor);
|
@@ -84,6 +85,11 @@ const lcbmetrics_METER *Meter::lcbProcs() const
|
|
84
85
|
return _lcbMeter;
|
85
86
|
}
|
86
87
|
|
88
|
+
void Meter::disconnect()
|
89
|
+
{
|
90
|
+
_enabled = false;
|
91
|
+
}
|
92
|
+
|
87
93
|
void Meter::destroy(const Meter *meter)
|
88
94
|
{
|
89
95
|
delete meter;
|
@@ -93,6 +99,10 @@ const lcbmetrics_VALUERECORDER *Meter::valueRecorder(const char *name,
|
|
93
99
|
const lcbmetrics_TAG *tags,
|
94
100
|
size_t ntags) const
|
95
101
|
{
|
102
|
+
if (!_enabled) {
|
103
|
+
return nullptr;
|
104
|
+
}
|
105
|
+
|
96
106
|
// We don't perform any cacheing to avoid calls into v8 here as libcouchbase
|
97
107
|
// already contractually provides cacheing to reduce the calls to this
|
98
108
|
// method.
|
package/src/metrics.h
CHANGED
package/src/mutationtoken.h
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#ifndef TOKEN_H
|
3
3
|
#define TOKEN_H
|
4
4
|
|
5
|
+
#include "addondata.h"
|
5
6
|
#include <libcouchbase/couchbase.h>
|
6
7
|
#include <nan.h>
|
7
8
|
#include <node.h>
|
@@ -24,8 +25,7 @@ public:
|
|
24
25
|
|
25
26
|
static inline Nan::Persistent<Function> &constructor()
|
26
27
|
{
|
27
|
-
|
28
|
-
return class_constructor;
|
28
|
+
return addondata::Get()->_mutationtokenConstructor;
|
29
29
|
}
|
30
30
|
|
31
31
|
private:
|