Explorar el Código

Add with serial consistency support

Add an option to Query to set the serial consistency for the
conditional update phase of a query.
Chris Bannister hace 10 años
padre
commit
4eb0e0532e
Se han modificado 4 ficheros con 21 adiciones y 2 borrados
  1. 1 0
      cassandra_test.go
  2. 1 0
      cluster.go
  3. 4 1
      conn.go
  4. 15 1
      session.go

+ 1 - 0
cassandra_test.go

@@ -251,6 +251,7 @@ func TestCAS(t *testing.T) {
 
 	session := createSession(t)
 	defer session.Close()
+	session.cfg.SerialConsistency = LocalSerial
 
 	if err := createTable(session, `CREATE TABLE cas_table (
 			title         varchar,

+ 1 - 0
cluster.go

@@ -73,6 +73,7 @@ type ClusterConfig struct {
 	MaxPreparedStmts  int           // Sets the maximum cache size for prepared statements globally for gocql (default: 1000)
 	MaxRoutingKeyInfo int           // Sets the maximum cache size for query info about statements for each session (default: 1000)
 	PageSize          int           // Default page size to use for created sessions (default: 0)
+	SerialConsistency Consistency   // Sets the consistency for the serial part of queries, values can be either SERIAL or LOCAL_SERIAL (default: unset)
 	Discovery         DiscoveryConfig
 	SslOpts           *SslOptions
 }

+ 4 - 1
conn.go

@@ -434,7 +434,10 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
 		consistency: qry.cons,
 	}
 
-	// TODO: Add DefaultTimestamp, SerialConsistency
+	// frame checks that it is not 0
+	params.serialConsistency = qry.serialCons
+
+	// TODO: Add DefaultTimestamp
 	if len(qry.pageState) > 0 {
 		params.pagingState = qry.pageState
 	}

+ 15 - 1
session.go

@@ -96,7 +96,7 @@ func (s *Session) Query(stmt string, values ...interface{}) *Query {
 	s.mu.RLock()
 	qry := &Query{stmt: stmt, values: values, cons: s.cons,
 		session: s, pageSize: s.pageSize, trace: s.trace,
-		prefetch: s.prefetch, rt: s.cfg.RetryPolicy}
+		prefetch: s.prefetch, rt: s.cfg.RetryPolicy, serialCons: s.cfg.SerialConsistency}
 	s.mu.RUnlock()
 	return qry
 }
@@ -372,6 +372,7 @@ type Query struct {
 	binding      func(q *QueryInfo) ([]interface{}, error)
 	attempts     int
 	totalLatency int64
+	serialCons   Consistency
 }
 
 //Attempts returns the number of times the query was executed.
@@ -517,6 +518,19 @@ func (q *Query) Bind(v ...interface{}) *Query {
 	return q
 }
 
+// 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.
+func (q *Query) SerialConsistency(cons Consistency) *Query {
+	if !(cons == Serial || cons == LocalSerial) {
+		panic("only acceptable consistency for serial_consistency is SERIAL or LOCAL_SERIAL")
+	}
+	q.serialCons = cons
+	return q
+}
+
 // Exec executes the query without returning any rows.
 func (q *Query) Exec() error {
 	iter := q.Iter()