Search in sources :

Example 1 with DATA_NOT_FOUND_PREDICATE

use of io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE in project pravega by pravega.

the class PersistentStreamBase method generateMarksForTransactions.

/**
 * This method takes the list of transactions in the committing transactions record, and tries to report marks
 * for writers for these transactions, if the information about writer is present in the record. The information
 * about writer and commit time is optionally provided by the client. A client not interested in watermarking may not
 * report writer id and time during commit request. Similarly older clients will not report writer id and time either.
 * WriterId, commit time and commit offsets are recorded in ActiveTxnRecord for each transaction.
 * For transactions where above fields are present, a mark is recorded for them.
 * This method will ignore any INVALID_TIME or INVALID_POSITION related failures in noting marks for writers.
 * This is because those will typically arise from idempotent commit case where this and a transaction with higher
 * position and time may already have been committed and the overall mark for the writer may already have progressed.
 *
 * @return A completableFuture, which when completed will have marks reported for all transactions in the committing
 * transaction record for which a writer with time and position information is available.
 */
CompletableFuture<Void> generateMarksForTransactions(OperationContext context, Map<String, TxnWriterMark> writerMarks) {
    Preconditions.checkNotNull(context, "Operation context cannot be null");
    Preconditions.checkArgument(writerMarks != null);
    // For each writerId we will take the transaction with the time and position pair (which is to take
    // max of all transactions for the said writer).
    // Note: if multiple transactions from same writer have same time, we will take any one arbitrarily and
    // use its position for watermarks. Other positions and times would be ignored.
    val noteTimeFutures = writerMarks.entrySet().stream().map(x -> Futures.exceptionallyExpecting(noteWriterMark(x.getKey(), x.getValue().getTimestamp(), x.getValue().getPosition(), context), DATA_NOT_FOUND_PREDICATE, null)).collect(Collectors.toList());
    return Futures.allOf(noteTimeFutures);
}
Also used : lombok.val(lombok.val) StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) SneakyThrows(lombok.SneakyThrows) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) TagLogger(io.pravega.common.tracing.TagLogger) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataNotFoundException(io.pravega.controller.store.stream.StoreException.DataNotFoundException) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) ImmutableSet(com.google.common.collect.ImmutableSet) StreamCutReferenceRecord(io.pravega.controller.store.stream.records.StreamCutReferenceRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) IntStream(java.util.stream.IntStream) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) NameUtils.computeSegmentId(io.pravega.shared.NameUtils.computeSegmentId) Exceptions(io.pravega.common.Exceptions) HistoryTimeSeriesRecord(io.pravega.controller.store.stream.records.HistoryTimeSeriesRecord) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) DATA_NOT_FOUND_PREDICATE(io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StateRecord(io.pravega.controller.store.stream.records.StateRecord) StreamSubscriber(io.pravega.controller.store.stream.records.StreamSubscriber) LinkedList(java.util.LinkedList) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) SimpleEntry(java.util.AbstractMap.SimpleEntry) LongSummaryStatistics(java.util.LongSummaryStatistics) CollectionHelpers(io.pravega.common.util.CollectionHelpers) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) WriterMark(io.pravega.controller.store.stream.records.WriterMark) lombok.val(lombok.val) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Version(io.pravega.controller.store.Version) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections)

Example 2 with DATA_NOT_FOUND_PREDICATE

use of io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE in project pravega by pravega.

the class PersistentStreamBase method noteWriterMark.

@Override
public CompletableFuture<WriterTimestampResponse> noteWriterMark(String writer, long timestamp, Map<Long, Long> position, OperationContext context) {
    Preconditions.checkNotNull(context, "operation context cannot be null");
    // Remember: a writer position is not a stream cut.
    // For sanity check we will check that the request advances the time and position.
    // if time is not advanced --> respond with invalid time.
    // if position is not advanced --> respond with invalid position
    ImmutableMap<Long, Long> newPosition = ImmutableMap.copyOf(position);
    return Futures.exceptionallyExpecting(getWriterMarkRecord(writer, context), DATA_NOT_FOUND_PREDICATE, null).thenCompose(record -> {
        if (record == null) {
            // we will translate it to writeConflict and let the caller deal with it.
            return createWriterMarkRecord(writer, timestamp, newPosition, context).exceptionally(e -> {
                if (Exceptions.unwrap(e) instanceof StoreException.DataExistsException) {
                    throw StoreException.create(StoreException.Type.WRITE_CONFLICT, "writer mark exists");
                }
                throw new CompletionException(e);
            }).thenApply(v -> WriterTimestampResponse.SUCCESS);
        } else {
            // sanity check and update
            if (record.getObject().getTimestamp() > timestamp) {
                // existing time is already ahead of new time
                return CompletableFuture.completedFuture(WriterTimestampResponse.INVALID_TIME);
            }
            if (!compareWriterPositions(record.getObject().getPosition(), newPosition)) {
                // existing position is already ahead of new position
                return CompletableFuture.completedFuture(WriterTimestampResponse.INVALID_POSITION);
            }
            // its a valid mark, update it
            return updateWriterMarkRecord(writer, timestamp, newPosition, true, record.getVersion(), context).thenApply(v -> WriterTimestampResponse.SUCCESS);
        }
    });
}
Also used : StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) SneakyThrows(lombok.SneakyThrows) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) TagLogger(io.pravega.common.tracing.TagLogger) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataNotFoundException(io.pravega.controller.store.stream.StoreException.DataNotFoundException) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) ImmutableSet(com.google.common.collect.ImmutableSet) StreamCutReferenceRecord(io.pravega.controller.store.stream.records.StreamCutReferenceRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) IntStream(java.util.stream.IntStream) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) NameUtils.computeSegmentId(io.pravega.shared.NameUtils.computeSegmentId) Exceptions(io.pravega.common.Exceptions) HistoryTimeSeriesRecord(io.pravega.controller.store.stream.records.HistoryTimeSeriesRecord) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) DATA_NOT_FOUND_PREDICATE(io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StateRecord(io.pravega.controller.store.stream.records.StateRecord) StreamSubscriber(io.pravega.controller.store.stream.records.StreamSubscriber) LinkedList(java.util.LinkedList) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) SimpleEntry(java.util.AbstractMap.SimpleEntry) LongSummaryStatistics(java.util.LongSummaryStatistics) CollectionHelpers(io.pravega.common.util.CollectionHelpers) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) WriterMark(io.pravega.controller.store.stream.records.WriterMark) lombok.val(lombok.val) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Version(io.pravega.controller.store.Version) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) CompletionException(java.util.concurrent.CompletionException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Exceptions (io.pravega.common.Exceptions)2 Futures (io.pravega.common.concurrent.Futures)2 TagLogger (io.pravega.common.tracing.TagLogger)2 CollectionHelpers (io.pravega.common.util.CollectionHelpers)2 Version (io.pravega.controller.store.Version)2 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)2 DATA_NOT_FOUND_PREDICATE (io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE)2 DataNotFoundException (io.pravega.controller.store.stream.StoreException.DataNotFoundException)2 ActiveTxnRecord (io.pravega.controller.store.stream.records.ActiveTxnRecord)2 CommittingTransactionsRecord (io.pravega.controller.store.stream.records.CommittingTransactionsRecord)2 CompletedTxnRecord (io.pravega.controller.store.stream.records.CompletedTxnRecord)2 EpochRecord (io.pravega.controller.store.stream.records.EpochRecord)2 EpochTransitionRecord (io.pravega.controller.store.stream.records.EpochTransitionRecord)2