HBASE-26476 Make DefaultMemStore extensible for HStore.memstore (#3869)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
chenglei 2021-11-27 12:05:47 +08:00 committed by Duo Zhang
parent 5101f372e4
commit 5437532910
2 changed files with 38 additions and 13 deletions

View File

@ -150,11 +150,8 @@ public class HStore implements Store, HeapSize, StoreConfigInformation,
private static final int SPLIT_REGION_COMPACTION_PRIORITY = Integer.MIN_VALUE + 1000;
private static final Logger LOG = LoggerFactory.getLogger(HStore.class);
/**
* TODO:After making the {@link DefaultMemStore} extensible in {@link HStore} by HBASE-26476,we
* change it back to final.
*/
protected MemStore memstore;
protected final MemStore memstore;
// This stores directory in the filesystem.
private final HRegion region;
protected Configuration conf;
@ -363,17 +360,21 @@ public class HStore implements Store, HeapSize, StoreConfigInformation,
MemoryCompactionPolicy.valueOf(conf.get(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY,
CompactingMemStore.COMPACTING_MEMSTORE_TYPE_DEFAULT).toUpperCase());
}
switch (inMemoryCompaction) {
case NONE:
ms = ReflectionUtils.newInstance(DefaultMemStore.class,
Class<? extends MemStore> memStoreClass =
conf.getClass(MEMSTORE_CLASS_NAME, DefaultMemStore.class, MemStore.class);
ms = ReflectionUtils.newInstance(memStoreClass,
new Object[] { conf, getComparator(),
this.getHRegion().getRegionServicesForStores()});
break;
default:
Class<? extends CompactingMemStore> clz = conf.getClass(MEMSTORE_CLASS_NAME,
CompactingMemStore.class, CompactingMemStore.class);
ms = ReflectionUtils.newInstance(clz, new Object[]{conf, getComparator(), this,
this.getHRegion().getRegionServicesForStores(), inMemoryCompaction});
Class<? extends CompactingMemStore> compactingMemStoreClass =
conf.getClass(MEMSTORE_CLASS_NAME, CompactingMemStore.class, CompactingMemStore.class);
ms = ReflectionUtils.newInstance(compactingMemStoreClass,
new Object[] { conf, getComparator(), this,
this.getHRegion().getRegionServicesForStores(), inMemoryCompaction });
}
return ms;
}

View File

@ -2204,9 +2204,7 @@ public class TestHStore {
conf.setBoolean(WALFactory.WAL_ENABLED, false);
init(name.getMethodName(), conf, ColumnFamilyDescriptorBuilder.newBuilder(family).build());
MyDefaultMemStore myDefaultMemStore = new MyDefaultMemStore(store.conf, store.getComparator(),
store.getHRegion().getRegionServicesForStores());
store.memstore = myDefaultMemStore;
MyDefaultMemStore myDefaultMemStore = (MyDefaultMemStore) (store.memstore);
myDefaultMemStore.store = store;
MemStoreSizing memStoreSizing = new NonThreadSafeMemStoreSizing();
@ -2300,6 +2298,32 @@ public class TestHStore {
store.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact());
}
/**
* This test is for HBASE-26476
*/
@Test
public void testExtendsDefaultMemStore() throws Exception {
Configuration conf = HBaseConfiguration.create();
conf.setBoolean(WALFactory.WAL_ENABLED, false);
init(name.getMethodName(), conf, ColumnFamilyDescriptorBuilder.newBuilder(family).build());
assertTrue(this.store.memstore.getClass() == DefaultMemStore.class);
tearDown();
conf.set(HStore.MEMSTORE_CLASS_NAME, CustomDefaultMemStore.class.getName());
init(name.getMethodName(), conf, ColumnFamilyDescriptorBuilder.newBuilder(family).build());
assertTrue(this.store.memstore.getClass() == CustomDefaultMemStore.class);
}
static class CustomDefaultMemStore extends DefaultMemStore {
public CustomDefaultMemStore(Configuration conf, CellComparator c,
RegionServicesForStores regionServices) {
super(conf, c, regionServices);
}
}
private HStoreFile mockStoreFileWithLength(long length) {
HStoreFile sf = mock(HStoreFile.class);
StoreFileReader sfr = mock(StoreFileReader.class);