فهرست منبع

storage: return error when tombstone on new generation

It is not allowed to put tombstone on an empty generation.
Yicheng Qin 10 سال پیش
والد
کامیت
ad8a291dc1
2فایلهای تغییر یافته به همراه7 افزوده شده و 3 حذف شده
  1. 1 2
      storage/index.go
  2. 6 1
      storage/key_index.go

+ 1 - 2
storage/index.go

@@ -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{} {

+ 6 - 1
storage/key_index.go

@@ -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.