diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java index df49e390ebc..8937d34e347 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -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 memStoreClass = + conf.getClass(MEMSTORE_CLASS_NAME, DefaultMemStore.class, MemStore.class); + ms = ReflectionUtils.newInstance(memStoreClass, new Object[] { conf, getComparator(), this.getHRegion().getRegionServicesForStores()}); break; default: - Class clz = conf.getClass(MEMSTORE_CLASS_NAME, - CompactingMemStore.class, CompactingMemStore.class); - ms = ReflectionUtils.newInstance(clz, new Object[]{conf, getComparator(), this, - this.getHRegion().getRegionServicesForStores(), inMemoryCompaction}); + Class 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; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java index ad40a98d74f..2f5350fb219 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java @@ -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);