-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
finish to add support of subset in items_*_batch() #3440
finish to add support of subset in items_*_batch() #3440
Conversation
- add items_lookup_batch() on subset keys - add items_lookup_and_delete_batch() on subset keys - add docstring on items_*_batch() - update the reference_guide.md
@egobillot This is the original kernel patch introduced for lookup_batch/lookup_and_delete_batch/update_batch/delete_batch. The quote from the commit message:
Basically, lookup/lookup_and_delete does not accept a list of keys as the input, So we do not need to provide lookup/lookup_and_delete API which accepts For you test failure, the reason is:
I think you do not need to have subset tests from lookup, lookup_and_delete as they are not really supported. |
Thank you @yonghong-song . It was not clear to me that subset batch was not supported for lookup and lookup_and_delete by the kernel. So I remove the code regarding subset for lookup_*. |
…rt batch on a subset of key: update code accordingly.
[buildbot, test this please] |
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.
Added some comments. Most importantly for the robust implementation, I suggest to have a loop for lookup_batch and lookup_and_delete_batch, could you take a look?
src/python/bcc/table.py
Outdated
alloc_v (bool): True to allocate values array, False otherwise. | ||
Default is False. | ||
count (int): number of elements in the array(s) to allocate. If | ||
count is None then it allocates the maximum nb of elements i.e |
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.
nb => number
src/python/bcc/table.py
Outdated
tuple: (count, keys, values). Where count is ct.c_uint32, | ||
and keys and values an instance of ct.Array | ||
Raises: | ||
ValueError: If count is not < 1 or > self.max_entries |
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.
ValueError: If count is less than 1 or greater than self.max_entries?
src/python/bcc/table.py
Outdated
Returns: | ||
ct.c_uint32 : the size of the array(s) | ||
Raises: | ||
ValueError: If length of arrays is < 1 or > self.max_entries, or |
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.
is less than 1 or greater than self.max_entries?
src/python/bcc/table.py
Outdated
tuple: The tuple of (key,value) for every entries that have | ||
been looked up. | ||
Raises: | ||
Exception: If bpf syscall has failed or is invalid |
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.
How about Exception: if bpf syscall return value indicates an error
src/python/bcc/table.py
Outdated
ct.byref(keys), | ||
ct.byref(values), | ||
ct.byref(count) | ||
ct.byref(ct_cnt), |
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 avoid future confusion, let us just use a separate variable out_batch
here by not overloading ct_cnt
.
src/python/bcc/table.py
Outdated
tuple: The tuple of (key,value) for every entries that have | ||
been deleted. | ||
Raises: | ||
Exception: If bpf syscall has failed or is invalid |
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.
if bpf syscall returns an error.
src/python/bcc/table.py
Outdated
ct.byref(keys), | ||
ct.byref(count) | ||
ct.byref(ct_keys), | ||
ct.byref(ct_cnt) | ||
) | ||
errcode = ct.get_errno() | ||
if (errcode == errno.EINVAL): |
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.
The error chacking here and below is not quite right. The delete_batch and update_batch use kernel internal function generic_map_{delete,update}_batch
function, they return 0 to indicate a success and non-0 as an error code. Just check errcode is 0 or not is enough.
src/python/bcc/table.py
Outdated
ct.byref(count) | ||
ct.byref(ct_keys), | ||
ct.byref(ct_values), | ||
ct.byref(ct_cnt) | ||
) | ||
|
||
errcode = ct.get_errno() |
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.
similar to delete_batch, just check whether errcode is 0 or not is enough below.
src/python/bcc/table.py
Outdated
tuple: The tuple of (key,value) for every entries that have | ||
been looked up and deleted. | ||
Raises: | ||
Exception: If bpf syscall has failed or is invalid |
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.
if bpf syscall return code indicates an error.
src/python/bcc/table.py
Outdated
ct.byref(ct_cnt), | ||
ct.byref(ct_keys), | ||
ct.byref(ct_values), | ||
ct.byref(ct_cnt) |
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.
similar to lookup_batch, we may need a loop here.
Yes, I will have a look at your comments. |
…ake it more robust.
@yonghong-song It should be better now with 7cbf766 . I have factorized the code for items_lookup_and_delete_batch() and items_lookup_batch() since it was almost the same. |
[buildbot, test this please] |
@egobillot Thanks for the update! Much better. I just added one more comment and I think we should be fine after that. |
[buildbot, ok to test] |
LGTM, Thanks! |
finish to add support of subset in items_*_batch() - rewrite items_lookup_batch() and items_lookup_and_delete_batch() to make it more robust. - add docstring on items_*_batch() - update the reference_guide.md
Hello,
Here is a partial PR in order to :
This is a partial PT because I am stuck with items_lookup_batch and items_lookup_and_delete_batch on a subset. Sometimes tests are Ok and sometimes they fails. See the output of tests.
Do I need to call the lib.bpf_lookup_and_delete_batch() several times until the sum of the nb of elements returned matches the subset size ? For example, If my subset size is 32 and get only 31 elem on the first call, do I need to call it again for the last element ? 🤔