Nuno Santos created OAK-12420:
---------------------------------

             Summary: Avoid retaining a UUID object per segment archive entry; 
stop eagerly caching TarReader#getUUIDs()
                 Key: OAK-12420
                 URL: https://issues.apache.org/jira/browse/OAK-12420
             Project: Jackrabbit Oak
          Issue Type: Improvement
            Reporter: Nuno Santos


Follow-up to [OAK-12417|https://issues.apache.org/jira/browse/OAK-12417] (PR: 
[apache/jackrabbit-oak#3151|https://github.com/apache/jackrabbit-oak/pull/3151]),
 which reworked {{AbstractRemoteSegmentArchiveReader}}'s in-memory segment 
index to avoid per-lookup {{UUID}} allocation on the hot read path. That change 
did not touch {{RemoteSegmentArchiveEntry}}, which still stores a {{UUID}} 
field per entry (built once and reused, so not itself the hot-path problem) 
purely so {{RemoteSegmentArchiveEntry#getUuid()}} can hand it to 
{{AbstractRemoteSegmentArchiveReader#getSegmentUUIDs()}}.

{{TarReader}} (in {{oak-segment-tar}}, shared by both local TAR-file and remote 
segment archive backends) calls {{SegmentArchiveReader#getSegmentUUIDs()}} 
once, eagerly, in its constructor, and retains the resulting {{Set<UUID>}} in a 
field ({{TarReader#segmentUUIDs}}) for as long as that archive stays part of 
the live index. That means one {{UUID}} object stays resident in memory per 
segment, for every currently open archive, indefinitely — a real, if 
individually small, per-segment cost that adds up across large repositories.

The only caller of {{TarReader#getUUIDs()}} is 
{{TarFiles#getSegmentIds()/getGraph()/getIndices()}}, which are only exposed 
through {{ReadOnlyFileStore}} — used exclusively by offline/maintenance tooling 
({{Check}}, {{Backup}}, {{Diff}}, {{DebugStore}}, {{DebugSegments}}, 
{{DebugTars}}, {{SearchNodes}}, {{RecoverJournal}}, {{ConsistencyChecker}}, 
{{RevisionHistory}}, {{FileStoreRestoreImpl}}, the {{oak-run}} explorer 
backend). Neither the writable {{FileStore}}/{{AbstractFileStore}} used by the 
live write/compaction path ever calls it.

h2. Proposed fix
* Stop eagerly caching the {{Set<UUID>}} in {{TarReader}} — build it lazily on 
demand inside {{getUUIDs()}} instead of in the constructor, since it is never 
on a hot path.
* Once nothing retains a {{UUID}} object per entry by default, replace 
{{RemoteSegmentArchiveEntry#uuid}} with two {{long}} fields ({{msb}}, {{lsb}}) 
and implement {{getMsb()}}/{{getLsb()}} as direct field reads; build a {{UUID}} 
on demand only inside {{getSegmentUUIDs()}} for that rare offline caller.
* {{AbstractRemoteSegmentArchiveWriter}} ({{oak-segment-remote}}) currently 
keys its own in-progress-archive index off 
{{RemoteSegmentArchiveEntry#getUuid()}} too; that call site will need reworking 
(e.g. an {{(msb, lsb)}}-keyed structure similar to the new {{SegmentIndex}}) 
since {{getUuid()}} would no longer return a free, pre-built instance.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to