From f709319457b43fca6de576d60f5a5e004da4116c Mon Sep 17 00:00:00 2001 From: Yiran-Wu Date: Mon, 27 Mar 2023 13:37:03 +0800 Subject: [PATCH] HBASE-27755 Fix update_all_config Table-level StoreHotnessProtector configuration was overwritten --- .../throttle/StoreHotnessProtector.java | 24 +++++++++++-- .../throttle/TestStoreHotnessProtector.java | 34 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java index 70683cb4572..f145309ba01 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java @@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CompoundConfiguration; import org.apache.hadoop.hbase.RegionTooBusyException; import org.apache.hadoop.hbase.regionserver.Region; import org.apache.hadoop.hbase.regionserver.Store; @@ -118,7 +119,12 @@ public class StoreHotnessProtector { } public void update(Configuration conf) { - init(conf); + // Add table descriptor configuration + CompoundConfiguration newconf = new CompoundConfiguration().add(conf); + if (this.region != null) { + newconf.addBytesMap(this.region.getTableDescriptor().getValues()); + } + init(newconf); preparePutToStoreMap.clear(); LOG.debug("update config: {}", this); } @@ -201,7 +207,9 @@ public class StoreHotnessProtector { } public String toString() { - return "StoreHotnessProtector, parallelPutToStoreThreadLimit=" + return "Table: " + + ((this.region != null) ? this.region.getTableDescriptor().getTableName() : "UNKUNOWN") + + "; StoreHotnessProtector, parallelPutToStoreThreadLimit=" + this.parallelPutToStoreThreadLimit + " ; minColumnNum=" + this.parallelPutToStoreThreadLimitCheckMinColumnCount + " ; preparePutThreadLimit=" + this.parallelPreparePutToStoreThreadLimit + " ; hotProtect now " @@ -217,6 +225,18 @@ public class StoreHotnessProtector { return preparePutToStoreMap; } + int getParallelPutToStoreThreadLimit() { + return parallelPutToStoreThreadLimit; + } + + int getParallelPreparePutToStoreThreadLimit() { + return parallelPreparePutToStoreThreadLimit; + } + + int getParallelPutToStoreThreadLimitCheckMinColumnCount() { + return parallelPutToStoreThreadLimitCheckMinColumnCount; + } + public static final long FIXED_SIZE = ClassSize.align(ClassSize.OBJECT + 2 * ClassSize.REFERENCE + 3 * Bytes.SIZEOF_INT); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/throttle/TestStoreHotnessProtector.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/throttle/TestStoreHotnessProtector.java index 290dce10487..a3a68867896 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/throttle/TestStoreHotnessProtector.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/throttle/TestStoreHotnessProtector.java @@ -35,7 +35,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.RegionTooBusyException; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.regionserver.Region; import org.apache.hadoop.hbase.regionserver.Store; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -129,4 +131,36 @@ public class TestStoreHotnessProtector { threadCount); } + @Test + public void testUpdateConfig() { + Configuration conf = new Configuration(); + conf.setInt(PARALLEL_PUT_STORE_THREADS_LIMIT_MIN_COLUMN_COUNT, 0); + conf.setInt(PARALLEL_PUT_STORE_THREADS_LIMIT, 10); + conf.setInt(PARALLEL_PREPARE_PUT_STORE_MULTIPLIER, 3); + Region mockRegion = mock(Region.class); + StoreHotnessProtector storeHotnessProtector = new StoreHotnessProtector(mockRegion, conf); + + Store mockStore1 = mock(Store.class); + RegionInfo mockRegionInfo = mock(RegionInfo.class); + byte[] family = "testF1".getBytes(); + + TableDescriptorBuilder builder = + TableDescriptorBuilder.newBuilder(TableName.valueOf("TestTable")); + builder.setValue(PARALLEL_PUT_STORE_THREADS_LIMIT_MIN_COLUMN_COUNT, "1"); + builder.setValue(PARALLEL_PUT_STORE_THREADS_LIMIT, "20"); + builder.setValue(PARALLEL_PREPARE_PUT_STORE_MULTIPLIER, "30"); + + when(mockRegion.getStore(family)).thenReturn(mockStore1); + when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo); + when(mockRegion.getTableDescriptor()).thenReturn(builder.build()); + + // update config + storeHotnessProtector.update(conf); + + // table config available + Assert.assertEquals(storeHotnessProtector.getParallelPreparePutToStoreThreadLimit(), 600); + Assert.assertEquals(storeHotnessProtector.getParallelPutToStoreThreadLimit(), 20); + Assert.assertEquals(storeHotnessProtector.getParallelPutToStoreThreadLimitCheckMinColumnCount(), + 1); + } }