8000 kvindexer/0.34/bugfixes in range queries and result deduplication by jmalicevic · Pull Request #76 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

kvindexer/0.34/bugfixes in range queries and result deduplication #76

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 27 commits into from
Feb 3, 2023

Conversation

jmalicevic
Copy link
Contributor

Original PR tendermint/tendermint#9884

This PR fixes two bugs when matching attributes within events:

  • When multiple events match in the same transaction or block, the query would return multiple times the same result.
  • When the query contains a height range and another range, the height range would get ignored under certain conditions.
  • A query containing both a height range and height equality would process them both. Now the equality is ignored when a range exists.
  • Queries containing CONTAINS and EXISTS would ignore the height requirement when match.events = 1.

There have been minor improvements to the readability of the code:

  • As we need to know the height range or the requested height to match events at and both whether the height related conditions are the only ones (beside match.events), there is now a heightInfo struct that encapsulates all of that. Additionally, spuradious checks on whether the length of the conditions is a certain number has been replaced with simple bool flags which are derived within the dedupHeight method.

@jmalicevic jmalicevic added bug Something isn't working indexer labels Jan 5, 2023
@jmalicevic jmalicevic requested a review from a team as a code owner January 5, 2023 11:41
@jmalicevic jmalicevic self-assigned this Jan 5, 2023
jmalicevic and others added 2 commits January 5, 2023 22:49
Co-authored-by: Thane Thomson <connect@thanethomson.com>
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale For use by stalebot label Jan 22, 2023
@thanethomson thanethomson added wip Work in progress and removed stale For use by stalebot labels Jan 22, 2023
@sergio-mena
Copy link
Contributor

Pushing a commit with the block indexing UTs I came up with...

@codecov-commenter
Copy link
codecov-commenter commented Feb 1, 2023

Codecov Report

❗ No coverage uploaded for pull request base (v0.34.x@d41a46e). Click here to learn what that means.
Patch has no changes to coverable lines.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             v0.34.x      #76   +/-   ##
==========================================
  Coverage           ?   48.42%           
==========================================
  Files              ?      280           
  Lines              ?    49887           
  Branches           ?        0           
==========================================
  Hits               ?    24157           
  Misses             ?    23875           
  Partials           ?     1855           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

ctx := context.Background()

results, err := indexer.Search(ctx, query.MustParse("account.number >= 1"))
assert.NoError(t, err)
for _, tc := range testCases {
Copy link
Contributor

Choose a reason for hiding this comment

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

I refactored this to be able to add new TCs easily

heightRangeExists := false
var heightCondition []query.Condition
heightInfo.>
heightInfo.>
for _, c := range conditions {
if c.CompositeKey == types.TxHeightKey {
if c.Op == query.OpEqual {
if heightRangeExists {
if heightRangeExists || found {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to back/forward port this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IT has to be included in the open PR for 0.37. I have it in my todo for that PR. As well as porting the UTs you added to this PR.

@jmalicevic jmalicevic merged commit 260c8de into v0.34.x Feb 3, 2023
@jmalicevic jmalicevic deleted the jasmina/kvindexer-fix-0.34 branch February 3, 2023 20:25
cometcrafter pushed a commit to graphprotocol/cometbft that referenced this pull request Jun 1, 2024
…… (backport cometbft#76) (cometbft#81)

* perf(blockstore): Add LRU caches to blockstore operations used in consensus (backport cometbft#3003) (cometbft#3083)

Closes cometbft#2844

We are seeing that the blockstore loading operations get used in hot
loops within gossip routines, and queryMaj23 routines. This PR reduces
that overhead using an LRU cache.

The LRU cache does have a mutex on every get, but the time with the LRU
cache is 9x faster than without (before even adding in DB overheads),
due to the proto unmarshalling saved. We could imagine a setup where we
avoided a lock there entirely. I don't think this is worth right now,
since the new code is 9x faster, and these mostly appear in catchup code
which should not be highly contended for across peers at the same time.

With the new benchmark I added:
OLD:
```
BenchmarkRepeatedLoadSeenCommit-12         24447             54691 ns/op           46495 B/op        319 allocs/op
```
NEW:
```
BenchmarkRepeatedLoadSeenCommit-12        224131              6401 ns/op            8320 B/op          2 allocs/op
```

It turns out these gossip routines don't need mutative copies, so we
could optimize out the large allocation in the future if we want.

1 hour cpu profile that shows this appearing in prod:

![image](https://github.com/cometbft/cometbft/assets/6440154/5a7e0f02-8385-4c01-aa6a-dba2a2bf376d)

The state machine execution time here for context is 92 seconds. So this
is adding up in system load (and GC! The GC load is 52GB, the entire
trace is 200GB, with other parts being optimized down from recent PRs)

---

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [ ] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request cometbft#3003 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
(cherry picked from commit 0c10bd5)

* Add Changelog

(cherry picked from commit 4594f29)

# Conflicts:
#	CHANGELOG.md

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
Co-authored-by: PaddyMc <paddymchale@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working indexer wip Work in progress
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants
0