Skip to content

Commit

Permalink
[-] add compacted revision handler, fixes #208 (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub authored Apr 22, 2024
1 parent b5d471f commit 60d6db6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 111 deletions.
16 changes: 11 additions & 5 deletions checker/etcd_leader_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"log"
"os"
"time"

"github.com/cybertec-postgresql/vip-manager/vipconfig"
rpcv3 "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
clientv3 "go.etcd.io/etcd/client/v3"
)

Expand Down Expand Up @@ -69,8 +71,8 @@ func getTransport(conf *vipconfig.Config) (*tls.Config, error) {
return tlsClientConfig, nil
}

// init gets the current leader from etcd
func (elc *EtcdLeaderChecker) init(ctx context.Context, out chan<- bool) {
// get gets the current leader from etcd
func (elc *EtcdLeaderChecker) get(ctx context.Context, out chan<- bool) {
resp, err := elc.Get(ctx, elc.Key)
if err != nil {
log.Printf("etcd error: %s", err)
Expand All @@ -93,8 +95,12 @@ func (elc *EtcdLeaderChecker) watch(ctx context.Context, out chan<- bool) error
return ctx.Err()
case watchResp := <-watchChan:
if err := watchResp.Err(); err != nil {
log.Printf("etcd watcher returned error: %s", err)
out <- false
if errors.Is(err, rpcv3.ErrCompacted) { // revision is compacted, try direct get key
elc.get(ctx, out)
} else {
log.Printf("etcd watcher returned error: %s", err)
out <- false
}
continue
}
for _, event := range watchResp.Events {
Expand All @@ -108,7 +114,7 @@ func (elc *EtcdLeaderChecker) watch(ctx context.Context, out chan<- bool) error
// GetChangeNotificationStream monitors the leader in etcd
func (elc *EtcdLeaderChecker) GetChangeNotificationStream(ctx context.Context, out chan<- bool) error {
defer elc.Close()
go elc.init(ctx, out)
go elc.get(ctx, out)
wctx, cancel := context.WithCancel(ctx)
defer cancel()
return elc.watch(wctx, out)
Expand Down
44 changes: 21 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,57 @@ require (
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
go.etcd.io/etcd/api/v3 v3.5.13
go.etcd.io/etcd/client/v3 v3.5.13
golang.org/x/sys v0.19.0
)

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/armon/go-metrics v0.5.3 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/josharian/native v1.0.0 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
github.com/mdlayher/packet v1.0.0 // indirect
github.com/mdlayher/socket v0.2.3 // indirect
github.com/mdlayher/packet v1.1.2 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.13 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace google.golang.org/grpc => google.golang.org/grpc v1.29.0
replace github.com/armon/go-metrics => github.com/hashicorp/go-metrics v0.5.3
Loading

0 comments on commit 60d6db6

Please sign in to comment.