Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return correct error code on create-producer/consumer is not complete yet #177

Merged
merged 1 commit into from
Jan 30, 2017

Conversation

rdhabalia
Copy link
Contributor

Motivation

When broker receives multiple create_producer request with same producer-id before it completes producer-creation, it returns UnknownError which misleads client while retrying the request.

Modifications

if client times out before broker successfully creates producer and if client retries to create producer then broker should return ServiceNotReady instead UnknownError (if broker is still creating the producer) so, client can again retry on this recoverable error.

Result

Broker returns ServiceNotReady error if it producer/consumer creation is not complete so, client can retry on this known error-code.

@rdhabalia rdhabalia added the type/bug The PR fixed a bug or issue reported a bug label Jan 28, 2017
@rdhabalia rdhabalia added this to the 1.17 milestone Jan 28, 2017
@rdhabalia rdhabalia self-assigned this Jan 28, 2017
@merlimat
Copy link
Contributor

Looks good, nice catch! Can you also verify the return code in the mocked unit test for the producer/subscribe timeout? Also, probably this should go on 1.16 release, right?

@@ -270,7 +270,8 @@ protected void handleSubscribe(final CommandSubscribe subscribe) {
// creation request either complete or fails.
log.warn("[{}][{}][{}] Consumer is already present on the connection", remoteAddress, topicName,
subscriptionName);
ctx.writeAndFlush(Commands.newError(requestId, ServerError.UnknownError,
ServerError error = !existingConsumerFuture.isDone() ? ServerError.ServiceNotReady : ServerError.UnknownError;
ctx.writeAndFlush(Commands.newError(requestId, error,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is not not to return unknown error to client. Isn't it consumer already exists scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if request is already in process then now, we are returning ServiceNotReady error instead unknown-error.

if consumer times-out before broker completes the request and if broker receives duplicate request while it is still processing the request then it was returning unknown error which was preventing client to retry again.
however, now, broker is returning ServiceNotReady error which is retriable error and client can retry later on and reconnect again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess @saandrews point is that there is still one case in which broker can return UnknownError. Though, after this fix, I think it shouldn't be possible to happen, barring any logical bug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in case of failure of existingProducerFuture, we are returning Unknown error code. In this case, should we return error-message of the exception with unknown error-code?

log.warn("[{}][{}] Producer is already present on the connection", remoteAddress, topicName);
ctx.writeAndFlush(Commands.newError(requestId, ServerError.UnknownError,
ctx.writeAndFlush(Commands.newError(requestId, error,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Producer already present error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is: producer-creation is still in process usecase. therefore, returning ServiceNotReady is a retriable error at client side and it can be reconnected later on.

@rdhabalia
Copy link
Contributor Author

@merlimat added the testcases for this error-code scenario.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

private <T> ServerError getErrorCode(CompletableFuture<T> future) {
ServerError error = ServerError.UnknownError;
try {
future.get(0, TimeUnit.MILLISECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use future.getNow(null) here

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rdhabalia rdhabalia merged commit de2a611 into apache:master Jan 30, 2017
@rdhabalia rdhabalia deleted the unknown branch June 21, 2017 18:55
sijie pushed a commit to sijie/pulsar that referenced this pull request Mar 4, 2018
* Move SimpleSerDe to api

* Renamed SimpleSerDe to DefaultSerDe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants