IncrementalIndex's ThreadLocal in can be static final. This ThreadLocal doesn't store anything specific to a given IncrementalIndex: rather, it's used to set a Row temporarily, and there is no situation when an IncrementalIndex could call recursively into another IncrementalIndex, so this temporary assignment cannot be disturbed.
As a safety net, we could add a check if (in.get() != null) throw ISE(..); in.set(row);
Furthermore, it would be ideal to get rid of ThreadLocal altogether (which would be beneficial for performance, because every Aggregator wouldn't need to query ThreadLocal upon every indexed row (ThreadLocal.get() is like Map.get(), not super cheap), and for reducing complexity, but this requires a significant refactoring of Aggregator interface and/or indexing logic, so saving this idea for a better time.
IncrementalIndex
'sThreadLocal in
can bestatic final
. ThisThreadLocal
doesn't store anything specific to a givenIncrementalIndex
: rather, it's used to set aRow
temporarily, and there is no situation when anIncrementalIndex
could call recursively into anotherIncrementalIndex
, so this temporary assignment cannot be disturbed.As a safety net, we could add a check
if (in.get() != null) throw ISE(..); in.set(row);
Furthermore, it would be ideal to get rid of
ThreadLocal
altogether (which would be beneficial for performance, because everyAggregator
wouldn't need to queryThreadLocal
upon every indexed row (ThreadLocal.get()
is likeMap.get()
, not super cheap), and for reducing complexity, but this requires a significant refactoring ofAggregator
interface and/or indexing logic, so saving this idea for a better time.