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 04:10:35 UTC

[hbase] branch branch-2 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
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 5437532  HBASE-26476 Make DefaultMemStore extensible for HStore.memstore (#3869)
5437532 is described below

commit 5437532910aab319654a00c4c0bca9c1af4863db
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 df49e39..8937d34 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<? 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 ad40a98..2f5350f 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);