@delali/narsil 0.3.0 → 0.3.1-next.102
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/README.md +9 -8
- package/dist/adapters/filesystem.d.ts +1 -1
- package/dist/adapters/filesystem.mjs +1 -1
- package/dist/adapters/indexeddb.d.ts +1 -1
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/{adapters-79OIa4xm.d.ts → adapters-BQFQ4PRz.d.ts} +27 -1
- package/dist/browser/chunk-BDOSMEEP.mjs +493 -0
- package/dist/browser/chunk-EJDUFWSO.mjs +602 -0
- package/dist/browser/chunk-HOZW3PKP.mjs +9 -0
- package/dist/browser/chunk-JOVZ6HMT.mjs +4358 -0
- package/dist/browser/chunk-JPTQZWJQ.mjs +10 -0
- package/dist/browser/chunk-KPJMDPHG.mjs +24558 -0
- package/dist/browser/chunk-PGIM3HIM.mjs +2743 -0
- package/dist/browser/chunk-RHG4O77A.mjs +206 -0
- package/dist/browser/chunk-RIJSLY2I.mjs +360 -0
- package/dist/browser/durability-wiring-SRUYT3VV.mjs +3875 -0
- package/dist/browser/module-CBB2ETYP.mjs +3111 -0
- package/dist/browser/release-76MXRPGV.mjs +33 -0
- package/dist/browser/replace-RURXTGVG.mjs +57 -0
- package/dist/browser/restore-queue-EEZQO6RF.mjs +35 -0
- package/dist/browser/runtime-7ZAHCHWR.mjs +557 -0
- package/dist/browser/snapshot-OAAA5UJ7.mjs +1210 -0
- package/dist/browser/write-7D6VIK6O.mjs +208 -0
- package/dist/{capabilities-DSsOGz6F.d.ts → capabilities-ByQRMOx-.d.ts} +68 -7
- package/dist/chunk-2RIRGOUL.mjs +113 -0
- package/dist/chunk-37CD3OKS.mjs +87 -0
- package/dist/chunk-44W3CBNG.mjs +7 -0
- package/dist/chunk-46D6JQIG.mjs +426 -0
- package/dist/{chunk-VMRR3DQU.mjs → chunk-5JNA5SKS.mjs} +546 -35
- package/dist/chunk-747OHOUA.mjs +11 -0
- package/dist/chunk-75XIEF6H.mjs +126 -0
- package/dist/chunk-7X5JST5L.mjs +114 -0
- package/dist/chunk-BOFBLJFZ.mjs +209 -0
- package/dist/{chunk-USKFU7J5.mjs → chunk-BWJVNZPR.mjs} +8 -1
- package/dist/chunk-C7SLA6CM.mjs +19 -0
- package/dist/{chunk-POWOTUKJ.mjs → chunk-CQUMNIIG.mjs} +3 -6
- package/dist/chunk-CVXLLEQ3.mjs +1011 -0
- package/dist/chunk-DJHHF2L5.mjs +17 -0
- package/dist/chunk-E74YLAIG.mjs +24 -0
- package/dist/{chunk-UXNWQZST.mjs → chunk-EMRMGYRE.mjs} +236 -18
- package/dist/chunk-EWZLIYHV.mjs +57 -0
- package/dist/chunk-GBEEG5AN.mjs +35 -0
- package/dist/chunk-GES7U2PM.mjs +68 -0
- package/dist/chunk-HJSN7UYG.mjs +10 -0
- package/dist/chunk-HLPRHOSO.mjs +17 -0
- package/dist/chunk-HMFNFVP7.mjs +14 -0
- package/dist/chunk-J5QP52HA.mjs +1751 -0
- package/dist/{chunk-YNVIUGF5.mjs → chunk-JZVARCRZ.mjs} +3 -28
- package/dist/chunk-KOKM4PQN.mjs +52 -0
- package/dist/{chunk-B2TFROFX.mjs → chunk-KWTW6VTG.mjs} +465 -250
- package/dist/chunk-KZ3NX2P7.mjs +21 -0
- package/dist/chunk-L5ORED7V.mjs +25 -0
- package/dist/{chunk-THYRHHO2.mjs → chunk-LGAMKHA2.mjs} +2009 -2351
- package/dist/chunk-LKOB5COA.mjs +117 -0
- package/dist/chunk-LPQOEU5M.mjs +96 -0
- package/dist/{chunk-3LHGNRYE.mjs → chunk-LXWDQLTW.mjs} +7 -2
- package/dist/{chunk-L6TNPLAR.mjs → chunk-OEYI3KRB.mjs} +270 -108
- package/dist/chunk-OM362BRO.mjs +948 -0
- package/dist/chunk-OZDFA4WC.mjs +67 -0
- package/dist/chunk-P36MUFEJ.mjs +10 -0
- package/dist/chunk-PC2G76VW.mjs +2540 -0
- package/dist/{chunk-GCM3JFVA.mjs → chunk-PNEYIHA4.mjs} +11 -2
- package/dist/chunk-PNFKUCG3.mjs +1130 -0
- package/dist/chunk-Q6XWVUZX.mjs +44 -0
- package/dist/chunk-R27EMH5M.mjs +617 -0
- package/dist/{chunk-YMZCMH5M.mjs → chunk-R6A773WK.mjs} +19 -24
- package/dist/chunk-RF7PLG43.mjs +106 -0
- package/dist/chunk-RFBLQLLZ.mjs +16 -0
- package/dist/{chunk-Y3L5MDRV.mjs → chunk-RFVUDM5E.mjs} +17 -2
- package/dist/chunk-S7FL6UAH.mjs +521 -0
- package/dist/chunk-S7GNDRPS.mjs +651 -0
- package/dist/chunk-SP3NM3ZG.mjs +3537 -0
- package/dist/chunk-U476IXKQ.mjs +10 -0
- package/dist/chunk-UA3AUGNV.mjs +462 -0
- package/dist/chunk-UTG5YNXV.mjs +507 -0
- package/dist/chunk-VI4R6W25.mjs +8484 -0
- package/dist/chunk-WQBCBKY3.mjs +8 -0
- package/dist/{chunk-24RXHMEL.mjs → chunk-WVCOCKBU.mjs} +3794 -7570
- package/dist/chunk-X5CV2E2B.mjs +1 -0
- package/dist/chunk-XADZPPZI.mjs +614 -0
- package/dist/chunk-YEEQHT4V.mjs +212 -0
- package/dist/chunk-YTJCGKM4.mjs +56 -0
- package/dist/chunk-YYQIODMF.mjs +275 -0
- package/dist/chunk-ZI34TVOA.mjs +144 -0
- package/dist/{chunk-OOSIDHA3.mjs → chunk-ZKWYWW4Y.mjs} +1 -1
- package/dist/chunk-ZM7KU4YW.mjs +35 -0
- package/dist/{client-BQK6Tf6A.d.ts → client-BOStAkc5.d.ts} +160 -37
- package/dist/client.d.ts +11 -10
- package/dist/client.mjs +209 -45
- package/dist/{config-DmXULPa-.d.ts → config-Cjvzbs_j.d.ts} +51 -3
- package/dist/config-H6SGzbPH.d.ts +421 -0
- package/dist/direct-executor-ZD64PPEZ.mjs +24 -0
- package/dist/distribution/coordinator/etcd.d.ts +79 -18
- package/dist/distribution/coordinator/etcd.mjs +553 -109
- package/dist/distribution/coordinator/in-memory.d.ts +4 -3
- package/dist/distribution/coordinator/in-memory.mjs +22 -3
- package/dist/distribution/transport/grpc.d.ts +2 -2
- package/dist/distribution/transport/grpc.mjs +79 -14
- package/dist/distribution/transport/in-memory.d.ts +2 -2
- package/dist/distribution/transport/in-memory.mjs +12 -7
- package/dist/distribution/transport/tcp.d.ts +2 -2
- package/dist/distribution/transport/tcp.mjs +50 -28
- package/dist/distribution.d.ts +144 -23
- package/dist/distribution.mjs +14479 -8173
- package/dist/durability-wiring-FEUBR5BT.mjs +3330 -0
- package/dist/embeddings/openai.d.ts +2 -2
- package/dist/embeddings/openai.mjs +22 -133
- package/dist/{engine-CIOyFozK.d.ts → engine-rC0vjjY-.d.ts} +165 -141
- package/dist/{memory-yFaVn2xZ.d.ts → events-DqOIg5xa.d.ts} +645 -136
- package/dist/{types-DAK7mnUZ.d.ts → index-Bkdt8nDw.d.ts} +182 -45
- package/dist/index.browser.mjs +4 -32180
- package/dist/index.d.ts +91 -20
- package/dist/index.mjs +33 -16
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/filesystem.mjs +2 -1
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/module-3S65MVCM.mjs +2151 -0
- package/dist/partial-words-DTIHO8G4.d.ts +19 -0
- package/dist/partial-words.d.ts +22 -0
- package/dist/partial-words.mjs +17 -0
- package/dist/pattern-Cledccbl.d.ts +18 -0
- package/dist/pattern.d.ts +22 -0
- package/dist/pattern.mjs +12 -0
- package/dist/persistence/durability/checkpoint-worker.d.ts +119 -72
- package/dist/persistence/durability/checkpoint-worker.mjs +51 -18
- package/dist/react.d.ts +279 -183
- package/dist/react.mjs +201 -48
- package/dist/release-BH3DKW3T.mjs +33 -0
- package/dist/replace-CEO5KJJ3.mjs +57 -0
- package/dist/rerank-K7C4WZFG.mjs +60 -0
- package/dist/rerankers/http.d.ts +50 -0
- package/dist/rerankers/http.mjs +104 -0
- package/dist/restore-queue-KQHA7ZV2.mjs +35 -0
- package/dist/runtime-6Y4ZYXOG.mjs +177 -0
- package/dist/{schema-d5Afu03A.d.ts → schema-4W_7tk1f.d.ts} +81 -11
- package/dist/server.d.ts +13 -12
- package/dist/server.mjs +611 -80
- package/dist/snapshot-QGZPODM5.mjs +799 -0
- package/dist/synonyms-CpOAHPa-.d.ts +52 -0
- package/dist/synonyms.d.ts +22 -0
- package/dist/synonyms.mjs +12 -0
- package/dist/{tasks-CH2Dod8w.d.ts → tasks-CwPTz-tP.d.ts} +10 -3
- package/dist/thread-N3IUGUS3.mjs +697 -0
- package/dist/{types-BQDlIvfS.d.ts → types-2qoitTXg.d.ts} +1 -1
- package/dist/{types-D5OwhtsQ.d.ts → types-Cz5okLml.d.ts} +2 -2
- package/dist/vector/search-worker.d.ts +46 -4
- package/dist/vector/search-worker.mjs +21 -11
- package/dist/workers/entry.mjs +9 -6
- package/dist/write-U5RI7MAX.mjs +241 -0
- package/package.json +55 -9
- package/dist/chunk-3L4U6EJQ.mjs +0 -49
- package/dist/chunk-IFBKLBGB.mjs +0 -7
- package/dist/chunk-ORBLD3EL.mjs +0 -6
- package/dist/chunk-U7KYW4BA.mjs +0 -135
- package/dist/chunk-ZJ4CSAB2.mjs +0 -13
- package/dist/chunk-ZNZBXMP5.mjs +0 -2117
- package/dist/chunk-ZZT3EAUC.mjs +0 -11168
- package/dist/config-BhldZgaK.d.ts +0 -194
- package/dist/direct-executor-ALAVE7FC.mjs +0 -12
- package/dist/serialization/crc32-worker.d.ts +0 -20
- package/dist/serialization/crc32-worker.mjs +0 -62
- package/dist/simd-DW5AtJ6B.d.ts +0 -41
- package/dist/thread-DYHEQRVY.mjs +0 -402
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { C as ClusterCoordinator } from '../../
|
|
2
|
-
import '../../schema-
|
|
3
|
-
import '../../adapters-
|
|
1
|
+
import { C as ClusterCoordinator } from '../../index-Bkdt8nDw.js';
|
|
2
|
+
import '../../schema-4W_7tk1f.js';
|
|
3
|
+
import '../../adapters-BQFQ4PRz.js';
|
|
4
|
+
import '../../synonyms-CpOAHPa-.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Builds a coordinator that holds the cluster's shared state in one process's
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { NODE_HEARTBEAT_TTL_MS } from '../../chunk-
|
|
2
|
-
import
|
|
1
|
+
import { CONTROLLER_LEASE_KEY, NODE_HEARTBEAT_TTL_MS } from '../../chunk-44W3CBNG.mjs';
|
|
2
|
+
import '../../chunk-R6A773WK.mjs';
|
|
3
|
+
import { compareCodePoints } from '../../chunk-YTJCGKM4.mjs';
|
|
3
4
|
|
|
4
5
|
// src/distribution/coordinator/in-memory.ts
|
|
5
6
|
var NODE_HEARTBEAT_PREFIX = "_narsil/node/";
|
|
@@ -19,6 +20,7 @@ function createInMemoryCoordinator() {
|
|
|
19
20
|
const allocations = /* @__PURE__ */ new Map();
|
|
20
21
|
const partitionStates = /* @__PURE__ */ new Map();
|
|
21
22
|
const leases = /* @__PURE__ */ new Map();
|
|
23
|
+
const registrationsHeldUntil = /* @__PURE__ */ new Map();
|
|
22
24
|
const schemas = /* @__PURE__ */ new Map();
|
|
23
25
|
const kvStore = /* @__PURE__ */ new Map();
|
|
24
26
|
const nodeWatchers = /* @__PURE__ */ new Set();
|
|
@@ -67,6 +69,7 @@ function createInMemoryCoordinator() {
|
|
|
67
69
|
if (key.startsWith(NODE_HEARTBEAT_PREFIX)) {
|
|
68
70
|
const expiredNodeId = key.slice(NODE_HEARTBEAT_PREFIX.length);
|
|
69
71
|
nodes.delete(expiredNodeId);
|
|
72
|
+
registrationsHeldUntil.delete(expiredNodeId);
|
|
70
73
|
emitNodeEvent({ type: "node_left", nodeId: expiredNodeId, registration: null });
|
|
71
74
|
}
|
|
72
75
|
}, ttlMs);
|
|
@@ -81,8 +84,10 @@ function createInMemoryCoordinator() {
|
|
|
81
84
|
const coordinator = {
|
|
82
85
|
async registerNode(registration) {
|
|
83
86
|
assertNotShutdown();
|
|
87
|
+
const renewedAt = performance.now();
|
|
84
88
|
const previous = nodes.get(registration.nodeId);
|
|
85
89
|
nodes.set(registration.nodeId, registration);
|
|
90
|
+
registrationsHeldUntil.set(registration.nodeId, renewedAt + NODE_HEARTBEAT_TTL_MS);
|
|
86
91
|
const heartbeatKey = `${NODE_HEARTBEAT_PREFIX}${registration.nodeId}`;
|
|
87
92
|
clearLeaseEntry(heartbeatKey);
|
|
88
93
|
const timer = createLeaseTimer(heartbeatKey, NODE_HEARTBEAT_TTL_MS);
|
|
@@ -99,12 +104,18 @@ function createInMemoryCoordinator() {
|
|
|
99
104
|
async deregisterNode(nodeId) {
|
|
100
105
|
assertNotShutdown();
|
|
101
106
|
const existed = nodes.delete(nodeId);
|
|
107
|
+
registrationsHeldUntil.delete(nodeId);
|
|
102
108
|
const heartbeatKey = `${NODE_HEARTBEAT_PREFIX}${nodeId}`;
|
|
103
109
|
clearLeaseEntry(heartbeatKey);
|
|
104
110
|
if (existed) {
|
|
105
111
|
emitNodeEvent({ type: "node_left", nodeId, registration: null });
|
|
106
112
|
}
|
|
107
113
|
},
|
|
114
|
+
registrationLease(nodeId) {
|
|
115
|
+
const heldUntil = registrationsHeldUntil.get(nodeId);
|
|
116
|
+
if (isShutdown || heldUntil === void 0) return null;
|
|
117
|
+
return { remainingMs: heldUntil - performance.now(), ttlMs: NODE_HEARTBEAT_TTL_MS };
|
|
118
|
+
},
|
|
108
119
|
async listNodes() {
|
|
109
120
|
assertNotShutdown();
|
|
110
121
|
return Array.from(nodes.values());
|
|
@@ -120,9 +131,12 @@ function createInMemoryCoordinator() {
|
|
|
120
131
|
assertNotShutdown();
|
|
121
132
|
return allocations.get(indexName) ?? null;
|
|
122
133
|
},
|
|
123
|
-
async putAllocation(indexName, table, expectedVersion) {
|
|
134
|
+
async putAllocation(indexName, table, expectedVersion, writerNodeId) {
|
|
124
135
|
assertNotShutdown();
|
|
125
136
|
if (expectedVersion !== void 0) {
|
|
137
|
+
if (!isLeaseValid(CONTROLLER_LEASE_KEY) || leases.get(CONTROLLER_LEASE_KEY)?.nodeId !== writerNodeId) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
126
140
|
const current = allocations.get(indexName);
|
|
127
141
|
if (expectedVersion === null) {
|
|
128
142
|
if (current !== void 0) {
|
|
@@ -229,6 +243,10 @@ function createInMemoryCoordinator() {
|
|
|
229
243
|
kvStore.set(key, new Uint8Array(value));
|
|
230
244
|
return true;
|
|
231
245
|
},
|
|
246
|
+
async delete(key) {
|
|
247
|
+
assertNotShutdown();
|
|
248
|
+
kvStore.delete(key);
|
|
249
|
+
},
|
|
232
250
|
async getSchema(indexName) {
|
|
233
251
|
assertNotShutdown();
|
|
234
252
|
return schemas.get(indexName) ?? null;
|
|
@@ -274,6 +292,7 @@ function createInMemoryCoordinator() {
|
|
|
274
292
|
clearTimeout(entry.timer);
|
|
275
293
|
}
|
|
276
294
|
leases.clear();
|
|
295
|
+
registrationsHeldUntil.clear();
|
|
277
296
|
nodes.clear();
|
|
278
297
|
allocations.clear();
|
|
279
298
|
partitionStates.clear();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TransportConfig, N as NodeTransport } from '../../types-
|
|
2
|
-
import { a as TlsConfig } from '../../types-
|
|
1
|
+
import { T as TransportConfig, N as NodeTransport } from '../../types-Cz5okLml.js';
|
|
2
|
+
import { a as TlsConfig } from '../../types-2qoitTXg.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* How the gRPC transport listens and dials.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { decodeTransportMessage, encodeTransportMessage } from '../../chunk-
|
|
1
|
+
import { decodeTransportMessage, encodeTransportMessage } from '../../chunk-ZKWYWW4Y.mjs';
|
|
2
|
+
import { replyDeadlineMs } from '../../chunk-747OHOUA.mjs';
|
|
2
3
|
import { MAX_MESSAGE_SIZE_BYTES, GRPC_KEEPALIVE_TIMEOUT_MS, GRPC_KEEPALIVE_TIME_MS, GRPC_ENVELOPE_OVERHEAD_BYTES } from '../../chunk-UNEEFTEU.mjs';
|
|
3
|
-
import { TransportError, TransportErrorCodes } from '../../chunk-
|
|
4
|
-
import { NarsilError, ErrorCodes } from '../../chunk-
|
|
4
|
+
import { TransportError, TransportErrorCodes } from '../../chunk-PNEYIHA4.mjs';
|
|
5
|
+
import { NarsilError, ErrorCodes } from '../../chunk-BWJVNZPR.mjs';
|
|
5
6
|
|
|
6
7
|
// src/distribution/transport/grpc/codec.ts
|
|
7
8
|
var FIELD_ONE_LENGTH_DELIMITED_KEY = 10;
|
|
@@ -138,6 +139,8 @@ function toCredentialBuffer(material) {
|
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
// src/distribution/transport/grpc/client.ts
|
|
142
|
+
var CONNECT_PROBE_PATH = "/narsil.transport.v1.ConnectProbe/LastError";
|
|
143
|
+
var LAST_ERROR_PATTERN = /Last error: (?:Error: )?(.*?)\. Resolution note:/s;
|
|
141
144
|
var GrpcClientPool = class {
|
|
142
145
|
grpc;
|
|
143
146
|
config;
|
|
@@ -150,7 +153,13 @@ var GrpcClientPool = class {
|
|
|
150
153
|
async send(target, message) {
|
|
151
154
|
const messageBytes = this.encodeChecked(target, message);
|
|
152
155
|
const client = await this.getClient(target);
|
|
153
|
-
const responseBytes = await this.unaryCall(
|
|
156
|
+
const responseBytes = await this.unaryCall(
|
|
157
|
+
client,
|
|
158
|
+
target,
|
|
159
|
+
message.requestId,
|
|
160
|
+
messageBytes,
|
|
161
|
+
replyDeadlineMs(message.type, this.config)
|
|
162
|
+
);
|
|
154
163
|
try {
|
|
155
164
|
return decodeTransportMessage(responseBytes);
|
|
156
165
|
} catch (err) {
|
|
@@ -170,17 +179,37 @@ var GrpcClientPool = class {
|
|
|
170
179
|
openStreamMethod.responseDeserialize,
|
|
171
180
|
messageBytes,
|
|
172
181
|
this.metadata(),
|
|
173
|
-
|
|
182
|
+
{}
|
|
174
183
|
);
|
|
175
184
|
return new Promise((resolve, reject) => {
|
|
176
185
|
let settled = false;
|
|
186
|
+
const timeoutMs = this.config.snapshotTimeout;
|
|
187
|
+
let idleTimer = null;
|
|
177
188
|
const settle = (fn) => {
|
|
189
|
+
if (idleTimer !== null) clearTimeout(idleTimer);
|
|
178
190
|
if (!settled) {
|
|
179
191
|
settled = true;
|
|
180
192
|
fn();
|
|
181
193
|
}
|
|
182
194
|
};
|
|
195
|
+
const rearm = () => {
|
|
196
|
+
if (idleTimer !== null) clearTimeout(idleTimer);
|
|
197
|
+
idleTimer = setTimeout(() => {
|
|
198
|
+
call.cancel();
|
|
199
|
+
settle(
|
|
200
|
+
() => reject(
|
|
201
|
+
new TransportError(
|
|
202
|
+
TransportErrorCodes.TIMEOUT,
|
|
203
|
+
`No chunk of the stream from '${target}' arrived within ${timeoutMs}ms`,
|
|
204
|
+
{ target, requestId: message.requestId, timeoutMs }
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
}, timeoutMs);
|
|
209
|
+
};
|
|
210
|
+
rearm();
|
|
183
211
|
call.on("data", (chunk) => {
|
|
212
|
+
rearm();
|
|
184
213
|
try {
|
|
185
214
|
handler(chunk);
|
|
186
215
|
} catch (err) {
|
|
@@ -256,19 +285,55 @@ var GrpcClientPool = class {
|
|
|
256
285
|
}
|
|
257
286
|
connect(target) {
|
|
258
287
|
const client = new this.grpc.Client(target, this.credentials(), channelOptions());
|
|
288
|
+
const channel = client.getChannel();
|
|
289
|
+
const { READY, SHUTDOWN, TRANSIENT_FAILURE } = this.grpc.connectivityState;
|
|
290
|
+
const deadline = Date.now() + this.config.connectTimeout;
|
|
259
291
|
return new Promise((resolve, reject) => {
|
|
260
|
-
|
|
261
|
-
if (err === void 0) {
|
|
262
|
-
resolve(client);
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
292
|
+
const fail = (reason) => {
|
|
265
293
|
client.close();
|
|
266
294
|
reject(
|
|
267
|
-
new TransportError(TransportErrorCodes.CONNECT_FAILED, `Failed to connect to '${target}': ${
|
|
295
|
+
new TransportError(TransportErrorCodes.CONNECT_FAILED, `Failed to connect to '${target}': ${reason}`, {
|
|
268
296
|
target
|
|
269
297
|
})
|
|
270
298
|
);
|
|
271
|
-
}
|
|
299
|
+
};
|
|
300
|
+
const check = (deadlinePassed) => {
|
|
301
|
+
if (deadlinePassed !== void 0) {
|
|
302
|
+
fail(`no connection was ready within ${this.config.connectTimeout}ms`);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const state = channel.getConnectivityState(true);
|
|
307
|
+
if (state === READY) {
|
|
308
|
+
resolve(client);
|
|
309
|
+
} else if (state === TRANSIENT_FAILURE) {
|
|
310
|
+
void this.lastConnectError(client, deadline).then(fail);
|
|
311
|
+
} else if (state === SHUTDOWN) {
|
|
312
|
+
fail("the channel shut down");
|
|
313
|
+
} else {
|
|
314
|
+
channel.watchConnectivityState(state, deadline, check);
|
|
315
|
+
}
|
|
316
|
+
} catch {
|
|
317
|
+
fail("the channel closed");
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
check();
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
lastConnectError(client, deadline) {
|
|
324
|
+
return new Promise((resolve) => {
|
|
325
|
+
client.makeUnaryRequest(
|
|
326
|
+
CONNECT_PROBE_PATH,
|
|
327
|
+
sendMethod.requestSerialize,
|
|
328
|
+
sendMethod.responseDeserialize,
|
|
329
|
+
new Uint8Array(0),
|
|
330
|
+
this.metadata(),
|
|
331
|
+
{ deadline },
|
|
332
|
+
(err) => {
|
|
333
|
+
const details = err?.details ?? "";
|
|
334
|
+
resolve(LAST_ERROR_PATTERN.exec(details)?.[1] ?? (details === "" ? "the channel failed to connect" : details));
|
|
335
|
+
}
|
|
336
|
+
);
|
|
272
337
|
});
|
|
273
338
|
}
|
|
274
339
|
credentials() {
|
|
@@ -291,7 +356,7 @@ var GrpcClientPool = class {
|
|
|
291
356
|
callOptions(timeoutMs) {
|
|
292
357
|
return { deadline: Date.now() + timeoutMs };
|
|
293
358
|
}
|
|
294
|
-
unaryCall(client, target, requestId, messageBytes) {
|
|
359
|
+
unaryCall(client, target, requestId, messageBytes, timeoutMs) {
|
|
295
360
|
return new Promise((resolve, reject) => {
|
|
296
361
|
client.makeUnaryRequest(
|
|
297
362
|
sendMethod.path,
|
|
@@ -299,7 +364,7 @@ var GrpcClientPool = class {
|
|
|
299
364
|
sendMethod.responseDeserialize,
|
|
300
365
|
messageBytes,
|
|
301
366
|
this.metadata(),
|
|
302
|
-
this.callOptions(
|
|
367
|
+
this.callOptions(timeoutMs),
|
|
303
368
|
(err, response) => {
|
|
304
369
|
if (err !== null) {
|
|
305
370
|
reject(this.mapCallError(target, requestId, err));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NodeTransport, a as TransportMessage, R as RespondFn, T as TransportConfig } from '../../types-
|
|
2
|
-
export { L as ListenHandler } from '../../types-
|
|
1
|
+
import { N as NodeTransport, a as TransportMessage, R as RespondFn, T as TransportConfig } from '../../types-Cz5okLml.js';
|
|
2
|
+
export { L as ListenHandler } from '../../types-Cz5okLml.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Receives a streamed response one chunk at a time.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { replyDeadlineMs } from '../../chunk-747OHOUA.mjs';
|
|
1
2
|
import { MAX_MESSAGE_SIZE_BYTES } from '../../chunk-UNEEFTEU.mjs';
|
|
2
|
-
import { DEFAULT_TRANSPORT_CONFIG, TransportError, TransportErrorCodes } from '../../chunk-
|
|
3
|
+
import { DEFAULT_TRANSPORT_CONFIG, TransportError, TransportErrorCodes } from '../../chunk-PNEYIHA4.mjs';
|
|
3
4
|
|
|
4
5
|
// src/distribution/transport/in-memory.ts
|
|
5
6
|
function createInMemoryNetwork() {
|
|
@@ -97,6 +98,7 @@ function createInMemoryTransport(nodeId, network, config) {
|
|
|
97
98
|
);
|
|
98
99
|
}
|
|
99
100
|
const peer = lookupPeer(target);
|
|
101
|
+
const timeoutMs = replyDeadlineMs(message.type, resolvedConfig);
|
|
100
102
|
return new Promise((resolve, reject) => {
|
|
101
103
|
let settled = false;
|
|
102
104
|
const timeoutId = setTimeout(() => {
|
|
@@ -105,12 +107,12 @@ function createInMemoryTransport(nodeId, network, config) {
|
|
|
105
107
|
reject(
|
|
106
108
|
new TransportError(
|
|
107
109
|
TransportErrorCodes.TIMEOUT,
|
|
108
|
-
`Request to node '${target}' timed out after ${
|
|
109
|
-
{ target, requestId: message.requestId, timeoutMs
|
|
110
|
+
`Request to node '${target}' timed out after ${timeoutMs}ms`,
|
|
111
|
+
{ target, requestId: message.requestId, timeoutMs }
|
|
110
112
|
)
|
|
111
113
|
);
|
|
112
114
|
}
|
|
113
|
-
},
|
|
115
|
+
}, timeoutMs);
|
|
114
116
|
try {
|
|
115
117
|
peer.deliverMessage(message, async (response) => {
|
|
116
118
|
if (!settled) {
|
|
@@ -133,18 +135,19 @@ function createInMemoryTransport(nodeId, network, config) {
|
|
|
133
135
|
const peer = lookupPeer(target);
|
|
134
136
|
return new Promise((resolve, reject) => {
|
|
135
137
|
let settled = false;
|
|
136
|
-
const
|
|
138
|
+
const expire = () => {
|
|
137
139
|
if (!settled) {
|
|
138
140
|
settled = true;
|
|
139
141
|
reject(
|
|
140
142
|
new TransportError(
|
|
141
143
|
TransportErrorCodes.TIMEOUT,
|
|
142
|
-
`
|
|
144
|
+
`No chunk of the stream from node '${target}' arrived within ${resolvedConfig.snapshotTimeout}ms`,
|
|
143
145
|
{ target, requestId: message.requestId, timeoutMs: resolvedConfig.snapshotTimeout }
|
|
144
146
|
)
|
|
145
147
|
);
|
|
146
148
|
}
|
|
147
|
-
}
|
|
149
|
+
};
|
|
150
|
+
let timeoutId = setTimeout(expire, resolvedConfig.snapshotTimeout);
|
|
148
151
|
const settle = (action) => {
|
|
149
152
|
if (settled) {
|
|
150
153
|
return;
|
|
@@ -158,6 +161,8 @@ function createInMemoryTransport(nodeId, network, config) {
|
|
|
158
161
|
if (settled) {
|
|
159
162
|
return Promise.resolve();
|
|
160
163
|
}
|
|
164
|
+
clearTimeout(timeoutId);
|
|
165
|
+
timeoutId = setTimeout(expire, resolvedConfig.snapshotTimeout);
|
|
161
166
|
try {
|
|
162
167
|
handler(payload);
|
|
163
168
|
} catch (error) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NodeTransport } from '../../types-
|
|
2
|
-
import { T as TcpTransportConfig, a as TlsConfig } from '../../types-
|
|
1
|
+
import { N as NodeTransport } from '../../types-Cz5okLml.js';
|
|
2
|
+
import { T as TcpTransportConfig, a as TlsConfig } from '../../types-2qoitTXg.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Builds the TCP transport a cluster node reaches its peers through, with
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DEFAULT_TCP_CONFIG, encodeTransportMessage, encodeFrame, FRAME_TYPE_REQUEST, FrameParser, FRAME_TYPE_RESPONSE, decodeTransportMessage, FRAME_TYPE_STREAM_CHUNK, FRAME_TYPE_STREAM_END } from '../../chunk-
|
|
1
|
+
import { DEFAULT_TCP_CONFIG, encodeTransportMessage, encodeFrame, FRAME_TYPE_REQUEST, FrameParser, FRAME_TYPE_RESPONSE, decodeTransportMessage, FRAME_TYPE_STREAM_CHUNK, FRAME_TYPE_STREAM_END } from '../../chunk-ZKWYWW4Y.mjs';
|
|
2
|
+
import { replyDeadlineMs } from '../../chunk-747OHOUA.mjs';
|
|
2
3
|
import { MAX_MESSAGE_SIZE_BYTES } from '../../chunk-UNEEFTEU.mjs';
|
|
3
|
-
import { TransportError, TransportErrorCodes } from '../../chunk-
|
|
4
|
+
import { TransportError, TransportErrorCodes } from '../../chunk-PNEYIHA4.mjs';
|
|
4
5
|
import { connect as connect$1, createServer as createServer$1 } from 'net';
|
|
5
6
|
import { connect, createServer } from 'tls';
|
|
6
7
|
|
|
@@ -24,6 +25,33 @@ function parseAddress(address) {
|
|
|
24
25
|
return [host, port];
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
// src/distribution/transport/tcp/pending-stream.ts
|
|
29
|
+
function createPendingStream(input) {
|
|
30
|
+
const { target, requestId, timeoutMs, reject } = input;
|
|
31
|
+
const expire = () => {
|
|
32
|
+
input.forget();
|
|
33
|
+
reject(
|
|
34
|
+
new TransportError(
|
|
35
|
+
TransportErrorCodes.TIMEOUT,
|
|
36
|
+
`No chunk of the stream from '${target}' arrived within ${timeoutMs}ms`,
|
|
37
|
+
{ target, requestId, timeoutMs }
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
const pending = {
|
|
42
|
+
target,
|
|
43
|
+
handler: input.handler,
|
|
44
|
+
resolve: input.resolve,
|
|
45
|
+
reject,
|
|
46
|
+
timer: setTimeout(expire, timeoutMs),
|
|
47
|
+
rearm: () => {
|
|
48
|
+
clearTimeout(pending.timer);
|
|
49
|
+
pending.timer = setTimeout(expire, timeoutMs);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return pending;
|
|
53
|
+
}
|
|
54
|
+
|
|
27
55
|
// src/distribution/transport/tcp/connection.ts
|
|
28
56
|
var TcpConnectionPool = class {
|
|
29
57
|
connections = /* @__PURE__ */ new Map();
|
|
@@ -56,21 +84,18 @@ var TcpConnectionPool = class {
|
|
|
56
84
|
const socket = await this.getOrCreateConnection(target);
|
|
57
85
|
const frame = encodeFrame(FRAME_TYPE_REQUEST, message.requestId, messageBytes);
|
|
58
86
|
const pendingKey = `${target}:${message.requestId}`;
|
|
87
|
+
const timeoutMs = replyDeadlineMs(message.type, this.config);
|
|
59
88
|
return new Promise((resolve, reject) => {
|
|
60
89
|
const timer = setTimeout(() => {
|
|
61
90
|
this.pendingRequests.delete(pendingKey);
|
|
62
91
|
reject(
|
|
63
|
-
new TransportError(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
requestId: message.requestId,
|
|
69
|
-
timeoutMs: this.config.requestTimeout
|
|
70
|
-
}
|
|
71
|
-
)
|
|
92
|
+
new TransportError(TransportErrorCodes.TIMEOUT, `Request to '${target}' timed out after ${timeoutMs}ms`, {
|
|
93
|
+
target,
|
|
94
|
+
requestId: message.requestId,
|
|
95
|
+
timeoutMs
|
|
96
|
+
})
|
|
72
97
|
);
|
|
73
|
-
},
|
|
98
|
+
}, timeoutMs);
|
|
74
99
|
this.pendingRequests.set(pendingKey, { target, resolve, reject, timer });
|
|
75
100
|
socket.write(frame, (err) => {
|
|
76
101
|
if (err) {
|
|
@@ -95,24 +120,19 @@ var TcpConnectionPool = class {
|
|
|
95
120
|
const frame = encodeFrame(FRAME_TYPE_REQUEST, message.requestId, messageBytes);
|
|
96
121
|
const pendingKey = `${target}:${message.requestId}`;
|
|
97
122
|
return new Promise((resolve, reject) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}, this.config.snapshotTimeout);
|
|
112
|
-
this.pendingStreams.set(pendingKey, { target, handler, resolve, reject, timer });
|
|
123
|
+
const pending = createPendingStream({
|
|
124
|
+
target,
|
|
125
|
+
requestId: message.requestId,
|
|
126
|
+
timeoutMs: this.config.snapshotTimeout,
|
|
127
|
+
handler,
|
|
128
|
+
resolve,
|
|
129
|
+
reject,
|
|
130
|
+
forget: () => this.pendingStreams.delete(pendingKey)
|
|
131
|
+
});
|
|
132
|
+
this.pendingStreams.set(pendingKey, pending);
|
|
113
133
|
socket.write(frame, (err) => {
|
|
114
134
|
if (err) {
|
|
115
|
-
clearTimeout(timer);
|
|
135
|
+
clearTimeout(pending.timer);
|
|
116
136
|
this.pendingStreams.delete(pendingKey);
|
|
117
137
|
reject(
|
|
118
138
|
new TransportError(
|
|
@@ -239,6 +259,7 @@ var TcpConnectionPool = class {
|
|
|
239
259
|
}
|
|
240
260
|
const pendingStream = this.pendingStreams.get(pendingKey);
|
|
241
261
|
if (pendingStream !== void 0) {
|
|
262
|
+
pendingStream.rearm();
|
|
242
263
|
try {
|
|
243
264
|
const message = decodeTransportMessage(frame.data);
|
|
244
265
|
pendingStream.handler(message.payload);
|
|
@@ -259,6 +280,7 @@ var TcpConnectionPool = class {
|
|
|
259
280
|
if (frame.frameType === FRAME_TYPE_STREAM_CHUNK) {
|
|
260
281
|
const pending = this.pendingStreams.get(pendingKey);
|
|
261
282
|
if (pending !== void 0) {
|
|
283
|
+
pending.rearm();
|
|
262
284
|
pending.handler(frame.data);
|
|
263
285
|
}
|
|
264
286
|
return;
|