HBASE-26476 Make DefaultMemStore extensible for HStore.memstore (#3869)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
1b27124c61
commit
e311e23ac6
|
@ -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 int SPLIT_REGION_COMPACTION_PRIORITY = Integer.MIN_VALUE + 1000;
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(HStore.class);
|
private static final Logger LOG = LoggerFactory.getLogger(HStore.class);
|
||||||
/**
|
|
||||||
* TODO:After making the {@link DefaultMemStore} extensible in {@link HStore} by HBASE-26476,we
|
protected final MemStore memstore;
|
||||||
* change it back to final.
|
|
||||||
*/
|
|
||||||
protected MemStore memstore;
|
|
||||||
// This stores directory in the filesystem.
|
// This stores directory in the filesystem.
|
||||||
private final HRegion region;
|
private final HRegion region;
|
||||||
protected Configuration conf;
|
protected Configuration conf;
|
||||||
|
@ -363,17 +360,21 @@ public class HStore implements Store, HeapSize, StoreConfigInformation,
|
||||||
MemoryCompactionPolicy.valueOf(conf.get(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY,
|
MemoryCompactionPolicy.valueOf(conf.get(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY,
|
||||||
CompactingMemStore.COMPACTING_MEMSTORE_TYPE_DEFAULT).toUpperCase());
|
CompactingMemStore.COMPACTING_MEMSTORE_TYPE_DEFAULT).toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (inMemoryCompaction) {
|
switch (inMemoryCompaction) {
|
||||||
case NONE:
|
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(),
|
new Object[] { conf, getComparator(),
|
||||||
this.getHRegion().getRegionServicesForStores()});
|
this.getHRegion().getRegionServicesForStores()});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Class<? extends CompactingMemStore> clz = conf.getClass(MEMSTORE_CLASS_NAME,
|
Class<? extends CompactingMemStore> compactingMemStoreClass =
|
||||||
CompactingMemStore.class, CompactingMemStore.class);
|
conf.getClass(MEMSTORE_CLASS_NAME, CompactingMemStore.class, CompactingMemStore.class);
|
||||||
ms = ReflectionUtils.newInstance(clz, new Object[]{conf, getComparator(), this,
|
ms = ReflectionUtils.newInstance(compactingMemStoreClass,
|
||||||
this.getHRegion().getRegionServicesForStores(), inMemoryCompaction});
|
new Object[] { conf, getComparator(), this,
|
||||||
|
this.getHRegion().getRegionServicesForStores(), inMemoryCompaction });
|
||||||
}
|
}
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2190,9 +2190,7 @@ public class TestHStore {
|
||||||
conf.setBoolean(WALFactory.WAL_ENABLED, false);
|
conf.setBoolean(WALFactory.WAL_ENABLED, false);
|
||||||
|
|
||||||
init(name.getMethodName(), conf, ColumnFamilyDescriptorBuilder.newBuilder(family).build());
|
init(name.getMethodName(), conf, ColumnFamilyDescriptorBuilder.newBuilder(family).build());
|
||||||
MyDefaultMemStore myDefaultMemStore = new MyDefaultMemStore(store.conf, store.getComparator(),
|
MyDefaultMemStore myDefaultMemStore = (MyDefaultMemStore) (store.memstore);
|
||||||
store.getHRegion().getRegionServicesForStores());
|
|
||||||
store.memstore = myDefaultMemStore;
|
|
||||||
myDefaultMemStore.store = store;
|
myDefaultMemStore.store = store;
|
||||||
|
|
||||||
MemStoreSizing memStoreSizing = new NonThreadSafeMemStoreSizing();
|
MemStoreSizing memStoreSizing = new NonThreadSafeMemStoreSizing();
|
||||||
|
@ -2286,6 +2284,32 @@ public class TestHStore {
|
||||||
store.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact());
|
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) {
|
private HStoreFile mockStoreFileWithLength(long length) {
|
||||||
HStoreFile sf = mock(HStoreFile.class);
|
HStoreFile sf = mock(HStoreFile.class);
|
||||||
StoreFileReader sfr = mock(StoreFileReader.class);
|
StoreFileReader sfr = mock(StoreFileReader.class);
|
||||||
|
|
Loading…
Reference in New Issue