@webex/plugin-meetings 3.12.0-next.11 → 3.12.0-next.110
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/AGENTS.md +9 -0
- package/dist/aiEnableRequest/index.js +15 -2
- package/dist/aiEnableRequest/index.js.map +1 -1
- package/dist/breakouts/breakout.js +8 -3
- package/dist/breakouts/breakout.js.map +1 -1
- package/dist/breakouts/events.js +29 -14
- package/dist/breakouts/events.js.map +1 -1
- package/dist/breakouts/index.js +90 -3
- package/dist/breakouts/index.js.map +1 -1
- package/dist/common/errors/webex-errors.js +49 -5
- package/dist/common/errors/webex-errors.js.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/constants.js +37 -10
- package/dist/constants.js.map +1 -1
- package/dist/controls-options-manager/constants.js +11 -1
- package/dist/controls-options-manager/constants.js.map +1 -1
- package/dist/controls-options-manager/index.js +67 -29
- package/dist/controls-options-manager/index.js.map +1 -1
- package/dist/controls-options-manager/util.js +91 -0
- package/dist/controls-options-manager/util.js.map +1 -1
- package/dist/hashTree/constants.js +4 -1
- package/dist/hashTree/constants.js.map +1 -1
- package/dist/hashTree/hashTreeParser.js +1003 -393
- package/dist/hashTree/hashTreeParser.js.map +1 -1
- package/dist/hashTree/utils.js +20 -0
- package/dist/hashTree/utils.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/interceptors/dataChannelAuthToken.js +75 -15
- package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
- package/dist/interceptors/locusRetry.js +23 -8
- package/dist/interceptors/locusRetry.js.map +1 -1
- package/dist/interpretation/index.js +10 -1
- package/dist/interpretation/index.js.map +1 -1
- package/dist/interpretation/interpretation.types.js +7 -0
- package/dist/interpretation/interpretation.types.js.map +1 -0
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/locus-info/controlsUtils.js +4 -1
- package/dist/locus-info/controlsUtils.js.map +1 -1
- package/dist/locus-info/index.js +406 -121
- package/dist/locus-info/index.js.map +1 -1
- package/dist/locus-info/infoUtils.js +36 -5
- package/dist/locus-info/infoUtils.js.map +1 -1
- package/dist/locus-info/types.js +19 -0
- package/dist/locus-info/types.js.map +1 -1
- package/dist/media/MediaConnectionAwaiter.js +15 -2
- package/dist/media/MediaConnectionAwaiter.js.map +1 -1
- package/dist/media/index.js +8 -2
- package/dist/media/index.js.map +1 -1
- package/dist/media/properties.js +4 -5
- package/dist/media/properties.js.map +1 -1
- package/dist/meeting/in-meeting-actions.js +5 -1
- package/dist/meeting/in-meeting-actions.js.map +1 -1
- package/dist/meeting/index.js +1662 -829
- package/dist/meeting/index.js.map +1 -1
- package/dist/meeting/locusMediaRequest.js +229 -82
- package/dist/meeting/locusMediaRequest.js.map +1 -1
- package/dist/meeting/muteState.js +10 -1
- package/dist/meeting/muteState.js.map +1 -1
- package/dist/meeting/request.js +5 -2
- package/dist/meeting/request.js.map +1 -1
- package/dist/meeting/util.js +34 -2
- package/dist/meeting/util.js.map +1 -1
- package/dist/meeting-info/meeting-info-v2.js +2 -2
- package/dist/meeting-info/meeting-info-v2.js.map +1 -1
- package/dist/meetings/index.js +256 -118
- package/dist/meetings/index.js.map +1 -1
- package/dist/meetings/meetings.types.js +6 -1
- package/dist/meetings/meetings.types.js.map +1 -1
- package/dist/meetings/request.js +39 -0
- package/dist/meetings/request.js.map +1 -1
- package/dist/meetings/util.js +116 -18
- package/dist/meetings/util.js.map +1 -1
- package/dist/member/index.js +10 -0
- package/dist/member/index.js.map +1 -1
- package/dist/member/types.js.map +1 -1
- package/dist/member/util.js +30 -0
- package/dist/member/util.js.map +1 -1
- package/dist/members/index.js +101 -43
- package/dist/members/index.js.map +1 -1
- package/dist/members/util.js +8 -1
- package/dist/members/util.js.map +1 -1
- package/dist/metrics/constants.js +7 -1
- package/dist/metrics/constants.js.map +1 -1
- package/dist/multistream/codec/constants.js +63 -0
- package/dist/multistream/codec/constants.js.map +1 -0
- package/dist/multistream/mediaRequestManager.js +62 -15
- package/dist/multistream/mediaRequestManager.js.map +1 -1
- package/dist/multistream/receiveSlot.js +9 -0
- package/dist/multistream/receiveSlot.js.map +1 -1
- package/dist/reachability/clusterReachability.js.map +1 -1
- package/dist/reachability/index.js +121 -83
- package/dist/reachability/index.js.map +1 -1
- package/dist/reachability/reachability.types.js +2 -0
- package/dist/reachability/reachability.types.js.map +1 -1
- package/dist/reachability/util.js +45 -0
- package/dist/reachability/util.js.map +1 -1
- package/dist/reactions/reactions.type.js.map +1 -1
- package/dist/recording-controller/index.js +1 -3
- package/dist/recording-controller/index.js.map +1 -1
- package/dist/roap/turnDiscovery.js +8 -1
- package/dist/roap/turnDiscovery.js.map +1 -1
- package/dist/types/common/errors/webex-errors.d.ts +32 -2
- package/dist/types/config.d.ts +2 -2
- package/dist/types/constants.d.ts +13 -1
- package/dist/types/controls-options-manager/constants.d.ts +6 -1
- package/dist/types/controls-options-manager/index.d.ts +16 -0
- package/dist/types/hashTree/constants.d.ts +1 -0
- package/dist/types/hashTree/hashTreeParser.d.ts +178 -22
- package/dist/types/hashTree/utils.d.ts +7 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/interceptors/locusRetry.d.ts +4 -4
- package/dist/types/interpretation/interpretation.types.d.ts +10 -0
- package/dist/types/locus-info/index.d.ts +61 -7
- package/dist/types/locus-info/infoUtils.d.ts +8 -0
- package/dist/types/locus-info/types.d.ts +21 -1
- package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
- package/dist/types/media/properties.d.ts +6 -2
- package/dist/types/meeting/in-meeting-actions.d.ts +4 -0
- package/dist/types/meeting/index.d.ts +175 -11
- package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
- package/dist/types/meeting/request.d.ts +1 -0
- package/dist/types/meeting/util.d.ts +9 -0
- package/dist/types/meetings/index.d.ts +38 -18
- package/dist/types/meetings/meetings.types.d.ts +15 -0
- package/dist/types/meetings/request.d.ts +14 -0
- package/dist/types/member/index.d.ts +1 -0
- package/dist/types/member/types.d.ts +1 -0
- package/dist/types/member/util.d.ts +9 -0
- package/dist/types/members/index.d.ts +15 -2
- package/dist/types/members/util.d.ts +1 -5
- package/dist/types/metrics/constants.d.ts +6 -0
- package/dist/types/multistream/codec/constants.d.ts +7 -0
- package/dist/types/multistream/mediaRequestManager.d.ts +22 -5
- package/dist/types/reachability/clusterReachability.d.ts +3 -3
- package/dist/types/reachability/index.d.ts +10 -3
- package/dist/types/reachability/reachability.types.d.ts +7 -0
- package/dist/types/reachability/util.d.ts +17 -0
- package/dist/types/reactions/reactions.type.d.ts +3 -0
- package/dist/webinar/index.js +307 -161
- package/dist/webinar/index.js.map +1 -1
- package/package.json +23 -23
- package/src/aiEnableRequest/index.ts +16 -0
- package/src/breakouts/breakout.ts +3 -1
- package/src/breakouts/events.ts +33 -11
- package/src/breakouts/index.ts +110 -1
- package/src/common/errors/webex-errors.ts +50 -3
- package/src/config.ts +2 -2
- package/src/constants.ts +21 -3
- package/src/controls-options-manager/constants.ts +14 -1
- package/src/controls-options-manager/index.ts +87 -28
- package/src/controls-options-manager/util.ts +81 -1
- package/src/hashTree/constants.ts +7 -0
- package/src/hashTree/hashTreeParser.ts +752 -192
- package/src/hashTree/utils.ts +19 -0
- package/src/index.ts +6 -0
- package/src/interceptors/dataChannelAuthToken.ts +88 -12
- package/src/interceptors/locusRetry.ts +25 -4
- package/src/interpretation/index.ts +27 -9
- package/src/interpretation/interpretation.types.ts +11 -0
- package/src/locus-info/controlsUtils.ts +3 -1
- package/src/locus-info/index.ts +412 -130
- package/src/locus-info/infoUtils.ts +41 -6
- package/src/locus-info/types.ts +25 -1
- package/src/media/MediaConnectionAwaiter.ts +21 -4
- package/src/media/index.ts +10 -1
- package/src/media/properties.ts +8 -3
- package/src/meeting/in-meeting-actions.ts +8 -0
- package/src/meeting/index.ts +913 -111
- package/src/meeting/locusMediaRequest.ts +106 -6
- package/src/meeting/muteState.ts +10 -1
- package/src/meeting/request.ts +11 -0
- package/src/meeting/util.ts +46 -5
- package/src/meeting-info/meeting-info-v2.ts +4 -2
- package/src/meetings/index.ts +168 -79
- package/src/meetings/meetings.types.ts +19 -0
- package/src/meetings/request.ts +43 -0
- package/src/meetings/util.ts +117 -4
- package/src/member/index.ts +10 -0
- package/src/member/types.ts +1 -0
- package/src/member/util.ts +29 -0
- package/src/members/index.ts +70 -7
- package/src/members/util.ts +12 -4
- package/src/metrics/constants.ts +6 -0
- package/src/multistream/codec/constants.ts +58 -0
- package/src/multistream/mediaRequestManager.ts +119 -28
- package/src/multistream/receiveSlot.ts +18 -0
- package/src/reachability/clusterReachability.ts +3 -2
- package/src/reachability/index.ts +47 -16
- package/src/reachability/reachability.types.ts +11 -0
- package/src/reachability/util.ts +36 -0
- package/src/reactions/reactions.type.ts +3 -0
- package/src/recording-controller/index.ts +1 -2
- package/src/roap/turnDiscovery.ts +9 -1
- package/src/webinar/index.ts +216 -38
- package/test/unit/spec/aiEnableRequest/index.ts +86 -0
- package/test/unit/spec/breakouts/breakout.ts +9 -3
- package/test/unit/spec/breakouts/events.ts +120 -2
- package/test/unit/spec/breakouts/index.ts +191 -2
- package/test/unit/spec/common/errors/webex-errors.ts +78 -0
- package/test/unit/spec/controls-options-manager/index.js +244 -29
- package/test/unit/spec/controls-options-manager/util.js +165 -0
- package/test/unit/spec/hashTree/hashTreeParser.ts +2110 -170
- package/test/unit/spec/hashTree/utils.ts +37 -0
- package/test/unit/spec/interceptors/dataChannelAuthToken.ts +196 -0
- package/test/unit/spec/interceptors/locusRetry.ts +205 -4
- package/test/unit/spec/interpretation/index.ts +26 -4
- package/test/unit/spec/locus-info/controlsUtils.js +172 -57
- package/test/unit/spec/locus-info/index.js +643 -63
- package/test/unit/spec/locus-info/infoUtils.js +184 -1
- package/test/unit/spec/media/MediaConnectionAwaiter.ts +55 -0
- package/test/unit/spec/media/index.ts +92 -0
- package/test/unit/spec/media/properties.ts +23 -23
- package/test/unit/spec/meeting/in-meeting-actions.ts +4 -0
- package/test/unit/spec/meeting/index.js +2711 -183
- package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
- package/test/unit/spec/meeting/muteState.js +81 -0
- package/test/unit/spec/meeting/request.js +12 -0
- package/test/unit/spec/meeting/utils.js +153 -1
- package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
- package/test/unit/spec/meetings/index.js +467 -36
- package/test/unit/spec/meetings/request.js +141 -0
- package/test/unit/spec/meetings/utils.js +402 -51
- package/test/unit/spec/member/index.js +7 -0
- package/test/unit/spec/member/util.js +89 -0
- package/test/unit/spec/members/index.js +216 -0
- package/test/unit/spec/members/request.js +37 -1
- package/test/unit/spec/members/utils.js +63 -0
- package/test/unit/spec/multistream/mediaRequestManager.ts +501 -37
- package/test/unit/spec/reachability/index.ts +128 -46
- package/test/unit/spec/reachability/util.ts +31 -0
- package/test/unit/spec/recording-controller/index.js +9 -8
- package/test/unit/spec/roap/turnDiscovery.ts +20 -0
- package/test/unit/spec/webinar/index.ts +332 -31
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import {cloneDeep, isEmpty, zip} from 'lodash';
|
|
2
|
+
import type {LocusSyncLatencyEventName} from '@webex/internal-plugin-metrics';
|
|
2
3
|
import HashTree, {LeafDataItem} from './hashTree';
|
|
3
4
|
import LoggerProxy from '../common/logs/logger-proxy';
|
|
5
|
+
import Metrics from '../metrics';
|
|
6
|
+
import BEHAVIORAL_METRICS from '../metrics/constants';
|
|
4
7
|
import {Enum, HTTP_VERBS} from '../constants';
|
|
5
|
-
import {DataSetNames, DATA_SET_INIT_PRIORITY, EMPTY_HASH} from './constants';
|
|
8
|
+
import {DataSetNames, DATA_SET_INIT_PRIORITY, EMPTY_HASH, LLM_DATASET_NAMES} from './constants';
|
|
6
9
|
import {ObjectType, HtMeta, HashTreeObject} from './types';
|
|
7
|
-
import {LocusDTO} from '../locus-info/types';
|
|
8
|
-
import {deleteNestedObjectsWithHtMeta, isMetadata, sortByInitPriority} from './utils';
|
|
10
|
+
import {LocusDTO, LocusErrorCodes} from '../locus-info/types';
|
|
11
|
+
import {deleteNestedObjectsWithHtMeta, isMetadata, sleep, sortByInitPriority} from './utils';
|
|
12
|
+
|
|
13
|
+
export enum SyncAllBackoffType {
|
|
14
|
+
NONE = 'none',
|
|
15
|
+
ONLY_LLM = 'onlyLLM',
|
|
16
|
+
ALL = 'all',
|
|
17
|
+
}
|
|
9
18
|
|
|
10
19
|
export interface DataSet {
|
|
11
20
|
url: string;
|
|
@@ -18,10 +27,12 @@ export interface DataSet {
|
|
|
18
27
|
maxMs: number;
|
|
19
28
|
exponent: number;
|
|
20
29
|
};
|
|
30
|
+
heartbeatIntervalMs?: number;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
export interface RootHashMessage {
|
|
24
34
|
dataSets: Array<DataSet>;
|
|
35
|
+
heartbeatIntervalMs?: number;
|
|
25
36
|
}
|
|
26
37
|
export interface HashTreeMessage {
|
|
27
38
|
dataSets: Array<DataSet>;
|
|
@@ -47,25 +58,65 @@ interface InternalDataSet extends DataSet {
|
|
|
47
58
|
hashTree?: HashTree; // set only for visible data sets
|
|
48
59
|
timer?: ReturnType<typeof setTimeout>;
|
|
49
60
|
heartbeatWatchdogTimer?: ReturnType<typeof setTimeout>;
|
|
61
|
+
syncAbortController?: AbortController;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
type WebexRequestMethod = (options: Record<string, any>) => Promise<any>;
|
|
65
|
+
type GenerateTrackingId = () => string | undefined;
|
|
53
66
|
|
|
54
67
|
export const LocusInfoUpdateType = {
|
|
55
68
|
OBJECTS_UPDATED: 'OBJECTS_UPDATED',
|
|
56
69
|
MEETING_ENDED: 'MEETING_ENDED',
|
|
70
|
+
LOCUS_NOT_FOUND: 'LOCUS_NOT_FOUND',
|
|
57
71
|
} as const;
|
|
58
72
|
|
|
59
73
|
export type LocusInfoUpdateType = Enum<typeof LocusInfoUpdateType>;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
|
|
75
|
+
interface LocusUpdatePayloads {
|
|
76
|
+
[LocusInfoUpdateType.OBJECTS_UPDATED]: {updatedObjects: HashTreeObject[]};
|
|
77
|
+
[LocusInfoUpdateType.MEETING_ENDED]: unknown; // No extra data
|
|
78
|
+
[LocusInfoUpdateType.LOCUS_NOT_FOUND]: unknown; // No extra data
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type LocusInfoUpdate = {
|
|
82
|
+
[K in keyof LocusUpdatePayloads]: {
|
|
83
|
+
updateType: K;
|
|
84
|
+
} & LocusUpdatePayloads[K];
|
|
85
|
+
}[keyof LocusUpdatePayloads];
|
|
86
|
+
|
|
87
|
+
export type LocusInfoUpdateCallback = (update: LocusInfoUpdate) => void;
|
|
88
|
+
|
|
89
|
+
export type SyncLatencyTracker = {
|
|
90
|
+
saveLatency: (
|
|
91
|
+
key: 'internal.client.locus.sync.random.backoff',
|
|
92
|
+
value: number,
|
|
93
|
+
options: {
|
|
94
|
+
meetingId: string;
|
|
95
|
+
dataSetName: string;
|
|
64
96
|
}
|
|
65
|
-
|
|
66
|
-
|
|
97
|
+
) => void;
|
|
98
|
+
saveTimestamp: (options: {
|
|
99
|
+
key: LocusSyncLatencyEventName;
|
|
100
|
+
options: {
|
|
101
|
+
meetingId: string;
|
|
102
|
+
dataSetName: string;
|
|
103
|
+
trackingId?: string;
|
|
67
104
|
};
|
|
68
|
-
|
|
105
|
+
}) => void;
|
|
106
|
+
clearLocusSyncLatency: (dataSetName: string, meetingId: string, trackingId?: string) => void;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type HashTreeParserCallbacks = {
|
|
110
|
+
locusInfoUpdateCallback: LocusInfoUpdateCallback;
|
|
111
|
+
syncLatencyTracker?: SyncLatencyTracker;
|
|
112
|
+
generateTrackingId?: GenerateTrackingId;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const SYNC_METRICS_DATA_SETS = [
|
|
116
|
+
DataSetNames.MAIN,
|
|
117
|
+
DataSetNames.ATD_ACTIVE,
|
|
118
|
+
DataSetNames.ATD_UNMUTED,
|
|
119
|
+
];
|
|
69
120
|
|
|
70
121
|
interface LeafInfo {
|
|
71
122
|
type: ObjectType;
|
|
@@ -80,6 +131,13 @@ interface LeafInfo {
|
|
|
80
131
|
*/
|
|
81
132
|
export class MeetingEndedError extends Error {}
|
|
82
133
|
|
|
134
|
+
/**
|
|
135
|
+
* This error is thrown when a 404 is received from Locus hash tree endpoints, indicating that the locus URL
|
|
136
|
+
* is no longer valid (e.g. participant moved to a breakout room, or meeting ended).
|
|
137
|
+
* It's handled internally by HashTreeParser and results in LOCUS_NOT_FOUND being sent up.
|
|
138
|
+
*/
|
|
139
|
+
export class LocusNotFoundError extends Error {}
|
|
140
|
+
|
|
83
141
|
/* Currently Locus always sends Metadata objects only in the "self" dataset.
|
|
84
142
|
* If this ever changes, update all the code that relies on this constant.
|
|
85
143
|
*/
|
|
@@ -98,13 +156,26 @@ class HashTreeParser {
|
|
|
98
156
|
dataSets: Record<string, InternalDataSet> = {};
|
|
99
157
|
visibleDataSetsUrl: string; // url from which we can get info about all data sets
|
|
100
158
|
webexRequest: WebexRequestMethod;
|
|
101
|
-
|
|
159
|
+
private callbacks: HashTreeParserCallbacks;
|
|
160
|
+
private syncLatencyMeetingId: string;
|
|
102
161
|
visibleDataSets: VisibleDataSetInfo[];
|
|
103
162
|
debugId: string;
|
|
104
|
-
heartbeatIntervalMs?: number;
|
|
105
163
|
private excludedDataSets: string[];
|
|
106
164
|
state: 'active' | 'stopped';
|
|
107
|
-
|
|
165
|
+
private syncQueue: Array<{
|
|
166
|
+
dataSetName: string;
|
|
167
|
+
reason: string;
|
|
168
|
+
isInitialization?: boolean;
|
|
169
|
+
}> = [];
|
|
170
|
+
|
|
171
|
+
private isSyncInProgress = false;
|
|
172
|
+
// tracks whether syncAllDatasets is currently in its backoff delay phase and with what scope
|
|
173
|
+
private syncAllBackoffType: SyncAllBackoffType = SyncAllBackoffType.NONE;
|
|
174
|
+
// datasets that received messages during the syncAllDatasets backoff sleep and should be skipped
|
|
175
|
+
private dataSetsSyncedDuringBackoff: Set<string> = new Set();
|
|
176
|
+
private syncQueueProcessingPromise: Promise<void> = Promise.resolve();
|
|
177
|
+
// top-level heartbeat interval from the most recent message, used as fallback when dataset-level value is missing
|
|
178
|
+
private topLevelHeartbeatIntervalMs?: number;
|
|
108
179
|
/**
|
|
109
180
|
* Constructor for HashTreeParser
|
|
110
181
|
* @param {Object} options
|
|
@@ -117,15 +188,17 @@ class HashTreeParser {
|
|
|
117
188
|
};
|
|
118
189
|
metadata: Metadata | null;
|
|
119
190
|
webexRequest: WebexRequestMethod;
|
|
120
|
-
|
|
191
|
+
callbacks: HashTreeParserCallbacks;
|
|
121
192
|
debugId: string;
|
|
122
193
|
excludedDataSets?: string[];
|
|
194
|
+
syncLatencyMeetingId: string;
|
|
123
195
|
}) {
|
|
124
196
|
const {dataSets, locus} = options.initialLocus; // extract dataSets from initialLocus
|
|
125
197
|
|
|
126
198
|
this.debugId = options.debugId;
|
|
127
199
|
this.webexRequest = options.webexRequest;
|
|
128
|
-
this.
|
|
200
|
+
this.callbacks = options.callbacks;
|
|
201
|
+
this.syncLatencyMeetingId = options.syncLatencyMeetingId;
|
|
129
202
|
this.excludedDataSets = options.excludedDataSets || [];
|
|
130
203
|
this.visibleDataSetsUrl = locus?.links?.resources?.visibleDataSets?.url;
|
|
131
204
|
this.setVisibleDataSets(options.metadata?.visibleDataSets || [], dataSets);
|
|
@@ -229,16 +302,16 @@ class HashTreeParser {
|
|
|
229
302
|
* @param {DataSet} dataSetInfo The new data set to be added
|
|
230
303
|
* @returns {Promise}
|
|
231
304
|
*/
|
|
232
|
-
private initializeNewVisibleDataSet(
|
|
305
|
+
private async initializeNewVisibleDataSet(
|
|
233
306
|
visibleDataSetInfo: VisibleDataSetInfo,
|
|
234
307
|
dataSetInfo: DataSet
|
|
235
|
-
): Promise<
|
|
308
|
+
): Promise<void> {
|
|
236
309
|
if (this.isVisibleDataSet(dataSetInfo.name)) {
|
|
237
310
|
LoggerProxy.logger.info(
|
|
238
311
|
`HashTreeParser#initializeNewVisibleDataSet --> ${this.debugId} Data set "${dataSetInfo.name}" already exists, skipping init`
|
|
239
312
|
);
|
|
240
313
|
|
|
241
|
-
return
|
|
314
|
+
return;
|
|
242
315
|
}
|
|
243
316
|
|
|
244
317
|
LoggerProxy.logger.info(
|
|
@@ -246,7 +319,7 @@ class HashTreeParser {
|
|
|
246
319
|
);
|
|
247
320
|
|
|
248
321
|
if (!this.addToVisibleDataSetsList(visibleDataSetInfo)) {
|
|
249
|
-
return
|
|
322
|
+
return;
|
|
250
323
|
}
|
|
251
324
|
|
|
252
325
|
const hashTree = new HashTree([], dataSetInfo.leafCount);
|
|
@@ -256,51 +329,8 @@ class HashTreeParser {
|
|
|
256
329
|
hashTree,
|
|
257
330
|
};
|
|
258
331
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Sends a special sync request to Locus with all leaves empty - this is a way to get all the data for a given dataset.
|
|
264
|
-
*
|
|
265
|
-
* @param {string} datasetName - name of the dataset for which to send the request
|
|
266
|
-
* @param {string} debugText - text to include in logs
|
|
267
|
-
* @returns {Promise}
|
|
268
|
-
*/
|
|
269
|
-
private sendInitializationSyncRequestToLocus(
|
|
270
|
-
datasetName: string,
|
|
271
|
-
debugText: string
|
|
272
|
-
): Promise<LocusInfoUpdate> {
|
|
273
|
-
const dataset = this.dataSets[datasetName];
|
|
274
|
-
|
|
275
|
-
if (!dataset) {
|
|
276
|
-
LoggerProxy.logger.warn(
|
|
277
|
-
`HashTreeParser#sendInitializationSyncRequestToLocus --> ${this.debugId} No data set found for ${datasetName}, cannot send the request for leaf data`
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
return Promise.resolve({updateType: LocusInfoUpdateType.OBJECTS_UPDATED, updatedObjects: []});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const emptyLeavesData = new Array(dataset.leafCount).fill([]);
|
|
284
|
-
|
|
285
|
-
LoggerProxy.logger.info(
|
|
286
|
-
`HashTreeParser#sendInitializationSyncRequestToLocus --> ${this.debugId} Sending initial sync request to Locus for data set "${datasetName}" with empty leaf data`
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
return this.sendSyncRequestToLocus(this.dataSets[datasetName], emptyLeavesData).then(
|
|
290
|
-
(syncResponse) => {
|
|
291
|
-
if (syncResponse) {
|
|
292
|
-
return {
|
|
293
|
-
updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
|
|
294
|
-
updatedObjects: this.parseMessage(
|
|
295
|
-
syncResponse,
|
|
296
|
-
`via empty leaves /sync API call for ${debugText}`
|
|
297
|
-
),
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return {updateType: LocusInfoUpdateType.OBJECTS_UPDATED, updatedObjects: []};
|
|
302
|
-
}
|
|
303
|
-
);
|
|
332
|
+
this.enqueueSyncForDataset(dataSetInfo.name, 'new visible data set initialization', true);
|
|
333
|
+
await this.syncQueueProcessingPromise;
|
|
304
334
|
}
|
|
305
335
|
|
|
306
336
|
/**
|
|
@@ -388,8 +418,6 @@ class HashTreeParser {
|
|
|
388
418
|
return;
|
|
389
419
|
}
|
|
390
420
|
|
|
391
|
-
const updatedObjects: HashTreeObject[] = [];
|
|
392
|
-
|
|
393
421
|
for (const dataSet of sortByInitPriority(visibleDataSets, DATA_SET_INIT_PRIORITY)) {
|
|
394
422
|
const {name, leafCount, url} = dataSet;
|
|
395
423
|
|
|
@@ -426,19 +454,12 @@ class HashTreeParser {
|
|
|
426
454
|
);
|
|
427
455
|
this.dataSets[name].hashTree = new HashTree([], leafCount);
|
|
428
456
|
|
|
429
|
-
|
|
430
|
-
const data = await this.sendInitializationSyncRequestToLocus(name, debugText);
|
|
431
|
-
|
|
432
|
-
if (data.updateType === LocusInfoUpdateType.OBJECTS_UPDATED) {
|
|
433
|
-
updatedObjects.push(...(data.updatedObjects || []));
|
|
434
|
-
}
|
|
457
|
+
this.enqueueSyncForDataset(name, `initialization sync for ${debugText}`, true);
|
|
435
458
|
}
|
|
436
459
|
}
|
|
437
460
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
updatedObjects,
|
|
441
|
-
});
|
|
461
|
+
// wait for all enqueued initialization syncs to complete
|
|
462
|
+
await this.syncQueueProcessingPromise;
|
|
442
463
|
}
|
|
443
464
|
|
|
444
465
|
/**
|
|
@@ -592,12 +613,40 @@ class HashTreeParser {
|
|
|
592
613
|
)}`
|
|
593
614
|
);
|
|
594
615
|
|
|
616
|
+
this.cancelPendingSyncsForDataSets(dataSets.map((ds) => ds.name));
|
|
617
|
+
|
|
595
618
|
dataSets.forEach((dataSet) => {
|
|
596
619
|
this.updateDataSetInfo(dataSet);
|
|
597
620
|
this.runSyncAlgorithm(dataSet);
|
|
598
621
|
});
|
|
599
622
|
}
|
|
600
623
|
|
|
624
|
+
/**
|
|
625
|
+
* Handles known errors that can happen during syncs
|
|
626
|
+
*
|
|
627
|
+
* @param {any} error - The error to handle
|
|
628
|
+
* @returns {boolean} true if the error was recognized and handled, false otherwise
|
|
629
|
+
*/
|
|
630
|
+
private handleSyncErrors(error: any) {
|
|
631
|
+
if (error instanceof MeetingEndedError) {
|
|
632
|
+
this.callLocusInfoUpdateCallback({
|
|
633
|
+
updateType: LocusInfoUpdateType.MEETING_ENDED,
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
if (error instanceof LocusNotFoundError) {
|
|
639
|
+
this.callLocusInfoUpdateCallback({
|
|
640
|
+
updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND,
|
|
641
|
+
});
|
|
642
|
+
this.stop();
|
|
643
|
+
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
|
|
601
650
|
/**
|
|
602
651
|
* Asynchronously initializes new visible data sets
|
|
603
652
|
*
|
|
@@ -614,11 +663,7 @@ class HashTreeParser {
|
|
|
614
663
|
);
|
|
615
664
|
queueMicrotask(() => {
|
|
616
665
|
this.initializeNewVisibleDataSets(dataSetsRequiringInitialization).catch((error) => {
|
|
617
|
-
if (error
|
|
618
|
-
this.callLocusInfoUpdateCallback({
|
|
619
|
-
updateType: LocusInfoUpdateType.MEETING_ENDED,
|
|
620
|
-
});
|
|
621
|
-
} else {
|
|
666
|
+
if (!this.handleSyncErrors(error)) {
|
|
622
667
|
LoggerProxy.logger.warn(
|
|
623
668
|
`HashTreeParser#queueInitForNewVisibleDataSets --> ${
|
|
624
669
|
this.debugId
|
|
@@ -696,7 +741,14 @@ class HashTreeParser {
|
|
|
696
741
|
|
|
697
742
|
const {dataSets, locus, metadata} = update;
|
|
698
743
|
|
|
744
|
+
LoggerProxy.logger.info(
|
|
745
|
+
`HashTreeParser#handleLocusUpdate --> ${this.debugId} received update with dataSets=${dataSets
|
|
746
|
+
?.map((ds) => ds.name)
|
|
747
|
+
.join(',')} metadata=${metadata ? 'yes' : 'no'}`
|
|
748
|
+
);
|
|
749
|
+
|
|
699
750
|
if (!dataSets) {
|
|
751
|
+
// this happens for example when we handle GET /loci response
|
|
700
752
|
LoggerProxy.logger.info(
|
|
701
753
|
`HashTreeParser#handleLocusUpdate --> ${this.debugId} received hash tree update without dataSets`
|
|
702
754
|
);
|
|
@@ -794,12 +846,25 @@ class HashTreeParser {
|
|
|
794
846
|
maxMs: receivedDataSet.backoff.maxMs,
|
|
795
847
|
exponent: receivedDataSet.backoff.exponent,
|
|
796
848
|
};
|
|
849
|
+
this.dataSets[receivedDataSet.name].heartbeatIntervalMs = receivedDataSet.heartbeatIntervalMs;
|
|
797
850
|
LoggerProxy.logger.info(
|
|
798
851
|
`HashTreeParser#updateDataSetInfo --> ${this.debugId} updated "${receivedDataSet.name}" dataset to version=${receivedDataSet.version}, root=${receivedDataSet.root}`
|
|
799
852
|
);
|
|
800
853
|
}
|
|
801
854
|
}
|
|
802
855
|
|
|
856
|
+
/**
|
|
857
|
+
* Updates the leaf count for a data set, resizing its hash tree accordingly.
|
|
858
|
+
*
|
|
859
|
+
* @param {InternalDataSet} dataSet - The data set to update
|
|
860
|
+
* @param {number} newLeafCount - The new leaf count
|
|
861
|
+
* @returns {void}
|
|
862
|
+
*/
|
|
863
|
+
private updateDataSetLeafCount(dataSet: InternalDataSet, newLeafCount: number): void {
|
|
864
|
+
dataSet.hashTree?.resize(newLeafCount);
|
|
865
|
+
dataSet.leafCount = newLeafCount;
|
|
866
|
+
}
|
|
867
|
+
|
|
803
868
|
/**
|
|
804
869
|
* Checks for changes in the visible data sets based on the updated objects.
|
|
805
870
|
* @param {HashTreeObject[]} updatedObjects - The list of updated hash tree objects.
|
|
@@ -850,6 +915,8 @@ class HashTreeParser {
|
|
|
850
915
|
*/
|
|
851
916
|
private deleteHashTree(dataSetName: string) {
|
|
852
917
|
this.dataSets[dataSetName].hashTree = undefined;
|
|
918
|
+
this.dataSets[dataSetName].syncAbortController?.abort();
|
|
919
|
+
this.dataSets[dataSetName].syncAbortController = undefined;
|
|
853
920
|
|
|
854
921
|
// we also need to stop the timers as there is no hash tree anymore to sync
|
|
855
922
|
if (this.dataSets[dataSetName].timer) {
|
|
@@ -979,9 +1046,7 @@ class HashTreeParser {
|
|
|
979
1046
|
);
|
|
980
1047
|
} else {
|
|
981
1048
|
// eslint-disable-next-line no-await-in-loop
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
this.callLocusInfoUpdateCallback(updates);
|
|
1049
|
+
await this.initializeNewVisibleDataSet(ds, dataSetInfo);
|
|
985
1050
|
}
|
|
986
1051
|
}
|
|
987
1052
|
}
|
|
@@ -1001,19 +1066,33 @@ class HashTreeParser {
|
|
|
1001
1066
|
const {dataSets, visibleDataSetsUrl} = message;
|
|
1002
1067
|
|
|
1003
1068
|
LoggerProxy.logger.info(
|
|
1004
|
-
`HashTreeParser#parseMessage --> ${this.debugId}
|
|
1005
|
-
|
|
1069
|
+
`HashTreeParser#parseMessage --> ${this.debugId} ${
|
|
1070
|
+
debugText || ''
|
|
1071
|
+
} dataSets: ${message.dataSets
|
|
1072
|
+
?.map(({name, version}) => `${name}:${version}`)
|
|
1073
|
+
.join(',')}, elements: ${message.locusStateElements
|
|
1074
|
+
?.map(
|
|
1075
|
+
(el) =>
|
|
1076
|
+
`${el.htMeta.elementId.type}:${el.htMeta.elementId.id}:${el.htMeta.elementId.version}${
|
|
1077
|
+
el.data ? '+' : '-'
|
|
1078
|
+
}`
|
|
1079
|
+
)
|
|
1080
|
+
.join(',')}`
|
|
1006
1081
|
);
|
|
1082
|
+
|
|
1007
1083
|
if (message.locusStateElements?.length === 0) {
|
|
1008
1084
|
LoggerProxy.logger.warn(
|
|
1009
1085
|
`HashTreeParser#parseMessage --> ${this.debugId} got empty locusStateElements!!!`
|
|
1010
1086
|
);
|
|
1011
|
-
|
|
1087
|
+
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS, {
|
|
1088
|
+
debugId: this.debugId,
|
|
1089
|
+
});
|
|
1012
1090
|
}
|
|
1013
1091
|
|
|
1014
1092
|
// first, update our metadata about the datasets with info from the message
|
|
1015
1093
|
this.visibleDataSetsUrl = visibleDataSetsUrl;
|
|
1016
1094
|
dataSets.forEach((dataSet) => this.updateDataSetInfo(dataSet));
|
|
1095
|
+
this.cancelPendingSyncsForDataSets(dataSets.map((ds) => ds.name));
|
|
1017
1096
|
|
|
1018
1097
|
const updatedObjects: HashTreeObject[] = [];
|
|
1019
1098
|
|
|
@@ -1122,9 +1201,10 @@ class HashTreeParser {
|
|
|
1122
1201
|
return;
|
|
1123
1202
|
}
|
|
1124
1203
|
|
|
1125
|
-
if (message.heartbeatIntervalMs) {
|
|
1126
|
-
this.
|
|
1204
|
+
if (message.heartbeatIntervalMs !== undefined) {
|
|
1205
|
+
this.topLevelHeartbeatIntervalMs = message.heartbeatIntervalMs;
|
|
1127
1206
|
}
|
|
1207
|
+
|
|
1128
1208
|
if (this.isEndMessage(message)) {
|
|
1129
1209
|
LoggerProxy.logger.info(
|
|
1130
1210
|
`HashTreeParser#handleMessage --> ${this.debugId} received sentinel END MEETING message`
|
|
@@ -1136,6 +1216,10 @@ class HashTreeParser {
|
|
|
1136
1216
|
this.handleRootHashHeartBeatMessage(message);
|
|
1137
1217
|
this.resetHeartbeatWatchdogs(message.dataSets);
|
|
1138
1218
|
} else {
|
|
1219
|
+
// Completion of the sync latency metric (client.locus.sync.complete) is driven solely from
|
|
1220
|
+
// Meeting#processLocusLLMEvent once the matching LLM message arrives. body-mode syncs return
|
|
1221
|
+
// the locus state elements in the /sync HTTP response body, but per design the CA metric is
|
|
1222
|
+
// emitted only from the LLM message path, so no completion happens here.
|
|
1139
1223
|
const updatedObjects = this.parseMessage(message, debugText);
|
|
1140
1224
|
|
|
1141
1225
|
this.resetHeartbeatWatchdogs(message.dataSets);
|
|
@@ -1146,6 +1230,40 @@ class HashTreeParser {
|
|
|
1146
1230
|
}
|
|
1147
1231
|
}
|
|
1148
1232
|
|
|
1233
|
+
/**
|
|
1234
|
+
* Checks if Locus sync latency metrics should be collected for a dataset.
|
|
1235
|
+
*
|
|
1236
|
+
* @param {string} dataSetName dataset name
|
|
1237
|
+
* @param {boolean} [isInitialization=false] whether this is an initialization sync
|
|
1238
|
+
* @returns {boolean}
|
|
1239
|
+
*/
|
|
1240
|
+
private shouldCollectSyncMetrics(dataSetName: string, isInitialization = false): boolean {
|
|
1241
|
+
return Boolean(
|
|
1242
|
+
this.callbacks.syncLatencyTracker &&
|
|
1243
|
+
!isInitialization &&
|
|
1244
|
+
SYNC_METRICS_DATA_SETS.includes(dataSetName)
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
private saveSyncBackoffLatency(
|
|
1249
|
+
dataSetName: string,
|
|
1250
|
+
randomBackoffTime: number,
|
|
1251
|
+
isInitialization = false
|
|
1252
|
+
) {
|
|
1253
|
+
if (!this.shouldCollectSyncMetrics(dataSetName, isInitialization)) {
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
this.callbacks.syncLatencyTracker?.saveLatency(
|
|
1258
|
+
'internal.client.locus.sync.random.backoff',
|
|
1259
|
+
Math.round(randomBackoffTime),
|
|
1260
|
+
{
|
|
1261
|
+
meetingId: this.syncLatencyMeetingId,
|
|
1262
|
+
dataSetName,
|
|
1263
|
+
}
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1149
1267
|
/**
|
|
1150
1268
|
* Calls the updateInfo callback if there are any updates to report
|
|
1151
1269
|
*
|
|
@@ -1199,10 +1317,10 @@ class HashTreeParser {
|
|
|
1199
1317
|
});
|
|
1200
1318
|
|
|
1201
1319
|
if (filteredUpdates.length > 0) {
|
|
1202
|
-
this.locusInfoUpdateCallback({updateType, updatedObjects: filteredUpdates});
|
|
1320
|
+
this.callbacks.locusInfoUpdateCallback({updateType, updatedObjects: filteredUpdates});
|
|
1203
1321
|
}
|
|
1204
1322
|
} else if (updateType !== LocusInfoUpdateType.OBJECTS_UPDATED) {
|
|
1205
|
-
this.locusInfoUpdateCallback({updateType});
|
|
1323
|
+
this.callbacks.locusInfoUpdateCallback({updateType});
|
|
1206
1324
|
}
|
|
1207
1325
|
}
|
|
1208
1326
|
|
|
@@ -1224,84 +1342,412 @@ class HashTreeParser {
|
|
|
1224
1342
|
* Performs a sync for the given data set.
|
|
1225
1343
|
*
|
|
1226
1344
|
* @param {InternalDataSet} dataSet - The data set to sync
|
|
1227
|
-
* @param {string} rootHash - Our current root hash for this data set
|
|
1228
1345
|
* @param {string} reason - The reason for the sync (used for logging)
|
|
1346
|
+
* @param {boolean} [isInitialization] - Whether this is an initialization sync (sends empty leaves data instead of comparing hashes)
|
|
1229
1347
|
* @returns {Promise<void>}
|
|
1230
1348
|
*/
|
|
1231
1349
|
private async performSync(
|
|
1232
1350
|
dataSet: InternalDataSet,
|
|
1233
|
-
|
|
1234
|
-
|
|
1351
|
+
reason: string,
|
|
1352
|
+
isInitialization?: boolean
|
|
1235
1353
|
): Promise<void> {
|
|
1236
1354
|
if (!dataSet.hashTree) {
|
|
1237
1355
|
return;
|
|
1238
1356
|
}
|
|
1239
1357
|
|
|
1358
|
+
const abortController = dataSet.syncAbortController ?? new AbortController();
|
|
1359
|
+
dataSet.syncAbortController = abortController;
|
|
1360
|
+
|
|
1361
|
+
const {hashTree} = dataSet;
|
|
1362
|
+
const rootHash = hashTree.getRootHash();
|
|
1363
|
+
const shouldCollectMetrics = this.shouldCollectSyncMetrics(dataSet.name, isInitialization);
|
|
1364
|
+
// Generate two distinct tracking ids up-front. Each Locus request must carry its own unique
|
|
1365
|
+
// tracking id, so the /hashtree and /sync requests must not share one. hashtreeTrackingId is
|
|
1366
|
+
// generated first so that syncTrackingId (forced onto the /sync request, stored in metrics, and
|
|
1367
|
+
// used to match the LLM broadcast message) ends up with the later/higher sequence number,
|
|
1368
|
+
// matching the order in which Locus sees the requests. If we never call /hashtree (single-leaf
|
|
1369
|
+
// or initialization syncs), hashtreeTrackingId is simply unused.
|
|
1370
|
+
const hashtreeTrackingId = shouldCollectMetrics
|
|
1371
|
+
? this.callbacks.generateTrackingId?.()
|
|
1372
|
+
: undefined;
|
|
1373
|
+
const syncTrackingId = shouldCollectMetrics ? this.callbacks.generateTrackingId?.() : undefined;
|
|
1374
|
+
let syncRequestSent = false;
|
|
1375
|
+
|
|
1376
|
+
if (shouldCollectMetrics) {
|
|
1377
|
+
this.callbacks.syncLatencyTracker?.saveTimestamp({
|
|
1378
|
+
key: 'internal.client.locus.sync.start',
|
|
1379
|
+
options: {
|
|
1380
|
+
meetingId: this.syncLatencyMeetingId,
|
|
1381
|
+
dataSetName: dataSet.name,
|
|
1382
|
+
trackingId: syncTrackingId,
|
|
1383
|
+
},
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1240
1387
|
try {
|
|
1241
1388
|
LoggerProxy.logger.info(
|
|
1242
1389
|
`HashTreeParser#performSync --> ${this.debugId} ${reason}, syncing data set "${dataSet.name}"`
|
|
1243
1390
|
);
|
|
1244
1391
|
|
|
1245
|
-
|
|
1392
|
+
let leavesData: Record<number, LeafDataItem[]> = {};
|
|
1246
1393
|
|
|
1247
|
-
if (
|
|
1248
|
-
|
|
1394
|
+
if (!isInitialization) {
|
|
1395
|
+
if (dataSet.leafCount !== 1) {
|
|
1396
|
+
let receivedHashes;
|
|
1249
1397
|
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1398
|
+
try {
|
|
1399
|
+
// request hashes from sender
|
|
1400
|
+
const hashesResult = await this.getHashesFromLocus(dataSet.name, rootHash, {
|
|
1401
|
+
requestTrackingId: hashtreeTrackingId,
|
|
1402
|
+
metricTrackingId: syncTrackingId,
|
|
1403
|
+
});
|
|
1256
1404
|
|
|
1257
|
-
|
|
1405
|
+
if (!hashesResult) {
|
|
1406
|
+
// hashes match, no sync needed
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1258
1409
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1410
|
+
receivedHashes = hashesResult.hashes;
|
|
1411
|
+
|
|
1412
|
+
this.updateDataSetLeafCount(dataSet, hashesResult.dataSet.leafCount);
|
|
1413
|
+
} catch (error: any) {
|
|
1414
|
+
if (error?.statusCode === 409) {
|
|
1415
|
+
// this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
|
|
1416
|
+
LoggerProxy.logger.info(
|
|
1417
|
+
`HashTreeParser#getHashesFromLocus --> ${this.debugId} Got 409 when fetching hashes for data set "${dataSet.name}": ${error.message}`
|
|
1418
|
+
);
|
|
1266
1419
|
|
|
1267
|
-
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
throw error;
|
|
1268
1423
|
}
|
|
1269
|
-
|
|
1424
|
+
|
|
1425
|
+
// identify mismatched leaves
|
|
1426
|
+
const mismatchedLeaveIndexes = hashTree.diffHashes(receivedHashes);
|
|
1427
|
+
|
|
1428
|
+
mismatchedLeaveIndexes.forEach((index) => {
|
|
1429
|
+
leavesData[index] = hashTree.getLeafData(index);
|
|
1430
|
+
});
|
|
1431
|
+
} else {
|
|
1432
|
+
leavesData = {0: hashTree.getLeafData(0)};
|
|
1270
1433
|
}
|
|
1434
|
+
}
|
|
1271
1435
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1436
|
+
if (abortController.signal.aborted) {
|
|
1437
|
+
LoggerProxy.logger.info(
|
|
1438
|
+
`HashTreeParser#performSync --> ${this.debugId} abandoning sync for "${dataSet.name}" before /sync - message received during sync`
|
|
1439
|
+
);
|
|
1274
1440
|
|
|
1275
|
-
|
|
1276
|
-
mismatchedLeavesData[index] = dataSet.hashTree.getLeafData(index);
|
|
1277
|
-
});
|
|
1278
|
-
} else {
|
|
1279
|
-
mismatchedLeavesData[0] = dataSet.hashTree.getLeafData(0);
|
|
1441
|
+
return;
|
|
1280
1442
|
}
|
|
1281
1443
|
// request sync for mismatched leaves
|
|
1282
|
-
|
|
1283
|
-
const syncResponse = await this.sendSyncRequestToLocus(dataSet, mismatchedLeavesData);
|
|
1444
|
+
let syncResponse: HashTreeMessage | null = null;
|
|
1284
1445
|
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1446
|
+
if (isInitialization) {
|
|
1447
|
+
syncResponse = await this.sendSyncRequestToLocus(
|
|
1448
|
+
dataSet,
|
|
1449
|
+
{isInitialization: true},
|
|
1450
|
+
syncTrackingId
|
|
1451
|
+
);
|
|
1452
|
+
|
|
1453
|
+
syncRequestSent = true;
|
|
1454
|
+
} else if (Object.keys(leavesData).length > 0) {
|
|
1455
|
+
syncResponse = await this.sendSyncRequestToLocus(
|
|
1456
|
+
dataSet,
|
|
1457
|
+
{mismatchedLeavesData: leavesData},
|
|
1458
|
+
syncTrackingId
|
|
1459
|
+
);
|
|
1460
|
+
|
|
1461
|
+
syncRequestSent = true;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// sync API may return nothing (in that case data will arrive via messages)
|
|
1465
|
+
// or it may return a response in the same format as messages
|
|
1466
|
+
// We still need to restart the sync timer as a safety net in case the messages don't arrive.
|
|
1467
|
+
this.runSyncAlgorithm(dataSet);
|
|
1468
|
+
|
|
1469
|
+
if (syncResponse) {
|
|
1470
|
+
// clear the abort controller before processing the response so that
|
|
1471
|
+
// parseMessage() -> cancelPendingSyncsForDataSets() doesn't log a
|
|
1472
|
+
// misleading "aborting sync" message for this already-completed sync
|
|
1473
|
+
dataSet.syncAbortController = undefined;
|
|
1474
|
+
|
|
1475
|
+
// the format of sync response is the same as messages, so we can reuse the same handler
|
|
1476
|
+
this.handleMessage(
|
|
1477
|
+
syncResponse,
|
|
1478
|
+
`via sync API (${
|
|
1479
|
+
isInitialization ? 'init' : `${Object.keys(leavesData).length} mismatched leaves`
|
|
1480
|
+
})`
|
|
1481
|
+
);
|
|
1290
1482
|
}
|
|
1291
1483
|
} catch (error) {
|
|
1292
|
-
if (error
|
|
1293
|
-
this.callLocusInfoUpdateCallback({
|
|
1294
|
-
updateType: LocusInfoUpdateType.MEETING_ENDED,
|
|
1295
|
-
});
|
|
1296
|
-
} else {
|
|
1484
|
+
if (!this.handleSyncErrors(error)) {
|
|
1297
1485
|
LoggerProxy.logger.warn(
|
|
1298
1486
|
`HashTreeParser#performSync --> ${this.debugId} error during sync for data set "${dataSet.name}":`,
|
|
1299
1487
|
error
|
|
1300
1488
|
);
|
|
1301
1489
|
}
|
|
1490
|
+
} finally {
|
|
1491
|
+
if (shouldCollectMetrics && !syncRequestSent) {
|
|
1492
|
+
// Drop only this sync's in-progress record (matched by its tracking id) rather than the
|
|
1493
|
+
// whole dataset, so a still-pending record from an earlier successful sync isn't wiped.
|
|
1494
|
+
// This mirrors the native client's onSyncError(syncId) which discards a single record.
|
|
1495
|
+
this.callbacks.syncLatencyTracker?.clearLocusSyncLatency(
|
|
1496
|
+
dataSet.name,
|
|
1497
|
+
this.syncLatencyMeetingId,
|
|
1498
|
+
syncTrackingId
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
dataSet.syncAbortController = undefined;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
/**
|
|
1506
|
+
* Cancels any pending or in-flight syncs for the specified data sets.
|
|
1507
|
+
* This removes matching entries from the sync queue and aborts any in-flight sync HTTP requests.
|
|
1508
|
+
*
|
|
1509
|
+
* @param {string[]} dataSetNames - The names of the data sets to cancel syncs for
|
|
1510
|
+
* @returns {void}
|
|
1511
|
+
*/
|
|
1512
|
+
private cancelPendingSyncsForDataSets(dataSetNames: string[]): void {
|
|
1513
|
+
const previousLength = this.syncQueue.length;
|
|
1514
|
+
|
|
1515
|
+
this.syncQueue = this.syncQueue.filter((entry) => !dataSetNames.includes(entry.dataSetName));
|
|
1516
|
+
|
|
1517
|
+
if (previousLength !== this.syncQueue.length) {
|
|
1518
|
+
LoggerProxy.logger.info(
|
|
1519
|
+
`HashTreeParser#cancelPendingSyncsForDataSets --> ${this.debugId} removed ${
|
|
1520
|
+
previousLength - this.syncQueue.length
|
|
1521
|
+
} entries from sync queue for data sets: ${dataSetNames.join(', ')}`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
this.markDataSetsForSyncAllBackoffSkip(dataSetNames);
|
|
1526
|
+
this.abortInFlightSyncs(dataSetNames);
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* If a syncAllDatasets backoff sleep is in progress, marks the given data sets to be skipped
|
|
1531
|
+
* after the sleep completes.
|
|
1532
|
+
*
|
|
1533
|
+
* @param {string[]} dataSetNames - The names of the data sets to mark
|
|
1534
|
+
* @returns {void}
|
|
1535
|
+
*/
|
|
1536
|
+
private markDataSetsForSyncAllBackoffSkip(dataSetNames: string[]): void {
|
|
1537
|
+
if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
|
|
1538
|
+
for (const name of dataSetNames) {
|
|
1539
|
+
this.dataSetsSyncedDuringBackoff.add(name);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* Aborts any in-flight sync HTTP requests for the specified data sets.
|
|
1546
|
+
*
|
|
1547
|
+
* @param {string[]} dataSetNames - The names of the data sets whose syncs should be aborted
|
|
1548
|
+
* @returns {void}
|
|
1549
|
+
*/
|
|
1550
|
+
private abortInFlightSyncs(dataSetNames: string[]): void {
|
|
1551
|
+
for (const name of dataSetNames) {
|
|
1552
|
+
if (this.dataSets[name]?.syncAbortController) {
|
|
1553
|
+
LoggerProxy.logger.info(
|
|
1554
|
+
`HashTreeParser#cancelPendingSyncsForDataSets --> ${this.debugId} aborting in-flight sync for data set "${name}"`
|
|
1555
|
+
);
|
|
1556
|
+
this.dataSets[name].syncAbortController.abort();
|
|
1557
|
+
}
|
|
1302
1558
|
}
|
|
1303
1559
|
}
|
|
1304
1560
|
|
|
1561
|
+
/**
|
|
1562
|
+
* Enqueues a sync for the given data set. If the data set is already in the queue, the request is ignored.
|
|
1563
|
+
* This ensures that all syncs are executed sequentially and no more than 1 sync runs at a time.
|
|
1564
|
+
*
|
|
1565
|
+
* @param {string} dataSetName - The name of the data set to sync
|
|
1566
|
+
* @param {string} reason - The reason for the sync (used for logging)
|
|
1567
|
+
* @param {boolean} [isInitialization=false] - Whether this is an initialization sync (uses empty leaves data instead of hash comparison)
|
|
1568
|
+
* @returns {void}
|
|
1569
|
+
*/
|
|
1570
|
+
private enqueueSyncForDataset(
|
|
1571
|
+
dataSetName: string,
|
|
1572
|
+
reason: string,
|
|
1573
|
+
isInitialization = false
|
|
1574
|
+
): void {
|
|
1575
|
+
if (this.state === 'stopped') return;
|
|
1576
|
+
|
|
1577
|
+
const existingEntry = this.syncQueue.find((entry) => entry.dataSetName === dataSetName);
|
|
1578
|
+
|
|
1579
|
+
if (existingEntry) {
|
|
1580
|
+
if (isInitialization) {
|
|
1581
|
+
existingEntry.isInitialization = true;
|
|
1582
|
+
}
|
|
1583
|
+
LoggerProxy.logger.info(
|
|
1584
|
+
`HashTreeParser#enqueueSyncForDataset --> ${this.debugId} data set "${dataSetName}" already in sync queue, skipping`
|
|
1585
|
+
);
|
|
1586
|
+
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
this.syncQueue.push({dataSetName, reason, isInitialization});
|
|
1591
|
+
|
|
1592
|
+
if (!this.isSyncInProgress) {
|
|
1593
|
+
this.syncQueueProcessingPromise = this.processSyncQueue();
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
/**
|
|
1598
|
+
* Processes the sync queue sequentially. Only one instance of this method runs at a time.
|
|
1599
|
+
*
|
|
1600
|
+
* @returns {Promise<void>}
|
|
1601
|
+
*/
|
|
1602
|
+
private async processSyncQueue(): Promise<void> {
|
|
1603
|
+
if (this.isSyncInProgress) return;
|
|
1604
|
+
|
|
1605
|
+
this.isSyncInProgress = true;
|
|
1606
|
+
try {
|
|
1607
|
+
while (this.syncQueue.length > 0 && this.state !== 'stopped') {
|
|
1608
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1609
|
+
const {dataSetName, reason, isInitialization} = this.syncQueue.shift()!;
|
|
1610
|
+
const dataSet = this.dataSets[dataSetName];
|
|
1611
|
+
|
|
1612
|
+
if (!dataSet?.hashTree) {
|
|
1613
|
+
// eslint-disable-next-line no-continue
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1618
|
+
await this.performSync(dataSet, reason, isInitialization);
|
|
1619
|
+
}
|
|
1620
|
+
} finally {
|
|
1621
|
+
this.isSyncInProgress = false;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* sets the backoff type for syncAllDatasets calls, which determines the scope of datasets that will be synced after the backoff delay.
|
|
1627
|
+
*
|
|
1628
|
+
* @param {boolean} onlyLLM - Whether the backoff is for a syncAllDatasets call that is syncing only LLM datasets
|
|
1629
|
+
* @returns {void}
|
|
1630
|
+
*/
|
|
1631
|
+
private setSyncAllBackoffType(onlyLLM: boolean): void {
|
|
1632
|
+
this.syncAllBackoffType = onlyLLM ? SyncAllBackoffType.ONLY_LLM : SyncAllBackoffType.ALL;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
/**
|
|
1636
|
+
* Checks if a syncAll backoff is already in progress. If so, upgrades the scope from
|
|
1637
|
+
* onlyLLM to all datasets when the new call has a broader scope.
|
|
1638
|
+
*
|
|
1639
|
+
* @param {boolean} onlyLLM - Whether the current call is for LLM datasets only
|
|
1640
|
+
* @returns {boolean} true if a backoff is already pending (caller should return early)
|
|
1641
|
+
*/
|
|
1642
|
+
private tryUpgradePendingBackoff(onlyLLM: boolean): boolean {
|
|
1643
|
+
if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
|
|
1644
|
+
if (!onlyLLM && this.syncAllBackoffType === SyncAllBackoffType.ONLY_LLM) {
|
|
1645
|
+
this.setSyncAllBackoffType(false);
|
|
1646
|
+
LoggerProxy.logger.info(
|
|
1647
|
+
`HashTreeParser#syncAllDatasets --> ${this.debugId} upgraded pending syncAll from onlyLLM to all datasets`
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
return true;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
return false;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
/**
|
|
1658
|
+
* Syncs all data sets that have hash trees, one by one in sequence, using the priority order
|
|
1659
|
+
* provided by sortByInitPriority().
|
|
1660
|
+
*
|
|
1661
|
+
* If a call is already waiting in the backoff delay phase, a new call with a broader scope
|
|
1662
|
+
* (onlyLLM=false) will upgrade the pending scope, and the dataset list will be computed after
|
|
1663
|
+
* the backoff using the upgraded scope. After the backoff, the sync queue handles deduplication
|
|
1664
|
+
* so no guard is needed.
|
|
1665
|
+
*
|
|
1666
|
+
* @param {Object} [options={}] - Options for syncing
|
|
1667
|
+
* @param {boolean} [options.onlyLLM=false] - Whether to sync only LLM based data sets
|
|
1668
|
+
* @returns {Promise<void>}
|
|
1669
|
+
*/
|
|
1670
|
+
public async syncAllDatasets(options: {onlyLLM?: boolean} = {}): Promise<void> {
|
|
1671
|
+
const {onlyLLM = false} = options;
|
|
1672
|
+
if (this.state === 'stopped') return;
|
|
1673
|
+
|
|
1674
|
+
// if we're already in the backoff delay phase, try to upgrade the scope instead of starting a new one
|
|
1675
|
+
if (this.tryUpgradePendingBackoff(onlyLLM)) {
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
const dataSetsToSync = this.getSortedDataSetsWithHashTrees(onlyLLM);
|
|
1680
|
+
|
|
1681
|
+
if (dataSetsToSync.length === 0) return;
|
|
1682
|
+
|
|
1683
|
+
this.setSyncAllBackoffType(onlyLLM);
|
|
1684
|
+
|
|
1685
|
+
const delay = this.getWeightedBackoffTime(dataSetsToSync[0].backoff);
|
|
1686
|
+
|
|
1687
|
+
LoggerProxy.logger.info(
|
|
1688
|
+
`HashTreeParser#syncAllDatasets --> ${this.debugId} starting backoff delay of ${delay}ms (onlyLLM=${onlyLLM})`
|
|
1689
|
+
);
|
|
1690
|
+
|
|
1691
|
+
// delay the start of the syncs - this is a Locus requirement to avoid thundering herd issues
|
|
1692
|
+
await sleep(delay);
|
|
1693
|
+
|
|
1694
|
+
// read the (possibly upgraded) scope and clear the backoff flag
|
|
1695
|
+
const effectiveBackoffType = this.syncAllBackoffType;
|
|
1696
|
+
const skippedDataSets = this.dataSetsSyncedDuringBackoff;
|
|
1697
|
+
|
|
1698
|
+
this.syncAllBackoffType = SyncAllBackoffType.NONE;
|
|
1699
|
+
this.dataSetsSyncedDuringBackoff = new Set();
|
|
1700
|
+
|
|
1701
|
+
if ((this.state as string) === 'stopped') return;
|
|
1702
|
+
|
|
1703
|
+
// re-evaluate the dataset list after the sleep, since the scope may have been upgraded
|
|
1704
|
+
// and exclude datasets that received messages during the backoff sleep
|
|
1705
|
+
const effectiveDataSetsToSync = this.getSortedDataSetsWithHashTrees(
|
|
1706
|
+
effectiveBackoffType === SyncAllBackoffType.ONLY_LLM
|
|
1707
|
+
).filter((ds) => !skippedDataSets.has(ds.name));
|
|
1708
|
+
|
|
1709
|
+
if (skippedDataSets.size > 0) {
|
|
1710
|
+
LoggerProxy.logger.info(
|
|
1711
|
+
`HashTreeParser#syncAllDatasets --> ${
|
|
1712
|
+
this.debugId
|
|
1713
|
+
} skipping datasets that received messages during backoff: ${[...skippedDataSets].join(
|
|
1714
|
+
', '
|
|
1715
|
+
)}`
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
LoggerProxy.logger.info(
|
|
1720
|
+
`HashTreeParser#syncAllDatasets --> ${this.debugId} syncing ${
|
|
1721
|
+
effectiveBackoffType === SyncAllBackoffType.ONLY_LLM ? 'only LLM' : 'all'
|
|
1722
|
+
} datasets: ${effectiveDataSetsToSync.map((ds) => ds.name).join(', ')}`
|
|
1723
|
+
);
|
|
1724
|
+
|
|
1725
|
+
for (const ds of effectiveDataSetsToSync) {
|
|
1726
|
+
this.saveSyncBackoffLatency(ds.name, delay);
|
|
1727
|
+
this.enqueueSyncForDataset(ds.name, 'syncAllDatasets');
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
await this.syncQueueProcessingPromise;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
/**
|
|
1734
|
+
* Returns the list of data sets that have hash trees, sorted by the priority order provided by sortByInitPriority().
|
|
1735
|
+
*
|
|
1736
|
+
* @param {boolean} onlyLLM - Whether to include only LLM based data sets
|
|
1737
|
+
* @returns {Array<{name: string, backoff: {maxMs: number, exponent: number}}>} The sorted list of data sets with their backoff configurations
|
|
1738
|
+
*/
|
|
1739
|
+
private getSortedDataSetsWithHashTrees(onlyLLM: boolean) {
|
|
1740
|
+
let dataSets = Object.values(this.dataSets)
|
|
1741
|
+
.filter((dataSet) => dataSet?.hashTree)
|
|
1742
|
+
.map((dataSet) => ({name: dataSet.name, backoff: dataSet.backoff}));
|
|
1743
|
+
|
|
1744
|
+
if (onlyLLM) {
|
|
1745
|
+
dataSets = dataSets.filter((ds) => LLM_DATASET_NAMES.includes(ds.name));
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
return sortByInitPriority(dataSets, DATA_SET_INIT_PRIORITY);
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1305
1751
|
/**
|
|
1306
1752
|
* Runs the sync algorithm for the given data set.
|
|
1307
1753
|
*
|
|
@@ -1320,33 +1766,25 @@ class HashTreeParser {
|
|
|
1320
1766
|
}
|
|
1321
1767
|
|
|
1322
1768
|
if (!dataSet.hashTree) {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
);
|
|
1769
|
+
// no hash tree, so no need to do any syncing
|
|
1770
|
+
// we fall into this branch often, because Locus sends dataSets in messages that are not visible to us
|
|
1326
1771
|
|
|
1327
1772
|
return;
|
|
1328
1773
|
}
|
|
1329
1774
|
|
|
1330
1775
|
dataSet.hashTree.resize(receivedDataSet.leafCount);
|
|
1331
1776
|
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1334
|
-
LoggerProxy.logger.info(
|
|
1335
|
-
`HashTreeParser#runSyncAlgorithm --> ${this.debugId} dataSet="${dataSet.name}" version=${dataSet.version} hashes before starting timer: ours=${ourCurrentRootHash} Locus=${dataSet.root}`
|
|
1336
|
-
);
|
|
1337
|
-
|
|
1338
|
-
const delay = dataSet.idleMs + this.getWeightedBackoffTime(dataSet.backoff);
|
|
1777
|
+
const randomBackoffTime = this.getWeightedBackoffTime(dataSet.backoff);
|
|
1778
|
+
const delay = dataSet.idleMs + randomBackoffTime;
|
|
1339
1779
|
|
|
1340
1780
|
if (delay > 0) {
|
|
1341
1781
|
if (dataSet.timer) {
|
|
1342
1782
|
clearTimeout(dataSet.timer);
|
|
1343
1783
|
}
|
|
1344
1784
|
|
|
1345
|
-
|
|
1346
|
-
`HashTreeParser#runSyncAlgorithm --> ${this.debugId} setting "${dataSet.name}" sync timer for ${delay}`
|
|
1347
|
-
);
|
|
1785
|
+
this.saveSyncBackoffLatency(dataSet.name, randomBackoffTime);
|
|
1348
1786
|
|
|
1349
|
-
dataSet.timer = setTimeout(
|
|
1787
|
+
dataSet.timer = setTimeout(() => {
|
|
1350
1788
|
dataSet.timer = undefined;
|
|
1351
1789
|
|
|
1352
1790
|
if (!dataSet.hashTree) {
|
|
@@ -1360,15 +1798,10 @@ class HashTreeParser {
|
|
|
1360
1798
|
const rootHash = dataSet.hashTree.getRootHash();
|
|
1361
1799
|
|
|
1362
1800
|
if (dataSet.root !== rootHash) {
|
|
1363
|
-
|
|
1364
|
-
dataSet,
|
|
1365
|
-
rootHash,
|
|
1801
|
+
this.enqueueSyncForDataset(
|
|
1802
|
+
dataSet.name,
|
|
1366
1803
|
`Root hash mismatch: received=${dataSet.root}, ours=${rootHash}`
|
|
1367
1804
|
);
|
|
1368
|
-
} else {
|
|
1369
|
-
LoggerProxy.logger.info(
|
|
1370
|
-
`HashTreeParser#runSyncAlgorithm --> ${this.debugId} "${dataSet.name}" root hash matching: ${rootHash}, version=${dataSet.version}`
|
|
1371
|
-
);
|
|
1372
1805
|
}
|
|
1373
1806
|
}, delay);
|
|
1374
1807
|
} else {
|
|
@@ -1388,38 +1821,41 @@ class HashTreeParser {
|
|
|
1388
1821
|
* @returns {void}
|
|
1389
1822
|
*/
|
|
1390
1823
|
private resetHeartbeatWatchdogs(receivedDataSets: Array<DataSet>): void {
|
|
1391
|
-
if (!this.heartbeatIntervalMs) {
|
|
1392
|
-
return;
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
1824
|
for (const receivedDataSet of receivedDataSets) {
|
|
1396
1825
|
const dataSet = this.dataSets[receivedDataSet.name];
|
|
1397
1826
|
|
|
1398
|
-
if (!dataSet?.hashTree) {
|
|
1399
|
-
// eslint-disable-next-line no-continue
|
|
1400
|
-
continue;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
1827
|
if (dataSet.heartbeatWatchdogTimer) {
|
|
1404
1828
|
clearTimeout(dataSet.heartbeatWatchdogTimer);
|
|
1405
1829
|
dataSet.heartbeatWatchdogTimer = undefined;
|
|
1406
1830
|
}
|
|
1407
1831
|
|
|
1832
|
+
// dataset-level heartbeatIntervalMs takes priority; fall back to top-level common value
|
|
1833
|
+
const heartbeatIntervalMs = dataSet?.heartbeatIntervalMs ?? this.topLevelHeartbeatIntervalMs;
|
|
1834
|
+
|
|
1835
|
+
if (!dataSet?.hashTree || !heartbeatIntervalMs) {
|
|
1836
|
+
// eslint-disable-next-line no-continue
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1408
1840
|
const backoffTime = this.getWeightedBackoffTime(dataSet.backoff);
|
|
1409
|
-
const delay =
|
|
1841
|
+
const delay = heartbeatIntervalMs + backoffTime;
|
|
1410
1842
|
|
|
1411
|
-
dataSet.heartbeatWatchdogTimer = setTimeout(
|
|
1843
|
+
dataSet.heartbeatWatchdogTimer = setTimeout(() => {
|
|
1412
1844
|
dataSet.heartbeatWatchdogTimer = undefined;
|
|
1413
1845
|
|
|
1414
1846
|
LoggerProxy.logger.warn(
|
|
1415
1847
|
`HashTreeParser#resetHeartbeatWatchdogs --> ${this.debugId} Heartbeat watchdog fired for data set "${dataSet.name}" - no heartbeat received within expected interval, initiating sync`
|
|
1416
1848
|
);
|
|
1417
1849
|
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
dataSet.
|
|
1421
|
-
|
|
1422
|
-
|
|
1850
|
+
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, {
|
|
1851
|
+
debugId: this.debugId,
|
|
1852
|
+
dataSetName: dataSet.name,
|
|
1853
|
+
});
|
|
1854
|
+
|
|
1855
|
+
this.saveSyncBackoffLatency(dataSet.name, backoffTime);
|
|
1856
|
+
|
|
1857
|
+
this.enqueueSyncForDataset(dataSet.name, `heartbeat watchdog expired`);
|
|
1858
|
+
this.resetHeartbeatWatchdogs([dataSet]);
|
|
1423
1859
|
}, delay);
|
|
1424
1860
|
}
|
|
1425
1861
|
}
|
|
@@ -1452,7 +1888,13 @@ class HashTreeParser {
|
|
|
1452
1888
|
`HashTreeParser#stop --> ${this.debugId} Stopping HashTreeParser, clearing timers and hash trees`
|
|
1453
1889
|
);
|
|
1454
1890
|
this.stopAllTimers();
|
|
1891
|
+
this.syncQueue = [];
|
|
1892
|
+
this.topLevelHeartbeatIntervalMs = undefined;
|
|
1893
|
+
this.syncAllBackoffType = SyncAllBackoffType.NONE;
|
|
1894
|
+
this.dataSetsSyncedDuringBackoff = new Set();
|
|
1455
1895
|
Object.values(this.dataSets).forEach((dataSet) => {
|
|
1896
|
+
dataSet.syncAbortController?.abort();
|
|
1897
|
+
dataSet.syncAbortController = undefined;
|
|
1456
1898
|
dataSet.hashTree = undefined;
|
|
1457
1899
|
});
|
|
1458
1900
|
this.visibleDataSets = [];
|
|
@@ -1470,17 +1912,16 @@ class HashTreeParser {
|
|
|
1470
1912
|
}
|
|
1471
1913
|
|
|
1472
1914
|
/**
|
|
1473
|
-
* Resumes the HashTreeParser that was previously stopped.
|
|
1915
|
+
* Resumes the HashTreeParser that was previously stopped, using a hash tree message.
|
|
1474
1916
|
* @param {HashTreeMessage} message - The message to resume with, it must contain metadata with visible data sets info
|
|
1475
1917
|
* @returns {void}
|
|
1476
1918
|
*/
|
|
1477
|
-
public
|
|
1478
|
-
// check that message contains metadata with visible data sets - this is essential to be able to resume
|
|
1919
|
+
public resumeFromMessage(message: HashTreeMessage) {
|
|
1479
1920
|
const metadataObject = message.locusStateElements?.find((el) => isMetadata(el));
|
|
1480
1921
|
|
|
1481
1922
|
if (!metadataObject?.data?.visibleDataSets) {
|
|
1482
1923
|
LoggerProxy.logger.warn(
|
|
1483
|
-
`HashTreeParser#
|
|
1924
|
+
`HashTreeParser#resumeFromMessage --> ${this.debugId} Cannot resume HashTreeParser because the message is missing metadata with visible data sets info`
|
|
1484
1925
|
);
|
|
1485
1926
|
|
|
1486
1927
|
return;
|
|
@@ -1501,7 +1942,7 @@ class HashTreeParser {
|
|
|
1501
1942
|
};
|
|
1502
1943
|
}
|
|
1503
1944
|
LoggerProxy.logger.info(
|
|
1504
|
-
`HashTreeParser#
|
|
1945
|
+
`HashTreeParser#resumeFromMessage --> ${
|
|
1505
1946
|
this.debugId
|
|
1506
1947
|
} Resuming HashTreeParser with data sets: ${Object.keys(this.dataSets).join(
|
|
1507
1948
|
', '
|
|
@@ -1512,18 +1953,47 @@ class HashTreeParser {
|
|
|
1512
1953
|
this.handleMessage(message, 'on resume');
|
|
1513
1954
|
}
|
|
1514
1955
|
|
|
1956
|
+
/**
|
|
1957
|
+
* Resumes the HashTreeParser that was previously stopped, using a Locus API response.
|
|
1958
|
+
* Unlike resumeFromMessage(), this does not require metadata/dataSets in the input,
|
|
1959
|
+
* as it fetches all necessary information from Locus via initializeFromGetLociResponse.
|
|
1960
|
+
* @param {LocusDTO} locus - locus object from an API response
|
|
1961
|
+
* @returns {Promise}
|
|
1962
|
+
*/
|
|
1963
|
+
public async resumeFromApiResponse(locus: LocusDTO) {
|
|
1964
|
+
this.state = 'active';
|
|
1965
|
+
this.dataSets = {};
|
|
1966
|
+
|
|
1967
|
+
LoggerProxy.logger.info(
|
|
1968
|
+
`HashTreeParser#resumeFromApiResponse --> ${this.debugId} Resuming HashTreeParser from API response`
|
|
1969
|
+
);
|
|
1970
|
+
|
|
1971
|
+
await this.initializeFromGetLociResponse(locus);
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1515
1974
|
private checkForSentinelHttpResponse(error: any, dataSetName?: string) {
|
|
1975
|
+
// 404 for any dataset means the locus is no longer available at this URL - could be replaced or ended
|
|
1976
|
+
// if a dataset is just not visible, we would get a 400
|
|
1977
|
+
if (error.statusCode === 404) {
|
|
1978
|
+
LoggerProxy.logger.info(
|
|
1979
|
+
`HashTreeParser#checkForSentinelHttpResponse --> ${this.debugId} Received 404 for data set "${dataSetName}", locus not found`
|
|
1980
|
+
);
|
|
1981
|
+
this.stopAllTimers();
|
|
1982
|
+
|
|
1983
|
+
throw new LocusNotFoundError();
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1516
1986
|
const isValidDataSetForSentinel =
|
|
1517
1987
|
dataSetName === undefined ||
|
|
1518
1988
|
PossibleSentinelMessageDataSetNames.includes(dataSetName.toLowerCase());
|
|
1519
1989
|
|
|
1520
1990
|
if (
|
|
1521
|
-
|
|
1522
|
-
|
|
1991
|
+
error.statusCode === 409 &&
|
|
1992
|
+
error.body?.errorCode === LocusErrorCodes.LOCUS_INACTIVE &&
|
|
1523
1993
|
isValidDataSetForSentinel
|
|
1524
1994
|
) {
|
|
1525
1995
|
LoggerProxy.logger.info(
|
|
1526
|
-
`HashTreeParser#checkForSentinelHttpResponse --> ${this.debugId} Received ${error.statusCode} for data set "${dataSetName}", indicating that the meeting has ended`
|
|
1996
|
+
`HashTreeParser#checkForSentinelHttpResponse --> ${this.debugId} Received ${error.statusCode}/${error.body?.errorCode} for data set "${dataSetName}", indicating that the meeting has ended`
|
|
1527
1997
|
);
|
|
1528
1998
|
this.stopAllTimers();
|
|
1529
1999
|
|
|
@@ -1535,9 +2005,18 @@ class HashTreeParser {
|
|
|
1535
2005
|
* Gets the current hashes from the locus for a specific data set.
|
|
1536
2006
|
* @param {string} dataSetName
|
|
1537
2007
|
* @param {string} currentRootHash
|
|
1538
|
-
* @
|
|
2008
|
+
* @param {Object} [trackingIds] tracking ids for the /hashtree request
|
|
2009
|
+
* @param {string} [trackingIds.requestTrackingId] tracking id forced onto the /hashtree HTTP request header (kept distinct from the /sync request's tracking id)
|
|
2010
|
+
* @param {string} [trackingIds.metricTrackingId] tracking id (the /sync request's) under which the hashtree latency milestones are recorded, so they belong to the same sync latency record
|
|
2011
|
+
* @returns {Object|null} An object containing the hashes and leaf count, or null if the hashes match and no sync is needed
|
|
1539
2012
|
*/
|
|
1540
|
-
private getHashesFromLocus(
|
|
2013
|
+
private getHashesFromLocus(
|
|
2014
|
+
dataSetName: string,
|
|
2015
|
+
currentRootHash: string,
|
|
2016
|
+
trackingIds?: {requestTrackingId?: string; metricTrackingId?: string}
|
|
2017
|
+
) {
|
|
2018
|
+
const {requestTrackingId, metricTrackingId} = trackingIds ?? {};
|
|
2019
|
+
|
|
1541
2020
|
LoggerProxy.logger.info(
|
|
1542
2021
|
`HashTreeParser#getHashesFromLocus --> ${this.debugId} Requesting hashes for data set "${dataSetName}"`
|
|
1543
2022
|
);
|
|
@@ -1546,14 +2025,48 @@ class HashTreeParser {
|
|
|
1546
2025
|
|
|
1547
2026
|
const url = `${dataSet.url}/hashtree`;
|
|
1548
2027
|
|
|
2028
|
+
if (this.shouldCollectSyncMetrics(dataSetName)) {
|
|
2029
|
+
this.callbacks.syncLatencyTracker?.saveTimestamp({
|
|
2030
|
+
key: 'internal.client.locus.hashtree.request',
|
|
2031
|
+
options: {
|
|
2032
|
+
meetingId: this.syncLatencyMeetingId,
|
|
2033
|
+
dataSetName,
|
|
2034
|
+
trackingId: metricTrackingId,
|
|
2035
|
+
},
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
|
|
1549
2039
|
return this.webexRequest({
|
|
1550
2040
|
method: HTTP_VERBS.GET,
|
|
1551
2041
|
uri: url,
|
|
1552
2042
|
qs: {
|
|
1553
2043
|
rootHash: currentRootHash,
|
|
1554
2044
|
},
|
|
2045
|
+
// Force a dedicated tracking id onto the /hashtree request so it does not share the /sync
|
|
2046
|
+
// request's tracking id; the tracking id interceptor leaves an already-set header untouched.
|
|
2047
|
+
...(requestTrackingId ? {headers: {trackingid: requestTrackingId}} : {}),
|
|
1555
2048
|
})
|
|
1556
2049
|
.then((response) => {
|
|
2050
|
+
if (this.shouldCollectSyncMetrics(dataSetName)) {
|
|
2051
|
+
this.callbacks.syncLatencyTracker?.saveTimestamp({
|
|
2052
|
+
key: 'internal.client.locus.hashtree.response',
|
|
2053
|
+
options: {
|
|
2054
|
+
meetingId: this.syncLatencyMeetingId,
|
|
2055
|
+
dataSetName,
|
|
2056
|
+
trackingId: metricTrackingId,
|
|
2057
|
+
},
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
if (!response.body || isEmpty(response.body)) {
|
|
2062
|
+
// 204 with empty body means our hashes match Locus, no sync needed
|
|
2063
|
+
LoggerProxy.logger.info(
|
|
2064
|
+
`HashTreeParser#getHashesFromLocus --> ${this.debugId} Got ${response.statusCode} with empty body for data set "${dataSetName}", hashes match - no sync needed`
|
|
2065
|
+
);
|
|
2066
|
+
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
1557
2070
|
const hashes = response.body?.hashes as string[] | undefined;
|
|
1558
2071
|
const dataSetFromResponse = response.body?.dataSet;
|
|
1559
2072
|
|
|
@@ -1582,6 +2095,13 @@ class HashTreeParser {
|
|
|
1582
2095
|
error
|
|
1583
2096
|
);
|
|
1584
2097
|
this.checkForSentinelHttpResponse(error, dataSet.name);
|
|
2098
|
+
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_SYNC_FAILURE, {
|
|
2099
|
+
debugId: this.debugId,
|
|
2100
|
+
dataSetName,
|
|
2101
|
+
request: 'GET /hashtree',
|
|
2102
|
+
statusCode: error.statusCode,
|
|
2103
|
+
reason: error.message,
|
|
2104
|
+
});
|
|
1585
2105
|
|
|
1586
2106
|
throw error;
|
|
1587
2107
|
});
|
|
@@ -1591,36 +2111,59 @@ class HashTreeParser {
|
|
|
1591
2111
|
* Sends a sync request to Locus for the specified data set.
|
|
1592
2112
|
*
|
|
1593
2113
|
* @param {InternalDataSet} dataSet The data set to sync.
|
|
1594
|
-
* @param {
|
|
1595
|
-
* @
|
|
2114
|
+
* @param {Object} options Either `{ isInitialization: true }` for init syncs (uses leafCount=1 with empty leaf data) or `{ mismatchedLeavesData }` for normal syncs.
|
|
2115
|
+
* @param {string} [trackingId] tracking id
|
|
2116
|
+
* @returns {Promise<HashTreeMessage | null>}
|
|
1596
2117
|
*/
|
|
1597
2118
|
private sendSyncRequestToLocus(
|
|
1598
2119
|
dataSet: InternalDataSet,
|
|
1599
|
-
mismatchedLeavesData: Record<number, LeafDataItem[]>
|
|
2120
|
+
options: {isInitialization: true} | {mismatchedLeavesData: Record<number, LeafDataItem[]>},
|
|
2121
|
+
trackingId?: string
|
|
1600
2122
|
): Promise<HashTreeMessage | null> {
|
|
1601
2123
|
LoggerProxy.logger.info(
|
|
1602
2124
|
`HashTreeParser#sendSyncRequestToLocus --> ${this.debugId} Sending sync request for data set "${dataSet.name}"`
|
|
1603
2125
|
);
|
|
1604
2126
|
|
|
2127
|
+
const isInitialization = 'isInitialization' in options;
|
|
2128
|
+
|
|
1605
2129
|
const url = `${dataSet.url}/sync`;
|
|
1606
2130
|
const body: {
|
|
1607
2131
|
leafCount: number;
|
|
1608
2132
|
leafDataEntries: {leafIndex: number; elementIds: LeafDataItem[]}[];
|
|
1609
2133
|
} = {
|
|
1610
|
-
leafCount: dataSet.leafCount,
|
|
2134
|
+
leafCount: isInitialization ? 1 : dataSet.leafCount,
|
|
1611
2135
|
leafDataEntries: [],
|
|
1612
2136
|
};
|
|
1613
2137
|
|
|
1614
|
-
|
|
1615
|
-
|
|
2138
|
+
if (isInitialization) {
|
|
2139
|
+
// initialization sync: Locus requires leafCount=1 with a single empty leaf
|
|
2140
|
+
body.leafDataEntries.push({leafIndex: 0, elementIds: []});
|
|
2141
|
+
} else {
|
|
2142
|
+
const {mismatchedLeavesData} = options;
|
|
2143
|
+
|
|
2144
|
+
Object.keys(mismatchedLeavesData).forEach((index) => {
|
|
2145
|
+
const leafIndex = parseInt(index, 10);
|
|
1616
2146
|
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
2147
|
+
body.leafDataEntries.push({
|
|
2148
|
+
leafIndex,
|
|
2149
|
+
elementIds: mismatchedLeavesData[leafIndex],
|
|
2150
|
+
});
|
|
1620
2151
|
});
|
|
1621
|
-
}
|
|
2152
|
+
}
|
|
1622
2153
|
|
|
1623
2154
|
const ourCurrentRootHash = dataSet.hashTree ? dataSet.hashTree.getRootHash() : EMPTY_HASH;
|
|
2155
|
+
const shouldCollectMetrics = this.shouldCollectSyncMetrics(dataSet.name, isInitialization);
|
|
2156
|
+
|
|
2157
|
+
if (shouldCollectMetrics) {
|
|
2158
|
+
this.callbacks.syncLatencyTracker?.saveTimestamp({
|
|
2159
|
+
key: 'internal.client.locus.sync.request',
|
|
2160
|
+
options: {
|
|
2161
|
+
meetingId: this.syncLatencyMeetingId,
|
|
2162
|
+
dataSetName: dataSet.name,
|
|
2163
|
+
trackingId,
|
|
2164
|
+
},
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
1624
2167
|
|
|
1625
2168
|
return this.webexRequest({
|
|
1626
2169
|
method: HTTP_VERBS.POST,
|
|
@@ -1628,12 +2171,22 @@ class HashTreeParser {
|
|
|
1628
2171
|
qs: {
|
|
1629
2172
|
rootHash: ourCurrentRootHash,
|
|
1630
2173
|
},
|
|
2174
|
+
// Force the pre-generated tracking id onto the /sync request so Locus echoes it back on the
|
|
2175
|
+
// resulting LLM message; the tracking id interceptor leaves an already-set header untouched.
|
|
2176
|
+
...(trackingId ? {headers: {trackingid: trackingId}} : {}),
|
|
1631
2177
|
body,
|
|
1632
2178
|
})
|
|
1633
2179
|
.then((resp) => {
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
2180
|
+
if (shouldCollectMetrics) {
|
|
2181
|
+
this.callbacks.syncLatencyTracker?.saveTimestamp({
|
|
2182
|
+
key: 'internal.client.locus.sync.response',
|
|
2183
|
+
options: {
|
|
2184
|
+
meetingId: this.syncLatencyMeetingId,
|
|
2185
|
+
dataSetName: dataSet.name,
|
|
2186
|
+
trackingId,
|
|
2187
|
+
},
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
1637
2190
|
|
|
1638
2191
|
if (!resp.body || isEmpty(resp.body)) {
|
|
1639
2192
|
LoggerProxy.logger.info(
|
|
@@ -1651,6 +2204,13 @@ class HashTreeParser {
|
|
|
1651
2204
|
error
|
|
1652
2205
|
);
|
|
1653
2206
|
this.checkForSentinelHttpResponse(error, dataSet.name);
|
|
2207
|
+
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_SYNC_FAILURE, {
|
|
2208
|
+
debugId: this.debugId,
|
|
2209
|
+
dataSetName: dataSet.name,
|
|
2210
|
+
request: 'POST /sync',
|
|
2211
|
+
statusCode: error.statusCode,
|
|
2212
|
+
reason: error.message,
|
|
2213
|
+
});
|
|
1654
2214
|
|
|
1655
2215
|
throw error;
|
|
1656
2216
|
});
|