Skip to content

Commit

Permalink
Add parsing TABLETS_ROUTING_V1 extension
Browse files Browse the repository at this point in the history
In order for Scylla to send the tablet info, the driver must tell
the database during connection handshake that it is able to
interpret it. It was implemented similarly to the
already-present LWT optimisation extension negotiation.
  • Loading branch information
sylwiaszunejko committed Jan 4, 2024
1 parent c8ac817 commit 1bdb234
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,16 @@ func newFramerWithExts(compressor Compressor, version byte, cqlProtoExts []cqlPr
f.rateLimitingErrorCode = castedExt.rateLimitErrorCode
}

if tabletsExt := findCQLProtoExtByName(cqlProtoExts, tabletsRoutingV1); tabletsExt != nil {
_, ok := tabletsExt.(*tabletsRoutingV1Ext)
if !ok {
Logger.Println(
fmt.Errorf("Failed to cast CQL protocol extension identified by name %s to type %T",
tabletsRoutingV1, tabletsRoutingV1Ext{}))
return f
}
}

return f
}

Expand Down
35 changes: 35 additions & 0 deletions scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,38 @@ func findCQLProtoExtByName(exts []cqlProtocolExtension, name string) cqlProtocol
const (
lwtAddMetadataMarkKey = "SCYLLA_LWT_ADD_METADATA_MARK"
rateLimitError = "SCYLLA_RATE_LIMIT_ERROR"
tabletsRoutingV1 = "TABLETS_ROUTING_V1"
)

// "tabletsRoutingV1" CQL Protocol Extension.
// This extension, if enabled (properly negotiated), allows Scylla server
// to send a tablet information in `custom_payload`.
//
// Implements cqlProtocolExtension interface.
type tabletsRoutingV1Ext struct {
}

var _ cqlProtocolExtension = &tabletsRoutingV1Ext{}

// Factory function to deserialize and create an `tabletsRoutingV1Ext` instance
// from SUPPORTED message payload.
func newTabletsRoutingV1Ext(supported map[string][]string) *tabletsRoutingV1Ext {
if _, found := supported[tabletsRoutingV1]; found {
return &tabletsRoutingV1Ext{}
}
return nil
}

func (ext *tabletsRoutingV1Ext) serialize() map[string]string {
return map[string]string{
tabletsRoutingV1: "",
}
}

func (ext *tabletsRoutingV1Ext) name() string {
return tabletsRoutingV1
}

// "Rate limit" CQL Protocol Extension.
// This extension, if enabled (properly negotiated), allows Scylla server
// to send a special kind of error.
Expand Down Expand Up @@ -243,6 +273,11 @@ func parseCQLProtocolExtensions(supported map[string][]string) []cqlProtocolExte
exts = append(exts, rateLimitExt)
}

tabletsExt := newTabletsRoutingV1Ext(supported)
if tabletsExt != nil {
exts = append(exts, tabletsExt)
}

return exts
}

Expand Down

0 comments on commit 1bdb234

Please sign in to comment.