Search in sources :

Example 21 with ZkVersion

use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingLockPath.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingLockPath() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)), new Versioned<byte[]>(ZKLogMetadataForWriter.intToBytes(ZKLogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Test(org.junit.Test)

Example 22 with ZkVersion

use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingReadLockPath.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingReadLockPath() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)), new Versioned<byte[]>(ZKLogMetadataForWriter.intToBytes(ZKLogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(new byte[0], new ZkVersion(1)), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Test(org.junit.Test)

Example 23 with ZkVersion

use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.

the class Utils method zkGetData.

/**
     * Retrieve data from zookeeper <code>path</code>.
     *
     * @param path
     *          zookeeper path to retrieve data
     * @param watch
     *          whether to watch the path
     * @return future representing the versioned value. null version or null value means path doesn't exist.
     */
public static Future<Versioned<byte[]>> zkGetData(ZooKeeper zk, String path, boolean watch) {
    final Promise<Versioned<byte[]>> promise = new Promise<Versioned<byte[]>>();
    zk.getData(path, watch, new AsyncCallback.DataCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
            if (KeeperException.Code.OK.intValue() == rc) {
                if (null == stat) {
                    promise.setValue(new Versioned<byte[]>(null, null));
                } else {
                    promise.setValue(new Versioned<byte[]>(data, new ZkVersion(stat.getVersion())));
                }
            } else if (KeeperException.Code.NONODE.intValue() == rc) {
                promise.setValue(new Versioned<byte[]>(null, null));
            } else {
                promise.setException(KeeperException.create(KeeperException.Code.get(rc)));
            }
        }
    }, null);
    return promise;
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) AsyncCallback(org.apache.zookeeper.AsyncCallback) Promise(com.twitter.util.Promise) Stat(org.apache.zookeeper.data.Stat) ZkVersion(org.apache.bookkeeper.meta.ZkVersion)

Example 24 with ZkVersion

use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.

the class BKLogWriteHandler method storeMaxSequenceNumber.

// Transactional operations for MaxLogSegmentSequenceNo
void storeMaxSequenceNumber(final Transaction txn, final MaxLogSegmentSequenceNo maxSeqNo, final long seqNo, final boolean isInprogress) {
    byte[] data = DLUtils.serializeLogSegmentSequenceNumber(seqNo);
    Op zkOp = Op.setData(logMetadata.getLogSegmentsPath(), data, maxSeqNo.getZkVersion());
    txn.addOp(new ZKVersionedSetOp(zkOp, new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version version) {
            if (validateLogSegmentSequenceNumber) {
                synchronized (inprogressLSSNs) {
                    if (isInprogress) {
                        inprogressLSSNs.add(seqNo);
                    } else {
                        inprogressLSSNs.removeFirst();
                    }
                }
            }
            maxSeqNo.update((ZkVersion) version, seqNo);
        }

        @Override
        public void onAbort(Throwable t) {
        // no-op
        }
    }));
}
Also used : Op(org.apache.zookeeper.Op) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZKOp(com.twitter.distributedlog.zk.ZKOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp)

Example 25 with ZkVersion

use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.

the class LedgerAllocatorPool method initializeAllocators.

/**
     * Initialize simple allocators with given list of allocator names <i>allocators</i>.
     * It initializes a simple allocator with its simple allocator path.
     */
private void initializeAllocators(List<String> allocators) throws IOException, InterruptedException {
    final AtomicInteger numPendings = new AtomicInteger(allocators.size());
    final AtomicInteger numFailures = new AtomicInteger(0);
    final CountDownLatch latch = new CountDownLatch(numPendings.get() > 0 ? 1 : 0);
    AsyncCallback.DataCallback dataCallback = new AsyncCallback.DataCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
            if (KeeperException.Code.OK.intValue() != rc) {
                numFailures.incrementAndGet();
                latch.countDown();
                return;
            }
            Versioned<byte[]> allocatorData = new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));
            SimpleLedgerAllocator allocator = new SimpleLedgerAllocator(path, allocatorData, quorumConfigProvider, zkc, bkc);
            allocator.start();
            pendingList.add(allocator);
            if (numPendings.decrementAndGet() == 0 && numFailures.get() == 0) {
                latch.countDown();
            }
        }
    };
    for (String name : allocators) {
        String path = poolPath + "/" + name;
        zkc.get().getData(path, false, dataCallback, null);
    }
    latch.await();
    if (numFailures.get() > 0) {
        throw new IOException("Failed to initialize allocators : " + allocators);
    }
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) AsyncCallback(org.apache.zookeeper.AsyncCallback) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Stat(org.apache.zookeeper.data.Stat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZkVersion(org.apache.bookkeeper.meta.ZkVersion)

Aggregations

ZkVersion (org.apache.bookkeeper.meta.ZkVersion)26 Versioned (org.apache.bookkeeper.versioning.Versioned)21 Test (org.junit.Test)16 Stat (org.apache.zookeeper.data.Stat)11 Promise (com.twitter.util.Promise)9 Version (org.apache.bookkeeper.versioning.Version)9 URI (java.net.URI)8 ZKException (com.twitter.distributedlog.exceptions.ZKException)7 Transaction (com.twitter.distributedlog.util.Transaction)6 AsyncCallback (org.apache.zookeeper.AsyncCallback)4 KeeperException (org.apache.zookeeper.KeeperException)4 Op (org.apache.zookeeper.Op)4 ZKOp (com.twitter.distributedlog.zk.ZKOp)3 ZKVersionedSetOp (com.twitter.distributedlog.zk.ZKVersionedSetOp)3 DefaultZKOp (com.twitter.distributedlog.zk.DefaultZKOp)2 ZKTransaction (com.twitter.distributedlog.zk.ZKTransaction)2 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 OpResult (org.apache.zookeeper.OpResult)2 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)1