-
Notifications
You must be signed in to change notification settings - Fork 683
kvindexer: Removing event function type as it is always the same #581
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
Conversation
…cometbft/cometbft into jasmina/571-kvindexer-remove-event-type
"query return all events from a height - exact - no match.events": { | ||
q: query.MustCompile("block.height = 1"), | ||
results: []int64{1}, | ||
}, |
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 don't understand why these test cases are no longer needed
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.
BEcause they are the exact duplicate of the existing tests - they were there because we used to test with and without the match-events keywords and then when I fixed the tests for not use the keyword, I did not delete the duplicate ones.
state/indexer/block/kv/util.go
Outdated
if err != nil { // If it cannot parse the event function type, it could be 1 | ||
remaining, err2 := orderedcode.Parse(string(key), &compositeKey, &eventValue, &height, &eventSeq) | ||
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq | ||
return 0, fmt.Errorf("failed to parse event key: %w", err) |
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.
Do we also want to report err2
?
state/indexer/block/kv/util.go
Outdated
} else { | ||
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If 2, , retrieve the eventSeq, otherwise ignore | ||
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq | ||
return 0, fmt.Errorf("failed to parse event key: %w", err) |
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.
Report err2
?
state/indexer/block/kv/util.go
Outdated
} | ||
|
||
} else { | ||
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If 2, , retrieve the eventSeq, otherwise ignore |
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.
What does "If 2, ," mean?
Also, how do we ignore here? (I see we're returning the error if err2 is not nil
)
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 2 - the case under number 2. above , that have both an event sequence and event type.
I will rephrase this, but essentially ignore means, that we do not have the event sequence, but rather just the event function type (case 3.), and we will ignore. Err2 should still be returned.
q: "account.number <= 2 AND account.owner CONTAINS '/Iv' AND account.owner CONTAINS 'an' AND tx.height = 1", | ||
resultsLength: 1, | ||
}, | ||
" Match range with match events contains": { |
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.
Are we testing all "if" branches in the changes to file state/indexer/block/kv/util.go
above?
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 could not think of how to test the cases with UTs because those if branches are handling events indexed using old versions of the indexer. Unless we create different indexing options in our UTs. We could provide a custom indexing function to generate the event key differently and then test. That is basically what i did manually. And I did this with the backwards compatibility tests when running on top of data indexed with old versions.
Co-authored-by: Sergio Mena <sergio@informal.systems>
state/indexer/block/kv/util.go
Outdated
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If the event follows the scenario in 2., | ||
// retrieve the eventSeq, otherwise, there should be no remainder | ||
// and no error and this parsing has no effect. | ||
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq if in 2. | ||
return 0, fmt.Errorf("failed to parse event key: %w", err2) | ||
} |
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.
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If the event follows the scenario in 2., | |
// retrieve the eventSeq, otherwise, there should be no remainder | |
// and no error and this parsing has no effect. | |
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq if in 2. | |
return 0, fmt.Errorf("failed to parse event key: %w", err2) | |
} | |
if len(remaining2) != 0 { // Are we in case 2 or 3 | |
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // the event follows the scenario in 2., | |
// retrieve the eventSeq | |
// there should be no error | |
if err2 != nil { // We should not have anything else after the eventSeq if in 2. | |
return 0, fmt.Errorf("failed to parse event key: %w", err2) | |
} | |
} |
I'm suggesting this, because I don't clearly see the path taken by scenario 3 in the present code.
I also see two main advantages with my suggestion:
- Easier to distinguish paths followed by scenarios 2 and 3
- You don't call
Parse
unless you're sure you need to call it (cleaner)
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 am fine with the chaneg but we still need to check whether len(remaining) != 0 because that is invalid. I will push a change including both. Let me know if you agree.
- `[kvindex]` Remove event function type from event key in kvindexer. The function type is not always `FinalizeBlock`. | ||
([\#581](https://github.com/cometbft/cometbft/pull/581)) |
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.
What's the impact here on the user? If there's no direct impact on the user, it's not clear to me that we'd need a changelog entry. If the overall goal is to reduce storage consumption, then I'd recommend rewording to something that explicitly highlights that. Users may not understand what this changelog entry means for them otherwise.
Also, if it's being backported to v0.38, then the PR to main
shouldn't have a changelog entry - only the backport PR should have a changelog entry (from a user's perspective, they'd be receiving this change in the v0.38 release series, so there'd be no need to also be notified about it in the v0.39 series).
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.
Makes sense. I will remove the changelog entry here. As for the impact on the user, there is no direct impact as far as I can see. We have info on this in the upgrading docs for 0.38 because the format of data on disk changes. However, people who have forks that play with the indexer, they might be impacted.
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.
Thanks for the refactoring of the intricate code!
Thank you guys for improving it! @lasarojc , let me know if you are happy with the changes and I can merge this :) |
…kport #581) (#774) * kvindexer: Removing event function type as it is always the same (#581) * Applied @serigo-menas PR comments * Removed changelog entry * Refactored code according to suggestion from @lasarojc --------- Co-authored-by: Sergio Mena <sergio@informal.systems> Co-authored-by: Lásaro Camargos <lasaro@informal.systems> (cherry picked from commit e9e9cf3) * Added changelog * Update .changelog/unreleased/breaking-changes/774-state-indexerevent-remove-function-type.md Co-authored-by: Thane Thomson <connect@thanethomson.com> --------- Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com> Co-authored-by: Thane Thomson <connect@thanethomson.com>
* Applied @serigo-menas PR comments * Removed changelog entry * Refactored code according to suggestion from @lasarojc --------- Co-authored-by: Sergio Mena <sergio@informal.systems> Co-authored-by: Lásaro Camargos <lasaro@informal.systems>
Closes #571 .
Removes the event function type identifier form the event key. Earlier having this in the key made sense as it differentiated between
BeginBlock
andEndBlock
events. WithFinalizeBlock
it will always be the same and has no point.The only issue is that we need to support data indexed with old versions where the key has the function identifier key (see
util.go:L123
.Note: I am piggybacking updates to the tests because there were duplicate UTs and UTs refering to
match_events
which do not exist in this version.PR checklist
.changelog
(we use unclog to manage our changelog)docs/
orspec/
) and code comments