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));
}
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;
}
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;
}
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;
}
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;
}
Aggregations