-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Non-locking, read-only opens #432
Conversation
This introduces a read-only option on the DB struct. The main effect is to force all transactions to be read-only. It also skips anything that might write to disk. It will put a shared lock on the directory when it's opened read-only. This will allow other read-only opens but will deny read-write opens until all readers have closed. If the database is already open read-write and an attempt is made to open it again (read-only or read-write), an error occurs. It also: - Fails if the manifest doesn't exist on read-only open - Does not attempt to truncate the manifest - Skips compactors and memtable - All vlogs are opened read-only
There shouldn't be any need anyways.
Truly, nice job @allenluce, is that tested on windows operating system as well? |
Really nice change! Got a few comments. Once you address them, I'll pull this change in. @allenluce : You can use the Reviewed 11 of 11 files at r1. db.go, line 261 at r1 (raw file):
If multiple processes are using the same Badger directory, then none of them should write back anything. So, also ensure that value log isn't replayed on start. This would mean that if the DB had crashed before, then a read-only open would appear to lose some data. We must warn users about that in the documentation. Alternatively: If ReadOnly is set, then the number of memtables above L0 should be set to a very high value, to allow value log to be replayed and stored in memtables, but without the process getting blocked on them getting compacted. This might be a better option to avoid an apparent loss of data. In any case, all these only take effect if the last run of read-write instance Badger had crashed, and not properly closed. db.go, line 333 at r1 (raw file):
Value log takes a copy of options on Open. So, it should already know about readonly flag and doesn't need to be passed explicitly. https://github.com/dgraph-io/badger/blob/e8ce3e9d89507ec60f9b1f2f4c7539ae3efe61cd/db.go#L265 db_test.go, line 1573 at r1 (raw file):
LGTM Nice test. manifest.go, line 263 at r1 (raw file):
Instead of 2 boolean params, how about using an int based flag. And do something like:
options.go, line 90 at r1 (raw file):
// Open the DB as read-only. With this set, multiple processes can open the same Badger DB. transaction.go, line 514 at r1 (raw file):
Convert this question into a statement. value.go, line 558 at r1 (raw file):
Same as above. This should be Note the function name has been changed to reflect that this function is no longer only about sync. value.go, line 615 at r1 (raw file):
This argument passing shouldn't be required because value log holds an opt as well. Comments from Reviewable |
I don't have easy access to a Windows build environment. I'd expect this to fail on Windows: the signature for Review status: all files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. Comments from Reviewable |
The -t comment is for:
|
If there is data in a vlog to be replayed, opening the DB with ReadOnly set will return an error.
The vlog structure already carries the opts from it's Open()
To reflect that it's not just for synced files.
Review status: all files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. db.go, line 261 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
I've taken the first approach somewhat modified: if the DB is opened read-only and there's data to play back, db.go, line 333 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Cool, I've corrected. db_test.go, line 1573 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Thanks! manifest.go, line 263 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
OK, I switched to that. Not sure the way the function is currently used makes the flags any less clunky. options.go, line 90 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Changed. transaction.go, line 514 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. value.go, line 558 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Gottit. I've changed the function names. value.go, line 615 at r1 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. Comments from Reviewable |
These tests are useless on Windows until the placeholder in dir_windows.go is removed.
Thanks for addressing the comments. One last round of follow up comments, and then we should be good to go. Reviewed 10 of 10 files at r2. db.go, line 295 at r2 (raw file):
You don't need to pass the opt here. vlog already has that opt. db_test.go, line 1526 at r2 (raw file):
Instead of checking the wordings, create an error variable (errors.go), and check equality of that variable. dir_windows.go, line 62 at r2 (raw file):
Use an error variable. You can define it in errors.go. manifest.go, line 263 at r1 (raw file): Previously, allenluce (Allen Luce) wrote…
Thanks. This is more in line with how Linux flags are passed. options.go, line 93 at r2 (raw file):
Remove the round brackets. value.go, line 303 at r2 (raw file):
Create an error variable in errors.go, and use that error. value.go, line 672 at r2 (raw file):
readOnly doesn't need to be passed. vlog should already know this via opt. value_test.go, line 533 at r2 (raw file):
You can check error variable equality instead. Comments from Reviewable |
Arg cleanups + house preferences.
Review status: 6 of 13 files reviewed at latest revision, 8 unresolved discussions. db.go, line 295 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. db_test.go, line 1526 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. dir_windows.go, line 62 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. options.go, line 93 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. value.go, line 303 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. value.go, line 672 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
Done. value_test.go, line 533 at r2 (raw file): Previously, manishrjain (Manish R Jain) wrote…
The Comments from Reviewable |
Review status: 6 of 13 files reviewed at latest revision, all discussions resolved, some commit checks failed. Comments from Reviewable |
This introduces a read-only option on the DB struct. The main effect is to force all transactions to be read-only. It also skips anything that might write to disk.
It will put a shared lock on the directory when it's opened read-only. This will allow other read-only opens but will deny read-write opens until all readers have closed. If the database is already open read-write and an attempt is made to open it again (read-only or read-write), an error occurs.
It also:
This change assumes that there will be no need to write anything during read-only operations, no need to do garbage collection or compaction or revising vlogs or anything. I'm not sure that this is a 100% valid assumption.
This addresses #372
This change is