Documentation ¶
Overview ¶
Package etcdtopo implements topo.Server with etcd as the backend.
We expect the following behavior from the etcd client library:
- Get and Delete return EcodeKeyNotFound if the node doesn't exist.
- Create returns EcodeNodeExist if the node already exists.
- Intermediate directories are always created automatically if necessary.
- CompareAndSwap returns EcodeKeyNotFound if the node doesn't exist already. It returns EcodeTestFailed 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 ¶
- Constants
- Variables
- type Client
- type EtcdVersion
- type Explorer
- type Server
- func (s *Server) Close()
- func (s *Server) Create(ctx context.Context, cell, filePath string, contents []byte) (topo.Version, error)
- func (s *Server) CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error
- func (s *Server) CreateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard) error
- func (s *Server) CreateTablet(ctx context.Context, tablet *topodatapb.Tablet) error
- func (s *Server) Delete(ctx context.Context, cell, filePath string, version topo.Version) error
- func (s *Server) DeleteKeyspace(ctx context.Context, keyspace string) error
- func (s *Server) DeleteKeyspaceReplication(ctx context.Context, cellName, keyspace string) error
- func (s *Server) DeleteShard(ctx context.Context, keyspace, shard string) error
- func (s *Server) DeleteShardReplication(ctx context.Context, cellName, keyspace, shard string) error
- func (s *Server) DeleteSrvKeyspace(ctx context.Context, cellName, keyspace string) error
- func (s *Server) DeleteTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error
- func (s *Server) Get(ctx context.Context, cell, filePath string) ([]byte, topo.Version, error)
- func (s *Server) GetKeyspace(ctx context.Context, keyspace string) (*topodatapb.Keyspace, int64, error)
- func (s *Server) GetKeyspaces(ctx context.Context) ([]string, error)
- func (s *Server) GetKnownCells(ctx context.Context) ([]string, error)
- func (s *Server) GetShard(ctx context.Context, keyspace, shard string) (*topodatapb.Shard, int64, error)
- func (s *Server) GetShardNames(ctx context.Context, keyspace string) ([]string, error)
- func (s *Server) GetShardReplication(ctx context.Context, cell, keyspace, shard string) (*topo.ShardReplicationInfo, error)
- func (s *Server) GetSrvKeyspace(ctx context.Context, cellName, keyspace string) (*topodatapb.SrvKeyspace, error)
- func (s *Server) GetSrvKeyspaceNames(ctx context.Context, cellName string) ([]string, error)
- func (s *Server) GetSrvVSchema(ctx context.Context, cellName string) (*vschemapb.SrvVSchema, error)
- func (s *Server) GetTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) (*topodatapb.Tablet, int64, error)
- func (s *Server) GetTabletsByCell(ctx context.Context, cellName string) ([]*topodatapb.TabletAlias, error)
- func (s *Server) GetVSchema(ctx context.Context, keyspace string) (*vschemapb.Keyspace, error)
- func (s *Server) ListDir(ctx context.Context, cell, dirPath string) ([]string, error)
- func (s *Server) LockKeyspaceForAction(ctx context.Context, keyspace, contents string) (string, error)
- func (s *Server) LockShardForAction(ctx context.Context, keyspace, shard, contents string) (string, error)
- func (s *Server) NewMasterParticipation(name, id string) (topo.MasterParticipation, error)
- func (s *Server) SaveVSchema(ctx context.Context, keyspace string, vschema *vschemapb.Keyspace) error
- func (s *Server) UnlockKeyspaceForAction(ctx context.Context, keyspace, actionPath, results string) error
- func (s *Server) UnlockShardForAction(ctx context.Context, keyspace, shard, actionPath, results string) error
- func (s *Server) Update(ctx context.Context, cell, filePath string, contents []byte, ...) (topo.Version, error)
- func (s *Server) UpdateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace, ...) (int64, error)
- func (s *Server) UpdateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard, ...) (int64, error)
- func (s *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, ...) error
- func (s *Server) UpdateSrvKeyspace(ctx context.Context, cellName, keyspace string, ...) error
- func (s *Server) UpdateSrvVSchema(ctx context.Context, cellName string, srvVSchema *vschemapb.SrvVSchema) error
- func (s *Server) UpdateTablet(ctx context.Context, tablet *topodatapb.Tablet, existingVersion int64) (int64, error)
- func (s *Server) ValidateShard(ctx context.Context, keyspace, shard string) error
- func (s *Server) ValidateTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error
- func (s *Server) Watch(ctx context.Context, cellName, filePath string) (*topo.WatchData, <-chan *topo.WatchData, topo.CancelFunc)
Constants ¶
const ( EcodeKeyNotFound = 100 EcodeTestFailed = 101 EcodeNotFile = 102 EcodeNoMorePeer = 103 EcodeNotDir = 104 EcodeNodeExist = 105 EcodeKeyIsPreserved = 106 EcodeRootROnly = 107 EcodeDirNotEmpty = 108 EcodeValueRequired = 200 EcodePrevValueRequired = 201 EcodeTTLNaN = 202 EcodeIndexNaN = 203 EcodeRaftInternal = 300 EcodeLeaderElect = 301 EcodeWatcherCleared = 400 EcodeEventIndexCleared = 401 )
Error codes returned by etcd: https://github.com/coreos/etcd/blob/v0.4.6/Documentation/errorcode.md
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.
var WatchSleepDuration = 30 * time.Second
WatchSleepDuration is how many seconds interval to poll for in case we get an error from the Watch method. It is exported so individual test and main programs can change it.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { CompareAndDelete(key string, prevValue string, prevIndex uint64) (*etcd.Response, error) CompareAndSwap(key string, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error) Create(key string, value string, ttl uint64) (*etcd.Response, error) Delete(key string, recursive bool) (*etcd.Response, error) DeleteDir(key string) (*etcd.Response, error) Get(key string, sort, recursive bool) (*etcd.Response, error) Set(key string, value string, ttl uint64) (*etcd.Response, error) SetCluster(machines []string) bool Watch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error) }
Client contains the parts of etcd.Client that are needed.
type EtcdVersion ¶
type EtcdVersion uint64
EtcdVersion is etcd's idea of a version. It implements topo.Version. We use the native etcd version type, uint64.
func (EtcdVersion) String ¶
func (v EtcdVersion) String() string
String is part of the topo.Version interface.
type Explorer ¶
type Explorer struct {
// contains filtered or unexported fields
}
Explorer is an implementation of vtctld's Explorer interface for etcd.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the implementation of topo.Server for etcd.
func (*Server) Create ¶
func (s *Server) Create(ctx context.Context, cell, filePath string, contents []byte) (topo.Version, error)
Create is part of the topo.Backend interface.
func (*Server) CreateKeyspace ¶
func (s *Server) CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error
CreateKeyspace implements topo.Server.
func (*Server) CreateShard ¶
func (s *Server) CreateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard) error
CreateShard implements topo.Server.
func (*Server) CreateTablet ¶
CreateTablet implements topo.Server.
func (*Server) DeleteKeyspace ¶
DeleteKeyspace implements topo.Server.
func (*Server) DeleteKeyspaceReplication ¶
DeleteKeyspaceReplication implements topo.Server.
func (*Server) DeleteShard ¶
DeleteShard implements topo.Server.
func (*Server) DeleteShardReplication ¶
func (s *Server) DeleteShardReplication(ctx context.Context, cellName, keyspace, shard string) error
DeleteShardReplication implements topo.Server.
func (*Server) DeleteSrvKeyspace ¶
DeleteSrvKeyspace implements topo.Server.
func (*Server) DeleteTablet ¶
func (s *Server) DeleteTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error
DeleteTablet implements topo.Server.
func (*Server) GetKeyspace ¶
func (s *Server) GetKeyspace(ctx context.Context, keyspace string) (*topodatapb.Keyspace, int64, error)
GetKeyspace implements topo.Server.
func (*Server) GetKeyspaces ¶
GetKeyspaces implements topo.Server.
func (*Server) GetKnownCells ¶
GetKnownCells implements topo.Server.
func (*Server) GetShard ¶
func (s *Server) GetShard(ctx context.Context, keyspace, shard string) (*topodatapb.Shard, int64, error)
GetShard implements topo.Server.
func (*Server) GetShardNames ¶
GetShardNames implements topo.Server.
func (*Server) GetShardReplication ¶
func (s *Server) GetShardReplication(ctx context.Context, cell, keyspace, shard string) (*topo.ShardReplicationInfo, error)
GetShardReplication implements topo.Server.
func (*Server) GetSrvKeyspace ¶
func (s *Server) GetSrvKeyspace(ctx context.Context, cellName, keyspace string) (*topodatapb.SrvKeyspace, error)
GetSrvKeyspace implements topo.Server.
func (*Server) GetSrvKeyspaceNames ¶
GetSrvKeyspaceNames implements topo.Server.
func (*Server) GetSrvVSchema ¶
GetSrvVSchema implements topo.Server.
func (*Server) GetTablet ¶
func (s *Server) GetTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) (*topodatapb.Tablet, int64, error)
GetTablet implements topo.Server.
func (*Server) GetTabletsByCell ¶
func (s *Server) GetTabletsByCell(ctx context.Context, cellName string) ([]*topodatapb.TabletAlias, error)
GetTabletsByCell implements topo.Server.
func (*Server) GetVSchema ¶
GetVSchema fetches the vschema from the topo.
func (*Server) LockKeyspaceForAction ¶
func (s *Server) LockKeyspaceForAction(ctx context.Context, keyspace, contents string) (string, error)
LockKeyspaceForAction implements topo.Server.
func (*Server) LockShardForAction ¶
func (s *Server) LockShardForAction(ctx context.Context, keyspace, shard, contents string) (string, error)
LockShardForAction implements topo.Server.
func (*Server) NewMasterParticipation ¶
func (s *Server) NewMasterParticipation(name, id string) (topo.MasterParticipation, error)
NewMasterParticipation is part of the topo.Server interface
func (*Server) SaveVSchema ¶
func (s *Server) SaveVSchema(ctx context.Context, keyspace string, vschema *vschemapb.Keyspace) error
SaveVSchema saves the JSON vschema into the topo.
func (*Server) UnlockKeyspaceForAction ¶
func (s *Server) UnlockKeyspaceForAction(ctx context.Context, keyspace, actionPath, results string) error
UnlockKeyspaceForAction implements topo.Server.
func (*Server) UnlockShardForAction ¶
func (s *Server) UnlockShardForAction(ctx context.Context, keyspace, shard, actionPath, results string) error
UnlockShardForAction implements topo.Server.
func (*Server) Update ¶
func (s *Server) Update(ctx context.Context, cell, filePath string, contents []byte, version topo.Version) (topo.Version, error)
Update is part of the topo.Backend interface.
func (*Server) UpdateKeyspace ¶
func (s *Server) UpdateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace, existingVersion int64) (int64, error)
UpdateKeyspace implements topo.Server.
func (*Server) UpdateShard ¶
func (s *Server) UpdateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard, existingVersion int64) (int64, error)
UpdateShard implements topo.Server.
func (*Server) UpdateShardReplicationFields ¶
func (s *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, updateFunc func(*topodatapb.ShardReplication) error) error
UpdateShardReplicationFields implements topo.Server.
func (*Server) UpdateSrvKeyspace ¶
func (s *Server) UpdateSrvKeyspace(ctx context.Context, cellName, keyspace string, srvKeyspace *topodatapb.SrvKeyspace) error
UpdateSrvKeyspace implements topo.Server.
func (*Server) UpdateSrvVSchema ¶
func (s *Server) UpdateSrvVSchema(ctx context.Context, cellName string, srvVSchema *vschemapb.SrvVSchema) error
UpdateSrvVSchema implements topo.Server.
func (*Server) UpdateTablet ¶
func (s *Server) UpdateTablet(ctx context.Context, tablet *topodatapb.Tablet, existingVersion int64) (int64, error)
UpdateTablet implements topo.Server.
func (*Server) ValidateShard ¶
ValidateShard implements topo.Server.
func (*Server) ValidateTablet ¶
func (s *Server) ValidateTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error
ValidateTablet implements topo.Server.