HBASE-26533 KeyValueScanner might not be properly closed when using InternalScan.checkOnlyMemStore() (#3917)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
RamanChodzka 2021-12-05 17:34:30 +03:00 committed by GitHub
parent b5b286d793
commit 554580f966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -464,6 +464,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
for (KeyValueScanner kvs : allScanners) {
boolean isFile = kvs.isFileScanner();
if ((!isFile && filesOnly) || (isFile && memOnly)) {
kvs.close();
continue;
}

View File

@ -22,6 +22,7 @@ import static org.apache.hadoop.hbase.regionserver.KeyValueScanFixture.scanFixtu
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
@ -56,6 +57,7 @@ import org.apache.hadoop.hbase.filter.QualifierFilter;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CollectionBackedScanner;
import org.apache.hadoop.hbase.util.EnvironmentEdge;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
@ -1080,4 +1082,46 @@ public class TestStoreScanner {
assertEquals(2, results.size());
}
}
@Test
public void testScannersClosedWhenCheckingOnlyMemStore() throws IOException {
class MyCollectionBackedScanner extends CollectionBackedScanner {
final boolean fileScanner;
boolean closed;
MyCollectionBackedScanner(boolean fileScanner) {
super(Collections.emptySortedSet());
this.fileScanner = fileScanner;
}
@Override
public boolean isFileScanner() {
return fileScanner;
}
@Override
public void close() {
super.close();
closed = true;
}
}
ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, 1, Long.MAX_VALUE,
KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0
, CellComparator.getInstance(), false);
InternalScan scan = new InternalScan(new Scan());
scan.checkOnlyMemStore();
MyCollectionBackedScanner fileScanner = new MyCollectionBackedScanner(true);
MyCollectionBackedScanner memStoreScanner = new MyCollectionBackedScanner(false);
List<? extends KeyValueScanner> allScanners = Arrays.asList(fileScanner, memStoreScanner);
try (StoreScanner scanner = new StoreScanner(scan, scanInfo, null, allScanners)) {
List<KeyValueScanner> remaining = scanner.selectScannersFrom(null, allScanners);
assertEquals(1, remaining.size());
assertSame(memStoreScanner, remaining.get(0));
assertTrue(fileScanner.closed);
assertFalse(memStoreScanner.closed);
}
}
}