@fluidframework/matrix 2.41.0-338401 → 2.42.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/CHANGELOG.md +8 -0
- package/dist/matrix.d.ts +2 -12
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +169 -115
- package/dist/matrix.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/permutationvector.d.ts +4 -1
- package/dist/permutationvector.d.ts.map +1 -1
- package/dist/permutationvector.js +34 -13
- package/dist/permutationvector.js.map +1 -1
- package/lib/matrix.d.ts +2 -12
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +169 -115
- package/lib/matrix.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/permutationvector.d.ts +4 -1
- package/lib/permutationvector.d.ts.map +1 -1
- package/lib/permutationvector.js +34 -13
- package/lib/permutationvector.js.map +1 -1
- package/package.json +20 -19
- package/src/matrix.ts +249 -148
- package/src/packageVersion.ts +1 -1
- package/src/permutationvector.ts +45 -19
package/CHANGELOG.md
CHANGED
package/dist/matrix.d.ts
CHANGED
|
@@ -140,9 +140,7 @@ export declare class SharedMatrix<T = any> extends SharedObject<ISharedMatrixEve
|
|
|
140
140
|
private readonly cols;
|
|
141
141
|
private cells;
|
|
142
142
|
private readonly pending;
|
|
143
|
-
private
|
|
144
|
-
private setCellLwwToFwwPolicySwitchOpSeqNumber;
|
|
145
|
-
private userSwitchedSetCellPolicy;
|
|
143
|
+
private fwwPolicy;
|
|
146
144
|
private reentrantCount;
|
|
147
145
|
/**
|
|
148
146
|
* Constructor for the Shared Matrix
|
|
@@ -208,6 +206,7 @@ export declare class SharedMatrix<T = any> extends SharedObject<ISharedMatrixEve
|
|
|
208
206
|
protected onConnect(): void;
|
|
209
207
|
private rebasePosition;
|
|
210
208
|
protected reSubmitCore(incoming: unknown, localOpMetadata: unknown): void;
|
|
209
|
+
protected rollback(content: unknown, localOpMetadata: unknown): void;
|
|
211
210
|
protected onDisconnect(): void;
|
|
212
211
|
/**
|
|
213
212
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
@@ -224,15 +223,6 @@ export declare class SharedMatrix<T = any> extends SharedObject<ISharedMatrixEve
|
|
|
224
223
|
private readonly onRowHandlesRecycled;
|
|
225
224
|
private readonly onColHandlesRecycled;
|
|
226
225
|
switchSetCellPolicy(): void;
|
|
227
|
-
/**
|
|
228
|
-
* Returns true if the latest pending write to the cell indicated by the given row/col handles
|
|
229
|
-
* matches the given 'localSeq'.
|
|
230
|
-
*
|
|
231
|
-
* A return value of `true` indicates that there are no later local operations queued that will
|
|
232
|
-
* clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell
|
|
233
|
-
* with a different value as well as row/col removals that might recycled the given row/col handles.
|
|
234
|
-
*/
|
|
235
|
-
private isLatestPendingWrite;
|
|
236
226
|
toString(): string;
|
|
237
227
|
/**
|
|
238
228
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
package/dist/matrix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,MAAM,EACN,qBAAqB,EACrB,KAAK,cAAc,EACnB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,QAAQ,EACb,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAEN,YAAY,EAOZ,MAAM,qCAAqC,CAAC;AAC7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,GAAG,IAAI;IAQ/D;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAUpB,SAAS,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IAkB/E,SAAS,CAAC,SAAS,IAAI,IAAI;IAS3B,SAAS,CAAC,SAAS,IAAI,IAAI;IAW3B,OAAO,CAAC,cAAc;IAetB,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAiEzE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAyCpE,SAAS,CAAC,YAAY,IAAI,IAAI;IAE9B;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CxE;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAuB/B,SAAS,CAAC,WAAW,CACpB,GAAG,EAAE,yBAAyB,EAC9B,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO,GACtB,IAAI;IA0IP,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAGF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAWnC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAWnC;IAEK,mBAAmB,IAAI,IAAI;IAY3B,QAAQ,IAAI,MAAM;IAoBzB;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;CAiBjD"}
|
package/dist/matrix.js
CHANGED
|
@@ -64,8 +64,9 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
64
64
|
this.getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);
|
|
65
65
|
this.cells = new sparsearray2d_js_1.SparseArray2D(); // Stores cell values.
|
|
66
66
|
this.pending = new sparsearray2d_js_1.SparseArray2D(); // Tracks pending writes.
|
|
67
|
-
this.
|
|
68
|
-
|
|
67
|
+
this.fwwPolicy = {
|
|
68
|
+
state: "off",
|
|
69
|
+
};
|
|
69
70
|
// Used to track if there is any reentrancy in setCell code.
|
|
70
71
|
this.reentrantCount = 0;
|
|
71
72
|
// Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.
|
|
@@ -84,17 +85,24 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
84
85
|
for (const rowHandle of rowHandles) {
|
|
85
86
|
this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);
|
|
86
87
|
this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);
|
|
87
|
-
this.
|
|
88
|
+
if (this.fwwPolicy.state === "on") {
|
|
89
|
+
this.fwwPolicy.cellLastWriteTracker?.clearRows(
|
|
90
|
+
/* rowStart: */ rowHandle,
|
|
91
|
+
/* rowCount: */ 1);
|
|
92
|
+
}
|
|
88
93
|
}
|
|
89
94
|
};
|
|
90
95
|
this.onColHandlesRecycled = (colHandles) => {
|
|
91
96
|
for (const colHandle of colHandles) {
|
|
92
97
|
this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);
|
|
93
98
|
this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);
|
|
94
|
-
this.
|
|
99
|
+
if (this.fwwPolicy.state === "on") {
|
|
100
|
+
this.fwwPolicy.cellLastWriteTracker?.clearCols(
|
|
101
|
+
/* colStart: */ colHandle,
|
|
102
|
+
/* colCount: */ 1);
|
|
103
|
+
}
|
|
95
104
|
}
|
|
96
105
|
};
|
|
97
|
-
this.setCellLwwToFwwPolicySwitchOpSeqNumber = -1;
|
|
98
106
|
this.rows = new permutationvector_js_1.PermutationVector(ops_js_1.SnapshotPath.rows, this.logger, runtime, this.onRowDelta, this.onRowHandlesRecycled, this.getMinInFlightRefSeq);
|
|
99
107
|
this.cols = new permutationvector_js_1.PermutationVector(ops_js_1.SnapshotPath.cols, this.logger, runtime, this.onColDelta, this.onColHandlesRecycled, this.getMinInFlightRefSeq);
|
|
100
108
|
}
|
|
@@ -129,7 +137,7 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
129
137
|
return this.cols.getLength();
|
|
130
138
|
}
|
|
131
139
|
isSetCellConflictResolutionPolicyFWW() {
|
|
132
|
-
return this.
|
|
140
|
+
return this.fwwPolicy.state !== "off";
|
|
133
141
|
}
|
|
134
142
|
getCell(row, col) {
|
|
135
143
|
// Perf: When possible, bounds checking is performed inside the implementation for
|
|
@@ -180,18 +188,18 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
180
188
|
}
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
|
-
setCellCore(row, col, value, rowHandle = this.rows.getAllocatedHandle(row), colHandle = this.cols.getAllocatedHandle(col)) {
|
|
191
|
+
setCellCore(row, col, value, rowHandle = this.rows.getAllocatedHandle(row), colHandle = this.cols.getAllocatedHandle(col), rollback) {
|
|
184
192
|
this.protectAgainstReentrancy(() => {
|
|
193
|
+
const oldValue = this.cells.getCell(rowHandle, colHandle) ?? undefined;
|
|
185
194
|
if (this.undo !== undefined) {
|
|
186
|
-
let oldValue = this.cells.getCell(rowHandle, colHandle);
|
|
187
|
-
if (oldValue === null) {
|
|
188
|
-
oldValue = undefined;
|
|
189
|
-
}
|
|
190
195
|
this.undo.cellSet(rowHandle, colHandle, oldValue);
|
|
191
196
|
}
|
|
192
197
|
this.cells.setCell(rowHandle, colHandle, value);
|
|
193
|
-
if (this.isAttached()) {
|
|
194
|
-
this.sendSetCellOp(row, col, value, rowHandle, colHandle);
|
|
198
|
+
if (this.isAttached() && rollback !== true) {
|
|
199
|
+
const pending = this.sendSetCellOp(row, col, value, rowHandle, colHandle);
|
|
200
|
+
if (pending.local.length === 1) {
|
|
201
|
+
pending.consensus ??= oldValue;
|
|
202
|
+
}
|
|
195
203
|
}
|
|
196
204
|
// Avoid reentrancy by raising change notifications after the op is queued.
|
|
197
205
|
for (const consumer of this.consumers.values()) {
|
|
@@ -211,7 +219,7 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
211
219
|
row,
|
|
212
220
|
col,
|
|
213
221
|
value,
|
|
214
|
-
fwwMode: this.
|
|
222
|
+
fwwMode: this.fwwPolicy.state !== "off",
|
|
215
223
|
};
|
|
216
224
|
const rowsRef = this.createOpMetadataLocalRef(this.rows, row, localSeq);
|
|
217
225
|
const colsRef = this.createOpMetadataLocalRef(this.cols, col, localSeq);
|
|
@@ -224,7 +232,12 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
224
232
|
referenceSeqNumber: this.deltaManager.lastSequenceNumber,
|
|
225
233
|
};
|
|
226
234
|
this.submitLocalMessage(op, metadata);
|
|
227
|
-
this.pending.
|
|
235
|
+
const pendingCell = this.pending.getCell(rowHandle, colHandle) ?? {
|
|
236
|
+
local: [],
|
|
237
|
+
};
|
|
238
|
+
pendingCell.local.push({ localSeq, value });
|
|
239
|
+
this.pending.setCell(rowHandle, colHandle, pendingCell);
|
|
240
|
+
return pendingCell;
|
|
228
241
|
}
|
|
229
242
|
/**
|
|
230
243
|
* This makes sure that the code inside the callback is not reentrant. We need to do that because we raise notifications
|
|
@@ -364,12 +377,21 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
364
377
|
builder.addWithStats(ops_js_1.SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));
|
|
365
378
|
const artifactsToSummarize = [
|
|
366
379
|
this.cells.snapshot(),
|
|
367
|
-
|
|
368
|
-
|
|
380
|
+
/**
|
|
381
|
+
* we used to write this.pending.snapshot(). this should have never been done, as pending is only for local
|
|
382
|
+
* changes, and there should never be local changes in the summarizer. This was also never used on load
|
|
383
|
+
* as there is no way to understand a previous clients pending changes. so we just set this to a constant
|
|
384
|
+
* which matches an empty this.pending.snapshot() for back-compat in terms of the array length
|
|
385
|
+
*/
|
|
386
|
+
[undefined],
|
|
369
387
|
];
|
|
370
388
|
// Only need to store it in the snapshot if we have switched the policy already.
|
|
371
|
-
if (this.
|
|
372
|
-
artifactsToSummarize.push(this.cellLastWriteTracker.snapshot());
|
|
389
|
+
if (this.fwwPolicy.state === "on") {
|
|
390
|
+
artifactsToSummarize.push(this.fwwPolicy.switchOpSeqNumber, this.fwwPolicy.cellLastWriteTracker.snapshot());
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
// back-compat: used -1 for disabled
|
|
394
|
+
artifactsToSummarize.push(-1);
|
|
373
395
|
}
|
|
374
396
|
builder.addBlob(ops_js_1.SnapshotPath.cells, serializer.stringify(artifactsToSummarize, this.handle));
|
|
375
397
|
return builder.getSummaryTree();
|
|
@@ -444,32 +466,36 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
444
466
|
const col = this.rebasePosition(this.cols, colsRef, localSeq);
|
|
445
467
|
this.rows.removeLocalReferencePosition(rowsRef);
|
|
446
468
|
this.cols.removeLocalReferencePosition(colsRef);
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
469
|
+
const pendingCell = this.pending.getCell(rowHandle, colHandle);
|
|
470
|
+
(0, internal_1.assert)(pendingCell !== undefined, 0xba4 /* local operation must have a pending array */);
|
|
471
|
+
const { local } = pendingCell;
|
|
472
|
+
(0, internal_1.assert)(local !== undefined, 0xba5 /* local operation must have a pending array */);
|
|
473
|
+
const localSeqIndex = local.findIndex((p) => p.localSeq === localSeq);
|
|
474
|
+
(0, internal_1.assert)(localSeqIndex >= 0, 0xba6 /* local operation must have a pending entry */);
|
|
475
|
+
const [change] = local.splice(localSeqIndex, 1);
|
|
476
|
+
(0, internal_1.assert)(change.localSeq === localSeq, 0xba7 /* must match */);
|
|
477
|
+
if (row !== undefined &&
|
|
478
|
+
col !== undefined &&
|
|
479
|
+
row >= 0 &&
|
|
480
|
+
col >= 0 && // If the mode is LWW, then send the op.
|
|
450
481
|
// Otherwise if the current mode is FWW and if we generated this op, after seeing the
|
|
451
482
|
// last set op, or it is the first set op for the cell, then regenerate the op,
|
|
452
483
|
// otherwise raise conflict. We want to check the current mode here and not that
|
|
453
484
|
// whether op was made in FWW or not.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
else if (this.pending.getCell(rowHandle, colHandle) !== undefined) {
|
|
460
|
-
// Clear the pending changes if any as we are not sending the op.
|
|
461
|
-
this.pending.setCell(rowHandle, colHandle, undefined);
|
|
462
|
-
}
|
|
485
|
+
(this.fwwPolicy.state !== "on" ||
|
|
486
|
+
referenceSeqNumber >=
|
|
487
|
+
(this.fwwPolicy.cellLastWriteTracker.getCell(rowHandle, colHandle)?.seqNum ?? 0))) {
|
|
488
|
+
this.sendSetCellOp(row, col, setOp.value, rowHandle, colHandle, localSeq);
|
|
463
489
|
}
|
|
464
490
|
}
|
|
465
491
|
else {
|
|
466
492
|
switch (content.target) {
|
|
467
493
|
case ops_js_1.SnapshotPath.cols: {
|
|
468
|
-
this.submitColMessage(this.cols.regeneratePendingOp(content, localOpMetadata));
|
|
494
|
+
this.submitColMessage(this.cols.regeneratePendingOp(content, localOpMetadata, false));
|
|
469
495
|
break;
|
|
470
496
|
}
|
|
471
497
|
case ops_js_1.SnapshotPath.rows: {
|
|
472
|
-
this.submitRowMessage(this.rows.regeneratePendingOp(content, localOpMetadata));
|
|
498
|
+
this.submitRowMessage(this.rows.regeneratePendingOp(content, localOpMetadata, false));
|
|
473
499
|
break;
|
|
474
500
|
}
|
|
475
501
|
default: {
|
|
@@ -478,6 +504,33 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
478
504
|
}
|
|
479
505
|
}
|
|
480
506
|
}
|
|
507
|
+
rollback(content, localOpMetadata) {
|
|
508
|
+
const contents = content;
|
|
509
|
+
const target = contents.target;
|
|
510
|
+
switch (target) {
|
|
511
|
+
case ops_js_1.SnapshotPath.cols: {
|
|
512
|
+
this.cols.rollback(content, localOpMetadata);
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
case ops_js_1.SnapshotPath.rows: {
|
|
516
|
+
this.rows.rollback(content, localOpMetadata);
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
case undefined: {
|
|
520
|
+
(0, internal_1.assert)(contents.type === ops_js_1.MatrixOp.set, 0xba8 /* only sets supported */);
|
|
521
|
+
const setMetadata = localOpMetadata;
|
|
522
|
+
const pendingCell = this.pending.getCell(setMetadata.rowHandle, setMetadata.colHandle);
|
|
523
|
+
(0, internal_1.assert)(pendingCell !== undefined, 0xba9 /* must have pending */);
|
|
524
|
+
const change = pendingCell.local.pop();
|
|
525
|
+
(0, internal_1.assert)(change?.localSeq === setMetadata.localSeq, 0xbaa /* must have change */);
|
|
526
|
+
const previous = pendingCell.local.length > 0
|
|
527
|
+
? pendingCell.local[pendingCell.local.length - 1].value
|
|
528
|
+
: pendingCell.consensus;
|
|
529
|
+
this.setCellCore(contents.row, contents.col, previous, setMetadata.rowHandle, setMetadata.colHandle, true);
|
|
530
|
+
}
|
|
531
|
+
default:
|
|
532
|
+
}
|
|
533
|
+
}
|
|
481
534
|
onDisconnect() { }
|
|
482
535
|
/**
|
|
483
536
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
@@ -490,11 +543,20 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
490
543
|
// Cast is needed since the (de)serializer returns content of type `any`.
|
|
491
544
|
] = (await (0, serialization_js_1.deserializeBlob)(storage, ops_js_1.SnapshotPath.cells, this.serializer));
|
|
492
545
|
this.cells = sparsearray2d_js_1.SparseArray2D.load(cellData);
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
546
|
+
// back-compat: used -1 for disabled, also may not exist
|
|
547
|
+
const switchOpSeqNumber = setCellLwwToFwwPolicySwitchOpSeqNumber === -1
|
|
548
|
+
? undefined
|
|
549
|
+
: (setCellLwwToFwwPolicySwitchOpSeqNumber ?? undefined);
|
|
550
|
+
this.fwwPolicy =
|
|
551
|
+
switchOpSeqNumber === undefined
|
|
552
|
+
? {
|
|
553
|
+
state: "off",
|
|
554
|
+
}
|
|
555
|
+
: {
|
|
556
|
+
state: "on",
|
|
557
|
+
switchOpSeqNumber,
|
|
558
|
+
cellLastWriteTracker: sparsearray2d_js_1.SparseArray2D.load(cellLastWriteTracker),
|
|
559
|
+
};
|
|
498
560
|
}
|
|
499
561
|
catch (error) {
|
|
500
562
|
this.logger.sendErrorEvent({ eventName: "MatrixLoadFailed" }, error);
|
|
@@ -505,9 +567,9 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
505
567
|
* we are in FWW mode.
|
|
506
568
|
*/
|
|
507
569
|
shouldSetCellBasedOnFWW(rowHandle, colHandle, message) {
|
|
508
|
-
(0, internal_1.assert)(this.
|
|
570
|
+
(0, internal_1.assert)(this.fwwPolicy.state === "on", 0x85f /* should be in Fww mode when calling this method */);
|
|
509
571
|
(0, internal_1.assert)(message.clientId !== null, 0x860 /* clientId should not be null */);
|
|
510
|
-
const lastCellModificationDetails = this.cellLastWriteTracker.getCell(rowHandle, colHandle);
|
|
572
|
+
const lastCellModificationDetails = this.fwwPolicy.cellLastWriteTracker.getCell(rowHandle, colHandle);
|
|
511
573
|
// If someone tried to Overwrite the cell value or first write on this cell or
|
|
512
574
|
// same client tried to modify the cell.
|
|
513
575
|
return (lastCellModificationDetails === undefined ||
|
|
@@ -540,78 +602,88 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
540
602
|
case undefined: {
|
|
541
603
|
(0, internal_1.assert)(contents.type === ops_js_1.MatrixOp.set, 0x021 /* "SharedMatrix message contents have unexpected type!" */);
|
|
542
604
|
const { row, col, value, fwwMode } = contents;
|
|
543
|
-
const isPreviousSetCellPolicyModeFWW = this.setCellLwwToFwwPolicySwitchOpSeqNumber > -1;
|
|
544
605
|
// If this is the first op notifying us of the policy change, then set the policy change seq number.
|
|
545
|
-
if (
|
|
546
|
-
this.
|
|
606
|
+
if (fwwMode === true && this.fwwPolicy.state !== "on") {
|
|
607
|
+
this.fwwPolicy = {
|
|
608
|
+
state: "on",
|
|
609
|
+
switchOpSeqNumber: msg.sequenceNumber,
|
|
610
|
+
cellLastWriteTracker: new sparsearray2d_js_1.SparseArray2D(),
|
|
611
|
+
};
|
|
547
612
|
}
|
|
548
613
|
(0, internal_1.assert)(msg.clientId !== null, 0x861 /* clientId should not be null!! */);
|
|
549
614
|
if (local) {
|
|
550
615
|
// We are receiving the ACK for a local pending set operation.
|
|
551
616
|
const { rowHandle, colHandle, localSeq, rowsRef, colsRef } = localOpMetadata;
|
|
552
|
-
const isLatestPendingOp = this.isLatestPendingWrite(rowHandle, colHandle, localSeq);
|
|
553
617
|
this.rows.removeLocalReferencePosition(rowsRef);
|
|
554
618
|
this.cols.removeLocalReferencePosition(colsRef);
|
|
619
|
+
const pendingCell = this.pending.getCell(rowHandle, colHandle);
|
|
620
|
+
const ackedChange = pendingCell?.local.shift();
|
|
621
|
+
(0, internal_1.assert)(ackedChange?.localSeq === localSeq, 0xbab /* must match */);
|
|
622
|
+
if (pendingCell?.local.length === 0) {
|
|
623
|
+
this.pending.setCell(rowHandle, colHandle, undefined);
|
|
624
|
+
}
|
|
555
625
|
// If policy is switched and cell should be modified too based on policy, then update the tracker.
|
|
556
626
|
// If policy is not switched, then also update the tracker in case it is the latest.
|
|
557
|
-
if (
|
|
558
|
-
this.shouldSetCellBasedOnFWW(rowHandle, colHandle, msg))
|
|
559
|
-
|
|
560
|
-
|
|
627
|
+
if (this.fwwPolicy.state === "on" &&
|
|
628
|
+
this.shouldSetCellBasedOnFWW(rowHandle, colHandle, msg)) {
|
|
629
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
630
|
+
pendingCell.consensus = ackedChange.value;
|
|
631
|
+
this.fwwPolicy.cellLastWriteTracker.setCell(rowHandle, colHandle, {
|
|
561
632
|
seqNum: msg.sequenceNumber,
|
|
562
633
|
clientId: msg.clientId,
|
|
563
634
|
});
|
|
564
635
|
}
|
|
565
|
-
if (isLatestPendingOp) {
|
|
566
|
-
this.pending.setCell(rowHandle, colHandle, undefined);
|
|
567
|
-
}
|
|
568
636
|
}
|
|
569
637
|
else {
|
|
570
638
|
const adjustedRow = this.rows.adjustPosition(row, msg);
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
639
|
+
const adjustedCol = this.cols.adjustPosition(col, msg);
|
|
640
|
+
const rowHandle = adjustedRow.handle;
|
|
641
|
+
const colHandle = adjustedCol.handle;
|
|
642
|
+
(0, internal_1.assert)((0, handletable_js_1.isHandleValid)(rowHandle) && (0, handletable_js_1.isHandleValid)(colHandle), 0x022 /* "SharedMatrix row and/or col handles are invalid!" */);
|
|
643
|
+
const pendingCell = this.pending.getCell(rowHandle, colHandle);
|
|
644
|
+
if (this.fwwPolicy.state === "on") {
|
|
645
|
+
// If someone tried to Overwrite the cell value or first write on this cell or
|
|
646
|
+
// same client tried to modify the cell or if the previous mode was LWW, then we need to still
|
|
647
|
+
// overwrite the cell and raise conflict if we have pending changes as our change is going to be lost.
|
|
648
|
+
if (this.shouldSetCellBasedOnFWW(rowHandle, colHandle, msg)) {
|
|
649
|
+
const previousValue = this.cells.getCell(rowHandle, colHandle);
|
|
650
|
+
this.cells.setCell(rowHandle, colHandle, value);
|
|
651
|
+
this.fwwPolicy.cellLastWriteTracker.setCell(rowHandle, colHandle, {
|
|
652
|
+
seqNum: msg.sequenceNumber,
|
|
653
|
+
clientId: msg.clientId,
|
|
654
|
+
});
|
|
655
|
+
if (pendingCell !== undefined) {
|
|
656
|
+
pendingCell.consensus = value;
|
|
657
|
+
}
|
|
658
|
+
if (adjustedRow.pos !== undefined && adjustedCol.pos !== undefined) {
|
|
659
|
+
for (const consumer of this.consumers.values()) {
|
|
660
|
+
consumer.cellsChanged(adjustedRow.pos, adjustedCol.pos, 1, 1, this);
|
|
661
|
+
}
|
|
662
|
+
// Check is there are any pending changes, which will be rejected. If so raise conflict.
|
|
663
|
+
if (pendingCell !== undefined && pendingCell.local.length > 0) {
|
|
664
|
+
// Don't reset the pending value yet, as there maybe more fww op from same client, so we want
|
|
665
|
+
// to raise conflict event for that op also.
|
|
666
|
+
this.emit("conflict", row, col, value, // Current value
|
|
667
|
+
previousValue, // Ignored local value
|
|
668
|
+
this);
|
|
600
669
|
}
|
|
601
670
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
if (pendingCell === undefined || pendingCell.local.length === 0) {
|
|
675
|
+
// If there is a pending (unACKed) local write to the same cell, skip the current op
|
|
676
|
+
// since it "happened before" the pending write.
|
|
677
|
+
this.cells.setCell(rowHandle, colHandle, value);
|
|
678
|
+
if (adjustedRow.pos !== undefined && adjustedCol.pos !== undefined) {
|
|
610
679
|
for (const consumer of this.consumers.values()) {
|
|
611
|
-
consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);
|
|
680
|
+
consumer.cellsChanged(adjustedRow.pos, adjustedCol.pos, 1, 1, this);
|
|
612
681
|
}
|
|
613
682
|
}
|
|
614
683
|
}
|
|
684
|
+
else {
|
|
685
|
+
pendingCell.consensus = value;
|
|
686
|
+
}
|
|
615
687
|
}
|
|
616
688
|
}
|
|
617
689
|
break;
|
|
@@ -622,34 +694,16 @@ class SharedMatrix extends internal_4.SharedObject {
|
|
|
622
694
|
}
|
|
623
695
|
}
|
|
624
696
|
switchSetCellPolicy() {
|
|
625
|
-
if (this.
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
697
|
+
if (this.fwwPolicy.state === "off") {
|
|
698
|
+
this.fwwPolicy = this.isAttached()
|
|
699
|
+
? { state: "local" }
|
|
700
|
+
: {
|
|
701
|
+
state: "on",
|
|
702
|
+
switchOpSeqNumber: 0,
|
|
703
|
+
cellLastWriteTracker: new sparsearray2d_js_1.SparseArray2D(),
|
|
704
|
+
};
|
|
632
705
|
}
|
|
633
706
|
}
|
|
634
|
-
/**
|
|
635
|
-
* Returns true if the latest pending write to the cell indicated by the given row/col handles
|
|
636
|
-
* matches the given 'localSeq'.
|
|
637
|
-
*
|
|
638
|
-
* A return value of `true` indicates that there are no later local operations queued that will
|
|
639
|
-
* clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell
|
|
640
|
-
* with a different value as well as row/col removals that might recycled the given row/col handles.
|
|
641
|
-
*/
|
|
642
|
-
isLatestPendingWrite(rowHandle, colHandle, localSeq) {
|
|
643
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
644
|
-
const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle);
|
|
645
|
-
// Note while we're awaiting the ACK for a local set, it's possible for the row/col to be
|
|
646
|
-
// locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will
|
|
647
|
-
// be 'undefined' or > 'localSeq'.
|
|
648
|
-
(0, internal_1.assert)(!(pendingLocalSeq < localSeq), 0x023 /* "The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op." */);
|
|
649
|
-
// If this is the most recent write to the cell by the local client, the stored localSeq
|
|
650
|
-
// will be an exact match for the given 'localSeq'.
|
|
651
|
-
return pendingLocalSeq === localSeq;
|
|
652
|
-
}
|
|
653
707
|
toString() {
|
|
654
708
|
let s = `client:${this.runtime.clientId}\nrows: ${this.rows.toString()}\ncols: ${this.cols.toString()}\n\n`;
|
|
655
709
|
for (let r = 0; r < this.rowCount; r++) {
|