@google-cloud/spanner 8.11.0 → 8.13.0
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/build/src/common-grpc/service.js +9 -10
- package/build/src/database.d.ts +33 -0
- package/build/src/database.js +161 -41
- package/build/src/instance-config.d.ts +1 -2
- package/build/src/instance-config.js +1 -1
- package/build/src/instance.d.ts +1 -2
- package/build/src/instrument.js +9 -5
- package/build/src/metrics/interceptor.js +4 -1
- package/build/src/metrics/spanner-metrics-exporter.js +3 -1
- package/build/src/multiplexed-session.d.ts +3 -0
- package/build/src/multiplexed-session.js +28 -2
- package/build/src/partial-result-stream.d.ts +43 -0
- package/build/src/partial-result-stream.js +303 -85
- package/build/src/session-factory.d.ts +4 -2
- package/build/src/session-factory.js +14 -3
- package/build/src/transaction.d.ts +64 -8
- package/build/src/transaction.js +429 -18
- package/package.json +5 -10
package/build/src/transaction.js
CHANGED
|
@@ -24,13 +24,14 @@ const google_gax_1 = require("google-gax");
|
|
|
24
24
|
const stream_1 = require("stream");
|
|
25
25
|
const codec_1 = require("./codec");
|
|
26
26
|
const partial_result_stream_1 = require("./partial-result-stream");
|
|
27
|
+
const instrument_1 = require("./instrument");
|
|
27
28
|
const common_1 = require("./common");
|
|
28
29
|
const spanner_api_1 = require("@google-cloud/spanner-api");
|
|
29
30
|
var spannerClient = spanner_api_1.protos.google;
|
|
30
31
|
var google = spanner_api_1.protos.google;
|
|
31
32
|
var IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
|
|
32
33
|
var ReadLockMode = google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
|
|
33
|
-
const
|
|
34
|
+
const transaction_runner_1 = require("./transaction-runner");
|
|
34
35
|
const request_id_header_1 = require("./request_id_header");
|
|
35
36
|
const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.retryinfo';
|
|
36
37
|
const RETRY_INFO_BIN = 'google.rpc.retryinfo-bin';
|
|
@@ -48,6 +49,17 @@ function injectGaxOpt(existingOpts, key, value) {
|
|
|
48
49
|
}),
|
|
49
50
|
});
|
|
50
51
|
}
|
|
52
|
+
function normalizeError(err) {
|
|
53
|
+
const errorWithCode = err;
|
|
54
|
+
if (errorWithCode.code === undefined) {
|
|
55
|
+
Object.assign(errorWithCode, {
|
|
56
|
+
code: google_gax_1.grpc.status.UNKNOWN,
|
|
57
|
+
details: err.message,
|
|
58
|
+
metadata: new google_gax_1.grpc.Metadata(),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return errorWithCode;
|
|
62
|
+
}
|
|
51
63
|
/**
|
|
52
64
|
* @typedef {object} TimestampBounds
|
|
53
65
|
* @property {boolean} [strong=true] Read at a timestamp where all previously
|
|
@@ -746,6 +758,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
746
758
|
return;
|
|
747
759
|
}
|
|
748
760
|
this.ended = true;
|
|
761
|
+
this._releaseWaitingRequests(new Error('Transaction has ended.'));
|
|
749
762
|
process.nextTick(() => this.emit('end'));
|
|
750
763
|
if (this._affinityKey) {
|
|
751
764
|
const database = this.session?.parent;
|
|
@@ -754,7 +767,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
754
767
|
if (client?.spannerStub) {
|
|
755
768
|
Promise.resolve(client.spannerStub)
|
|
756
769
|
.then((stub) => {
|
|
757
|
-
stub?.getChannel?.()?.unbind?.(this._affinityKey);
|
|
770
|
+
return stub?.getChannel?.()?.unbind?.(this._affinityKey);
|
|
758
771
|
})
|
|
759
772
|
.catch(() => { });
|
|
760
773
|
}
|
|
@@ -791,6 +804,19 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
791
804
|
});
|
|
792
805
|
}
|
|
793
806
|
run(query, callback) {
|
|
807
|
+
if (this.runStream !== Snapshot.prototype.runStream) {
|
|
808
|
+
return this._runLegacy(query, callback);
|
|
809
|
+
}
|
|
810
|
+
return this._run(query, callback);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Always runs the query through the full streaming pipeline (Snapshot.prototype.runStream).
|
|
814
|
+
* Used when runStream has been overridden on Snapshot to preserve backward compatibility
|
|
815
|
+
* with custom stream implementations.
|
|
816
|
+
*
|
|
817
|
+
* @private
|
|
818
|
+
*/
|
|
819
|
+
_runLegacy(query, callback) {
|
|
794
820
|
const rows = [];
|
|
795
821
|
let stats;
|
|
796
822
|
let metadata;
|
|
@@ -798,18 +824,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
798
824
|
...query,
|
|
799
825
|
...this._traceConfig,
|
|
800
826
|
}, span => {
|
|
801
|
-
|
|
827
|
+
this.runStream(query)
|
|
802
828
|
.on('error', err => {
|
|
803
829
|
(0, instrument_1.setSpanError)(span, err);
|
|
804
830
|
span.end();
|
|
805
|
-
|
|
806
|
-
Object.assign(err, {
|
|
807
|
-
code: google_gax_1.grpc.status.UNKNOWN,
|
|
808
|
-
details: err.message,
|
|
809
|
-
metadata: new google_gax_1.grpc.Metadata(),
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
callback(err, rows, stats, metadata);
|
|
831
|
+
callback(normalizeError(err), rows, stats, metadata);
|
|
813
832
|
})
|
|
814
833
|
.on('response', response => {
|
|
815
834
|
if (response.metadata) {
|
|
@@ -819,14 +838,298 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
819
838
|
}
|
|
820
839
|
}
|
|
821
840
|
})
|
|
822
|
-
.on('data', row =>
|
|
823
|
-
.
|
|
841
|
+
.on('data', row => {
|
|
842
|
+
rows.push(row);
|
|
843
|
+
})
|
|
844
|
+
.on('stats', _stats => {
|
|
845
|
+
stats = _stats;
|
|
846
|
+
})
|
|
824
847
|
.on('end', () => {
|
|
825
848
|
span.end();
|
|
826
849
|
callback(null, rows, stats, metadata);
|
|
827
850
|
});
|
|
828
851
|
});
|
|
829
852
|
}
|
|
853
|
+
/**
|
|
854
|
+
* Executes a query using an optimized streaming model:
|
|
855
|
+
* 1. If all results are returned in a single PartialResultSet, the internal streaming
|
|
856
|
+
* pipeline is simplified and rows are decoded directly, bypassing Stream overhead.
|
|
857
|
+
* 2. If there are more than one PartialResultSets, it seamlessly falls back to
|
|
858
|
+
* the standard streaming model.
|
|
859
|
+
*
|
|
860
|
+
* @private
|
|
861
|
+
*/
|
|
862
|
+
_run(queryInput, callback, options) {
|
|
863
|
+
let query = typeof queryInput === 'string' ? { sql: queryInput } : queryInput;
|
|
864
|
+
query = Object.assign({}, query);
|
|
865
|
+
query.queryOptions = Object.assign(Object.assign({}, this.queryOptions), query.queryOptions);
|
|
866
|
+
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, types: _omittedTypes, directedReadOptions: rawDirectedReadOptions, ...rawQuery } = query;
|
|
867
|
+
void _omittedTypes;
|
|
868
|
+
let formattedRequest;
|
|
869
|
+
const seqno = this._seqno++;
|
|
870
|
+
const directedReadOptions = this._getDirectedReadOptions(rawDirectedReadOptions);
|
|
871
|
+
const sanitizeRequest = () => {
|
|
872
|
+
const { params, paramTypes } = Snapshot.encodeParams(query);
|
|
873
|
+
const transaction = {};
|
|
874
|
+
if (this.id) {
|
|
875
|
+
transaction.id = this.id;
|
|
876
|
+
}
|
|
877
|
+
else if (this._options.readWrite) {
|
|
878
|
+
transaction.begin = this._options;
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
transaction.singleUse = this._options;
|
|
882
|
+
}
|
|
883
|
+
if (!this.id &&
|
|
884
|
+
this._options.readWrite &&
|
|
885
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
886
|
+
this._setPreviousTransactionId(transaction);
|
|
887
|
+
}
|
|
888
|
+
formattedRequest = Object.assign({}, rawQuery, {
|
|
889
|
+
session: this.session.formattedName_,
|
|
890
|
+
seqno,
|
|
891
|
+
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', this.requestOptions?.transactionTag ?? undefined, requestOptions),
|
|
892
|
+
directedReadOptions,
|
|
893
|
+
transaction,
|
|
894
|
+
params,
|
|
895
|
+
paramTypes,
|
|
896
|
+
});
|
|
897
|
+
};
|
|
898
|
+
const headers = Object.assign({}, this.commonHeaders_);
|
|
899
|
+
if (this._getSpanner().routeToLeaderEnabled &&
|
|
900
|
+
(this._options.readWrite !== undefined ||
|
|
901
|
+
this._options.partitionedDml !== undefined)) {
|
|
902
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
903
|
+
}
|
|
904
|
+
const traceConfig = {
|
|
905
|
+
transactionTag: this.requestOptions?.transactionTag,
|
|
906
|
+
requestTag: requestOptions?.requestTag,
|
|
907
|
+
...query,
|
|
908
|
+
...this._traceConfig,
|
|
909
|
+
};
|
|
910
|
+
const executeWithSpans = (fn) => {
|
|
911
|
+
const startRunSpan = options?.startRunSpan !== false;
|
|
912
|
+
if (startRunSpan) {
|
|
913
|
+
return (0, instrument_1.startTrace)('Snapshot.run', traceConfig, runSpan => {
|
|
914
|
+
return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, streamSpan => {
|
|
915
|
+
fn(runSpan, streamSpan);
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
else {
|
|
920
|
+
return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, streamSpan => {
|
|
921
|
+
fn(null, streamSpan);
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
executeWithSpans((runSpan, streamSpan) => {
|
|
926
|
+
let attempt = 0;
|
|
927
|
+
const database = this.session.parent;
|
|
928
|
+
const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
|
|
929
|
+
let completed = false;
|
|
930
|
+
const complete = (err, rows = [], stats, metadata) => {
|
|
931
|
+
if (completed) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
completed = true;
|
|
935
|
+
if (err) {
|
|
936
|
+
(0, instrument_1.setSpanError)(streamSpan, err);
|
|
937
|
+
}
|
|
938
|
+
streamSpan.end();
|
|
939
|
+
if (runSpan) {
|
|
940
|
+
if (err) {
|
|
941
|
+
(0, instrument_1.setSpanError)(runSpan, err);
|
|
942
|
+
}
|
|
943
|
+
runSpan.end();
|
|
944
|
+
}
|
|
945
|
+
callback(err ? normalizeError(err) : null, rows, stats, metadata);
|
|
946
|
+
};
|
|
947
|
+
const makeRequest = (resumeToken) => {
|
|
948
|
+
attempt++;
|
|
949
|
+
if (!resumeToken) {
|
|
950
|
+
if (attempt === 1) {
|
|
951
|
+
streamSpan.addEvent('Starting stream');
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
streamSpan.addEvent('Re-attempting start stream', { attempt });
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
streamSpan.addEvent('Resuming stream', {
|
|
959
|
+
resume_token: resumeToken.toString(),
|
|
960
|
+
attempt,
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
if (!formattedRequest ||
|
|
964
|
+
(this.id && !formattedRequest.transaction?.id)) {
|
|
965
|
+
try {
|
|
966
|
+
sanitizeRequest();
|
|
967
|
+
}
|
|
968
|
+
catch (e) {
|
|
969
|
+
const errorStream = new stream_1.PassThrough();
|
|
970
|
+
setImmediate(() => {
|
|
971
|
+
errorStream.destroy(e);
|
|
972
|
+
});
|
|
973
|
+
return errorStream;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const injectedHeaders = (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt);
|
|
977
|
+
const requestId = injectedHeaders[request_id_header_1.X_GOOG_SPANNER_REQUEST_ID_HEADER];
|
|
978
|
+
if (runSpan && requestId) {
|
|
979
|
+
runSpan.setAttribute(request_id_header_1.X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR, requestId);
|
|
980
|
+
}
|
|
981
|
+
return this.requestStream({
|
|
982
|
+
client: 'SpannerClient',
|
|
983
|
+
method: 'executeStreamingSql',
|
|
984
|
+
reqOpts: Object.assign({}, formattedRequest, {
|
|
985
|
+
resumeToken,
|
|
986
|
+
}),
|
|
987
|
+
gaxOpts: gaxOptions,
|
|
988
|
+
headers: injectedHeaders,
|
|
989
|
+
});
|
|
990
|
+
};
|
|
991
|
+
const retryableCodes = [google_gax_1.grpc.status.UNAVAILABLE];
|
|
992
|
+
const wrappedMakeRequest = this._wrapWithIdWaiter(makeRequest);
|
|
993
|
+
const startTime = Date.now();
|
|
994
|
+
const timeout = gaxOptions?.timeout ?? Infinity;
|
|
995
|
+
const executeRequest = () => {
|
|
996
|
+
const requestStream = this.id ? makeRequest() : wrappedMakeRequest();
|
|
997
|
+
const onError = (err) => {
|
|
998
|
+
const elapsed = Date.now() - startTime;
|
|
999
|
+
let maxRetries = Infinity;
|
|
1000
|
+
if (maxResumeRetries !== undefined) {
|
|
1001
|
+
maxRetries = maxResumeRetries;
|
|
1002
|
+
}
|
|
1003
|
+
else if (timeout === Infinity) {
|
|
1004
|
+
maxRetries = 10;
|
|
1005
|
+
}
|
|
1006
|
+
if (elapsed < timeout &&
|
|
1007
|
+
attempt <= maxRetries &&
|
|
1008
|
+
err.code &&
|
|
1009
|
+
(retryableCodes.includes(err.code) || (0, transaction_runner_1.isRetryableInternalError)(err))) {
|
|
1010
|
+
requestStream.removeAllListeners();
|
|
1011
|
+
requestStream.on('error', () => { });
|
|
1012
|
+
requestStream.destroy();
|
|
1013
|
+
setImmediate(() => {
|
|
1014
|
+
executeRequest();
|
|
1015
|
+
});
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const wasAborted = isErrorAborted(err);
|
|
1019
|
+
if (!this.id && this._useInRunner && !wasAborted) {
|
|
1020
|
+
streamSpan.addEvent('Stream broken. Safe to retry');
|
|
1021
|
+
void this.begin();
|
|
1022
|
+
}
|
|
1023
|
+
else if (wasAborted) {
|
|
1024
|
+
streamSpan.addEvent('Stream broken. Not safe to retry', {
|
|
1025
|
+
'transaction.id': this.id?.toString(),
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
const finalError = elapsed >= timeout ? new transaction_runner_1.DeadlineError(err) : err;
|
|
1029
|
+
complete(finalError);
|
|
1030
|
+
};
|
|
1031
|
+
const onEnd = () => {
|
|
1032
|
+
requestStream.removeListener('error', onError);
|
|
1033
|
+
complete(null, []);
|
|
1034
|
+
};
|
|
1035
|
+
const onData = (firstChunk) => {
|
|
1036
|
+
requestStream.removeListener('error', onError);
|
|
1037
|
+
requestStream.removeListener('end', onEnd);
|
|
1038
|
+
if (firstChunk.last && !firstChunk.chunkedValue) {
|
|
1039
|
+
// ⚡ FAST-PATH: Complete result in single chunk!
|
|
1040
|
+
if (firstChunk.metadata?.transaction && !this.id) {
|
|
1041
|
+
this._update(firstChunk.metadata.transaction, streamSpan);
|
|
1042
|
+
}
|
|
1043
|
+
this._updatePrecommitToken(firstChunk);
|
|
1044
|
+
let rows;
|
|
1045
|
+
try {
|
|
1046
|
+
rows = (0, partial_result_stream_1.decodeRowsDirect)(firstChunk, {
|
|
1047
|
+
json,
|
|
1048
|
+
jsonOptions,
|
|
1049
|
+
columnsMetadata,
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
catch (decodeErr) {
|
|
1053
|
+
requestStream.removeAllListeners();
|
|
1054
|
+
requestStream.on('error', () => { });
|
|
1055
|
+
requestStream.destroy();
|
|
1056
|
+
complete(decodeErr, [], undefined, firstChunk.metadata || undefined);
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
// Query completed successfully. Do not cancel the gRPC call; allow it
|
|
1060
|
+
// to drain remaining trailers/EOF in the background so it is not marked
|
|
1061
|
+
// CANCELLED by Spanner or Cloud Monitoring.
|
|
1062
|
+
requestStream.removeAllListeners('data');
|
|
1063
|
+
requestStream.removeAllListeners('error');
|
|
1064
|
+
requestStream.on('error', () => { });
|
|
1065
|
+
requestStream.resume();
|
|
1066
|
+
complete(null, rows, firstChunk.stats || undefined, firstChunk.metadata || undefined);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
// 🌊 FALLBACK PATH: Multi-chunk query!
|
|
1070
|
+
if (firstChunk.metadata?.transaction && !this.id) {
|
|
1071
|
+
this._update(firstChunk.metadata.transaction, streamSpan);
|
|
1072
|
+
}
|
|
1073
|
+
this._updatePrecommitToken(firstChunk);
|
|
1074
|
+
requestStream.removeAllListeners('data');
|
|
1075
|
+
requestStream.removeAllListeners('error');
|
|
1076
|
+
const replayStream = new stream_1.PassThrough({ objectMode: true });
|
|
1077
|
+
replayStream.write(firstChunk);
|
|
1078
|
+
requestStream.pipe(replayStream);
|
|
1079
|
+
requestStream.on('error', err => {
|
|
1080
|
+
replayStream.destroy(err);
|
|
1081
|
+
});
|
|
1082
|
+
replayStream.on('close', () => {
|
|
1083
|
+
if (!requestStream.destroyed) {
|
|
1084
|
+
if (requestStream.readableEnded) {
|
|
1085
|
+
requestStream.resume();
|
|
1086
|
+
}
|
|
1087
|
+
else {
|
|
1088
|
+
requestStream.destroy();
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
let initialStream = replayStream;
|
|
1093
|
+
const fallbackMakeRequest = (resumeToken) => {
|
|
1094
|
+
if (!resumeToken && initialStream) {
|
|
1095
|
+
const stream = initialStream;
|
|
1096
|
+
initialStream = null;
|
|
1097
|
+
return stream;
|
|
1098
|
+
}
|
|
1099
|
+
return makeRequest(resumeToken);
|
|
1100
|
+
};
|
|
1101
|
+
const rows = [];
|
|
1102
|
+
let stats;
|
|
1103
|
+
let metadata;
|
|
1104
|
+
const fallbackStream = (0, partial_result_stream_1.partialResultStream)(fallbackMakeRequest, {
|
|
1105
|
+
json,
|
|
1106
|
+
jsonOptions,
|
|
1107
|
+
maxResumeRetries,
|
|
1108
|
+
columnsMetadata,
|
|
1109
|
+
gaxOptions,
|
|
1110
|
+
});
|
|
1111
|
+
fallbackStream
|
|
1112
|
+
.on('response', response => {
|
|
1113
|
+
this._updatePrecommitToken(response);
|
|
1114
|
+
if (response.metadata?.transaction && !this.id) {
|
|
1115
|
+
this._update(response.metadata.transaction, streamSpan);
|
|
1116
|
+
}
|
|
1117
|
+
if (response.metadata) {
|
|
1118
|
+
metadata = response.metadata;
|
|
1119
|
+
}
|
|
1120
|
+
})
|
|
1121
|
+
.on('data', row => rows.push(row))
|
|
1122
|
+
.on('stats', _stats => (stats = _stats))
|
|
1123
|
+
.on('error', err => complete(err, rows, stats, metadata))
|
|
1124
|
+
.on('end', () => complete(null, rows, stats, metadata));
|
|
1125
|
+
};
|
|
1126
|
+
requestStream.once('error', onError);
|
|
1127
|
+
requestStream.once('data', onData);
|
|
1128
|
+
requestStream.once('end', onEnd);
|
|
1129
|
+
};
|
|
1130
|
+
executeRequest();
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
830
1133
|
/**
|
|
831
1134
|
* ExecuteSql request options. This includes all standard ExecuteSqlRequest
|
|
832
1135
|
* options as well as several convenience properties.
|
|
@@ -1231,10 +1534,17 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1231
1534
|
}
|
|
1232
1535
|
// Queue subsequent requests.
|
|
1233
1536
|
return (resumeToken) => {
|
|
1537
|
+
if (this.id) {
|
|
1538
|
+
return makeRequest(resumeToken);
|
|
1539
|
+
}
|
|
1234
1540
|
const streamProxy = new stream_1.Readable({
|
|
1235
1541
|
read() { },
|
|
1236
1542
|
});
|
|
1237
|
-
this._waitingRequests.push(() => {
|
|
1543
|
+
this._waitingRequests.push((err) => {
|
|
1544
|
+
if (err) {
|
|
1545
|
+
streamProxy.destroy(err);
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1238
1548
|
makeRequest(resumeToken)
|
|
1239
1549
|
.on('data', chunk => streamProxy.emit('data', chunk))
|
|
1240
1550
|
.on('error', err => streamProxy.emit('error', err))
|
|
@@ -1243,10 +1553,10 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1243
1553
|
return streamProxy;
|
|
1244
1554
|
};
|
|
1245
1555
|
}
|
|
1246
|
-
_releaseWaitingRequests() {
|
|
1556
|
+
_releaseWaitingRequests(err) {
|
|
1247
1557
|
while (this._waitingRequests.length > 0) {
|
|
1248
1558
|
const request = this._waitingRequests.shift();
|
|
1249
|
-
request?.();
|
|
1559
|
+
request?.(err);
|
|
1250
1560
|
}
|
|
1251
1561
|
}
|
|
1252
1562
|
/**
|
|
@@ -1553,7 +1863,8 @@ class Transaction extends Dml {
|
|
|
1553
1863
|
if (this.session.parent.isMuxEnabledForRW_) {
|
|
1554
1864
|
this._setMutationKey(mutations);
|
|
1555
1865
|
}
|
|
1556
|
-
this.begin()
|
|
1866
|
+
this.begin()
|
|
1867
|
+
.then(() => {
|
|
1557
1868
|
this.commit(options, (err, resp) => {
|
|
1558
1869
|
if (err) {
|
|
1559
1870
|
(0, instrument_1.setSpanError)(span, err);
|
|
@@ -1561,7 +1872,9 @@ class Transaction extends Dml {
|
|
|
1561
1872
|
span.end();
|
|
1562
1873
|
callback(err, resp);
|
|
1563
1874
|
});
|
|
1564
|
-
|
|
1875
|
+
return null;
|
|
1876
|
+
})
|
|
1877
|
+
.catch(err => {
|
|
1565
1878
|
(0, instrument_1.setSpanError)(span, err);
|
|
1566
1879
|
span.end();
|
|
1567
1880
|
callback(err, null);
|
|
@@ -1807,6 +2120,26 @@ class Transaction extends Dml {
|
|
|
1807
2120
|
insert(table, rows) {
|
|
1808
2121
|
this._mutate('insert', table, rows);
|
|
1809
2122
|
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Queue a send mutation.
|
|
2125
|
+
*
|
|
2126
|
+
* @param {string} queue The name of the queue.
|
|
2127
|
+
* @param {Key} key The key of the message to send.
|
|
2128
|
+
* @param {QueueSendOptions} [options] Options for the send mutation.
|
|
2129
|
+
*/
|
|
2130
|
+
queueSend(queue, key, options) {
|
|
2131
|
+
this._queuedMutations.push(buildSendMutation(queue, key, options));
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Queue an ack mutation.
|
|
2135
|
+
*
|
|
2136
|
+
* @param {string} queue The name of the queue.
|
|
2137
|
+
* @param {Key} key The key of the message to ack.
|
|
2138
|
+
* @param {QueueAckOptions} [options] Options for the ack mutation.
|
|
2139
|
+
*/
|
|
2140
|
+
queueAck(queue, key, options) {
|
|
2141
|
+
this._queuedMutations.push(buildAckMutation(queue, key, options));
|
|
2142
|
+
}
|
|
1810
2143
|
/**
|
|
1811
2144
|
* Replace rows of data within a table.
|
|
1812
2145
|
*
|
|
@@ -2098,6 +2431,58 @@ function buildDeleteMutation(table, keys) {
|
|
|
2098
2431
|
};
|
|
2099
2432
|
return mutation;
|
|
2100
2433
|
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Builds a send mutation.
|
|
2436
|
+
*
|
|
2437
|
+
* @param {string} queue - The name of the queue.
|
|
2438
|
+
* @param {Key} key - The key for the message.
|
|
2439
|
+
* @param {QueueSendOptions} [options] - Options for sending the message.
|
|
2440
|
+
* @returns {spannerClient.spanner.v1.Mutation} - The formatted send mutation.
|
|
2441
|
+
*/
|
|
2442
|
+
function buildSendMutation(queue, key, options) {
|
|
2443
|
+
const send = {
|
|
2444
|
+
queue,
|
|
2445
|
+
key: codec_1.codec.convertToListValue((0, helper_1.toArray)(key)),
|
|
2446
|
+
};
|
|
2447
|
+
if (options) {
|
|
2448
|
+
if (options.payload !== undefined) {
|
|
2449
|
+
send.payload = codec_1.codec.encode(options.payload);
|
|
2450
|
+
}
|
|
2451
|
+
if (options.deliverTime) {
|
|
2452
|
+
if (options.deliverTime instanceof Date) {
|
|
2453
|
+
send.deliverTime = codec_1.codec.convertMsToProtoTimestamp(options.deliverTime.getTime());
|
|
2454
|
+
}
|
|
2455
|
+
else {
|
|
2456
|
+
send.deliverTime = options.deliverTime;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
const mutation = {
|
|
2461
|
+
send,
|
|
2462
|
+
};
|
|
2463
|
+
return mutation;
|
|
2464
|
+
}
|
|
2465
|
+
/**
|
|
2466
|
+
* Builds an ack mutation.
|
|
2467
|
+
*
|
|
2468
|
+
* @param {string} queue - The name of the queue.
|
|
2469
|
+
* @param {Key} key - The key for the message.
|
|
2470
|
+
* @param {QueueAckOptions} [options] - Options for acking the message.
|
|
2471
|
+
* @returns {spannerClient.spanner.v1.Mutation} - The formatted ack mutation.
|
|
2472
|
+
*/
|
|
2473
|
+
function buildAckMutation(queue, key, options) {
|
|
2474
|
+
const ack = {
|
|
2475
|
+
queue,
|
|
2476
|
+
key: codec_1.codec.convertToListValue((0, helper_1.toArray)(key)),
|
|
2477
|
+
};
|
|
2478
|
+
if (options && options.ignoreNotFound !== undefined) {
|
|
2479
|
+
ack.ignoreNotFound = options.ignoreNotFound;
|
|
2480
|
+
}
|
|
2481
|
+
const mutation = {
|
|
2482
|
+
ack,
|
|
2483
|
+
};
|
|
2484
|
+
return mutation;
|
|
2485
|
+
}
|
|
2101
2486
|
/**
|
|
2102
2487
|
* MutationSet represent a set of changes to be applied atomically to a Cloud Spanner
|
|
2103
2488
|
* database with a {@link Transaction}.
|
|
@@ -2150,6 +2535,26 @@ class MutationSet {
|
|
|
2150
2535
|
insert(table, rows) {
|
|
2151
2536
|
this._queuedMutations.push(buildMutation('insert', table, rows));
|
|
2152
2537
|
}
|
|
2538
|
+
/**
|
|
2539
|
+
* Queue a send mutation.
|
|
2540
|
+
*
|
|
2541
|
+
* @param {string} queue The name of the queue.
|
|
2542
|
+
* @param {Key} key The key of the message to send.
|
|
2543
|
+
* @param {QueueSendOptions} [options] Options for the send mutation.
|
|
2544
|
+
*/
|
|
2545
|
+
queueSend(queue, key, options) {
|
|
2546
|
+
this._queuedMutations.push(buildSendMutation(queue, key, options));
|
|
2547
|
+
}
|
|
2548
|
+
/**
|
|
2549
|
+
* Queue an ack mutation.
|
|
2550
|
+
*
|
|
2551
|
+
* @param {string} queue The name of the queue.
|
|
2552
|
+
* @param {Key} key The key of the message to ack.
|
|
2553
|
+
* @param {QueueAckOptions} [options] Options for the ack mutation.
|
|
2554
|
+
*/
|
|
2555
|
+
queueAck(queue, key, options) {
|
|
2556
|
+
this._queuedMutations.push(buildAckMutation(queue, key, options));
|
|
2557
|
+
}
|
|
2153
2558
|
/**
|
|
2154
2559
|
* Adds an update operation to the mutation set.
|
|
2155
2560
|
* @param {string} table. The name of the table to update.
|
|
@@ -2235,6 +2640,12 @@ class MutationGroup {
|
|
|
2235
2640
|
insert(table, rows) {
|
|
2236
2641
|
this._proto.mutations.push(buildMutation('insert', table, rows));
|
|
2237
2642
|
}
|
|
2643
|
+
queueSend(queue, key, options) {
|
|
2644
|
+
this._proto.mutations.push(buildSendMutation(queue, key, options));
|
|
2645
|
+
}
|
|
2646
|
+
queueAck(queue, key, options) {
|
|
2647
|
+
this._proto.mutations.push(buildAckMutation(queue, key, options));
|
|
2648
|
+
}
|
|
2238
2649
|
update(table, rows) {
|
|
2239
2650
|
this._proto.mutations.push(buildMutation('update', table, rows));
|
|
2240
2651
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/spanner",
|
|
3
3
|
"description": "Cloud Spanner Client Library for Node.js",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.13.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Google Inc.",
|
|
7
7
|
"engines": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"docs": "jsdoc -c .jsdoc.js",
|
|
35
|
-
"predocs": "
|
|
35
|
+
"predocs": "pnpm run compile",
|
|
36
36
|
"lint": "gts check",
|
|
37
37
|
"system-test": "mocha build/system-test --timeout 1600000",
|
|
38
38
|
"observability-test": "mocha build/observability-test --timeout 1600000",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"clean": "gts clean",
|
|
44
44
|
"compile": "tsc -p . && cp -r protos build && cp -r test/data build/test",
|
|
45
45
|
"prepare": "cp -r protos build && npm run compile",
|
|
46
|
-
"pretest": "
|
|
47
|
-
"presystem-test": "
|
|
48
|
-
"preobservability-test": "
|
|
46
|
+
"pretest": "pnpm run compile",
|
|
47
|
+
"presystem-test": "pnpm run compile",
|
|
48
|
+
"preobservability-test": "pnpm run compile",
|
|
49
49
|
"benchwrapper": "node bin/benchwrapper.js",
|
|
50
50
|
"precompile": "gts clean",
|
|
51
51
|
"coverage": "c8 mocha build/test build/test/common && c8 report --check-coverage"
|
|
@@ -71,19 +71,15 @@
|
|
|
71
71
|
"@types/big.js": "^6.2.2",
|
|
72
72
|
"@types/stack-trace": "^0.0.33",
|
|
73
73
|
"big.js": "^7.0.0",
|
|
74
|
-
"checkpoint-stream": "^0.1.2",
|
|
75
74
|
"duplexify": "^4.1.3",
|
|
76
|
-
"events-intercept": "^2.0.0",
|
|
77
75
|
"extend": "^3.0.2",
|
|
78
76
|
"google-auth-library": "^10.0.0-rc.1",
|
|
79
77
|
"google-gax": "5.0.6",
|
|
80
78
|
"grpc-gcp": "^1.0.1",
|
|
81
79
|
"lodash.snakecase": "^4.1.1",
|
|
82
|
-
"merge-stream": "^2.0.0",
|
|
83
80
|
"p-queue": "^6.0.2",
|
|
84
81
|
"protobufjs": "^7.4.0",
|
|
85
82
|
"retry-request": "^8.0.0",
|
|
86
|
-
"split-array-stream": "^2.0.0",
|
|
87
83
|
"stack-trace": "0.0.10",
|
|
88
84
|
"stream-events": "^1.0.5",
|
|
89
85
|
"teeny-request": "^10.0.0",
|
|
@@ -98,7 +94,6 @@
|
|
|
98
94
|
"@types/extend": "^3.0.4",
|
|
99
95
|
"@types/is": "^0.0.25",
|
|
100
96
|
"@types/lodash.snakecase": "^4.1.9",
|
|
101
|
-
"@types/merge-stream": "^2.0.0",
|
|
102
97
|
"@types/mocha": "^10.0.10",
|
|
103
98
|
"@types/mv": "^2.1.4",
|
|
104
99
|
"@types/ncp": "^2.0.8",
|