-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Is your feature request related to a problem? Please describe
When opening a database directory with WithReadOnly: https://pkg.go.dev/github.com/dgraph-io/badger/v4#Options.WithReadOnly
and when the user running badger only has read permissions for the database files,
then badger produces the following error:
err: while opening file: DISCARD
err: open db/DISCARD: permission denied
unable to open: db/DISCARD
Describe the solution you'd like
Badger shouldn't try to write to (or create) the DISCARD file: https://github.com/dgraph-io/badger/blob/v4.7.0/discard.go#L29-L35 when in read-only mode.
Using DISCARD seems to be unavoidable currently, except for in-memory mode: https://github.com/dgraph-io/badger/blob/v4.7.0/value.go#L538-L544
Describe alternatives you've considered
I'm currently working around this by loading a copy of the database from a writeable directory.
But ideally, I'd like to drop the workaround.
(If needed I can elaborate on why I consume a read-only database in the first place)
Additional context
Found the PR that introduced the read-only mode:
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.
#432
And the commit that introduced "discard stats" as separate file:
- Discard stats are now stored in a separate file, instead of within the LSM tree.
- GC only picks up value logs based off discard stats.
- GC no longer does sampling, it uses discard stats to inform when a value log needs to be GCed.
I might be wrong, but to me it looks like discard stats & GC weren't intended to be active during read-only mode.
And if they weren't, it seems like it would solve the issue I'm facing?
Just my rough guess - I didn't spend enough time with badger's internals to properly evaluate that.
I'd appreciate any help or input! :)