@plexspaces/sdk 0.1.9 → 0.1.10
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/dist/host.d.ts +68 -8
- package/dist/host.js +295 -20
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/shard_types.d.ts +76 -0
- package/dist/shard_types.js +5 -0
- package/dist/wire/shard-group-proto-wire.d.ts +12 -0
- package/dist/wire/shard-group-proto-wire.js +533 -36
- package/dist/wire/tuplespace-proto-wire.d.ts +1 -1
- package/dist/wire/tuplespace-proto-wire.js +6 -6
- package/package.json +1 -1
|
@@ -158,10 +158,13 @@ function ulid() {
|
|
|
158
158
|
return id;
|
|
159
159
|
}
|
|
160
160
|
function encodeMessage(query) {
|
|
161
|
+
const op = query['op'] || query['message_type'] || 'call';
|
|
161
162
|
let buf = new Uint8Array(0);
|
|
162
163
|
buf = appendString(buf, 1, ulid());
|
|
163
|
-
buf = appendString(buf, 5,
|
|
164
|
-
|
|
164
|
+
buf = appendString(buf, 5, op);
|
|
165
|
+
// inject message_type into payload so the receiver can read it
|
|
166
|
+
const payloadObj = { ...query, message_type: op };
|
|
167
|
+
const payloadBytes = new Uint8Array(encW.encode(JSON.stringify(payloadObj)));
|
|
165
168
|
buf = appendBytes(buf, 6, payloadBytes);
|
|
166
169
|
return buf;
|
|
167
170
|
}
|
|
@@ -169,14 +172,17 @@ function encodeMessage(query) {
|
|
|
169
172
|
// CreateShardGroupRequest encoder
|
|
170
173
|
//
|
|
171
174
|
// message CreateShardGroupRequest {
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
175
|
+
// string request_id = 1;
|
|
176
|
+
// DataParallelConfig config = 2; (embedded)
|
|
177
|
+
// string actor_type = 3;
|
|
178
|
+
// ActorConfig shard_config = 4; (not used here)
|
|
179
|
+
// bytes initial_state = 5;
|
|
180
|
+
// map<string, string> metadata = 6;
|
|
176
181
|
// }
|
|
177
182
|
// ---------------------------------------------------------------------------
|
|
178
183
|
export function encodeCreateShardGroupRequest(req) {
|
|
179
184
|
let buf = new Uint8Array(0);
|
|
185
|
+
buf = appendString(buf, 1, ulid());
|
|
180
186
|
// config = DataParallelConfig (fields: group_id, shard_count, partition_strategy, rebalance_policy, placement)
|
|
181
187
|
const cfgFields = {
|
|
182
188
|
group_id: req.group_id,
|
|
@@ -186,13 +192,22 @@ export function encodeCreateShardGroupRequest(req) {
|
|
|
186
192
|
placement: req.placement,
|
|
187
193
|
};
|
|
188
194
|
const cfgBytes = encodeDataParallelConfig(cfgFields);
|
|
189
|
-
buf = appendLengthDelimited(buf,
|
|
190
|
-
buf = appendString(buf,
|
|
195
|
+
buf = appendLengthDelimited(buf, 2, cfgBytes);
|
|
196
|
+
buf = appendString(buf, 3, req.actor_type ?? '');
|
|
191
197
|
const initialState = req.initial_state;
|
|
192
198
|
if (initialState !== undefined && initialState !== null) {
|
|
193
199
|
const stateBytes = new Uint8Array(encW.encode(JSON.stringify(initialState)));
|
|
194
200
|
if (stateBytes.length > 0) {
|
|
195
|
-
buf = appendBytes(buf,
|
|
201
|
+
buf = appendBytes(buf, 5, stateBytes);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const metadata = req.metadata;
|
|
205
|
+
if (metadata && typeof metadata === 'object') {
|
|
206
|
+
for (const [k, v] of Object.entries(metadata)) {
|
|
207
|
+
let entry = new Uint8Array(0);
|
|
208
|
+
entry = appendString(entry, 1, k);
|
|
209
|
+
entry = appendString(entry, 2, String(v));
|
|
210
|
+
buf = appendLengthDelimited(buf, 6, entry);
|
|
196
211
|
}
|
|
197
212
|
}
|
|
198
213
|
return buf;
|
|
@@ -201,11 +216,12 @@ export function encodeCreateShardGroupRequest(req) {
|
|
|
201
216
|
// ScatterGatherRequest encoder
|
|
202
217
|
//
|
|
203
218
|
// message ScatterGatherRequest {
|
|
204
|
-
// string
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
219
|
+
// string request_id = 1;
|
|
220
|
+
// string group_id = 2;
|
|
221
|
+
// Message query = 3; (embedded)
|
|
222
|
+
// google.protobuf.Duration timeout = 4; (embedded)
|
|
223
|
+
// ShardGroupAggregationStrategy aggregation = 5; (varint)
|
|
224
|
+
// uint32 min_responses = 6;
|
|
209
225
|
// }
|
|
210
226
|
//
|
|
211
227
|
// google.protobuf.Duration { int64 seconds=1, int32 nanos=2 }
|
|
@@ -228,24 +244,25 @@ function encodeDurationMs(ms) {
|
|
|
228
244
|
}
|
|
229
245
|
export function encodeScatterGatherRequest(req) {
|
|
230
246
|
let buf = new Uint8Array(0);
|
|
231
|
-
buf = appendString(buf, 1,
|
|
247
|
+
buf = appendString(buf, 1, ulid());
|
|
248
|
+
buf = appendString(buf, 2, req.group_id ?? '');
|
|
232
249
|
const query = req.query;
|
|
233
250
|
if (query && typeof query === 'object') {
|
|
234
251
|
const msgBytes = encodeMessage(query);
|
|
235
|
-
buf = appendLengthDelimited(buf,
|
|
252
|
+
buf = appendLengthDelimited(buf, 3, msgBytes);
|
|
236
253
|
}
|
|
237
254
|
const timeoutMs = Number(req.timeout_ms ?? 30000);
|
|
238
255
|
if (timeoutMs > 0) {
|
|
239
256
|
const durBytes = encodeDurationMs(timeoutMs);
|
|
240
257
|
if (durBytes.length > 0)
|
|
241
|
-
buf = appendLengthDelimited(buf,
|
|
258
|
+
buf = appendLengthDelimited(buf, 4, durBytes);
|
|
242
259
|
}
|
|
243
260
|
const agg = aggregationStrategyEnum(req.aggregation);
|
|
244
261
|
if (agg !== 0)
|
|
245
|
-
buf = appendUint32(buf,
|
|
262
|
+
buf = appendUint32(buf, 5, agg);
|
|
246
263
|
const minResponses = Number(req.min_responses ?? 0) >>> 0;
|
|
247
264
|
if (minResponses > 0)
|
|
248
|
-
buf = appendUint32(buf,
|
|
265
|
+
buf = appendUint32(buf, 6, minResponses);
|
|
249
266
|
return buf;
|
|
250
267
|
}
|
|
251
268
|
// ---------------------------------------------------------------------------
|
|
@@ -347,7 +364,7 @@ export function decodeCreateShardGroupResponse(data) {
|
|
|
347
364
|
pos += tn;
|
|
348
365
|
const fn = Number(tag >> 3n);
|
|
349
366
|
const wt = Number(tag & 7n);
|
|
350
|
-
if (fn ===
|
|
367
|
+
if (fn === 2 && wt === 2) {
|
|
351
368
|
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
352
369
|
pos = nextPos;
|
|
353
370
|
group = decodeShardGroup(slice);
|
|
@@ -362,17 +379,25 @@ export function decodeCreateShardGroupResponse(data) {
|
|
|
362
379
|
// ScatterGatherResponse decoder
|
|
363
380
|
//
|
|
364
381
|
// message ScatterGatherResponse {
|
|
365
|
-
//
|
|
366
|
-
//
|
|
367
|
-
//
|
|
382
|
+
// string request_id = 1;
|
|
383
|
+
// Message result = 2;
|
|
384
|
+
// repeated ShardQueryResponse shard_responses = 3;
|
|
385
|
+
// ScatterGatherStats stats = 4;
|
|
368
386
|
// }
|
|
369
387
|
// message ShardQueryResponse {
|
|
370
|
-
//
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
//
|
|
375
|
-
//
|
|
388
|
+
// string request_id = 1;
|
|
389
|
+
// uint32 shard_id = 2;
|
|
390
|
+
// string shard_actor_id = 3;
|
|
391
|
+
// Message response = 4;
|
|
392
|
+
// Duration latency = 5;
|
|
393
|
+
// bool success = 6;
|
|
394
|
+
// string error = 7;
|
|
395
|
+
// }
|
|
396
|
+
// message ScatterGatherStats {
|
|
397
|
+
// uint32 shards_queried = 1;
|
|
398
|
+
// uint32 shards_responded = 2;
|
|
399
|
+
// uint32 shards_failed = 3;
|
|
400
|
+
// Duration max_latency = 4;
|
|
376
401
|
// }
|
|
377
402
|
// message Message { ... bytes payload = 6; ... }
|
|
378
403
|
// ---------------------------------------------------------------------------
|
|
@@ -403,6 +428,37 @@ function decodeMessagePayload(data) {
|
|
|
403
428
|
return text;
|
|
404
429
|
}
|
|
405
430
|
}
|
|
431
|
+
function decodeScatterGatherStats(data) {
|
|
432
|
+
const result = {
|
|
433
|
+
shards_queried: 0, shards_responded: 0, shards_failed: 0, max_latency_ms: 0,
|
|
434
|
+
};
|
|
435
|
+
let pos = 0;
|
|
436
|
+
while (pos < data.length) {
|
|
437
|
+
const { value: tag, n: tn } = readVarint(data, pos);
|
|
438
|
+
pos += tn;
|
|
439
|
+
const fn = Number(tag >> 3n);
|
|
440
|
+
const wt = Number(tag & 7n);
|
|
441
|
+
if (fn === 1 && wt === 0) {
|
|
442
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
443
|
+
result.shards_queried = value;
|
|
444
|
+
pos = nextPos;
|
|
445
|
+
}
|
|
446
|
+
else if (fn === 2 && wt === 0) {
|
|
447
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
448
|
+
result.shards_responded = value;
|
|
449
|
+
pos = nextPos;
|
|
450
|
+
}
|
|
451
|
+
else if (fn === 3 && wt === 0) {
|
|
452
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
453
|
+
result.shards_failed = value;
|
|
454
|
+
pos = nextPos;
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
pos = skipField(data, pos, wt);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return result;
|
|
461
|
+
}
|
|
406
462
|
function decodeShardQueryResponse(data) {
|
|
407
463
|
const result = {
|
|
408
464
|
shard_id: 0,
|
|
@@ -417,28 +473,27 @@ function decodeShardQueryResponse(data) {
|
|
|
417
473
|
pos += tn;
|
|
418
474
|
const fn = Number(tag >> 3n);
|
|
419
475
|
const wt = Number(tag & 7n);
|
|
420
|
-
if (fn ===
|
|
476
|
+
if (fn === 2 && wt === 0) {
|
|
421
477
|
const { value, nextPos } = readUint32(data, pos);
|
|
422
478
|
pos = nextPos;
|
|
423
479
|
result.shard_id = value;
|
|
424
480
|
}
|
|
425
|
-
else if (fn ===
|
|
481
|
+
else if (fn === 3 && wt === 2) {
|
|
426
482
|
const { value, nextPos } = readString(data, pos);
|
|
427
483
|
pos = nextPos;
|
|
428
484
|
result.shard_actor_id = value;
|
|
429
485
|
}
|
|
430
|
-
else if (fn ===
|
|
486
|
+
else if (fn === 4 && wt === 2) {
|
|
431
487
|
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
432
488
|
pos = nextPos;
|
|
433
|
-
// Expose the message payload directly so normalizeWorkerPayload can find it
|
|
434
489
|
result.payload = decodeMessagePayload(slice);
|
|
435
490
|
}
|
|
436
|
-
else if (fn ===
|
|
491
|
+
else if (fn === 6 && wt === 0) {
|
|
437
492
|
const { value, nextPos } = readUint32(data, pos);
|
|
438
493
|
pos = nextPos;
|
|
439
494
|
result.success = value !== 0;
|
|
440
495
|
}
|
|
441
|
-
else if (fn ===
|
|
496
|
+
else if (fn === 7 && wt === 2) {
|
|
442
497
|
const { value, nextPos } = readString(data, pos);
|
|
443
498
|
pos = nextPos;
|
|
444
499
|
result.error = value;
|
|
@@ -451,6 +506,34 @@ function decodeShardQueryResponse(data) {
|
|
|
451
506
|
}
|
|
452
507
|
export function decodeScatterGatherResponse(data) {
|
|
453
508
|
const shardResponses = [];
|
|
509
|
+
let stats = null;
|
|
510
|
+
let pos = 0;
|
|
511
|
+
while (pos < data.length) {
|
|
512
|
+
const { value: tag, n: tn } = readVarint(data, pos);
|
|
513
|
+
pos += tn;
|
|
514
|
+
const fn = Number(tag >> 3n);
|
|
515
|
+
const wt = Number(tag & 7n);
|
|
516
|
+
if (fn === 3 && wt === 2) {
|
|
517
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
518
|
+
pos = nextPos;
|
|
519
|
+
shardResponses.push(decodeShardQueryResponse(slice));
|
|
520
|
+
}
|
|
521
|
+
else if (fn === 4 && wt === 2) {
|
|
522
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
523
|
+
pos = nextPos;
|
|
524
|
+
stats = decodeScatterGatherStats(slice);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
pos = skipField(data, pos, wt);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return { shard_responses: shardResponses, stats: stats ?? {} };
|
|
531
|
+
}
|
|
532
|
+
// BroadcastShardGroupResponse and BarrierShardGroupResponse have shard_responses at field 2
|
|
533
|
+
// (not field 3 like ScatterGatherResponse) — they lack the aggregated result field.
|
|
534
|
+
function decodeBroadcastLikeResponse(data) {
|
|
535
|
+
const shardResponses = [];
|
|
536
|
+
let stats = null;
|
|
454
537
|
let pos = 0;
|
|
455
538
|
while (pos < data.length) {
|
|
456
539
|
const { value: tag, n: tn } = readVarint(data, pos);
|
|
@@ -462,11 +545,16 @@ export function decodeScatterGatherResponse(data) {
|
|
|
462
545
|
pos = nextPos;
|
|
463
546
|
shardResponses.push(decodeShardQueryResponse(slice));
|
|
464
547
|
}
|
|
548
|
+
else if (fn === 3 && wt === 2) {
|
|
549
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
550
|
+
pos = nextPos;
|
|
551
|
+
stats = decodeScatterGatherStats(slice);
|
|
552
|
+
}
|
|
465
553
|
else {
|
|
466
554
|
pos = skipField(data, pos, wt);
|
|
467
555
|
}
|
|
468
556
|
}
|
|
469
|
-
return { shard_responses: shardResponses };
|
|
557
|
+
return { shard_responses: shardResponses, stats: stats ?? {} };
|
|
470
558
|
}
|
|
471
559
|
// ---------------------------------------------------------------------------
|
|
472
560
|
// GetApplicationStatusResponse decoder
|
|
@@ -689,6 +777,415 @@ function encodeUint64MapEntry(key, value) {
|
|
|
689
777
|
entry = appendUint64(entry, 2, value);
|
|
690
778
|
return entry;
|
|
691
779
|
}
|
|
780
|
+
// ---------------------------------------------------------------------------
|
|
781
|
+
// BulkUpdateShardGroupRequest encoder
|
|
782
|
+
//
|
|
783
|
+
// BulkUpdateShardGroupRequest {
|
|
784
|
+
// string request_id = 1;
|
|
785
|
+
// string group_id = 2;
|
|
786
|
+
// map<string, Message> updates = 3; // partition_key -> message
|
|
787
|
+
// ConsistencyLevel consistency_level = 4;
|
|
788
|
+
// Duration timeout = 5;
|
|
789
|
+
// bool wait_for_responses = 6;
|
|
790
|
+
// }
|
|
791
|
+
// ---------------------------------------------------------------------------
|
|
792
|
+
export function encodeBulkUpdateShardGroupRequest(req) {
|
|
793
|
+
let buf = new Uint8Array(0);
|
|
794
|
+
buf = appendString(buf, 1, req.request_id ?? '');
|
|
795
|
+
buf = appendString(buf, 2, req.group_id ?? '');
|
|
796
|
+
const rawUpdates = req.updates;
|
|
797
|
+
let items;
|
|
798
|
+
if (Array.isArray(rawUpdates)) {
|
|
799
|
+
items = rawUpdates;
|
|
800
|
+
}
|
|
801
|
+
else if (rawUpdates && typeof rawUpdates === 'object') {
|
|
802
|
+
items = Object.entries(rawUpdates).map(([k, v]) => ({
|
|
803
|
+
key: k,
|
|
804
|
+
payload: v,
|
|
805
|
+
}));
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
items = [];
|
|
809
|
+
}
|
|
810
|
+
for (const entry of items) {
|
|
811
|
+
const partitionKey = String(entry.key ?? '');
|
|
812
|
+
const payload = entry.payload && typeof entry.payload === 'object' ? entry.payload : {};
|
|
813
|
+
const msgBytes = encodeMessage(payload);
|
|
814
|
+
let mapEntry = new Uint8Array(0);
|
|
815
|
+
mapEntry = appendString(mapEntry, 1, partitionKey);
|
|
816
|
+
mapEntry = appendLengthDelimited(mapEntry, 2, msgBytes);
|
|
817
|
+
buf = appendLengthDelimited(buf, 3, mapEntry);
|
|
818
|
+
}
|
|
819
|
+
const consistencyLevel = Number(req.consistency_level ?? 0) >>> 0;
|
|
820
|
+
if (consistencyLevel !== 0)
|
|
821
|
+
buf = appendUint32(buf, 4, consistencyLevel);
|
|
822
|
+
const timeoutMs = Number(req.timeout_ms ?? 5000);
|
|
823
|
+
if (timeoutMs > 0) {
|
|
824
|
+
const durBytes = encodeDurationMs(timeoutMs);
|
|
825
|
+
if (durBytes.length > 0)
|
|
826
|
+
buf = appendLengthDelimited(buf, 5, durBytes);
|
|
827
|
+
}
|
|
828
|
+
const waitForResponses = req.wait_for_responses !== false; // default true
|
|
829
|
+
if (waitForResponses) {
|
|
830
|
+
buf = appendUint32(buf, 6, 1);
|
|
831
|
+
}
|
|
832
|
+
return buf;
|
|
833
|
+
}
|
|
834
|
+
// ---------------------------------------------------------------------------
|
|
835
|
+
// BulkUpdateShardGroupResponse decoder
|
|
836
|
+
//
|
|
837
|
+
// BulkUpdateShardGroupResponse {
|
|
838
|
+
// string request_id = 1;
|
|
839
|
+
// uint32 updates_sent = 2;
|
|
840
|
+
// uint32 updates_succeeded = 3;
|
|
841
|
+
// uint32 updates_failed = 4;
|
|
842
|
+
// repeated ShardUpdateStats shard_stats = 5;
|
|
843
|
+
// repeated string errors = 6;
|
|
844
|
+
// }
|
|
845
|
+
// ---------------------------------------------------------------------------
|
|
846
|
+
export function decodeBulkUpdateShardGroupResponse(data) {
|
|
847
|
+
const result = {
|
|
848
|
+
request_id: '',
|
|
849
|
+
updates_sent: 0,
|
|
850
|
+
updates_succeeded: 0,
|
|
851
|
+
updates_failed: 0,
|
|
852
|
+
shard_stats: [],
|
|
853
|
+
errors: [],
|
|
854
|
+
};
|
|
855
|
+
if (!data || data.length === 0)
|
|
856
|
+
return result;
|
|
857
|
+
let pos = 0;
|
|
858
|
+
while (pos < data.length) {
|
|
859
|
+
const { value: tagVal, n: tagN } = readVarint(data, pos);
|
|
860
|
+
pos += tagN;
|
|
861
|
+
const fieldNum = Number(tagVal >> BigInt(3));
|
|
862
|
+
const wireType = Number(tagVal & BigInt(7));
|
|
863
|
+
if (fieldNum === 1 && wireType === 2) {
|
|
864
|
+
const { value, nextPos } = readString(data, pos);
|
|
865
|
+
result.request_id = value;
|
|
866
|
+
pos = nextPos;
|
|
867
|
+
}
|
|
868
|
+
else if (fieldNum === 2 && wireType === 0) {
|
|
869
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
870
|
+
result.updates_sent = value;
|
|
871
|
+
pos = nextPos;
|
|
872
|
+
}
|
|
873
|
+
else if (fieldNum === 3 && wireType === 0) {
|
|
874
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
875
|
+
result.updates_succeeded = value;
|
|
876
|
+
pos = nextPos;
|
|
877
|
+
}
|
|
878
|
+
else if (fieldNum === 4 && wireType === 0) {
|
|
879
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
880
|
+
result.updates_failed = value;
|
|
881
|
+
pos = nextPos;
|
|
882
|
+
}
|
|
883
|
+
else if (fieldNum === 5 && wireType === 2) {
|
|
884
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
885
|
+
result.shard_stats.push(decodeShardUpdateStats(slice));
|
|
886
|
+
pos = nextPos;
|
|
887
|
+
}
|
|
888
|
+
else if (fieldNum === 6 && wireType === 2) {
|
|
889
|
+
const { value, nextPos } = readString(data, pos);
|
|
890
|
+
result.errors.push(value);
|
|
891
|
+
pos = nextPos;
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
pos = skipField(data, pos, wireType);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return result;
|
|
898
|
+
}
|
|
899
|
+
function decodeShardUpdateStats(data) {
|
|
900
|
+
const result = {
|
|
901
|
+
shard_id: 0, shard_actor_id: '', updates_sent: 0, updates_succeeded: 0, updates_failed: 0,
|
|
902
|
+
};
|
|
903
|
+
if (!data || data.length === 0)
|
|
904
|
+
return result;
|
|
905
|
+
let pos = 0;
|
|
906
|
+
while (pos < data.length) {
|
|
907
|
+
const { value: tagVal, n: tagN } = readVarint(data, pos);
|
|
908
|
+
pos += tagN;
|
|
909
|
+
const fieldNum = Number(tagVal >> BigInt(3));
|
|
910
|
+
const wireType = Number(tagVal & BigInt(7));
|
|
911
|
+
if (fieldNum === 1 && wireType === 0) {
|
|
912
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
913
|
+
result.shard_id = value;
|
|
914
|
+
pos = nextPos;
|
|
915
|
+
}
|
|
916
|
+
else if (fieldNum === 2 && wireType === 2) {
|
|
917
|
+
const { value, nextPos } = readString(data, pos);
|
|
918
|
+
result.shard_actor_id = value;
|
|
919
|
+
pos = nextPos;
|
|
920
|
+
}
|
|
921
|
+
else if (fieldNum === 3 && wireType === 0) {
|
|
922
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
923
|
+
result.updates_sent = value;
|
|
924
|
+
pos = nextPos;
|
|
925
|
+
}
|
|
926
|
+
else if (fieldNum === 4 && wireType === 0) {
|
|
927
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
928
|
+
result.updates_succeeded = value;
|
|
929
|
+
pos = nextPos;
|
|
930
|
+
}
|
|
931
|
+
else if (fieldNum === 5 && wireType === 0) {
|
|
932
|
+
const { value, nextPos } = readUint32(data, pos);
|
|
933
|
+
result.updates_failed = value;
|
|
934
|
+
pos = nextPos;
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
pos = skipField(data, pos, wireType);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return result;
|
|
941
|
+
}
|
|
942
|
+
// ---------------------------------------------------------------------------
|
|
943
|
+
// collectiveReductionEnum — maps JS string names to proto CollectiveReduction values
|
|
944
|
+
// sum=1, min=2, max=3, product=4, concat=5, bool_and=6, bool_or=7
|
|
945
|
+
// ---------------------------------------------------------------------------
|
|
946
|
+
function collectiveReductionEnum(s) {
|
|
947
|
+
switch ((s ?? '').toLowerCase()) {
|
|
948
|
+
case 'sum': return 1;
|
|
949
|
+
case 'min': return 2;
|
|
950
|
+
case 'max': return 3;
|
|
951
|
+
case 'product': return 4;
|
|
952
|
+
case 'concat': return 5;
|
|
953
|
+
case 'bool_and': return 6;
|
|
954
|
+
case 'bool_or': return 7;
|
|
955
|
+
default: return 0;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
// ---------------------------------------------------------------------------
|
|
959
|
+
// BroadcastShardGroupRequest encoder
|
|
960
|
+
//
|
|
961
|
+
// message BroadcastShardGroupRequest {
|
|
962
|
+
// string request_id = 1;
|
|
963
|
+
// string group_id = 2;
|
|
964
|
+
// Message message = 3;
|
|
965
|
+
// google.protobuf.Duration timeout = 4;
|
|
966
|
+
// uint32 min_acks = 5;
|
|
967
|
+
// }
|
|
968
|
+
// ---------------------------------------------------------------------------
|
|
969
|
+
export function encodeBroadcastShardGroupRequest(req) {
|
|
970
|
+
let buf = new Uint8Array(0);
|
|
971
|
+
buf = appendString(buf, 1, ulid());
|
|
972
|
+
buf = appendString(buf, 2, req.group_id ?? '');
|
|
973
|
+
const message = req.message;
|
|
974
|
+
if (message && typeof message === 'object') {
|
|
975
|
+
buf = appendLengthDelimited(buf, 3, encodeMessage(message));
|
|
976
|
+
}
|
|
977
|
+
const timeoutMs = Number(req.timeout_ms ?? 30000);
|
|
978
|
+
if (timeoutMs > 0) {
|
|
979
|
+
const durBytes = encodeDurationMs(timeoutMs);
|
|
980
|
+
if (durBytes.length > 0)
|
|
981
|
+
buf = appendLengthDelimited(buf, 4, durBytes);
|
|
982
|
+
}
|
|
983
|
+
const minAcks = Number(req.min_acks ?? 0) >>> 0;
|
|
984
|
+
if (minAcks > 0)
|
|
985
|
+
buf = appendUint32(buf, 5, minAcks);
|
|
986
|
+
return buf;
|
|
987
|
+
}
|
|
988
|
+
// ---------------------------------------------------------------------------
|
|
989
|
+
// ReduceShardGroupRequest encoder
|
|
990
|
+
//
|
|
991
|
+
// message ReduceShardGroupRequest {
|
|
992
|
+
// string request_id = 1;
|
|
993
|
+
// string group_id = 2;
|
|
994
|
+
// Message map_function = 3;
|
|
995
|
+
// google.protobuf.Duration timeout = 4;
|
|
996
|
+
// uint32 min_responses = 5;
|
|
997
|
+
// CollectiveReduction reduction = 6; (varint)
|
|
998
|
+
// CollectiveTargetField target = 7; (embedded: string value_path = 1)
|
|
999
|
+
// }
|
|
1000
|
+
// ---------------------------------------------------------------------------
|
|
1001
|
+
export function encodeReduceShardGroupRequest(req) {
|
|
1002
|
+
let buf = new Uint8Array(0);
|
|
1003
|
+
buf = appendString(buf, 1, ulid());
|
|
1004
|
+
buf = appendString(buf, 2, req.group_id ?? '');
|
|
1005
|
+
const mapFn = req.map_function;
|
|
1006
|
+
if (mapFn && typeof mapFn === 'object') {
|
|
1007
|
+
buf = appendLengthDelimited(buf, 3, encodeMessage(mapFn));
|
|
1008
|
+
}
|
|
1009
|
+
const timeoutMs = Number(req.timeout_ms ?? 30000);
|
|
1010
|
+
if (timeoutMs > 0) {
|
|
1011
|
+
const durBytes = encodeDurationMs(timeoutMs);
|
|
1012
|
+
if (durBytes.length > 0)
|
|
1013
|
+
buf = appendLengthDelimited(buf, 4, durBytes);
|
|
1014
|
+
}
|
|
1015
|
+
const minResponses = Number(req.min_responses ?? 0) >>> 0;
|
|
1016
|
+
if (minResponses > 0)
|
|
1017
|
+
buf = appendUint32(buf, 5, minResponses);
|
|
1018
|
+
const reduction = collectiveReductionEnum(req.reduction);
|
|
1019
|
+
if (reduction !== 0)
|
|
1020
|
+
buf = appendUint32(buf, 6, reduction);
|
|
1021
|
+
const target = req.target;
|
|
1022
|
+
if (target) {
|
|
1023
|
+
let targetField = new Uint8Array(0);
|
|
1024
|
+
targetField = appendString(targetField, 1, target);
|
|
1025
|
+
buf = appendLengthDelimited(buf, 7, targetField);
|
|
1026
|
+
}
|
|
1027
|
+
return buf;
|
|
1028
|
+
}
|
|
1029
|
+
// ---------------------------------------------------------------------------
|
|
1030
|
+
// AllReduceShardGroupRequest encoder — identical shape to ReduceShardGroupRequest
|
|
1031
|
+
// ---------------------------------------------------------------------------
|
|
1032
|
+
export function encodeAllReduceShardGroupRequest(req) {
|
|
1033
|
+
return encodeReduceShardGroupRequest(req);
|
|
1034
|
+
}
|
|
1035
|
+
// ---------------------------------------------------------------------------
|
|
1036
|
+
// BarrierShardGroupRequest encoder
|
|
1037
|
+
//
|
|
1038
|
+
// message BarrierShardGroupRequest {
|
|
1039
|
+
// string request_id = 1;
|
|
1040
|
+
// string group_id = 2;
|
|
1041
|
+
// string barrier_id = 3;
|
|
1042
|
+
// uint64 round = 4; (varint)
|
|
1043
|
+
// google.protobuf.Duration timeout = 5;
|
|
1044
|
+
// uint32 min_acks = 6;
|
|
1045
|
+
// }
|
|
1046
|
+
// ---------------------------------------------------------------------------
|
|
1047
|
+
export function encodeBarrierShardGroupRequest(req) {
|
|
1048
|
+
let buf = new Uint8Array(0);
|
|
1049
|
+
buf = appendString(buf, 1, ulid());
|
|
1050
|
+
buf = appendString(buf, 2, req.group_id ?? '');
|
|
1051
|
+
buf = appendString(buf, 3, req.barrier_id ?? '');
|
|
1052
|
+
const round = Number(req.round ?? 0);
|
|
1053
|
+
if (round > 0) {
|
|
1054
|
+
buf = appendVarint(buf, (4 << 3) | 0);
|
|
1055
|
+
buf = appendVarint(buf, round);
|
|
1056
|
+
}
|
|
1057
|
+
const timeoutMs = Number(req.timeout_ms ?? 30000);
|
|
1058
|
+
if (timeoutMs > 0) {
|
|
1059
|
+
const durBytes = encodeDurationMs(timeoutMs);
|
|
1060
|
+
if (durBytes.length > 0)
|
|
1061
|
+
buf = appendLengthDelimited(buf, 5, durBytes);
|
|
1062
|
+
}
|
|
1063
|
+
const minAcks = Number(req.min_acks ?? 0) >>> 0;
|
|
1064
|
+
if (minAcks > 0)
|
|
1065
|
+
buf = appendUint32(buf, 6, minAcks);
|
|
1066
|
+
return buf;
|
|
1067
|
+
}
|
|
1068
|
+
// ---------------------------------------------------------------------------
|
|
1069
|
+
// MapShardGroupRequest encoder
|
|
1070
|
+
//
|
|
1071
|
+
// message MapShardGroupRequest {
|
|
1072
|
+
// string request_id = 1;
|
|
1073
|
+
// string group_id = 2;
|
|
1074
|
+
// Message map_function = 3;
|
|
1075
|
+
// google.protobuf.Duration timeout = 4;
|
|
1076
|
+
// uint32 min_responses = 5;
|
|
1077
|
+
// }
|
|
1078
|
+
// ---------------------------------------------------------------------------
|
|
1079
|
+
export function encodeMapShardGroupRequest(req) {
|
|
1080
|
+
let buf = new Uint8Array(0);
|
|
1081
|
+
buf = appendString(buf, 1, ulid());
|
|
1082
|
+
buf = appendString(buf, 2, req.group_id ?? '');
|
|
1083
|
+
const mapFn = req.map_function;
|
|
1084
|
+
if (mapFn && typeof mapFn === 'object') {
|
|
1085
|
+
buf = appendLengthDelimited(buf, 3, encodeMessage(mapFn));
|
|
1086
|
+
}
|
|
1087
|
+
const timeoutMs = Number(req.timeout_ms ?? 30000);
|
|
1088
|
+
if (timeoutMs > 0) {
|
|
1089
|
+
const durBytes = encodeDurationMs(timeoutMs);
|
|
1090
|
+
if (durBytes.length > 0)
|
|
1091
|
+
buf = appendLengthDelimited(buf, 4, durBytes);
|
|
1092
|
+
}
|
|
1093
|
+
const minResponses = Number(req.min_responses ?? 0) >>> 0;
|
|
1094
|
+
if (minResponses > 0)
|
|
1095
|
+
buf = appendUint32(buf, 5, minResponses);
|
|
1096
|
+
return buf;
|
|
1097
|
+
}
|
|
1098
|
+
// ---------------------------------------------------------------------------
|
|
1099
|
+
// BroadcastShardGroupResponse decoder
|
|
1100
|
+
//
|
|
1101
|
+
// message BroadcastShardGroupResponse {
|
|
1102
|
+
// string request_id = 1;
|
|
1103
|
+
// repeated ShardQueryResponse shard_responses = 2;
|
|
1104
|
+
// ScatterGatherStats stats = 3;
|
|
1105
|
+
// }
|
|
1106
|
+
// ---------------------------------------------------------------------------
|
|
1107
|
+
export function decodeBroadcastShardGroupResponse(data) {
|
|
1108
|
+
return decodeBroadcastLikeResponse(data);
|
|
1109
|
+
}
|
|
1110
|
+
// ---------------------------------------------------------------------------
|
|
1111
|
+
// ReduceShardGroupResponse decoder
|
|
1112
|
+
//
|
|
1113
|
+
// message ReduceShardGroupResponse {
|
|
1114
|
+
// string request_id = 1;
|
|
1115
|
+
// Message result = 2;
|
|
1116
|
+
// repeated ShardQueryResponse shard_responses = 3;
|
|
1117
|
+
// }
|
|
1118
|
+
// ---------------------------------------------------------------------------
|
|
1119
|
+
export function decodeReduceShardGroupResponse(data) {
|
|
1120
|
+
const shardResponses = [];
|
|
1121
|
+
let result = {};
|
|
1122
|
+
let pos = 0;
|
|
1123
|
+
while (pos < data.length) {
|
|
1124
|
+
const { value: tag, n: tn } = readVarint(data, pos);
|
|
1125
|
+
pos += tn;
|
|
1126
|
+
const fn = Number(tag >> 3n);
|
|
1127
|
+
const wt = Number(tag & 7n);
|
|
1128
|
+
if (fn === 2 && wt === 2) {
|
|
1129
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
1130
|
+
pos = nextPos;
|
|
1131
|
+
result = decodeMessagePayload(slice);
|
|
1132
|
+
}
|
|
1133
|
+
else if (fn === 3 && wt === 2) {
|
|
1134
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
1135
|
+
pos = nextPos;
|
|
1136
|
+
shardResponses.push(decodeShardQueryResponse(slice));
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
pos = skipField(data, pos, wt);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return { result, shard_responses: shardResponses };
|
|
1143
|
+
}
|
|
1144
|
+
// ---------------------------------------------------------------------------
|
|
1145
|
+
// AllReduceShardGroupResponse decoder — same shape as ReduceShardGroupResponse
|
|
1146
|
+
// ---------------------------------------------------------------------------
|
|
1147
|
+
export function decodeAllReduceShardGroupResponse(data) {
|
|
1148
|
+
return decodeReduceShardGroupResponse(data);
|
|
1149
|
+
}
|
|
1150
|
+
// ---------------------------------------------------------------------------
|
|
1151
|
+
// BarrierShardGroupResponse decoder — same shape as BroadcastShardGroupResponse
|
|
1152
|
+
//
|
|
1153
|
+
// message BarrierShardGroupResponse {
|
|
1154
|
+
// string request_id = 1;
|
|
1155
|
+
// repeated ShardQueryResponse shard_responses = 2;
|
|
1156
|
+
// ScatterGatherStats stats = 3;
|
|
1157
|
+
// }
|
|
1158
|
+
// ---------------------------------------------------------------------------
|
|
1159
|
+
export function decodeBarrierShardGroupResponse(data) {
|
|
1160
|
+
return decodeBroadcastLikeResponse(data);
|
|
1161
|
+
}
|
|
1162
|
+
// ---------------------------------------------------------------------------
|
|
1163
|
+
// MapShardGroupResponse decoder
|
|
1164
|
+
//
|
|
1165
|
+
// message MapShardGroupResponse {
|
|
1166
|
+
// string request_id = 1;
|
|
1167
|
+
// repeated ShardQueryResponse shard_results = 2;
|
|
1168
|
+
// }
|
|
1169
|
+
// ---------------------------------------------------------------------------
|
|
1170
|
+
export function decodeMapShardGroupResponse(data) {
|
|
1171
|
+
const shardResults = [];
|
|
1172
|
+
let pos = 0;
|
|
1173
|
+
while (pos < data.length) {
|
|
1174
|
+
const { value: tag, n: tn } = readVarint(data, pos);
|
|
1175
|
+
pos += tn;
|
|
1176
|
+
const fn = Number(tag >> 3n);
|
|
1177
|
+
const wt = Number(tag & 7n);
|
|
1178
|
+
if (fn === 2 && wt === 2) {
|
|
1179
|
+
const { slice, nextPos } = readLengthDelimited(data, pos);
|
|
1180
|
+
pos = nextPos;
|
|
1181
|
+
shardResults.push(decodeShardQueryResponse(slice));
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
pos = skipField(data, pos, wt);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return { shard_results: shardResults };
|
|
1188
|
+
}
|
|
692
1189
|
export function encodeApplicationMetrics(metrics) {
|
|
693
1190
|
let buf = new Uint8Array(0);
|
|
694
1191
|
const counterMetrics = metrics.counter_metrics;
|