Skip to content

Commit 60d6db6

Browse files
authored
[-] add compacted revision handler, fixes #208 (#217)
1 parent b5d471f commit 60d6db6

3 files changed

Lines changed: 79 additions & 111 deletions

File tree

checker/etcd_leader_checker.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"context"
55
"crypto/tls"
66
"crypto/x509"
7+
"errors"
78
"fmt"
89
"log"
910
"os"
1011
"time"
1112

1213
"github.com/cybertec-postgresql/vip-manager/vipconfig"
14+
rpcv3 "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
1315
clientv3 "go.etcd.io/etcd/client/v3"
1416
)
1517

@@ -69,8 +71,8 @@ func getTransport(conf *vipconfig.Config) (*tls.Config, error) {
6971
return tlsClientConfig, nil
7072
}
7173

72-
// init gets the current leader from etcd
73-
func (elc *EtcdLeaderChecker) init(ctx context.Context, out chan<- bool) {
74+
// get gets the current leader from etcd
75+
func (elc *EtcdLeaderChecker) get(ctx context.Context, out chan<- bool) {
7476
resp, err := elc.Get(ctx, elc.Key)
7577
if err != nil {
7678
log.Printf("etcd error: %s", err)
@@ -93,8 +95,12 @@ func (elc *EtcdLeaderChecker) watch(ctx context.Context, out chan<- bool) error
9395
return ctx.Err()
9496
case watchResp := <-watchChan:
9597
if err := watchResp.Err(); err != nil {
96-
log.Printf("etcd watcher returned error: %s", err)
97-
out <- false
98+
if errors.Is(err, rpcv3.ErrCompacted) { // revision is compacted, try direct get key
99+
elc.get(ctx, out)
100+
} else {
101+
log.Printf("etcd watcher returned error: %s", err)
102+
out <- false
103+
}
98104
continue
99105
}
100106
for _, event := range watchResp.Events {
@@ -108,7 +114,7 @@ func (elc *EtcdLeaderChecker) watch(ctx context.Context, out chan<- bool) error
108114
// GetChangeNotificationStream monitors the leader in etcd
109115
func (elc *EtcdLeaderChecker) GetChangeNotificationStream(ctx context.Context, out chan<- bool) error {
110116
defer elc.Close()
111-
go elc.init(ctx, out)
117+
go elc.get(ctx, out)
112118
wctx, cancel := context.WithCancel(ctx)
113119
defer cancel()
114120
return elc.watch(wctx, out)

go.mod

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,57 @@ require (
77
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875
88
github.com/spf13/pflag v1.0.5
99
github.com/spf13/viper v1.18.2
10+
go.etcd.io/etcd/api/v3 v3.5.13
1011
go.etcd.io/etcd/client/v3 v3.5.13
1112
golang.org/x/sys v0.19.0
1213
)
1314

1415
require (
15-
github.com/armon/go-metrics v0.4.1 // indirect
16-
github.com/coreos/go-semver v0.3.0 // indirect
17-
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
18-
github.com/fatih/color v1.14.1 // indirect
16+
github.com/armon/go-metrics v0.5.3 // indirect
17+
github.com/coreos/go-semver v0.3.1 // indirect
18+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
19+
github.com/fatih/color v1.16.0 // indirect
1920
github.com/fsnotify/fsnotify v1.7.0 // indirect
2021
github.com/gogo/protobuf v1.3.2 // indirect
2122
github.com/golang/protobuf v1.5.4 // indirect
2223
github.com/hashicorp/errwrap v1.1.0 // indirect
2324
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
24-
github.com/hashicorp/go-hclog v1.5.0 // indirect
25+
github.com/hashicorp/go-hclog v1.6.3 // indirect
2526
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
2627
github.com/hashicorp/go-multierror v1.1.1 // indirect
2728
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
28-
github.com/hashicorp/golang-lru v0.5.4 // indirect
29+
github.com/hashicorp/golang-lru v1.0.2 // indirect
2930
github.com/hashicorp/hcl v1.0.0 // indirect
3031
github.com/hashicorp/serf v0.10.1 // indirect
31-
github.com/josharian/native v1.0.0 // indirect
32+
github.com/josharian/native v1.1.0 // indirect
3233
github.com/magiconair/properties v1.8.7 // indirect
3334
github.com/mattn/go-colorable v0.1.13 // indirect
34-
github.com/mattn/go-isatty v0.0.17 // indirect
35+
github.com/mattn/go-isatty v0.0.20 // indirect
3536
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
36-
github.com/mdlayher/packet v1.0.0 // indirect
37-
github.com/mdlayher/socket v0.2.3 // indirect
37+
github.com/mdlayher/packet v1.1.2 // indirect
38+
github.com/mdlayher/socket v0.5.1 // indirect
3839
github.com/mitchellh/go-homedir v1.1.0 // indirect
3940
github.com/mitchellh/mapstructure v1.5.0 // indirect
40-
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
41+
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
4142
github.com/sagikazarmark/locafero v0.4.0 // indirect
4243
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
4344
github.com/sourcegraph/conc v0.3.0 // indirect
4445
github.com/spf13/afero v1.11.0 // indirect
4546
github.com/spf13/cast v1.6.0 // indirect
4647
github.com/subosito/gotenv v1.6.0 // indirect
47-
go.etcd.io/etcd/api/v3 v3.5.13 // indirect
4848
go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
49-
go.uber.org/atomic v1.9.0 // indirect
50-
go.uber.org/multierr v1.9.0 // indirect
51-
go.uber.org/zap v1.21.0 // indirect
52-
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
53-
golang.org/x/net v0.19.0 // indirect
54-
golang.org/x/sync v0.5.0 // indirect
49+
go.uber.org/multierr v1.11.0 // indirect
50+
go.uber.org/zap v1.27.0 // indirect
51+
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
52+
golang.org/x/net v0.24.0 // indirect
53+
golang.org/x/sync v0.7.0 // indirect
5554
golang.org/x/text v0.14.0 // indirect
56-
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
57-
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
58-
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
59-
google.golang.org/grpc v1.59.0 // indirect
55+
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
56+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
57+
google.golang.org/grpc v1.63.2 // indirect
6058
google.golang.org/protobuf v1.33.0 // indirect
6159
gopkg.in/ini.v1 v1.67.0 // indirect
6260
gopkg.in/yaml.v3 v3.0.1 // indirect
6361
)
6462

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

0 commit comments

Comments
 (0)