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

[PIP-51] Introduce sticky consumer #5388

Merged
merged 8 commits into from
Nov 8, 2019

Conversation

codelipenghui
Copy link
Contributor

@codelipenghui codelipenghui commented Oct 15, 2019

Motivation

Introduce sticky consumer, users can enable it by

client.newConsumer()
         .keySharedPolicy(KeySharedPolicy.sticky().ranges(Range.of(0, 10)))
         .subscribe();

Modifications

Add a new consumer selector named HashRangeExclusiveStickyKeyConsumerSelector to support sticky consumer.

This change added tests and can be verified as follows:

Add new unit tests.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (yes)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (yes)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

  • Does this pull request introduce a new feature? (yes)

@codelipenghui codelipenghui self-assigned this Oct 15, 2019
@codelipenghui codelipenghui added this to the 2.5.0 milestone Oct 15, 2019
@codelipenghui
Copy link
Contributor Author

run java8 tests
run Integration Tests

1 similar comment
@codelipenghui
Copy link
Contributor Author

run java8 tests
run Integration Tests

@aahmed-se
Copy link
Contributor

run java8 tests
run integration tests.

@codelipenghui
Copy link
Contributor Author

retest this please

2 similar comments
@codelipenghui
Copy link
Contributor Author

retest this please

@codelipenghui
Copy link
Contributor Author

retest this please

@codelipenghui
Copy link
Contributor Author

rerun cpp tests

1 similar comment
@codelipenghui
Copy link
Contributor Author

rerun cpp tests

@codelipenghui
Copy link
Contributor Author

run java8 tests
run integration tests

1 similar comment
@codelipenghui
Copy link
Contributor Author

run java8 tests
run integration tests

@codelipenghui
Copy link
Contributor Author

run java8 tests

@codelipenghui
Copy link
Contributor Author

run integration tests

2 similar comments
@codelipenghui
Copy link
Contributor Author

run integration tests

@codelipenghui
Copy link
Contributor Author

run integration tests

@sijie
Copy link
Member

sijie commented Oct 26, 2019

@codelipenghui this needs to be PIP-47?

@codelipenghui codelipenghui changed the title [PIP-46] Introduce sticky consumer [PIP-47] Introduce sticky consumer Oct 28, 2019
@codelipenghui
Copy link
Contributor Author

@sijie Yes, it should be PIP-47

@codelipenghui
Copy link
Contributor Author

run java8 tests

@codelipenghui
Copy link
Contributor Author

run java8 tests
run integration tests

@codelipenghui
Copy link
Contributor Author

run cpp tests

Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

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

@codelipenghui implementation looks good to me in general. however I don't think we should let user specify the total hash range. we should pick a fixed hash range (e.g. 0~66536), and provide util functions for consumers to split the hash range based on their requirements. please take a look at my detailed comment below.

* If new consumer use conflict hash range with exits consumers, new consumer
* will be rejected.
*/
EXCLUSIVE_HASH_RANGE
Copy link
Member

Choose a reason for hiding this comment

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

probably just call it STICKY?

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, STICKY is more simpler


message KeySharedMeta {
required KeySharedMode keySharedMode = 1;
required int32 totalHashRange = 2;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should allow users to configure thee totalHashRange. The hash range should be fixed (e.g. 0.0 ~ 1.0, Long.MIN_VALUE ~ Long.MAX_VALUE, or Integer.MIN_VALUE to Integer.MAX_VALUE, or 0 ~ 66536). Just pick up a range, and let consumer specify the hash range.

Allowing user configuring the totalHashRange introduces inconsistent across consumers of a subscription. people can make mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, i will fix by using a fixed range(0-65536), current total range for key shared subscription is also (0-65536)

return end;
}

public Range intersect(Range range) {
Copy link
Member

Choose a reason for hiding this comment

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

Guava has a Range class. You might consider reusing its class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pulsar client api module do not add guava dependency, shall we add the guava dependency?

@codelipenghui codelipenghui changed the title [PIP-47] Introduce sticky consumer [PIP-51] Introduce sticky consumer Nov 7, 2019
@codelipenghui
Copy link
Contributor Author

@sijie I have addressed you comments except the new Range class in pulsar client api module, because currently the pulsar client api module do not add guava dependency, considering to keep api module thin, so i add the new Range class.

Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

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

@codelipenghui lgtm. this is a great addon to key_shared subscription.

I left one minor comment.

@@ -250,6 +255,16 @@ message AuthData {
optional bytes auth_data = 2;
}

enum KeySharedMode {
autoSplit = 0;
Copy link
Member

Choose a reason for hiding this comment

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

can you use upper case for enums?

AUTO_SPLIT = 0;
STICKY = 1;

@codelipenghui
Copy link
Contributor Author

codelipenghui commented Nov 7, 2019

@sijie I have added a task tracker #5586 to track the reset cursor approach for sticky consumer.

@sijie
Copy link
Member

sijie commented Nov 7, 2019

@codelipenghui can you update the enum?

@codelipenghui
Copy link
Contributor Author

@sijie I can update it tomorrow, my mac book has some problems with docker environment, can not build the proto. need to build them on another machine 😊

@codelipenghui
Copy link
Contributor Author

run java8 tests

@codelipenghui
Copy link
Contributor Author

@sijie I have updated the enum in PulsarApi.proto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants