Skip to content

Add example how to calculate bucketId on client #274

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

Merged
merged 10 commits into from
Nov 9, 2022

Conversation

ArtDu
Copy link
Contributor

@ArtDu ArtDu commented Sep 29, 2022

What has been done? Why? What problem is being solved?

I didn't forget about

  • Tests
  • Changelog
  • Documentation
  • Cleanup the code for review. See checklist

Closes #???

@ArtDu ArtDu force-pushed the crud/bucket_id_strcrc32 branch from f4d15d4 to 4412b80 Compare September 29, 2022 18:11
@ArtDu ArtDu marked this pull request as ready for review September 30, 2022 09:14
@ArtDu ArtDu requested review from akudiyar and Elishtar September 30, 2022 09:14
@ArtDu ArtDu self-assigned this Sep 30, 2022
@ArtDu
Copy link
Contributor Author

ArtDu commented Sep 30, 2022

@akudiyar @Elishtar

@dkasimovskiy suggests to export this implementation in source. What do you think about it?

@akudiyar
Copy link
Collaborator

akudiyar commented Oct 2, 2022

I think a good solution will be to describe how to create and use your own sharding function with the help of vshard API calls in the README. And leave the sample code in the tests how it is now.

@ArtDu ArtDu added the 2sp label Oct 4, 2022
@ArtDu ArtDu changed the title Add tests how to calculate bucketId on client Add example how to calculate bucketId on client Oct 6, 2022
@ArtDu ArtDu force-pushed the crud/bucket_id_strcrc32 branch 2 times, most recently from 5d7f09a to 8bb7c18 Compare October 6, 2022 19:39
@ArtDu ArtDu force-pushed the crud/bucket_id_strcrc32 branch from 8bb7c18 to 59b635f Compare October 6, 2022 19:41
@ArtDu
Copy link
Contributor Author

ArtDu commented Oct 6, 2022

I think a good solution will be to describe how to create and use your own sharding function with the help of vshard API calls in the README. And leave the sample code in the tests how it is now.

Added, please validate it

@ArtDu ArtDu requested a review from akudiyar October 6, 2022 19:43
Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

LGTM,just two points here:

  • an example of converting a tuple to bytes will be useful
  • fixed the grammar a bit

README.md Outdated
client.callForSingleResult("vshard.router.bucket_count", Integer.class).get()
);
}
return bucketCount.get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to handle an unexpected null value better, like with an orElseThrow callback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten, please check it out

README.md Outdated

Then we can determine bucket id by passing your key through hash function and get the remainder of the division by number of buckets:
```java
byte[] key = ... // can be multipart
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not clear now what to put in the key. An example with a tuple will be better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten, please check it out

ArtDu and others added 8 commits October 28, 2022 17:11
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
Co-authored-by: Alexey Kuzin <akudiyar@gmail.com>
@ArtDu ArtDu force-pushed the crud/bucket_id_strcrc32 branch from 5bc9e6a to 6e7b3de Compare October 28, 2022 15:07
@ArtDu ArtDu requested a review from akudiyar October 28, 2022 15:08
@ArtDu
Copy link
Contributor Author

ArtDu commented Nov 7, 2022

@akudiyar Could you check it?

Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

LGTM

@ArtDu ArtDu merged commit 26d2d8a into master Nov 9, 2022
@ArtDu ArtDu deleted the crud/bucket_id_strcrc32 branch November 9, 2022 08:10
Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

Two small changes are needed, I forgot to mention this, sorry. Let's do this on the next doc change.

client.callForSingleResult("vshard.router.bucket_count", Integer.class).get()
);
}
bucketCount.orElseThrow(() -> new TarantoolClientException("Failed to get bucket count"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

return is missing

Then we can determine bucket id by passing your key through hash function and get the remainder of the division by number of buckets:
```java
TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100);
byte[] key = getBytesFromList(Arrays.asList(tarantoolTuple.getInteger(0), tarantoolTuple.getInteger(2)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may be good to place a link to this getBytesFromList method in the tests to the comment above, because it is not a built-in and therefore produces questions

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.

2 participants