use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.
the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingVersion.
@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingVersion() 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[]>(null, null));
ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
use of org.apache.bookkeeper.versioning.Versioned 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);
}
use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.
the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingMaxTxnId.
@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingMaxTxnId() throws Exception {
String rootPath = "/test-missing-max-txn-id";
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[]>(null, null));
ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
use of org.apache.bookkeeper.versioning.Versioned 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);
}
}
use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.
the class SimpleLedgerAllocator method createAllocationData.
private static Future<Versioned<byte[]>> createAllocationData(final String allocatePath, final ZooKeeperClient zkc) {
try {
final Promise<Versioned<byte[]>> promise = new Promise<Versioned<byte[]>>();
zkc.get().create(allocatePath, DistributedLogConstants.EMPTY_BYTES, zkc.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.Create2Callback() {
@Override
public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
promise.setValue(new Versioned<byte[]>(DistributedLogConstants.EMPTY_BYTES, new ZkVersion(stat.getVersion())));
} else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
Utils.zkGetData(zkc, allocatePath, false).proxyTo(promise);
} else {
promise.setException(FutureUtils.zkException(KeeperException.create(KeeperException.Code.get(rc)), allocatePath));
}
}
}, null);
return promise;
} catch (ZooKeeperClient.ZooKeeperConnectionException e) {
return Future.exception(FutureUtils.zkException(e, allocatePath));
} catch (InterruptedException e) {
return Future.exception(FutureUtils.zkException(e, allocatePath));
}
}
Aggregations