Explorar el Código

mvcc/backend: defrag to block concurrent read requests while resetting tx

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee hace 8 años
padre
commit
6c40b2b5d4
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      mvcc/backend/backend.go

+ 6 - 1
mvcc/backend/backend.go

@@ -304,7 +304,12 @@ func (b *backend) defrag() error {
 	b.mu.Lock()
 	defer b.mu.Unlock()
 
-	b.batchTx.commit(true)
+	// block concurrent read requests while resetting tx
+	b.readTx.mu.Lock()
+	defer b.readTx.mu.Unlock()
+
+	b.batchTx.unsafeCommit(true)
+
 	b.batchTx.tx = nil
 
 	tmpdb, err := bolt.Open(b.db.Path()+".tmp", 0600, boltOpenOptions)