Переглянути джерело

storage: delete key instead of setting it to false

When getting the watched events, it iterate all keys in putm and delm
to generate the events. If we don't delete the key from putm/delm,
it would range on the key that is not actually put or deleted. This is
incorrect.

Fix the panic that happens when single put/delete is watched.
Yicheng Qin 10 роки тому
батько
коміт
6dbfc21846
1 змінених файлів з 6 додано та 2 видалено
  1. 6 2
      storage/watchable_store.go

+ 6 - 2
storage/watchable_store.go

@@ -317,12 +317,16 @@ func newOngoingTx() *ongoingTx {
 
 
 func (tx *ongoingTx) put(k string) {
 func (tx *ongoingTx) put(k string) {
 	tx.putm[k] = true
 	tx.putm[k] = true
-	tx.delm[k] = false
+	if _, ok := tx.delm[k]; ok {
+		delete(tx.delm, k)
+	}
 }
 }
 
 
 func (tx *ongoingTx) del(k string) {
 func (tx *ongoingTx) del(k string) {
 	tx.delm[k] = true
 	tx.delm[k] = true
-	tx.putm[k] = false
+	if _, ok := tx.putm[k]; ok {
+		delete(tx.putm, k)
+	}
 }
 }
 
 
 type watching struct {
 type watching struct {