@fluid-experimental/tree 0.59.3000-66610 → 0.59.3001
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/dist/EditLog.js +2 -1
- package/dist/EditLog.js.map +1 -1
- package/lib/EditLog.js +2 -1
- package/lib/EditLog.js.map +1 -1
- package/package.json +16 -16
- package/src/EditLog.ts +1 -1
package/dist/EditLog.js
CHANGED
|
@@ -146,8 +146,9 @@ class EditLog extends common_utils_1.TypedEventEmitter {
|
|
|
146
146
|
* @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).
|
|
147
147
|
*/
|
|
148
148
|
isLocalEdit(editId) {
|
|
149
|
+
var _a;
|
|
149
150
|
const entry = this.allEditIds.get(editId);
|
|
150
|
-
return entry
|
|
151
|
+
return (_a = entry === null || entry === void 0 ? void 0 : entry.isLocal) !== null && _a !== void 0 ? _a : false;
|
|
151
152
|
}
|
|
152
153
|
/**
|
|
153
154
|
* @returns true iff the revision is a sequenced revision (not local).
|
package/dist/EditLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditLog.js","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,gEAAiC;AACjC,+DAAiE;AAEjE,qCAAiG;AAGjG,uDAAwG;AACxG,6CAAyD;AAmIzD;;GAEG;AACH,SAAgB,iBAAiB,CAAU,IAAmB;IAI7D,MAAM,aAAa,mCAAQ,IAAI,KAAE,EAAE,EAAE,SAAS,GAAE,CAAC;IACjD,OAAO,aAAa,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC;AAPD,8CAOC;AAED,SAAS,aAAa,CAAU,EAAU,EAAE,IAA4B;IACvE,uBAAS,EAAE,IAAK,IAAI,EAAG;AACxB,CAAC;AAED;;;GAGG;AACH,SAAgB,oCAAoC,C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AAc;QACnC,6FAA6F;QAC7F,IAAI,MAAM,IAAI,IAAI,CAAC,qBAAqB,EAAE;YACzC,sFAAsF;YACtF,IAAI,MAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBACpC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;aACvE;YAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAEnC,qEAAqE;YACrE,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,oBAAoB,EAAE;gBACxD,MAAM,YAAY,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;gBACvE,MAAM,YAAY,GAAG,IAAA,2BAAkB,EACtC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,EACjC,mEAAmE,CACnE,CAAC;gBACF,YAAY,CAAC,KAAK,GAAG,SAAS,CAAC;aAC/B;SACD;IACF,CAAC;CACD;AAxeD,0BAweC;AAED,SAAS,YAAY,CACpB,KAA8D;IAE9D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport type { IEvent, ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { assert, assertNotUndefined, compareArrays, compareFiniteNumbers, fail } from './Common';\nimport type { EditId } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport { Edit, EditLogSummary, editsPerChunk, EditWithoutId, FluidEditHandle } from './persisted-types';\nimport { SharedTreeDiagnosticEvent } from './EventTypes';\nimport type { ChangeCompressor } from './ChangeCompression';\n\n/**\n * An ordered set of Edits associated with a SharedTree.\n * Supports fast lookup of edits by ID and enforces idempotence.\n * Edits are virtualized, however, edits added during the current session are guaranteed to be available\n * synchronously.\n * @public\n * @sealed\n */\nexport interface OrderedEditSet<TChange = unknown> {\n\t/**\n\t * The length of this `OrderedEditSet`.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The edit IDs of all edits in the log.\n\t */\n\treadonly editIds: readonly EditId[];\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`.\n\t */\n\tgetIndexOfId(editId: EditId): number;\n\n\t/**\n\t * @returns the id of the edit at the given index within this 'OrderedEditSet'.\n\t */\n\tgetIdAtIndex(index: number): EditId;\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.\n\t */\n\ttryGetIndexOfId(editId: EditId): number | undefined;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t */\n\tgetEditAtIndex(index: number): Promise<Edit<TChange>>;\n\n\t/**\n\t * @returns the edit at the given index. Must have been added to the log during the current session.\n\t */\n\tgetEditInSessionAtIndex(index: number): Edit<TChange>;\n\n\t/**\n\t * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.\n\t */\n\ttryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface EditSequencingInfo {\n\t/**\n\t * The server-assigned sequence number of the op.\n\t */\n\treadonly sequenceNumber: number;\n\t/**\n\t * Last known sequenced edit at the time this op was issued.\n\t */\n\treadonly referenceSequenceNumber: number;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface MessageSequencingInfo extends EditSequencingInfo {\n\t/**\n\t * Last sequenced edit that all clients are guaranteed to be aware of.\n\t * If not specified, then some clients have not seen any edits yet.\n\t */\n\treadonly minimumSequenceNumber?: number;\n}\n\n/**\n * Metadata for a sequenced edit.\n */\nexport interface SequencedOrderedEditId {\n\treadonly isLocal: false;\n\treadonly index: number;\n\t/**\n\t * Information about the edit's relationship to other sequenced edits.\n\t * Undefined iff the edit was loaded from a summary.\n\t */\n\treadonly sequenceInfo?: EditSequencingInfo;\n}\n\n/**\n * Metadata for a local edit.\n */\nexport interface LocalOrderedEditId {\n\treadonly isLocal: true;\n\treadonly localSequence: number;\n}\n\n/**\n * Metadata for an edit.\n */\nexport type OrderedEditId = SequencedOrderedEditId | LocalOrderedEditId;\n\n/**\n * Compressor+interner pair used for encoding an {@link EditLog} into a summary.\n * @internal\n */\nexport interface EditLogEncoder {\n\tcompressor: ChangeCompressor;\n\tinterner: StringInterner;\n}\n\n/**\n * A sequence of edits that may or may not need to be downloaded into the EditLog from an external service\n */\nexport interface EditChunk<TChange> {\n\thandle?: EditHandle<TChange>;\n\tedits?: EditWithoutId<TChange>[];\n}\n\n/**\n * EditHandles are used to load edit chunks stored outside of the EditLog.\n * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.\n * @public\n */\nexport interface EditHandle<TChange> {\n\treadonly get: () => Promise<EditWithoutId<TChange>[]>;\n\treadonly baseHandle: FluidEditHandle;\n}\n\n/**\n * Returns an object that separates an Edit into two fields, id and editWithoutId.\n */\nexport function separateEditAndId<TChange>(edit: Edit<TChange>): {\n\tid: EditId;\n\teditWithoutId: EditWithoutId<TChange>;\n} {\n\tconst editWithoutId = { ...edit, id: undefined };\n\tdelete editWithoutId.id;\n\treturn { id: edit.id, editWithoutId };\n}\n\nfunction joinEditAndId<TChange>(id: EditId, edit: EditWithoutId<TChange>): Edit<TChange> {\n\treturn { id, ...edit };\n}\n\n/**\n * @param summary - The edit log summary to parse.\n * @returns the number of handles saved to the provided edit log summary.\n */\nexport function getNumberOfHandlesFromEditLogSummary(summary: EditLogSummary<unknown, unknown>): number {\n\tconst { editChunks } = summary;\n\n\tlet numberOfHandles = 0;\n\teditChunks.forEach(({ chunk }) => {\n\t\tif (!Array.isArray(chunk)) {\n\t\t\tnumberOfHandles++;\n\t\t}\n\t});\n\n\treturn numberOfHandles;\n}\n\n/**\n * The number of blobs to be loaded in memory at any time.\n * TODO:#49901: Change cache size once the virtualized history summary format is being written.\n * \t\t This is so the summarizer doesn't have to reload every edit to generate summaries.\n * */\nconst loadedChunkCacheSize = Number.POSITIVE_INFINITY;\n\n/**\n * Event fired when an edit is added to an `EditLog`.\n * @param edit - The edit that was added to the log\n * @param isLocal - true iff this edit was generated locally\n */\nexport type EditAddedHandler<TChange> = (edit: Edit<TChange>, isLocal: boolean, wasLocal: boolean) => void;\n\n/**\n * Events which may be emitted by `EditLog`.\n * @public\n */\nexport interface IEditLogEvents extends IEvent {\n\t(event: 'unexpectedHistoryChunk', listener: () => void);\n}\n\n/**\n * The edit history log for SharedTree.\n * Contains only completed edits (no in-progress edits).\n * Ordered first by locality (acked or local), then by time of insertion.\n * May not contain more than one edit with the same ID.\n * @sealed\n */\nexport class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents> implements OrderedEditSet<TChange> {\n\tprivate localEditSequence = 0;\n\tprivate _minSequenceNumber = 0;\n\n\tprivate readonly sequencedEditIds: EditId[];\n\tprivate readonly editChunks: BTree<number, EditChunk<TChange>>;\n\tprivate readonly localEdits: Edit<TChange>[] = [];\n\tprivate readonly loadedChunkCache: number[] = [];\n\tprivate readonly indexOfFirstEditInSession: number;\n\tprivate readonly maximumEvictableIndex: number;\n\n\tprivate readonly allEditIds: Map<EditId, OrderedEditId> = new Map();\n\tprivate readonly _editAddedHandlers: Set<EditAddedHandler<TChange>> = new Set();\n\n\tprivate readonly logger?: ITelemetryLogger;\n\n\t/**\n\t * The number of edits associated with each blob.\n\t */\n\tpublic readonly editsPerChunk: number;\n\n\t/**\n\t * @returns The index of the earliest edit available through `getEditInSessionAtIndex`.\n\t */\n\tpublic get earliestAvailableEditIndex(): number {\n\t\treturn this.maximumEvictableIndex + 1;\n\t}\n\n\t/**\n\t * @returns The sequence number of the latest edit known by all nodes.\n\t */\n\tpublic get minSequenceNumber(): number {\n\t\treturn this._minSequenceNumber;\n\t}\n\n\t/**\n\t * Construct an `EditLog` using the given options.\n\t * @param summary - An edit log summary used to populate the edit log.\n\t * @param logger - An optional logger to record telemetry/errors\n\t */\n\tpublic constructor(\n\t\tsummary: EditLogSummary<TChange, EditHandle<TChange>> = { editIds: [], editChunks: [] },\n\t\tlogger?: ITelemetryLogger,\n\t\teditAddedHandlers: readonly EditAddedHandler<TChange>[] = [],\n\t\tindexOfFirstEditInSession = summary.editIds.length\n\t) {\n\t\tsuper();\n\t\tconst { editChunks, editIds } = summary;\n\t\tthis.logger = logger;\n\t\tthis.editsPerChunk = editsPerChunk;\n\n\t\tfor (const handler of editAddedHandlers) {\n\t\t\tthis.registerEditAddedHandler(handler);\n\t\t}\n\n\t\tthis.editChunks = new BTree<number, EditChunk<TChange>>(undefined, compareFiniteNumbers);\n\n\t\teditChunks.forEach((editChunkOrHandle) => {\n\t\t\tconst { startRevision, chunk } = editChunkOrHandle;\n\n\t\t\tif (isEditHandle(chunk)) {\n\t\t\t\tthis.editChunks.set(startRevision, { handle: chunk });\n\t\t\t} else {\n\t\t\t\tthis.editChunks.set(startRevision, { edits: chunk as EditWithoutId<TChange>[] });\n\t\t\t}\n\t\t});\n\n\t\tthis.sequencedEditIds = editIds.slice();\n\n\t\tthis.indexOfFirstEditInSession = indexOfFirstEditInSession;\n\t\tthis.maximumEvictableIndex = this.indexOfFirstEditInSession - 1;\n\n\t\tthis.sequencedEditIds.forEach((id, index) => {\n\t\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\t\tassert(encounteredEditId === undefined, 'Duplicate acked edit.');\n\t\t\tthis.allEditIds.set(id, { isLocal: false, index });\n\t\t});\n\t}\n\n\t/**\n\t * Registers a handler for when an edit is added to this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditAddedHandler(handler: EditAddedHandler<TChange>): () => void {\n\t\tthis._editAddedHandlers.add(handler);\n\t\treturn () => this._editAddedHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditAddedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editAddedHandlers(): readonly EditAddedHandler<TChange>[] {\n\t\treturn Array.from(this._editAddedHandlers);\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.length}\n\t */\n\tpublic get length(): number {\n\t\treturn this.numberOfSequencedEdits + this.numberOfLocalEdits;\n\t}\n\n\t/**\n\t * The number of sequenced (acked) edits in the log.\n\t */\n\tpublic get numberOfSequencedEdits(): number {\n\t\treturn this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * The number of local (unacked) edits in the log.\n\t */\n\tpublic get numberOfLocalEdits(): number {\n\t\treturn this.localEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.editIds}\n\t */\n\tpublic get editIds(): EditId[] {\n\t\treturn this.sequencedEditIds.concat(this.localEdits.map(({ id }) => id));\n\t}\n\n\t/**\n\t * @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).\n\t */\n\tpublic isLocalEdit(editId: EditId): boolean {\n\t\tconst entry = this.allEditIds.get(editId);\n\t\treturn entry !== undefined && entry.isLocal;\n\t}\n\n\t/**\n\t * @returns true iff the revision is a sequenced revision (not local).\n\t */\n\tpublic isSequencedRevision(revision: number): boolean {\n\t\treturn revision <= this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetIndexOfId}\n\t */\n\tpublic tryGetIndexOfId(editId: EditId): number | undefined {\n\t\tconst orderedEdit = this.allEditIds.get(editId);\n\t\tif (orderedEdit === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (orderedEdit.isLocal) {\n\t\t\tconst firstLocal = assertNotUndefined(this.allEditIds.get(this.localEdits[0].id));\n\t\t\tassert(firstLocal.isLocal);\n\t\t\treturn this.numberOfSequencedEdits + orderedEdit.localSequence - firstLocal.localSequence;\n\t\t}\n\t\treturn orderedEdit.index;\n\t}\n\n\t/**\n\t * @returns Edit metadata for the edit with the given `editId`.\n\t */\n\tpublic getOrderedEditId(editId: EditId): OrderedEditId {\n\t\treturn assertNotUndefined(this.allEditIds.get(editId), 'All edits should exist in this map');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIndexOfId}\n\t */\n\tpublic getIndexOfId(editId: EditId): number {\n\t\treturn this.tryGetIndexOfId(editId) ?? fail('edit not found');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIdAtIndex}\n\t */\n\tpublic getIdAtIndex(index: number): EditId {\n\t\tif (this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits].id;\n\t\t}\n\n\t\treturn this.sequencedEditIds[index];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditAtIndex}\n\t */\n\tpublic async getEditAtIndex(index: number): Promise<Edit<TChange>> {\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { handle, edits } = editChunk;\n\n\t\t\tif (edits === undefined) {\n\t\t\t\tassert(handle !== undefined, 'An edit chunk should include at least a handle or edits.');\n\t\t\t\tconst edits = await handle.get();\n\n\t\t\t\t// Make sure the loaded edit chunk is the correct size. If a higher starting revison is set, the length is the difference of both.\n\t\t\t\t// Otherwise, it means that there are no sequenced edits in memory so the length is the difference of the number of\n\t\t\t\t// sequenced edits and the starting revision.\n\t\t\t\tconst nextKey = this.editChunks.nextHigherKey(index);\n\t\t\t\tconst expectedEditLength =\n\t\t\t\t\t(nextKey === undefined ? this.numberOfSequencedEdits : nextKey) - startRevision;\n\t\t\t\tassert(edits.length === expectedEditLength, 'The chunk does not contain the correct number of edits.');\n\n\t\t\t\teditChunk.edits = edits;\n\n\t\t\t\tthis.addKeyToCache(startRevision);\n\t\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t\t}\n\n\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t}\n\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditInSessionAtIndex}\n\t */\n\tpublic getEditInSessionAtIndex(index: number): Edit<TChange> {\n\t\tassert(\n\t\t\tindex > this.maximumEvictableIndex,\n\t\t\t'Edit to retrieve must have been added to the log during the current session.'\n\t\t);\n\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { edits } = editChunk;\n\n\t\t\treturn joinEditAndId(\n\t\t\t\tthis.getIdAtIndex(index),\n\t\t\t\tassertNotUndefined(edits, 'Edits should not have been evicted.')[index - startRevision]\n\t\t\t);\n\t\t}\n\n\t\tassert(index - this.numberOfSequencedEdits < this.localEdits.length, 'Edit to retrieve must be in the log.');\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEdit}\n\t */\n\tpublic async tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined> {\n\t\ttry {\n\t\t\tconst index = this.getIndexOfId(editId);\n\t\t\treturn await this.getEditAtIndex(index);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * @returns The edits of edit chunks that do not have associated edit handles, does not include the last edit chunk if it is not full.\n\t */\n\tpublic *getEditChunksReadyForUpload(): Iterable<[number, readonly EditWithoutId<TChange>[]]> {\n\t\tconst maxStartRevision = this.editChunks.maxKey();\n\n\t\tif (maxStartRevision === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const [startRevision, chunk] of this.editChunks.entries(undefined, [])) {\n\t\t\tif (chunk.handle === undefined) {\n\t\t\t\tconst edits = assertNotUndefined(chunk.edits);\n\n\t\t\t\t// If there is no handle, the chunk should either not be the last chunk or should be full if it is.\n\t\t\t\tif (maxStartRevision !== startRevision || edits.length >= this.editsPerChunk) {\n\t\t\t\t\tyield [startRevision, edits];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Assigns provided handles to edit chunks based on chunk index specified.\n\t */\n\tpublic processEditChunkHandle(chunkHandle: EditHandle<TChange>, startRevision: number): void {\n\t\tconst chunk = this.editChunks.get(startRevision);\n\t\tif (chunk !== undefined) {\n\t\t\tassertNotUndefined(\n\t\t\t\tchunk.edits,\n\t\t\t\t'A chunk handle op should not be received before the edit ops it corresponds to.'\n\t\t\t);\n\t\t\tchunk.handle = chunkHandle;\n\t\t\tthis.addKeyToCache(startRevision);\n\t\t} else {\n\t\t\tthis.logger?.sendErrorEvent({ eventName: 'UnexpectedHistoryChunk' });\n\t\t\tthis.emit(SharedTreeDiagnosticEvent.UnexpectedHistoryChunk);\n\t\t}\n\t}\n\n\t/**\n\t * Sequences all local edits.\n\t */\n\tpublic sequenceLocalEdits(): void {\n\t\tthis.localEdits.slice().forEach((edit) => this.addSequencedEditInternal(edit));\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t *\n\t */\n\tpublic addSequencedEdit(edit: Edit<TChange>, message: MessageSequencingInfo): void {\n\t\tthis.addSequencedEditInternal(edit, message, message.minimumSequenceNumber);\n\t}\n\n\t/**\n\t * Returns all local edits from this EditLog\n\t * This is useful for op format upgrades, which might warrant re-submission of these ops using the new format.\n\t * See the breaking change documentation for more information.\n\t */\n\tpublic *getLocalEdits(): Iterable<Edit<TChange>> {\n\t\tfor (const edit of this.localEdits) {\n\t\t\tyield edit;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t */\n\tprivate addSequencedEditInternal(\n\t\tedit: Edit<TChange>,\n\t\tinfo?: EditSequencingInfo,\n\t\tminSequenceNumber: number = 0\n\t): void {\n\t\tconst { id, editWithoutId } = separateEditAndId(edit);\n\n\t\tassert(\n\t\t\tminSequenceNumber >= this.minSequenceNumber,\n\t\t\t'Sequenced edits should carry a monotonically increasing min number'\n\t\t);\n\t\t// The new minSequenceNumber indicates that no future edit will require information from edits with a smaller or equal seq number\n\t\t// for its resolution.\n\t\tthis._minSequenceNumber = minSequenceNumber;\n\t\t// TODO:#57176: Increment maximumEvictableIndex to reflect the fact we can now evict edits with a sequenceNumber lower or equal to\n\t\t// it. Note that this will change the meaning of our 'InSession' APIs so we should make sure to rename them at the same time.\n\t\t// The code might look like this:\n\t\t// while (this.maximumEvictableIndex + 1 < this.indexOfFirstEditInSession) {\n\t\t// \tconst nextEdit = this.getEditInSessionAtIndex(this.maximumEvictableIndex + 1);\n\t\t// \tconst nextEditInfo = this.getOrderedEditId(nextEdit.id) as SequencedOrderedEditId;\n\t\t// \tif (\n\t\t// \t\tnextEditInfo.sequenceInfo !== undefined &&\n\t\t// \t\tnextEditInfo.sequenceInfo.sequenceNumber > minSequenceNumber\n\t\t// \t) {\n\t\t// \t\tbreak;\n\t\t// \t}\n\t\t// \t++this.maximumEvictableIndex;\n\t\t// }\n\n\t\t// Remove the edit from local edits if it exists.\n\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\tif (encounteredEditId !== undefined) {\n\t\t\t// New edit already exits: it must have been a local edit.\n\t\t\tassert(encounteredEditId.isLocal, 'Duplicate acked edit.');\n\t\t\t// Remove it from localEdits. Due to ordering requirements, it must be first.\n\t\t\tconst oldLocalEditId = assertNotUndefined(this.localEdits.shift(), 'Local edit should exist').id;\n\t\t\tassert(oldLocalEditId === id, 'Causal ordering should be upheld');\n\t\t}\n\n\t\t// The starting revision for a newly created chunk.\n\t\tconst startRevision = this.numberOfSequencedEdits;\n\t\t// The initial edits for a newly created chunk.\n\t\tconst edits: EditWithoutId<TChange>[] = [editWithoutId];\n\n\t\tconst lastPair = this.editChunks.nextLowerPair(undefined);\n\t\tif (lastPair === undefined) {\n\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t} else {\n\t\t\t// Add to the last edit chunk if it has room and hasn't already been uploaded, otherwise create a new chunk.\n\t\t\t// If the chunk has a corresponding handle, create a new chunk.\n\t\t\tconst { edits: lastEditChunk, handle } = lastPair[1];\n\t\t\tif (handle === undefined && lastEditChunk !== undefined && lastEditChunk.length < this.editsPerChunk) {\n\t\t\t\tlastEditChunk.push(editWithoutId);\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\thandle !== undefined || lastEditChunk !== undefined,\n\t\t\t\t\t'An edit chunk must have either a handle or a list of edits.'\n\t\t\t\t);\n\t\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t\t}\n\t\t}\n\n\t\tthis.sequencedEditIds.push(id);\n\t\tconst sequencedEditId: SequencedOrderedEditId = {\n\t\t\tindex: this.numberOfSequencedEdits - 1,\n\t\t\tisLocal: false,\n\t\t\tsequenceInfo: info,\n\t\t};\n\t\tthis.allEditIds.set(id, sequencedEditId);\n\t\tthis.emitAdd(edit, false, encounteredEditId !== undefined);\n\t}\n\n\t/**\n\t * @returns The last edit chunk i.e. the chunk which the most recent sequenced edits have been placed into, as well as its starting revision.\n\t * Returns undefined iff there are no sequenced edits.\n\t * When defined, this chunk is guaranteed to contain at least one edit\n\t * (though it may be necessary to load the chunk via its handle to use it)\n\t */\n\tpublic getLastEditChunk(): [startRevision: number, edits: EditChunk<TChange>] | undefined {\n\t\treturn this.editChunks.nextLowerPair(undefined);\n\t}\n\n\t/**\n\t * Adds a non-sequenced (local) edit to the edit log.\n\t * Duplicate edits are ignored.\n\t */\n\tpublic addLocalEdit(edit: Edit<TChange>): void {\n\t\tthis.localEdits.push(edit);\n\t\tconst localEditId: LocalOrderedEditId = { localSequence: this.localEditSequence++, isLocal: true };\n\t\tthis.allEditIds.set(edit.id, localEditId);\n\t\tthis.emitAdd(edit, true, false);\n\t}\n\n\tprivate emitAdd(editAdded: Edit<TChange>, isLocal: boolean, wasLocal: boolean): void {\n\t\tfor (const handler of this._editAddedHandlers) {\n\t\t\thandler(editAdded, isLocal, wasLocal);\n\t\t}\n\t}\n\n\t/**\n\t * @returns true iff this `EditLog` and `other` are equivalent, regardless of locality.\n\t */\n\tpublic equals<TOtherChangeTypesInternal>(other: EditLog<TOtherChangeTypesInternal>): boolean {\n\t\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\t\treturn compareArrays(this.editIds, other.editIds);\n\t}\n\n\t/**\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary(): EditLogSummary<TChange, FluidEditHandle>;\n\t/**\n\t * @param compressEdit - a function which compresses edits\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TCompressedChange, FluidEditHandle>;\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit?: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TChange, FluidEditHandle> | EditLogSummary<TCompressedChange, FluidEditHandle> {\n\t\tif (compressEdit !== undefined) {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits?.map((edit) => compressEdit(edit)) ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate addKeyToCache(newKey: number): void {\n\t\t// Indices are only added to the cache if they are not higher than the maximum evicted index.\n\t\tif (newKey <= this.maximumEvictableIndex) {\n\t\t\t// If the new index is already in the cache, remove it first to update its last usage.\n\t\t\tif (newKey in this.loadedChunkCache) {\n\t\t\t\tthis.loadedChunkCache.splice(this.loadedChunkCache.indexOf(newKey), 1);\n\t\t\t}\n\n\t\t\tthis.loadedChunkCache.push(newKey);\n\n\t\t\t// If the cache is out of space, evict the oldest index in the cache.\n\t\t\tif (this.loadedChunkCache.length > loadedChunkCacheSize) {\n\t\t\t\tconst indexToEvict = assertNotUndefined(this.loadedChunkCache.shift());\n\t\t\t\tconst chunkToEvict = assertNotUndefined(\n\t\t\t\t\tthis.editChunks.get(indexToEvict),\n\t\t\t\t\t'Chunk start revision added to cache should exist in the edit log.'\n\t\t\t\t);\n\t\t\t\tchunkToEvict.edits = undefined;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isEditHandle<TChange>(\n\tchunk: EditHandle<TChange> | readonly EditWithoutId<unknown>[]\n): chunk is EditHandle<TChange> {\n\treturn !Array.isArray(chunk);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditLog.js","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,gEAAiC;AACjC,+DAAiE;AAEjE,qCAAiG;AAGjG,uDAAwG;AACxG,6CAAyD;AAmIzD;;GAEG;AACH,SAAgB,iBAAiB,CAAU,IAAmB;IAI7D,MAAM,aAAa,mCAAQ,IAAI,KAAE,EAAE,EAAE,SAAS,GAAE,CAAC;IACjD,OAAO,aAAa,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,IA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AM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,mCAClB,KAAK,mCACL,IAAA,aAAI,EAAC,6DAA6D,CAAC;qBACpE,CAAC,CAAA;iBAAA,CAAC;gBACH,OAAO,EAAE,IAAI,CAAC,gBAAgB;aAC9B,CAAC;SACF;IACF,CAAC;IAEO,aAAa,CAAC,MAAc;QACnC,6FAA6F;QAC7F,IAAI,MAAM,IAAI,IAAI,CAAC,qBAAqB,EAAE;YACzC,sFAAsF;YACtF,IAAI,MAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBACpC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;aACvE;YAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAEnC,qEAAqE;YACrE,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,oBAAoB,EAAE;gBACxD,MAAM,YAAY,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;gBACvE,MAAM,YAAY,GAAG,IAAA,2BAAkB,EACtC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,EACjC,mEAAmE,CACnE,CAAC;gBACF,YAAY,CAAC,KAAK,GAAG,SAAS,CAAC;aAC/B;SACD;IACF,CAAC;CACD;AAxeD,0BAweC;AAED,SAAS,YAAY,CACpB,KAA8D;IAE9D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport type { IEvent, ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { assert, assertNotUndefined, compareArrays, compareFiniteNumbers, fail } from './Common';\nimport type { EditId } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport { Edit, EditLogSummary, editsPerChunk, EditWithoutId, FluidEditHandle } from './persisted-types';\nimport { SharedTreeDiagnosticEvent } from './EventTypes';\nimport type { ChangeCompressor } from './ChangeCompression';\n\n/**\n * An ordered set of Edits associated with a SharedTree.\n * Supports fast lookup of edits by ID and enforces idempotence.\n * Edits are virtualized, however, edits added during the current session are guaranteed to be available\n * synchronously.\n * @public\n * @sealed\n */\nexport interface OrderedEditSet<TChange = unknown> {\n\t/**\n\t * The length of this `OrderedEditSet`.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The edit IDs of all edits in the log.\n\t */\n\treadonly editIds: readonly EditId[];\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`.\n\t */\n\tgetIndexOfId(editId: EditId): number;\n\n\t/**\n\t * @returns the id of the edit at the given index within this 'OrderedEditSet'.\n\t */\n\tgetIdAtIndex(index: number): EditId;\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.\n\t */\n\ttryGetIndexOfId(editId: EditId): number | undefined;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t */\n\tgetEditAtIndex(index: number): Promise<Edit<TChange>>;\n\n\t/**\n\t * @returns the edit at the given index. Must have been added to the log during the current session.\n\t */\n\tgetEditInSessionAtIndex(index: number): Edit<TChange>;\n\n\t/**\n\t * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.\n\t */\n\ttryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface EditSequencingInfo {\n\t/**\n\t * The server-assigned sequence number of the op.\n\t */\n\treadonly sequenceNumber: number;\n\t/**\n\t * Last known sequenced edit at the time this op was issued.\n\t */\n\treadonly referenceSequenceNumber: number;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface MessageSequencingInfo extends EditSequencingInfo {\n\t/**\n\t * Last sequenced edit that all clients are guaranteed to be aware of.\n\t * If not specified, then some clients have not seen any edits yet.\n\t */\n\treadonly minimumSequenceNumber?: number;\n}\n\n/**\n * Metadata for a sequenced edit.\n */\nexport interface SequencedOrderedEditId {\n\treadonly isLocal: false;\n\treadonly index: number;\n\t/**\n\t * Information about the edit's relationship to other sequenced edits.\n\t * Undefined iff the edit was loaded from a summary.\n\t */\n\treadonly sequenceInfo?: EditSequencingInfo;\n}\n\n/**\n * Metadata for a local edit.\n */\nexport interface LocalOrderedEditId {\n\treadonly isLocal: true;\n\treadonly localSequence: number;\n}\n\n/**\n * Metadata for an edit.\n */\nexport type OrderedEditId = SequencedOrderedEditId | LocalOrderedEditId;\n\n/**\n * Compressor+interner pair used for encoding an {@link EditLog} into a summary.\n * @internal\n */\nexport interface EditLogEncoder {\n\tcompressor: ChangeCompressor;\n\tinterner: StringInterner;\n}\n\n/**\n * A sequence of edits that may or may not need to be downloaded into the EditLog from an external service\n */\nexport interface EditChunk<TChange> {\n\thandle?: EditHandle<TChange>;\n\tedits?: EditWithoutId<TChange>[];\n}\n\n/**\n * EditHandles are used to load edit chunks stored outside of the EditLog.\n * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.\n * @public\n */\nexport interface EditHandle<TChange> {\n\treadonly get: () => Promise<EditWithoutId<TChange>[]>;\n\treadonly baseHandle: FluidEditHandle;\n}\n\n/**\n * Returns an object that separates an Edit into two fields, id and editWithoutId.\n */\nexport function separateEditAndId<TChange>(edit: Edit<TChange>): {\n\tid: EditId;\n\teditWithoutId: EditWithoutId<TChange>;\n} {\n\tconst editWithoutId = { ...edit, id: undefined };\n\tdelete editWithoutId.id;\n\treturn { id: edit.id, editWithoutId };\n}\n\nfunction joinEditAndId<TChange>(id: EditId, edit: EditWithoutId<TChange>): Edit<TChange> {\n\treturn { id, ...edit };\n}\n\n/**\n * @param summary - The edit log summary to parse.\n * @returns the number of handles saved to the provided edit log summary.\n */\nexport function getNumberOfHandlesFromEditLogSummary(summary: EditLogSummary<unknown, unknown>): number {\n\tconst { editChunks } = summary;\n\n\tlet numberOfHandles = 0;\n\teditChunks.forEach(({ chunk }) => {\n\t\tif (!Array.isArray(chunk)) {\n\t\t\tnumberOfHandles++;\n\t\t}\n\t});\n\n\treturn numberOfHandles;\n}\n\n/**\n * The number of blobs to be loaded in memory at any time.\n * TODO:#49901: Change cache size once the virtualized history summary format is being written.\n * \t\t This is so the summarizer doesn't have to reload every edit to generate summaries.\n * */\nconst loadedChunkCacheSize = Number.POSITIVE_INFINITY;\n\n/**\n * Event fired when an edit is added to an `EditLog`.\n * @param edit - The edit that was added to the log\n * @param isLocal - true iff this edit was generated locally\n */\nexport type EditAddedHandler<TChange> = (edit: Edit<TChange>, isLocal: boolean, wasLocal: boolean) => void;\n\n/**\n * Events which may be emitted by `EditLog`.\n * @public\n */\nexport interface IEditLogEvents extends IEvent {\n\t(event: 'unexpectedHistoryChunk', listener: () => void);\n}\n\n/**\n * The edit history log for SharedTree.\n * Contains only completed edits (no in-progress edits).\n * Ordered first by locality (acked or local), then by time of insertion.\n * May not contain more than one edit with the same ID.\n * @sealed\n */\nexport class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents> implements OrderedEditSet<TChange> {\n\tprivate localEditSequence = 0;\n\tprivate _minSequenceNumber = 0;\n\n\tprivate readonly sequencedEditIds: EditId[];\n\tprivate readonly editChunks: BTree<number, EditChunk<TChange>>;\n\tprivate readonly localEdits: Edit<TChange>[] = [];\n\tprivate readonly loadedChunkCache: number[] = [];\n\tprivate readonly indexOfFirstEditInSession: number;\n\tprivate readonly maximumEvictableIndex: number;\n\n\tprivate readonly allEditIds: Map<EditId, OrderedEditId> = new Map();\n\tprivate readonly _editAddedHandlers: Set<EditAddedHandler<TChange>> = new Set();\n\n\tprivate readonly logger?: ITelemetryLogger;\n\n\t/**\n\t * The number of edits associated with each blob.\n\t */\n\tpublic readonly editsPerChunk: number;\n\n\t/**\n\t * @returns The index of the earliest edit available through `getEditInSessionAtIndex`.\n\t */\n\tpublic get earliestAvailableEditIndex(): number {\n\t\treturn this.maximumEvictableIndex + 1;\n\t}\n\n\t/**\n\t * @returns The sequence number of the latest edit known by all nodes.\n\t */\n\tpublic get minSequenceNumber(): number {\n\t\treturn this._minSequenceNumber;\n\t}\n\n\t/**\n\t * Construct an `EditLog` using the given options.\n\t * @param summary - An edit log summary used to populate the edit log.\n\t * @param logger - An optional logger to record telemetry/errors\n\t */\n\tpublic constructor(\n\t\tsummary: EditLogSummary<TChange, EditHandle<TChange>> = { editIds: [], editChunks: [] },\n\t\tlogger?: ITelemetryLogger,\n\t\teditAddedHandlers: readonly EditAddedHandler<TChange>[] = [],\n\t\tindexOfFirstEditInSession = summary.editIds.length\n\t) {\n\t\tsuper();\n\t\tconst { editChunks, editIds } = summary;\n\t\tthis.logger = logger;\n\t\tthis.editsPerChunk = editsPerChunk;\n\n\t\tfor (const handler of editAddedHandlers) {\n\t\t\tthis.registerEditAddedHandler(handler);\n\t\t}\n\n\t\tthis.editChunks = new BTree<number, EditChunk<TChange>>(undefined, compareFiniteNumbers);\n\n\t\teditChunks.forEach((editChunkOrHandle) => {\n\t\t\tconst { startRevision, chunk } = editChunkOrHandle;\n\n\t\t\tif (isEditHandle(chunk)) {\n\t\t\t\tthis.editChunks.set(startRevision, { handle: chunk });\n\t\t\t} else {\n\t\t\t\tthis.editChunks.set(startRevision, { edits: chunk as EditWithoutId<TChange>[] });\n\t\t\t}\n\t\t});\n\n\t\tthis.sequencedEditIds = editIds.slice();\n\n\t\tthis.indexOfFirstEditInSession = indexOfFirstEditInSession;\n\t\tthis.maximumEvictableIndex = this.indexOfFirstEditInSession - 1;\n\n\t\tthis.sequencedEditIds.forEach((id, index) => {\n\t\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\t\tassert(encounteredEditId === undefined, 'Duplicate acked edit.');\n\t\t\tthis.allEditIds.set(id, { isLocal: false, index });\n\t\t});\n\t}\n\n\t/**\n\t * Registers a handler for when an edit is added to this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditAddedHandler(handler: EditAddedHandler<TChange>): () => void {\n\t\tthis._editAddedHandlers.add(handler);\n\t\treturn () => this._editAddedHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditAddedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editAddedHandlers(): readonly EditAddedHandler<TChange>[] {\n\t\treturn Array.from(this._editAddedHandlers);\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.length}\n\t */\n\tpublic get length(): number {\n\t\treturn this.numberOfSequencedEdits + this.numberOfLocalEdits;\n\t}\n\n\t/**\n\t * The number of sequenced (acked) edits in the log.\n\t */\n\tpublic get numberOfSequencedEdits(): number {\n\t\treturn this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * The number of local (unacked) edits in the log.\n\t */\n\tpublic get numberOfLocalEdits(): number {\n\t\treturn this.localEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.editIds}\n\t */\n\tpublic get editIds(): EditId[] {\n\t\treturn this.sequencedEditIds.concat(this.localEdits.map(({ id }) => id));\n\t}\n\n\t/**\n\t * @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).\n\t */\n\tpublic isLocalEdit(editId: EditId): boolean {\n\t\tconst entry = this.allEditIds.get(editId);\n\t\treturn entry?.isLocal ?? false;\n\t}\n\n\t/**\n\t * @returns true iff the revision is a sequenced revision (not local).\n\t */\n\tpublic isSequencedRevision(revision: number): boolean {\n\t\treturn revision <= this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetIndexOfId}\n\t */\n\tpublic tryGetIndexOfId(editId: EditId): number | undefined {\n\t\tconst orderedEdit = this.allEditIds.get(editId);\n\t\tif (orderedEdit === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (orderedEdit.isLocal) {\n\t\t\tconst firstLocal = assertNotUndefined(this.allEditIds.get(this.localEdits[0].id));\n\t\t\tassert(firstLocal.isLocal);\n\t\t\treturn this.numberOfSequencedEdits + orderedEdit.localSequence - firstLocal.localSequence;\n\t\t}\n\t\treturn orderedEdit.index;\n\t}\n\n\t/**\n\t * @returns Edit metadata for the edit with the given `editId`.\n\t */\n\tpublic getOrderedEditId(editId: EditId): OrderedEditId {\n\t\treturn assertNotUndefined(this.allEditIds.get(editId), 'All edits should exist in this map');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIndexOfId}\n\t */\n\tpublic getIndexOfId(editId: EditId): number {\n\t\treturn this.tryGetIndexOfId(editId) ?? fail('edit not found');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIdAtIndex}\n\t */\n\tpublic getIdAtIndex(index: number): EditId {\n\t\tif (this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits].id;\n\t\t}\n\n\t\treturn this.sequencedEditIds[index];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditAtIndex}\n\t */\n\tpublic async getEditAtIndex(index: number): Promise<Edit<TChange>> {\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { handle, edits } = editChunk;\n\n\t\t\tif (edits === undefined) {\n\t\t\t\tassert(handle !== undefined, 'An edit chunk should include at least a handle or edits.');\n\t\t\t\tconst edits = await handle.get();\n\n\t\t\t\t// Make sure the loaded edit chunk is the correct size. If a higher starting revison is set, the length is the difference of both.\n\t\t\t\t// Otherwise, it means that there are no sequenced edits in memory so the length is the difference of the number of\n\t\t\t\t// sequenced edits and the starting revision.\n\t\t\t\tconst nextKey = this.editChunks.nextHigherKey(index);\n\t\t\t\tconst expectedEditLength =\n\t\t\t\t\t(nextKey === undefined ? this.numberOfSequencedEdits : nextKey) - startRevision;\n\t\t\t\tassert(edits.length === expectedEditLength, 'The chunk does not contain the correct number of edits.');\n\n\t\t\t\teditChunk.edits = edits;\n\n\t\t\t\tthis.addKeyToCache(startRevision);\n\t\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t\t}\n\n\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t}\n\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditInSessionAtIndex}\n\t */\n\tpublic getEditInSessionAtIndex(index: number): Edit<TChange> {\n\t\tassert(\n\t\t\tindex > this.maximumEvictableIndex,\n\t\t\t'Edit to retrieve must have been added to the log during the current session.'\n\t\t);\n\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { edits } = editChunk;\n\n\t\t\treturn joinEditAndId(\n\t\t\t\tthis.getIdAtIndex(index),\n\t\t\t\tassertNotUndefined(edits, 'Edits should not have been evicted.')[index - startRevision]\n\t\t\t);\n\t\t}\n\n\t\tassert(index - this.numberOfSequencedEdits < this.localEdits.length, 'Edit to retrieve must be in the log.');\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEdit}\n\t */\n\tpublic async tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined> {\n\t\ttry {\n\t\t\tconst index = this.getIndexOfId(editId);\n\t\t\treturn await this.getEditAtIndex(index);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * @returns The edits of edit chunks that do not have associated edit handles, does not include the last edit chunk if it is not full.\n\t */\n\tpublic *getEditChunksReadyForUpload(): Iterable<[number, readonly EditWithoutId<TChange>[]]> {\n\t\tconst maxStartRevision = this.editChunks.maxKey();\n\n\t\tif (maxStartRevision === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const [startRevision, chunk] of this.editChunks.entries(undefined, [])) {\n\t\t\tif (chunk.handle === undefined) {\n\t\t\t\tconst edits = assertNotUndefined(chunk.edits);\n\n\t\t\t\t// If there is no handle, the chunk should either not be the last chunk or should be full if it is.\n\t\t\t\tif (maxStartRevision !== startRevision || edits.length >= this.editsPerChunk) {\n\t\t\t\t\tyield [startRevision, edits];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Assigns provided handles to edit chunks based on chunk index specified.\n\t */\n\tpublic processEditChunkHandle(chunkHandle: EditHandle<TChange>, startRevision: number): void {\n\t\tconst chunk = this.editChunks.get(startRevision);\n\t\tif (chunk !== undefined) {\n\t\t\tassertNotUndefined(\n\t\t\t\tchunk.edits,\n\t\t\t\t'A chunk handle op should not be received before the edit ops it corresponds to.'\n\t\t\t);\n\t\t\tchunk.handle = chunkHandle;\n\t\t\tthis.addKeyToCache(startRevision);\n\t\t} else {\n\t\t\tthis.logger?.sendErrorEvent({ eventName: 'UnexpectedHistoryChunk' });\n\t\t\tthis.emit(SharedTreeDiagnosticEvent.UnexpectedHistoryChunk);\n\t\t}\n\t}\n\n\t/**\n\t * Sequences all local edits.\n\t */\n\tpublic sequenceLocalEdits(): void {\n\t\tthis.localEdits.slice().forEach((edit) => this.addSequencedEditInternal(edit));\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t *\n\t */\n\tpublic addSequencedEdit(edit: Edit<TChange>, message: MessageSequencingInfo): void {\n\t\tthis.addSequencedEditInternal(edit, message, message.minimumSequenceNumber);\n\t}\n\n\t/**\n\t * Returns all local edits from this EditLog\n\t * This is useful for op format upgrades, which might warrant re-submission of these ops using the new format.\n\t * See the breaking change documentation for more information.\n\t */\n\tpublic *getLocalEdits(): Iterable<Edit<TChange>> {\n\t\tfor (const edit of this.localEdits) {\n\t\t\tyield edit;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t */\n\tprivate addSequencedEditInternal(\n\t\tedit: Edit<TChange>,\n\t\tinfo?: EditSequencingInfo,\n\t\tminSequenceNumber: number = 0\n\t): void {\n\t\tconst { id, editWithoutId } = separateEditAndId(edit);\n\n\t\tassert(\n\t\t\tminSequenceNumber >= this.minSequenceNumber,\n\t\t\t'Sequenced edits should carry a monotonically increasing min number'\n\t\t);\n\t\t// The new minSequenceNumber indicates that no future edit will require information from edits with a smaller or equal seq number\n\t\t// for its resolution.\n\t\tthis._minSequenceNumber = minSequenceNumber;\n\t\t// TODO:#57176: Increment maximumEvictableIndex to reflect the fact we can now evict edits with a sequenceNumber lower or equal to\n\t\t// it. Note that this will change the meaning of our 'InSession' APIs so we should make sure to rename them at the same time.\n\t\t// The code might look like this:\n\t\t// while (this.maximumEvictableIndex + 1 < this.indexOfFirstEditInSession) {\n\t\t// \tconst nextEdit = this.getEditInSessionAtIndex(this.maximumEvictableIndex + 1);\n\t\t// \tconst nextEditInfo = this.getOrderedEditId(nextEdit.id) as SequencedOrderedEditId;\n\t\t// \tif (\n\t\t// \t\tnextEditInfo.sequenceInfo !== undefined &&\n\t\t// \t\tnextEditInfo.sequenceInfo.sequenceNumber > minSequenceNumber\n\t\t// \t) {\n\t\t// \t\tbreak;\n\t\t// \t}\n\t\t// \t++this.maximumEvictableIndex;\n\t\t// }\n\n\t\t// Remove the edit from local edits if it exists.\n\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\tif (encounteredEditId !== undefined) {\n\t\t\t// New edit already exits: it must have been a local edit.\n\t\t\tassert(encounteredEditId.isLocal, 'Duplicate acked edit.');\n\t\t\t// Remove it from localEdits. Due to ordering requirements, it must be first.\n\t\t\tconst oldLocalEditId = assertNotUndefined(this.localEdits.shift(), 'Local edit should exist').id;\n\t\t\tassert(oldLocalEditId === id, 'Causal ordering should be upheld');\n\t\t}\n\n\t\t// The starting revision for a newly created chunk.\n\t\tconst startRevision = this.numberOfSequencedEdits;\n\t\t// The initial edits for a newly created chunk.\n\t\tconst edits: EditWithoutId<TChange>[] = [editWithoutId];\n\n\t\tconst lastPair = this.editChunks.nextLowerPair(undefined);\n\t\tif (lastPair === undefined) {\n\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t} else {\n\t\t\t// Add to the last edit chunk if it has room and hasn't already been uploaded, otherwise create a new chunk.\n\t\t\t// If the chunk has a corresponding handle, create a new chunk.\n\t\t\tconst { edits: lastEditChunk, handle } = lastPair[1];\n\t\t\tif (handle === undefined && lastEditChunk !== undefined && lastEditChunk.length < this.editsPerChunk) {\n\t\t\t\tlastEditChunk.push(editWithoutId);\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\thandle !== undefined || lastEditChunk !== undefined,\n\t\t\t\t\t'An edit chunk must have either a handle or a list of edits.'\n\t\t\t\t);\n\t\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t\t}\n\t\t}\n\n\t\tthis.sequencedEditIds.push(id);\n\t\tconst sequencedEditId: SequencedOrderedEditId = {\n\t\t\tindex: this.numberOfSequencedEdits - 1,\n\t\t\tisLocal: false,\n\t\t\tsequenceInfo: info,\n\t\t};\n\t\tthis.allEditIds.set(id, sequencedEditId);\n\t\tthis.emitAdd(edit, false, encounteredEditId !== undefined);\n\t}\n\n\t/**\n\t * @returns The last edit chunk i.e. the chunk which the most recent sequenced edits have been placed into, as well as its starting revision.\n\t * Returns undefined iff there are no sequenced edits.\n\t * When defined, this chunk is guaranteed to contain at least one edit\n\t * (though it may be necessary to load the chunk via its handle to use it)\n\t */\n\tpublic getLastEditChunk(): [startRevision: number, edits: EditChunk<TChange>] | undefined {\n\t\treturn this.editChunks.nextLowerPair(undefined);\n\t}\n\n\t/**\n\t * Adds a non-sequenced (local) edit to the edit log.\n\t * Duplicate edits are ignored.\n\t */\n\tpublic addLocalEdit(edit: Edit<TChange>): void {\n\t\tthis.localEdits.push(edit);\n\t\tconst localEditId: LocalOrderedEditId = { localSequence: this.localEditSequence++, isLocal: true };\n\t\tthis.allEditIds.set(edit.id, localEditId);\n\t\tthis.emitAdd(edit, true, false);\n\t}\n\n\tprivate emitAdd(editAdded: Edit<TChange>, isLocal: boolean, wasLocal: boolean): void {\n\t\tfor (const handler of this._editAddedHandlers) {\n\t\t\thandler(editAdded, isLocal, wasLocal);\n\t\t}\n\t}\n\n\t/**\n\t * @returns true iff this `EditLog` and `other` are equivalent, regardless of locality.\n\t */\n\tpublic equals<TOtherChangeTypesInternal>(other: EditLog<TOtherChangeTypesInternal>): boolean {\n\t\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\t\treturn compareArrays(this.editIds, other.editIds);\n\t}\n\n\t/**\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary(): EditLogSummary<TChange, FluidEditHandle>;\n\t/**\n\t * @param compressEdit - a function which compresses edits\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TCompressedChange, FluidEditHandle>;\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit?: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TChange, FluidEditHandle> | EditLogSummary<TCompressedChange, FluidEditHandle> {\n\t\tif (compressEdit !== undefined) {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits?.map((edit) => compressEdit(edit)) ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate addKeyToCache(newKey: number): void {\n\t\t// Indices are only added to the cache if they are not higher than the maximum evicted index.\n\t\tif (newKey <= this.maximumEvictableIndex) {\n\t\t\t// If the new index is already in the cache, remove it first to update its last usage.\n\t\t\tif (newKey in this.loadedChunkCache) {\n\t\t\t\tthis.loadedChunkCache.splice(this.loadedChunkCache.indexOf(newKey), 1);\n\t\t\t}\n\n\t\t\tthis.loadedChunkCache.push(newKey);\n\n\t\t\t// If the cache is out of space, evict the oldest index in the cache.\n\t\t\tif (this.loadedChunkCache.length > loadedChunkCacheSize) {\n\t\t\t\tconst indexToEvict = assertNotUndefined(this.loadedChunkCache.shift());\n\t\t\t\tconst chunkToEvict = assertNotUndefined(\n\t\t\t\t\tthis.editChunks.get(indexToEvict),\n\t\t\t\t\t'Chunk start revision added to cache should exist in the edit log.'\n\t\t\t\t);\n\t\t\t\tchunkToEvict.edits = undefined;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isEditHandle<TChange>(\n\tchunk: EditHandle<TChange> | readonly EditWithoutId<unknown>[]\n): chunk is EditHandle<TChange> {\n\treturn !Array.isArray(chunk);\n}\n"]}
|
package/lib/EditLog.js
CHANGED
|
@@ -138,8 +138,9 @@ export class EditLog extends TypedEventEmitter {
|
|
|
138
138
|
* @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).
|
|
139
139
|
*/
|
|
140
140
|
isLocalEdit(editId) {
|
|
141
|
+
var _a;
|
|
141
142
|
const entry = this.allEditIds.get(editId);
|
|
142
|
-
return entry
|
|
143
|
+
return (_a = entry === null || entry === void 0 ? void 0 : entry.isLocal) !== null && _a !== void 0 ? _a : false;
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
145
146
|
* @returns true iff the revision is a sequenced revision (not local).
|
package/lib/EditLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditLog.js","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGjG,OAAO,EAAwB,aAAa,EAAkC,MAAM,mBAAmB,CAAC;AACxG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAmIzD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAU,IAAmB;IAI7D,MAAM,aAAa,mCAAQ,IAAI,KAAE,EAAE,EAAE,SAAS,GAAE,CAAC;IACjD,OAAO,aAAa,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC;AAED,SAAS,aAAa,CAAU,EAAU,EAAE,IAA4B;IACvE,uBAAS,EAAE,IAAK,IAAI,EAAG;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oCAAoC,CAAC,OAAyC;IAC7F,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE/B,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,CA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AqE;YACrE,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,oBAAoB,EAAE;gBACxD,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;gBACvE,MAAM,YAAY,GAAG,kBAAkB,CACtC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,EACjC,mEAAmE,CACnE,CAAC;gBACF,YAAY,CAAC,KAAK,GAAG,SAAS,CAAC;aAC/B;SACD;IACF,CAAC;CACD;AAED,SAAS,YAAY,CACpB,KAA8D;IAE9D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport type { IEvent, ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { assert, assertNotUndefined, compareArrays, compareFiniteNumbers, fail } from './Common';\nimport type { EditId } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport { Edit, EditLogSummary, editsPerChunk, EditWithoutId, FluidEditHandle } from './persisted-types';\nimport { SharedTreeDiagnosticEvent } from './EventTypes';\nimport type { ChangeCompressor } from './ChangeCompression';\n\n/**\n * An ordered set of Edits associated with a SharedTree.\n * Supports fast lookup of edits by ID and enforces idempotence.\n * Edits are virtualized, however, edits added during the current session are guaranteed to be available\n * synchronously.\n * @public\n * @sealed\n */\nexport interface OrderedEditSet<TChange = unknown> {\n\t/**\n\t * The length of this `OrderedEditSet`.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The edit IDs of all edits in the log.\n\t */\n\treadonly editIds: readonly EditId[];\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`.\n\t */\n\tgetIndexOfId(editId: EditId): number;\n\n\t/**\n\t * @returns the id of the edit at the given index within this 'OrderedEditSet'.\n\t */\n\tgetIdAtIndex(index: number): EditId;\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.\n\t */\n\ttryGetIndexOfId(editId: EditId): number | undefined;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t */\n\tgetEditAtIndex(index: number): Promise<Edit<TChange>>;\n\n\t/**\n\t * @returns the edit at the given index. Must have been added to the log during the current session.\n\t */\n\tgetEditInSessionAtIndex(index: number): Edit<TChange>;\n\n\t/**\n\t * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.\n\t */\n\ttryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface EditSequencingInfo {\n\t/**\n\t * The server-assigned sequence number of the op.\n\t */\n\treadonly sequenceNumber: number;\n\t/**\n\t * Last known sequenced edit at the time this op was issued.\n\t */\n\treadonly referenceSequenceNumber: number;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface MessageSequencingInfo extends EditSequencingInfo {\n\t/**\n\t * Last sequenced edit that all clients are guaranteed to be aware of.\n\t * If not specified, then some clients have not seen any edits yet.\n\t */\n\treadonly minimumSequenceNumber?: number;\n}\n\n/**\n * Metadata for a sequenced edit.\n */\nexport interface SequencedOrderedEditId {\n\treadonly isLocal: false;\n\treadonly index: number;\n\t/**\n\t * Information about the edit's relationship to other sequenced edits.\n\t * Undefined iff the edit was loaded from a summary.\n\t */\n\treadonly sequenceInfo?: EditSequencingInfo;\n}\n\n/**\n * Metadata for a local edit.\n */\nexport interface LocalOrderedEditId {\n\treadonly isLocal: true;\n\treadonly localSequence: number;\n}\n\n/**\n * Metadata for an edit.\n */\nexport type OrderedEditId = SequencedOrderedEditId | LocalOrderedEditId;\n\n/**\n * Compressor+interner pair used for encoding an {@link EditLog} into a summary.\n * @internal\n */\nexport interface EditLogEncoder {\n\tcompressor: ChangeCompressor;\n\tinterner: StringInterner;\n}\n\n/**\n * A sequence of edits that may or may not need to be downloaded into the EditLog from an external service\n */\nexport interface EditChunk<TChange> {\n\thandle?: EditHandle<TChange>;\n\tedits?: EditWithoutId<TChange>[];\n}\n\n/**\n * EditHandles are used to load edit chunks stored outside of the EditLog.\n * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.\n * @public\n */\nexport interface EditHandle<TChange> {\n\treadonly get: () => Promise<EditWithoutId<TChange>[]>;\n\treadonly baseHandle: FluidEditHandle;\n}\n\n/**\n * Returns an object that separates an Edit into two fields, id and editWithoutId.\n */\nexport function separateEditAndId<TChange>(edit: Edit<TChange>): {\n\tid: EditId;\n\teditWithoutId: EditWithoutId<TChange>;\n} {\n\tconst editWithoutId = { ...edit, id: undefined };\n\tdelete editWithoutId.id;\n\treturn { id: edit.id, editWithoutId };\n}\n\nfunction joinEditAndId<TChange>(id: EditId, edit: EditWithoutId<TChange>): Edit<TChange> {\n\treturn { id, ...edit };\n}\n\n/**\n * @param summary - The edit log summary to parse.\n * @returns the number of handles saved to the provided edit log summary.\n */\nexport function getNumberOfHandlesFromEditLogSummary(summary: EditLogSummary<unknown, unknown>): number {\n\tconst { editChunks } = summary;\n\n\tlet numberOfHandles = 0;\n\teditChunks.forEach(({ chunk }) => {\n\t\tif (!Array.isArray(chunk)) {\n\t\t\tnumberOfHandles++;\n\t\t}\n\t});\n\n\treturn numberOfHandles;\n}\n\n/**\n * The number of blobs to be loaded in memory at any time.\n * TODO:#49901: Change cache size once the virtualized history summary format is being written.\n * \t\t This is so the summarizer doesn't have to reload every edit to generate summaries.\n * */\nconst loadedChunkCacheSize = Number.POSITIVE_INFINITY;\n\n/**\n * Event fired when an edit is added to an `EditLog`.\n * @param edit - The edit that was added to the log\n * @param isLocal - true iff this edit was generated locally\n */\nexport type EditAddedHandler<TChange> = (edit: Edit<TChange>, isLocal: boolean, wasLocal: boolean) => void;\n\n/**\n * Events which may be emitted by `EditLog`.\n * @public\n */\nexport interface IEditLogEvents extends IEvent {\n\t(event: 'unexpectedHistoryChunk', listener: () => void);\n}\n\n/**\n * The edit history log for SharedTree.\n * Contains only completed edits (no in-progress edits).\n * Ordered first by locality (acked or local), then by time of insertion.\n * May not contain more than one edit with the same ID.\n * @sealed\n */\nexport class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents> implements OrderedEditSet<TChange> {\n\tprivate localEditSequence = 0;\n\tprivate _minSequenceNumber = 0;\n\n\tprivate readonly sequencedEditIds: EditId[];\n\tprivate readonly editChunks: BTree<number, EditChunk<TChange>>;\n\tprivate readonly localEdits: Edit<TChange>[] = [];\n\tprivate readonly loadedChunkCache: number[] = [];\n\tprivate readonly indexOfFirstEditInSession: number;\n\tprivate readonly maximumEvictableIndex: number;\n\n\tprivate readonly allEditIds: Map<EditId, OrderedEditId> = new Map();\n\tprivate readonly _editAddedHandlers: Set<EditAddedHandler<TChange>> = new Set();\n\n\tprivate readonly logger?: ITelemetryLogger;\n\n\t/**\n\t * The number of edits associated with each blob.\n\t */\n\tpublic readonly editsPerChunk: number;\n\n\t/**\n\t * @returns The index of the earliest edit available through `getEditInSessionAtIndex`.\n\t */\n\tpublic get earliestAvailableEditIndex(): number {\n\t\treturn this.maximumEvictableIndex + 1;\n\t}\n\n\t/**\n\t * @returns The sequence number of the latest edit known by all nodes.\n\t */\n\tpublic get minSequenceNumber(): number {\n\t\treturn this._minSequenceNumber;\n\t}\n\n\t/**\n\t * Construct an `EditLog` using the given options.\n\t * @param summary - An edit log summary used to populate the edit log.\n\t * @param logger - An optional logger to record telemetry/errors\n\t */\n\tpublic constructor(\n\t\tsummary: EditLogSummary<TChange, EditHandle<TChange>> = { editIds: [], editChunks: [] },\n\t\tlogger?: ITelemetryLogger,\n\t\teditAddedHandlers: readonly EditAddedHandler<TChange>[] = [],\n\t\tindexOfFirstEditInSession = summary.editIds.length\n\t) {\n\t\tsuper();\n\t\tconst { editChunks, editIds } = summary;\n\t\tthis.logger = logger;\n\t\tthis.editsPerChunk = editsPerChunk;\n\n\t\tfor (const handler of editAddedHandlers) {\n\t\t\tthis.registerEditAddedHandler(handler);\n\t\t}\n\n\t\tthis.editChunks = new BTree<number, EditChunk<TChange>>(undefined, compareFiniteNumbers);\n\n\t\teditChunks.forEach((editChunkOrHandle) => {\n\t\t\tconst { startRevision, chunk } = editChunkOrHandle;\n\n\t\t\tif (isEditHandle(chunk)) {\n\t\t\t\tthis.editChunks.set(startRevision, { handle: chunk });\n\t\t\t} else {\n\t\t\t\tthis.editChunks.set(startRevision, { edits: chunk as EditWithoutId<TChange>[] });\n\t\t\t}\n\t\t});\n\n\t\tthis.sequencedEditIds = editIds.slice();\n\n\t\tthis.indexOfFirstEditInSession = indexOfFirstEditInSession;\n\t\tthis.maximumEvictableIndex = this.indexOfFirstEditInSession - 1;\n\n\t\tthis.sequencedEditIds.forEach((id, index) => {\n\t\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\t\tassert(encounteredEditId === undefined, 'Duplicate acked edit.');\n\t\t\tthis.allEditIds.set(id, { isLocal: false, index });\n\t\t});\n\t}\n\n\t/**\n\t * Registers a handler for when an edit is added to this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditAddedHandler(handler: EditAddedHandler<TChange>): () => void {\n\t\tthis._editAddedHandlers.add(handler);\n\t\treturn () => this._editAddedHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditAddedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editAddedHandlers(): readonly EditAddedHandler<TChange>[] {\n\t\treturn Array.from(this._editAddedHandlers);\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.length}\n\t */\n\tpublic get length(): number {\n\t\treturn this.numberOfSequencedEdits + this.numberOfLocalEdits;\n\t}\n\n\t/**\n\t * The number of sequenced (acked) edits in the log.\n\t */\n\tpublic get numberOfSequencedEdits(): number {\n\t\treturn this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * The number of local (unacked) edits in the log.\n\t */\n\tpublic get numberOfLocalEdits(): number {\n\t\treturn this.localEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.editIds}\n\t */\n\tpublic get editIds(): EditId[] {\n\t\treturn this.sequencedEditIds.concat(this.localEdits.map(({ id }) => id));\n\t}\n\n\t/**\n\t * @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).\n\t */\n\tpublic isLocalEdit(editId: EditId): boolean {\n\t\tconst entry = this.allEditIds.get(editId);\n\t\treturn entry !== undefined && entry.isLocal;\n\t}\n\n\t/**\n\t * @returns true iff the revision is a sequenced revision (not local).\n\t */\n\tpublic isSequencedRevision(revision: number): boolean {\n\t\treturn revision <= this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetIndexOfId}\n\t */\n\tpublic tryGetIndexOfId(editId: EditId): number | undefined {\n\t\tconst orderedEdit = this.allEditIds.get(editId);\n\t\tif (orderedEdit === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (orderedEdit.isLocal) {\n\t\t\tconst firstLocal = assertNotUndefined(this.allEditIds.get(this.localEdits[0].id));\n\t\t\tassert(firstLocal.isLocal);\n\t\t\treturn this.numberOfSequencedEdits + orderedEdit.localSequence - firstLocal.localSequence;\n\t\t}\n\t\treturn orderedEdit.index;\n\t}\n\n\t/**\n\t * @returns Edit metadata for the edit with the given `editId`.\n\t */\n\tpublic getOrderedEditId(editId: EditId): OrderedEditId {\n\t\treturn assertNotUndefined(this.allEditIds.get(editId), 'All edits should exist in this map');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIndexOfId}\n\t */\n\tpublic getIndexOfId(editId: EditId): number {\n\t\treturn this.tryGetIndexOfId(editId) ?? fail('edit not found');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIdAtIndex}\n\t */\n\tpublic getIdAtIndex(index: number): EditId {\n\t\tif (this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits].id;\n\t\t}\n\n\t\treturn this.sequencedEditIds[index];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditAtIndex}\n\t */\n\tpublic async getEditAtIndex(index: number): Promise<Edit<TChange>> {\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { handle, edits } = editChunk;\n\n\t\t\tif (edits === undefined) {\n\t\t\t\tassert(handle !== undefined, 'An edit chunk should include at least a handle or edits.');\n\t\t\t\tconst edits = await handle.get();\n\n\t\t\t\t// Make sure the loaded edit chunk is the correct size. If a higher starting revison is set, the length is the difference of both.\n\t\t\t\t// Otherwise, it means that there are no sequenced edits in memory so the length is the difference of the number of\n\t\t\t\t// sequenced edits and the starting revision.\n\t\t\t\tconst nextKey = this.editChunks.nextHigherKey(index);\n\t\t\t\tconst expectedEditLength =\n\t\t\t\t\t(nextKey === undefined ? this.numberOfSequencedEdits : nextKey) - startRevision;\n\t\t\t\tassert(edits.length === expectedEditLength, 'The chunk does not contain the correct number of edits.');\n\n\t\t\t\teditChunk.edits = edits;\n\n\t\t\t\tthis.addKeyToCache(startRevision);\n\t\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t\t}\n\n\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t}\n\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditInSessionAtIndex}\n\t */\n\tpublic getEditInSessionAtIndex(index: number): Edit<TChange> {\n\t\tassert(\n\t\t\tindex > this.maximumEvictableIndex,\n\t\t\t'Edit to retrieve must have been added to the log during the current session.'\n\t\t);\n\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { edits } = editChunk;\n\n\t\t\treturn joinEditAndId(\n\t\t\t\tthis.getIdAtIndex(index),\n\t\t\t\tassertNotUndefined(edits, 'Edits should not have been evicted.')[index - startRevision]\n\t\t\t);\n\t\t}\n\n\t\tassert(index - this.numberOfSequencedEdits < this.localEdits.length, 'Edit to retrieve must be in the log.');\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEdit}\n\t */\n\tpublic async tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined> {\n\t\ttry {\n\t\t\tconst index = this.getIndexOfId(editId);\n\t\t\treturn await this.getEditAtIndex(index);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * @returns The edits of edit chunks that do not have associated edit handles, does not include the last edit chunk if it is not full.\n\t */\n\tpublic *getEditChunksReadyForUpload(): Iterable<[number, readonly EditWithoutId<TChange>[]]> {\n\t\tconst maxStartRevision = this.editChunks.maxKey();\n\n\t\tif (maxStartRevision === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const [startRevision, chunk] of this.editChunks.entries(undefined, [])) {\n\t\t\tif (chunk.handle === undefined) {\n\t\t\t\tconst edits = assertNotUndefined(chunk.edits);\n\n\t\t\t\t// If there is no handle, the chunk should either not be the last chunk or should be full if it is.\n\t\t\t\tif (maxStartRevision !== startRevision || edits.length >= this.editsPerChunk) {\n\t\t\t\t\tyield [startRevision, edits];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Assigns provided handles to edit chunks based on chunk index specified.\n\t */\n\tpublic processEditChunkHandle(chunkHandle: EditHandle<TChange>, startRevision: number): void {\n\t\tconst chunk = this.editChunks.get(startRevision);\n\t\tif (chunk !== undefined) {\n\t\t\tassertNotUndefined(\n\t\t\t\tchunk.edits,\n\t\t\t\t'A chunk handle op should not be received before the edit ops it corresponds to.'\n\t\t\t);\n\t\t\tchunk.handle = chunkHandle;\n\t\t\tthis.addKeyToCache(startRevision);\n\t\t} else {\n\t\t\tthis.logger?.sendErrorEvent({ eventName: 'UnexpectedHistoryChunk' });\n\t\t\tthis.emit(SharedTreeDiagnosticEvent.UnexpectedHistoryChunk);\n\t\t}\n\t}\n\n\t/**\n\t * Sequences all local edits.\n\t */\n\tpublic sequenceLocalEdits(): void {\n\t\tthis.localEdits.slice().forEach((edit) => this.addSequencedEditInternal(edit));\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t *\n\t */\n\tpublic addSequencedEdit(edit: Edit<TChange>, message: MessageSequencingInfo): void {\n\t\tthis.addSequencedEditInternal(edit, message, message.minimumSequenceNumber);\n\t}\n\n\t/**\n\t * Returns all local edits from this EditLog\n\t * This is useful for op format upgrades, which might warrant re-submission of these ops using the new format.\n\t * See the breaking change documentation for more information.\n\t */\n\tpublic *getLocalEdits(): Iterable<Edit<TChange>> {\n\t\tfor (const edit of this.localEdits) {\n\t\t\tyield edit;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t */\n\tprivate addSequencedEditInternal(\n\t\tedit: Edit<TChange>,\n\t\tinfo?: EditSequencingInfo,\n\t\tminSequenceNumber: number = 0\n\t): void {\n\t\tconst { id, editWithoutId } = separateEditAndId(edit);\n\n\t\tassert(\n\t\t\tminSequenceNumber >= this.minSequenceNumber,\n\t\t\t'Sequenced edits should carry a monotonically increasing min number'\n\t\t);\n\t\t// The new minSequenceNumber indicates that no future edit will require information from edits with a smaller or equal seq number\n\t\t// for its resolution.\n\t\tthis._minSequenceNumber = minSequenceNumber;\n\t\t// TODO:#57176: Increment maximumEvictableIndex to reflect the fact we can now evict edits with a sequenceNumber lower or equal to\n\t\t// it. Note that this will change the meaning of our 'InSession' APIs so we should make sure to rename them at the same time.\n\t\t// The code might look like this:\n\t\t// while (this.maximumEvictableIndex + 1 < this.indexOfFirstEditInSession) {\n\t\t// \tconst nextEdit = this.getEditInSessionAtIndex(this.maximumEvictableIndex + 1);\n\t\t// \tconst nextEditInfo = this.getOrderedEditId(nextEdit.id) as SequencedOrderedEditId;\n\t\t// \tif (\n\t\t// \t\tnextEditInfo.sequenceInfo !== undefined &&\n\t\t// \t\tnextEditInfo.sequenceInfo.sequenceNumber > minSequenceNumber\n\t\t// \t) {\n\t\t// \t\tbreak;\n\t\t// \t}\n\t\t// \t++this.maximumEvictableIndex;\n\t\t// }\n\n\t\t// Remove the edit from local edits if it exists.\n\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\tif (encounteredEditId !== undefined) {\n\t\t\t// New edit already exits: it must have been a local edit.\n\t\t\tassert(encounteredEditId.isLocal, 'Duplicate acked edit.');\n\t\t\t// Remove it from localEdits. Due to ordering requirements, it must be first.\n\t\t\tconst oldLocalEditId = assertNotUndefined(this.localEdits.shift(), 'Local edit should exist').id;\n\t\t\tassert(oldLocalEditId === id, 'Causal ordering should be upheld');\n\t\t}\n\n\t\t// The starting revision for a newly created chunk.\n\t\tconst startRevision = this.numberOfSequencedEdits;\n\t\t// The initial edits for a newly created chunk.\n\t\tconst edits: EditWithoutId<TChange>[] = [editWithoutId];\n\n\t\tconst lastPair = this.editChunks.nextLowerPair(undefined);\n\t\tif (lastPair === undefined) {\n\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t} else {\n\t\t\t// Add to the last edit chunk if it has room and hasn't already been uploaded, otherwise create a new chunk.\n\t\t\t// If the chunk has a corresponding handle, create a new chunk.\n\t\t\tconst { edits: lastEditChunk, handle } = lastPair[1];\n\t\t\tif (handle === undefined && lastEditChunk !== undefined && lastEditChunk.length < this.editsPerChunk) {\n\t\t\t\tlastEditChunk.push(editWithoutId);\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\thandle !== undefined || lastEditChunk !== undefined,\n\t\t\t\t\t'An edit chunk must have either a handle or a list of edits.'\n\t\t\t\t);\n\t\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t\t}\n\t\t}\n\n\t\tthis.sequencedEditIds.push(id);\n\t\tconst sequencedEditId: SequencedOrderedEditId = {\n\t\t\tindex: this.numberOfSequencedEdits - 1,\n\t\t\tisLocal: false,\n\t\t\tsequenceInfo: info,\n\t\t};\n\t\tthis.allEditIds.set(id, sequencedEditId);\n\t\tthis.emitAdd(edit, false, encounteredEditId !== undefined);\n\t}\n\n\t/**\n\t * @returns The last edit chunk i.e. the chunk which the most recent sequenced edits have been placed into, as well as its starting revision.\n\t * Returns undefined iff there are no sequenced edits.\n\t * When defined, this chunk is guaranteed to contain at least one edit\n\t * (though it may be necessary to load the chunk via its handle to use it)\n\t */\n\tpublic getLastEditChunk(): [startRevision: number, edits: EditChunk<TChange>] | undefined {\n\t\treturn this.editChunks.nextLowerPair(undefined);\n\t}\n\n\t/**\n\t * Adds a non-sequenced (local) edit to the edit log.\n\t * Duplicate edits are ignored.\n\t */\n\tpublic addLocalEdit(edit: Edit<TChange>): void {\n\t\tthis.localEdits.push(edit);\n\t\tconst localEditId: LocalOrderedEditId = { localSequence: this.localEditSequence++, isLocal: true };\n\t\tthis.allEditIds.set(edit.id, localEditId);\n\t\tthis.emitAdd(edit, true, false);\n\t}\n\n\tprivate emitAdd(editAdded: Edit<TChange>, isLocal: boolean, wasLocal: boolean): void {\n\t\tfor (const handler of this._editAddedHandlers) {\n\t\t\thandler(editAdded, isLocal, wasLocal);\n\t\t}\n\t}\n\n\t/**\n\t * @returns true iff this `EditLog` and `other` are equivalent, regardless of locality.\n\t */\n\tpublic equals<TOtherChangeTypesInternal>(other: EditLog<TOtherChangeTypesInternal>): boolean {\n\t\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\t\treturn compareArrays(this.editIds, other.editIds);\n\t}\n\n\t/**\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary(): EditLogSummary<TChange, FluidEditHandle>;\n\t/**\n\t * @param compressEdit - a function which compresses edits\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TCompressedChange, FluidEditHandle>;\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit?: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TChange, FluidEditHandle> | EditLogSummary<TCompressedChange, FluidEditHandle> {\n\t\tif (compressEdit !== undefined) {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits?.map((edit) => compressEdit(edit)) ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate addKeyToCache(newKey: number): void {\n\t\t// Indices are only added to the cache if they are not higher than the maximum evicted index.\n\t\tif (newKey <= this.maximumEvictableIndex) {\n\t\t\t// If the new index is already in the cache, remove it first to update its last usage.\n\t\t\tif (newKey in this.loadedChunkCache) {\n\t\t\t\tthis.loadedChunkCache.splice(this.loadedChunkCache.indexOf(newKey), 1);\n\t\t\t}\n\n\t\t\tthis.loadedChunkCache.push(newKey);\n\n\t\t\t// If the cache is out of space, evict the oldest index in the cache.\n\t\t\tif (this.loadedChunkCache.length > loadedChunkCacheSize) {\n\t\t\t\tconst indexToEvict = assertNotUndefined(this.loadedChunkCache.shift());\n\t\t\t\tconst chunkToEvict = assertNotUndefined(\n\t\t\t\t\tthis.editChunks.get(indexToEvict),\n\t\t\t\t\t'Chunk start revision added to cache should exist in the edit log.'\n\t\t\t\t);\n\t\t\t\tchunkToEvict.edits = undefined;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isEditHandle<TChange>(\n\tchunk: EditHandle<TChange> | readonly EditWithoutId<unknown>[]\n): chunk is EditHandle<TChange> {\n\treturn !Array.isArray(chunk);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditLog.js","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGjG,OAAO,EAAwB,aAAa,EAAkC,MAAM,mBAAmB,CAAC;AACxG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAmIzD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAU,IAAmB;IAI7D,MAAM,aAAa,mCAAQ,IAAI,KAAE,EAAE,EAAE,SAAS,GAAE,CAAC;IACjD,OAAO,aAAa,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC;AAED,SAAS,aAAa,CAAU,EAAU,EAAE,IAA4B;IACvE,uBAAS,EAAE,IAAK,IAAI,EAAG;AACxB,CAA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AsF;YACtF,IAAI,MAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBACpC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;aACvE;YAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAEnC,qEAAqE;YACrE,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,oBAAoB,EAAE;gBACxD,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;gBACvE,MAAM,YAAY,GAAG,kBAAkB,CACtC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,EACjC,mEAAmE,CACnE,CAAC;gBACF,YAAY,CAAC,KAAK,GAAG,SAAS,CAAC;aAC/B;SACD;IACF,CAAC;CACD;AAED,SAAS,YAAY,CACpB,KAA8D;IAE9D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport type { IEvent, ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { assert, assertNotUndefined, compareArrays, compareFiniteNumbers, fail } from './Common';\nimport type { EditId } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport { Edit, EditLogSummary, editsPerChunk, EditWithoutId, FluidEditHandle } from './persisted-types';\nimport { SharedTreeDiagnosticEvent } from './EventTypes';\nimport type { ChangeCompressor } from './ChangeCompression';\n\n/**\n * An ordered set of Edits associated with a SharedTree.\n * Supports fast lookup of edits by ID and enforces idempotence.\n * Edits are virtualized, however, edits added during the current session are guaranteed to be available\n * synchronously.\n * @public\n * @sealed\n */\nexport interface OrderedEditSet<TChange = unknown> {\n\t/**\n\t * The length of this `OrderedEditSet`.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The edit IDs of all edits in the log.\n\t */\n\treadonly editIds: readonly EditId[];\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`.\n\t */\n\tgetIndexOfId(editId: EditId): number;\n\n\t/**\n\t * @returns the id of the edit at the given index within this 'OrderedEditSet'.\n\t */\n\tgetIdAtIndex(index: number): EditId;\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.\n\t */\n\ttryGetIndexOfId(editId: EditId): number | undefined;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t */\n\tgetEditAtIndex(index: number): Promise<Edit<TChange>>;\n\n\t/**\n\t * @returns the edit at the given index. Must have been added to the log during the current session.\n\t */\n\tgetEditInSessionAtIndex(index: number): Edit<TChange>;\n\n\t/**\n\t * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.\n\t */\n\ttryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface EditSequencingInfo {\n\t/**\n\t * The server-assigned sequence number of the op.\n\t */\n\treadonly sequenceNumber: number;\n\t/**\n\t * Last known sequenced edit at the time this op was issued.\n\t */\n\treadonly referenceSequenceNumber: number;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface MessageSequencingInfo extends EditSequencingInfo {\n\t/**\n\t * Last sequenced edit that all clients are guaranteed to be aware of.\n\t * If not specified, then some clients have not seen any edits yet.\n\t */\n\treadonly minimumSequenceNumber?: number;\n}\n\n/**\n * Metadata for a sequenced edit.\n */\nexport interface SequencedOrderedEditId {\n\treadonly isLocal: false;\n\treadonly index: number;\n\t/**\n\t * Information about the edit's relationship to other sequenced edits.\n\t * Undefined iff the edit was loaded from a summary.\n\t */\n\treadonly sequenceInfo?: EditSequencingInfo;\n}\n\n/**\n * Metadata for a local edit.\n */\nexport interface LocalOrderedEditId {\n\treadonly isLocal: true;\n\treadonly localSequence: number;\n}\n\n/**\n * Metadata for an edit.\n */\nexport type OrderedEditId = SequencedOrderedEditId | LocalOrderedEditId;\n\n/**\n * Compressor+interner pair used for encoding an {@link EditLog} into a summary.\n * @internal\n */\nexport interface EditLogEncoder {\n\tcompressor: ChangeCompressor;\n\tinterner: StringInterner;\n}\n\n/**\n * A sequence of edits that may or may not need to be downloaded into the EditLog from an external service\n */\nexport interface EditChunk<TChange> {\n\thandle?: EditHandle<TChange>;\n\tedits?: EditWithoutId<TChange>[];\n}\n\n/**\n * EditHandles are used to load edit chunks stored outside of the EditLog.\n * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.\n * @public\n */\nexport interface EditHandle<TChange> {\n\treadonly get: () => Promise<EditWithoutId<TChange>[]>;\n\treadonly baseHandle: FluidEditHandle;\n}\n\n/**\n * Returns an object that separates an Edit into two fields, id and editWithoutId.\n */\nexport function separateEditAndId<TChange>(edit: Edit<TChange>): {\n\tid: EditId;\n\teditWithoutId: EditWithoutId<TChange>;\n} {\n\tconst editWithoutId = { ...edit, id: undefined };\n\tdelete editWithoutId.id;\n\treturn { id: edit.id, editWithoutId };\n}\n\nfunction joinEditAndId<TChange>(id: EditId, edit: EditWithoutId<TChange>): Edit<TChange> {\n\treturn { id, ...edit };\n}\n\n/**\n * @param summary - The edit log summary to parse.\n * @returns the number of handles saved to the provided edit log summary.\n */\nexport function getNumberOfHandlesFromEditLogSummary(summary: EditLogSummary<unknown, unknown>): number {\n\tconst { editChunks } = summary;\n\n\tlet numberOfHandles = 0;\n\teditChunks.forEach(({ chunk }) => {\n\t\tif (!Array.isArray(chunk)) {\n\t\t\tnumberOfHandles++;\n\t\t}\n\t});\n\n\treturn numberOfHandles;\n}\n\n/**\n * The number of blobs to be loaded in memory at any time.\n * TODO:#49901: Change cache size once the virtualized history summary format is being written.\n * \t\t This is so the summarizer doesn't have to reload every edit to generate summaries.\n * */\nconst loadedChunkCacheSize = Number.POSITIVE_INFINITY;\n\n/**\n * Event fired when an edit is added to an `EditLog`.\n * @param edit - The edit that was added to the log\n * @param isLocal - true iff this edit was generated locally\n */\nexport type EditAddedHandler<TChange> = (edit: Edit<TChange>, isLocal: boolean, wasLocal: boolean) => void;\n\n/**\n * Events which may be emitted by `EditLog`.\n * @public\n */\nexport interface IEditLogEvents extends IEvent {\n\t(event: 'unexpectedHistoryChunk', listener: () => void);\n}\n\n/**\n * The edit history log for SharedTree.\n * Contains only completed edits (no in-progress edits).\n * Ordered first by locality (acked or local), then by time of insertion.\n * May not contain more than one edit with the same ID.\n * @sealed\n */\nexport class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents> implements OrderedEditSet<TChange> {\n\tprivate localEditSequence = 0;\n\tprivate _minSequenceNumber = 0;\n\n\tprivate readonly sequencedEditIds: EditId[];\n\tprivate readonly editChunks: BTree<number, EditChunk<TChange>>;\n\tprivate readonly localEdits: Edit<TChange>[] = [];\n\tprivate readonly loadedChunkCache: number[] = [];\n\tprivate readonly indexOfFirstEditInSession: number;\n\tprivate readonly maximumEvictableIndex: number;\n\n\tprivate readonly allEditIds: Map<EditId, OrderedEditId> = new Map();\n\tprivate readonly _editAddedHandlers: Set<EditAddedHandler<TChange>> = new Set();\n\n\tprivate readonly logger?: ITelemetryLogger;\n\n\t/**\n\t * The number of edits associated with each blob.\n\t */\n\tpublic readonly editsPerChunk: number;\n\n\t/**\n\t * @returns The index of the earliest edit available through `getEditInSessionAtIndex`.\n\t */\n\tpublic get earliestAvailableEditIndex(): number {\n\t\treturn this.maximumEvictableIndex + 1;\n\t}\n\n\t/**\n\t * @returns The sequence number of the latest edit known by all nodes.\n\t */\n\tpublic get minSequenceNumber(): number {\n\t\treturn this._minSequenceNumber;\n\t}\n\n\t/**\n\t * Construct an `EditLog` using the given options.\n\t * @param summary - An edit log summary used to populate the edit log.\n\t * @param logger - An optional logger to record telemetry/errors\n\t */\n\tpublic constructor(\n\t\tsummary: EditLogSummary<TChange, EditHandle<TChange>> = { editIds: [], editChunks: [] },\n\t\tlogger?: ITelemetryLogger,\n\t\teditAddedHandlers: readonly EditAddedHandler<TChange>[] = [],\n\t\tindexOfFirstEditInSession = summary.editIds.length\n\t) {\n\t\tsuper();\n\t\tconst { editChunks, editIds } = summary;\n\t\tthis.logger = logger;\n\t\tthis.editsPerChunk = editsPerChunk;\n\n\t\tfor (const handler of editAddedHandlers) {\n\t\t\tthis.registerEditAddedHandler(handler);\n\t\t}\n\n\t\tthis.editChunks = new BTree<number, EditChunk<TChange>>(undefined, compareFiniteNumbers);\n\n\t\teditChunks.forEach((editChunkOrHandle) => {\n\t\t\tconst { startRevision, chunk } = editChunkOrHandle;\n\n\t\t\tif (isEditHandle(chunk)) {\n\t\t\t\tthis.editChunks.set(startRevision, { handle: chunk });\n\t\t\t} else {\n\t\t\t\tthis.editChunks.set(startRevision, { edits: chunk as EditWithoutId<TChange>[] });\n\t\t\t}\n\t\t});\n\n\t\tthis.sequencedEditIds = editIds.slice();\n\n\t\tthis.indexOfFirstEditInSession = indexOfFirstEditInSession;\n\t\tthis.maximumEvictableIndex = this.indexOfFirstEditInSession - 1;\n\n\t\tthis.sequencedEditIds.forEach((id, index) => {\n\t\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\t\tassert(encounteredEditId === undefined, 'Duplicate acked edit.');\n\t\t\tthis.allEditIds.set(id, { isLocal: false, index });\n\t\t});\n\t}\n\n\t/**\n\t * Registers a handler for when an edit is added to this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditAddedHandler(handler: EditAddedHandler<TChange>): () => void {\n\t\tthis._editAddedHandlers.add(handler);\n\t\treturn () => this._editAddedHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditAddedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editAddedHandlers(): readonly EditAddedHandler<TChange>[] {\n\t\treturn Array.from(this._editAddedHandlers);\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.length}\n\t */\n\tpublic get length(): number {\n\t\treturn this.numberOfSequencedEdits + this.numberOfLocalEdits;\n\t}\n\n\t/**\n\t * The number of sequenced (acked) edits in the log.\n\t */\n\tpublic get numberOfSequencedEdits(): number {\n\t\treturn this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * The number of local (unacked) edits in the log.\n\t */\n\tpublic get numberOfLocalEdits(): number {\n\t\treturn this.localEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.editIds}\n\t */\n\tpublic get editIds(): EditId[] {\n\t\treturn this.sequencedEditIds.concat(this.localEdits.map(({ id }) => id));\n\t}\n\n\t/**\n\t * @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).\n\t */\n\tpublic isLocalEdit(editId: EditId): boolean {\n\t\tconst entry = this.allEditIds.get(editId);\n\t\treturn entry?.isLocal ?? false;\n\t}\n\n\t/**\n\t * @returns true iff the revision is a sequenced revision (not local).\n\t */\n\tpublic isSequencedRevision(revision: number): boolean {\n\t\treturn revision <= this.sequencedEditIds.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetIndexOfId}\n\t */\n\tpublic tryGetIndexOfId(editId: EditId): number | undefined {\n\t\tconst orderedEdit = this.allEditIds.get(editId);\n\t\tif (orderedEdit === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (orderedEdit.isLocal) {\n\t\t\tconst firstLocal = assertNotUndefined(this.allEditIds.get(this.localEdits[0].id));\n\t\t\tassert(firstLocal.isLocal);\n\t\t\treturn this.numberOfSequencedEdits + orderedEdit.localSequence - firstLocal.localSequence;\n\t\t}\n\t\treturn orderedEdit.index;\n\t}\n\n\t/**\n\t * @returns Edit metadata for the edit with the given `editId`.\n\t */\n\tpublic getOrderedEditId(editId: EditId): OrderedEditId {\n\t\treturn assertNotUndefined(this.allEditIds.get(editId), 'All edits should exist in this map');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIndexOfId}\n\t */\n\tpublic getIndexOfId(editId: EditId): number {\n\t\treturn this.tryGetIndexOfId(editId) ?? fail('edit not found');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIdAtIndex}\n\t */\n\tpublic getIdAtIndex(index: number): EditId {\n\t\tif (this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits].id;\n\t\t}\n\n\t\treturn this.sequencedEditIds[index];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditAtIndex}\n\t */\n\tpublic async getEditAtIndex(index: number): Promise<Edit<TChange>> {\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { handle, edits } = editChunk;\n\n\t\t\tif (edits === undefined) {\n\t\t\t\tassert(handle !== undefined, 'An edit chunk should include at least a handle or edits.');\n\t\t\t\tconst edits = await handle.get();\n\n\t\t\t\t// Make sure the loaded edit chunk is the correct size. If a higher starting revison is set, the length is the difference of both.\n\t\t\t\t// Otherwise, it means that there are no sequenced edits in memory so the length is the difference of the number of\n\t\t\t\t// sequenced edits and the starting revision.\n\t\t\t\tconst nextKey = this.editChunks.nextHigherKey(index);\n\t\t\t\tconst expectedEditLength =\n\t\t\t\t\t(nextKey === undefined ? this.numberOfSequencedEdits : nextKey) - startRevision;\n\t\t\t\tassert(edits.length === expectedEditLength, 'The chunk does not contain the correct number of edits.');\n\n\t\t\t\teditChunk.edits = edits;\n\n\t\t\t\tthis.addKeyToCache(startRevision);\n\t\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t\t}\n\n\t\t\treturn joinEditAndId(this.getIdAtIndex(index), edits[index - startRevision]);\n\t\t}\n\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getEditInSessionAtIndex}\n\t */\n\tpublic getEditInSessionAtIndex(index: number): Edit<TChange> {\n\t\tassert(\n\t\t\tindex > this.maximumEvictableIndex,\n\t\t\t'Edit to retrieve must have been added to the log during the current session.'\n\t\t);\n\n\t\tif (index < this.numberOfSequencedEdits) {\n\t\t\tconst [startRevision, editChunk] = assertNotUndefined(this.editChunks.getPairOrNextLower(index));\n\t\t\tconst { edits } = editChunk;\n\n\t\t\treturn joinEditAndId(\n\t\t\t\tthis.getIdAtIndex(index),\n\t\t\t\tassertNotUndefined(edits, 'Edits should not have been evicted.')[index - startRevision]\n\t\t\t);\n\t\t}\n\n\t\tassert(index - this.numberOfSequencedEdits < this.localEdits.length, 'Edit to retrieve must be in the log.');\n\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEdit}\n\t */\n\tpublic async tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined> {\n\t\ttry {\n\t\t\tconst index = this.getIndexOfId(editId);\n\t\t\treturn await this.getEditAtIndex(index);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * @returns The edits of edit chunks that do not have associated edit handles, does not include the last edit chunk if it is not full.\n\t */\n\tpublic *getEditChunksReadyForUpload(): Iterable<[number, readonly EditWithoutId<TChange>[]]> {\n\t\tconst maxStartRevision = this.editChunks.maxKey();\n\n\t\tif (maxStartRevision === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const [startRevision, chunk] of this.editChunks.entries(undefined, [])) {\n\t\t\tif (chunk.handle === undefined) {\n\t\t\t\tconst edits = assertNotUndefined(chunk.edits);\n\n\t\t\t\t// If there is no handle, the chunk should either not be the last chunk or should be full if it is.\n\t\t\t\tif (maxStartRevision !== startRevision || edits.length >= this.editsPerChunk) {\n\t\t\t\t\tyield [startRevision, edits];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Assigns provided handles to edit chunks based on chunk index specified.\n\t */\n\tpublic processEditChunkHandle(chunkHandle: EditHandle<TChange>, startRevision: number): void {\n\t\tconst chunk = this.editChunks.get(startRevision);\n\t\tif (chunk !== undefined) {\n\t\t\tassertNotUndefined(\n\t\t\t\tchunk.edits,\n\t\t\t\t'A chunk handle op should not be received before the edit ops it corresponds to.'\n\t\t\t);\n\t\t\tchunk.handle = chunkHandle;\n\t\t\tthis.addKeyToCache(startRevision);\n\t\t} else {\n\t\t\tthis.logger?.sendErrorEvent({ eventName: 'UnexpectedHistoryChunk' });\n\t\t\tthis.emit(SharedTreeDiagnosticEvent.UnexpectedHistoryChunk);\n\t\t}\n\t}\n\n\t/**\n\t * Sequences all local edits.\n\t */\n\tpublic sequenceLocalEdits(): void {\n\t\tthis.localEdits.slice().forEach((edit) => this.addSequencedEditInternal(edit));\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t *\n\t */\n\tpublic addSequencedEdit(edit: Edit<TChange>, message: MessageSequencingInfo): void {\n\t\tthis.addSequencedEditInternal(edit, message, message.minimumSequenceNumber);\n\t}\n\n\t/**\n\t * Returns all local edits from this EditLog\n\t * This is useful for op format upgrades, which might warrant re-submission of these ops using the new format.\n\t * See the breaking change documentation for more information.\n\t */\n\tpublic *getLocalEdits(): Iterable<Edit<TChange>> {\n\t\tfor (const edit of this.localEdits) {\n\t\t\tyield edit;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t */\n\tprivate addSequencedEditInternal(\n\t\tedit: Edit<TChange>,\n\t\tinfo?: EditSequencingInfo,\n\t\tminSequenceNumber: number = 0\n\t): void {\n\t\tconst { id, editWithoutId } = separateEditAndId(edit);\n\n\t\tassert(\n\t\t\tminSequenceNumber >= this.minSequenceNumber,\n\t\t\t'Sequenced edits should carry a monotonically increasing min number'\n\t\t);\n\t\t// The new minSequenceNumber indicates that no future edit will require information from edits with a smaller or equal seq number\n\t\t// for its resolution.\n\t\tthis._minSequenceNumber = minSequenceNumber;\n\t\t// TODO:#57176: Increment maximumEvictableIndex to reflect the fact we can now evict edits with a sequenceNumber lower or equal to\n\t\t// it. Note that this will change the meaning of our 'InSession' APIs so we should make sure to rename them at the same time.\n\t\t// The code might look like this:\n\t\t// while (this.maximumEvictableIndex + 1 < this.indexOfFirstEditInSession) {\n\t\t// \tconst nextEdit = this.getEditInSessionAtIndex(this.maximumEvictableIndex + 1);\n\t\t// \tconst nextEditInfo = this.getOrderedEditId(nextEdit.id) as SequencedOrderedEditId;\n\t\t// \tif (\n\t\t// \t\tnextEditInfo.sequenceInfo !== undefined &&\n\t\t// \t\tnextEditInfo.sequenceInfo.sequenceNumber > minSequenceNumber\n\t\t// \t) {\n\t\t// \t\tbreak;\n\t\t// \t}\n\t\t// \t++this.maximumEvictableIndex;\n\t\t// }\n\n\t\t// Remove the edit from local edits if it exists.\n\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\tif (encounteredEditId !== undefined) {\n\t\t\t// New edit already exits: it must have been a local edit.\n\t\t\tassert(encounteredEditId.isLocal, 'Duplicate acked edit.');\n\t\t\t// Remove it from localEdits. Due to ordering requirements, it must be first.\n\t\t\tconst oldLocalEditId = assertNotUndefined(this.localEdits.shift(), 'Local edit should exist').id;\n\t\t\tassert(oldLocalEditId === id, 'Causal ordering should be upheld');\n\t\t}\n\n\t\t// The starting revision for a newly created chunk.\n\t\tconst startRevision = this.numberOfSequencedEdits;\n\t\t// The initial edits for a newly created chunk.\n\t\tconst edits: EditWithoutId<TChange>[] = [editWithoutId];\n\n\t\tconst lastPair = this.editChunks.nextLowerPair(undefined);\n\t\tif (lastPair === undefined) {\n\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t} else {\n\t\t\t// Add to the last edit chunk if it has room and hasn't already been uploaded, otherwise create a new chunk.\n\t\t\t// If the chunk has a corresponding handle, create a new chunk.\n\t\t\tconst { edits: lastEditChunk, handle } = lastPair[1];\n\t\t\tif (handle === undefined && lastEditChunk !== undefined && lastEditChunk.length < this.editsPerChunk) {\n\t\t\t\tlastEditChunk.push(editWithoutId);\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\thandle !== undefined || lastEditChunk !== undefined,\n\t\t\t\t\t'An edit chunk must have either a handle or a list of edits.'\n\t\t\t\t);\n\t\t\t\tthis.editChunks.set(startRevision, { edits });\n\t\t\t}\n\t\t}\n\n\t\tthis.sequencedEditIds.push(id);\n\t\tconst sequencedEditId: SequencedOrderedEditId = {\n\t\t\tindex: this.numberOfSequencedEdits - 1,\n\t\t\tisLocal: false,\n\t\t\tsequenceInfo: info,\n\t\t};\n\t\tthis.allEditIds.set(id, sequencedEditId);\n\t\tthis.emitAdd(edit, false, encounteredEditId !== undefined);\n\t}\n\n\t/**\n\t * @returns The last edit chunk i.e. the chunk which the most recent sequenced edits have been placed into, as well as its starting revision.\n\t * Returns undefined iff there are no sequenced edits.\n\t * When defined, this chunk is guaranteed to contain at least one edit\n\t * (though it may be necessary to load the chunk via its handle to use it)\n\t */\n\tpublic getLastEditChunk(): [startRevision: number, edits: EditChunk<TChange>] | undefined {\n\t\treturn this.editChunks.nextLowerPair(undefined);\n\t}\n\n\t/**\n\t * Adds a non-sequenced (local) edit to the edit log.\n\t * Duplicate edits are ignored.\n\t */\n\tpublic addLocalEdit(edit: Edit<TChange>): void {\n\t\tthis.localEdits.push(edit);\n\t\tconst localEditId: LocalOrderedEditId = { localSequence: this.localEditSequence++, isLocal: true };\n\t\tthis.allEditIds.set(edit.id, localEditId);\n\t\tthis.emitAdd(edit, true, false);\n\t}\n\n\tprivate emitAdd(editAdded: Edit<TChange>, isLocal: boolean, wasLocal: boolean): void {\n\t\tfor (const handler of this._editAddedHandlers) {\n\t\t\thandler(editAdded, isLocal, wasLocal);\n\t\t}\n\t}\n\n\t/**\n\t * @returns true iff this `EditLog` and `other` are equivalent, regardless of locality.\n\t */\n\tpublic equals<TOtherChangeTypesInternal>(other: EditLog<TOtherChangeTypesInternal>): boolean {\n\t\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\t\treturn compareArrays(this.editIds, other.editIds);\n\t}\n\n\t/**\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary(): EditLogSummary<TChange, FluidEditHandle>;\n\t/**\n\t * @param compressEdit - a function which compresses edits\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TCompressedChange, FluidEditHandle>;\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit?: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TChange, FluidEditHandle> | EditLogSummary<TCompressedChange, FluidEditHandle> {\n\t\tif (compressEdit !== undefined) {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits?.map((edit) => compressEdit(edit)) ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\teditChunks: this.editChunks.toArray().map(([startRevision, { handle, edits }]) => ({\n\t\t\t\t\tstartRevision,\n\t\t\t\t\tchunk:\n\t\t\t\t\t\thandle?.baseHandle ??\n\t\t\t\t\t\tedits ??\n\t\t\t\t\t\tfail('An edit chunk must have either a handle or a list of edits.'),\n\t\t\t\t})),\n\t\t\t\teditIds: this.sequencedEditIds,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate addKeyToCache(newKey: number): void {\n\t\t// Indices are only added to the cache if they are not higher than the maximum evicted index.\n\t\tif (newKey <= this.maximumEvictableIndex) {\n\t\t\t// If the new index is already in the cache, remove it first to update its last usage.\n\t\t\tif (newKey in this.loadedChunkCache) {\n\t\t\t\tthis.loadedChunkCache.splice(this.loadedChunkCache.indexOf(newKey), 1);\n\t\t\t}\n\n\t\t\tthis.loadedChunkCache.push(newKey);\n\n\t\t\t// If the cache is out of space, evict the oldest index in the cache.\n\t\t\tif (this.loadedChunkCache.length > loadedChunkCacheSize) {\n\t\t\t\tconst indexToEvict = assertNotUndefined(this.loadedChunkCache.shift());\n\t\t\t\tconst chunkToEvict = assertNotUndefined(\n\t\t\t\t\tthis.editChunks.get(indexToEvict),\n\t\t\t\t\t'Chunk start revision added to cache should exist in the edit log.'\n\t\t\t\t);\n\t\t\t\tchunkToEvict.edits = undefined;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isEditHandle<TChange>(\n\tchunk: EditHandle<TChange> | readonly EditWithoutId<unknown>[]\n): chunk is EditHandle<TChange> {\n\treturn !Array.isArray(chunk);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/tree",
|
|
3
|
-
"version": "0.59.
|
|
3
|
+
"version": "0.59.3001",
|
|
4
4
|
"description": "Distributed tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"@fluidframework/common-utils": "^0.32.1",
|
|
39
39
|
"@fluidframework/container-definitions": "^0.48.1000",
|
|
40
40
|
"@fluidframework/core-interfaces": "^0.43.1000",
|
|
41
|
-
"@fluidframework/datastore-definitions": "0.59.
|
|
41
|
+
"@fluidframework/datastore-definitions": "^0.59.3001",
|
|
42
42
|
"@fluidframework/protocol-definitions": "^0.1028.1000",
|
|
43
|
-
"@fluidframework/runtime-definitions": "0.59.
|
|
44
|
-
"@fluidframework/shared-object-base": "0.59.
|
|
45
|
-
"@fluidframework/telemetry-utils": "0.59.
|
|
43
|
+
"@fluidframework/runtime-definitions": "^0.59.3001",
|
|
44
|
+
"@fluidframework/shared-object-base": "^0.59.3001",
|
|
45
|
+
"@fluidframework/telemetry-utils": "^0.59.3001",
|
|
46
46
|
"buffer": "^6.0.3",
|
|
47
47
|
"denque": "^1.5.1",
|
|
48
48
|
"lru-cache": "^6.0.0",
|
|
@@ -50,19 +50,19 @@
|
|
|
50
50
|
"uuid": "^8.3.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@fluid-internal/stochastic-test-utils": "0.59.
|
|
53
|
+
"@fluid-internal/stochastic-test-utils": "^0.59.3001",
|
|
54
54
|
"@fluid-tools/benchmark": "^0.40.0",
|
|
55
55
|
"@fluidframework/build-common": "^0.23.0",
|
|
56
|
-
"@fluidframework/container-loader": "0.59.
|
|
57
|
-
"@fluidframework/container-runtime": "0.59.
|
|
58
|
-
"@fluidframework/eslint-config-fluid": "^0.28.2000
|
|
59
|
-
"@fluidframework/mocha-test-setup": "0.59.
|
|
60
|
-
"@fluidframework/runtime-utils": "0.59.
|
|
61
|
-
"@fluidframework/test-driver-definitions": "0.59.
|
|
62
|
-
"@fluidframework/test-drivers": "0.59.
|
|
63
|
-
"@fluidframework/test-runtime-utils": "0.59.
|
|
64
|
-
"@fluidframework/test-utils": "0.59.
|
|
65
|
-
"@fluidframework/undo-redo": "0.59.
|
|
56
|
+
"@fluidframework/container-loader": "^0.59.3001",
|
|
57
|
+
"@fluidframework/container-runtime": "^0.59.3001",
|
|
58
|
+
"@fluidframework/eslint-config-fluid": "^0.28.2000",
|
|
59
|
+
"@fluidframework/mocha-test-setup": "^0.59.3001",
|
|
60
|
+
"@fluidframework/runtime-utils": "^0.59.3001",
|
|
61
|
+
"@fluidframework/test-driver-definitions": "^0.59.3001",
|
|
62
|
+
"@fluidframework/test-drivers": "^0.59.3001",
|
|
63
|
+
"@fluidframework/test-runtime-utils": "^0.59.3001",
|
|
64
|
+
"@fluidframework/test-utils": "^0.59.3001",
|
|
65
|
+
"@fluidframework/undo-redo": "^0.59.3001",
|
|
66
66
|
"@microsoft/api-extractor": "^7.22.2",
|
|
67
67
|
"@rushstack/eslint-config": "^2.5.1",
|
|
68
68
|
"@types/lru-cache": "^5.1.0",
|
package/src/EditLog.ts
CHANGED
|
@@ -331,7 +331,7 @@ export class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents
|
|
|
331
331
|
*/
|
|
332
332
|
public isLocalEdit(editId: EditId): boolean {
|
|
333
333
|
const entry = this.allEditIds.get(editId);
|
|
334
|
-
return entry
|
|
334
|
+
return entry?.isLocal ?? false;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
/**
|