@@ -220,9 +220,8 @@ private void loadFromSingleLeaf(Block[] blocks, int shard, int segment, BlockLoa
220
220
positionFieldWork (shard , segment , firstDoc );
221
221
StoredFieldsSpec storedFieldsSpec = StoredFieldsSpec .NO_REQUIREMENTS ;
222
222
List <RowStrideReaderWork > rowStrideReaders = new ArrayList <>(fields .length );
223
- ComputeBlockLoaderFactory loaderBlockFactory = new ComputeBlockLoaderFactory (blockFactory , docs .count ());
224
223
LeafReaderContext ctx = ctx (shard , segment );
225
- try {
224
+ try ( ComputeBlockLoaderFactory loaderBlockFactory = new ComputeBlockLoaderFactory ( blockFactory , docs . count ())) {
226
225
for (int f = 0 ; f < fields .length ; f ++) {
227
226
FieldWork field = fields [f ];
228
227
BlockLoader .ColumnAtATimeReader columnAtATime = field .columnAtATime (ctx );
@@ -345,27 +344,28 @@ void run() throws IOException {
345
344
builders [f ] = new Block .Builder [shardContexts .size ()];
346
345
converters [f ] = new BlockLoader [shardContexts .size ()];
347
346
}
348
- ComputeBlockLoaderFactory loaderBlockFactory = new ComputeBlockLoaderFactory (blockFactory , docs .getPositionCount ());
349
- int p = forwards [0 ];
350
- int shard = shards .getInt (p );
351
- int segment = segments .getInt (p );
352
- int firstDoc = docs .getInt (p );
353
- positionFieldWork (shard , segment , firstDoc );
354
- LeafReaderContext ctx = ctx (shard , segment );
355
- fieldsMoved (ctx , shard );
356
- verifyBuilders (loaderBlockFactory , shard );
357
- read (firstDoc , shard );
358
- for (int i = 1 ; i < forwards .length ; i ++) {
359
- p = forwards [i ];
360
- shard = shards .getInt (p );
361
- segment = segments .getInt (p );
362
- boolean changedSegment = positionFieldWorkDocGuarteedAscending (shard , segment );
363
- if (changedSegment ) {
364
- ctx = ctx (shard , segment );
365
- fieldsMoved (ctx , shard );
366
- }
347
+ try (ComputeBlockLoaderFactory loaderBlockFactory = new ComputeBlockLoaderFactory (blockFactory , docs .getPositionCount ())) {
348
+ int p = forwards [0 ];
349
+ int shard = shards .getInt (p );
350
+ int segment = segments .getInt (p );
351
+ int firstDoc = docs .getInt (p );
352
+ positionFieldWork (shard , segment , firstDoc );
353
+ LeafReaderContext ctx = ctx (shard , segment );
354
+ fieldsMoved (ctx , shard );
367
355
verifyBuilders (loaderBlockFactory , shard );
368
- read (docs .getInt (p ), shard );
356
+ read (firstDoc , shard );
357
+ for (int i = 1 ; i < forwards .length ; i ++) {
358
+ p = forwards [i ];
359
+ shard = shards .getInt (p );
360
+ segment = segments .getInt (p );
361
+ boolean changedSegment = positionFieldWorkDocGuarteedAscending (shard , segment );
362
+ if (changedSegment ) {
363
+ ctx = ctx (shard , segment );
364
+ fieldsMoved (ctx , shard );
365
+ }
366
+ verifyBuilders (loaderBlockFactory , shard );
367
+ read (docs .getInt (p ), shard );
368
+ }
369
369
}
370
370
for (int f = 0 ; f < target .length ; f ++) {
371
371
for (int s = 0 ; s < shardContexts .size (); s ++) {
@@ -614,7 +614,7 @@ public String toString() {
614
614
}
615
615
}
616
616
617
- private static class ComputeBlockLoaderFactory implements BlockLoader .BlockFactory {
617
+ private static class ComputeBlockLoaderFactory implements BlockLoader .BlockFactory , Releasable {
618
618
private final BlockFactory factory ;
619
619
private final int pageSize ;
620
620
private Block nullBlock ;
@@ -683,12 +683,18 @@ public BlockLoader.Builder nulls(int expectedCount) {
683
683
public Block constantNulls () {
684
684
if (nullBlock == null ) {
685
685
nullBlock = factory .newConstantNullBlock (pageSize );
686
- } else {
687
- nullBlock .incRef ();
688
686
}
687
+ nullBlock .incRef ();
689
688
return nullBlock ;
690
689
}
691
690
691
+ @ Override
692
+ public void close () {
693
+ if (nullBlock != null ) {
694
+ nullBlock .close ();
695
+ }
696
+ }
697
+
692
698
@ Override
693
699
public BytesRefBlock constantBytes (BytesRef value ) {
694
700
return factory .newConstantBytesRefBlockWith (value , pageSize );
0 commit comments