Skip to content
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

add a BadgerDB backend #115

Merged
merged 7 commits into from
Jul 9, 2020
Merged

add a BadgerDB backend #115

merged 7 commits into from
Jul 9, 2020

Conversation

mvdan
Copy link
Contributor

@mvdan mvdan commented Jun 30, 2020

With multiple commits, to show the incremental changes on top of Anton's work in
early 2019.

Updates #38.

Mainly, many now return errors, so we can get rid of all panics.

Also add the missing BackendType.
The commented out code might be useful in the future, but it's in the
git history anyway.
@codecov
Copy link

codecov bot commented Jun 30, 2020

Codecov Report

Merging #115 into master will increase coverage by 1.75%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #115      +/-   ##
==========================================
+ Coverage   68.86%   70.61%   +1.75%     
==========================================
  Files          26       27       +1     
  Lines        1593     1746     +153     
==========================================
+ Hits         1097     1233     +136     
- Misses        429      441      +12     
- Partials       67       72       +5     
Impacted Files Coverage Δ
db.go 41.17% <ø> (ø)
badger_db.go 88.88% <88.88%> (ø)
Impacted Files Coverage Δ
db.go 41.17% <ø> (ø)
badger_db.go 88.88% <88.88%> (ø)

@mvdan
Copy link
Contributor Author

mvdan commented Jun 30, 2020

FYI @melekes @erikgrinaker @marbar3778

@mvdan
Copy link
Contributor Author

mvdan commented Jun 30, 2020

CI is failing because interfacer is complaining about an unexported function. You should disable that linter altogether - that warning isn't particularly useful :)

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

great work @mvdan 👍

badger_db.go Outdated Show resolved Hide resolved
badger_db.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

could badger_db.go be broken out to match the file structure of other dbs?

@mvdan
Copy link
Contributor Author

mvdan commented Jul 1, 2020

badger_db.go is under 300 lines, so I would generally not split it up. The current file structure seems a bit weird to me, with over a dozen files under 100 lines, and over 30 files total. But if you strongly prefer consistency, I can split it up.

@mvdan
Copy link
Contributor Author

mvdan commented Jul 1, 2020

Two follow-up comments:

  1. The tests here are passing, but I assume something will fail once tendermint is properly tested with this code. Can someone with more tendermint experience help?

  2. It would be interesting to get some benchmark numbers. I can help if you can point me at a benchmark that is bottlenecked by the database, and that reflects somewhat realistic usage.

@tac0turtle
Copy link
Contributor

badger_db.go is under 300 lines, so I would generally not split it up. The current file structure seems a bit weird to me, with over a dozen files under 100 lines, and over 30 files total. But if you strongly prefer consistency, I can split it up.

it should be fine since there will be a followup to restructuring the package.

@erikgrinaker erikgrinaker self-assigned this Jul 6, 2020
Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @mvdan! Can you add a README description and changelog entry as well please?

The tests here are passing, but I assume something will fail once tendermint is properly tested with this code. Can someone with more tendermint experience help?

The Tendermint end-to-end tests pass, but IAVL fails with a panic. I believe this is caused by the lack of iter.Valid() checks, we should add a tm-db test case for this as well:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x45102e6]

goroutine 174 [running]:
testing.tRunner.func1.1(0x48400e0, 0x4f26760)
	/usr/local/Cellar/go/1.14.4/libexec/src/testing/testing.go:940 +0x2f5
testing.tRunner.func1(0xc0001dd8c0)
	/usr/local/Cellar/go/1.14.4/libexec/src/testing/testing.go:943 +0x3f9
panic(0x48400e0, 0x4f26760)
	/usr/local/Cellar/go/1.14.4/libexec/src/runtime/panic.go:969 +0x166
github.com/dgraph-io/badger/v2.(*Item).Key(...)
	/Users/erik/Projects/go/pkg/mod/github.com/dgraph-io/badger/[email protected]/iterator.go:70
github.com/dgraph-io/badger/v2.(*Iterator).Item(...)
	/Users/erik/Projects/go/pkg/mod/github.com/dgraph-io/badger/[email protected]/iterator.go:504
github.com/tendermint/tm-db.(*BadgerDB).iteratorOpts(0xc000010068, 0xc0003b6a20, 0x9, 0x9, 0xc0003b6a00, 0x9, 0x9, 0x1, 0x64, 0x1, ...)
	/Users/erik/Projects/tendermint/tm-db/badger_db.go:140 +0x266
github.com/tendermint/tm-db.(*BadgerDB).ReverseIterator(0xc000010068, 0xc0003b6a00, 0x9, 0x9, 0xc0003b6a20, 0x9, 0x9, 0x401571c, 0xc00009f100, 0x8, ...)

It would be interesting to get some benchmark numbers. I can help if you can point me at a benchmark that is bottlenecked by the database, and that reflects somewhat realistic usage.

The best option would probably be Cosmos SDK simulations, which use tm-db via IAVL. I'm not very familiar with these though, as it's managed by a different team.

badger_db.go Outdated Show resolved Hide resolved
badger_db.go Outdated Show resolved Hide resolved
badger_db.go Show resolved Hide resolved
@mvdan
Copy link
Contributor Author

mvdan commented Jul 6, 2020

Can you add a README description and changelog entry as well please?

For sure.

The Tendermint end-to-end tests pass, but IAVL fails with a panic.

Thanks, I'll take a look.

The best option would probably be Cosmos SDK simulations, which use tm-db via IAVL. I'm not very familiar with these though, as it's managed by a different team.

Sounds good - I'll wait for someone from that team to give some insight, then. Benchmarking should probably come once the reviews are done.

@erikgrinaker
Copy link
Contributor

@alexanderbez Do you have any SDK sims that would be suitable for benchmarking database backends with realistic workloads?

@alexanderbez
Copy link

Only thing that comes to mind is simulation benchmarking, which you can look into. Although, you should be able to get away with a pretty easy one-off benchmark, where you create a simapp with a corresponding backend, begin block, deliver txs, end block, commit, repeat.

@erikgrinaker
Copy link
Contributor

Thanks Bez. I don't think benchmarks are necessary to merge this, especially since we don't really have a good general-purpose benchmarking suite at the moment. If you want to spend some time on it @mvdan then it's definitely welcome, but otherwise we can punt it and do some performance optimizations later if necessary.

mvdan added 3 commits July 8, 2020 21:58
Passing all the relevant tests.
It's been deprecated for years and for good reason. The warning it was
showing in this branch wasn't useful.
@mvdan
Copy link
Contributor Author

mvdan commented Jul 8, 2020

How did you run those iavl tests, beyond replacing the tm-db module with my branch? I assume you had to make some change somewhere to use the badger backend, because I don't think iavl tests against all tm-db backends.

Also, your suspicion about that missing iter.Valid call was spot on - I added a couple of iterator test cases on an empty database, and got the same panic as you did:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x81d47d]

goroutine 90 [running]:
testing.tRunner.func1.1(0x92a2c0, 0xc8cc90)
	/home/mvdan/tip/src/testing/testing.go:1057 +0x30d
testing.tRunner.func1(0xc000082480)
	/home/mvdan/tip/src/testing/testing.go:1060 +0x41a
panic(0x92a2c0, 0xc8cc90)
	/home/mvdan/tip/src/runtime/panic.go:969 +0x175
github.com/dgraph-io/badger/v2.(*Item).Key(...)
	/home/mvdan/go/pkg/mod/github.com/dgraph-io/badger/[email protected]/iterator.go:70
github.com/dgraph-io/badger/v2.(*Iterator).Item(...)
	/home/mvdan/go/pkg/mod/github.com/dgraph-io/badger/[email protected]/iterator.go:504
github.com/tendermint/tm-db.(*BadgerDB).iteratorOpts(0xc0000a00f8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x64, 0x1, ...)
	/home/mvdan/git/tm-db/badger_db.go:140 +0x23d
github.com/tendermint/tm-db.(*BadgerDB).ReverseIterator(0xc0000a00f8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0xc00b2343c0, 0x0, ...)
	/home/mvdan/git/tm-db/badger_db.go:163 +0x106
github.com/tendermint/tm-db.testDBIterator(0xc000082480, 0x9a78c4, 0x8)
	/home/mvdan/git/tm-db/backend_test.go:314 +0x2b77
github.com/tendermint/tm-db.TestDBIterator.func1(0xc000082480)
	/home/mvdan/git/tm-db/backend_test.go:159 +0x45
testing.tRunner(0xc000082480, 0xc00555cc20)
	/home/mvdan/tip/src/testing/testing.go:1108 +0xef
created by testing.(*T).Run
	/home/mvdan/tip/src/testing/testing.go:1159 +0x386
exit status 2

Should be all good to go, I think, unless there are other iavl panics or errors.

@mvdan
Copy link
Contributor Author

mvdan commented Jul 8, 2020

Also, I've kept multiple commits, but I've also merged some changes together to not explode this into 15 commits. I think this is nicer as a series of commits than as a single commit conflating my work with Anton's.

@erikgrinaker
Copy link
Contributor

Thanks @mvdan! IAVL tests pass - to run them, I point go.mod to a local clone and manually update TestRandomOperations to use BadgerDB.

Could you update the README and CHANGELOG as well please?

Also, I've kept multiple commits, but I've also merged some changes together to not explode this into 15 commits. I think this is nicer as a series of commits than as a single commit conflating my work with Anton's.

Thanks! We prefer to squash-merge PRs, since this makes it easier to e.g. cherry-pick or revert them.

@mvdan
Copy link
Contributor Author

mvdan commented Jul 9, 2020

Could you update the README and CHANGELOG as well please?

Whoops, forgot about those. Done.

Thanks! We prefer to squash-merge PRs, since this makes it easier to e.g. cherry-pick or revert them.

Of course - I would probably go for the same :) Do you want me to squash myself then, to provide a good commit message on the squashed commit? Or are you OK with a squashed commit message that simply lists all original commit messages?

@erikgrinaker
Copy link
Contributor

Thanks! I can squash-merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants