From 3830890635261c9eccd7ceeff8ad1b95e3714cd6 Mon Sep 17 00:00:00 2001 From: tedyu Date: Wed, 12 Oct 2016 10:07:37 -0700 Subject: [PATCH] HBASE-16801 The Append/Increment may return the data from future (ChiaPing Tsai) --- .../regionserver/ServerNonceManager.java | 2 +- .../regionserver/TestServerNonceManager.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java index bd9dad9ef63..1e1a9a97862 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java @@ -62,7 +62,7 @@ public class ServerNonceManager { private static final long WAITING_BIT = 4; private static final long ALL_FLAG_BITS = WAITING_BIT | STATE_BITS; - private long mvcc; + private volatile long mvcc; @Override public String toString() { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerNonceManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerNonceManager.java index 940f715c551..6bf17210dcb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerNonceManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestServerNonceManager.java @@ -44,6 +44,27 @@ import org.mockito.stubbing.Answer; @Category(SmallTests.class) public class TestServerNonceManager { + @Test + public void testMvcc() throws Exception { + ServerNonceManager nm = createManager(); + final long group = 100; + final long nonce = 1; + final long initMvcc = 999; + assertTrue(nm.startOperation(group, nonce, createStoppable())); + nm.addMvccToOperationContext(group, nonce, initMvcc); + nm.endOperation(group, nonce, true); + assertEquals(initMvcc, nm.getMvccFromOperationContext(group, nonce)); + long newMvcc = initMvcc + 1; + for (long newNonce = nonce + 1; newNonce != (nonce + 5); ++newNonce) { + assertTrue(nm.startOperation(group, newNonce, createStoppable())); + nm.addMvccToOperationContext(group, newNonce, newMvcc); + nm.endOperation(group, newNonce, true); + assertEquals(newMvcc, nm.getMvccFromOperationContext(group, newNonce)); + ++newMvcc; + } + assertEquals(initMvcc, nm.getMvccFromOperationContext(group, nonce)); + } + @Test public void testNormalStartEnd() throws Exception { final long[] numbers = new long[] { NO_NONCE, 1, 2, Long.MAX_VALUE, Long.MIN_VALUE };