Skip to content

Commit 990cc74

Browse files
author
Abram Sanderson
committed
fix lint
1 parent e4970f9 commit 990cc74

File tree

5 files changed

+40
-50
lines changed

5 files changed

+40
-50
lines changed

packages/dds/merge-tree/src/partialLengths.ts

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,30 @@ export class PartialSequenceLengths {
239239
*
240240
* As per doc comment on {@link PartialSequenceLengths}, the overall adjustment performed for the perspective of
241241
* (clientId, refSeq) is given by the sum of length deltas in `perClientAdjustments[clientId]`
242-
* for all sequence numbers S such that S >= refSeq.
242+
* for all sequence numbers S such that S \>= refSeq.
243243
*
244244
* (since these are ordered by sequence number and we cache cumulative sums, this is implemented using two lookups and a subtraction).
245245
*
246246
* The specific adjustments that are made roughly categorize as follows:
247247
*
248248
* - Ops submitted by a given client generally receive a partial lengths entry corresponding to their sequence number.
249-
* e.g. insert of "ABC" at seq 5 will have a per-client adjustment entry of { seq: 5, seglen: 3 }.
249+
* e.g. insert of "ABC" at seq 5 will have a per-client adjustment entry of \{ seq: 5, seglen: 3 \}.
250250
*
251251
* - When client A deletes a segment concurrently with client B and loses the race (B's delete is sequenced first),
252-
* A's per-client adjustments will contain an entry with a negative `seglen` corresponding to the length of the segment
253-
* and a sequence number corresponding to that of B's delete. It will *not* receive a per-client adjustment for its own delete.
254-
* This ensures that for perspectives (A, refSeq), the deleted segment will show up as a negative delta for all values of refSeq, since:
255-
* - For refSeq < B's delete, the per-client adjustment will apply and be added to the total length
256-
* - For refSeq >= B's delete, B's partial length entry in the overall set will apply, and the per-client adjustment will not apply
252+
* A's per-client adjustments will contain an entry with a negative `seglen` corresponding to the length of the segment
253+
* and a sequence number corresponding to that of B's delete. It will *not* receive a per-client adjustment for its own delete.
254+
* This ensures that for perspectives (A, refSeq), the deleted segment will show up as a negative delta for all values of refSeq, since:
255+
* 1. For refSeq \< B's delete, the per-client adjustment will apply and be added to the total length
256+
* 2. For refSeq \>= B's delete, B's partial length entry in the overall set will apply, and the per-client adjustment will not apply
257257
*
258258
* - When client A attempts to insert a segment into a location that is concurrently obliterated by client B immediately upon insertion,
259-
* A's per-client adjustments will again not include an entry for its own insert.
260-
* Instead, the entry which would normally contain `seq` equal to that of A's insert would instead have `seq` equal to that of B's obliterate.
261-
* This gives the overall correct behavior: for any perspective which isn't client A, there is no adjustment necessary anywhere (it's as if
262-
* the segment never existed). For client A's perspective, the segment should be considered visible until A has acked B's obliterate.
263-
* This is accomplished as for the perspective (A, refSeq):
264-
* - For refSeq < B's obliterate, the segment length will be included as part of the per-client adjustment for A
265-
* - For refSeq >= B's obliterate, the segment will be omitted from the per-client adjustment for A
259+
* A's per-client adjustments will again not include an entry for its own insert.
260+
* Instead, the entry which would normally contain `seq` equal to that of A's insert would instead have `seq` equal to that of B's obliterate.
261+
* This gives the overall correct behavior: for any perspective which isn't client A, there is no adjustment necessary anywhere (it's as if
262+
* the segment never existed). For client A's perspective, the segment should be considered visible until A has acked B's obliterate.
263+
* This is accomplished as for the perspective (A, refSeq):
264+
* 1. For refSeq \< B's obliterate, the segment length will be included as part of the per-client adjustment for A
265+
* 2. For refSeq \>= B's obliterate, the segment will be omitted from the per-client adjustment for A
266266
*
267267
* Note that the special-casing for inserting segments that are immediately obliterated is only necessary for segments that never were visible
268268
* in the tree. If an insert and obliterate are concurrent but the insert is sequenced first, the normal per-client adjustment is fine.
@@ -463,16 +463,7 @@ export class PartialSequenceLengths {
463463
}
464464
}
465465

466-
// TODO: Consider putting the overall length post-process bit back, but for now this should be handled
467-
// by addOrUpdate
468-
try {
469-
PartialSequenceLengths.options.verifier?.(combinedPartialLengths);
470-
} catch (err) {
471-
if (retry) {
472-
this.fromLeaves(block, collabWindow, computeLocalPartials, false);
473-
}
474-
throw err;
475-
}
466+
PartialSequenceLengths.options.verifier?.(combinedPartialLengths);
476467
return combinedPartialLengths;
477468
}
478469

@@ -506,16 +497,18 @@ export class PartialSequenceLengths {
506497
// Implication -> this is a local segment which will be obliterated as soon as it is acked.
507498
// For refSeqs preceding that movedSeq and localSeqs following the localSeq, it will be visible.
508499
// For the rest, it will not be visible.
500+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
501+
const localSeq = segment.localSeq!;
509502
partials.addOrUpdate({
510-
seq: segment.localSeq!,
503+
seq: localSeq,
511504
len: 0,
512505
seglen: segment.cachedLength,
513506
clientId,
514507
});
515508

516509
combinedPartialLengths.addLocalAdjustment({
517510
refSeq: moveInfo.movedSeq,
518-
localSeq: segment.localSeq!,
511+
localSeq,
519512
seglen: -segment.cachedLength,
520513
});
521514
} else {
@@ -850,18 +843,15 @@ export class PartialSequenceLengths {
850843
}
851844
segCount += branchPartialLengths.segmentCount;
852845

853-
// I kinda like the sparse loop, but Number.parseInt it forces is pretty ugly.
854-
for (const clientId in branchPartialLengths.perClientAdjustments) {
855-
const clientAdjustments = branchPartialLengths.perClientAdjustments[clientId];
856-
if (clientAdjustments === undefined) {
857-
continue;
858-
}
859-
860-
const leqPartial = clientAdjustments.latestLeq(seq);
861-
if (leqPartial && leqPartial.seq === seq) {
862-
this.addClientSeqNumber(Number.parseInt(clientId), seq, leqPartial.seglen);
846+
// The suggested for..of alternative doesn't give easy access to the index while
847+
// exploiting sparseness.
848+
// eslint-disable-next-line unicorn/no-array-for-each
849+
branchPartialLengths.perClientAdjustments.forEach((clientAdjustments, id) => {
850+
const leqBranchPartial = clientAdjustments.latestLeq(seq);
851+
if (leqBranchPartial && leqBranchPartial.seq === seq) {
852+
this.addClientSeqNumber(id, seq, leqBranchPartial.seglen);
863853
}
864-
}
854+
});
865855
}
866856
}
867857

@@ -1041,7 +1031,7 @@ export class PartialSequenceLengths {
10411031
}
10421032

10431033
/**
1044-
* @returns The partial lengths associated with the latest change associated with `clientId` at or before `refSeq`.
1034+
* Returns the partial lengths associated with the latest change associated with `clientId` at or before `refSeq`.
10451035
* Returns undefined if no such change exists.
10461036
*/
10471037
private latestClientEntryLEQ(
@@ -1052,7 +1042,7 @@ export class PartialSequenceLengths {
10521042
}
10531043

10541044
/**
1055-
* @returns The partial lengths associated with the most recent change received by `clientId`, or undefined
1045+
* Get the partial lengths associated with the most recent change received by `clientId`, or undefined
10561046
* if this client has made no changes in this block within the collab window.
10571047
*/
10581048
private latestClientEntry(clientId: number): PartialSequenceLength | undefined {

packages/dds/merge-tree/src/test/mergeTreeOperationRunner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,22 +367,22 @@ export function generateOperationMessagesForClients(
367367

368368
const len = client.getLength();
369369
const sg = client.peekPendingSegmentGroups();
370-
let op: IMergeTreeOp[] | IMergeTreeOp | undefined;
370+
let opOrOps: IMergeTreeOp[] | IMergeTreeOp | undefined;
371371
if (len === 0 || len < minLength) {
372-
op =
372+
opOrOps =
373373
insertText === undefined ? generateInsert(client, random) : insertText(client, random);
374374
} else {
375375
let opIndex = random.integer(0, operations.length - 1);
376376
const start = random.integer(0, len - 1);
377377
const end = random.integer(start + 1, len);
378378

379-
for (let y = 0; y < operations.length && op === undefined; y++) {
380-
op = operations[opIndex](client, start, end, random);
379+
for (let y = 0; y < operations.length && opOrOps === undefined; y++) {
380+
opOrOps = operations[opIndex](client, start, end, random);
381381
opIndex++;
382382
opIndex %= operations.length;
383383
}
384384
}
385-
if (op !== undefined) {
385+
if (opOrOps !== undefined) {
386386
// Pre-check to avoid logger.toString() in the string template
387387
if (sg === client.peekPendingSegmentGroups()) {
388388
assert.notEqual(
@@ -392,7 +392,7 @@ export function generateOperationMessagesForClients(
392392
);
393393
}
394394

395-
const ops = Array.isArray(op) ? op : [op];
395+
const ops = Array.isArray(opOrOps) ? opOrOps : [opOrOps];
396396
const totalIndividualOps = ops
397397
.map((o) => (o.type === MergeTreeDeltaType.GROUP ? o.ops.length : 1))
398398
.reduce((a, b) => a + b, 0);

packages/dds/merge-tree/src/test/obliterate.concurrent.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { strict as assert } from "node:assert";
88
import { LoggingError } from "@fluidframework/telemetry-utils/internal";
99

1010
import { MergeTree } from "../mergeTree.js";
11+
import { Side } from "../sequencePlace.js";
1112

1213
import { PartialSyncTestHelper } from "./partialSyncHelper.js";
1314
import { ReconnectTestHelper } from "./reconnectHelper.js";
1415
import { useStrictPartialLengthChecks } from "./testUtils.js";
15-
import { Side } from "../sequencePlace.js";
1616

1717
/**
1818
* Some tests contain ASCII diagrams of the trees to make it easier to reason about

packages/dds/merge-tree/src/test/obliterateOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const posInField = (
2020
client: TestClient,
2121
pos: number,
2222
): { startPos: number; endPos: number } | undefined => {
23-
const isFieldCharacter = (char: string) =>
23+
const isFieldCharacter = (char: string): boolean =>
2424
Number.isInteger(Number(char)) || char === "{" || char === "}";
2525
if (pos >= client.getLength() || !isFieldCharacter(client.getText(pos, pos + 1))) {
2626
// pos is not within a field.

packages/dds/merge-tree/src/test/partialSyncHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ export class PartialSyncTestHelper {
9999
"Cannot attempt to advance clients to sequence numbers that don't yet exist",
100100
);
101101
let startIndex: number;
102-
if (lastApplied !== undefined) {
102+
if (lastApplied === undefined) {
103+
startIndex = 0;
104+
} else {
103105
if (lastApplied >= seq) {
104106
return;
105107
}
106108
startIndex = lastApplied;
107-
} else {
108-
startIndex = 0;
109109
}
110110
for (let i = startIndex; i < seq; i++) {
111111
const nextMessage = this.ops[i];

0 commit comments

Comments
 (0)