@sentio/runtime 2.59.0-rc.8 → 2.59.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/lib/chunk-JPHAFAK7.js +38 -0
- package/lib/{chunk-GD7EL7GH.js.map → chunk-JPHAFAK7.js.map} +1 -1
- package/lib/chunk-UWKXTTDA.js +116 -0
- package/lib/{chunk-J23VJQSB.js.map → chunk-UWKXTTDA.js.map} +1 -1
- package/lib/chunk-VUN3TGG5.js +26 -0
- package/lib/chunk-VUN3TGG5.js.map +1 -0
- package/lib/chunk-WHWNPZZ3.js +3 -0
- package/lib/{chunk-6XHWJ2VS.js.map → chunk-WHWNPZZ3.js.map} +1 -1
- package/lib/index.d.ts +193 -3
- package/lib/index.js +1 -70
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +21 -26592
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.d.ts +5 -6
- package/lib/service-worker.js +2 -128
- package/lib/service-worker.js.map +1 -1
- package/lib/test-processor.test.js.map +1 -1
- package/package.json +1 -1
- package/src/db-context.ts +2 -4
- package/src/full-service.ts +59 -13
- package/src/gen/processor/protos/processor.ts +1077 -159
- package/src/gen/service/common/protos/common.ts +17 -0
- package/src/metrics.ts +8 -4
- package/src/plugin.ts +24 -0
- package/src/processor-runner.ts +10 -3
- package/src/service-manager.ts +72 -106
- package/src/service-worker.ts +49 -60
- package/src/service.ts +89 -46
- package/src/utils.ts +20 -4
- package/lib/chunk-3T4PWGQU.js +0 -23070
- package/lib/chunk-3T4PWGQU.js.map +0 -1
- package/lib/chunk-6XHWJ2VS.js +0 -92
- package/lib/chunk-GD7EL7GH.js +0 -10975
- package/lib/chunk-J23VJQSB.js +0 -59833
package/src/service.ts
CHANGED
@@ -56,14 +56,17 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
56
56
|
private readonly enablePreprocess: boolean
|
57
57
|
|
58
58
|
private preparedData: PreparedData | undefined
|
59
|
+
readonly enablePartition: boolean
|
59
60
|
|
60
|
-
constructor(loader: () => Promise<any>, shutdownHandler?: () => void) {
|
61
|
+
constructor(loader: () => Promise<any>, options?: any, shutdownHandler?: () => void) {
|
61
62
|
this.loader = loader
|
62
63
|
this.shutdownHandler = shutdownHandler
|
63
64
|
|
64
65
|
this.enablePreprocess = process.env['ENABLE_PREPROCESS']
|
65
66
|
? process.env['ENABLE_PREPROCESS'].toLowerCase() == 'true'
|
66
67
|
: false
|
68
|
+
|
69
|
+
this.enablePartition = options?.['enable-partition'] == true
|
67
70
|
}
|
68
71
|
|
69
72
|
async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {
|
@@ -413,65 +416,105 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
413
416
|
yield* from(subject).pipe(withAbort(context.signal))
|
414
417
|
}
|
415
418
|
|
419
|
+
private dbContexts = new Contexts()
|
420
|
+
|
416
421
|
protected async handleRequests(
|
417
422
|
requests: AsyncIterable<ProcessStreamRequest>,
|
418
423
|
subject: Subject<DeepPartial<ProcessStreamResponse>>
|
419
424
|
) {
|
420
|
-
|
425
|
+
let lastBinding: DataBinding | undefined = undefined
|
421
426
|
for await (const request of requests) {
|
422
427
|
try {
|
423
|
-
// console.
|
428
|
+
// console.log('received request:', request, 'lastBinding:', lastBinding)
|
424
429
|
if (request.binding) {
|
425
|
-
|
426
|
-
|
427
|
-
// Adjust binding will make some request become invalid by setting UNKNOWN HandlerType
|
428
|
-
// for older SDK version, so we just return empty result for them here
|
429
|
-
if (request.binding.handlerType === HandlerType.UNKNOWN) {
|
430
|
-
subject.next({
|
431
|
-
processId: request.processId,
|
432
|
-
result: ProcessResult.create()
|
433
|
-
})
|
434
|
-
continue
|
435
|
-
}
|
436
|
-
|
437
|
-
const binding = request.binding
|
438
|
-
const dbContext = contexts.new(request.processId, subject)
|
439
|
-
const start = Date.now()
|
440
|
-
PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext)
|
441
|
-
.then(async (result) => {
|
442
|
-
// await all pending db requests
|
443
|
-
await dbContext.awaitPendings()
|
444
|
-
subject.next({
|
445
|
-
result,
|
446
|
-
processId: request.processId
|
447
|
-
})
|
448
|
-
recordRuntimeInfo(result, binding.handlerType)
|
449
|
-
})
|
450
|
-
.catch((e) => {
|
451
|
-
console.debug(e)
|
452
|
-
dbContext.error(request.processId, e)
|
453
|
-
process_binding_error.add(1)
|
454
|
-
})
|
455
|
-
.finally(() => {
|
456
|
-
const cost = Date.now() - start
|
457
|
-
process_binding_time.add(cost)
|
458
|
-
contexts.delete(request.processId)
|
459
|
-
})
|
460
|
-
}
|
461
|
-
if (request.dbResult) {
|
462
|
-
const dbContext = contexts.get(request.processId)
|
463
|
-
try {
|
464
|
-
dbContext?.result(request.dbResult)
|
465
|
-
} catch (e) {
|
466
|
-
subject.error(new Error('db result error, process should stop'))
|
467
|
-
}
|
430
|
+
lastBinding = request.binding
|
468
431
|
}
|
432
|
+
this.handleRequest(request, lastBinding, subject)
|
469
433
|
} catch (e) {
|
470
434
|
// should not happen
|
471
435
|
console.error('unexpect error during handle loop', e)
|
472
436
|
}
|
473
437
|
}
|
474
438
|
}
|
439
|
+
|
440
|
+
async handleRequest(
|
441
|
+
request: ProcessStreamRequest,
|
442
|
+
lastBinding: DataBinding | undefined,
|
443
|
+
subject: Subject<DeepPartial<ProcessStreamResponse>>
|
444
|
+
) {
|
445
|
+
if (request.binding) {
|
446
|
+
process_binding_count.add(1)
|
447
|
+
|
448
|
+
// Adjust binding will make some request become invalid by setting UNKNOWN HandlerType
|
449
|
+
// for older SDK version, so we just return empty result for them here
|
450
|
+
if (request.binding.handlerType === HandlerType.UNKNOWN) {
|
451
|
+
subject.next({
|
452
|
+
processId: request.processId,
|
453
|
+
result: ProcessResult.create()
|
454
|
+
})
|
455
|
+
return
|
456
|
+
}
|
457
|
+
|
458
|
+
if (this.enablePartition) {
|
459
|
+
try {
|
460
|
+
const partitions = await PluginManager.INSTANCE.partition(request.binding)
|
461
|
+
subject.next({
|
462
|
+
processId: request.processId,
|
463
|
+
partitions
|
464
|
+
})
|
465
|
+
} catch (e) {
|
466
|
+
console.error('Partition error:', e)
|
467
|
+
subject.error(new Error('Partition error: ' + errorString(e)))
|
468
|
+
return
|
469
|
+
}
|
470
|
+
} else {
|
471
|
+
this.startProcess(request.processId, request.binding, subject)
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
475
|
+
if (request.start) {
|
476
|
+
if (!lastBinding) {
|
477
|
+
console.error('start request received without binding')
|
478
|
+
subject.error(new Error('start request received without binding'))
|
479
|
+
return
|
480
|
+
}
|
481
|
+
this.startProcess(request.processId, lastBinding, subject)
|
482
|
+
}
|
483
|
+
|
484
|
+
if (request.dbResult) {
|
485
|
+
const dbContext = this.dbContexts.get(request.processId)
|
486
|
+
try {
|
487
|
+
dbContext?.result(request.dbResult)
|
488
|
+
} catch (e) {
|
489
|
+
subject.error(new Error('db result error, process should stop'))
|
490
|
+
}
|
491
|
+
}
|
492
|
+
}
|
493
|
+
|
494
|
+
private startProcess(processId: number, binding: DataBinding, subject: Subject<DeepPartial<ProcessStreamResponse>>) {
|
495
|
+
const dbContext = this.dbContexts.new(processId, subject)
|
496
|
+
const start = Date.now()
|
497
|
+
PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext)
|
498
|
+
.then(async (result) => {
|
499
|
+
// await all pending db requests
|
500
|
+
await dbContext.awaitPendings()
|
501
|
+
subject.next({
|
502
|
+
result,
|
503
|
+
processId: processId
|
504
|
+
})
|
505
|
+
recordRuntimeInfo(result, binding.handlerType)
|
506
|
+
})
|
507
|
+
.catch((e) => {
|
508
|
+
console.error(e)
|
509
|
+
dbContext.error(processId, e)
|
510
|
+
process_binding_error.add(1)
|
511
|
+
})
|
512
|
+
.finally(() => {
|
513
|
+
const cost = Date.now() - start
|
514
|
+
process_binding_time.add(cost)
|
515
|
+
this.dbContexts.delete(processId)
|
516
|
+
})
|
517
|
+
}
|
475
518
|
}
|
476
519
|
|
477
520
|
export function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
package/src/utils.ts
CHANGED
@@ -10,12 +10,22 @@ export function mergeProcessResults(results: ProcessResult[]): Required<ProcessR
|
|
10
10
|
...ProcessResultFull.create(),
|
11
11
|
states: StateResult.create()
|
12
12
|
}
|
13
|
+
return mergeProcessResultsInPlace(res, results)
|
14
|
+
}
|
13
15
|
|
16
|
+
export function mergeProcessResultsInPlace(
|
17
|
+
res: ProcessResult,
|
18
|
+
results: ProcessResult[]
|
19
|
+
): Required<ProcessResult, 'states'> {
|
20
|
+
res.states = res.states || StateResult.create()
|
14
21
|
for (const r of results) {
|
15
|
-
|
16
|
-
|
17
|
-
res.
|
18
|
-
res.
|
22
|
+
// not using spread operator since it puts all element on the stack
|
23
|
+
// cause maximum call stack size exceeded error if it's a large array
|
24
|
+
mergeArrayInPlace(res.counters, r.counters)
|
25
|
+
mergeArrayInPlace(res.gauges, r.gauges)
|
26
|
+
mergeArrayInPlace(res.events, r.events)
|
27
|
+
mergeArrayInPlace(res.exports, r.exports)
|
28
|
+
mergeArrayInPlace(res.timeseriesResult, r.timeseriesResult)
|
19
29
|
res.states = {
|
20
30
|
configUpdated: res.states?.configUpdated || r.states?.configUpdated || false
|
21
31
|
}
|
@@ -23,6 +33,12 @@ export function mergeProcessResults(results: ProcessResult[]): Required<ProcessR
|
|
23
33
|
return res
|
24
34
|
}
|
25
35
|
|
36
|
+
function mergeArrayInPlace<T>(dst: T[], src: T[]) {
|
37
|
+
for (const r of src) {
|
38
|
+
dst.push(r)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
26
42
|
export function errorString(e: Error): string {
|
27
43
|
return e.message + '\n' + e.stack
|
28
44
|
}
|