diff --git a/README.md b/README.md index 37a9801..9a4f6b4 100644 --- a/README.md +++ b/README.md @@ -231,4 +231,5 @@ $ DOCKER_BUILDKIT=1 docker build --build-arg ARCH=${ARCH} -t "etcd-defrag:${VERS Any contribution is welcome! ## Note -Please ensure running etcd on a version >= 3.5.6, and read [Two possible data inconsistency issues in etcd](https://groups.google.com/g/etcd-dev/c/8S7u6NqW6C4) to get more details. +- Please ensure running etcd on a version >= 3.5.6, and read [Two possible data inconsistency issues in etcd](https://groups.google.com/g/etcd-dev/c/8S7u6NqW6C4) to get more details. +- Please do not get learner members' endpoints included in `--endpoints`, refer to discussion in https://github.com/ahrtr/etcd-defrag/issues/26. diff --git a/endpoints.go b/endpoints.go index c7af005..280c265 100644 --- a/endpoints.go +++ b/endpoints.go @@ -48,7 +48,10 @@ func endpointsFromCluster(gcfg globalConfig) ([]string, error) { var eps []string for _, m := range memberlistResp.Members { - eps = append(eps, m.ClientURLs...) + // learner member only serves Status and SerializableRead requests, just ignore it + if !m.GetIsLearner() { + eps = append(eps, m.ClientURLs...) + } } slices.Sort(eps) diff --git a/endpoints_test.go b/endpoints_test.go index 0f14bc6..34bd4a0 100644 --- a/endpoints_test.go +++ b/endpoints_test.go @@ -76,6 +76,24 @@ func TestEndpointDedup(t *testing.T) { }, []string{"etcd.example.com:2379", "etcd1.example.com:2379", "etcd2.example.com:2379", "etcd3.example.com:2379"}, }, + { + "ignore learner", + &clientv3.MemberListResponse{ + Members: []*etcdserverpb.Member{ + { + ClientURLs: []string{"etcd1.example.com:2379"}, + IsLearner: true, + }, + { + ClientURLs: []string{"etcd3.example.com:2379"}, + }, + { + ClientURLs: []string{"etcd2.example.com:2379"}, + }, + }, + }, + []string{"etcd2.example.com:2379", "etcd3.example.com:2379"}, + }, } for _, testcase := range testcases {