Skip to content

Commit 76a1c5f

Browse files
consistency serial was added
1 parent 953e0df commit 76a1c5f

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

frame.go

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ const (
192192

193193
type Consistency uint16
194194

195+
type SerialConsistency = Consistency
196+
195197
const (
196198
Any Consistency = 0x00
197199
One Consistency = 0x01
@@ -202,6 +204,8 @@ const (
202204
LocalQuorum Consistency = 0x06
203205
EachQuorum Consistency = 0x07
204206
LocalOne Consistency = 0x0A
207+
Serial Consistency = 0x08
208+
LocalSerial Consistency = 0x09
205209
)
206210

207211
func (c Consistency) String() string {
@@ -224,6 +228,10 @@ func (c Consistency) String() string {
224228
return "EACH_QUORUM"
225229
case LocalOne:
226230
return "LOCAL_ONE"
231+
case Serial:
232+
return "SERIAL"
233+
case LocalSerial:
234+
return "LOCAL_SERIAL"
227235
default:
228236
return fmt.Sprintf("UNKNOWN_CONS_0x%x", uint16(c))
229237
}
@@ -253,13 +261,21 @@ func (c *Consistency) UnmarshalText(text []byte) error {
253261
*c = EachQuorum
254262
case "LOCAL_ONE":
255263
*c = LocalOne
264+
case "SERIAL":
265+
*c = Serial
266+
case "LOCAL_SERIAL":
267+
*c = LocalSerial
256268
default:
257269
return fmt.Errorf("invalid consistency %q", string(text))
258270
}
259271

260272
return nil
261273
}
262274

275+
func (c Consistency) IsSerial() bool {
276+
return c == Serial || c == LocalSerial
277+
278+
}
263279
func ParseConsistency(s string) Consistency {
264280
var c Consistency
265281
if err := c.UnmarshalText([]byte(strings.ToUpper(s))); err != nil {
@@ -286,40 +302,35 @@ func MustParseConsistency(s string) (Consistency, error) {
286302
return c, nil
287303
}
288304

289-
type SerialConsistency uint16
290-
291-
const (
292-
Serial SerialConsistency = 0x08
293-
LocalSerial SerialConsistency = 0x09
294-
)
295-
296-
func (s SerialConsistency) String() string {
297-
switch s {
298-
case Serial:
299-
return "SERIAL"
300-
case LocalSerial:
301-
return "LOCAL_SERIAL"
302-
default:
303-
return fmt.Sprintf("UNKNOWN_SERIAL_CONS_0x%x", uint16(s))
304-
}
305-
}
306-
307-
func (s SerialConsistency) MarshalText() (text []byte, err error) {
308-
return []byte(s.String()), nil
309-
}
310-
311-
func (s *SerialConsistency) UnmarshalText(text []byte) error {
312-
switch string(text) {
313-
case "SERIAL":
314-
*s = Serial
315-
case "LOCAL_SERIAL":
316-
*s = LocalSerial
317-
default:
318-
return fmt.Errorf("invalid consistency %q", string(text))
319-
}
320-
321-
return nil
322-
}
305+
//type SerialConsistency = Consistency
306+
//
307+
//func (s SerialConsistency) ToString() string {
308+
// switch s {
309+
// case Serial:
310+
// return "SERIAL"
311+
// case LocalSerial:
312+
// return "LOCAL_SERIAL"
313+
// default:
314+
// return fmt.Sprintf("UNKNOWN_SERIAL_CONS_0x%x", uint16(s))
315+
// }
316+
//}
317+
//
318+
//func (s SerialConsistency) MarshalSerialText() (text []byte, err error) {
319+
// return []byte(s.String()), nil
320+
//}
321+
//
322+
//func (s *SerialConsistency) UnmarshalSerialText(text []byte) error {
323+
// switch string(text) {
324+
// case "SERIAL":
325+
// *s = Serial
326+
// case "LOCAL_SERIAL":
327+
// *s = LocalSerial
328+
// default:
329+
// return fmt.Errorf("invalid consistency %q", string(text))
330+
// }
331+
//
332+
// return nil
333+
//}
323334

324335
const (
325336
apacheCassandraTypePrefix = "org.apache.cassandra.db.marshal."

session.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,9 @@ func (q *Query) Bind(v ...interface{}) *Query {
12651265
// SERIAL. This option will be ignored for anything else that a
12661266
// conditional update/insert.
12671267
func (q *Query) SerialConsistency(cons SerialConsistency) *Query {
1268+
if !cons.IsSerial() {
1269+
panic("Serial consistency can only be SERIAL or LOCAL_SERIAL got " + cons.String())
1270+
}
12681271
q.serialCons = cons
12691272
return q
12701273
}
@@ -1915,6 +1918,9 @@ func (b *Batch) Size() int {
19151918
//
19161919
// Only available for protocol 3 and above
19171920
func (b *Batch) SerialConsistency(cons SerialConsistency) *Batch {
1921+
if !cons.IsSerial() {
1922+
panic("Serial consistency can only be SERIAL or LOCAL_SERIAL got " + cons.String())
1923+
}
19181924
b.serialCons = cons
19191925
return b
19201926
}

0 commit comments

Comments
 (0)