While opening memtables error: while opening fid: 1 error: while updating skiplist error: while truncate file: /tmp/badger/00001.mem, error: truncate /tmp/badger/00001.mem: invalid argument

What version of Go are you using (go version)?

$ go version
1.14.2

What operating system are you using?

Ubuntu 20.04.2 LTS

What version of Badger are you using?

v3.2011.1

Does this issue reproduce with the latest master?

Yes

Steps to Reproduce the issue

nothing simple open database like:

bdb, err := badger.Open(badger.DefaultOptions("/tmp/badger"))
	if err != nil {
		log.Fatal(errorPrint(err.Error(), DB102))
	}
	defer bdb.Close()

And on panic error in the application, when the application got crashed and stop, during restart, app can no longer start as it is throwing above error.

What did you do?

Just do ./app

What did you expect to see?

Running of an app successfully but getting an error

What did you see instead?

while opening memtables error: while opening fid: 1 error: while updating skiplist error: while truncate file: /tmp/badger/00001.mem, error: truncate /tmp/badger/00001.mem: invalid argument

That’s because in the crash, the file /tmp/badger is not cleaned up. Simply delete the file and it should work…

@ibrahim should we add a post-panic cleanup process at the top level?

Simply deleting the file will also delete all database, what if we need to keep database?

You probably need to pass read only = false option. And a truncate option. Look in options.

I have not set read only = false, but I assume this should be default as it is DB, there is 1 or 10 out of 100 chances that someone uses it for the read-only.

Edit:
I have set the ReadOnly=false now, But can’t find “truncate” option in “options.go” file, my badger version is v3.2011.1, am I missing something?

Thanks

If nothing else works, delete the .mem file.

1 Like