void postIOFailure(IOException e) { addStatusIfCountNotOverLimit(new ErrorStatus("IO failure while writing to " + getDescription(), this, e)); presumedClean = false; if (recoveryCoordinator == null) { recoveryCoordinator = new RecoveryCoordinator(); } }
public void write(byte b[], int off, int len) { if (isPresumedInError()) { if (!recoveryCoordinator.isTooSoon()) { attemptRecovery(); } return; // return regardless of the success of the recovery attempt } try { os.write(b, off, len); postSuccessfulWrite(); } catch (IOException e) { postIOFailure(e); } }
public boolean isTooSoon() { long now = getCurrentTime(); if(now > next) { next = now + getBackoffCoefficient(); return false; } else { return true; } }
@Test public void recoveryNotNeededAfterInit() { RecoveryCoordinator rc = new RecoveryCoordinator(); assertTrue(rc.isTooSoon()); }
@Test public void recoveryNeededIfCurrentTimeSetToExceedBackOffTime() { rc.setCurrentTime(now + RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN + 1); assertFalse(rc.isTooSoon()); }
@Test public void recoveryNeededIfAsleepForMoreThanBackOffTime() throws InterruptedException { rc.setCurrentTime(now + RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN + 20); assertFalse(rc.isTooSoon()); }
public boolean isTooSoon() { long now = getCurrentTime(); if(now > next) { next = now + getBackoffCoefficient(); return false; } else { return true; } }
@Override public void write(int b) { if (isPresumedInError()) { if (!recoveryCoordinator.isTooSoon()) { attemptRecovery(); } return; // return regardless of the success of the recovery attempt } try { os.write(b); postSuccessfulWrite(); } catch (IOException e) { postIOFailure(e); } }
public void postIOFailure(IOException e) { addStatusIfCountNotOverLimit(new ErrorStatus("IO failure while writing to " + getDescription(), this, e)); presumedClean = false; if (recoveryCoordinator == null) { recoveryCoordinator = new RecoveryCoordinator(); } }
@Test public void recoveryNotNeededIfAsleepForLessThanBackOffTime() throws InterruptedException { rc.setCurrentTime(now + RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN / 2); assertTrue(rc.isTooSoon()); }
public boolean isTooSoon() { long now = getCurrentTime(); if(now > next) { next = now + getBackoffCoefficient(); return false; } else { return true; } }
public void write(byte b[], int off, int len) { if (isPresumedInError()) { if (!recoveryCoordinator.isTooSoon()) { attemptRecovery(); } return; // return regardless of the success of the recovery attempt } try { os.write(b, off, len); postSuccessfulWrite(); } catch (IOException e) { postIOFailure(e); } }
public void postIOFailure(IOException e) { addStatusIfCountNotOverLimit(new ErrorStatus("IO failure while writing to " + getDescription(), this, e)); presumedClean = false; if (recoveryCoordinator == null) { recoveryCoordinator = new RecoveryCoordinator(); } }
@Test public void recoveryNotNeededIfCurrentTimeSetToBackOffTime() throws InterruptedException { rc.setCurrentTime(now + RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN); assertTrue(rc.isTooSoon()); }
public RecoveryCoordinator(long currentTime) { this.currentTime = currentTime; next = getCurrentTime() + getBackoffCoefficient(); }
public void write(byte b[], int off, int len) { if (isPresumedInError()) { if (!recoveryCoordinator.isTooSoon()) { attemptRecovery(); } return; // return regardless of the success of the recovery attempt } try { os.write(b, off, len); postSuccessfulWrite(); } catch (IOException e) { postIOFailure(e); } }
void postIOFailure(IOException e) { addStatusIfCountNotOverLimit(new ErrorStatus("IO failure while writing to " + getDescription(), this, e)); presumedClean = false; if (recoveryCoordinator == null) { recoveryCoordinator = new RecoveryCoordinator(); } }
@Test public void recoveryConditionDetectedEvenAfterReallyLongTimesBetweenRecovery() { // Since backoff time quadruples whenever recovery is needed, // we double the offset on each for-loop iteration, causing // every other iteration to trigger recovery. long offset = RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN; for (int i = 0; i < 16; i++) { rc.setCurrentTime(now + offset); if (i % 2 == 0) { assertTrue("recovery should've been needed at " + offset, rc.isTooSoon()); } else { assertFalse("recovery should NOT have been needed at " + offset, rc.isTooSoon()); } offset *= 2; } } }
public boolean isTooSoon() { long now = getCurrentTime(); if(now > next) { next = now + getBackoffCoefficient(); return false; } else { return true; } }
public void write(byte b[], int off, int len) { if (isPresumedInError()) { if (!recoveryCoordinator.isTooSoon()) { attemptRecovery(); } return; // return regardless of the success of the recovery attempt } try { os.write(b, off, len); postSuccessfulWrite(); } catch (IOException e) { postIOFailure(e); } }