Fix AtomicPut panic if previous KVPair is not nil and key not exists in boltdb

Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
Chun Chen 2015-09-22 10:18:03 +08:00
parent 79b8613c95
commit 1f9cf17713

View file

@ -257,6 +257,9 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair, opt
return store.ErrKeyModified
}
if previous != nil {
if len(val) == 0 {
return store.ErrKeyNotFound
}
dbIndex = binary.LittleEndian.Uint64(val[:libkvmetadatalen])
if dbIndex != previous.LastIndex {
return store.ErrKeyModified