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

[CHANGED] Ordered consumer recreate on missing heartbeat #1097

Merged
merged 3 commits into from
Oct 4, 2022

Conversation

piotrpio
Copy link
Collaborator

@piotrpio piotrpio commented Oct 3, 2022

Addresses: nats-io/nats-architecture-and-design#162
Resolves: #1094

This PR changes:

  • Ordered consumer will now be recreated on missing heartbeats (failed activity check)
  • Timeout or no responders on resetting ordered consumer is no longer considered terminal error - operation will be retried on subsequent failed heartbeat checks

@piotrpio piotrpio requested a review from kozlovic October 3, 2022 16:21
@coveralls
Copy link

coveralls commented Oct 3, 2022

Coverage Status

Coverage increased (+0.1%) to 86.143% when pulling e090573 on ordered-consumer-create into 36d2b65 on main.

js_test.go Outdated
@@ -292,7 +293,7 @@ func TestJetStreamOrderedConsumer(t *testing.T) {
testSyncConsumer()
}

func TestJetStreamOrderedConsumerWithErrors(t *testing.T) {
func TestOrderedConsumerDeleteAssets(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to maintain TestJetStream prefix so that if you want to quickly check that your JS changes are having an impact, you can limit the tests locally to run JetStream tests...

test/js_test.go Outdated
@@ -8126,3 +8145,59 @@ func TestJetStreamMsgAckShouldErrForConsumerAckNone(t *testing.T) {
t.Fatalf("Expected error indicating that sub is AckNone, got %v", err)
}
}

func TestOrderedConsumerRecreateAfterReconnect(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment than before.

js.go Outdated
}
pushErr(err)
pushErr(fmt.Errorf("%w: recreating ordered consumer", err))
Copy link
Member

Choose a reason for hiding this comment

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

What is the %w doing? Also, since you seem to have this fmt.Errorf() almost every time you call pushErr(), should you have that part of pushErr() itself? (I know there is a check/pushErr in case of request marshaling failing, but that is very unlikely, and still it would be a failure recreating the ordered consumer anyway).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

%w is the error wrapping semantic. Thanks to it, if you call e.g. errors.Is(err, ErrStreamNotFound) on this error it will unwrap correctly and return true for fmt.Errorf("%w: recreating ordered consumer", ErrStreamNotFound).

As to your second point, you're right, I'll change it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Additionally, I added the recreating ordered consumer part to at least give some insight to the user as to where an error happened (async error callback does not give any information on where the error comes from, so this is better than nothing).
In the near future I'll be working on the async errors revamp (at least for ordered consumers) to be able to identify them and react more easily)

@piotrpio piotrpio requested a review from kozlovic October 3, 2022 16:59
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM

@piotrpio piotrpio merged commit 1ee76ea into main Oct 4, 2022
@piotrpio piotrpio deleted the ordered-consumer-create branch October 4, 2022 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jetstream KV watcher does not watch after NATS server restart
3 participants