HBASE-15579 Procedure v2 - Remove synchronized around nonce in Procedure submit
This commit is contained in:
parent
57e1dbc8a6
commit
bfca2a4606
|
@ -635,34 +635,23 @@ public class ProcedureExecutor<TEnvironment> {
|
||||||
Preconditions.checkArgument(lastProcId.get() >= 0);
|
Preconditions.checkArgument(lastProcId.get() >= 0);
|
||||||
Preconditions.checkArgument(!proc.hasParent());
|
Preconditions.checkArgument(!proc.hasParent());
|
||||||
|
|
||||||
Long currentProcId;
|
// Initialize the Procedure ID
|
||||||
|
long currentProcId = nextProcId();
|
||||||
|
proc.setProcId(currentProcId);
|
||||||
|
|
||||||
// The following part of the code has to be synchronized to prevent multiple request
|
// Check whether the proc exists. If exist, just return the proc id.
|
||||||
// with the same nonce to execute at the same time.
|
// This is to prevent the same proc to submit multiple times (it could happen
|
||||||
synchronized (this) {
|
// when client could not talk to server and resubmit the same request).
|
||||||
// Check whether the proc exists. If exist, just return the proc id.
|
if (nonce != HConstants.NO_NONCE) {
|
||||||
// This is to prevent the same proc to submit multiple times (it could happen
|
NonceKey noncekey = new NonceKey(nonceGroup, nonce);
|
||||||
// when client could not talk to server and resubmit the same request).
|
proc.setNonceKey(noncekey);
|
||||||
NonceKey noncekey = null;
|
|
||||||
if (nonce != HConstants.NO_NONCE) {
|
Long oldProcId = nonceKeysToProcIdsMap.putIfAbsent(noncekey, currentProcId);
|
||||||
noncekey = new NonceKey(nonceGroup, nonce);
|
if (oldProcId != null) {
|
||||||
currentProcId = nonceKeysToProcIdsMap.get(noncekey);
|
// Found the proc
|
||||||
if (currentProcId != null) {
|
return oldProcId.longValue();
|
||||||
// Found the proc
|
|
||||||
return currentProcId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Initialize the Procedure ID
|
|
||||||
currentProcId = nextProcId();
|
|
||||||
proc.setProcId(currentProcId);
|
|
||||||
|
|
||||||
// This is new procedure. Set the noncekey and insert into the map.
|
|
||||||
if (noncekey != null) {
|
|
||||||
proc.setNonceKey(noncekey);
|
|
||||||
nonceKeysToProcIdsMap.put(noncekey, currentProcId);
|
|
||||||
}
|
|
||||||
} // end of synchronized (this)
|
|
||||||
|
|
||||||
// Commit the transaction
|
// Commit the transaction
|
||||||
store.insert(proc, null);
|
store.insert(proc, null);
|
||||||
|
|
|
@ -207,6 +207,32 @@ public class TestWALProcedureStore {
|
||||||
storeRestart(loader);
|
storeRestart(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProcIdHoles() throws Exception {
|
||||||
|
// Insert
|
||||||
|
for (int i = 0; i < 100; i += 2) {
|
||||||
|
procStore.insert(new TestProcedure(i), null);
|
||||||
|
if (i > 0 && (i % 10) == 0) {
|
||||||
|
LoadCounter loader = new LoadCounter();
|
||||||
|
storeRestart(loader);
|
||||||
|
assertEquals(0, loader.getCorruptedCount());
|
||||||
|
assertEquals((i / 2) + 1, loader.getLoadedCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(10, procStore.getActiveLogs().size());
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
for (int i = 0; i < 100; i += 2) {
|
||||||
|
procStore.delete(i);
|
||||||
|
}
|
||||||
|
assertEquals(1, procStore.getActiveLogs().size());
|
||||||
|
|
||||||
|
LoadCounter loader = new LoadCounter();
|
||||||
|
storeRestart(loader);
|
||||||
|
assertEquals(0, loader.getLoadedCount());
|
||||||
|
assertEquals(0, loader.getCorruptedCount());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCorruptedTrailer() throws Exception {
|
public void testCorruptedTrailer() throws Exception {
|
||||||
// Insert something
|
// Insert something
|
||||||
|
|
Loading…
Reference in New Issue