-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix: store cursors should be exclusive and match a DB item #1263
Conversation
Jenkins BuildsClick to see older builds (4)
|
Note that this bug has the side effect of allowing a workaround for the issue reported in #1157. We therefore first need to fix that issue, before merging this. |
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.
LGTM!
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.
LGTM ✅
It took me some time to review it. Thanks for the fixes :)
As I see it, this is a tradeoff decision. With current behavior, we avoid doing an extra query to see that the next page is empty; and I think that all implementations should be able to build a cursor based on the last message they received. The rationale behind this decision was: Having the clients to query once more to stop the queries loop is terrible for the waku store nodes as it implies a new request to process and a new DB query with the corresponding CPU usage. This is the typical behavior when implementing pagination on a REST API: https://developer.atlassian.com/server/confluence/pagination-in-the-rest-api/#how-do-i-know-if-there-are-more-pages- |
This behavior aligned with the "no-cursor if no-more messages" logic. I am keener to implement it by fixing the message store queries by including the message on the next page. But if your changes fixes the bug with another approach, I am ok with it 😁 |
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.
lgtm!
as a nitpick/question, any reason behind using a non deterministic timestamp getNanosecondTime(getTime().toUnixFloat())
instead of hardcoded value?
In this case it shouldn't matter but tests should be reproduzable/deterministic/idempotent/etc.
I agree! In this case using real time was necessary, because the underlying store message validity check uses real time to determine if a message will be inserted or not. The test would therefore fail if it uses timestamps that do not fall within 20 seconds of current time. Out of scope for this PR, but the way to fix it would be to change the underlying validity check to take a reference timestamp as parameter (which defaults to current time). |
This fixes two related bugs in nwaku v0.12.0 with regards to cursors in the store protocol:
Bug 1: message indexed by cursor excluded from results
Summary of unexpected behaviour:
cursor
pointing to the beginning of the next page, if such a page existscursor
is excluded from a subsequent history response as per RFC 13 and is therefore excluded from the retrievable historyFix
This fix:
v0.12.0
and is described in the RFC)v0.12.0
behaviour of only returning a cursor when a next page is available. This is how most clients are currently implemented and is necessary to fix a fairly urgent bug.Comments:
Bug 2: cursor retrieval from sqlite DB using incorrect length
Summary of unexpected behaviour
HistoryResponse
s containing the wrong cursorstoredAt
component playing an important role).Fix
Tests
Since these bugs were missed in tests, I've modified the unit tests to verify that we can page through an entire history in both directions.
This:
pagingInfo
cursor are excluded as expected from subsequent queries