storage: return error when tombstone on new generation

It is not allowed to put tombstone on an empty generation.
This commit is contained in:
Yicheng Qin 2015-08-24 23:52:14 -07:00
parent ffa87f9678
commit ad8a291dc1
2 changed files with 7 additions and 3 deletions

View File

@ -115,8 +115,7 @@ func (ti *treeIndex) Tombstone(key []byte, rev revision) error {
}
ki := item.(*keyIndex)
ki.tombstone(rev.main, rev.sub)
return nil
return ki.tombstone(rev.main, rev.sub)
}
func (ti *treeIndex) Compact(rev int64) map[revision]struct{} {

View File

@ -90,12 +90,17 @@ func (ki *keyIndex) restore(created, modified revision, ver int64) {
// tombstone puts a revision, pointing to a tombstone, to the keyIndex.
// It also creates a new empty generation in the keyIndex.
func (ki *keyIndex) tombstone(main int64, sub int64) {
// It returns ErrRevisionNotFound when tombstone on an empty generation.
func (ki *keyIndex) tombstone(main int64, sub int64) error {
if ki.isEmpty() {
log.Panicf("store.keyindex: unexpected tombstone on empty keyIndex %s", string(ki.key))
}
if ki.generations[len(ki.generations)-1].isEmpty() {
return ErrRevisionNotFound
}
ki.put(main, sub)
ki.generations = append(ki.generations, generation{})
return nil
}
// get gets the modified, created revision and version of the key that satisfies the given atRev.