Skip to content

Commit

Permalink
Merge pull request #28 from git-yww/main
Browse files Browse the repository at this point in the history
Remove learner member from endpointsFromCluster
  • Loading branch information
ahrtr authored Oct 19, 2023
2 parents a7a0f2e + 4a4a74f commit bcec0ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 4 additions & 1 deletion endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bcec0ac

Please sign in to comment.