@yarkivaev/scada 2.6.3 → 2.6.4
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
CHANGED
|
@@ -754,3 +754,25 @@ No observation is merged, sampled or discarded by batching. An `accept()` promis
|
|
|
754
754
|
The positive safe-integer `maxInFlight` option defaults to32. A drain initiates at most that many publications concurrently, in stored order per logical AMQP session. All concurrent writers await the same session opening; one mandatory return does not retire independent confirms. Receipt admission and serialized publication bytes are reserved before network publication, then the receipt is queued only after its individual mandatory confirmation. The retained publication bytes count toward `maxPendingBytes`, separately from receipt mutation bytes counted toward the group byte limit. Confirmed receipts accumulate in a bounded window; `drain()` counts them delivered only after their FULL commit. Graceful close rejects new source submissions, flushes existing submissions, waits for the active drain and its receipts, then closes sessions and persistence. Caller write deadlines abort the actual AMQP writer and retire its session. A caller timeout alone does not release a publication slot or its prospective ACK reservation; late actual success still commits its receipt, and late callbacks from an aborted AMQP generation cannot ACK a retry. A custom factory that ignores both AbortSignal and stop remains fenced and bounded until actual settlement. Close fails after its bounded session wait and retains spool ownership if that work cannot quiesce; retry close after settlement. The existing crash-after-confirm/before-local-receipt replay contract remains unchanged.
|
|
755
755
|
|
|
756
756
|
Healthy full drain pages with durable progress continue on subsequent event-loop turns; after four pages the scheduler pauses 25 ms. Failed, empty or zero-progress pages back off 1s. This removes the former 100-event/s scheduling ceiling without spinning on an offline recipient. Actual append and online catch-up throughput still require qualification on the target filesystem; a serial producer awaiting every individual acceptance cannot benefit from concurrent group formation.
|
|
757
|
+
|
|
758
|
+
### Bounded native history commits
|
|
759
|
+
|
|
760
|
+
Native history receivers advertise `nativeTailProtocol: preserve-known-suffix-v1`
|
|
761
|
+
on configuration. Workers must negotiate this before starting. A computed
|
|
762
|
+
terminal anchor must not clip an existing segment whose known end lies beyond
|
|
763
|
+
the observed page. An unchanged exterior anchor can be omitted entirely.
|
|
764
|
+
|
|
765
|
+
An exterior row requires `context.nativeTailMode` with that protocol and a
|
|
766
|
+
`preserveSuffix` object identifying a current segment by `kind`, `name`,
|
|
767
|
+
`start_time`, and `end_time`. Under the existing context revision lock, the
|
|
768
|
+
receiver checks its class, extent and current ownership. Archive-only rows
|
|
769
|
+
cannot justify exterior changes. Changing a current segment inside the page
|
|
770
|
+
must retain any unobserved suffix, potentially as a piece starting one
|
|
771
|
+
millisecond after the page end; unseen cut collisions fail atomically.
|
|
772
|
+
Conservative page-boundary cuts remain protected, so a paged transition can
|
|
773
|
+
leave additional adjacent same-class pieces. No new exterior observations or
|
|
774
|
+
classes are inferred. A rejected commit leaves both projection and work intact.
|
|
775
|
+
|
|
776
|
+
Applicable children carry operator metadata and `consumed`; existing rows keep
|
|
777
|
+
their stored consumed state. This native protocol is separate from the staged
|
|
778
|
+
stateful correction protocol used with external raw observation stores.
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import nativeHistoryBounds, {nativeTailProtocol} from './historyNativeBounds.js';
|
|
1
2
|
import retainMetricReceipts from '../../ingest/db/retainMetricReceipts.js';
|
|
2
3
|
import historyContext from './historyContext.js';
|
|
3
4
|
import historyAdmission, {assertHistoryReady} from './historyAdmission.js';
|
|
@@ -88,8 +89,12 @@ function commit(pool, machine, workId, segments, {base, observationSource,timeSc
|
|
|
88
89
|
if (segments.length && !base?.revision) { throw new TypeError('History context revision required'); }
|
|
89
90
|
if (observationSource) { await assertHistoryReady(client,machine); }
|
|
90
91
|
const latest = base?.revision ? await unchanged(client, machine, base, {observationSource,timeScale}) : null;
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const exteriors = nativeHistoryBounds(segments, latest, base, timeScale);
|
|
93
|
+
for (const item of exteriors) {
|
|
94
|
+
// An unseen existing cut must never be overwritten by a new exterior piece.
|
|
95
|
+
// eslint-disable-next-line no-await-in-loop
|
|
96
|
+
const conflict = await client.query('SELECT 1 FROM segments WHERE machine=$1 AND kind=$2 AND start_time=$3', [machine, item.kind ?? 'phase', item.start_time]);
|
|
97
|
+
if (conflict.rowCount) { throw new TypeError('History suffix collides with a cut outside the observed page'); }
|
|
93
98
|
}
|
|
94
99
|
if(base?.replace){
|
|
95
100
|
const next=await historyCorrection(client,machine,work.rows[0],segments,{base,context:latest,timeScale});
|
|
@@ -103,8 +108,8 @@ function commit(pool, machine, workId, segments, {base, observationSource,timeSc
|
|
|
103
108
|
for (const item of segments) {
|
|
104
109
|
// Only computed fields change. User cuts/labels must be applied by caller before commit.
|
|
105
110
|
// eslint-disable-next-line no-await-in-loop
|
|
106
|
-
await client.query(`INSERT INTO segments(machine,kind,name,start_time,end_time,duration,options,tags,properties,resolved)
|
|
107
|
-
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) ON CONFLICT(machine,kind,start_time) DO UPDATE
|
|
111
|
+
await client.query(`INSERT INTO segments(machine,kind,name,start_time,end_time,duration,options,tags,properties,resolved,consumed)
|
|
112
|
+
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) ON CONFLICT(machine,kind,start_time) DO UPDATE
|
|
108
113
|
SET name=EXCLUDED.name,end_time=EXCLUDED.end_time,duration=EXCLUDED.duration,options=EXCLUDED.options,updated_at=clock_timestamp(),
|
|
109
114
|
tags=CASE WHEN segments.name=EXCLUDED.name THEN segments.tags ELSE EXCLUDED.tags END,
|
|
110
115
|
properties=CASE WHEN segments.name=EXCLUDED.name THEN segments.properties ELSE EXCLUDED.properties END,
|
|
@@ -112,7 +117,7 @@ function commit(pool, machine, workId, segments, {base, observationSource,timeSc
|
|
|
112
117
|
[machine, item.kind ?? 'phase', item.name, item.start_time, item.end_time, item.duration,
|
|
113
118
|
typeof item.options === 'string' ? item.options : JSON.stringify(item.options ?? null),
|
|
114
119
|
typeof item.tags === 'string' ? item.tags : JSON.stringify(item.tags ?? null),
|
|
115
|
-
typeof item.properties === 'string' ? item.properties : JSON.stringify(item.properties ?? null), item.resolved ?? true]);
|
|
120
|
+
typeof item.properties === 'string' ? item.properties : JSON.stringify(item.properties ?? null), item.resolved ?? true, item.consumed ?? true]);
|
|
116
121
|
}
|
|
117
122
|
const converged=await saveCheckpoint(client,machine,base?.checkpoint,latest);
|
|
118
123
|
await advance(client,machine,workId,converged ? {next:null} : latest?.context.page);
|
|
@@ -134,7 +139,7 @@ export default function historyPg(pool, { retentionDays = 30, now = Date.now, ob
|
|
|
134
139
|
const source=observationSource?.(client);
|
|
135
140
|
const result=await historyConfigure(client,machine,topics,bucketMs*timeScale,{retentionDays,observations:source});
|
|
136
141
|
await configureClassifier(client,machine,classifierKey,source);
|
|
137
|
-
return {...result,...((timeScale!==1 || classifierKey) && {timeScale}),...(classifierKey && {classifierProtocol:historyProtocol})};
|
|
142
|
+
return {...result,...((timeScale!==1 || classifierKey) && {timeScale}),...(!classifierKey && {nativeTailProtocol}),...(classifierKey && {classifierProtocol:historyProtocol})};
|
|
138
143
|
},true);
|
|
139
144
|
},
|
|
140
145
|
async purge() {
|
|
@@ -50,7 +50,7 @@ export default async function historyContext(pool,machine,from,until,{padding,cu
|
|
|
50
50
|
const annotations = await pool.query(`SELECT a.kind,a.name,a.start_time,a.end_time,a.duration,
|
|
51
51
|
CASE WHEN s.machine IS NOT NULL THEN s.tags ELSE a.tags END AS tags,
|
|
52
52
|
CASE WHEN s.machine IS NOT NULL THEN s.properties ELSE a.properties END AS properties,
|
|
53
|
-
CASE WHEN s.machine IS NOT NULL THEN s.resolved ELSE a.resolved END AS resolved
|
|
53
|
+
CASE WHEN s.machine IS NOT NULL THEN s.resolved ELSE a.resolved END AS resolved,CASE WHEN s.machine IS NOT NULL THEN s.consumed ELSE NULL END AS consumed
|
|
54
54
|
FROM history_annotations a LEFT JOIN segments s ON s.machine=a.machine AND s.kind=a.kind AND s.start_time=a.start_time AND s.name=a.name
|
|
55
55
|
WHERE a.machine=$1 AND a.kind='phase' AND a.start_time<=$3 AND a.end_time>=$2
|
|
56
56
|
AND (COALESCE(a.tags,'') NOT IN ('','null','[]') OR COALESCE(a.properties,'') NOT IN ('','null','{}')) ORDER BY a.start_time,a.name LIMIT 10001`,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const nativeTailProtocol = 'preserve-known-suffix-v1';
|
|
2
|
+
function instant(value) { return new Date(value).getTime(); }
|
|
3
|
+
function kind(row) { return row.kind ?? 'phase'; }
|
|
4
|
+
function identity(left, right) {
|
|
5
|
+
return kind(left) === kind(right) && left.name === right.name
|
|
6
|
+
&& instant(left.start_time) === instant(right.start_time) && instant(left.end_time) === instant(right.end_time);
|
|
7
|
+
}
|
|
8
|
+
function provedOwner(item, latest, base, until) {
|
|
9
|
+
const start = instant(item.start_time); const end = instant(item.end_time);
|
|
10
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start > end) { throw new TypeError('Invalid bounded history segment'); }
|
|
11
|
+
if (end <= until) { return null; }
|
|
12
|
+
const owner = base.nativeTailMode === nativeTailProtocol && (latest.segments ?? []).find(row => {
|
|
13
|
+
return item.preserveSuffix && identity(row, item.preserveSuffix)
|
|
14
|
+
&& kind(row) === kind(item) && row.name === item.name
|
|
15
|
+
&& instant(row.start_time) <= until && instant(row.start_time) <= start
|
|
16
|
+
&& start <= until + 1 && instant(row.end_time) === end;
|
|
17
|
+
});
|
|
18
|
+
if (!owner) { throw new TypeError('Segment extends beyond bounded history page without a current suffix proof'); }
|
|
19
|
+
return owner;
|
|
20
|
+
}
|
|
21
|
+
function retainExterior(segments, current, owners, until) {
|
|
22
|
+
for (const owner of current) {
|
|
23
|
+
const change = segments.find(item => { return kind(item) === kind(owner) && instant(item.start_time) === instant(owner.start_time); });
|
|
24
|
+
if (change && instant(owner.end_time) > until
|
|
25
|
+
&& (change.name !== owner.name || instant(change.end_time) < instant(owner.end_time))) {
|
|
26
|
+
const retained = [...owners].some(([item, proof]) => {
|
|
27
|
+
return identity(proof, owner) && instant(item.start_time) <= until + 1;
|
|
28
|
+
});
|
|
29
|
+
if (!retained) { throw new TypeError('Known history tail would be truncated; upgrade the history worker'); }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A bounded native correction may carry existing exterior, never classify new exterior. */
|
|
34
|
+
export default function nativeHistoryBounds(segments, latest, base, timeScale) {
|
|
35
|
+
if (!latest) { return []; }
|
|
36
|
+
const until = Math.round(latest.context.page.until / timeScale);
|
|
37
|
+
if (base.nativeTailMode !== undefined && (base.nativeTailMode !== nativeTailProtocol || base.replace)) {
|
|
38
|
+
throw new TypeError('Unsupported native history suffix protocol');
|
|
39
|
+
}
|
|
40
|
+
const owners = new Map(segments.map(item => { return [item, provedOwner(item, latest, base, until)]; }).filter(([, owner]) => { return owner; }));
|
|
41
|
+
if (!base.replace) { retainExterior(segments, latest.segments ?? [], owners, until); }
|
|
42
|
+
return [...owners.keys()].filter(item => { return instant(item.start_time) > until; });
|
|
43
|
+
}
|