This is an automated email from the ASF dual-hosted git repository.

liuxiaocs7 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 12b9cfd8208 HBASE-30177 Make block caching configurable for MOB 
compaction reads (#8381)
12b9cfd8208 is described below

commit 12b9cfd8208755c3ff5d4ca15138c803a072f1a9
Author: Xiao Liu <[email protected]>
AuthorDate: Mon Jun 22 14:09:08 2026 +0800

    HBASE-30177 Make block caching configurable for MOB compaction reads (#8381)
    
    Signed-off-by: Peng Lu <[email protected]>
    Reviewed-by: Vladimir Rodionov <[email protected]>
    
    (cherry picked from commit be5f2289b75d7110853f89db7305943783761883)
---
 hbase-common/src/main/resources/hbase-default.xml  |  9 ++++
 .../hadoop/hbase/mob/DefaultMobStoreCompactor.java |  8 +--
 .../org/apache/hadoop/hbase/mob/MobConstants.java  |  3 ++
 .../hadoop/hbase/mob/FaultyMobStoreCompactor.java  |  4 +-
 .../hbase/mob/TestDefaultMobStoreCompactor.java    | 61 ++++++++++++++++++++++
 5 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/hbase-common/src/main/resources/hbase-default.xml 
b/hbase-common/src/main/resources/hbase-default.xml
index af819f30f32..eda46a144c2 100644
--- a/hbase-common/src/main/resources/hbase-default.xml
+++ b/hbase-common/src/main/resources/hbase-default.xml
@@ -1920,6 +1920,15 @@ possible configurations would overwhelm and obscure the 
important.
       The default value is one week.
     </description>
   </property>
+  <property>
+    <name>hbase.mob.compaction.read.cache.blocks</name>
+    <value>true</value>
+    <description>
+      Whether MOB compaction should cache blocks while reading existing MOB 
files to resolve
+      references during compaction. The default value is true to preserve the 
previous behavior.
+      Set to false to avoid polluting the block cache with background 
compaction reads.
+    </description>
+  </property>
   <property>
     <name>hbase.snapshot.master.timeout.millis</name>
     <value>300000</value>
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/DefaultMobStoreCompactor.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/DefaultMobStoreCompactor.java
index a91bb953eb4..b0e8ecb9c45 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/DefaultMobStoreCompactor.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/DefaultMobStoreCompactor.java
@@ -79,6 +79,7 @@ public class DefaultMobStoreCompactor extends 
DefaultCompactor {
   protected long mobSizeThreshold;
   protected HMobStore mobStore;
   protected boolean ioOptimizedMode = false;
+  protected final boolean cacheMobBlocksOnCompaction;
 
   /*
    * MOB file reference set thread local variable. It contains set of a MOB 
file names, which newly
@@ -86,7 +87,6 @@ public class DefaultMobStoreCompactor extends 
DefaultCompactor {
    * content of it is written into meta section of a newly created store file 
at the final step of
    * compaction process.
    */
-
   static ThreadLocal<SetMultimap<TableName, String>> mobRefSet =
     ThreadLocal.withInitial(HashMultimap::create);
 
@@ -169,7 +169,8 @@ public class DefaultMobStoreCompactor extends 
DefaultCompactor {
     this.ioOptimizedMode =
       conf.get(MobConstants.MOB_COMPACTION_TYPE_KEY, 
MobConstants.DEFAULT_MOB_COMPACTION_TYPE)
         .equals(MobConstants.OPTIMIZED_MOB_COMPACTION_TYPE);
-
+    this.cacheMobBlocksOnCompaction = 
conf.getBoolean(MobConstants.MOB_COMPACTION_READ_CACHE_BLOCKS,
+      MobConstants.DEFAULT_MOB_COMPACTION_READ_CACHE_BLOCKS);
   }
 
   @Override
@@ -258,7 +259,6 @@ public class DefaultMobStoreCompactor extends 
DefaultCompactor {
         throw new FileNotFoundException("Could not find mob file " + mobfile + 
" in the list of "
           + "expected locations: " + locations);
       }
-
     }
   }
 
@@ -371,7 +371,7 @@ public class DefaultMobStoreCompactor extends 
DefaultCompactor {
               String fName = MobUtils.getMobFileName(c);
               // Added to support migration
               try {
-                mobCell = mobStore.resolve(c, true, false).getCell();
+                mobCell = mobStore.resolve(c, cacheMobBlocksOnCompaction, 
false).getCell();
               } catch (FileNotFoundException fnfe) {
                 if (discardMobMiss) {
                   LOG.error("Missing MOB cell: file={} not found cell={}", 
fName, c);
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobConstants.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobConstants.java
index 052058a42ad..b2301bb3823 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobConstants.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobConstants.java
@@ -76,6 +76,9 @@ public final class MobConstants {
   public static final String MOB_COMPACTION_CHORE_PERIOD = 
"hbase.mob.compaction.chore.period";
   public static final int DEFAULT_MOB_COMPACTION_CHORE_PERIOD = 24 * 60 * 60 * 
7; // a week
   public static final String MOB_COMPACTOR_CLASS_KEY = 
"hbase.mob.compactor.class";
+  public static final String MOB_COMPACTION_READ_CACHE_BLOCKS =
+    "hbase.mob.compaction.read.cache.blocks";
+  public static final boolean DEFAULT_MOB_COMPACTION_READ_CACHE_BLOCKS = true;
 
   /**
    * Mob compaction type: "full", "optimized" "full" - run full major 
compaction (during migration)
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/FaultyMobStoreCompactor.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/FaultyMobStoreCompactor.java
index c0eb3539997..49de40f38c4 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/FaultyMobStoreCompactor.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/FaultyMobStoreCompactor.java
@@ -192,7 +192,7 @@ public class FaultyMobStoreCompactor extends 
DefaultMobStoreCompactor {
               String fName = MobUtils.getMobFileName(c);
               // Added to support migration
               try {
-                mobCell = mobStore.resolve(c, true, false).getCell();
+                mobCell = mobStore.resolve(c, cacheMobBlocksOnCompaction, 
false).getCell();
               } catch (FileNotFoundException fnfe) {
                 if (discardMobMiss) {
                   LOG.error("Missing MOB cell: file={} not found", fName);
@@ -259,7 +259,7 @@ public class FaultyMobStoreCompactor extends 
DefaultMobStoreCompactor {
               } else {
                 // If the value is not larger than the threshold, it's not 
regarded a mob. Retrieve
                 // the mob cell from the mob file, and write it back to the 
store file.
-                mobCell = mobStore.resolve(c, true, false).getCell();
+                mobCell = mobStore.resolve(c, cacheMobBlocksOnCompaction, 
false).getCell();
                 if (mobCell.getValueLength() != 0) {
                   // put the mob data back to the store file
                   PrivateCellUtil.setSequenceId(mobCell, c.getSequenceId());
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/TestDefaultMobStoreCompactor.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/TestDefaultMobStoreCompactor.java
new file mode 100644
index 00000000000..510ba600cfc
--- /dev/null
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/TestDefaultMobStoreCompactor.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.mob;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
+import org.apache.hadoop.hbase.io.compress.Compression;
+import org.apache.hadoop.hbase.regionserver.HMobStore;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+@Tag(SmallTests.TAG)
+public class TestDefaultMobStoreCompactor {
+
+  @Test
+  public void testCacheMobBlocksOnCompactionDefaultsToTrue() {
+    DefaultMobStoreCompactor compactor = newCompactor(new Configuration());
+
+    assertTrue(compactor.cacheMobBlocksOnCompaction);
+  }
+
+  @Test
+  public void testCacheMobBlocksOnCompactionCanBeDisabled() {
+    Configuration conf = new Configuration();
+    conf.setBoolean(MobConstants.MOB_COMPACTION_READ_CACHE_BLOCKS, false);
+    DefaultMobStoreCompactor compactor = newCompactor(conf);
+
+    assertFalse(compactor.cacheMobBlocksOnCompaction);
+  }
+
+  private DefaultMobStoreCompactor newCompactor(Configuration conf) {
+    HMobStore store = mock(HMobStore.class);
+    ColumnFamilyDescriptor family = mock(ColumnFamilyDescriptor.class);
+    when(store.getColumnFamilyDescriptor()).thenReturn(family);
+    
when(family.getMajorCompactionCompressionType()).thenReturn(Compression.Algorithm.NONE);
+    
when(family.getMinorCompactionCompressionType()).thenReturn(Compression.Algorithm.NONE);
+    when(family.getMobThreshold()).thenReturn(123L);
+    return new DefaultMobStoreCompactor(conf, store);
+  }
+}

Reply via email to