use of org.apache.bookkeeper.common.util.Watcher in project bookkeeper by apache.
the class IndexPersistenceMgrTest method testEvictBeforeReleaseRace.
@Test
public void testEvictBeforeReleaseRace() throws Exception {
IndexPersistenceMgr indexPersistenceMgr = null;
Watcher<LastAddConfirmedUpdateNotification> watcher = notification -> notification.recycle();
try {
indexPersistenceMgr = createIndexPersistenceManager(1);
indexPersistenceMgr.getFileInfo(1L, masterKey);
indexPersistenceMgr.getFileInfo(2L, masterKey);
indexPersistenceMgr.getFileInfo(3L, masterKey);
indexPersistenceMgr.getFileInfo(4L, masterKey);
CachedFileInfo fi = indexPersistenceMgr.getFileInfo(1L, masterKey);
// trigger eviction
indexPersistenceMgr.getFileInfo(2L, masterKey);
indexPersistenceMgr.getFileInfo(3L, null);
indexPersistenceMgr.getFileInfo(4L, null);
Thread.sleep(1000);
fi.setFenced();
fi.release();
assertTrue(indexPersistenceMgr.isFenced(1));
} finally {
if (null != indexPersistenceMgr) {
indexPersistenceMgr.close();
}
}
}
use of org.apache.bookkeeper.common.util.Watcher in project bookkeeper by apache.
the class LongPollReadEntryProcessorV3 method getLongPollReadResponse.
private ReadResponse getLongPollReadResponse() {
if (!shouldReadEntry() && readRequest.hasTimeOut()) {
if (logger.isTraceEnabled()) {
logger.trace("Waiting For LAC Update {}", previousLAC);
}
final Stopwatch startTimeSw = Stopwatch.createStarted();
final boolean watched;
try {
watched = requestProcessor.bookie.waitForLastAddConfirmedUpdate(ledgerId, previousLAC, this);
} catch (Bookie.NoLedgerException e) {
logger.info("No ledger found while longpoll reading ledger {}, previous lac = {}.", ledgerId, previousLAC);
return buildErrorResponse(StatusCode.ENOLEDGER, startTimeSw);
} catch (IOException ioe) {
logger.error("IOException while longpoll reading ledger {}, previous lac = {} : ", ledgerId, previousLAC, ioe);
return buildErrorResponse(StatusCode.EIO, startTimeSw);
}
registerSuccessfulEvent(requestProcessor.longPollPreWaitStats, startTimeSw);
lastPhaseStartTime.reset().start();
if (watched) {
// successfully registered watcher to lac updates
if (logger.isTraceEnabled()) {
logger.trace("Waiting For LAC Update {}: Timeout {}", previousLAC, readRequest.getTimeOut());
}
synchronized (this) {
expirationTimerTask = requestTimer.newTimeout(timeout -> {
// When the timeout expires just get whatever is the current
// readLastConfirmed
LongPollReadEntryProcessorV3.this.scheduleDeferredRead(true);
}, readRequest.getTimeOut(), TimeUnit.MILLISECONDS);
}
return null;
}
}
// request doesn't have timeout or fail to wait, proceed to read entry
return getReadResponse();
}
Aggregations