Search in sources :

Example 1 with MetaRangeImpl

use of org.apache.bookkeeper.stream.storage.impl.metadata.stream.MetaRangeImpl 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 MetaRangeImpl

use of org.apache.bookkeeper.stream.storage.impl.metadata.stream.MetaRangeImpl in project bookkeeper by apache.

the class MetaRangeStoreImpl method getActiveRanges.

@Override
public CompletableFuture<StorageContainerResponse> getActiveRanges(StorageContainerRequest request) {
    checkState(GET_ACTIVE_RANGES_REQ == request.getRequestCase(), "Wrong request type: %s", request.getRequestCase());
    final long streamId = request.getGetActiveRangesReq().getStreamId();
    MetaRangeImpl metaRange = streams.get(streamId);
    if (null == metaRange) {
        final MetaRangeImpl metaRangeImpl = new MetaRangeImpl(store, executor, rangePlacementPolicy);
        return metaRangeImpl.load(streamId).thenCompose(mr -> {
            if (null == mr) {
                StreamProperties streamProps = request.getGetActiveRangesReq().hasStreamProps() ? request.getGetActiveRangesReq().getStreamProps() : null;
                return createStreamIfMissing(streamId, metaRangeImpl, streamProps);
            } else {
                synchronized (streams) {
                    streams.put(streamId, (MetaRangeImpl) mr);
                }
                return getActiveRanges(mr);
            }
        });
    } else {
        return getActiveRanges(metaRange);
    }
}
Also used : StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) MetaRangeImpl(org.apache.bookkeeper.stream.storage.impl.metadata.stream.MetaRangeImpl)

Aggregations

MetaRangeImpl (org.apache.bookkeeper.stream.storage.impl.metadata.stream.MetaRangeImpl)2 RangeMetadata (org.apache.bookkeeper.stream.proto.RangeMetadata)1 StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)1 RelatedRanges (org.apache.bookkeeper.stream.proto.storage.RelatedRanges)1