Search in sources :

Example 6 with LogMetadataForWriter

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());
    }
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) CompletableFuture(java.util.concurrent.CompletableFuture) ZKException(org.apache.distributedlog.exceptions.ZKException) Transaction(org.apache.distributedlog.util.Transaction) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Version(org.apache.bookkeeper.versioning.Version) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogMetadataForWriter(org.apache.distributedlog.metadata.LogMetadataForWriter) Test(org.junit.Test)

Example 7 with LogMetadataForWriter

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());
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) CompletableFuture(java.util.concurrent.CompletableFuture) Stat(org.apache.zookeeper.data.Stat) Transaction(org.apache.distributedlog.util.Transaction) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Version(org.apache.bookkeeper.versioning.Version) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogMetadataForWriter(org.apache.distributedlog.metadata.LogMetadataForWriter) Test(org.junit.Test)

Example 8 with LogMetadataForWriter

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);
    }
}
Also used : UnexpectedException(org.apache.distributedlog.exceptions.UnexpectedException) LogMetadataForWriter(org.apache.distributedlog.metadata.LogMetadataForWriter)

Aggregations

LogMetadataForWriter (org.apache.distributedlog.metadata.LogMetadataForWriter)8 LongVersion (org.apache.bookkeeper.versioning.LongVersion)7 Versioned (org.apache.bookkeeper.versioning.Versioned)7 Test (org.junit.Test)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 Transaction (org.apache.distributedlog.util.Transaction)4 URI (java.net.URI)3 Version (org.apache.bookkeeper.versioning.Version)3 ZKException (org.apache.distributedlog.exceptions.ZKException)3 Stat (org.apache.zookeeper.data.Stat)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 UTF_8 (com.google.common.base.Charsets.UTF_8)1 Optional (com.google.common.base.Optional)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1