-
Notifications
You must be signed in to change notification settings - Fork 112
[CLIENT-4086] (Breaking change) Have aerospike.get_partition_id() take in a bytearray as argument instead of a tuple containing a str. Add missing documentation for aerospike.get_partition_id(). #928
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
[CLIENT-4086] (Breaking change) Have aerospike.get_partition_id() take in a bytearray as argument instead of a tuple containing a str. Add missing documentation for aerospike.get_partition_id(). #928
Conversation
…turns a bytearray...
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #928 +/- ##
==========================================
+ Coverage 83.31% 83.38% +0.06%
==========================================
Files 99 99
Lines 14422 14438 +16
==========================================
+ Hits 12016 12039 +23
+ Misses 2406 2399 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
DomPeliniAerospike
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looked good! Left a few suggestions/comments.
| // Python Function Argument Parsing | ||
| if (PyArg_Parse(args, "(s)", &digest) == false) { | ||
| return NULL; | ||
| if (PyArg_Parse(arg, "y*", &py_buffer) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To optimize, you should change to "y#" in order to avoid creating an entire py_buffer object:
Since you don't need to write to the buffer, using read only mode should be faster.
Snippet:
`
const uint8_t *buf;
Py_ssize_t len;
if (!PyArg_ParseTuple(args, "y#", &buf, &len)) {
return NULL; // PyArg_ParseTuple already sets an exception
}
`
Also requires changing METH_O back to METH_VARARGS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think switching to "y#" would make get_partition_id() and calc_digest() harder to use. The user can no longer pass a digest from aerospike.calc_digest() directly into aerospike.get_partition_id(). calc_digest() returns a bytearray which is mutable, and "y#" only accepts a "read-only bytes-like object"
y# documentation: https://docs.python.org/3/c-api/arg.html#:~:text=accept%20binary%20data.-,y#,-(read%2Donly%20bytes
aerospike.calc_digest() has returned a bytearray for a while now: https://aerospike-python-client.readthedocs.io/en/8.0.0/aerospike.html#aerospike.calc_digest
To give more context, this PR is for aerospike.get_partition_id() debugging QE's bank test. (the Jira ticket explains more about what aerospike.get_partition_id() is used for) I don't believe customers are using this in production.
We could make a breaking change to aerospike.calc_digest() to return a bytes object instead of bytearray; bytes is immutable whereas the latter is mutable. But I feel like that's outside the scope of this PR
doc/aerospike.rst
Outdated
|
|
||
| .. py:function:: get_partition_id(digest) -> int | ||
|
|
||
| Calculate the partition id for a record using its digest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the partition_id associated with key's digest? It doesn't have to be a record right?
Also Nit: Capital ID looks better in documentation than id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, will fix
| import pytest | ||
|
|
||
| # This isn't a correctness test. It's only for code coverage purposes | ||
| # and to make sure the API is aligned with the documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will QE be testing the correctness of this? Should be right, but we should confirm with testing. Should be easy to verify with AS_POLICY_KEY_DIGEST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just manually check using gdb. I don't think it's necessary to write a correctness test since customers shouldn't be using this (it's only meant for internal testing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to see that maybe this API call isn't necessary.. we can just use gdb to print the partition id...
doc/aerospike.rst
Outdated
|
|
||
| Calculate the partition id for a record using its digest. | ||
|
|
||
| :param bytes-like object digest: the record's digest calculated by :py:meth:`aerospike.calc_digest`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description suggest calc_digest is mandatory, but if you have a digest from a record result, you don't need calc_digest.
Might be better to say:
The records digest. To calculate the digest, use :py:meth...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
This also fixes a bug where passing in a digest with embedded NULL characters will raise a ValueError exception.
Extra changes
Add missing test cases for aerospike.get_partition_id()
TODO
Docs
https://aerospike-python-client--928.org.readthedocs.build/en/928/aerospike.html#aerospike.get_partition_id