Search in sources :

Example 1 with Watcher

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();
        }
    }
}
Also used : NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) DiskChecker(org.apache.bookkeeper.util.DiskChecker) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) UTF_8(com.google.common.base.Charsets.UTF_8) File(java.io.File) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) Assert.assertNull(org.junit.Assert.assertNull) Watcher(org.apache.bookkeeper.common.util.Watcher) After(org.junit.After) Assert.fail(org.junit.Assert.fail) CachedFileInfo(org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo) Assert.assertEquals(org.junit.Assert.assertEquals) SnapshotMap(org.apache.bookkeeper.util.SnapshotMap) Before(org.junit.Before) CachedFileInfo(org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo) Test(org.junit.Test)

Example 2 with Watcher

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();
}
Also used : Timeout(io.netty.util.Timeout) Logger(org.slf4j.Logger) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Request(org.apache.bookkeeper.proto.BookkeeperProtocol.Request) StatusCode(org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) ReadResponse(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadResponse) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) LastAddConfirmedUpdateNotification(org.apache.bookkeeper.bookie.LastAddConfirmedUpdateNotification) Watcher(org.apache.bookkeeper.common.util.Watcher) Optional(com.google.common.base.Optional) HashedWheelTimer(io.netty.util.HashedWheelTimer) Bookie(org.apache.bookkeeper.bookie.Bookie) ExecutorService(java.util.concurrent.ExecutorService) Bookie(org.apache.bookkeeper.bookie.Bookie) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException)

Aggregations

Watcher (org.apache.bookkeeper.common.util.Watcher)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 UTF_8 (com.google.common.base.Charsets.UTF_8)1 Optional (com.google.common.base.Optional)1 Stopwatch (com.google.common.base.Stopwatch)1 Channel (io.netty.channel.Channel)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Timeout (io.netty.util.Timeout)1 File (java.io.File)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Bookie (org.apache.bookkeeper.bookie.Bookie)1 CachedFileInfo (org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo)1 LastAddConfirmedUpdateNotification (org.apache.bookkeeper.bookie.LastAddConfirmedUpdateNotification)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 ReadResponse (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadResponse)1