Search in sources :

Example 1 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class BatchClientImpl method segmentToInfo.

private SegmentInfo segmentToInfo(Segment s) {
    String delegationToken;
    synchronized (this) {
        delegationToken = latestDelegationToken.get();
    }
    @Cleanup SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, delegationToken);
    return client.getSegmentInfo();
}
Also used : Cleanup(lombok.Cleanup) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Example 2 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class ClientFactoryImpl method createRevisionedStreamClient.

@Override
public <T> RevisionedStreamClient<T> createRevisionedStreamClient(String streamName, Serializer<T> serializer, SynchronizerConfig config) {
    log.info("Creating revisioned stream client for stream: {} with synchronizer configuration: {}", streamName, config);
    Segment segment = new Segment(scope, streamName, 0);
    SegmentInputStream in = inFactory.createInputStreamForSegment(segment);
    // Segment sealed is not expected for Revisioned Stream Client.
    Consumer<Segment> segmentSealedCallBack = s -> {
        throw new IllegalStateException("RevisionedClient: Segmentsealed exception observed for segment:" + s);
    };
    String delegationToken = Futures.getAndHandleExceptions(controller.getOrRefreshDelegationTokenFor(segment.getScope(), segment.getStreamName()), RuntimeException::new);
    SegmentOutputStream out = outFactory.createOutputStreamForSegment(segment, segmentSealedCallBack, config.getEventWriterConfig(), delegationToken);
    SegmentMetadataClient meta = metaFactory.createSegmentMetadataClient(segment, delegationToken);
    return new RevisionedStreamClientImpl<>(segment, in, out, meta, serializer, controller, delegationToken);
}
Also used : StateSynchronizer(io.pravega.client.state.StateSynchronizer) Segment(io.pravega.client.segment.impl.Segment) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) Supplier(java.util.function.Supplier) SegmentMetadataClientFactory(io.pravega.client.segment.impl.SegmentMetadataClientFactory) Update(io.pravega.client.state.Update) Stream(io.pravega.client.stream.Stream) RevisionedStreamClient(io.pravega.client.state.RevisionedStreamClient) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) RevisionedStreamClientImpl(io.pravega.client.state.impl.RevisionedStreamClientImpl) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Serializer(io.pravega.client.stream.Serializer) NameUtils(io.pravega.shared.NameUtils) BatchClientImpl(io.pravega.client.batch.impl.BatchClientImpl) SegmentInputStreamFactory(io.pravega.client.segment.impl.SegmentInputStreamFactory) StateSynchronizerImpl(io.pravega.client.state.impl.StateSynchronizerImpl) lombok.val(lombok.val) EventStreamReader(io.pravega.client.stream.EventStreamReader) InitialUpdate(io.pravega.client.state.InitialUpdate) Revisioned(io.pravega.client.state.Revisioned) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) Consumer(java.util.function.Consumer) Slf4j(lombok.extern.slf4j.Slf4j) SegmentInputStream(io.pravega.client.segment.impl.SegmentInputStream) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) UpdateOrInitSerializer(io.pravega.client.state.impl.UpdateOrInitSerializer) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) ClientFactory(io.pravega.client.ClientFactory) BatchClient(io.pravega.client.batch.BatchClient) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) ReaderConfig(io.pravega.client.stream.ReaderConfig) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) SegmentInputStream(io.pravega.client.segment.impl.SegmentInputStream) RevisionedStreamClientImpl(io.pravega.client.state.impl.RevisionedStreamClientImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Example 3 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class EventStreamReaderImpl method handleSegmentTruncated.

private void handleSegmentTruncated(SegmentInputStream segmentReader) throws ReinitializationRequiredException, TruncatedDataException {
    Segment segmentId = segmentReader.getSegmentId();
    log.info("{} encountered truncation for segment {} ", this, segmentId);
    String delegationToken = groupState.getLatestDelegationToken();
    @Cleanup SegmentMetadataClient metadataClient = metadataClientFactory.createSegmentMetadataClient(segmentId, delegationToken);
    try {
        long startingOffset = metadataClient.getSegmentInfo().getStartingOffset();
        segmentReader.setOffset(startingOffset);
    } catch (NoSuchSegmentException e) {
        handleEndOfSegment(segmentReader);
    }
    throw new TruncatedDataException();
}
Also used : TruncatedDataException(io.pravega.client.stream.TruncatedDataException) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) NoSuchSegmentException(io.pravega.client.segment.impl.NoSuchSegmentException)

Example 4 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class ReaderGroupImpl method getRemainingBytes.

private long getRemainingBytes(SegmentMetadataClientFactory metaFactory, StreamCut position) {
    long totalLength = 0;
    CompletableFuture<StreamSegmentSuccessors> unread = controller.getSuccessors(position);
    StreamSegmentSuccessors unreadVal = Futures.getAndHandleExceptions(unread, RuntimeException::new);
    for (Segment s : unreadVal.getSegments()) {
        @Cleanup SegmentMetadataClient metadataClient = metaFactory.createSegmentMetadataClient(s, unreadVal.getDelegationToken());
        totalLength += metadataClient.fetchCurrentSegmentLength();
    }
    for (long bytesRead : position.asImpl().getPositions().values()) {
        totalLength -= bytesRead;
    }
    log.debug("Remaining bytes after position: {} is {}", position, totalLength);
    return totalLength;
}
Also used : Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Example 5 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class StreamCutHelper method segmentToInfos.

private CompletableFuture<List<SegmentInfo>> segmentToInfos(Collection<Segment> segments, DelegationTokenProvider tokenProvider) {
    List<CompletableFuture<SegmentInfo>> results = new ArrayList<>();
    for (Segment s : segments) {
        SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, tokenProvider);
        CompletableFuture<SegmentInfo> info = client.getSegmentInfo();
        results.add(info);
        info.whenComplete((v, e) -> client.close());
    }
    return Futures.allOfWithResults(results);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) SegmentInfo(io.pravega.client.segment.impl.SegmentInfo) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Aggregations

SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)19 Segment (io.pravega.client.segment.impl.Segment)15 Cleanup (lombok.Cleanup)14 Test (org.junit.Test)10 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)7 MockController (io.pravega.client.stream.mock.MockController)6 SegmentMetadataClientFactory (io.pravega.client.segment.impl.SegmentMetadataClientFactory)5 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)5 Controller (io.pravega.client.control.impl.Controller)4 DelegationTokenProvider (io.pravega.client.security.auth.DelegationTokenProvider)4 SegmentInfo (io.pravega.client.segment.impl.SegmentInfo)4 SegmentInputStreamFactory (io.pravega.client.segment.impl.SegmentInputStreamFactory)4 SegmentMetadataClientFactoryImpl (io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl)4 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)4 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)3 EventSegmentReader (io.pravega.client.segment.impl.EventSegmentReader)3 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)3 ClientConfig (io.pravega.client.ClientConfig)2 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)2 ConditionalOutputStream (io.pravega.client.segment.impl.ConditionalOutputStream)2