You need to run this twice. On the second run badger will try to truncate mem file and it is the core of the problem:
package main
import (
"log"
"github.com/dgraph-io/badger/v3"
)
func main() {
_, err := badger.Open(badger.DefaultOptions("/tmp/badger"))
if err != nil {
log.Fatal(err)
}
//defer db.Close() // It's a requirement condition, not to close db
}
On the second run you will have the following error:
2021/08/20 08:37:31 while opening memtables error: while opening fid: 5 error: while updating skiplist error: mremap size mismatch: requested: 20 got: 134217728
exit status 1
This error can only be reproduced on ARM64. The same script will work correctly on AMD64.
As I understood the problem lies within the mremap implementation in the ristretto library.
This is exactly a serious problem. As the ristretto library and badger are all Golang programs and never claim they are only compatible with AMD64 architecture. We are having the same issue as well.
Great to see this merged. I tried to advantage of it via having run go get -u github.com/dgraph-io/ristretto@c2901dc76889a90201a15b9cfc3c04bbfe0c298c but I still got an error with making the memory map. I’ve reverted to Badger v2 and am using FileIO. My projects are on Pi3, so it might have been related to the severe memory limitations. Eventually I’d like to use a Pi4 and dig in a bit more.
Badger still seems fairly unstable on my Raspberry Pi 4. I’m seeing data loss when writing lots of data and there’s nothing in debug logs. Not sure what to do but give up and use AMD64