Panic: Index Cache must be set for encrypted workloads [recovered]

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

$ go version
1.16.3

What operating system are you using?

macos big sur

What version of Badger are you using?

v3.2011.1

Does this issue reproduce with the latest master?

Steps to Reproduce the issue

Opening badger db something like this

func BadgerDB(storePath string) {
var newClient BadgerDbClient

opts := badger.DefaultOptions(storePath)

opts.Dir = storePath
opts.ValueDir = storePath
opts.DetectConflicts = true
opts.CompactL0OnClose = true
opts.Logger = nil
opts.SyncWrites = true 
opts.EncryptionKey = encryptionkey
opts.EncryptionKeyRotationDuration = 24 * time.Hour 

client, err := badger.Open(opts)
if err != nil {
	log.Errorln("DBProvider() failed to open", newClient.Err)
	return &newClient
} else {
	return &newClient
}

}

What Badger options were set?

opts.Dir = storePath
opts.ValueDir = storePath
opts.DetectConflicts = true
opts.CompactL0OnClose = true
opts.Logger = nil
opts.SyncWrites = true
opts.EncryptionKey = encryptionkey
opts.EncryptionKeyRotationDuration = 24 * time.Hour

What did you do?

Able to open the db the first time, however after closing it an attempt to reopen panics

What did you expect to see?

Able to open the db

What did you see instead?

panic: Index Cache must be set for encrypted workloads [recovered]
panic:
== Recovering from initIndex crash ==
File Info: [ID: 1, Size: 814, Zeros: 0]
isEnrypted: true checksumLen: 6 checksum: sum:1381902636 indexLen: 208 index:

Are there additional configuration that must be added to ensure proper reopening of the DB?

hey @sup, you need to set the index cache size since you have encryption enabled.
With encryption, your reads would be very slow and having a cache would improve the performance.

Please set the

opts.IndexCache = 100 << 20 // 100 mb or some other size based on the amount of data

See this as well

@ibrahim thanks! exactly what I was missing. Could this be somehow made more evident in the documentation, I couldn’t find this in the getting started guide - Get started —

1 Like

@hardik let’s add this somewhere in the docs ^

1 Like