2222import org .elasticsearch .core .RefCounted ;
2323import org .elasticsearch .core .Releasables ;
2424
25+ import java .util .Collections ;
2526import java .util .HashMap ;
2627import java .util .List ;
2728import java .util .Map ;
@@ -169,11 +170,11 @@ private void collectOneDoc(int groupId, DocVector docVector, int valuePosition)
169170 segments .set (groupId , docVector .segments ().getInt (valuePosition ));
170171 docIds = bigArrays .grow (docIds , groupId + 1 );
171172 docIds .set (groupId , docVector .docs ().getInt (valuePosition ));
172- contextRefs .computeIfAbsent (shard , s -> {
173+ if ( contextRefs .containsKey (shard ) == false ) {
173174 RefCounted refCounted = docVector .shardRefCounted ().get (shard );
174175 refCounted .incRef ();
175- return refCounted ;
176- });
176+ contextRefs . put ( shard , refCounted ) ;
177+ }
177178 }
178179
179180 @ Override
@@ -226,12 +227,8 @@ public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected)
226227 try {
227228 segmentVector = segmentBuilder .build ();
228229 docVector = docBuilder .build ();
229- var shardRefs = new HashMap <>(contextRefs );
230- try {
231- blocks [offset ] = new DocVector (shardRefs ::get , shardVector , segmentVector , docVector , null ).asBlock ();
232- } catch (Exception e ) {
233- throw e ;
234- }
230+ var unmodifiedContextRefs = Collections .unmodifiableMap (contextRefs );
231+ blocks [offset ] = new DocVector (unmodifiedContextRefs ::get , shardVector , segmentVector , docVector , null ).asBlock ();
235232 } finally {
236233 if (blocks [offset ] == null ) {
237234 Releasables .closeExpectNoException (shardVector , segmentVector , docVector );
@@ -246,7 +243,6 @@ public void close() {
246243 for (RefCounted ref : contextRefs .values ()) {
247244 ref .decRef ();
248245 }
249- contextRefs .clear ();
250246 });
251247 }
252248
0 commit comments