You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2021/11/27 08:41:58 UTC
[hbase] branch branch-2.4 updated: HBASE-26476 Make DefaultMemStore extensible for HStore.memstore (#3869)
This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.4 by this push:
new b9b075f HBASE-26476 Make DefaultMemStore extensible for HStore.memstore (#3869)
b9b075f is described below
commit b9b075f21a4276f080fafdf7e4dea566dc056207
Author: chenglei <ch...@apache.org>
AuthorDate: Sat Nov 27 12:05:47 2021 +0800
HBASE-26476 Make DefaultMemStore extensible for HStore.memstore (#3869)
Signed-off-by: Duo Zhang <zh...@apache.org>
---
.../apache/hadoop/hbase/regionserver/HStore.java | 21 +++++++--------
.../hadoop/hbase/regionserver/TestHStore.java | 30 +++++++++++++++++++---
2 files changed, 38 insertions(+), 13 deletions(-)
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 55aa76c..fe2e635 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
@@ -153,11 +153,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;
@@ -373,17 +370,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;
}
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 abbff94..27df05c 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
@@ -2206,9 +2206,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();
@@ -2302,6 +2300,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);