couchbase 4.7.0 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +3 -0
- package/deps/couchbase-cxx-cache/mozilla-ca-bundle.crt +96 -727
- package/deps/couchbase-cxx-cache/mozilla-ca-bundle.sha256 +1 -1
- package/deps/couchbase-cxx-client/CMakeLists.txt +3 -1
- package/deps/couchbase-cxx-client/README.md +2 -2
- package/deps/couchbase-cxx-client/core/error_context/base_error_context.hxx +32 -0
- package/deps/couchbase-cxx-client/core/error_context/key_value.cxx +1 -0
- package/deps/couchbase-cxx-client/core/error_context/key_value.hxx +23 -0
- package/deps/couchbase-cxx-client/core/error_context/key_value_error_context.hxx +35 -0
- package/deps/couchbase-cxx-client/core/error_context/subdocument_error_context.hxx +41 -0
- package/deps/couchbase-cxx-client/core/impl/binary_collection.cxx +123 -88
- package/deps/couchbase-cxx-client/core/impl/collection.cxx +416 -189
- package/deps/couchbase-cxx-client/core/impl/error.cxx +29 -4
- package/deps/couchbase-cxx-client/core/impl/invoke_with_node_id.hxx +44 -0
- package/deps/couchbase-cxx-client/core/impl/node_id.cxx +110 -0
- package/deps/couchbase-cxx-client/core/impl/node_id.hxx +40 -0
- package/deps/couchbase-cxx-client/core/io/configuration_belongs_to_session.hxx +67 -0
- package/deps/couchbase-cxx-client/core/io/http_session_manager.hxx +97 -57
- package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +7 -16
- package/deps/couchbase-cxx-client/core/operations/document_get_all_replicas.hxx +14 -4
- package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -4
- package/deps/couchbase-cxx-client/core/operations/document_lookup_in_all_replicas.hxx +4 -0
- package/deps/couchbase-cxx-client/core/operations/document_query.cxx +12 -12
- package/deps/couchbase-cxx-client/core/operations/management/collection_create.cxx +11 -11
- package/deps/couchbase-cxx-client/core/operations/management/collection_drop.cxx +11 -11
- package/deps/couchbase-cxx-client/core/operations/management/collection_update.cxx +11 -11
- package/deps/couchbase-cxx-client/core/operations/management/error_utils.cxx +9 -6
- package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +5 -4
- package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +7 -6
- package/deps/couchbase-cxx-client/core/operations/management/scope_create.cxx +12 -13
- package/deps/couchbase-cxx-client/core/operations/management/scope_drop.cxx +8 -9
- package/deps/couchbase-cxx-client/core/topology/configuration.cxx +21 -0
- package/deps/couchbase-cxx-client/core/topology/configuration.hxx +28 -0
- package/deps/couchbase-cxx-client/core/utils/contains_string.cxx +61 -0
- package/deps/couchbase-cxx-client/core/utils/contains_string.hxx +26 -0
- package/deps/couchbase-cxx-client/couchbase/collection.hxx +73 -0
- package/deps/couchbase-cxx-client/couchbase/error.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/node_id.hxx +123 -0
- package/deps/couchbase-cxx-client/couchbase/node_id_for_options.hxx +61 -0
- package/deps/couchbase-cxx-client/couchbase/node_ids_options.hxx +62 -0
- package/deps/couchbase-cxx-client/couchbase/result.hxx +42 -0
- package/dist/analyticsexecutor.d.ts +4 -0
- package/dist/analyticsexecutor.js +26 -11
- package/dist/analyticsindexmanager.js +2 -2
- package/dist/binding.d.ts +12 -2
- package/dist/bindingutilities.js +8 -5
- package/dist/bucket.d.ts +9 -1
- package/dist/bucket.js +21 -0
- package/dist/cluster.d.ts +10 -1
- package/dist/cluster.js +25 -3
- package/dist/collection.d.ts +3 -3
- package/dist/collection.js +189 -143
- package/dist/diagnosticsexecutor.js +2 -2
- package/dist/diagnosticstypes.d.ts +36 -0
- package/dist/diagnosticstypes.js +22 -1
- package/dist/mutationstate.js +1 -1
- package/dist/observability.d.ts +5 -1
- package/dist/observability.js +11 -3
- package/dist/observabilityhandler.d.ts +19 -0
- package/dist/observabilityhandler.js +81 -14
- package/dist/observabilitytypes.js +19 -42
- package/dist/observabilityutilities.js +1 -1
- package/dist/oteltracer.d.ts +5 -0
- package/dist/oteltracer.js +7 -0
- package/dist/queryexecutor.d.ts +9 -0
- package/dist/queryexecutor.js +18 -0
- package/dist/queryindexmanager.js +15 -0
- package/dist/searchexecutor.d.ts +4 -0
- package/dist/searchexecutor.js +30 -15
- package/dist/thresholdlogging.d.ts +5 -0
- package/dist/thresholdlogging.js +7 -0
- package/dist/tracing.d.ts +6 -0
- package/dist/transactions.js +29 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/viewexecutor.d.ts +4 -0
- package/dist/viewexecutor.js +30 -15
- package/dist/waituntilreadyexecutor.d.ts +37 -0
- package/dist/waituntilreadyexecutor.js +156 -0
- package/package.json +8 -8
- package/scripts/prebuilds.js +13 -0
- package/src/binding.cpp +1 -1
- package/src/connection.hpp +24 -3
- package/src/jstocbpp_errors.hpp +6 -0
package/dist/searchexecutor.js
CHANGED
|
@@ -6,10 +6,10 @@ const bindingutilities_1 = require("./bindingutilities");
|
|
|
6
6
|
const observability_1 = require("./observability");
|
|
7
7
|
const observabilityhandler_1 = require("./observabilityhandler");
|
|
8
8
|
const observabilitytypes_1 = require("./observabilitytypes");
|
|
9
|
+
const queryexecutor_1 = require("./queryexecutor");
|
|
9
10
|
const searchquery_1 = require("./searchquery");
|
|
10
11
|
const searchtypes_1 = require("./searchtypes");
|
|
11
12
|
const streamablepromises_1 = require("./streamablepromises");
|
|
12
|
-
const utilities_1 = require("./utilities");
|
|
13
13
|
/**
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
@@ -28,30 +28,40 @@ class SearchExecutor {
|
|
|
28
28
|
get observabilityInstruments() {
|
|
29
29
|
return this._cluster.observabilityInstruments;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
static _endWithError(emitter, err, obsReqHandler) {
|
|
35
|
+
obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
|
|
36
|
+
emitter.emit('error', err);
|
|
37
|
+
emitter.emit('end');
|
|
38
|
+
}
|
|
31
39
|
/**
|
|
32
40
|
* @internal
|
|
33
41
|
*/
|
|
34
42
|
static _processSearchResponse(emitter, err, resp, obsReqHandler) {
|
|
35
43
|
if (err) {
|
|
36
|
-
|
|
37
|
-
emitter.emit('error', err);
|
|
38
|
-
emitter.emit('end');
|
|
44
|
+
SearchExecutor._endWithError(emitter, err, obsReqHandler);
|
|
39
45
|
return;
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
try {
|
|
48
|
+
resp.rows.forEach((row) => {
|
|
49
|
+
row.fields = row.fields ? JSON.parse(row.fields) : undefined;
|
|
50
|
+
row.explanation = row.explanation
|
|
51
|
+
? JSON.parse(row.explanation)
|
|
52
|
+
: undefined;
|
|
53
|
+
emitter.emit('row', row);
|
|
54
|
+
});
|
|
49
55
|
const metaData = resp.meta;
|
|
50
56
|
emitter.emit('meta', {
|
|
51
57
|
facets: Object.fromEntries(Object.values(resp.facets).map((v) => [v.name, v])),
|
|
52
58
|
...metaData,
|
|
53
59
|
});
|
|
54
60
|
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
SearchExecutor._endWithError(emitter, err, obsReqHandler);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
55
65
|
obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
|
|
56
66
|
emitter.emit('end');
|
|
57
67
|
}
|
|
@@ -65,9 +75,14 @@ class SearchExecutor {
|
|
|
65
75
|
meta: meta,
|
|
66
76
|
});
|
|
67
77
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
searchPromise.then(([err, resp]) => {
|
|
79
|
+
queryexecutor_1.QueryExecutor._rethrowListenerErrors(() => {
|
|
80
|
+
SearchExecutor._processSearchResponse(emitter, err, resp, obsReqHandler);
|
|
81
|
+
});
|
|
82
|
+
}, (err) => {
|
|
83
|
+
queryexecutor_1.QueryExecutor._rethrowListenerErrors(() => {
|
|
84
|
+
SearchExecutor._endWithError(emitter, err, obsReqHandler);
|
|
85
|
+
});
|
|
71
86
|
});
|
|
72
87
|
return emitter;
|
|
73
88
|
}
|
|
@@ -196,6 +196,11 @@ export declare class ThresholdLoggingSpan implements RequestSpan {
|
|
|
196
196
|
* Adds a timestamped event to the span.
|
|
197
197
|
*/
|
|
198
198
|
addEvent(): void;
|
|
199
|
+
/**
|
|
200
|
+
* Always returns true — threshold logging spans must record every operation
|
|
201
|
+
* to evaluate against configured thresholds.
|
|
202
|
+
*/
|
|
203
|
+
isRecording(): boolean;
|
|
199
204
|
/**
|
|
200
205
|
* Sets the status of the span.
|
|
201
206
|
*
|
package/dist/thresholdlogging.js
CHANGED
|
@@ -447,6 +447,13 @@ class ThresholdLoggingSpan {
|
|
|
447
447
|
* Adds a timestamped event to the span.
|
|
448
448
|
*/
|
|
449
449
|
addEvent() { }
|
|
450
|
+
/**
|
|
451
|
+
* Always returns true — threshold logging spans must record every operation
|
|
452
|
+
* to evaluate against configured thresholds.
|
|
453
|
+
*/
|
|
454
|
+
isRecording() {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
450
457
|
/**
|
|
451
458
|
* Sets the status of the span.
|
|
452
459
|
*
|
package/dist/tracing.d.ts
CHANGED
|
@@ -36,6 +36,12 @@ export interface RequestSpan {
|
|
|
36
36
|
* @param endTime - Optional end time; defaults to current time if not provided.
|
|
37
37
|
*/
|
|
38
38
|
end(endTime?: TimeInput): void;
|
|
39
|
+
/**
|
|
40
|
+
* Returns whether this span is actively recording. When false, setAttribute
|
|
41
|
+
* and processCoreSpan work is skipped. Defaults to true when not implemented,
|
|
42
|
+
* preserving backward compatibility with existing custom implementations.
|
|
43
|
+
*/
|
|
44
|
+
isRecording?(): boolean;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* Interface for creating and managing distributed tracing spans.
|
package/dist/transactions.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Transactions = exports.TransactionAttemptContext = exports.TransactionQueryResult = exports.TransactionGetMultiReplicasFromPreferredServerGroupResult = exports.TransactionGetMultiReplicasFromPreferredServerGroupResultEntry = exports.TransactionGetMultiResult = exports.TransactionGetMultiResultEntry = exports.TransactionGetResult = exports.TransactionResult = exports.TransactionGetMultiReplicasFromPreferredServerGroupSpec = exports.TransactionGetMultiSpec = exports.TransactionGetMultiReplicasFromPreferredServerGroupMode = exports.TransactionGetMultiMode = exports.DocumentId = void 0;
|
|
7
7
|
const binding_1 = __importDefault(require("./binding"));
|
|
8
8
|
const bindingutilities_1 = require("./bindingutilities");
|
|
9
|
+
const errorcontexts_1 = require("./errorcontexts");
|
|
9
10
|
const errors_1 = require("./errors");
|
|
10
11
|
const queryexecutor_1 = require("./queryexecutor");
|
|
11
12
|
const transcoders_1 = require("./transcoders");
|
|
@@ -338,6 +339,28 @@ function translateGetMultiReplicasFromPreferredServerGroupResult(cppRes, transco
|
|
|
338
339
|
content,
|
|
339
340
|
});
|
|
340
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* The C++ core reports no error context for a key-value failure raised inside
|
|
344
|
+
* a transaction, so the context the same operation carries outside one never
|
|
345
|
+
* arrives. Until the core carries it, fill in what the SDK already holds:
|
|
346
|
+
* the document the operation was aimed at. The server-supplied fields are
|
|
347
|
+
* left absent rather than zeroed, since a status_code of 0 is SUCCESS, and a
|
|
348
|
+
* context claiming success for an operation that failed is worse than one
|
|
349
|
+
* that claims nothing.
|
|
350
|
+
*
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
function kvContextFromDocId(err, id) {
|
|
354
|
+
if (err instanceof errors_1.CouchbaseError && !err.context) {
|
|
355
|
+
err.context = new errorcontexts_1.KeyValueErrorContext({
|
|
356
|
+
key: id.key,
|
|
357
|
+
bucket: id.bucket,
|
|
358
|
+
scope: id.scope,
|
|
359
|
+
collection: id.collection,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return err;
|
|
363
|
+
}
|
|
341
364
|
/**
|
|
342
365
|
* Provides an interface to preform transactional operations in a transaction.
|
|
343
366
|
*
|
|
@@ -389,7 +412,7 @@ class TransactionAttemptContext {
|
|
|
389
412
|
this._impl.get({
|
|
390
413
|
id,
|
|
391
414
|
}, (cppErr, cppRes) => {
|
|
392
|
-
const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
|
415
|
+
const err = kvContextFromDocId((0, bindingutilities_1.errorFromCpp)(cppErr), id);
|
|
393
416
|
if (err) {
|
|
394
417
|
return wrapCallback(err, null);
|
|
395
418
|
}
|
|
@@ -411,7 +434,7 @@ class TransactionAttemptContext {
|
|
|
411
434
|
this._impl.getReplicaFromPreferredServerGroup({
|
|
412
435
|
id,
|
|
413
436
|
}, (cppErr, cppRes) => {
|
|
414
|
-
const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
|
437
|
+
const err = kvContextFromDocId((0, bindingutilities_1.errorFromCpp)(cppErr), id);
|
|
415
438
|
if (err) {
|
|
416
439
|
return wrapCallback(err, null);
|
|
417
440
|
}
|
|
@@ -483,7 +506,7 @@ class TransactionAttemptContext {
|
|
|
483
506
|
flags,
|
|
484
507
|
},
|
|
485
508
|
}, (cppErr, cppRes) => {
|
|
486
|
-
const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
|
509
|
+
const err = kvContextFromDocId((0, bindingutilities_1.errorFromCpp)(cppErr), id);
|
|
487
510
|
if (err) {
|
|
488
511
|
return wrapCallback(err, null);
|
|
489
512
|
}
|
|
@@ -518,7 +541,7 @@ class TransactionAttemptContext {
|
|
|
518
541
|
flags,
|
|
519
542
|
},
|
|
520
543
|
}, (cppErr, cppRes) => {
|
|
521
|
-
const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
|
544
|
+
const err = kvContextFromDocId((0, bindingutilities_1.errorFromCpp)(cppErr), doc.id);
|
|
522
545
|
if (err) {
|
|
523
546
|
return wrapCallback(err, null);
|
|
524
547
|
}
|
|
@@ -545,7 +568,7 @@ class TransactionAttemptContext {
|
|
|
545
568
|
metadata: doc._metadata,
|
|
546
569
|
},
|
|
547
570
|
}, (cppErr) => {
|
|
548
|
-
const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
|
571
|
+
const err = kvContextFromDocId((0, bindingutilities_1.errorFromCpp)(cppErr), doc.id);
|
|
549
572
|
wrapCallback(err, null);
|
|
550
573
|
});
|
|
551
574
|
});
|
|
@@ -704,7 +727,7 @@ class Transactions {
|
|
|
704
727
|
e instanceof errors_1.TransactionCommitAmbiguousError) {
|
|
705
728
|
throw e;
|
|
706
729
|
}
|
|
707
|
-
throw new errors_1.TransactionFailedError(e);
|
|
730
|
+
throw new errors_1.TransactionFailedError(e, e instanceof errors_1.CouchbaseError ? e.context : undefined);
|
|
708
731
|
}
|
|
709
732
|
try {
|
|
710
733
|
const txnResult = await txn._commit(); // this is actually finalize internally
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.7.
|
|
1
|
+
export declare const SDK_VERSION = "4.7.2";
|
|
2
2
|
export declare const SDK_NAME = "couchbase";
|
package/dist/version.js
CHANGED
package/dist/viewexecutor.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export declare class ViewExecutor {
|
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
24
|
get observabilityInstruments(): ObservabilityInstruments;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
static _endWithError<TValue = any, TKey = any>(emitter: StreamableRowPromise<ViewResult<TValue, TKey>, ViewRow<TValue, TKey>, ViewMetaData>, err: Error, obsReqHandler?: ObservableRequestHandler): void;
|
|
25
29
|
/**
|
|
26
30
|
* @internal
|
|
27
31
|
*/
|
package/dist/viewexecutor.js
CHANGED
|
@@ -6,8 +6,8 @@ const bindingutilities_1 = require("./bindingutilities");
|
|
|
6
6
|
const observability_1 = require("./observability");
|
|
7
7
|
const observabilityhandler_1 = require("./observabilityhandler");
|
|
8
8
|
const observabilitytypes_1 = require("./observabilitytypes");
|
|
9
|
+
const queryexecutor_1 = require("./queryexecutor");
|
|
9
10
|
const streamablepromises_1 = require("./streamablepromises");
|
|
10
|
-
const utilities_1 = require("./utilities");
|
|
11
11
|
const viewtypes_1 = require("./viewtypes");
|
|
12
12
|
/**
|
|
13
13
|
* @internal
|
|
@@ -31,24 +31,30 @@ class ViewExecutor {
|
|
|
31
31
|
get observabilityInstruments() {
|
|
32
32
|
return this._cluster.observabilityInstruments;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
static _endWithError(emitter, err, obsReqHandler) {
|
|
38
|
+
obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
|
|
39
|
+
emitter.emit('error', err);
|
|
40
|
+
emitter.emit('end');
|
|
41
|
+
}
|
|
34
42
|
/**
|
|
35
43
|
* @internal
|
|
36
44
|
*/
|
|
37
45
|
static _processViewResponse(emitter, err, resp, obsReqHandler) {
|
|
38
46
|
if (err) {
|
|
39
|
-
|
|
40
|
-
emitter.emit('error', err);
|
|
41
|
-
emitter.emit('end');
|
|
47
|
+
ViewExecutor._endWithError(emitter, err, obsReqHandler);
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
try {
|
|
51
|
+
resp.rows.forEach((row) => {
|
|
52
|
+
emitter.emit('row', new viewtypes_1.ViewRow({
|
|
53
|
+
value: JSON.parse(row.value),
|
|
54
|
+
id: row.id,
|
|
55
|
+
key: JSON.parse(row.key),
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
52
58
|
const metaData = resp.meta;
|
|
53
59
|
const meta = new viewtypes_1.ViewMetaData({
|
|
54
60
|
totalRows: metaData.total_rows,
|
|
@@ -56,6 +62,10 @@ class ViewExecutor {
|
|
|
56
62
|
});
|
|
57
63
|
emitter.emit('meta', meta);
|
|
58
64
|
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
ViewExecutor._endWithError(emitter, err, obsReqHandler);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
59
69
|
obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
|
|
60
70
|
emitter.emit('end');
|
|
61
71
|
}
|
|
@@ -69,9 +79,14 @@ class ViewExecutor {
|
|
|
69
79
|
meta: meta,
|
|
70
80
|
});
|
|
71
81
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
viewPromise.then(([err, resp]) => {
|
|
83
|
+
queryexecutor_1.QueryExecutor._rethrowListenerErrors(() => {
|
|
84
|
+
ViewExecutor._processViewResponse(emitter, err, resp, obsReqHandler);
|
|
85
|
+
});
|
|
86
|
+
}, (err) => {
|
|
87
|
+
queryexecutor_1.QueryExecutor._rethrowListenerErrors(() => {
|
|
88
|
+
ViewExecutor._endWithError(emitter, err, obsReqHandler);
|
|
89
|
+
});
|
|
75
90
|
});
|
|
76
91
|
return emitter;
|
|
77
92
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Cluster } from './cluster';
|
|
2
|
+
import { WaitUntilReadyOptions } from './diagnosticstypes';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class WaitUntilReadyExecutor {
|
|
7
|
+
private _cluster;
|
|
8
|
+
private _bucketName;
|
|
9
|
+
private _diagExec;
|
|
10
|
+
private _pingExec;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
constructor(cluster: Cluster, bucketName?: string);
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether the endpoints for a single service satisfy the desired cluster state.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
private _meetsDesiredState;
|
|
21
|
+
/**
|
|
22
|
+
* Logs any ping endpoints that reported an error, at warn level.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
private _logPingErrors;
|
|
27
|
+
/**
|
|
28
|
+
* Builds the set of services to wait on, either from the user provided list or via discovery ping.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
private _resolveWaitSet;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
waitUntilReady(timeout: number, options: WaitUntilReadyOptions): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaitUntilReadyExecutor = void 0;
|
|
4
|
+
const diagnosticsexecutor_1 = require("./diagnosticsexecutor");
|
|
5
|
+
const diagnosticstypes_1 = require("./diagnosticstypes");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
const generaltypes_1 = require("./generaltypes");
|
|
8
|
+
const utilities_1 = require("./utilities");
|
|
9
|
+
const ALL_SERVICE_TYPES = Object.values(generaltypes_1.ServiceType);
|
|
10
|
+
const BACKOFF_BASE_MS = 50;
|
|
11
|
+
const BACKOFF_CAP_MS = 500;
|
|
12
|
+
const BACKOFF_MAX_EXP = 4;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
class WaitUntilReadyExecutor {
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
constructor(cluster, bucketName) {
|
|
21
|
+
this._cluster = cluster;
|
|
22
|
+
this._bucketName = bucketName;
|
|
23
|
+
this._diagExec = new diagnosticsexecutor_1.DiagnoticsExecutor(cluster);
|
|
24
|
+
this._pingExec = new diagnosticsexecutor_1.PingExecutor(cluster);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether the endpoints for a single service satisfy the desired cluster state.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
_meetsDesiredState(endpoints, desiredState) {
|
|
32
|
+
if (endpoints.length === 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const connected = endpoints.filter((ep) => ep.state === diagnosticstypes_1.EndpointState.Connected).length;
|
|
36
|
+
if (desiredState === diagnosticstypes_1.ClusterState.Online) {
|
|
37
|
+
return connected === endpoints.length;
|
|
38
|
+
}
|
|
39
|
+
if (desiredState === diagnosticstypes_1.ClusterState.Degraded) {
|
|
40
|
+
return connected > 0;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Logs any ping endpoints that reported an error, at warn level.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
_logPingErrors(pingResult) {
|
|
50
|
+
for (const [serviceType, endpoints] of Object.entries(pingResult.services)) {
|
|
51
|
+
for (const ep of endpoints) {
|
|
52
|
+
if (ep.state === diagnosticstypes_1.PingState.Error && ep.error) {
|
|
53
|
+
this._cluster.logger.warn(`waitUntilReady: ping error on service ${serviceType}, remote ${ep.remote}: ${ep.error}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Builds the set of services to wait on, either from the user provided list or via discovery ping.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
async _resolveWaitSet(serviceTypes, deadline) {
|
|
64
|
+
let waitSet;
|
|
65
|
+
if (serviceTypes) {
|
|
66
|
+
waitSet = [...serviceTypes];
|
|
67
|
+
if (this._bucketName === undefined) {
|
|
68
|
+
const filtered = waitSet.filter((s) => s === generaltypes_1.ServiceType.KeyValue || s === generaltypes_1.ServiceType.Views);
|
|
69
|
+
if (filtered.length > 0) {
|
|
70
|
+
this._cluster.logger.warn(`waitUntilReady: ignoring [${filtered.join(', ')}] at cluster scope (no bucket context)`);
|
|
71
|
+
waitSet = waitSet.filter((s) => s !== generaltypes_1.ServiceType.KeyValue && s !== generaltypes_1.ServiceType.Views);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const discoveryResult = await this._pingExec.ping({
|
|
77
|
+
bucket: this._bucketName,
|
|
78
|
+
timeout: deadline.left(),
|
|
79
|
+
});
|
|
80
|
+
this._logPingErrors(discoveryResult);
|
|
81
|
+
waitSet = [];
|
|
82
|
+
for (const [serviceType, endpoints] of Object.entries(discoveryResult.services)) {
|
|
83
|
+
if (endpoints.length > 0) {
|
|
84
|
+
waitSet.push(serviceType);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return waitSet;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
async waitUntilReady(timeout, options) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
if (typeof timeout !== 'number' || !isFinite(timeout) || timeout <= 0) {
|
|
96
|
+
throw new errors_1.InvalidArgumentError(new Error('timeout must be a positive finite number'));
|
|
97
|
+
}
|
|
98
|
+
const desiredState = (_a = options.desiredState) !== null && _a !== void 0 ? _a : diagnosticstypes_1.ClusterState.Online;
|
|
99
|
+
if (desiredState === diagnosticstypes_1.ClusterState.Offline) {
|
|
100
|
+
throw new errors_1.InvalidArgumentError(new Error('ClusterState.Offline is not a valid desired state'));
|
|
101
|
+
}
|
|
102
|
+
if (options.serviceTypes) {
|
|
103
|
+
for (const st of options.serviceTypes) {
|
|
104
|
+
if (!ALL_SERVICE_TYPES.includes(st)) {
|
|
105
|
+
throw new errors_1.InvalidArgumentError(new Error(`Invalid service type: ${st}`));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (options.serviceTypes.length === 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const deadline = new utilities_1.CompoundTimeout(timeout);
|
|
113
|
+
const waitSet = await this._resolveWaitSet(options.serviceTypes, deadline);
|
|
114
|
+
if (waitSet.length === 0) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let iterations = 0;
|
|
118
|
+
let needPing = [...waitSet];
|
|
119
|
+
while (true) {
|
|
120
|
+
const diagResult = await this._diagExec.diagnostics({});
|
|
121
|
+
needPing = [];
|
|
122
|
+
for (const svc of waitSet) {
|
|
123
|
+
const endpoints = diagResult.services[svc] || [];
|
|
124
|
+
if (!this._meetsDesiredState(endpoints, desiredState)) {
|
|
125
|
+
needPing.push(svc);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (needPing.length === 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (deadline.expired()) {
|
|
132
|
+
throw new errors_1.UnambiguousTimeoutError(new Error('Timed out prior to reaching desired state. ' +
|
|
133
|
+
'Services not ready: ' + needPing.join(', ')));
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const pingResult = await this._pingExec.ping({
|
|
137
|
+
serviceTypes: needPing,
|
|
138
|
+
bucket: this._bucketName,
|
|
139
|
+
timeout: deadline.left(),
|
|
140
|
+
});
|
|
141
|
+
this._logPingErrors(pingResult);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// One failed ping isn't fatal, try again or eventually time out after deadline is reached.
|
|
145
|
+
}
|
|
146
|
+
const backoffMs = Math.min(BACKOFF_BASE_MS * Math.pow(2, Math.min(iterations, BACKOFF_MAX_EXP)), BACKOFF_CAP_MS);
|
|
147
|
+
const timeLeft = (_b = deadline.left()) !== null && _b !== void 0 ? _b : 0;
|
|
148
|
+
const sleepMs = Math.min(backoffMs, timeLeft);
|
|
149
|
+
if (sleepMs > 0) {
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, sleepMs));
|
|
151
|
+
}
|
|
152
|
+
iterations++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.WaitUntilReadyExecutor = WaitUntilReadyExecutor;
|
package/package.json
CHANGED
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"type": "git",
|
|
69
69
|
"url": "http://github.com/couchbase/couchnode.git"
|
|
70
70
|
},
|
|
71
|
-
"version": "4.7.
|
|
71
|
+
"version": "4.7.2",
|
|
72
72
|
"config": {
|
|
73
73
|
"native": false
|
|
74
74
|
},
|
|
@@ -166,12 +166,12 @@
|
|
|
166
166
|
"deps/couchbase-cxx-cache/mozilla-ca-bundle.*"
|
|
167
167
|
],
|
|
168
168
|
"optionalDependencies": {
|
|
169
|
-
"@couchbase/couchbase-darwin-arm64-napi": "4.7.
|
|
170
|
-
"@couchbase/couchbase-darwin-x64-napi": "4.7.
|
|
171
|
-
"@couchbase/couchbase-linux-arm64-napi": "4.7.
|
|
172
|
-
"@couchbase/couchbase-linuxmusl-arm64-napi": "4.7.
|
|
173
|
-
"@couchbase/couchbase-linuxmusl-x64-napi": "4.7.
|
|
174
|
-
"@couchbase/couchbase-linux-x64-napi": "4.7.
|
|
175
|
-
"@couchbase/couchbase-win32-x64-napi": "4.7.
|
|
169
|
+
"@couchbase/couchbase-darwin-arm64-napi": "4.7.2",
|
|
170
|
+
"@couchbase/couchbase-darwin-x64-napi": "4.7.2",
|
|
171
|
+
"@couchbase/couchbase-linux-arm64-napi": "4.7.2",
|
|
172
|
+
"@couchbase/couchbase-linuxmusl-arm64-napi": "4.7.2",
|
|
173
|
+
"@couchbase/couchbase-linuxmusl-x64-napi": "4.7.2",
|
|
174
|
+
"@couchbase/couchbase-linux-x64-napi": "4.7.2",
|
|
175
|
+
"@couchbase/couchbase-win32-x64-napi": "4.7.2"
|
|
176
176
|
}
|
|
177
177
|
}
|
package/scripts/prebuilds.js
CHANGED
|
@@ -100,6 +100,19 @@ function buildBinary(
|
|
|
100
100
|
cmakejsBuildCmd.push(...['--config', `${buildConfig}`])
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
const sanitizers = process.env.CN_SANITIZERS
|
|
104
|
+
if (sanitizers && sanitizers.length > 0) {
|
|
105
|
+
for (const sanitizer of sanitizers.split(',')) {
|
|
106
|
+
if (
|
|
107
|
+
['address', 'thread', 'undefined', 'memory', 'leak'].includes(
|
|
108
|
+
sanitizer
|
|
109
|
+
)
|
|
110
|
+
) {
|
|
111
|
+
cmakejsBuildCmd.push(`--CDENABLE_SANITIZER_${sanitizer.toUpperCase()}=ON`)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
103
116
|
const cmakeGeneratorPlatform = process.env.CN_CMAKE_GENERATOR_PLATFORM
|
|
104
117
|
if (cmakeGeneratorPlatform) {
|
|
105
118
|
cmakejsBuildCmd.push(`--generator=${cmakeGeneratorPlatform}`)
|
package/src/binding.cpp
CHANGED
|
@@ -51,7 +51,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|
|
51
51
|
cbppLogLevel = couchbase::core::logger::level::info;
|
|
52
52
|
} else if (logLevelStr == "warn") {
|
|
53
53
|
cbppLogLevel = couchbase::core::logger::level::warn;
|
|
54
|
-
} else if (logLevelStr == "err") {
|
|
54
|
+
} else if (logLevelStr == "err" || logLevelStr == "error") {
|
|
55
55
|
cbppLogLevel = couchbase::core::logger::level::err;
|
|
56
56
|
} else if (logLevelStr == "critical") {
|
|
57
57
|
cbppLogLevel = couchbase::core::logger::level::critical;
|
package/src/connection.hpp
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
#include "addondata.hpp"
|
|
3
3
|
#include "instance.hpp"
|
|
4
4
|
#include "jstocbpp.hpp"
|
|
5
|
+
#include <core/logger/logger.hxx>
|
|
5
6
|
#include <core/tracing/wrapper_sdk_tracer.hxx>
|
|
6
7
|
#include <core/utils/movable_function.hxx>
|
|
7
8
|
#include <napi.h>
|
|
9
|
+
#include <utility>
|
|
8
10
|
|
|
9
11
|
namespace couchnode
|
|
10
12
|
{
|
|
@@ -31,15 +33,34 @@ public:
|
|
|
31
33
|
|
|
32
34
|
CallCookie(CallCookie &o) = delete;
|
|
33
35
|
|
|
36
|
+
// The thread-safe function wrapper copies its handle on a move, so take
|
|
37
|
+
// it explicitly and leave the source with nothing to release.
|
|
34
38
|
CallCookie(CallCookie &&o)
|
|
35
|
-
: _ttsf(std::
|
|
39
|
+
: _ttsf(std::exchange(o._ttsf, CallCookieTTSF()))
|
|
36
40
|
{
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
// Release the thread-safe function if invoke() never ran, so a cookie
|
|
44
|
+
// that is dropped cannot keep a reference on the event loop.
|
|
45
|
+
~CallCookie()
|
|
46
|
+
{
|
|
47
|
+
if (static_cast<napi_threadsafe_function>(_ttsf) != nullptr) {
|
|
48
|
+
_ttsf.Release();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
39
52
|
void invoke(FwdFunc &&callback)
|
|
40
53
|
{
|
|
41
|
-
|
|
42
|
-
_ttsf.
|
|
54
|
+
auto *fn = new FwdFunc(std::move(callback));
|
|
55
|
+
auto status = _ttsf.BlockingCall(fn);
|
|
56
|
+
if (status != napi_ok) {
|
|
57
|
+
// BlockingCall only takes ownership of fn once the item is queued,
|
|
58
|
+
// so on failure it is still ours to free.
|
|
59
|
+
CB_LOG_WARNING("Unable to queue callback for execution (status={})",
|
|
60
|
+
static_cast<int>(status));
|
|
61
|
+
delete fn;
|
|
62
|
+
}
|
|
63
|
+
std::exchange(_ttsf, CallCookieTTSF()).Release();
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
private:
|
package/src/jstocbpp_errors.hpp
CHANGED
|
@@ -69,6 +69,9 @@ struct js_to_cbpp_t<couchbase::core::key_value_error_context> {
|
|
|
69
69
|
err.Set("ctxtype", Napi::String::New(env, "key_value"));
|
|
70
70
|
err.Set("code", cbpp_to_js(env, ctx.ec().value()));
|
|
71
71
|
err.Set("id", cbpp_to_js(env, ctx.id()));
|
|
72
|
+
err.Set("bucket", cbpp_to_js(env, ctx.bucket()));
|
|
73
|
+
err.Set("scope", cbpp_to_js(env, ctx.scope()));
|
|
74
|
+
err.Set("collection", cbpp_to_js(env, ctx.collection()));
|
|
72
75
|
err.Set("opaque", cbpp_to_js(env, ctx.opaque()));
|
|
73
76
|
err.Set("cas", cbpp_to_js(env, ctx.cas()));
|
|
74
77
|
err.Set("status_code", cbpp_to_js(env, ctx.status_code()));
|
|
@@ -100,6 +103,9 @@ struct js_to_cbpp_t<couchbase::core::subdocument_error_context> {
|
|
|
100
103
|
err.Set("ctxtype", Napi::String::New(env, "subdocument"));
|
|
101
104
|
err.Set("code", cbpp_to_js(env, ctx.ec().value()));
|
|
102
105
|
err.Set("id", cbpp_to_js(env, ctx.id()));
|
|
106
|
+
err.Set("bucket", cbpp_to_js(env, ctx.bucket()));
|
|
107
|
+
err.Set("scope", cbpp_to_js(env, ctx.scope()));
|
|
108
|
+
err.Set("collection", cbpp_to_js(env, ctx.collection()));
|
|
103
109
|
err.Set("opaque", cbpp_to_js(env, ctx.opaque()));
|
|
104
110
|
err.Set("cas", cbpp_to_js(env, ctx.cas()));
|
|
105
111
|
err.Set("status_code", cbpp_to_js(env, ctx.status_code()));
|