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

liuxiaocs7 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new be5f2289b75 HBASE-30177 Make block caching configurable for MOB 
compaction reads (#8276)
be5f2289b75 is described below

commit be5f2289b75d7110853f89db7305943783761883
Author: Xiao Liu <[email protected]>
AuthorDate: Fri Jun 19 21:45:15 2026 +0800

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

diff --git a/hbase-common/src/main/resources/hbase-default.xml 
b/hbase-common/src/main/resources/hbase-default.xml
index 6e8b9ea9e1f..7eb264c837e 100644
--- a/hbase-common/src/main/resources/hbase-default.xml
+++ b/hbase-common/src/main/resources/hbase-default.xml
@@ -1926,6 +1926,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 87248e7bab6..cc38fac5a15 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
@@ -80,6 +80,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
@@ -169,7 +170,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
@@ -377,7 +379,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 (DoNotRetryIOException e) {
                 if (
                   discardMobMiss && e.getCause() != null
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 e8332cd0a01..7c3f88223dd 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 b08a44c04e7..536f40eb0af 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
@@ -199,7 +199,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 (DoNotRetryIOException e) {
                 if (
                   discardMobMiss && e.getCause() != null
@@ -269,7 +269,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