EungsopYoo commented on code in PR #7901:
URL: https://github.com/apache/hbase/pull/7901#discussion_r3037590591
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RowCache.java:
##########
@@ -110,16 +229,67 @@ boolean tryGetFromCache(RowCacheKey key, Get get,
List<Cell> results) {
}
results.addAll(row.getCells());
- // TODO: implement update of metrics
return true;
}
- void populateCache(List<Cell> results, RowCacheKey key) {
- // TODO: implement with barrier to avoid cache read during mutation
- try {
- rowCacheStrategy.cacheRow(key, new RowCells(results));
- } catch (CloneNotSupportedException ignored) {
- // Not able to cache row cells, ignore
- }
+ void populateCache(HRegion region, List<Cell> results, RowCacheKey key) {
+ // The row cache is populated only when no region level barriers remain
+ regionLevelBarrierMap.computeIfAbsent(region, t -> {
+ // The row cache is populated only when no row level barriers remain
+ rowLevelBarrierMap.computeIfAbsent(key, k -> {
+ try {
+ rowCacheStrategy.cacheRow(key, new RowCells(results));
+ } catch (CloneNotSupportedException ignored) {
+ // Not able to cache row cells, ignore
+ }
+ return null;
+ });
+ return null;
+ });
+ }
+
+ void createRegionLevelBarrier(HRegion region) {
+ regionLevelBarrierMap.computeIfAbsent(region, k -> new
AtomicInteger(0)).incrementAndGet();
+ }
+
+ void increaseRowCacheSeqNum(HRegion region) {
+ region.increaseRowCacheSeqNum();
+ }
+
+ void removeTableLevelBarrier(HRegion region) {
+ regionLevelBarrierMap.computeIfPresent(region, (k, counter) -> {
+ int remaining = counter.decrementAndGet();
+ return (remaining <= 0) ? null : counter;
+ });
+ }
Review Comment:
Done, renamed to removeRegionLevelBarrier. (95de81b)
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java:
##########
@@ -946,14 +949,19 @@ public HRegion(final HRegionFileSystem fs, final WAL wal,
final Configuration co
this.isRowCacheEnabled = checkRowCacheConfig();
}
- private boolean checkRowCacheConfig() {
+ boolean checkRowCacheConfig() {
Boolean fromDescriptor = htableDescriptor.getRowCacheEnabled();
// The setting from TableDescriptor has higher priority than the global
configuration
return fromDescriptor != null
? fromDescriptor
: conf.getBoolean(HConstants.ROW_CACHE_ENABLED_KEY,
HConstants.ROW_CACHE_ENABLED_DEFAULT);
}
+ // For testing only
+ void setRowCache(RowCache rowCache) {
+ this.rowCache = rowCache;
+ }
Review Comment:
Done, added @RestrictedApi annotation. (267f4ef)
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerWrapperImpl.java:
##########
@@ -69,6 +69,7 @@ class MetricsRegionServerWrapperImpl implements
MetricsRegionServerWrapper {
private BlockCache l2Cache = null;
private MobFileCache mobFileCache;
private CacheStats cacheStats;
+ private final RowCache rowCache;
Review Comment:
Done, moved rowCache field next to MobFileCache. (782dd75)
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerWrapperImpl.java:
##########
@@ -99,6 +100,8 @@ public MetricsRegionServerWrapperImpl(final HRegionServer
regionServer) {
this.regionServer = regionServer;
initBlockCache();
initMobFileCache();
+ RSRpcServices rsRpcServices = this.regionServer.getRSRpcServices();
+ this.rowCache = rsRpcServices == null ? null :
rsRpcServices.getServer().getRowCache();
Review Comment:
Done, extracted initRowCache() method. (782dd75)
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowCache.java:
##########
@@ -0,0 +1,547 @@
+/*
+ * 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.regionserver;
+
+import static org.apache.hadoop.hbase.HConstants.HFILE_BLOCK_CACHE_SIZE_KEY;
+import static org.apache.hadoop.hbase.HConstants.ROW_CACHE_SIZE_KEY;
+import static
org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.ROW_CACHE_EVICTED_ROW_COUNT;
+import static
org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.ROW_CACHE_HIT_COUNT;
+import static
org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.ROW_CACHE_MISS_COUNT;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.CompatibilityFactory;
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Append;
+import org.apache.hadoop.hbase.client.CheckAndMutate;
+import org.apache.hadoop.hbase.client.CheckAndMutateResult;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Row;
+import org.apache.hadoop.hbase.client.RowMutations;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
+import org.apache.hadoop.hbase.test.MetricsAssertHelper;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.RegionServerTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+@Category({ RegionServerTests.class, MediumTests.class })
+public class TestRowCache {
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestRowCache.class);
Review Comment:
Done, migrated TestRowCache to JUnit5. (1fc9d5c)
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java:
##########
@@ -2347,8 +2347,21 @@ public BulkLoadHFileResponse bulkLoadHFile(final
RpcController controller,
return bulkLoadHFileInternal(request);
}
- // TODO: implement row cache logic for bulk load
- return bulkLoadHFileInternal(request);
+ RowCache rowCache = region.getRegionServerServices().getRowCache();
+
+ // Since bulkload modifies the store files, the row cache should be
disabled until the bulkload
+ // is finished.
+ rowCache.createRegionLevelBarrier(region);
+ try {
+ // We do not invalidate the entire row cache directly, as it contains a
large number of
+ // entries and takes a long time. Instead, we increment rowCacheSeqNum,
which is used when
+ // constructing a RowCacheKey, thereby making the existing row cache
entries stale.
+ rowCache.increaseRowCacheSeqNum(region);
+ return bulkLoadHFileInternal(request);
+ } finally {
+ // The row cache for the region has been enabled again
+ rowCache.removeTableLevelBarrier(region);
Review Comment:
Done, renamed to removeRegionLevelBarrier. (95de81b)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]