Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1616,66 +1616,53 @@ protected void handleProducer(final CommandProducer cmdProducer) {
});

schemaVersionFuture.thenAccept(schemaVersion -> {
topic.checkIfTransactionBufferRecoverCompletely(isTxnEnabled).thenAccept(future -> {
CompletionStage<Subscription> createInitSubFuture;
if (!Strings.isNullOrEmpty(initialSubscriptionName)
&& topic.isPersistent()
&& !topic.getSubscriptions().containsKey(initialSubscriptionName)) {
createInitSubFuture = service.isAllowAutoSubscriptionCreationAsync(topicName)
.thenCompose(isAllowAutoSubscriptionCreation -> {
if (!isAllowAutoSubscriptionCreation) {
return CompletableFuture.failedFuture(
new BrokerServiceException.NotAllowedException(
"Could not create the initial subscription due to"
+ " the auto subscription creation is not allowed."));
}
return topic.createSubscription(initialSubscriptionName,
InitialPosition.Earliest, false, null);
});
} else {
createInitSubFuture = CompletableFuture.completedFuture(null);
}

createInitSubFuture.whenComplete((sub, ex) -> {
if (ex != null) {
final Throwable rc = FutureUtil.unwrapCompletionException(ex);
if (rc instanceof BrokerServiceException.NotAllowedException) {
log.warn("[{}] {} initialSubscriptionName: {}, topic: {}",
remoteAddress, rc.getMessage(), initialSubscriptionName, topicName);
if (producerFuture.completeExceptionally(rc)) {
commandSender.sendErrorResponse(requestId,
ServerError.NotAllowedError, rc.getMessage());
CompletionStage<Subscription> createInitSubFuture;
if (!Strings.isNullOrEmpty(initialSubscriptionName)
&& topic.isPersistent()
&& !topic.getSubscriptions().containsKey(initialSubscriptionName)) {
createInitSubFuture = service.isAllowAutoSubscriptionCreationAsync(topicName)
.thenCompose(isAllowAutoSubscriptionCreation -> {
if (!isAllowAutoSubscriptionCreation) {
return CompletableFuture.failedFuture(
new BrokerServiceException.NotAllowedException(
"Could not create the initial subscription due to the "
+ "auto subscription creation is not allowed."));
}
producers.remove(producerId, producerFuture);
return;
}
String msg =
"Failed to create the initial subscription: " + ex.getCause().getMessage();
return topic.createSubscription(initialSubscriptionName,
InitialPosition.Earliest, false, null);
});
} else {
createInitSubFuture = CompletableFuture.completedFuture(null);
}

createInitSubFuture.whenComplete((sub, ex) -> {
if (ex != null) {
final Throwable rc = FutureUtil.unwrapCompletionException(ex);
if (rc instanceof BrokerServiceException.NotAllowedException) {
log.warn("[{}] {} initialSubscriptionName: {}, topic: {}",
remoteAddress, msg, initialSubscriptionName, topicName);
if (producerFuture.completeExceptionally(ex)) {
remoteAddress, rc.getMessage(), initialSubscriptionName, topicName);
if (producerFuture.completeExceptionally(rc)) {
commandSender.sendErrorResponse(requestId,
BrokerServiceException.getClientErrorCode(ex), msg);
ServerError.NotAllowedError, rc.getMessage());
}
producers.remove(producerId, producerFuture);
return;
}
String msg =
"Failed to create the initial subscription: " + ex.getCause().getMessage();
log.warn("[{}] {} initialSubscriptionName: {}, topic: {}",
remoteAddress, msg, initialSubscriptionName, topicName);
if (producerFuture.completeExceptionally(ex)) {
commandSender.sendErrorResponse(requestId,
BrokerServiceException.getClientErrorCode(ex), msg);
}
producers.remove(producerId, producerFuture);
return;
}

buildProducerAndAddTopic(topic, producerId, producerName, requestId, isEncrypted,
buildProducerAndAddTopic(topic, producerId, producerName, requestId, isEncrypted,
metadata, schemaVersion, epoch, userProvidedProducerName, topicName,
producerAccessMode, topicEpoch, supportsPartialProducer, producerFuture);
});
}).exceptionally(exception -> {
Throwable cause = exception.getCause();
log.error("producerId {}, requestId {} : TransactionBuffer recover failed",
producerId, requestId, exception);
if (producerFuture.completeExceptionally(exception)) {
commandSender.sendErrorResponse(requestId,
ServiceUnitNotReadyException.getClientErrorCode(cause),
cause.getMessage());
}
producers.remove(producerId, producerFuture);
return null;
});
});
});
Expand Down Expand Up @@ -2249,7 +2236,7 @@ protected void handleGetLastMessageId(CommandGetLastMessageId getLastMessageId)
long requestId = getLastMessageId.getRequestId();

Topic topic = consumer.getSubscription().getTopic();
topic.checkIfTransactionBufferRecoverCompletely(true)
topic.checkIfTransactionBufferRecoverCompletely()
.thenCompose(__ -> topic.getLastDispatchablePosition())
.thenApply(lastPosition -> {
int partitionIndex = TopicName.getPartitionIndex(topic.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,11 @@ default void setEntryTimestamp(long entryTimestamp) {
void removeProducer(Producer producer);

/**
* Wait TransactionBuffer Recovers completely.
* Take snapshot after TB Recovers completely.
* @param isTxnEnabled isTxnEnabled
* @return a future which has completely if isTxn = false. Or a future return by takeSnapshot.
* Wait TransactionBuffer recovers completely.
*
* @return a future that will be completed after the transaction buffer recover completely.
*/
CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely(boolean isTxnEnabled);
CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely();

/**
* record add-latency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public boolean isReplicationBacklogExist() {
}

@Override
public CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely(boolean isTxnEnabled) {
public CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely() {
return CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,8 @@ public CompletableFuture<Optional<Long>> addProducer(Producer producer,
}

@Override
public CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely(boolean isTxnEnabled) {
return getTransactionBuffer().checkIfTBRecoverCompletely(isTxnEnabled);
public CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely() {
return getTransactionBuffer().checkIfTBRecoverCompletely();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,11 @@ public interface TransactionBuffer {
TransactionBufferStats getStats(boolean lowWaterMarks);

/**
* Wait TransactionBuffer Recovers completely.
* Take snapshot after TB Recovers completely.
* @param isTxn
* @return a future which has completely if isTxn = false. Or a future return by takeSnapshot.
* Wait TransactionBuffer recovers completely.
*
* @return a future that will be completed after the transaction buffer recover completely.
*/
CompletableFuture<Void> checkIfTBRecoverCompletely(boolean isTxn);


CompletableFuture<Void> checkIfTBRecoverCompletely();

long getOngoingTxnCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public TransactionBufferStats getStats(boolean lowWaterMarks) {


@Override
public CompletableFuture<Void> checkIfTBRecoverCompletely(boolean isTxn) {
public CompletableFuture<Void> checkIfTBRecoverCompletely() {
return CompletableFuture.completedFuture(null);
}

Expand Down
Loading