From 195f8ab610e13dd224753b3414f25075f80f9147 Mon Sep 17 00:00:00 2001 From: Shaad7 Date: Mon, 8 May 2023 15:34:54 +0600 Subject: [PATCH] Export TLS Handler fields Signed-off-by: Shaad7 --- go.mod | 2 +- go.sum | 4 +- pkg/redisdump/tlsutils.go | 28 +++++----- .../mediocregopher/radix/v3/CHANGELOG.md | 10 ++++ .../mediocregopher/radix/v3/README.md | 4 ++ .../mediocregopher/radix/v3/cluster.go | 25 +++++++-- .../mediocregopher/radix/v3/cluster_topo.go | 55 +++++++++++++++---- vendor/modules.txt | 2 +- 8 files changed, 94 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 11245d2..c4850b7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/yannh/redis-dump-go go 1.18 require ( - github.com/mediocregopher/radix/v3 v3.8.0 + github.com/mediocregopher/radix/v3 v3.8.1 github.com/pkg/errors v0.9.1 ) diff --git a/go.sum b/go.sum index 311d53c..436d04b 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/mediocregopher/radix/v3 v3.8.0 h1:HI8EgkaM7WzsrFpYAkOXIgUKbjNonb2Ne7K6Le61Pmg= -github.com/mediocregopher/radix/v3 v3.8.0/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= +github.com/mediocregopher/radix/v3 v3.8.1 h1:rOkHflVuulFKlwsLY01/M2cM2tWCjDoETcMqKbAWu1M= +github.com/mediocregopher/radix/v3 v3.8.1/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/pkg/redisdump/tlsutils.go b/pkg/redisdump/tlsutils.go index 3aa3804..9d26fab 100644 --- a/pkg/redisdump/tlsutils.go +++ b/pkg/redisdump/tlsutils.go @@ -9,17 +9,17 @@ import ( ) type TlsHandler struct { - skipVerify bool - caCertPath string - certPath string - keyPath string + SkipVerify bool + CACertPath string + CertPath string + KeyPath string } func NewTlsHandler(caCertPath, certPath, keyPath string, insecure bool) (*TlsHandler, error) { if caCertPath == "" && certPath == "" && keyPath == "" { if insecure { return &TlsHandler{ - skipVerify: true, + SkipVerify: true, }, nil } else { return nil, errors.New("no cert is set. if skip cert validation to set -insecure option") @@ -27,10 +27,10 @@ func NewTlsHandler(caCertPath, certPath, keyPath string, insecure bool) (*TlsHan } return &TlsHandler{ - skipVerify: false, - caCertPath: caCertPath, - certPath: certPath, - keyPath: keyPath, + SkipVerify: false, + CACertPath: caCertPath, + CertPath: certPath, + KeyPath: keyPath, }, nil } @@ -39,7 +39,7 @@ func tlsConfig(tlsHandler *TlsHandler) (*tls.Config, error) { return nil, nil } - if tlsHandler.skipVerify { + if tlsHandler.SkipVerify { return &tls.Config{ InsecureSkipVerify: true, }, nil @@ -47,8 +47,8 @@ func tlsConfig(tlsHandler *TlsHandler) (*tls.Config, error) { certPool := x509.NewCertPool() // ca cert is optional - if tlsHandler.caCertPath != "" { - pem, err := ioutil.ReadFile(tlsHandler.caCertPath) + if tlsHandler.CACertPath != "" { + pem, err := ioutil.ReadFile(tlsHandler.CACertPath) if err != nil { return nil, fmt.Errorf("connectionpool: unable to open CA certs: %v", err) } @@ -63,8 +63,8 @@ func tlsConfig(tlsHandler *TlsHandler) (*tls.Config, error) { RootCAs: certPool, } - if tlsHandler.certPath != "" && tlsHandler.keyPath != "" { - cert, err := tls.LoadX509KeyPair(tlsHandler.certPath, tlsHandler.keyPath) + if tlsHandler.CertPath != "" && tlsHandler.KeyPath != "" { + cert, err := tls.LoadX509KeyPair(tlsHandler.CertPath, tlsHandler.KeyPath) if err != nil { return nil, err } diff --git a/vendor/github.com/mediocregopher/radix/v3/CHANGELOG.md b/vendor/github.com/mediocregopher/radix/v3/CHANGELOG.md index 1a04e28..642fbe6 100644 --- a/vendor/github.com/mediocregopher/radix/v3/CHANGELOG.md +++ b/vendor/github.com/mediocregopher/radix/v3/CHANGELOG.md @@ -1,5 +1,15 @@ Changelog from v3.0.1 and up. Prior changes don't have a changelog. +# v3.8.1 + +* Fixed `NewCluster` not returning an error if it can't connect to any of the + redis instances given. (#319) + +* Fix deadlock in `Cluster` when using `DoSecondary`. (#317) + +* Fix parsing for `CLUSTER SLOTS` command, which changed slightly with redis + 7.0. (#322) + # v3.8.0 **New** diff --git a/vendor/github.com/mediocregopher/radix/v3/README.md b/vendor/github.com/mediocregopher/radix/v3/README.md index 4ad0763..588398d 100644 --- a/vendor/github.com/mediocregopher/radix/v3/README.md +++ b/vendor/github.com/mediocregopher/radix/v3/README.md @@ -7,6 +7,10 @@ below for documentation and general usage examples. **[v4 Documentation](https://pkg.go.dev/github.com/mediocregopher/radix/v4#section-documentation)** +**[Discussion/Support Chat](https://matrix.to/#/#radix:waffle.farm)** + +Please open an issue, or start a discussion in the chat, before opening a pull request! + ## Features * Standard print-like API which supports **all current and future redis commands**. diff --git a/vendor/github.com/mediocregopher/radix/v3/cluster.go b/vendor/github.com/mediocregopher/radix/v3/cluster.go index 5c47271..7de66a5 100644 --- a/vendor/github.com/mediocregopher/radix/v3/cluster.go +++ b/vendor/github.com/mediocregopher/radix/v3/cluster.go @@ -201,16 +201,24 @@ func NewCluster(clusterAddrs []string, opts ...ClusterOpt) (*Cluster, error) { } } + var err error + // make a pool to base the cluster on for _, addr := range clusterAddrs { - p, err := c.co.pf("tcp", addr) - if err != nil { + + var p Client + + if p, err = c.co.pf("tcp", addr); err != nil { continue } c.pools[addr] = p break } + if len(c.pools) == 0 { + return nil, fmt.Errorf("could not connect to any redis instances, last error was: %w", err) + } + p, err := c.pool("") if err != nil { for _, p := range c.pools { @@ -486,10 +494,9 @@ func (c *Cluster) syncEvery(d time.Duration) { }() } -func (c *Cluster) addrForKey(key string) string { +// v3.8.5 add the getting master node without lock to fix the fix deadlock. +func (c *Cluster) addrForKeyWithNoLock(key string) string { s := ClusterSlot([]byte(key)) - c.l.RLock() - defer c.l.RUnlock() for _, t := range c.primTopo { for _, slot := range t.Slots { if s >= slot[0] && s < slot[1] { @@ -500,10 +507,16 @@ func (c *Cluster) addrForKey(key string) string { return "" } +func (c *Cluster) addrForKey(key string) string { + c.l.RLock() + defer c.l.RUnlock() + return c.addrForKeyWithNoLock(key) +} + func (c *Cluster) secondaryAddrForKey(key string) string { c.l.RLock() defer c.l.RUnlock() - primAddr := c.addrForKey(key) + primAddr := c.addrForKeyWithNoLock(key) for addr := range c.secondaries[primAddr] { return addr } diff --git a/vendor/github.com/mediocregopher/radix/v3/cluster_topo.go b/vendor/github.com/mediocregopher/radix/v3/cluster_topo.go index b105a0a..9398889 100644 --- a/vendor/github.com/mediocregopher/radix/v3/cluster_topo.go +++ b/vendor/github.com/mediocregopher/radix/v3/cluster_topo.go @@ -6,6 +6,7 @@ import ( "io" "net" "sort" + "strconv" "github.com/mediocregopher/radix/v3/resp" "github.com/mediocregopher/radix/v3/resp/resp2" @@ -157,8 +158,15 @@ func (tss topoSlotSet) MarshalRESP(w io.Writer) error { marshal(resp2.Any{I: tss.slots[1] - 1}) for _, n := range tss.nodes { - host, port, _ := net.SplitHostPort(n.Addr) - node := []string{host, port} + + host, portStr, _ := net.SplitHostPort(n.Addr) + + port, err := strconv.Atoi(portStr) + if err != nil { + return err + } + + node := []interface{}{host, port} if n.ID != "" { node = append(node, n.ID) } @@ -186,21 +194,44 @@ func (tss *topoSlotSet) UnmarshalRESP(br *bufio.Reader) error { var primaryNode ClusterNode for i := 0; i < arrHead.N; i++ { - var nodeStrs []string - if err := (resp2.Any{I: &nodeStrs}).UnmarshalRESP(br); err != nil { + + var nodeArrHead resp2.ArrayHeader + if err := nodeArrHead.UnmarshalRESP(br); err != nil { + return err + } else if nodeArrHead.N < 2 { + return fmt.Errorf("expected at least 2 array elements, got %d", nodeArrHead.N) + } + + var ip resp2.BulkString + if err := ip.UnmarshalRESP(br); err != nil { return err - } else if len(nodeStrs) < 2 { - return fmt.Errorf("malformed node array: %#v", nodeStrs) } - ip, port := nodeStrs[0], nodeStrs[1] - var id string - if len(nodeStrs) > 2 { - id = nodeStrs[2] + + var port resp2.Int + if err := port.UnmarshalRESP(br); err != nil { + return err + } + + nodeArrHead.N -= 2 + + var id resp2.BulkString + if nodeArrHead.N > 0 { + if err := id.UnmarshalRESP(br); err != nil { + return err + } + nodeArrHead.N-- + } + + // discard anything after + for i := 0; i < nodeArrHead.N; i++ { + if err := (resp2.Any{}).UnmarshalRESP(br); err != nil { + return err + } } node := ClusterNode{ - Addr: net.JoinHostPort(ip, port), - ID: id, + Addr: net.JoinHostPort(ip.S, strconv.FormatInt(port.I, 10)), + ID: id.S, Slots: [][2]uint16{tss.slots}, } diff --git a/vendor/modules.txt b/vendor/modules.txt index 3452da7..af97fe9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/mediocregopher/radix/v3 v3.8.0 +# github.com/mediocregopher/radix/v3 v3.8.1 ## explicit; go 1.13 github.com/mediocregopher/radix/v3 github.com/mediocregopher/radix/v3/internal/bytesutil