Skip to content

Commit 7e560bb

Browse files
committed
make etcd periodic member sync configurable and optional
fix #137
1 parent 1d84310 commit 7e560bb

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

store/etcd/etcd.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type etcdLock struct {
4040
}
4141

4242
const (
43-
periodicSync = 5 * time.Minute
4443
defaultLockTTL = 20 * time.Second
4544
defaultUpdateTime = 5 * time.Second
4645
)
@@ -88,13 +87,15 @@ func New(addrs []string, options *store.Config) (store.Store, error) {
8887
s.client = etcd.NewKeysAPI(c)
8988

9089
// Periodic Cluster Sync
91-
go func() {
92-
for {
93-
if err := c.AutoSync(context.Background(), periodicSync); err != nil {
94-
return
90+
if options.SyncPeriod != 0 {
91+
go func() {
92+
for {
93+
if err := c.AutoSync(context.Background(), options.SyncPeriod); err != nil {
94+
return
95+
}
9596
}
96-
}
97-
}()
97+
}()
98+
}
9899

99100
return s, nil
100101
}

store/store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Config struct {
4444
ClientTLS *ClientTLSConfig
4545
TLS *tls.Config
4646
ConnectionTimeout time.Duration
47+
SyncPeriod time.Duration
4748
Bucket string
4849
PersistConnection bool
4950
Username string

0 commit comments

Comments
 (0)