Search in sources :

Example 1 with RangeMetadata

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());
    }
}
Also used : MetaRangeImpl(org.apache.bookkeeper.stream.storage.impl.metadata.stream.MetaRangeImpl) RelatedRanges(org.apache.bookkeeper.stream.proto.storage.RelatedRanges) RangeMetadata(org.apache.bookkeeper.stream.proto.RangeMetadata)

Example 2 with RangeMetadata

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);
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RangeMetadata(org.apache.bookkeeper.stream.proto.RangeMetadata)

Example 3 with RangeMetadata

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;
    }
}
Also used : RangeMetadata(org.apache.bookkeeper.stream.proto.RangeMetadata)

Example 4 with RangeMetadata

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);
}
Also used : RangeMetadata(org.apache.bookkeeper.stream.proto.RangeMetadata)

Example 5 with RangeMetadata

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;
    }
}
Also used : RangeMetadata(org.apache.bookkeeper.stream.proto.RangeMetadata)

Aggregations

RangeMetadata (org.apache.bookkeeper.stream.proto.RangeMetadata)7 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 List (java.util.List)1 NavigableMap (java.util.NavigableMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 GuardedBy (javax.annotation.concurrent.GuardedBy)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CompareResult (org.apache.bookkeeper.api.kv.op.CompareResult)1 Op (org.apache.bookkeeper.api.kv.op.Op)1 TxnOp (org.apache.bookkeeper.api.kv.op.TxnOp)1 KeyValue (org.apache.bookkeeper.api.kv.result.KeyValue)1