Search in sources :

Example 1 with Subscription

use of org.apache.pulsar.common.api.proto.Subscription in project pulsar by apache.

the class TransactionCoordinatorClientImpl method addSubscriptionToTxnAsync.

@Override
public CompletableFuture<Void> addSubscriptionToTxnAsync(TxnID txnID, String topic, String subscription) {
    TransactionMetaStoreHandler handler = handlerMap.get(txnID.getMostSigBits());
    if (handler == null) {
        return FutureUtil.failedFuture(new TransactionCoordinatorClientException.MetaStoreHandlerNotExistsException(txnID.getMostSigBits()));
    }
    Subscription sub = new Subscription().setTopic(topic).setSubscription(subscription);
    return handler.addSubscriptionToTxn(txnID, Collections.singletonList(sub));
}
Also used : TransactionMetaStoreHandler(org.apache.pulsar.client.impl.TransactionMetaStoreHandler) TransactionCoordinatorClientException(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException) Subscription(org.apache.pulsar.common.api.proto.Subscription)

Example 2 with Subscription

use of org.apache.pulsar.common.api.proto.Subscription in project pulsar by apache.

the class MLTransactionMetadataStore method subscriptionToTxnSubscription.

public static List<TransactionSubscription> subscriptionToTxnSubscription(List<Subscription> subscriptions) {
    List<TransactionSubscription> transactionSubscriptions = new ArrayList<>(subscriptions.size());
    for (Subscription subscription : subscriptions) {
        TransactionSubscription.TransactionSubscriptionBuilder transactionSubscriptionBuilder = TransactionSubscription.builder();
        transactionSubscriptionBuilder.subscription(subscription.getSubscription());
        transactionSubscriptionBuilder.topic(subscription.getTopic());
        transactionSubscriptions.add(transactionSubscriptionBuilder.build());
    }
    return transactionSubscriptions;
}
Also used : TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) ArrayList(java.util.ArrayList) TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) Subscription(org.apache.pulsar.common.api.proto.Subscription)

Example 3 with Subscription

use of org.apache.pulsar.common.api.proto.Subscription in project pulsar by yahoo.

the class MLTransactionMetadataStore method addAckedPartitionToTxn.

@Override
public CompletableFuture<Void> addAckedPartitionToTxn(TxnID txnID, List<TransactionSubscription> txnSubscriptions) {
    CompletableFuture<Void> promise = new CompletableFuture<>();
    internalPinnedExecutor.execute(() -> {
        if (!checkIfReady()) {
            promise.completeExceptionally(new CoordinatorException.TransactionMetadataStoreStateException(tcID, State.Ready, getState(), "add acked partition"));
            return;
        }
        getTxnPositionPair(txnID).thenCompose(txnMetaListPair -> {
            TransactionMetadataEntry transactionMetadataEntry = new TransactionMetadataEntry().setTxnidMostBits(txnID.getMostSigBits()).setTxnidLeastBits(txnID.getLeastSigBits()).setMetadataOp(TransactionMetadataOp.ADD_SUBSCRIPTION).addAllSubscriptions(txnSubscriptionToSubscription(txnSubscriptions)).setLastModificationTime(System.currentTimeMillis()).setMaxLocalTxnId(sequenceIdGenerator.getCurrentSequenceId());
            return transactionLog.append(transactionMetadataEntry).thenAccept(position -> {
                appendLogCount.increment();
                try {
                    synchronized (txnMetaListPair.getLeft()) {
                        txnMetaListPair.getLeft().addAckedPartitions(txnSubscriptions);
                        txnMetaMap.get(txnID.getLeastSigBits()).getRight().add(position);
                    }
                    promise.complete(null);
                } catch (InvalidTxnStatusException e) {
                    transactionLog.deletePosition(Collections.singletonList(position));
                    log.error("TxnID : " + txnMetaListPair.getLeft().id().toString() + " add acked subscription error with TxnStatus : " + txnMetaListPair.getLeft().status().name(), e);
                    promise.completeExceptionally(e);
                }
            });
        }).exceptionally(ex -> {
            promise.completeExceptionally(ex);
            return null;
        });
    });
    return promise;
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TransactionMetadataStore(org.apache.pulsar.transaction.coordinator.TransactionMetadataStore) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) TransactionLogReplayCallback(org.apache.pulsar.transaction.coordinator.TransactionLogReplayCallback) TransactionCoordinatorStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorStats) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) ArrayList(java.util.ArrayList) TransactionTimeoutTracker(org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker) TxnID(org.apache.pulsar.client.api.transaction.TxnID) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CoordinatorException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException) TransactionMetadataEntry(org.apache.pulsar.transaction.coordinator.proto.TransactionMetadataEntry) Duration(java.time.Duration) TransactionRecoverTracker(org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker) NoSuchElementException(java.util.NoSuchElementException) Subscription(org.apache.pulsar.common.api.proto.Subscription) ExecutorService(java.util.concurrent.ExecutorService) TransactionMetadataOp(org.apache.pulsar.transaction.coordinator.proto.TransactionMetadataEntry.TransactionMetadataOp) Logger(org.slf4j.Logger) Position(org.apache.bookkeeper.mledger.Position) TransactionMetadataStoreState(org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState) Executors(java.util.concurrent.Executors) TransactionNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException) TxnMeta(org.apache.pulsar.transaction.coordinator.TxnMeta) List(java.util.List) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) FutureUtil(org.apache.pulsar.common.util.FutureUtil) InvalidTxnStatusException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.InvalidTxnStatusException) TxnStatus(org.apache.pulsar.transaction.coordinator.proto.TxnStatus) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) Collections(java.util.Collections) CompletableFuture(java.util.concurrent.CompletableFuture) InvalidTxnStatusException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.InvalidTxnStatusException) CoordinatorException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException) TransactionMetadataEntry(org.apache.pulsar.transaction.coordinator.proto.TransactionMetadataEntry)

Example 4 with Subscription

use of org.apache.pulsar.common.api.proto.Subscription in project pulsar by yahoo.

the class MLTransactionMetadataStore method txnSubscriptionToSubscription.

public static List<Subscription> txnSubscriptionToSubscription(List<TransactionSubscription> tnxSubscriptions) {
    List<Subscription> subscriptions = new ArrayList<>(tnxSubscriptions.size());
    for (TransactionSubscription transactionSubscription : tnxSubscriptions) {
        Subscription subscription = new Subscription().setSubscription(transactionSubscription.getSubscription()).setTopic(transactionSubscription.getTopic());
        subscriptions.add(subscription);
    }
    return subscriptions;
}
Also used : ArrayList(java.util.ArrayList) TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) Subscription(org.apache.pulsar.common.api.proto.Subscription)

Example 5 with Subscription

use of org.apache.pulsar.common.api.proto.Subscription in project pulsar by yahoo.

the class MLTransactionMetadataStore method subscriptionToTxnSubscription.

public static List<TransactionSubscription> subscriptionToTxnSubscription(List<Subscription> subscriptions) {
    List<TransactionSubscription> transactionSubscriptions = new ArrayList<>(subscriptions.size());
    for (Subscription subscription : subscriptions) {
        TransactionSubscription.TransactionSubscriptionBuilder transactionSubscriptionBuilder = TransactionSubscription.builder();
        transactionSubscriptionBuilder.subscription(subscription.getSubscription());
        transactionSubscriptionBuilder.topic(subscription.getTopic());
        transactionSubscriptions.add(transactionSubscriptionBuilder.build());
    }
    return transactionSubscriptions;
}
Also used : TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) ArrayList(java.util.ArrayList) TransactionSubscription(org.apache.pulsar.transaction.coordinator.TransactionSubscription) Subscription(org.apache.pulsar.common.api.proto.Subscription)

Aggregations

Subscription (org.apache.pulsar.common.api.proto.Subscription)11 ArrayList (java.util.ArrayList)8 TransactionSubscription (org.apache.pulsar.transaction.coordinator.TransactionSubscription)8 TransactionCoordinatorClientException (org.apache.pulsar.client.api.transaction.TransactionCoordinatorClientException)3 TransactionMetaStoreHandler (org.apache.pulsar.client.impl.TransactionMetaStoreHandler)3 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)2 Duration (java.time.Duration)2 Collections (java.util.Collections)2 List (java.util.List)2 NoSuchElementException (java.util.NoSuchElementException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)2 Position (org.apache.bookkeeper.mledger.Position)2 MutablePair (org.apache.commons.lang3.tuple.MutablePair)2 Pair (org.apache.commons.lang3.tuple.Pair)2