Ver código fonte

Add SerialConsistency to Batch to mirror Query

Chris Bannister 10 anos atrás
pai
commit
feac633a80
2 arquivos alterados com 18 adições e 4 exclusões
  1. 4 3
      conn.go
  2. 14 1
      session.go

+ 4 - 3
conn.go

@@ -605,9 +605,10 @@ func (c *Conn) executeBatch(batch *Batch) error {
 
 	n := len(batch.Entries)
 	req := &writeBatchFrame{
-		typ:         batch.Type,
-		statements:  make([]batchStatment, n),
-		consistency: batch.Cons,
+		typ:               batch.Type,
+		statements:        make([]batchStatment, n),
+		consistency:       batch.Cons,
+		serialConsistency: batch.serialCons,
 	}
 
 	stmts := make(map[string]string)

+ 14 - 1
session.go

@@ -698,6 +698,7 @@ type Batch struct {
 	rt           RetryPolicy
 	attempts     int
 	totalLatency int64
+	serialCons   Consistency
 }
 
 // NewBatch creates a new batch operation without defaults from the cluster
@@ -707,7 +708,7 @@ func NewBatch(typ BatchType) *Batch {
 
 // NewBatch creates a new batch operation using defaults defined in the cluster
 func (s *Session) NewBatch(typ BatchType) *Batch {
-	return &Batch{Type: typ, rt: s.cfg.RetryPolicy}
+	return &Batch{Type: typ, rt: s.cfg.RetryPolicy, serialCons: s.cfg.SerialConsistency}
 }
 
 // Attempts returns the number of attempts made to execute the batch.
@@ -752,6 +753,18 @@ func (b *Batch) Size() int {
 	return len(b.Entries)
 }
 
+// SerialConsistency sets the consistencyc level for the
+// serial phase of conditional updates. That consitency can only be
+// either SERIAL or LOCAL_SERIAL and if not present, it defaults to
+// SERIAL. This option will be ignored for anything else that a
+// conditional update/insert.
+//
+// Only available for protocol 3 and above
+func (b *Batch) SerialConsistency(cons Consistency) *Batch {
+	b.serialCons = cons
+	return b
+}
+
 type BatchType byte
 
 const (