Differential summary potential bug: Reuse child of differential summary
Found a potential bug with differential summaries which might cause ops to be lost.
Scenario
Suppose tree contains some path: /A/B/...
- At ref seq 10, suppose
/Aand/A/Bsummarize successfully - An op with seq 15 is sent to
/A/B - At ref seq 20, suppose
/Agenerates a differential summary - At ref seq 30, a summary is being generated, and suppose
/A/Blatest op is still seq 15
The state of /A latest summary is:
{
referenceSequenceNumber: 20,
basePath: "/",
localPath: "A",
additionalPath: "_baseSummary",
}
The state of /A/B latest summary is:
{
referenceSequenceNumber: 20,
basePath: "/A/_baseSummary",
localPath: "B",
additionalPath: undefined,
}
So now when generating a summary at seq 30, /A/B will see 15<20 and think that it can reuse previous summary handle, which will yield path: /A/_baseSummary/B (which is the correct path).
The problem is that the /A/_outstandingOps blob will be lost in the latest summary, so op 15 will be missing. The summary at seq 30 will be something like this:
/ -> [tree] {
A -> [tree]: {
B -> [handle]: "<summaryAtSeq20>/A/_baseSummary/B",
X -> [tree]: { ... },
},
...
}
So when a client loads from that summary it will load /A/B at the state of seq 10, but start processing ops from seq 20, thus missing seq 15.
Detailed Explanation
This is the result of the code in SummarizerNode.completeSummaryCore which detects if the parent node sent a differential summary or handle via wipSkipRecursion. In the case of handle, this all works fine, since there should not be an op with seq 15 addressed to /A/B, or else it would not send a handle at all.
In the case of differential summary, the problem above is possible. It does a second check: if the node /A/B in this example has never seen a previous acked summary (i.e. latestSummary is undefined), then it will be fine because it will skip recursion. This node and child nodes will essentially have ref seq 0, and always think it has changed since last summary.
In the case that there is a previous acked summary, it will correctly update the paths to the children, but will continue to send ref seq 20 down to children. If we change it to always skip recursion, the problem should not resolve, because the paths are incorrect. For example if op seq 15 did not exist, then it would try to send a handle but with path /A/B which does not exist in the summary at seq 20, it should be /A/_baseSummary/B. There would be a similar issue with subsequent differential summaries from /A/B's perspective.
Proposed Fix
If we propagate the correct paths down, but keep the reference sequence number unchanged, that should fix it. In the case where op seq 15 does not exist, then the handle sent would have the correct path and there would be no ops between 10 and 20. In the case where op seq 15 does exist, 15>20 would prevent a handle from being sent. A differential summary would reference the correct path as a baseline, but would include ops between 10 and 20.
We would need to refine the assertion in SummarizerNode.refreshLatestSummaryFromPending that the passed in ref seq may be different from the one in the pending node, and the one from the pending node should be used for clearing outstanding ops. It might be useful to store both the real reference sequence number of the summary and the effective one for clearing outstanding ops, because the real one would be used for clearing the pendingSummaries.
Currently differential summaries are completely disabled, so this should only arise when turned back on. We need automated testing around SummarizerNode and differential summaries before we can turn them on again.
#4296