use of org.apache.bookkeeper.stream.proto.RangeMetadata in project bookkeeper by apache.
the class MetaRangeStoreImplTest method verifyGetResponse.
private void verifyGetResponse(GetActiveRangesResponse getResp) throws Exception {
MetaRangeImpl metaRange = new MetaRangeImpl(this.store, this.scheduler.chooseThread(), StorageContainerPlacementPolicyImpl.of(1024));
assertNotNull(FutureUtils.result(metaRange.load(streamProps.getStreamId())));
verifyStreamMetadata(metaRange, streamProps);
List<RelatedRanges> rangesList = getResp.getRangesList();
List<Long> currentRanges = metaRange.unsafeGetCurrentRanges();
assertEquals(currentRanges.size(), rangesList.size());
for (int i = 0; i < rangesList.size(); i++) {
RelatedRanges actualRR = rangesList.get(i);
long expectedRid = currentRanges.get(i);
RangeMetadata expectedRangeMetadata = metaRange.unsafeGetRanges().get(expectedRid);
assertNotNull(expectedRangeMetadata);
assertEquals(Collections.emptyList(), actualRR.getRelatedRangesList());
assertEquals(expectedRangeMetadata.getProps(), actualRR.getProps());
}
}
use of org.apache.bookkeeper.stream.proto.RangeMetadata in project bookkeeper by apache.
the class MetaRangeImpl method loadRangeMetadata.
private void loadRangeMetadata(long streamId, long rangeId, byte[] rangeMetadataBytes) {
checkArgument(this.streamId == streamId);
checkArgument(rangeId >= 0L);
RangeMetadata metadata;
try {
metadata = RangeMetadata.parseFrom(rangeMetadataBytes);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Invalid range metadata of range (" + streamId + ", " + rangeId + ")", e);
}
this.ranges.put(rangeId, metadata);
}
use of org.apache.bookkeeper.stream.proto.RangeMetadata in project bookkeeper by apache.
the class MetaRangeStoreImplTest method verifyStreamMetadata.
private void verifyStreamMetadata(MetaRangeImpl metaRange, StreamProperties streamProps) throws Exception {
// verify the stream properties
assertEquals(LifecycleState.CREATED, metaRange.unsafeGetLifecycleState());
assertEquals(name.getMethodName() + "_stream", metaRange.getName());
long cTime = metaRange.unsafeGetCreationTime();
assertEquals(streamProps, metaRange.unsafeGetStreamProperties());
assertEquals(streamProps.getStreamId(), metaRange.unsafeGetStreamId());
assertEquals(ServingState.WRITABLE, FutureUtils.result(metaRange.getServingState()));
assertEquals(streamProps.getStreamConf(), FutureUtils.result(metaRange.getConfiguration()));
// verify the stream ranges
List<Long> activeRanges = Lists.transform(FutureUtils.result(metaRange.getActiveRanges()), (metadata) -> metadata.getProps().getRangeId());
assertEquals(streamProps.getStreamConf().getInitialNumRanges(), activeRanges.size());
assertEquals(Lists.newArrayList(LongStream.range(1024L, 1024L + activeRanges.size()).iterator()), activeRanges);
NavigableMap<Long, RangeMetadata> ranges = metaRange.unsafeGetRanges();
long startKey = Long.MIN_VALUE;
long rangeSize = Long.MAX_VALUE / (activeRanges.size() / 2);
for (int idx = 0; idx < activeRanges.size(); ++idx) {
long rid = activeRanges.get(idx);
RangeMetadata rangeMetadata = ranges.get(rid);
long endKey = startKey + rangeSize;
if (idx == activeRanges.size() - 1) {
endKey = Long.MAX_VALUE;
}
verifyRangeMetadata(rangeMetadata, startKey, endKey, rid, cTime, Long.MAX_VALUE, RangeState.RANGE_ACTIVE);
readRangeMetadataAndVerify(streamProps.getStreamId(), rid, startKey, endKey, rid, cTime, Long.MAX_VALUE, RangeState.RANGE_ACTIVE);
startKey = endKey;
}
}
use of org.apache.bookkeeper.stream.proto.RangeMetadata in project bookkeeper by apache.
the class MetaRangeStoreImplTest method readRangeMetadataAndVerify.
private void readRangeMetadataAndVerify(long streamId, long rangeId, long expectedStartKey, long expectedEndKey, long expectedRid, long expectedCTime, long expectedFenceTime, RangeState expectedRangeState) throws Exception {
byte[] rangeKey = MetaRangeImpl.getStreamRangeKey(streamId, rangeId);
byte[] rangeMetadataBytes = FutureUtils.result(store.get(rangeKey));
RangeMetadata rangeMetadata = RangeMetadata.parseFrom(rangeMetadataBytes);
verifyRangeMetadata(rangeMetadata, expectedStartKey, expectedEndKey, expectedRid, expectedCTime, expectedFenceTime, expectedRangeState);
}
use of org.apache.bookkeeper.stream.proto.RangeMetadata in project bookkeeper by apache.
the class TestMetaRangeImpl method verifyStreamMetadata.
private void verifyStreamMetadata(MetaRangeImpl metaRange, StreamProperties streamProps) throws Exception {
// verify the stream properties
assertEquals(LifecycleState.CREATED, metaRange.unsafeGetLifecycleState());
assertEquals(name.getMethodName() + "_stream", this.metaRange.getName());
long cTime = metaRange.unsafeGetCreationTime();
assertTrue(metaRange.unsafeGetCreationTime() == this.metaRange.unsafeGetModificationTime());
assertEquals(streamProps, metaRange.unsafeGetStreamProperties());
assertEquals(streamProps.getStreamId(), metaRange.unsafeGetStreamId());
assertEquals(ServingState.WRITABLE, FutureUtils.result(metaRange.getServingState()));
assertEquals(streamProps.getStreamConf(), FutureUtils.result(metaRange.getConfiguration()));
// verify the stream ranges
List<Long> activeRanges = Lists.transform(FutureUtils.result(metaRange.getActiveRanges()), (metadata) -> metadata.getProps().getRangeId());
assertEquals(streamProps.getStreamConf().getInitialNumRanges(), activeRanges.size());
assertEquals(Lists.newArrayList(LongStream.range(1024L, 1024L + activeRanges.size()).iterator()), activeRanges);
NavigableMap<Long, RangeMetadata> ranges = metaRange.unsafeGetRanges();
long startKey = Long.MIN_VALUE;
long rangeSize = Long.MAX_VALUE / (activeRanges.size() / 2);
for (int idx = 0; idx < activeRanges.size(); ++idx) {
long rid = activeRanges.get(idx);
RangeMetadata rangeMetadata = ranges.get(rid);
long endKey = startKey + rangeSize;
if (idx == activeRanges.size() - 1) {
endKey = Long.MAX_VALUE;
}
verifyRangeMetadata(rangeMetadata, startKey, endKey, rid, cTime, Long.MAX_VALUE, RangeState.RANGE_ACTIVE);
readRangeMetadataAndVerify(streamProps.getStreamId(), rid, startKey, endKey, rid, cTime, Long.MAX_VALUE, RangeState.RANGE_ACTIVE);
startKey = endKey;
}
}
Aggregations