Browse Source

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

Nimi Wariboko Jr 11 years ago
parent
commit
5f2aeff0ed
1 changed files with 17 additions and 0 deletions
  1. 17 0
      conn.go

+ 17 - 0
conn.go

@@ -6,6 +6,7 @@ package gocql
 
 
 import (
 import (
 	"bufio"
 	"bufio"
+	"bytes"
 	"fmt"
 	"fmt"
 	"net"
 	"net"
 	"sync"
 	"sync"
@@ -504,6 +505,22 @@ func (c *Conn) executeBatch(batch *Batch) error {
 	switch x := resp.(type) {
 	switch x := resp.(type) {
 	case resultVoidFrame:
 	case resultVoidFrame:
 		return nil
 		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:
 	case error:
 		return x
 		return x
 	default:
 	default: