[
https://issues.apache.org/jira/browse/OAK-12565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18155186#comment-18155186
]
Julian Sedding commented on OAK-12565:
--------------------------------------
h3. Implementation
* Stage new deduplication cache entries in the segment buffer that owns them.
Publish them to the shared cache only after the segment write succeeds.
* Allow reuse within the same in-flight buffer when the writer can verify the
buffer and generation. Prefer an already published entry over a pending copy.
* Add regression tests for cross-buffer reuse, same-buffer reuse, buffer
rollover, and failed writes. The change is enabled by default;
{{oak.segmentNodeStore.preventDeduplicationForwardReferences=false}} restores
the previous behavior.
h3. Benchmark results
I compared the patch against trunk using 19 stock {{oak-benchmarks}} workloads
on {{Oak-Segment-Tar}} (5 s warmup, 60 s measurement). Across all 19, the
equal-weight average changes were {*}+6.6% p50 latency{*}, {*}+4.7% p90
latency{*}, and {*}−4.4% completed iterations{*}. Excluding
{{{}ConcurrentTraversalTest{}}}, the changes were {*}+4.6%{*}, {*}+1.6%{*}, and
{*}−2.6%{*}, respectively.
||Benchmark class||p50 latency, trunk → patch||p90 latency, trunk → patch||
|{{BasicWriteTest}}|100 → 101 ms|104 → 115 ms|
|{{StringWriteTest}}|1 → 1 ms|1 → 1 ms|
|{{SmallFileWriteTest}}|17 → 17 ms|18 → 18 ms|
|{{ConcurrentTraversalTest}}|7 → 11 ms|10 → 16 ms|
A small performance cost is expected. When a matching record is still buffered
by another writer, the writer may write a duplicate rather than reuse it. That
means more records are written, and duplicates with distinct record IDs can
occupy separate read-cache entries. I’d expect this to be less noticeable in a
steady-state repository where writers can often reuse records that have already
been appended, unlike a benchmark that builds its fixture in one write-heavy
setup phase. I haven’t measured that on a production workload.
*Why traversal was an outlier.* At the stock *100 MiB* segment-cache budget,
the patch’s setup layout brought the warm cache to about {*}52 MiB{*}, versus
*49.5 MiB* with the old write behavior. Only the patched layout crossed
Caffeine’s 50% threshold for tracking hits for eviction, adding work to the
read path even though there were no segment-cache misses or evictions during
measurement. At {{{}--cache 128{}}}, both layouts fit below that threshold. In
two stock trunk-versus-patch reruns at that budget, p50 latency was unchanged
and the patch completed {*}2.9% fewer iterations{*}, comparable to the *2.6%*
average reduction across the other workloads.
*128 MiB cache, averaged across two runs per build*
||Benchmark class||p50 latency, trunk → patch||p90 latency, trunk →
patch||Completed iterations, trunk → patch||
|{{ConcurrentTraversalTest}}|7 → 7 ms|10.5 → 11 ms|7,091 → 6,888 (−2.9%)|
> Record deduplication caches may introduce forward references
> ------------------------------------------------------------
>
> Key: OAK-12565
> URL: https://issues.apache.org/jira/browse/OAK-12565
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: segment-tar
> Affects Versions: 2.8.0
> Reporter: Julian Sedding
> Assignee: Julian Sedding
> Priority: Major
>
> A segment writer can reuse a cached {{Record}} from another writer’s buffer
> before that segment is persisted. If the referring segment is appended first,
> it points forward in TAR order. It is even possible that two segments
> reference each other. This can be unsafe: cleanup of "dangling future
> segments" assumes that compacted segments written after the last compacted
> root are unreachable and may reclaim them (see OAK-12400).
> Publish shared deduplication cache entries only after the owning segment is
> successfully written. Preserve safe reuse within the same buffer, and never
> publish entries from a failed write.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)