Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect interval start & end side on ack #22945

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/dds/sequence/src/intervalCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@ export class IntervalCollection<TInterval extends ISerializableInterval>

private getSlideToSegment(
lref: LocalReferencePosition,
slidingPreference: SlidingPreference,
): { segment: ISegment | undefined; offset: number | undefined } | undefined {
if (!this.client) {
throw new LoggingError("client does not exist");
Expand All @@ -1640,7 +1641,7 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
}
const newSegoff = getSlideToSegoff(
segoff,
undefined,
slidingPreference,
this.options.mergeTreeReferencesCanSlideToEndpoint,
);
const value: { segment: ISegment | undefined; offset: number | undefined } | undefined =
Expand All @@ -1663,8 +1664,14 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
return;
}

const newStart = this.getSlideToSegment(interval.start);
const newEnd = this.getSlideToSegment(interval.end);
const newStart = this.getSlideToSegment(
interval.start,
startReferenceSlidingPreference(interval.stickiness),
);
const newEnd = this.getSlideToSegment(
interval.end,
endReferenceSlidingPreference(interval.stickiness),
);

const id = interval.properties[reservedIntervalIdKey];
const hasPendingStartChange = this.hasPendingChangeStart(id);
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/sequence/src/intervals/sequenceInterval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function createPositionReference(
referenceSequenceNumber: op.referenceSequenceNumber,
clientId: op.clientId,
});
segoff = getSlideToSegoff(segoff, undefined, useNewSlidingBehavior);
segoff = getSlideToSegoff(segoff, slidingPreference, useNewSlidingBehavior);
}
} else {
assert(
Expand Down
33 changes: 32 additions & 1 deletion packages/dds/sequence/src/test/intervalCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,38 @@ describe("SharedString interval collections", () => {
assertSequenceIntervals(sharedString, collection1, [{ start: 1, end: 2 }]);
});

it("can slide intervals on create ack", () => {
describe("respects interval slide preference on create", () => {
for (const { testName, side, expectedPos } of [
{ testName: "Side.Before -> prefer forward", side: Side.Before, expectedPos: 1 },
{ testName: "Side.After -> prefer backward", side: Side.After, expectedPos: 0 },
]) {
it(testName, () => {
const collection1 = sharedString.getIntervalCollection("test");
sharedString.insertText(0, "ABCD");
containerRuntimeFactory.processAllMessages();
const collection2 = sharedString2.getIntervalCollection("test");
sharedString.removeRange(1, 3);

collection2.add({
start: { pos: 1, side },
end: { pos: 2, side },
});

containerRuntimeFactory.processAllMessages();
assert.strictEqual(sharedString.getText(), "AD");
assert.strictEqual(sharedString2.getText(), "AD");

assertSequenceIntervals(sharedString, collection1, [
{ start: expectedPos, end: expectedPos },
]);
assertSequenceIntervals(sharedString2, collection2, [
{ start: expectedPos, end: expectedPos },
]);
});
}
});

it("can slide intervals backward on create ack", () => {
// Create and connect a third SharedString.
const dataStoreRuntime3 = new MockFluidDataStoreRuntime({ clientId: "3" });
const containerRuntime3 =
Expand Down
Loading