Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add node checking from the “Servers” configuration #3

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ jobs:
- uses: stefanzweifel/git-auto-commit-action@v5
id: auto-commit-action
with:
commit_message: Apply Code Coverage Badge
commit_message: 'chore: apply code coverage badge'
file_pattern: ./README.md
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<img src="https://github.com/aliexpressru/gomemcached/raw/main/assets/logo.png" width="300"/>

[![License](https://img.shields.io/github/license/gogf/gf.svg?style=flat)](https://github.com/aliexpressru/gomemcached)
[![Gomemcached](https://goreportcard.com/badge/github.com/aliexpressru/gomemcached)](https://goreportcard.com/report/github.com/aliexpressru/gomemcached)
[![Tag](https://img.shields.io/github/v/tag/aliexpressru/gomemcached?color=%23ff8936&logo=fitbit)](https://github.com/aliexpressru/gomemcached/tags)
[![Godoc](https://godoc.org/github.com/aliexpressru/gomemcached?status.svg)](https://pkg.go.dev/github.com/aliexpressru/gomemcached)

[![Tag](https://img.shields.io/github/v/tag/aliexpressru/gomemcached?color=%23ff8936&logo=fitbit&style=flat-square)](https://github.com/aliexpressru/gomemcached/tags)
![Coverage](https://img.shields.io/badge/Coverage-90.9%25-brightgreen)
[![Gomemcached](https://goreportcard.com/badge/github.com/aliexpressru/gomemcached)](https://goreportcard.com/report/github.com/aliexpressru/gomemcached)
![Coverage](https://img.shields.io/badge/Coverage-91.0%25-brightgreen)

[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go?tab=readme-ov-file#nosql-database-drivers)
</div>

___
Expand Down
13 changes: 9 additions & 4 deletions memcached/node_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (c *Client) checkNodesHealth() {
for node := range c.safeGetDeadNodes() {
wg.Add(1)
go func(n string) {
defer wg.Done()
recheckDeadNodes(n)
wg.Done()
}(node)
}
wg.Wait()
Expand All @@ -92,11 +92,11 @@ func (c *Client) checkNodesHealth() {
for _, node := range ringNodes {
wg.Add(1)
go func(n any) {
defer wg.Done()
if c.nodeIsDead(n) {
sNode := utils.Repr(n)
c.safeAddToDeadNodes(sNode)
}
wg.Done()
}(node)
}

Expand Down Expand Up @@ -127,8 +127,7 @@ func (c *Client) rebuildNodes() {
}
slices.Sort(currentNodes)

deadNodes := c.safeGetDeadNodes()
for node := range deadNodes {
for node := range c.safeGetDeadNodes() {
currentNodes = slices.DeleteFunc(currentNodes, func(a string) bool { return a == node })
}

Expand Down Expand Up @@ -246,6 +245,12 @@ func getNodes(lookup func(host string) (addrs []string, err error), cfg *config)

return nodesWithHost, nil
} else if len(cfg.Servers) != 0 {
for _, s := range cfg.Servers {
_, _, err := net.SplitHostPort(s)
if err != nil {
return nil, err
}
}
return cfg.Servers, nil
}
}
Expand Down
16 changes: 15 additions & 1 deletion memcached/node_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Test_getNodes(t *testing.T) {
},
},
{
name: "error",
name: "error headless",
args: args{
mock: &network{lookupHost: func(host string) (addrs []string, err error) {
return nil, &net.DNSError{
Expand All @@ -102,6 +102,20 @@ func Test_getNodes(t *testing.T) {
return false
},
},
{
name: "error servers",
args: args{
mock: new(network),
cfg: &config{Servers: []string{"localhost:1234", "fakeaddress.r", "localhost"}}},
want: nil,
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
if err != nil {
return true
}
t.Errorf("getNodes dot't have error")
return false
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading