use of org.apache.distributedlog.metadata.LogMetadataForWriter in project bookkeeper by apache.
the class TestZKLogSegmentMetadataStore method testStoreMaxTxnIdOnNonExistentPath.
@Test(timeout = 60000)
public void testStoreMaxTxnIdOnNonExistentPath() throws Exception {
Transaction<Object> updateTxn = lsmStore.transaction();
Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(10));
final CompletableFuture<Version> result = new CompletableFuture<Version>();
String nonExistentPath = rootZkPath + "/non-existent";
LogMetadataForWriter metadata = mock(LogMetadataForWriter.class);
when(metadata.getMaxTxIdPath()).thenReturn(nonExistentPath);
lsmStore.storeMaxTxnId(updateTxn, metadata, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.complete(r);
}
@Override
public void onAbort(Throwable t) {
result.completeExceptionally(t);
}
});
try {
Utils.ioResult(updateTxn.execute());
fail("Should fail on storing log record transaction id if path doesn't exist");
} catch (ZKException zke) {
assertEquals(KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
}
try {
Utils.ioResult(result);
fail("Should fail on storing log record transaction id if path doesn't exist");
} catch (ZKException ze) {
assertEquals(KeeperException.Code.NONODE, ze.getKeeperExceptionCode());
}
}
use of org.apache.distributedlog.metadata.LogMetadataForWriter in project bookkeeper by apache.
the class TestZKLogSegmentMetadataStore method testStoreMaxTxnId.
@Test(timeout = 60000)
public void testStoreMaxTxnId() throws Exception {
Transaction<Object> updateTxn = lsmStore.transaction();
Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(0));
final CompletableFuture<Version> result = new CompletableFuture<Version>();
LogMetadataForWriter metadata = mock(LogMetadataForWriter.class);
when(metadata.getMaxTxIdPath()).thenReturn(rootZkPath);
lsmStore.storeMaxTxnId(updateTxn, metadata, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.complete(r);
}
@Override
public void onAbort(Throwable t) {
result.completeExceptionally(t);
}
});
Utils.ioResult(updateTxn.execute());
assertEquals(1L, ((LongVersion) Utils.ioResult(result)).getLongVersion());
Stat stat = new Stat();
byte[] data = zkc.get().getData(rootZkPath, false, stat);
assertEquals(999L, DLUtils.deserializeTransactionId(data));
assertEquals(1, stat.getVersion());
}
use of org.apache.distributedlog.metadata.LogMetadataForWriter in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method processLogMetadatas.
static LogMetadataForWriter processLogMetadatas(URI uri, String logName, String logIdentifier, List<Versioned<byte[]>> metadatas, boolean ownAllocator) throws UnexpectedException {
try {
// max id
Versioned<byte[]> maxTxnIdData = metadatas.get(MetadataIndex.MAX_TXID);
ensureMetadataExist(maxTxnIdData);
// version
Versioned<byte[]> versionData = metadatas.get(MetadataIndex.VERSION);
ensureMetadataExist(maxTxnIdData);
checkArgument(LAYOUT_VERSION == bytesToInt(versionData.getValue()));
// lock path
ensureMetadataExist(metadatas.get(MetadataIndex.LOCK));
// read lock path
ensureMetadataExist(metadatas.get(MetadataIndex.READ_LOCK));
// max lssn
Versioned<byte[]> maxLSSNData = metadatas.get(MetadataIndex.LOGSEGMENTS);
ensureMetadataExist(maxLSSNData);
try {
DLUtils.deserializeLogSegmentSequenceNumber(maxLSSNData.getValue());
} catch (NumberFormatException nfe) {
throw new UnexpectedException("Invalid max sequence number found in log " + logName, nfe);
}
// allocation path
Versioned<byte[]> allocationData;
if (ownAllocator) {
allocationData = metadatas.get(MetadataIndex.ALLOCATION);
ensureMetadataExist(allocationData);
} else {
allocationData = new Versioned<byte[]>(null, null);
}
return new LogMetadataForWriter(uri, logName, logIdentifier, maxLSSNData, maxTxnIdData, allocationData);
} catch (IllegalArgumentException iae) {
throw new UnexpectedException("Invalid log " + logName, iae);
} catch (NullPointerException npe) {
throw new UnexpectedException("Invalid log " + logName, npe);
}
}
Aggregations