Search in sources :

Example 11 with WriteHandle

use of org.apache.bookkeeper.client.api.WriteHandle in project herddb by diennea.

the class BookKeeperDataStorageManager method writeToLedger.

private long writeToLedger(String tableSpace, Map<String, byte[]> metadata, final VisibleByteArrayOutputStream buffer) throws InterruptedException, org.apache.bookkeeper.client.api.BKException {
    long ledgerId;
    int expectedReplicaCount = tableSpaceExpectedReplicaCount.getOrDefault(tableSpace, 1);
    int actualEnsembleSize = Math.max(expectedReplicaCount, bk.getEnsemble());
    int actualWriteQuorumSize = Math.max(expectedReplicaCount, bk.getWriteQuorumSize());
    int actualAckQuorumSize = Math.max(expectedReplicaCount, bk.getAckQuorumSize());
    try (WriteHandle result = FutureUtils.result(bk.getBookKeeper().newCreateLedgerOp().withEnsembleSize(actualEnsembleSize).withWriteQuorumSize(actualWriteQuorumSize).withAckQuorumSize(actualAckQuorumSize).withPassword(EMPTY_ARRAY).withDigestType(DigestType.CRC32C).withCustomMetadata(metadata).execute(), BKException.HANDLER)) {
        result.append(buffer.getBuffer(), 0, buffer.size());
        ledgerId = result.getId();
    }
    return ledgerId;
}
Also used : WriteHandle(org.apache.bookkeeper.client.api.WriteHandle)

Aggregations

WriteHandle (org.apache.bookkeeper.client.api.WriteHandle)11 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)3 IOException (java.io.IOException)3 lombok.val (lombok.val)3 HashMap (java.util.HashMap)2 CompletionException (java.util.concurrent.CompletionException)2 Test (org.junit.Test)2 DataStorageManagerException (herddb.storage.DataStorageManagerException)1 VisibleByteArrayOutputStream (herddb.utils.VisibleByteArrayOutputStream)1 ArrayView (io.pravega.common.util.ArrayView)1 DataLogDisabledException (io.pravega.segmentstore.storage.DataLogDisabledException)1 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)1 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 SneakyThrows (lombok.SneakyThrows)1 BKException (org.apache.bookkeeper.client.BKException)1 BookKeeper (org.apache.bookkeeper.client.api.BookKeeper)1 CreateBuilder (org.apache.bookkeeper.client.api.CreateBuilder)1 DigestType (org.apache.bookkeeper.client.api.DigestType)1