Skip to content
Snippets Groups Projects
Commit b0c130c5 authored by ale's avatar ale
Browse files

use CreateDir to initialize presence directory

parent 6855abb0
Branches
Tags
No related merge requests found
...@@ -200,7 +200,7 @@ func (s *FakeEtcdClient) Set(key, value string, ttl uint64) (*etcd.Response, err ...@@ -200,7 +200,7 @@ func (s *FakeEtcdClient) Set(key, value string, ttl uint64) (*etcd.Response, err
return s.trigger("set", key), nil return s.trigger("set", key), nil
} }
func (s *FakeEtcdClient) SetDir(key string, ttl uint64) (*etcd.Response, error) { func (s *FakeEtcdClient) CreateDir(key string, ttl uint64) (*etcd.Response, error) {
// TODO. There are no directories. // TODO. There are no directories.
return &etcd.Response{}, nil return &etcd.Response{}, nil
} }
......
package presence package presence
import ( import (
"fmt"
"log" "log"
"time" "time"
...@@ -12,10 +11,10 @@ import ( ...@@ -12,10 +11,10 @@ import (
type EtcdClient interface { type EtcdClient interface {
AddChild(key string, value string, ttl uint64) (*etcd.Response, error) AddChild(key string, value string, ttl uint64) (*etcd.Response, error)
Create(key string, value string, ttl uint64) (*etcd.Response, error) Create(key string, value string, ttl uint64) (*etcd.Response, error)
CreateDir(key string, ttl uint64) (*etcd.Response, error)
Update(key string, value string, ttl uint64) (*etcd.Response, error) Update(key string, value string, ttl uint64) (*etcd.Response, error)
Delete(key string, recursive bool) (*etcd.Response, error) Delete(key string, recursive bool) (*etcd.Response, error)
Get(key string, sort, recursive bool) (*etcd.Response, error) Get(key string, sort, recursive bool) (*etcd.Response, error)
SetDir(key string, ttl uint64) (*etcd.Response, error)
} }
// A Client can read the list of active nodes written by Presence workers. // A Client can read the list of active nodes written by Presence workers.
...@@ -77,10 +76,8 @@ func (p *Presence) Stop() { ...@@ -77,10 +76,8 @@ func (p *Presence) Stop() {
// Start the presence worker. // Start the presence worker.
func (p *Presence) Start() error { func (p *Presence) Start() error {
// Create the presence directory if it does not exist. // Create the presence directory if it does not exist. Ignore errors.
if _, err := p.client.SetDir(p.path, 0); err != nil { p.client.CreateDir(p.path, 0)
return fmt.Errorf("could not create presence directory: %v", err)
}
go p.run() go p.run()
return nil return nil
......
...@@ -90,11 +90,11 @@ func NewEtcdClient(strongReads bool) EtcdClient { ...@@ -90,11 +90,11 @@ func NewEtcdClient(strongReads bool) EtcdClient {
type EtcdClient interface { type EtcdClient interface {
AddChild(string, string, uint64) (*etcd.Response, error) AddChild(string, string, uint64) (*etcd.Response, error)
Create(string, string, uint64) (*etcd.Response, error) Create(string, string, uint64) (*etcd.Response, error)
CreateDir(string, uint64) (*etcd.Response, error)
CompareAndSwap(string, string, uint64, string, uint64) (*etcd.Response, error) CompareAndSwap(string, string, uint64, string, uint64) (*etcd.Response, error)
Delete(string, bool) (*etcd.Response, error) Delete(string, bool) (*etcd.Response, error)
Get(string, bool, bool) (*etcd.Response, error) Get(string, bool, bool) (*etcd.Response, error)
Set(string, string, uint64) (*etcd.Response, error) Set(string, string, uint64) (*etcd.Response, error)
SetDir(string, uint64) (*etcd.Response, error)
Update(string, string, uint64) (*etcd.Response, error) Update(string, string, uint64) (*etcd.Response, error)
Watch(string, uint64, bool, chan *etcd.Response, chan bool) (*etcd.Response, error) Watch(string, uint64, bool, chan *etcd.Response, chan bool) (*etcd.Response, error)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment