use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class TestPByteBufTableImpl method prepareRanges.
private static HashStreamRanges prepareRanges(long streamId, int numRanges, long nextRangeId) {
List<RangeProperties> ranges = ProtoUtils.split(streamId, numRanges, nextRangeId, (sid, rid) -> 1L);
NavigableMap<Long, RangeProperties> rangeMap = Maps.newTreeMap();
for (RangeProperties props : ranges) {
rangeMap.put(props.getStartHashKey(), props);
}
return HashStreamRanges.ofHash(RangeKeyType.HASH, rangeMap);
}
use of org.apache.bookkeeper.stream.proto.RangeProperties in project bookkeeper by apache.
the class MetaRangeImpl method unsafeCreate.
private void unsafeCreate(CompletableFuture<Boolean> createFuture, StreamProperties streamProps) {
// 1. verify the state
checkLifecycleState(LifecycleState.UNINIT);
this.lifecycleState = LifecycleState.CREATING;
// 2. store the props/configuration
synchronized (this) {
this.streamProps = streamProps;
}
this.streamId = streamProps.getStreamId();
this.cTime = this.mTime = System.currentTimeMillis();
// 3. create the ranges
List<RangeProperties> propertiesList = split(streamId, streamProps.getStreamConf().getInitialNumRanges(), nextRangeId, placementPolicy);
List<Op<byte[], byte[]>> successOps = Lists.newArrayListWithExpectedSize(propertiesList.size() + 1);
for (RangeProperties props : propertiesList) {
RangeMetadata meta = RangeMetadata.newBuilder().setProps(props).setCreateTime(cTime).setFenceTime(Long.MAX_VALUE).setState(RangeState.RANGE_ACTIVE).addAllParents(Lists.newArrayList()).build();
ranges.put(props.getRangeId(), meta);
currentRanges.add(props.getRangeId());
successOps.add(store.newPut(getStreamRangeKey(streamId, props.getRangeId()), meta.toByteArray()));
}
nextRangeId += propertiesList.size();
// serialize the stream metadata
byte[] streamMetadataKey = getStreamMetadataKey(streamId);
successOps.add(store.newPut(streamMetadataKey, toStreamMetadata(LifecycleState.CREATED).toByteArray()));
TxnOp<byte[], byte[]> txn = store.newTxn().If(store.newCompareValue(CompareResult.EQUAL, streamMetadataKey, null)).Then(successOps.toArray(new Op[successOps.size()])).build();
if (log.isTraceEnabled()) {
log.trace("Execute create stream metadata range txn {}", streamProps);
}
store.txn(txn).thenApplyAsync(txnResult -> {
try {
if (log.isTraceEnabled()) {
log.trace("Create stream metadata range txn result = {}", txnResult.isSuccess());
}
if (txnResult.isSuccess()) {
List<Result<byte[], byte[]>> results = txnResult.results();
MetaRangeImpl.this.revision = results.get(results.size() - 1).revision();
// mark the state to CREATED
this.lifecycleState = LifecycleState.CREATED;
createFuture.complete(true);
} else {
createFuture.complete(false);
}
return null;
} finally {
txnResult.close();
}
}, executor).exceptionally(cause -> {
createFuture.completeExceptionally(cause);
return null;
});
}
Aggregations