From bbfbe335204cde4c73c98e5a31cb7530d6536649 Mon Sep 17 00:00:00 2001 From: WenFeiYi Date: Fri, 11 Sep 2020 00:46:04 +0800 Subject: [PATCH] HBASE-24958 CompactingMemStore.timeOfOldestEdit error update (#2321) --- .../hbase/regionserver/AbstractMemStore.java | 6 ++++- .../regionserver/CompactingMemStore.java | 1 + .../hbase/regionserver/DefaultMemStore.java | 1 + .../regionserver/TestCompactingMemStore.java | 24 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java index 3c3834a4df8..60cc92f428c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java @@ -80,6 +80,7 @@ public abstract class AbstractMemStore implements MemStore { this.comparator = c; this.regionServices = regionServices; resetActive(); + resetTimeOfOldestEdit(); this.snapshot = SegmentFactory.instance().createImmutableSegment(c); this.snapshotId = NO_SNAPSHOT_ID; } @@ -95,7 +96,10 @@ public abstract class AbstractMemStore implements MemStore { memstoreAccounting.getHeapSize(), memstoreAccounting.getOffHeapSize(), memstoreAccounting.getCellsCount()); } - timeOfOldestEdit = Long.MAX_VALUE; + } + + protected void resetTimeOfOldestEdit() { + this.timeOfOldestEdit = Long.MAX_VALUE; } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactingMemStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactingMemStore.java index 8ffe7b30d36..76292736558 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactingMemStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactingMemStore.java @@ -212,6 +212,7 @@ public class CompactingMemStore extends AbstractMemStore { // region level lock ensures pushing active to pipeline is done in isolation // no concurrent update operations trying to flush the active segment pushActiveToPipeline(getActive()); + resetTimeOfOldestEdit(); snapshotId = EnvironmentEdgeManager.currentTime(); // in both cases whatever is pushed to snapshot is cleared from the pipeline if (compositeSnapshot) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DefaultMemStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DefaultMemStore.java index a50d0fc34e8..e38c5a3f292 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DefaultMemStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DefaultMemStore.java @@ -109,6 +109,7 @@ public class DefaultMemStore extends AbstractMemStore { } this.snapshot = immutableSegment; resetActive(); + resetTimeOfOldestEdit(); } } return new MemStoreSnapshot(this.snapshotId, this.snapshot); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java index 33bf94003da..9b336c21fc6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.regionserver; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -131,6 +132,29 @@ public class TestCompactingMemStore extends TestDefaultMemStore { assertNotNull(chunkCreator); } + /** + * A simple test which flush in memory affect timeOfOldestEdit + */ + @Test + public void testTimeOfOldestEdit() { + assertEquals(Long.MAX_VALUE, memstore.timeOfOldestEdit()); + final byte[] r = Bytes.toBytes("r"); + final byte[] f = Bytes.toBytes("f"); + final byte[] q = Bytes.toBytes("q"); + final byte[] v = Bytes.toBytes("v"); + final KeyValue kv = new KeyValue(r, f, q, v); + memstore.add(kv, null); + long timeOfOldestEdit = memstore.timeOfOldestEdit(); + assertNotEquals(Long.MAX_VALUE, timeOfOldestEdit); + + ((CompactingMemStore)memstore).flushInMemory(); + assertEquals(timeOfOldestEdit, memstore.timeOfOldestEdit()); + memstore.add(kv, null); + assertEquals(timeOfOldestEdit, memstore.timeOfOldestEdit()); + memstore.snapshot(); + assertEquals(Long.MAX_VALUE, memstore.timeOfOldestEdit()); + } + /** * A simple test which verifies the 3 possible states when scanning across snapshot. *