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;
}
Aggregations