Badger db returns an empty value and empty error when item.Value() called


Our team has encountered problems with badger Read.
The symptom of the problem is that it fails to read value what normally written to the badger db.
We have not figured out the exact cause yet, but we are guessing roughly.

The code that fails is:

Item, err := txn.Get(key)
value, err:= item.Value() // problem point, both value and err are nil.

I checked When the value and error nil.
I find the following code in the yieldItemValue() of the iterator.go that item.Value() calls and I think it is a problem.

if vs.Version != item.Version() {
    return nil, nil, nil

So, the problem is that the version of the valueStruct is different from the version of the item. (edited)
I looked for when the version could be different.

In fact, we run compaction(RunValueLogGC()) quite often.
Actually, RunValueLogGC()(More specifically, RunValueLogGC’s valueLog.rewrite()) is run as a batch.

When doing the valueLog.rewrite() operation,
Let’s assume that the document with key A that changed to !badger!moveA in the previous rewrite in logFile(old version) and the newly updated same key A document exists in the log file at the same time (new version).

Both !badger!moveA and A will be !badger!moveA during rewrite.
What if the new version of the document is rewritten first and the old version of the document is later overwritten with the key’s document?
Is there only old version of the document in logFile?

And later, when reading from item.value (), It will find the document of the new version, but since the two versions are different, does value and err return nil at the end?

I wonder what your thoughts are like.
Is this make sense? Will it happen?
I’ll wait for your answer. Thank you.

Can you try master? This seems like an older version of Badger.

We used version 1.5.4 of badger.
Is this an old version?
There seems to be no difference at valueLog rewrite between version 1.5.4 and the master.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.