You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MergeOperator/CompactionFilter: scratch buffers keyed by Thread pin dead threads #359
MergeOperator.Custom (since #358) and CompactionFilter keep their per-thread result buffers in a per-operator ConcurrentHashMap<Thread, ScratchBuffer>, freed by destructorDispatch and pruned for dead threads once more than 64 entries are held.
Keying by Thread has weaknesses:
The map holds a strong reference to every thread that ever ran a merge or filter call, until the operator is destroyed or the prune runs.
The prune only runs past 64 entries and only on a call, so with fewer threads a dead thread's Thread object and buffer linger until the operator is destroyed.
Merges also run on application threads that call get; many short-lived virtual threads fill the map and rely on the prune.
64 is an arbitrary threshold.
What is fine: RocksDB's own pool threads are few and long-lived, the map is bounded by the operator's lifetime, and a shared Arena can be closed from whichever thread destroys the native operator.
Option
Replace the map with a ThreadLocal held in the operator's State (an instance field, not static), with Arena.ofAuto() buffers:
entries die with the thread or the operator, no pruning code and no destructorDispatch close loop, no pinned Thread objects;
a stale entry stays in a live thread's map until that thread next touches any ThreadLocal;
Sonar S5164 will probably flag it again, so it needs a documented suppression.
Rejected: keying by thread id (nothing pinned, but the prune can no longer ask isAlive(), so the map only grows).
Do both classes in one change so they stay the same shape.
Activity