瀏覽代碼

If a batch fails because of an unprepared statement, reprepare the statement and redo the batch.

Nimi Wariboko Jr 11 年之前
父節點
當前提交
5f2aeff0ed
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      conn.go

+ 17 - 0
conn.go

@@ -6,6 +6,7 @@ package gocql
 
 import (
 	"bufio"
+	"bytes"
 	"fmt"
 	"net"
 	"sync"
@@ -504,6 +505,22 @@ func (c *Conn) executeBatch(batch *Batch) error {
 	switch x := resp.(type) {
 	case resultVoidFrame:
 		return nil
+	case RequestErrUnprepared:
+		c.prepMu.Lock()
+		found := false
+		for stmt, flight := range c.prep {
+			if bytes.Equal(flight.info.id, x.StatementId) {
+				found = true
+				delete(c.prep, stmt)
+				break
+			}
+		}
+		c.prepMu.Unlock()
+		if found {
+			return c.executeBatch(batch)
+		} else {
+			return x
+		}
 	case error:
 		return x
 	default: