Search in sources :

Example 36 with DLSN

use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.

the class ZKSubscriptionStateStore method getLastCommitPositionFromZK.

Future<DLSN> getLastCommitPositionFromZK() {
    final Promise<DLSN> result = new Promise<DLSN>();
    try {
        logger.debug("Reading last commit position from path {}", zkPath);
        zooKeeperClient.get().getData(zkPath, false, new AsyncCallback.DataCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
                logger.debug("Read last commit position from path {}: rc = {}", zkPath, rc);
                if (KeeperException.Code.NONODE.intValue() == rc) {
                    result.setValue(DLSN.NonInclusiveLowerBound);
                } else if (KeeperException.Code.OK.intValue() != rc) {
                    result.setException(KeeperException.create(KeeperException.Code.get(rc), path));
                } else {
                    try {
                        DLSN dlsn = DLSN.deserialize(new String(data, Charsets.UTF_8));
                        result.setValue(dlsn);
                    } catch (Exception t) {
                        logger.warn("Invalid last commit position found from path {}", zkPath, t);
                        // invalid dlsn recorded in subscription state store
                        result.setValue(DLSN.NonInclusiveLowerBound);
                    }
                }
            }
        }, null);
    } catch (ZooKeeperClient.ZooKeeperConnectionException zkce) {
        result.setException(zkce);
    } catch (InterruptedException ie) {
        result.setException(new DLInterruptedException("getLastCommitPosition was interrupted", ie));
    }
    return result;
}
Also used : DLSN(com.twitter.distributedlog.DLSN) AsyncCallback(org.apache.zookeeper.AsyncCallback) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) Promise(com.twitter.util.Promise) Stat(org.apache.zookeeper.data.Stat) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException)

Aggregations

DLSN (com.twitter.distributedlog.DLSN)36 Test (org.junit.Test)21 LogRecordWithDLSN (com.twitter.distributedlog.LogRecordWithDLSN)14 DistributedLogClient (com.twitter.distributedlog.service.DistributedLogClient)11 ByteBuffer (java.nio.ByteBuffer)10 DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)8 AsyncLogReader (com.twitter.distributedlog.AsyncLogReader)6 LogRecord (com.twitter.distributedlog.LogRecord)6 LogReader (com.twitter.distributedlog.LogReader)5 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)5 Future (com.twitter.util.Future)5 DLException (com.twitter.distributedlog.exceptions.DLException)4 LogNotFoundException (com.twitter.distributedlog.exceptions.LogNotFoundException)4 ArrayList (java.util.ArrayList)4 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)3 NoBrokersAvailableException (com.twitter.finagle.NoBrokersAvailableException)3 Promise (com.twitter.util.Promise)3 IOException (java.io.IOException)3 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)2 LogRecordSet (com.twitter.distributedlog.LogRecordSet)2