@fluidframework/odsp-driver 0.59.4002 → 1.0.2
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/.eslintrc.js +1 -1
- package/dist/compactSnapshotParser.d.ts.map +1 -1
- package/dist/compactSnapshotParser.js +4 -1
- package/dist/compactSnapshotParser.js.map +1 -1
- package/dist/compactSnapshotWriter.d.ts.map +1 -1
- package/dist/compactSnapshotWriter.js +6 -3
- package/dist/compactSnapshotWriter.js.map +1 -1
- package/dist/epochTracker.d.ts +3 -2
- package/dist/epochTracker.d.ts.map +1 -1
- package/dist/epochTracker.js +10 -4
- package/dist/epochTracker.js.map +1 -1
- package/dist/fetchSnapshot.js +2 -2
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/odspDocumentDeltaConnection.js +2 -1
- package/dist/odspDocumentDeltaConnection.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +2 -2
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +0 -1
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +0 -4
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspSnapshotParser.d.ts +1 -1
- package/dist/odspSnapshotParser.js +3 -3
- package/dist/odspSnapshotParser.js.map +1 -1
- package/dist/odspSummaryUploadManager.d.ts.map +1 -1
- package/dist/odspSummaryUploadManager.js +1 -4
- package/dist/odspSummaryUploadManager.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/retryErrorsStorageAdapter.d.ts +1 -2
- package/dist/retryErrorsStorageAdapter.d.ts.map +1 -1
- package/dist/retryErrorsStorageAdapter.js +0 -3
- package/dist/retryErrorsStorageAdapter.js.map +1 -1
- package/dist/retryUtils.d.ts.map +1 -1
- package/dist/retryUtils.js +2 -3
- package/dist/retryUtils.js.map +1 -1
- package/lib/compactSnapshotParser.d.ts.map +1 -1
- package/lib/compactSnapshotParser.js +4 -1
- package/lib/compactSnapshotParser.js.map +1 -1
- package/lib/compactSnapshotWriter.d.ts.map +1 -1
- package/lib/compactSnapshotWriter.js +6 -3
- package/lib/compactSnapshotWriter.js.map +1 -1
- package/lib/epochTracker.d.ts +3 -2
- package/lib/epochTracker.d.ts.map +1 -1
- package/lib/epochTracker.js +10 -4
- package/lib/epochTracker.js.map +1 -1
- package/lib/fetchSnapshot.js +3 -3
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/lib/odspDocumentDeltaConnection.js +2 -1
- package/lib/odspDocumentDeltaConnection.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +2 -2
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +0 -1
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +0 -4
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspSnapshotParser.d.ts +1 -1
- package/lib/odspSnapshotParser.js +1 -1
- package/lib/odspSnapshotParser.js.map +1 -1
- package/lib/odspSummaryUploadManager.d.ts.map +1 -1
- package/lib/odspSummaryUploadManager.js +1 -4
- package/lib/odspSummaryUploadManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/retryErrorsStorageAdapter.d.ts +1 -2
- package/lib/retryErrorsStorageAdapter.d.ts.map +1 -1
- package/lib/retryErrorsStorageAdapter.js +0 -3
- package/lib/retryErrorsStorageAdapter.js.map +1 -1
- package/lib/retryUtils.d.ts.map +1 -1
- package/lib/retryUtils.js +3 -4
- package/lib/retryUtils.js.map +1 -1
- package/package.json +12 -25
- package/src/compactSnapshotParser.ts +3 -1
- package/src/compactSnapshotWriter.ts +6 -3
- package/src/epochTracker.ts +10 -3
- package/src/fetchSnapshot.ts +3 -3
- package/src/odspDocumentDeltaConnection.ts +2 -1
- package/src/odspDocumentServiceFactoryCore.ts +4 -2
- package/src/odspDocumentStorageManager.ts +0 -6
- package/src/odspSnapshotParser.ts +1 -1
- package/src/odspSummaryUploadManager.ts +1 -4
- package/src/packageVersion.ts +1 -1
- package/src/retryErrorsStorageAdapter.ts +0 -8
- package/src/retryUtils.ts +3 -4
|
@@ -57,10 +57,13 @@ function readTreeSection(node) {
|
|
|
57
57
|
assertBlobCoreInstance(records.value, "Blob value should be BlobCore");
|
|
58
58
|
snapshotTree.blobs[path] = records.value.toString();
|
|
59
59
|
}
|
|
60
|
-
else {
|
|
60
|
+
else if (records.children !== undefined) {
|
|
61
61
|
assertNodeCoreInstance(records.children, "Trees should be of type NodeCore");
|
|
62
62
|
snapshotTree.trees[path] = readTreeSection(records.children);
|
|
63
63
|
}
|
|
64
|
+
else {
|
|
65
|
+
snapshotTree.trees[path] = { blobs: {}, commits: {}, trees: {} };
|
|
66
|
+
}
|
|
64
67
|
if (records.unreferenced !== undefined) {
|
|
65
68
|
assertBoolInstance(records.unreferenced, "Unreferenced flag should be bool");
|
|
66
69
|
const unreferenced = records.unreferenced.valueOf();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compactSnapshotParser.js","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAKtD,OAAO,EACH,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EAGvB,WAAW,GACd,MAAM,gCAAgC,CAAC;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K,CAAC,8BAA8B,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEhC,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,EACxC,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;IAEzD,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,2CAA2C,CAAC,CAAC;IACjF,sBAAsB,CAAC,OAAO,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAC;IAC/E,MAAM,CAAC,sBAAsB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EACnD,KAAK,CAAC,kEAAkE,CAAC,CAAC;IAC9E,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,sBAAsB,EAClD,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC3E,MAAM,CAAC,kBAAkB,KAAK,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,EAC/C,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACxE,uCACO,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,KACxC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EACrC,GAAG,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IACzE;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ISnapshotContents } from \"./odspUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport { ISnapshotTreeEx } from \"./contracts\";\nimport {\n assertBlobCoreInstance,\n assertBoolInstance,\n assertNodeCoreInstance,\n assertNumberInstance,\n getAndValidateNodeProps,\n NodeCore,\n NodeTypes,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\nexport const snapshotMinReadVersion = \"1.0\";\nexport const currentReadVersion = \"1.0\";\n\ninterface ISnapshotSection {\n snapshotTree: ISnapshotTree;\n sequenceNumber: number;\n}\n\n/**\n * Recreates blobs section of the tree.\n * @param node - tree node to read blob section from\n */\nfunction readBlobSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"TreeBlobs should be of type NodeCore\");\n const blobs: Map<string, ArrayBuffer> = new Map();\n for (let count = 0; count < node.length; ++count) {\n const blob = node.getNode(count);\n const records = getAndValidateNodeProps(blob, [\"id\", \"data\"]);\n assertBlobCoreInstance(records.data, \"data should be of BlobCore type\");\n assertBlobCoreInstance(records.id, \"blob id should be of BlobCore type\");\n blobs.set(records.id.toString(), records.data.arrayBuffer);\n }\n return blobs;\n}\n\n/**\n * Recreates ops section of the tree.\n * @param node - tree node to read ops section from\n */\nfunction readOpsSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"Deltas should be of type NodeCore\");\n const ops: ISequencedDocumentMessage[] = [];\n const records = getAndValidateNodeProps(node, [\"firstSequenceNumber\", \"deltas\"]);\n assertNumberInstance(records.firstSequenceNumber, \"Seq number should be a number\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be a Node\");\n for (let i = 0; i < records.deltas.length; ++i) {\n ops.push(JSON.parse(records.deltas.getString(i)));\n }\n assert(records.firstSequenceNumber.valueOf() === ops[0].sequenceNumber,\n 0x280 /* \"Validate first op seq number\" */);\n return ops;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readTreeSection(node: NodeCore) {\n const snapshotTree: ISnapshotTreeEx = {\n blobs: {},\n commits: {},\n trees: {},\n };\n for (let count = 0; count < node.length; count++) {\n const treeNode = node.getNode(count);\n const records = getAndValidateNodeProps(treeNode,\n [\"name\", \"value\", \"children\", \"unreferenced\"], false);\n assertBlobCoreInstance(records.name, \"Path should be of BlobCore\");\n const path = records.name.toString();\n if (records.value !== undefined) {\n assertBlobCoreInstance(records.value, \"Blob value should be BlobCore\");\n snapshotTree.blobs[path] = records.value.toString();\n } else {\n assertNodeCoreInstance(records.children, \"Trees should be of type NodeCore\");\n snapshotTree.trees[path] = readTreeSection(records.children);\n }\n if (records.unreferenced !== undefined) {\n assertBoolInstance(records.unreferenced, \"Unreferenced flag should be bool\");\n const unreferenced = records.unreferenced.valueOf();\n assert(unreferenced, 0x281 /* \"Unreferenced if present should be true\" */);\n snapshotTree.unreferenced = unreferenced;\n }\n }\n return snapshotTree;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readSnapshotSection(node: NodeTypes): ISnapshotSection {\n assertNodeCoreInstance(node, \"Snapshot should be of type NodeCore\");\n const records = getAndValidateNodeProps(node,\n [\"id\", \"sequenceNumber\", \"treeNodes\"]);\n\n assertNodeCoreInstance(records.treeNodes, \"TreeNodes should be of type NodeCore\");\n assertNumberInstance(records.sequenceNumber, \"sequenceNumber should be of type number\");\n assertBlobCoreInstance(records.id, \"snapshotId should be BlobCore\");\n const snapshotTree: ISnapshotTree = readTreeSection(records.treeNodes);\n snapshotTree.id = records.id.toString();\n const sequenceNumber = records.sequenceNumber.valueOf();\n return {\n sequenceNumber,\n snapshotTree,\n };\n}\n\n/**\n * Converts snapshot from binary compact representation to tree/blobs/ops.\n * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.\n * @returns - tree, blobs and ops from the snapshot.\n */\nexport function parseCompactSnapshotResponse(buffer: ReadBuffer): ISnapshotContents {\n const builder = TreeBuilder.load(buffer);\n assert(builder.length === 1, 0x219 /* \"1 root should be there\" */);\n const root = builder.getNode(0);\n\n const records = getAndValidateNodeProps(root,\n [\"mrv\", \"cv\", \"snapshot\", \"blobs\", \"deltas\"], false);\n\n assertBlobCoreInstance(records.mrv, \"minReadVersion should be of BlobCore type\");\n assertBlobCoreInstance(records.cv, \"createVersion should be of BlobCore type\");\n assert(snapshotMinReadVersion >= records.mrv.toString(),\n 0x20f /* \"Driver min read version should >= to server minReadVersion\" */);\n assert(records.cv.toString() >= snapshotMinReadVersion,\n 0x210 /* \"Snapshot should be created with minReadVersion or above\" */);\n assert(currentReadVersion === records.cv.toString(),\n 0x2c2 /* \"Create Version should be equal to currentReadVersion\" */);\n return {\n ...readSnapshotSection(records.snapshot),\n blobs: readBlobSection(records.blobs),\n ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [],\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"compactSnapshotParser.js","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAKtD,OAAO,EACH,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EAGvB,WAAW,GACd,MAAM,gCAAgC,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAOxC;;;GAGG;AACH,SAAS,eAAe,CAAC,IAAe;IACpC,sBAAsB,CAAC,IAAI,EAAE,sCAAsC,CAAC,CAAC;IACrE,MAAM,KAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;IAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9D,sBAAsB,CAAC,OAAO,CAAC,IAAI,EAAE,iCAAiC,CAAC,CAAC;QACxE,sBAAsB,CAA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,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EACnD,KAAK,CAAC,kEAAkE,CAAC,CAAC;IAC9E,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,sBAAsB,EAClD,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC3E,MAAM,CAAC,kBAAkB,KAAK,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,EAC/C,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACxE,uCACO,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,KACxC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EACrC,GAAG,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IACzE;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ISnapshotContents } from \"./odspUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport { ISnapshotTreeEx } from \"./contracts\";\nimport {\n assertBlobCoreInstance,\n assertBoolInstance,\n assertNodeCoreInstance,\n assertNumberInstance,\n getAndValidateNodeProps,\n NodeCore,\n NodeTypes,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\nexport const snapshotMinReadVersion = \"1.0\";\nexport const currentReadVersion = \"1.0\";\n\ninterface ISnapshotSection {\n snapshotTree: ISnapshotTree;\n sequenceNumber: number;\n}\n\n/**\n * Recreates blobs section of the tree.\n * @param node - tree node to read blob section from\n */\nfunction readBlobSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"TreeBlobs should be of type NodeCore\");\n const blobs: Map<string, ArrayBuffer> = new Map();\n for (let count = 0; count < node.length; ++count) {\n const blob = node.getNode(count);\n const records = getAndValidateNodeProps(blob, [\"id\", \"data\"]);\n assertBlobCoreInstance(records.data, \"data should be of BlobCore type\");\n assertBlobCoreInstance(records.id, \"blob id should be of BlobCore type\");\n blobs.set(records.id.toString(), records.data.arrayBuffer);\n }\n return blobs;\n}\n\n/**\n * Recreates ops section of the tree.\n * @param node - tree node to read ops section from\n */\nfunction readOpsSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"Deltas should be of type NodeCore\");\n const ops: ISequencedDocumentMessage[] = [];\n const records = getAndValidateNodeProps(node, [\"firstSequenceNumber\", \"deltas\"]);\n assertNumberInstance(records.firstSequenceNumber, \"Seq number should be a number\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be a Node\");\n for (let i = 0; i < records.deltas.length; ++i) {\n ops.push(JSON.parse(records.deltas.getString(i)));\n }\n assert(records.firstSequenceNumber.valueOf() === ops[0].sequenceNumber,\n 0x280 /* \"Validate first op seq number\" */);\n return ops;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readTreeSection(node: NodeCore) {\n const snapshotTree: ISnapshotTreeEx = {\n blobs: {},\n commits: {},\n trees: {},\n };\n for (let count = 0; count < node.length; count++) {\n const treeNode = node.getNode(count);\n const records = getAndValidateNodeProps(treeNode,\n [\"name\", \"value\", \"children\", \"unreferenced\"], false);\n assertBlobCoreInstance(records.name, \"Path should be of BlobCore\");\n const path = records.name.toString();\n if (records.value !== undefined) {\n assertBlobCoreInstance(records.value, \"Blob value should be BlobCore\");\n snapshotTree.blobs[path] = records.value.toString();\n } else if (records.children !== undefined) {\n assertNodeCoreInstance(records.children, \"Trees should be of type NodeCore\");\n snapshotTree.trees[path] = readTreeSection(records.children);\n } else {\n snapshotTree.trees[path] = { blobs: {}, commits: {}, trees: {} };\n }\n if (records.unreferenced !== undefined) {\n assertBoolInstance(records.unreferenced, \"Unreferenced flag should be bool\");\n const unreferenced = records.unreferenced.valueOf();\n assert(unreferenced, 0x281 /* \"Unreferenced if present should be true\" */);\n snapshotTree.unreferenced = unreferenced;\n }\n }\n return snapshotTree;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readSnapshotSection(node: NodeTypes): ISnapshotSection {\n assertNodeCoreInstance(node, \"Snapshot should be of type NodeCore\");\n const records = getAndValidateNodeProps(node,\n [\"id\", \"sequenceNumber\", \"treeNodes\"]);\n\n assertNodeCoreInstance(records.treeNodes, \"TreeNodes should be of type NodeCore\");\n assertNumberInstance(records.sequenceNumber, \"sequenceNumber should be of type number\");\n assertBlobCoreInstance(records.id, \"snapshotId should be BlobCore\");\n const snapshotTree: ISnapshotTree = readTreeSection(records.treeNodes);\n snapshotTree.id = records.id.toString();\n const sequenceNumber = records.sequenceNumber.valueOf();\n return {\n sequenceNumber,\n snapshotTree,\n };\n}\n\n/**\n * Converts snapshot from binary compact representation to tree/blobs/ops.\n * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.\n * @returns - tree, blobs and ops from the snapshot.\n */\nexport function parseCompactSnapshotResponse(buffer: ReadBuffer): ISnapshotContents {\n const builder = TreeBuilder.load(buffer);\n assert(builder.length === 1, 0x219 /* \"1 root should be there\" */);\n const root = builder.getNode(0);\n\n const records = getAndValidateNodeProps(root,\n [\"mrv\", \"cv\", \"snapshot\", \"blobs\", \"deltas\"], false);\n\n assertBlobCoreInstance(records.mrv, \"minReadVersion should be of BlobCore type\");\n assertBlobCoreInstance(records.cv, \"createVersion should be of BlobCore type\");\n assert(snapshotMinReadVersion >= records.mrv.toString(),\n 0x20f /* \"Driver min read version should >= to server minReadVersion\" */);\n assert(records.cv.toString() >= snapshotMinReadVersion,\n 0x210 /* \"Snapshot should be created with minReadVersion or above\" */);\n assert(currentReadVersion === records.cv.toString(),\n 0x2c2 /* \"Create Version should be equal to currentReadVersion\" */);\n return {\n ...readSnapshotSection(records.snapshot),\n blobs: readBlobSection(records.blobs),\n ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [],\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compactSnapshotWriter.d.ts","sourceRoot":"","sources":["../src/compactSnapshotWriter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"compactSnapshotWriter.d.ts","sourceRoot":"","sources":["../src/compactSnapshotWriter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAqH/C;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,iBAAiB,GAAG,UAAU,CAsBxF"}
|
|
@@ -54,9 +54,12 @@ function writeTreeSectionCore(treesNode, snapshotTree) {
|
|
|
54
54
|
if (snapshotTree.unreferenced) {
|
|
55
55
|
addBoolProperty(treeNode, "unreferenced", snapshotTree.unreferenced);
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
// Only write children prop if either blobs or trees are present.
|
|
58
|
+
if (Object.keys(value.blobs).length > 0 || Object.keys(value.trees).length > 0) {
|
|
59
|
+
treeNode.addString("children", true);
|
|
60
|
+
const childNode = treeNode.addNode("list");
|
|
61
|
+
writeTreeSectionCore(childNode, value);
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
if (snapshotTree.blobs) {
|
|
62
65
|
for (const [path, id] of Object.entries(snapshotTree.blobs)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compactSnapshotWriter.js","sourceRoot":"","sources":["../src/compactSnapshotWriter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAA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AAE,KAAK,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAmC;IACxE,MAAM,OAAO,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAC5C,wBAAwB;IACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IACnC,MAAM,CAAC,gBAAgB,CAAC,cAAc,KAAK,SAAS,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACnG,MAAM,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC;IACjC,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,gBAAgB,CAAC,cAAc,CAAC;IACnH,kBAAkB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAEnD,oBAAoB,CAChB,QAAQ,EACR,gBAAgB,CAAC,YAAY,EAC7B,gBAAgB,CAAC,cAAc,CAClC,CAAC;IAEF,YAAY;IACZ,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAEpD,2BAA2B;IAC3B,eAAe,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAE/B,OAAO,OAAO,CAAC,SAAS,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, stringToBuffer } from \"@fluidframework/common-utils\";\nimport { IBlob, ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { snapshotMinReadVersion } from \"./compactSnapshotParser\";\nimport { ISnapshotContents } from \"./odspUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport { TreeBuilderSerializer } from \"./WriteBufferUtils\";\nimport { addBoolProperty, addNumberProperty, addStringProperty, NodeCore } from \"./zipItDataRepresentationUtils\";\n\n/**\n * Writes header section of the snapshot.\n * @param node - snapshot node to serialize to\n * @param latestSequenceNumber - latest seq number of the container.\n*/\nfunction writeSnapshotProps(node: NodeCore, latestSequenceNumber: number) {\n addStringProperty(node, \"mrv\", snapshotMinReadVersion);\n addStringProperty(node, \"cv\", snapshotMinReadVersion);\n addNumberProperty(node, \"lsn\", latestSequenceNumber);\n}\n\n/**\n * Represents blobs in the tree.\n * @param snapshotNode - node to serialize to.\n * @param blobs - blobs that is being serialized\n*/\nfunction writeBlobsSection(snapshotNode: NodeCore, blobs: Map<string, IBlob | ArrayBuffer>) {\n snapshotNode.addString(\"blobs\", true);\n const blobsNode = snapshotNode.addNode(\"list\");\n for (const [storageBlobId, blob] of blobs) {\n const blobNode = blobsNode.addNode();\n addStringProperty(blobNode, \"id\", storageBlobId, true);\n blobNode.addString(\"data\", true);\n if (blob instanceof ArrayBuffer) {\n blobNode.addBlob(new Uint8Array(blob), false);\n } else {\n blobNode.addBlob(new Uint8Array(stringToBuffer(blob.contents, blob.encoding ?? \"utf-8\")), false);\n }\n }\n}\n\n/**\n * Represents and serializes tree part of the snapshot\n * @param snapshotNode - tree node to serialize to\n * @param snapshotTree - snapshot tree that is being serialized\n*/\nfunction writeTreeSection(snapshotNode: NodeCore, snapshotTree: ISnapshotTree) {\n snapshotNode.addString(\"treeNodes\", true);\n const treesNode = snapshotNode.addNode(\"list\");\n writeTreeSectionCore(treesNode, snapshotTree);\n}\n\nfunction writeTreeSectionCore(treesNode: NodeCore, snapshotTree: ISnapshotTree) {\n for (const [path, value] of Object.entries(snapshotTree.trees)) {\n const treeNode = treesNode.addNode();\n addStringProperty(treeNode, \"name\", path);\n if (snapshotTree.unreferenced) {\n addBoolProperty(treeNode, \"unreferenced\", snapshotTree.unreferenced);\n }\n treeNode.addString(\"children\", true);\n const childNode = treeNode.addNode(\"list\");\n writeTreeSectionCore(childNode, value);\n }\n\n if (snapshotTree.blobs) {\n for (const [path, id] of Object.entries(snapshotTree.blobs)) {\n const blobNode = treesNode.addNode();\n addStringProperty(blobNode, \"name\", path);\n addStringProperty(blobNode, \"value\", id, true);\n }\n }\n}\n\n/**\n * Represents (serializes) snapshot tree as generalizes tree\n * @param rootNode - tree node to serialize to\n * @param snapshotTree - snapshot tree that is being serialized\n * @param blobs - blobs mapping of the snapshot\n * @param snapshotSequenceNumber - seq number at which snapshot is taken\n*/\nfunction writeSnapshotSection(\n rootNode: NodeCore,\n snapshotTree: ISnapshotTree,\n snapshotSequenceNumber: number,\n) {\n rootNode.addString(\"snapshot\", true);\n const snapshotNode = rootNode.addNode();\n\n const snapshotId = snapshotTree.id;\n assert(snapshotId !== undefined, 0x21b /* \"Snapshot id should be provided\" */);\n addStringProperty(snapshotNode, \"id\", snapshotId);\n addStringProperty(snapshotNode, \"message\", `Snapshot@${snapshotSequenceNumber}`);\n addNumberProperty(snapshotNode, \"sequenceNumber\", snapshotSequenceNumber);\n\n // Add Trees\n writeTreeSection(snapshotNode, snapshotTree);\n}\n\n/**\n * Represents ops in the tree.\n * @param rootNode - node to serialize to.\n * @param ops - ops that is being serialized\n*/\nfunction writeOpsSection(rootNode: NodeCore, ops: ISequencedDocumentMessage[]) {\n let firstSequenceNumber: number | undefined;\n if (ops.length > 0) {\n firstSequenceNumber = ops[0].sequenceNumber;\n }\n if (firstSequenceNumber !== undefined) {\n rootNode.addString(\"deltas\", true);\n const opsNode = rootNode.addNode();\n addNumberProperty(opsNode, \"firstSequenceNumber\", firstSequenceNumber);\n opsNode.addString(\"deltas\", true);\n const deltaNode = opsNode.addNode(\"list\");\n ops.forEach((op) => {\n deltaNode.addString(JSON.stringify(op), false);\n });\n }\n}\n\n/**\n * Converts trees/blobs/ops to binary compact representation.\n * @param snapshotContents - snapshot tree contents to serialize\n * @returns - ReadBuffer - binary representation of the data.\n */\nexport function convertToCompactSnapshot(snapshotContents: ISnapshotContents): ReadBuffer {\n const builder = new TreeBuilderSerializer();\n // Create the root node.\n const rootNode = builder.addNode();\n assert(snapshotContents.sequenceNumber !== undefined, 0x21c /* \"Seq number should be provided\" */);\n const ops = snapshotContents.ops;\n const latestSequenceNumber = ops.length > 0 ? ops[ops.length - 1].sequenceNumber : snapshotContents.sequenceNumber;\n writeSnapshotProps(rootNode, latestSequenceNumber);\n\n writeSnapshotSection(\n rootNode,\n snapshotContents.snapshotTree,\n snapshotContents.sequenceNumber,\n );\n\n // Add Blobs\n writeBlobsSection(rootNode, snapshotContents.blobs);\n\n // Then write the ops node.\n writeOpsSection(rootNode, ops);\n\n return builder.serialize();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"compactSnapshotWriter.js","sourceRoot":"","sources":["../src/compactSnapshotWriter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAY,MAAM,gCAAgC,CAAC;AAEjH;;;;EAIE;AACF,SAAS,kBAAkB,CAAC,IAAc,EAAE,oBAA4B;IACpE,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACvD,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACtD,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC;AACzD,CAAC;AAED;;;;EAIE;AACF,SAAS,iBAAiB,CAAC,YAAsB,EAAE,KAAuC;;IACtF,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,KAAK,MAAM,CAAC,aAAa,EAAE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CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,gBAAgB,CAAC,cAAc,CAAC;IACnH,kBAAkB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAEnD,oBAAoB,CAChB,QAAQ,EACR,gBAAgB,CAAC,YAAY,EAC7B,gBAAgB,CAAC,cAAc,CAClC,CAAC;IAEF,YAAY;IACZ,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAEpD,2BAA2B;IAC3B,eAAe,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAE/B,OAAO,OAAO,CAAC,SAAS,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, stringToBuffer } from \"@fluidframework/common-utils\";\nimport { IBlob, ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { snapshotMinReadVersion } from \"./compactSnapshotParser\";\nimport { ISnapshotContents } from \"./odspUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport { TreeBuilderSerializer } from \"./WriteBufferUtils\";\nimport { addBoolProperty, addNumberProperty, addStringProperty, NodeCore } from \"./zipItDataRepresentationUtils\";\n\n/**\n * Writes header section of the snapshot.\n * @param node - snapshot node to serialize to\n * @param latestSequenceNumber - latest seq number of the container.\n*/\nfunction writeSnapshotProps(node: NodeCore, latestSequenceNumber: number) {\n addStringProperty(node, \"mrv\", snapshotMinReadVersion);\n addStringProperty(node, \"cv\", snapshotMinReadVersion);\n addNumberProperty(node, \"lsn\", latestSequenceNumber);\n}\n\n/**\n * Represents blobs in the tree.\n * @param snapshotNode - node to serialize to.\n * @param blobs - blobs that is being serialized\n*/\nfunction writeBlobsSection(snapshotNode: NodeCore, blobs: Map<string, IBlob | ArrayBuffer>) {\n snapshotNode.addString(\"blobs\", true);\n const blobsNode = snapshotNode.addNode(\"list\");\n for (const [storageBlobId, blob] of blobs) {\n const blobNode = blobsNode.addNode();\n addStringProperty(blobNode, \"id\", storageBlobId, true);\n blobNode.addString(\"data\", true);\n if (blob instanceof ArrayBuffer) {\n blobNode.addBlob(new Uint8Array(blob), false);\n } else {\n blobNode.addBlob(new Uint8Array(stringToBuffer(blob.contents, blob.encoding ?? \"utf-8\")), false);\n }\n }\n}\n\n/**\n * Represents and serializes tree part of the snapshot\n * @param snapshotNode - tree node to serialize to\n * @param snapshotTree - snapshot tree that is being serialized\n*/\nfunction writeTreeSection(snapshotNode: NodeCore, snapshotTree: ISnapshotTree) {\n snapshotNode.addString(\"treeNodes\", true);\n const treesNode = snapshotNode.addNode(\"list\");\n writeTreeSectionCore(treesNode, snapshotTree);\n}\n\nfunction writeTreeSectionCore(treesNode: NodeCore, snapshotTree: ISnapshotTree) {\n for (const [path, value] of Object.entries(snapshotTree.trees)) {\n const treeNode = treesNode.addNode();\n addStringProperty(treeNode, \"name\", path);\n if (snapshotTree.unreferenced) {\n addBoolProperty(treeNode, \"unreferenced\", snapshotTree.unreferenced);\n }\n // Only write children prop if either blobs or trees are present.\n if (Object.keys(value.blobs).length > 0 || Object.keys(value.trees).length > 0) {\n treeNode.addString(\"children\", true);\n const childNode = treeNode.addNode(\"list\");\n writeTreeSectionCore(childNode, value);\n }\n }\n\n if (snapshotTree.blobs) {\n for (const [path, id] of Object.entries(snapshotTree.blobs)) {\n const blobNode = treesNode.addNode();\n addStringProperty(blobNode, \"name\", path);\n addStringProperty(blobNode, \"value\", id, true);\n }\n }\n}\n\n/**\n * Represents (serializes) snapshot tree as generalizes tree\n * @param rootNode - tree node to serialize to\n * @param snapshotTree - snapshot tree that is being serialized\n * @param blobs - blobs mapping of the snapshot\n * @param snapshotSequenceNumber - seq number at which snapshot is taken\n*/\nfunction writeSnapshotSection(\n rootNode: NodeCore,\n snapshotTree: ISnapshotTree,\n snapshotSequenceNumber: number,\n) {\n rootNode.addString(\"snapshot\", true);\n const snapshotNode = rootNode.addNode();\n\n const snapshotId = snapshotTree.id;\n assert(snapshotId !== undefined, 0x21b /* \"Snapshot id should be provided\" */);\n addStringProperty(snapshotNode, \"id\", snapshotId);\n addStringProperty(snapshotNode, \"message\", `Snapshot@${snapshotSequenceNumber}`);\n addNumberProperty(snapshotNode, \"sequenceNumber\", snapshotSequenceNumber);\n\n // Add Trees\n writeTreeSection(snapshotNode, snapshotTree);\n}\n\n/**\n * Represents ops in the tree.\n * @param rootNode - node to serialize to.\n * @param ops - ops that is being serialized\n*/\nfunction writeOpsSection(rootNode: NodeCore, ops: ISequencedDocumentMessage[]) {\n let firstSequenceNumber: number | undefined;\n if (ops.length > 0) {\n firstSequenceNumber = ops[0].sequenceNumber;\n }\n if (firstSequenceNumber !== undefined) {\n rootNode.addString(\"deltas\", true);\n const opsNode = rootNode.addNode();\n addNumberProperty(opsNode, \"firstSequenceNumber\", firstSequenceNumber);\n opsNode.addString(\"deltas\", true);\n const deltaNode = opsNode.addNode(\"list\");\n ops.forEach((op) => {\n deltaNode.addString(JSON.stringify(op), false);\n });\n }\n}\n\n/**\n * Converts trees/blobs/ops to binary compact representation.\n * @param snapshotContents - snapshot tree contents to serialize\n * @returns - ReadBuffer - binary representation of the data.\n */\nexport function convertToCompactSnapshot(snapshotContents: ISnapshotContents): ReadBuffer {\n const builder = new TreeBuilderSerializer();\n // Create the root node.\n const rootNode = builder.addNode();\n assert(snapshotContents.sequenceNumber !== undefined, 0x21c /* \"Seq number should be provided\" */);\n const ops = snapshotContents.ops;\n const latestSequenceNumber = ops.length > 0 ? ops[ops.length - 1].sequenceNumber : snapshotContents.sequenceNumber;\n writeSnapshotProps(rootNode, latestSequenceNumber);\n\n writeSnapshotSection(\n rootNode,\n snapshotContents.snapshotTree,\n snapshotContents.sequenceNumber,\n );\n\n // Add Blobs\n writeBlobsSection(rootNode, snapshotContents.blobs);\n\n // Then write the ops node.\n writeOpsSection(rootNode, ops);\n\n return builder.serialize();\n}\n"]}
|
package/lib/epochTracker.d.ts
CHANGED
|
@@ -22,11 +22,12 @@ export declare class EpochTracker implements IPersistedFileCache {
|
|
|
22
22
|
protected readonly cache: IPersistedCache;
|
|
23
23
|
protected readonly fileEntry: IFileEntry;
|
|
24
24
|
protected readonly logger: ITelemetryLogger;
|
|
25
|
+
protected readonly clientIsSummarizer?: boolean | undefined;
|
|
25
26
|
private _fluidEpoch;
|
|
26
27
|
readonly rateLimiter: RateLimiter;
|
|
27
28
|
private readonly driverId;
|
|
28
29
|
private networkCallNumber;
|
|
29
|
-
constructor(cache: IPersistedCache, fileEntry: IFileEntry, logger: ITelemetryLogger);
|
|
30
|
+
constructor(cache: IPersistedCache, fileEntry: IFileEntry, logger: ITelemetryLogger, clientIsSummarizer?: boolean | undefined);
|
|
30
31
|
setEpoch(epoch: string, fromCache: boolean, fetchType: FetchTypeInternal): void;
|
|
31
32
|
get(entry: IEntry): Promise<any>;
|
|
32
33
|
put(entry: IEntry, value: any): Promise<void>;
|
|
@@ -83,5 +84,5 @@ export interface ICacheAndTracker {
|
|
|
83
84
|
cache: IOdspCache;
|
|
84
85
|
epochTracker: EpochTracker;
|
|
85
86
|
}
|
|
86
|
-
export declare function createOdspCacheAndTracker(persistedCacheArg: IPersistedCache, nonpersistentCache: INonPersistentCache, fileEntry: IFileEntry, logger: ITelemetryLogger): ICacheAndTracker;
|
|
87
|
+
export declare function createOdspCacheAndTracker(persistedCacheArg: IPersistedCache, nonpersistentCache: INonPersistentCache, fileEntry: IFileEntry, logger: ITelemetryLogger, clientIsSummarizer?: boolean): ICacheAndTracker;
|
|
87
88
|
//# sourceMappingURL=epochTracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epochTracker.d.ts","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAmB,WAAW,EAAqB,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,UAAU,E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gD/B;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,UAAU,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;CAC9B;AAED,wBAAgB,yBAAyB,CACrC,iBAAiB,EAAE,eAAe,EAClC,kBAAkB,EAAE,mBAAmB,EACvC,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,gBAAgB,EACxB,kBAAkB,CAAC,EAAE,OAAO,GAAG,gBAAgB,CASlD"}
|
package/lib/epochTracker.js
CHANGED
|
@@ -22,10 +22,11 @@ export const defaultCacheExpiryTimeoutMs = 2 * 24 * 60 * 60 * 1000;
|
|
|
22
22
|
* then it also clears all the cached entries for the given container.
|
|
23
23
|
*/
|
|
24
24
|
export class EpochTracker {
|
|
25
|
-
constructor(cache, fileEntry, logger) {
|
|
25
|
+
constructor(cache, fileEntry, logger, clientIsSummarizer) {
|
|
26
26
|
this.cache = cache;
|
|
27
27
|
this.fileEntry = fileEntry;
|
|
28
28
|
this.logger = logger;
|
|
29
|
+
this.clientIsSummarizer = clientIsSummarizer;
|
|
29
30
|
this.driverId = uuid();
|
|
30
31
|
// This tracks the request number made by the driver instance.
|
|
31
32
|
this.networkCallNumber = 1;
|
|
@@ -228,7 +229,12 @@ export class EpochTracker {
|
|
|
228
229
|
fetchOptions.body = formParams.join("\r\n");
|
|
229
230
|
}
|
|
230
231
|
formatClientCorrelationId(fetchReason) {
|
|
231
|
-
const items = [
|
|
232
|
+
const items = [
|
|
233
|
+
`driverId=${this.driverId}`,
|
|
234
|
+
`RequestNumber=${this.networkCallNumber++}`,
|
|
235
|
+
`driverVersion=${driverVersion}`,
|
|
236
|
+
`isSummarizer=${this.clientIsSummarizer}`,
|
|
237
|
+
];
|
|
232
238
|
if (fetchReason !== undefined) {
|
|
233
239
|
items.push(`fetchReason=${fetchReason}`);
|
|
234
240
|
}
|
|
@@ -356,8 +362,8 @@ export class EpochTrackerWithRedemption extends EpochTracker {
|
|
|
356
362
|
return super.fetchAndParseAsJSON(url, fetchOptions, fetchType, addInBody);
|
|
357
363
|
}
|
|
358
364
|
}
|
|
359
|
-
export function createOdspCacheAndTracker(persistedCacheArg, nonpersistentCache, fileEntry, logger) {
|
|
360
|
-
const epochTracker = new EpochTrackerWithRedemption(persistedCacheArg, fileEntry, logger);
|
|
365
|
+
export function createOdspCacheAndTracker(persistedCacheArg, nonpersistentCache, fileEntry, logger, clientIsSummarizer) {
|
|
366
|
+
const epochTracker = new EpochTrackerWithRedemption(persistedCacheArg, fileEntry, logger, clientIsSummarizer);
|
|
361
367
|
return {
|
|
362
368
|
cache: Object.assign(Object.assign({}, nonpersistentCache), { persistedCache: epochTracker }),
|
|
363
369
|
epochTracker,
|
package/lib/epochTracker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epochTracker.js","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAE/F,OAAO,EACH,WAAW,GAMd,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjG,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAiB,MAAM,aAAa,CAAC;AAMpH,OAAO,EAA4B,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAO/D,MAAM,CAAC,MAAM,YAAY,G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K,CAAC,mBAAmB,CAAI,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACjF,CAAC;CACJ;AAOD,MAAM,UAAU,yBAAyB,CACrC,iBAAkC,EAClC,kBAAuC,EACvC,SAAqB,EACrB,MAAwB;IACxB,MAAM,YAAY,GAAG,IAAI,0BAA0B,CAAC,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1F,OAAO;QACH,KAAK,kCACE,kBAAkB,KACrB,cAAc,EAAE,YAAY,GAC/B;QACD,YAAY;KACf,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { assert, Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ThrottlingError, RateLimiter, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { IConnected } from \"@fluidframework/protocol-definitions\";\nimport {\n snapshotKey,\n ICacheEntry,\n IEntry,\n IFileEntry,\n IPersistedCache,\n IOdspError,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { PerformanceEvent, isFluidError, normalizeError } from \"@fluidframework/telemetry-utils\";\nimport { fetchAndParseAsJSONHelper, fetchArray, fetchHelper, getOdspResolvedUrl, IOdspResponse } from \"./odspUtils\";\nimport {\n IOdspCache,\n INonPersistentCache,\n IPersistedFileCache,\n } from \"./odspCache\";\nimport { IVersionedValueWithEpoch, persistedCacheValueVersion } from \"./contracts\";\nimport { ClpCompliantAppHeader } from \"./contractsPublic\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\nexport type FetchType = \"blob\" | \"createBlob\" | \"createFile\" | \"joinSession\" | \"ops\" | \"test\" | \"snapshotTree\" |\n \"treesLatest\" | \"uploadSummary\" | \"push\" | \"versions\";\n\nexport type FetchTypeInternal = FetchType | \"cache\";\n\nexport const Odsp409Error = \"Odsp409Error\";\n\n// Please update the README file in odsp-driver-definitions if you change the defaultCacheExpiryTimeoutMs.\nexport const defaultCacheExpiryTimeoutMs: number = 2 * 24 * 60 * 60 * 1000;\n\n/**\n * This class is a wrapper around fetch calls. It adds epoch to the request made so that the\n * server can match it with its epoch value in order to match the version.\n * It also validates the epoch value received in response of fetch calls. If the epoch does not match,\n * then it also clears all the cached entries for the given container.\n */\nexport class EpochTracker implements IPersistedFileCache {\n private _fluidEpoch: string | undefined;\n\n public readonly rateLimiter: RateLimiter;\n private readonly driverId = uuid();\n // This tracks the request number made by the driver instance.\n private networkCallNumber = 1;\n constructor(\n protected readonly cache: IPersistedCache,\n protected readonly fileEntry: IFileEntry,\n protected readonly logger: ITelemetryLogger,\n ) {\n // Limits the max number of concurrent requests to 24.\n this.rateLimiter = new RateLimiter(24);\n }\n\n // public for UT purposes only!\n public setEpoch(epoch: string, fromCache: boolean, fetchType: FetchTypeInternal) {\n assert(this._fluidEpoch === undefined, 0x1db /* \"epoch exists\" */);\n this._fluidEpoch = epoch;\n\n this.logger.sendTelemetryEvent(\n {\n eventName: \"EpochLearnedFirstTime\",\n epoch,\n fetchType,\n fromCache,\n },\n );\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n try {\n // Return undefined so that the ops/snapshots are grabbed from the server instead of the cache\n const value: IVersionedValueWithEpoch = await this.cache.get(this.fileEntryFromEntry(entry));\n // Version mismatch between what the runtime expects and what it recieved.\n // The cached value should not be used\n if (value === undefined || value.version !== persistedCacheValueVersion) {\n return undefined;\n }\n assert(value.fluidEpoch !== undefined, 0x1dc /* \"all entries have to have epoch\" */);\n if (this._fluidEpoch === undefined) {\n this.setEpoch(value.fluidEpoch, true, \"cache\");\n // Epoch mismatch, the cached value is considerably different from what the current state of\n // the runtime and should not be used\n } else if (this._fluidEpoch !== value.fluidEpoch) {\n return undefined;\n }\n // Expire the cached snapshot if it's older than the defaultCacheExpiryTimeoutMs and immediately\n // expire all old caches that do not have cacheEntryTime\n if (entry.type === snapshotKey) {\n const cacheTime = value.value?.cacheEntryTime;\n const currentTime = Date.now();\n if (cacheTime === undefined || currentTime - cacheTime >= defaultCacheExpiryTimeoutMs) {\n this.logger.sendTelemetryEvent(\n {\n eventName: \"odspVersionsCacheExpired\",\n duration: currentTime - cacheTime,\n maxCacheAgeMs: defaultCacheExpiryTimeoutMs,\n });\n await this.removeEntries();\n return undefined;\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value.value;\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"cacheFetchError\", type: entry.type }, error);\n return undefined;\n }\n }\n\n public async put(entry: IEntry, value: any) {\n assert(this._fluidEpoch !== undefined, 0x1dd /* \"no epoch\" */);\n // For snapshots, the value should have the cacheEntryTime. This will be used to expire snapshots older\n // than the defaultCacheExpiryTimeoutMs.\n if (entry.type === snapshotKey) {\n value.cacheEntryTime = value.cacheEntryTime ?? Date.now();\n }\n const data: IVersionedValueWithEpoch = {\n value,\n version: persistedCacheValueVersion,\n fluidEpoch: this._fluidEpoch,\n };\n return this.cache.put(this.fileEntryFromEntry(entry), data)\n .catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"cachePutError\", type: entry.type }, error);\n throw error;\n });\n }\n\n public async removeEntries(): Promise<void> {\n try {\n return await this.cache.removeEntries(this.fileEntry);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"removeCacheEntries\" }, error);\n }\n }\n\n public get fluidEpoch() {\n return this._fluidEpoch;\n }\n\n public async validateEpochFromPush(details: IConnected) {\n const epoch = details.epoch;\n assert(epoch !== undefined, 0x09d /* \"Connection details should contain epoch\" */);\n try {\n this.validateEpochFromResponse(epoch, \"push\");\n } catch (error) {\n await this.checkForEpochError(error, epoch, \"push\");\n throw error;\n }\n }\n\n /**\n * Api to fetch the response for given request and parse it as json.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n * @param fetchReason - fetch reason to add to the request.\n */\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: RequestInit,\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ): Promise<IOdspResponse<T>> {\n return this.fetchCore<T>(url, fetchOptions, fetchAndParseAsJSONHelper, fetchType, addInBody, fetchReason);\n }\n\n /**\n * Api to fetch the response for given request and parse it as json.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n * @param fetchReason - fetch reason to add to the request.\n */\n public async fetch(\n url: string,\n fetchOptions: RequestInit,\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ) {\n return this.fetchCore<Response>(url, fetchOptions, fetchHelper, fetchType, addInBody, fetchReason);\n }\n\n private async fetchCore<T>(\n url: string,\n fetchOptions: { [index: string]: any; },\n fetcher: (url: string, fetchOptions: { [index: string]: any; }) => Promise<IOdspResponse<T>>,\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ) {\n const clientCorrelationId = this.formatClientCorrelationId(fetchReason);\n // Add epoch in fetch request.\n this.addEpochInRequest(fetchOptions, addInBody, clientCorrelationId);\n let epochFromResponse: string | undefined;\n return this.rateLimiter.schedule(\n async () => fetcher(url, fetchOptions),\n ).then((response) => {\n epochFromResponse = response.headers.get(\"x-fluid-epoch\");\n this.validateEpochFromResponse(epochFromResponse, fetchType);\n response.propsToLog.XRequestStatsHeader = clientCorrelationId;\n return response;\n }).catch(async (error) => {\n // Get the server epoch from error in case we don't have it as if undefined we won't be able\n // to mark it as epoch error.\n if (epochFromResponse === undefined) {\n epochFromResponse = (error as IOdspError).serverEpoch;\n }\n await this.checkForEpochError(error, epochFromResponse, fetchType);\n throw error;\n }).catch((error) => {\n const fluidError = normalizeError(error, { props: { XRequestStatsHeader: clientCorrelationId } });\n throw fluidError;\n });\n }\n\n /**\n * Api to fetch the response as it is for given request.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n * @param fetchReason - fetch reason to add to the request.\n */\n public async fetchArray(\n url: string,\n fetchOptions: { [index: string]: any; },\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ) {\n return this.fetchCore<ArrayBuffer>(url, fetchOptions, fetchArray, fetchType, addInBody, fetchReason);\n }\n\n private addEpochInRequest(\n fetchOptions: RequestInit,\n addInBody: boolean,\n clientCorrelationId: string,\n ) {\n const isClpCompliantApp = getOdspResolvedUrl(this.fileEntry.resolvedUrl).isClpCompliantApp;\n if (addInBody) {\n const headers: { [key: string]: string; } = {};\n headers[\"X-RequestStats\"] = clientCorrelationId;\n if (this.fluidEpoch !== undefined) {\n headers[\"x-fluid-epoch\"] = this.fluidEpoch;\n }\n if (isClpCompliantApp) {\n headers[ClpCompliantAppHeader.isClpCompliantApp] = isClpCompliantApp.toString();\n }\n this.addParamInBody(fetchOptions, headers);\n } else {\n const addHeader = (key: string, val: string) => {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n };\n assert(fetchOptions.headers !== undefined, 0x282 /* \"Headers should be present now\" */);\n fetchOptions.headers[key] = val;\n };\n addHeader(\"X-RequestStats\", clientCorrelationId);\n if (this.fluidEpoch !== undefined) {\n addHeader(\"x-fluid-epoch\", this.fluidEpoch);\n }\n if (isClpCompliantApp) {\n addHeader(ClpCompliantAppHeader.isClpCompliantApp, isClpCompliantApp.toString());\n }\n }\n }\n\n private addParamInBody(fetchOptions: RequestInit, headers: { [key: string]: string; }) {\n // We use multi part form request for post body where we want to use this.\n // So extract the form boundary to mark the end of form.\n const body = fetchOptions.body;\n assert(typeof body === \"string\", 0x21d /* \"body is not string\" */);\n const splitBody = body.split(\"\\r\\n\");\n const firstLine = splitBody.shift();\n assert(firstLine?.startsWith(\"--\") === true, 0x21e /* \"improper boundary format\" */);\n const formParams = [firstLine];\n Object.entries(headers).forEach(([key, value]) => {\n formParams.push(`${key}: ${value}`);\n });\n splitBody.forEach((value: string) => {\n formParams.push(value);\n });\n fetchOptions.body = formParams.join(\"\\r\\n\");\n }\n\n private formatClientCorrelationId(fetchReason?: string) {\n const items: string[] = [`driverId=${this.driverId}`, `RequestNumber=${this.networkCallNumber++}`];\n if (fetchReason !== undefined) {\n items.push(`fetchReason=${fetchReason}`);\n }\n return items.join(\", \");\n }\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n const error = this.checkForEpochErrorCore(epochFromResponse);\n if (error !== undefined) {\n throw error;\n }\n if (epochFromResponse !== undefined) {\n if (this._fluidEpoch === undefined) {\n this.setEpoch(epochFromResponse, fromCache, fetchType);\n }\n }\n }\n\n private async checkForEpochError(\n error: unknown,\n epochFromResponse: string | null | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n if (isFluidError(error) && error.errorType === DriverErrorType.fileOverwrittenInStorage) {\n const epochError = this.checkForEpochErrorCore(epochFromResponse);\n if (epochError !== undefined) {\n epochError.addTelemetryProperties({\n fromCache,\n clientEpoch: this.fluidEpoch,\n fetchType,\n });\n this.logger.sendErrorEvent({ eventName: \"fileOverwrittenInStorage\" }, epochError);\n // If the epoch mismatches, then clear all entries for such file entry from cache.\n await this.removeEntries();\n throw epochError;\n }\n // If it was categorized as epoch error but the epoch returned in response matches with the client epoch\n // then it was coherency 409, so rethrow it as throttling error so that it can retried. Default throttling\n // time is 1s.\n throw new ThrottlingError(\n `Coherency 409: ${error.message}`,\n 1 /* retryAfterSeconds */,\n { [Odsp409Error]: true, driverVersion });\n }\n }\n\n private checkForEpochErrorCore(epochFromResponse: string | null | undefined) {\n // If epoch is undefined, then don't compare it because initially for createNew or TreesLatest\n // initializes this value. Sometimes response does not contain epoch as it is still in\n // implementation phase at server side. In that case also, don't compare it with our epoch value.\n if (this.fluidEpoch && epochFromResponse && (this.fluidEpoch !== epochFromResponse)) {\n // This is similar in nature to how fluidEpochMismatchError (409) is handled.\n // Difference - client detected mismatch, instead of server detecting it.\n return new NonRetryableError(\n \"Epoch mismatch\", DriverErrorType.fileOverwrittenInStorage, { driverVersion });\n }\n }\n\n private fileEntryFromEntry(entry: IEntry): ICacheEntry {\n return { ...entry, file: this.fileEntry };\n }\n}\n\nexport class EpochTrackerWithRedemption extends EpochTracker {\n private readonly treesLatestDeferral = new Deferred<void>();\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchType,\n fromCache: boolean = false,\n ) {\n super.validateEpochFromResponse(epochFromResponse, fetchType, fromCache);\n\n // Any successful call means we have access to a file, i.e. any redemption that was required already happened.\n // That covers cases of \"treesLatest\" as well as \"getVersions\" or \"createFile\" - all the ways we can start\n // exploring a file.\n this.treesLatestDeferral.resolve();\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n let result = super.get(entry);\n\n // equivalence of what happens in fetchAndParseAsJSON()\n if (entry.type === snapshotKey) {\n result = result\n .then((value) => {\n // If there is nothing in cache, we need to wait for network call to complete (and do redemption)\n // Otherwise file was redeemed in prior session, so if joinSession failed, we should not retry\n if (value !== undefined) {\n this.treesLatestDeferral.resolve();\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n })\n .catch((error) => {\n this.treesLatestDeferral.reject(error);\n throw error;\n });\n }\n return result;\n }\n\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: { [index: string]: any; },\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ): Promise<IOdspResponse<T>> {\n // Optimize the flow if we know that treesLatestDeferral was already completed by the timer we started\n // joinSession call. If we did - there is no reason to repeat the call as it will fail with same error.\n const completed = this.treesLatestDeferral.isCompleted;\n\n try {\n return await super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody, fetchReason);\n } catch (error: any) {\n // Only handling here treesLatest. If createFile failed, we should never try to do joinSession.\n // Similar, if getVersions failed, we should not do any further storage calls.\n // So treesLatest is the only call that can have parallel joinSession request.\n if (fetchType === \"treesLatest\") {\n this.treesLatestDeferral.reject(error);\n }\n if (fetchType !== \"joinSession\" || error.statusCode < 401 || error.statusCode > 404 || completed) {\n throw error;\n }\n }\n\n // It is joinSession failing with 401..404 error\n // Repeat after waiting for treeLatest succeeding (or fail if it failed).\n // No special handling after first call - if file has been deleted, then it's game over.\n\n // Ensure we have some safety here - we do not want to deadlock if we got logic somewhere wrong.\n // If we waited too long, we will log error event and proceed with call.\n // It may result in failure for user, but refreshing document would address it.\n // Thus we use rather long timeout (not to get these failures as much as possible), but not large enough\n // to unblock the process.\n await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"JoinSessionSyncWait\" },\n async (event) => {\n const timeoutRes = 51; // anything will work here\n let timer: ReturnType<typeof setTimeout>;\n const timeoutP = new Promise<number>((resolve) => {\n timer = setTimeout(() => { resolve(timeoutRes); }, 15000);\n });\n const res = await Promise.race([\n timeoutP,\n // cancel timeout to unblock UTs (otherwise Node process does not exit for 15 sec)\n this.treesLatestDeferral.promise.finally(() => clearTimeout(timer))]);\n if (res === timeoutRes) {\n event.cancel();\n }\n },\n { start: true, end: true, cancel: \"generic\" });\n return super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody);\n }\n}\n\nexport interface ICacheAndTracker {\n cache: IOdspCache;\n epochTracker: EpochTracker;\n}\n\nexport function createOdspCacheAndTracker(\n persistedCacheArg: IPersistedCache,\n nonpersistentCache: INonPersistentCache,\n fileEntry: IFileEntry,\n logger: ITelemetryLogger): ICacheAndTracker {\n const epochTracker = new EpochTrackerWithRedemption(persistedCacheArg, fileEntry, logger);\n return {\n cache: {\n ...nonpersistentCache,\n persistedCache: epochTracker,\n },\n epochTracker,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"epochTracker.js","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":"AAAA;;;GA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contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { assert, Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ThrottlingError, RateLimiter, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { IConnected } from \"@fluidframework/protocol-definitions\";\nimport {\n snapshotKey,\n ICacheEntry,\n IEntry,\n IFileEntry,\n IPersistedCache,\n IOdspError,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { PerformanceEvent, isFluidError, normalizeError } from \"@fluidframework/telemetry-utils\";\nimport { fetchAndParseAsJSONHelper, fetchArray, fetchHelper, getOdspResolvedUrl, IOdspResponse } from \"./odspUtils\";\nimport {\n IOdspCache,\n INonPersistentCache,\n IPersistedFileCache,\n } from \"./odspCache\";\nimport { IVersionedValueWithEpoch, persistedCacheValueVersion } from \"./contracts\";\nimport { ClpCompliantAppHeader } from \"./contractsPublic\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\nexport type FetchType = \"blob\" | \"createBlob\" | \"createFile\" | \"joinSession\" | \"ops\" | \"test\" | \"snapshotTree\" |\n \"treesLatest\" | \"uploadSummary\" | \"push\" | \"versions\";\n\nexport type FetchTypeInternal = FetchType | \"cache\";\n\nexport const Odsp409Error = \"Odsp409Error\";\n\n// Please update the README file in odsp-driver-definitions if you change the defaultCacheExpiryTimeoutMs.\nexport const defaultCacheExpiryTimeoutMs: number = 2 * 24 * 60 * 60 * 1000;\n\n/**\n * This class is a wrapper around fetch calls. It adds epoch to the request made so that the\n * server can match it with its epoch value in order to match the version.\n * It also validates the epoch value received in response of fetch calls. If the epoch does not match,\n * then it also clears all the cached entries for the given container.\n */\nexport class EpochTracker implements IPersistedFileCache {\n private _fluidEpoch: string | undefined;\n\n public readonly rateLimiter: RateLimiter;\n private readonly driverId = uuid();\n // This tracks the request number made by the driver instance.\n private networkCallNumber = 1;\n constructor(\n protected readonly cache: IPersistedCache,\n protected readonly fileEntry: IFileEntry,\n protected readonly logger: ITelemetryLogger,\n protected readonly clientIsSummarizer?: boolean,\n ) {\n // Limits the max number of concurrent requests to 24.\n this.rateLimiter = new RateLimiter(24);\n }\n\n // public for UT purposes only!\n public setEpoch(epoch: string, fromCache: boolean, fetchType: FetchTypeInternal) {\n assert(this._fluidEpoch === undefined, 0x1db /* \"epoch exists\" */);\n this._fluidEpoch = epoch;\n\n this.logger.sendTelemetryEvent(\n {\n eventName: \"EpochLearnedFirstTime\",\n epoch,\n fetchType,\n fromCache,\n },\n );\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n try {\n // Return undefined so that the ops/snapshots are grabbed from the server instead of the cache\n const value: IVersionedValueWithEpoch = await this.cache.get(this.fileEntryFromEntry(entry));\n // Version mismatch between what the runtime expects and what it recieved.\n // The cached value should not be used\n if (value === undefined || value.version !== persistedCacheValueVersion) {\n return undefined;\n }\n assert(value.fluidEpoch !== undefined, 0x1dc /* \"all entries have to have epoch\" */);\n if (this._fluidEpoch === undefined) {\n this.setEpoch(value.fluidEpoch, true, \"cache\");\n // Epoch mismatch, the cached value is considerably different from what the current state of\n // the runtime and should not be used\n } else if (this._fluidEpoch !== value.fluidEpoch) {\n return undefined;\n }\n // Expire the cached snapshot if it's older than the defaultCacheExpiryTimeoutMs and immediately\n // expire all old caches that do not have cacheEntryTime\n if (entry.type === snapshotKey) {\n const cacheTime = value.value?.cacheEntryTime;\n const currentTime = Date.now();\n if (cacheTime === undefined || currentTime - cacheTime >= defaultCacheExpiryTimeoutMs) {\n this.logger.sendTelemetryEvent(\n {\n eventName: \"odspVersionsCacheExpired\",\n duration: currentTime - cacheTime,\n maxCacheAgeMs: defaultCacheExpiryTimeoutMs,\n });\n await this.removeEntries();\n return undefined;\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value.value;\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"cacheFetchError\", type: entry.type }, error);\n return undefined;\n }\n }\n\n public async put(entry: IEntry, value: any) {\n assert(this._fluidEpoch !== undefined, 0x1dd /* \"no epoch\" */);\n // For snapshots, the value should have the cacheEntryTime. This will be used to expire snapshots older\n // than the defaultCacheExpiryTimeoutMs.\n if (entry.type === snapshotKey) {\n value.cacheEntryTime = value.cacheEntryTime ?? Date.now();\n }\n const data: IVersionedValueWithEpoch = {\n value,\n version: persistedCacheValueVersion,\n fluidEpoch: this._fluidEpoch,\n };\n return this.cache.put(this.fileEntryFromEntry(entry), data)\n .catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"cachePutError\", type: entry.type }, error);\n throw error;\n });\n }\n\n public async removeEntries(): Promise<void> {\n try {\n return await this.cache.removeEntries(this.fileEntry);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"removeCacheEntries\" }, error);\n }\n }\n\n public get fluidEpoch() {\n return this._fluidEpoch;\n }\n\n public async validateEpochFromPush(details: IConnected) {\n const epoch = details.epoch;\n assert(epoch !== undefined, 0x09d /* \"Connection details should contain epoch\" */);\n try {\n this.validateEpochFromResponse(epoch, \"push\");\n } catch (error) {\n await this.checkForEpochError(error, epoch, \"push\");\n throw error;\n }\n }\n\n /**\n * Api to fetch the response for given request and parse it as json.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n * @param fetchReason - fetch reason to add to the request.\n */\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: RequestInit,\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ): Promise<IOdspResponse<T>> {\n return this.fetchCore<T>(url, fetchOptions, fetchAndParseAsJSONHelper, fetchType, addInBody, fetchReason);\n }\n\n /**\n * Api to fetch the response for given request and parse it as json.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n * @param fetchReason - fetch reason to add to the request.\n */\n public async fetch(\n url: string,\n fetchOptions: RequestInit,\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ) {\n return this.fetchCore<Response>(url, fetchOptions, fetchHelper, fetchType, addInBody, fetchReason);\n }\n\n private async fetchCore<T>(\n url: string,\n fetchOptions: { [index: string]: any; },\n fetcher: (url: string, fetchOptions: { [index: string]: any; }) => Promise<IOdspResponse<T>>,\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ) {\n const clientCorrelationId = this.formatClientCorrelationId(fetchReason);\n // Add epoch in fetch request.\n this.addEpochInRequest(fetchOptions, addInBody, clientCorrelationId);\n let epochFromResponse: string | undefined;\n return this.rateLimiter.schedule(\n async () => fetcher(url, fetchOptions),\n ).then((response) => {\n epochFromResponse = response.headers.get(\"x-fluid-epoch\");\n this.validateEpochFromResponse(epochFromResponse, fetchType);\n response.propsToLog.XRequestStatsHeader = clientCorrelationId;\n return response;\n }).catch(async (error) => {\n // Get the server epoch from error in case we don't have it as if undefined we won't be able\n // to mark it as epoch error.\n if (epochFromResponse === undefined) {\n epochFromResponse = (error as IOdspError).serverEpoch;\n }\n await this.checkForEpochError(error, epochFromResponse, fetchType);\n throw error;\n }).catch((error) => {\n const fluidError = normalizeError(error, { props: { XRequestStatsHeader: clientCorrelationId } });\n throw fluidError;\n });\n }\n\n /**\n * Api to fetch the response as it is for given request.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n * @param fetchReason - fetch reason to add to the request.\n */\n public async fetchArray(\n url: string,\n fetchOptions: { [index: string]: any; },\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ) {\n return this.fetchCore<ArrayBuffer>(url, fetchOptions, fetchArray, fetchType, addInBody, fetchReason);\n }\n\n private addEpochInRequest(\n fetchOptions: RequestInit,\n addInBody: boolean,\n clientCorrelationId: string,\n ) {\n const isClpCompliantApp = getOdspResolvedUrl(this.fileEntry.resolvedUrl).isClpCompliantApp;\n if (addInBody) {\n const headers: { [key: string]: string; } = {};\n headers[\"X-RequestStats\"] = clientCorrelationId;\n if (this.fluidEpoch !== undefined) {\n headers[\"x-fluid-epoch\"] = this.fluidEpoch;\n }\n if (isClpCompliantApp) {\n headers[ClpCompliantAppHeader.isClpCompliantApp] = isClpCompliantApp.toString();\n }\n this.addParamInBody(fetchOptions, headers);\n } else {\n const addHeader = (key: string, val: string) => {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n };\n assert(fetchOptions.headers !== undefined, 0x282 /* \"Headers should be present now\" */);\n fetchOptions.headers[key] = val;\n };\n addHeader(\"X-RequestStats\", clientCorrelationId);\n if (this.fluidEpoch !== undefined) {\n addHeader(\"x-fluid-epoch\", this.fluidEpoch);\n }\n if (isClpCompliantApp) {\n addHeader(ClpCompliantAppHeader.isClpCompliantApp, isClpCompliantApp.toString());\n }\n }\n }\n\n private addParamInBody(fetchOptions: RequestInit, headers: { [key: string]: string; }) {\n // We use multi part form request for post body where we want to use this.\n // So extract the form boundary to mark the end of form.\n const body = fetchOptions.body;\n assert(typeof body === \"string\", 0x21d /* \"body is not string\" */);\n const splitBody = body.split(\"\\r\\n\");\n const firstLine = splitBody.shift();\n assert(firstLine?.startsWith(\"--\") === true, 0x21e /* \"improper boundary format\" */);\n const formParams = [firstLine];\n Object.entries(headers).forEach(([key, value]) => {\n formParams.push(`${key}: ${value}`);\n });\n splitBody.forEach((value: string) => {\n formParams.push(value);\n });\n fetchOptions.body = formParams.join(\"\\r\\n\");\n }\n\n private formatClientCorrelationId(fetchReason?: string) {\n const items: string[] = [\n `driverId=${this.driverId}`,\n `RequestNumber=${this.networkCallNumber++}`,\n `driverVersion=${driverVersion}`,\n `isSummarizer=${this.clientIsSummarizer}`,\n ];\n if (fetchReason !== undefined) {\n items.push(`fetchReason=${fetchReason}`);\n }\n return items.join(\", \");\n }\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n const error = this.checkForEpochErrorCore(epochFromResponse);\n if (error !== undefined) {\n throw error;\n }\n if (epochFromResponse !== undefined) {\n if (this._fluidEpoch === undefined) {\n this.setEpoch(epochFromResponse, fromCache, fetchType);\n }\n }\n }\n\n private async checkForEpochError(\n error: unknown,\n epochFromResponse: string | null | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n if (isFluidError(error) && error.errorType === DriverErrorType.fileOverwrittenInStorage) {\n const epochError = this.checkForEpochErrorCore(epochFromResponse);\n if (epochError !== undefined) {\n epochError.addTelemetryProperties({\n fromCache,\n clientEpoch: this.fluidEpoch,\n fetchType,\n });\n this.logger.sendErrorEvent({ eventName: \"fileOverwrittenInStorage\" }, epochError);\n // If the epoch mismatches, then clear all entries for such file entry from cache.\n await this.removeEntries();\n throw epochError;\n }\n // If it was categorized as epoch error but the epoch returned in response matches with the client epoch\n // then it was coherency 409, so rethrow it as throttling error so that it can retried. Default throttling\n // time is 1s.\n throw new ThrottlingError(\n `Coherency 409: ${error.message}`,\n 1 /* retryAfterSeconds */,\n { [Odsp409Error]: true, driverVersion });\n }\n }\n\n private checkForEpochErrorCore(epochFromResponse: string | null | undefined) {\n // If epoch is undefined, then don't compare it because initially for createNew or TreesLatest\n // initializes this value. Sometimes response does not contain epoch as it is still in\n // implementation phase at server side. In that case also, don't compare it with our epoch value.\n if (this.fluidEpoch && epochFromResponse && (this.fluidEpoch !== epochFromResponse)) {\n // This is similar in nature to how fluidEpochMismatchError (409) is handled.\n // Difference - client detected mismatch, instead of server detecting it.\n return new NonRetryableError(\n \"Epoch mismatch\", DriverErrorType.fileOverwrittenInStorage, { driverVersion });\n }\n }\n\n private fileEntryFromEntry(entry: IEntry): ICacheEntry {\n return { ...entry, file: this.fileEntry };\n }\n}\n\nexport class EpochTrackerWithRedemption extends EpochTracker {\n private readonly treesLatestDeferral = new Deferred<void>();\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchType,\n fromCache: boolean = false,\n ) {\n super.validateEpochFromResponse(epochFromResponse, fetchType, fromCache);\n\n // Any successful call means we have access to a file, i.e. any redemption that was required already happened.\n // That covers cases of \"treesLatest\" as well as \"getVersions\" or \"createFile\" - all the ways we can start\n // exploring a file.\n this.treesLatestDeferral.resolve();\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n let result = super.get(entry);\n\n // equivalence of what happens in fetchAndParseAsJSON()\n if (entry.type === snapshotKey) {\n result = result\n .then((value) => {\n // If there is nothing in cache, we need to wait for network call to complete (and do redemption)\n // Otherwise file was redeemed in prior session, so if joinSession failed, we should not retry\n if (value !== undefined) {\n this.treesLatestDeferral.resolve();\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n })\n .catch((error) => {\n this.treesLatestDeferral.reject(error);\n throw error;\n });\n }\n return result;\n }\n\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: { [index: string]: any; },\n fetchType: FetchType,\n addInBody: boolean = false,\n fetchReason?: string,\n ): Promise<IOdspResponse<T>> {\n // Optimize the flow if we know that treesLatestDeferral was already completed by the timer we started\n // joinSession call. If we did - there is no reason to repeat the call as it will fail with same error.\n const completed = this.treesLatestDeferral.isCompleted;\n\n try {\n return await super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody, fetchReason);\n } catch (error: any) {\n // Only handling here treesLatest. If createFile failed, we should never try to do joinSession.\n // Similar, if getVersions failed, we should not do any further storage calls.\n // So treesLatest is the only call that can have parallel joinSession request.\n if (fetchType === \"treesLatest\") {\n this.treesLatestDeferral.reject(error);\n }\n if (fetchType !== \"joinSession\" || error.statusCode < 401 || error.statusCode > 404 || completed) {\n throw error;\n }\n }\n\n // It is joinSession failing with 401..404 error\n // Repeat after waiting for treeLatest succeeding (or fail if it failed).\n // No special handling after first call - if file has been deleted, then it's game over.\n\n // Ensure we have some safety here - we do not want to deadlock if we got logic somewhere wrong.\n // If we waited too long, we will log error event and proceed with call.\n // It may result in failure for user, but refreshing document would address it.\n // Thus we use rather long timeout (not to get these failures as much as possible), but not large enough\n // to unblock the process.\n await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"JoinSessionSyncWait\" },\n async (event) => {\n const timeoutRes = 51; // anything will work here\n let timer: ReturnType<typeof setTimeout>;\n const timeoutP = new Promise<number>((resolve) => {\n timer = setTimeout(() => { resolve(timeoutRes); }, 15000);\n });\n const res = await Promise.race([\n timeoutP,\n // cancel timeout to unblock UTs (otherwise Node process does not exit for 15 sec)\n this.treesLatestDeferral.promise.finally(() => clearTimeout(timer))]);\n if (res === timeoutRes) {\n event.cancel();\n }\n },\n { start: true, end: true, cancel: \"generic\" });\n return super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody);\n }\n}\n\nexport interface ICacheAndTracker {\n cache: IOdspCache;\n epochTracker: EpochTracker;\n}\n\nexport function createOdspCacheAndTracker(\n persistedCacheArg: IPersistedCache,\n nonpersistentCache: INonPersistentCache,\n fileEntry: IFileEntry,\n logger: ITelemetryLogger,\n clientIsSummarizer?: boolean): ICacheAndTracker {\n const epochTracker = new EpochTrackerWithRedemption(persistedCacheArg, fileEntry, logger, clientIsSummarizer);\n return {\n cache: {\n ...nonpersistentCache,\n persistedCache: epochTracker,\n },\n epochTracker,\n };\n}\n"]}
|
package/lib/fetchSnapshot.js
CHANGED
|
@@ -13,7 +13,7 @@ import { persistedCacheValueVersion } from "./contracts";
|
|
|
13
13
|
import { getQueryString } from "./getQueryString";
|
|
14
14
|
import { getUrlAndHeadersWithAuth } from "./getUrlAndHeadersWithAuth";
|
|
15
15
|
import { fetchAndParseAsJSONHelper, fetchHelper, getWithRetryForTokenRefresh, getWithRetryForTokenRefreshRepeat, } from "./odspUtils";
|
|
16
|
-
import {
|
|
16
|
+
import { convertOdspSnapshotToSnapshotTreeAndBlobs } from "./odspSnapshotParser";
|
|
17
17
|
import { currentReadVersion, parseCompactSnapshotResponse } from "./compactSnapshotParser";
|
|
18
18
|
import { ReadBuffer } from "./ReadBufferUtils";
|
|
19
19
|
/**
|
|
@@ -52,7 +52,7 @@ export async function fetchSnapshot(snapshotUrl, token, versionId, fetchFullSnap
|
|
|
52
52
|
eventName: "fetchSnapshot",
|
|
53
53
|
headers: Object.keys(headers).length !== 0 ? true : undefined,
|
|
54
54
|
}, async () => snapshotDownloader(url, { headers }));
|
|
55
|
-
return
|
|
55
|
+
return convertOdspSnapshotToSnapshotTreeAndBlobs(response.content);
|
|
56
56
|
}
|
|
57
57
|
export async function fetchSnapshotWithRedeem(odspResolvedUrl, storageTokenFetcher, snapshotOptions, forceAccessTokenViaAuthorizationHeader, logger, snapshotDownloader, putInCache, removeEntries, enableRedeemFallback) {
|
|
58
58
|
// back-compat: This block to be removed with #8784 when we only consume/consider odsp resolvers that are >= 0.51
|
|
@@ -340,7 +340,7 @@ export async function downloadSnapshot(odspResolvedUrl, storageToken, logger, sn
|
|
|
340
340
|
const text = await response.content.text();
|
|
341
341
|
const content = JSON.parse(text);
|
|
342
342
|
response.propsToLog.bodySize = text.length;
|
|
343
|
-
const snapshotContents =
|
|
343
|
+
const snapshotContents = convertOdspSnapshotToSnapshotTreeAndBlobs(content);
|
|
344
344
|
finalSnapshotContents = Object.assign(Object.assign({}, response), { content: snapshotContents });
|
|
345
345
|
}
|
|
346
346
|
else {
|