Documentation ¶
Overview ¶
Package etcd2topo implements topo.Server with etcd as the backend.
We expect the following behavior from the etcd client library:
- Get and Delete return ErrorCodeKeyNotFound if the node doesn't exist.
- Create returns ErrorCodeNodeExist if the node already exists.
- Intermediate directories are always created automatically if necessary.
- Set returns ErrorCodeKeyNotFound if the node doesn't exist already.
- It returns ErrorCodeTestFailed if the provided version index doesn't match.
We follow these conventions within this package:
- Call convertError(err) on any errors returned from the etcd client library. Functions defined in this package can be assumed to have already converted errors as necessary.
Index ¶
- Variables
- type EtcdVersion
- type Factory
- type Server
- func (s *Server) Close()
- func (s *Server) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error)
- func (s *Server) Delete(ctx context.Context, filePath string, version topo.Version) error
- func (s *Server) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error)
- func (s *Server) GetVersion(ctx context.Context, filePath string, version int64) ([]byte, error)
- func (s *Server) List(ctx context.Context, filePathPrefix string) ([]topo.KVInfo, error)
- func (s *Server) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error)
- func (s *Server) Lock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
- func (s *Server) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
- func (s *Server) TryLock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
- func (s *Server) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error)
- func (s *Server) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, error)
- func (s *Server) WatchRecursive(ctx context.Context, dirpath string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadResponse is returned from this package if the response from the etcd // server does not contain the data that the API promises. The etcd client // unmarshals JSON from the server into a Response struct that uses pointers, // so we need to check for nil pointers, or else a misbehaving etcd could // cause us to panic. ErrBadResponse = errors.New("etcd request returned success, but response is missing required data") )
Errors specific to this package.
Functions ¶
This section is empty.
Types ¶
type EtcdVersion ¶
type EtcdVersion int64
EtcdVersion is etcd's idea of a version. It implements topo.Version. We use the native etcd version type, int64.
func (EtcdVersion) String ¶
func (v EtcdVersion) String() string
String is part of the topo.Version interface.
type Factory ¶
type Factory struct{}
Factory is the consul topo.Factory implementation.
func (Factory) HasGlobalReadOnlyCell ¶
HasGlobalReadOnlyCell is part of the topo.Factory interface.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the implementation of topo.Server for etcd.
func NewServerWithOpts ¶
NewServerWithOpts creates a new server with the provided TLS options
func (*Server) Close ¶
func (s *Server) Close()
Close implements topo.Server.Close. It will nil out the global and cells fields, so any attempt to re-use this server will panic.
func (*Server) Create ¶
func (s *Server) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error)
Create is part of the topo.Conn interface.
func (*Server) GetVersion ¶ added in v0.20.0
GetVersion is part of the topo.Conn interface.
func (*Server) NewLeaderParticipation ¶ added in v0.13.0
func (s *Server) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
NewLeaderParticipation is part of the topo.Server interface
func (*Server) TryLock ¶ added in v0.16.0
func (s *Server) TryLock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
TryLock is part of the topo.Conn interface.
func (*Server) Update ¶
func (s *Server) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error)
Update is part of the topo.Conn interface.
func (*Server) Watch ¶
func (s *Server) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, error)
Watch is part of the topo.Conn interface.
func (*Server) WatchRecursive ¶ added in v0.15.0
func (s *Server) WatchRecursive(ctx context.Context, dirpath string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error)
WatchRecursive is part of the topo.Conn interface.