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

Feature/etcd service discovery #5

Merged
merged 2 commits into from
Jun 23, 2020
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
5 changes: 2 additions & 3 deletions registry/etcdv3/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ func (e *etcdV3ServiceDiscovery) Register(instance registry.ServiceInstance) err
if nil != e.client {
ins, err := jsonutil.EncodeJSON(instance)
if err == nil {
err = e.client.Update(path, string(ins))
err = e.client.RegisterTemp(path, string(ins))
if err != nil {
logger.Errorf("cannot register the instance: %s", string(ins), err)
} else {
e.services.Add(instance.GetServiceName())
}

}
}

Expand All @@ -109,7 +108,7 @@ func (e *etcdV3ServiceDiscovery) Update(instance registry.ServiceInstance) error
if nil != e.client {
ins, err := jsonutil.EncodeJSON(instance)
if nil == err {
e.client.Update(path, string(ins))
e.client.RegisterTemp(path, string(ins))
e.services.Add(instance.GetServiceName())
}
}
Expand Down
11 changes: 4 additions & 7 deletions remoting/etcdv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package etcdv3

import (
"context"
"path"
"sync"
"time"
)
Expand Down Expand Up @@ -520,16 +519,14 @@ func (c *Client) Delete(k string) error {
}

// RegisterTemp registers a temporary node
func (c *Client) RegisterTemp(basePath string, node string) (string, error) {
func (c *Client) RegisterTemp(k, v string) error {

completeKey := path.Join(basePath, node)

err := c.keepAliveKV(completeKey, "")
err := c.keepAliveKV(k, v)
if err != nil {
return "", perrors.WithMessagef(err, "keepalive kv (key %s)", completeKey)
return perrors.WithMessagef(err, "keepalive kv (key %s)", k)
}

return completeKey, nil
return nil
}

// GetChildrenKVList gets children kv list by @k
Expand Down
2 changes: 1 addition & 1 deletion remoting/etcdv3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
assert.Contains(t, events, eDelete)
}()

_, err := c.RegisterTemp("scott", "wang")
err := c.RegisterTemp("scott/wang", "test")
if err != nil {
t.Fatal(err)
}
Expand Down