HBASE-24958 CompactingMemStore.timeOfOldestEdit error update (#2321)

This commit is contained in:
WenFeiYi 2020-09-11 00:46:04 +08:00 committed by GitHub
parent ce59a2ba30
commit bbfbe33520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 1 deletions

View File

@ -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;
}
/**

View File

@ -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) {

View File

@ -109,6 +109,7 @@ public class DefaultMemStore extends AbstractMemStore {
}
this.snapshot = immutableSegment;
resetActive();
resetTimeOfOldestEdit();
}
}
return new MemStoreSnapshot(this.snapshotId, this.snapshot);

View File

@ -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.
*