Skip to content

Commit fcd5565

Browse files
committed
Support of keyspace field for BATCH message
1 parent 974fa12 commit fcd5565

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

conn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,10 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
15541554
customPayload: batch.CustomPayload,
15551555
}
15561556

1557+
if c.version > protoVersion4 {
1558+
req.keyspace = c.currentKeyspace
1559+
}
1560+
15571561
stmts := make(map[string]string, len(batch.Entries))
15581562

15591563
for i := 0; i < n; i++ {

frame.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,9 @@ type writeBatchFrame struct {
16591659

16601660
//v4+
16611661
customPayload map[string][]byte
1662+
1663+
//v5+
1664+
keyspace string
16621665
}
16631666

16641667
func (w *writeBatchFrame) buildFrame(framer *framer, streamID int) error {
@@ -1718,6 +1721,13 @@ func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload
17181721
flags |= flagDefaultTimestamp
17191722
}
17201723

1724+
if w.keyspace != "" {
1725+
if f.proto < protoVersion5 {
1726+
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
1727+
}
1728+
flags |= flagWithKeyspace
1729+
}
1730+
17211731
if f.proto > protoVersion4 {
17221732
f.writeUint(uint32(flags))
17231733
} else {
@@ -1737,6 +1747,10 @@ func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload
17371747
}
17381748
f.writeLong(ts)
17391749
}
1750+
1751+
if w.keyspace != "" {
1752+
f.writeString(w.keyspace)
1753+
}
17401754
}
17411755

17421756
return f.finish()

0 commit comments

Comments
 (0)