@Test public void testNoEndWithoutStart() { ServerNonceManager nm = createManager(); try { nm.endOperation(NO_NONCE, 1, true); fail("Should have thrown"); } catch (AssertionError err) {} }
public void endOperation(long group, long nonce, boolean success) { if (nonce == HConstants.NO_NONCE) return; NonceKey nk = new NonceKey(group, nonce); OperationContext newResult = nonces.get(nk); assert newResult != null; synchronized (newResult) { assert newResult.getState() == OperationContext.WAIT; newResult.setState(success ? OperationContext.DONT_PROCEED : OperationContext.PROCEED); if (success) { newResult.reportActivity(); } else { OperationContext val = nonces.remove(nk); assert val == newResult; } if (newResult.hasWait()) { LOG.debug("Conflict with running op ended: " + nk + ", " + newResult); newResult.notifyAll(); } } }
ServerNonceManager { public void endOperation(long group, long nonce, boolean success) { if (nonce == HConstants.NO_NONCE) return; NonceKey nk = new NonceKey(group, nonce); OperationContext newResult = nonces.get(nk); assert newResult != null; synchronized (newResult) { assert newResult.getState() == OperationContext.WAIT; newResult.setState(success ? OperationContext.DONT_PROCEED : OperationContext.PROCEED); if (success) { newResult.reportActivity(); } else { OperationContext val = nonces.remove(nk); assert val == newResult; } if (newResult.hasWait()) { LOG.debug("Conflict with running op ended: " + nk + ", " + newResult); newResult.notifyAll(); } } } }
ServerNonceManager { public void endOperation(long group, long nonce, boolean success) { if (nonce == HConstants.NO_NONCE) return; NonceKey nk = new NonceKey(group, nonce); OperationContext newResult = nonces.get(nk); assert newResult != null; synchronized (newResult) { assert newResult.getState() == OperationContext.WAIT; newResult.setState(success ? OperationContext.DONT_PROCEED : OperationContext.PROCEED); if (success) { newResult.reportActivity(); } else { OperationContext val = nonces.remove(nk); assert val == newResult; } if (newResult.hasWait()) { LOG.debug("Conflict with running op ended: " + nk + ", " + newResult); newResult.notifyAll(); } } } ServerNonceManager(Configuration conf); }
ServerNonceManager { public void endOperation(long group, long nonce, boolean success) { if (nonce == HConstants.NO_NONCE) return; NonceKey nk = new NonceKey(group, nonce); OperationContext newResult = nonces.get(nk); assert newResult != null; synchronized (newResult) { assert newResult.getState() == OperationContext.WAIT; newResult.setState(success ? OperationContext.DONT_PROCEED : OperationContext.PROCEED); if (success) { newResult.reportActivity(); } else { OperationContext val = nonces.remove(nk); assert val == newResult; } if (newResult.hasWait()) { LOG.debug("Conflict with running op ended: " + nk + ", " + newResult); newResult.notifyAll(); } } } ServerNonceManager(Configuration conf); @VisibleForTesting void setConflictWaitIterationMs(int conflictWaitIterationMs); boolean startOperation(long group, long nonce, Stoppable stoppable); void endOperation(long group, long nonce, boolean success); void reportOperationFromWal(long group, long nonce, long writeTime); Chore createCleanupChore(Stoppable stoppable); }
ServerNonceManager { public void endOperation(long group, long nonce, boolean success) { if (nonce == HConstants.NO_NONCE) return; NonceKey nk = new NonceKey(group, nonce); OperationContext newResult = nonces.get(nk); assert newResult != null; synchronized (newResult) { assert newResult.getState() == OperationContext.WAIT; newResult.setState(success ? OperationContext.DONT_PROCEED : OperationContext.PROCEED); if (success) { newResult.reportActivity(); } else { OperationContext val = nonces.remove(nk); assert val == newResult; } if (newResult.hasWait()) { LOG.debug("Conflict with running op ended: " + nk + ", " + newResult); newResult.notifyAll(); } } } ServerNonceManager(Configuration conf); @VisibleForTesting void setConflictWaitIterationMs(int conflictWaitIterationMs); boolean startOperation(long group, long nonce, Stoppable stoppable); void endOperation(long group, long nonce, boolean success); void reportOperationFromWal(long group, long nonce, long writeTime); Chore createCleanupChore(Stoppable stoppable); static final String HASH_NONCE_GRACE_PERIOD_KEY; }