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 Explorer
- func (ex Explorer) GetKeyspacePath(keyspace string) string
- func (ex Explorer) GetReplicationSlaves(cell, keyspace, shard string) string
- func (ex Explorer) GetShardPath(keyspace, shard string) string
- func (ex Explorer) GetSrvKeyspacePath(cell, keyspace string) string
- func (ex Explorer) GetSrvShardPath(cell, keyspace, shard string) string
- func (ex Explorer) GetSrvTypePath(cell, keyspace, shard string, tabletType topo.TabletType) string
- func (ex Explorer) GetTabletPath(alias topo.TabletAlias) string
- func (ex Explorer) HandlePath(actionRepo ctlproto.ActionRepository, rPath string, r *http.Request) interface{}
- type Server
- func (s *Server) Close()
- func (s *Server) CreateKeyspace(keyspace string, value *topo.Keyspace) error
- func (s *Server) CreateShard(keyspace, shard string, value *topo.Shard) error
- func (s *Server) CreateTablet(tablet *topo.Tablet) error
- func (s *Server) DeleteEndPoints(cellName, keyspace, shard string, tabletType topo.TabletType) error
- func (s *Server) DeleteKeyspaceShards(keyspace string) error
- func (s *Server) DeleteShard(keyspace, shard string) error
- func (s *Server) DeleteShardReplication(cellName, keyspace, shard string) error
- func (s *Server) DeleteSrvShard(cellName, keyspace, shard string) error
- func (s *Server) DeleteTablet(tabletAlias topo.TabletAlias) error
- func (s *Server) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)
- func (s *Server) GetKeyspace(keyspace string) (*topo.KeyspaceInfo, error)
- func (s *Server) GetKeyspaces() ([]string, error)
- func (s *Server) GetKnownCells() ([]string, error)
- func (s *Server) GetShard(keyspace, shard string) (*topo.ShardInfo, error)
- func (s *Server) GetShardNames(keyspace string) ([]string, error)
- func (s *Server) GetShardReplication(cell, keyspace, shard string) (*topo.ShardReplicationInfo, error)
- func (s *Server) GetSrvKeyspace(cellName, keyspace string) (*topo.SrvKeyspace, error)
- func (s *Server) GetSrvKeyspaceNames(cellName string) ([]string, error)
- func (s *Server) GetSrvShard(cellName, keyspace, shard string) (*topo.SrvShard, error)
- func (s *Server) GetSrvTabletTypesPerShard(cellName, keyspace, shard string) ([]topo.TabletType, error)
- func (s *Server) GetTablet(tabletAlias topo.TabletAlias) (*topo.TabletInfo, error)
- func (s *Server) GetTabletsByCell(cellName string) ([]topo.TabletAlias, error)
- func (s *Server) GetVSchema() (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) LockSrvShardForAction(ctx context.Context, cellName, keyspace, shard, contents string) (string, error)
- func (s *Server) SaveVSchema(vschema string) error
- func (s *Server) UnlockKeyspaceForAction(keyspace, actionPath, results string) error
- func (s *Server) UnlockShardForAction(keyspace, shard, actionPath, results string) error
- func (s *Server) UnlockSrvShardForAction(cellName, keyspace, shard, actionPath, results string) error
- func (s *Server) UpdateEndPoints(cellName, keyspace, shard string, tabletType topo.TabletType, ...) error
- func (s *Server) UpdateKeyspace(ki *topo.KeyspaceInfo, existingVersion int64) (int64, error)
- func (s *Server) UpdateShard(si *topo.ShardInfo, existingVersion int64) (int64, error)
- func (s *Server) UpdateShardReplicationFields(cell, keyspace, shard string, updateFunc func(*topo.ShardReplication) error) error
- func (s *Server) UpdateSrvKeyspace(cellName, keyspace string, srvKeyspace *topo.SrvKeyspace) error
- func (s *Server) UpdateSrvShard(cellName, keyspace, shard string, srvShard *topo.SrvShard) error
- func (s *Server) UpdateTablet(ti *topo.TabletInfo, existingVersion int64) (int64, error)
- func (s *Server) UpdateTabletEndpoint(cell, keyspace, shard string, tabletType topo.TabletType, addr *topo.EndPoint) error
- func (s *Server) UpdateTabletFields(tabletAlias topo.TabletAlias, updateFunc func(*topo.Tablet) error) error
- func (s *Server) ValidateShard(keyspace, shard string) error
- func (s *Server) ValidateTablet(tabletAlias topo.TabletAlias) error
- func (s *Server) WatchEndPoints(cellName, keyspace, shard string, tabletType topo.TabletType) (<-chan *topo.EndPoints, chan<- struct{}, error)
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) 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 Explorer ¶
type Explorer struct {
// contains filtered or unexported fields
}
Explorer is an implementation of vtctld's Explorer interface for etcd.
func (Explorer) GetKeyspacePath ¶
GetKeyspacePath implements vtctld Explorer.
func (Explorer) GetReplicationSlaves ¶
GetReplicationSlaves implements vtctld Explorer.
func (Explorer) GetShardPath ¶
GetShardPath implements vtctld Explorer.
func (Explorer) GetSrvKeyspacePath ¶
GetSrvKeyspacePath implements vtctld Explorer.
func (Explorer) GetSrvShardPath ¶
GetSrvShardPath implements vtctld Explorer.
func (Explorer) GetSrvTypePath ¶
func (ex Explorer) GetSrvTypePath(cell, keyspace, shard string, tabletType topo.TabletType) string
GetSrvTypePath implements vtctld Explorer.
func (Explorer) GetTabletPath ¶
func (ex Explorer) GetTabletPath(alias topo.TabletAlias) string
GetTabletPath implements vtctld Explorer.
func (Explorer) HandlePath ¶
func (ex Explorer) HandlePath(actionRepo ctlproto.ActionRepository, rPath string, r *http.Request) interface{}
HandlePath implements vtctld Explorer.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the implementation of topo.Server for etcd.
func (*Server) CreateKeyspace ¶
CreateKeyspace implements topo.Server.
func (*Server) CreateShard ¶
CreateShard implements topo.Server.
func (*Server) CreateTablet ¶
CreateTablet implements topo.Server.
func (*Server) DeleteEndPoints ¶
func (s *Server) DeleteEndPoints(cellName, keyspace, shard string, tabletType topo.TabletType) error
DeleteEndPoints implements topo.Server.
func (*Server) DeleteKeyspaceShards ¶
DeleteKeyspaceShards implements topo.Server.
func (*Server) DeleteShard ¶
DeleteShard implements topo.Server.
func (*Server) DeleteShardReplication ¶
DeleteShardReplication implements topo.Server.
func (*Server) DeleteSrvShard ¶
DeleteSrvShard implements topo.Server.
func (*Server) DeleteTablet ¶
func (s *Server) DeleteTablet(tabletAlias topo.TabletAlias) error
DeleteTablet implements topo.Server.
func (*Server) GetEndPoints ¶
func (s *Server) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)
GetEndPoints implements topo.Server.
func (*Server) GetKeyspace ¶
func (s *Server) GetKeyspace(keyspace string) (*topo.KeyspaceInfo, error)
GetKeyspace implements topo.Server.
func (*Server) GetKeyspaces ¶
GetKeyspaces implements topo.Server.
func (*Server) GetKnownCells ¶
GetKnownCells implements topo.Server.
func (*Server) GetShardNames ¶
GetShardNames implements topo.Server.
func (*Server) GetShardReplication ¶
func (s *Server) GetShardReplication(cell, keyspace, shard string) (*topo.ShardReplicationInfo, error)
GetShardReplication implements topo.Server.
func (*Server) GetSrvKeyspace ¶
func (s *Server) GetSrvKeyspace(cellName, keyspace string) (*topo.SrvKeyspace, error)
GetSrvKeyspace implements topo.Server.
func (*Server) GetSrvKeyspaceNames ¶
GetSrvKeyspaceNames implements topo.Server.
func (*Server) GetSrvShard ¶
GetSrvShard implements topo.Server.
func (*Server) GetSrvTabletTypesPerShard ¶
func (s *Server) GetSrvTabletTypesPerShard(cellName, keyspace, shard string) ([]topo.TabletType, error)
GetSrvTabletTypesPerShard implements topo.Server.
func (*Server) GetTablet ¶
func (s *Server) GetTablet(tabletAlias topo.TabletAlias) (*topo.TabletInfo, error)
GetTablet implements topo.Server.
func (*Server) GetTabletsByCell ¶
func (s *Server) GetTabletsByCell(cellName string) ([]topo.TabletAlias, error)
GetTabletsByCell implements topo.Server.
func (*Server) GetVSchema ¶
GetVSchema fetches the JSON 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) LockSrvShardForAction ¶
func (s *Server) LockSrvShardForAction(ctx context.Context, cellName, keyspace, shard, contents string) (string, error)
LockSrvShardForAction implements topo.Server.
func (*Server) SaveVSchema ¶
SaveVSchema saves the JSON vschema into the topo.
func (*Server) UnlockKeyspaceForAction ¶
UnlockKeyspaceForAction implements topo.Server.
func (*Server) UnlockShardForAction ¶
UnlockShardForAction implements topo.Server.
func (*Server) UnlockSrvShardForAction ¶
func (s *Server) UnlockSrvShardForAction(cellName, keyspace, shard, actionPath, results string) error
UnlockSrvShardForAction implements topo.Server.
func (*Server) UpdateEndPoints ¶
func (s *Server) UpdateEndPoints(cellName, keyspace, shard string, tabletType topo.TabletType, addrs *topo.EndPoints) error
UpdateEndPoints implements topo.Server.
func (*Server) UpdateKeyspace ¶
UpdateKeyspace implements topo.Server.
func (*Server) UpdateShard ¶
UpdateShard implements topo.Server.
func (*Server) UpdateShardReplicationFields ¶
func (s *Server) UpdateShardReplicationFields(cell, keyspace, shard string, updateFunc func(*topo.ShardReplication) error) error
UpdateShardReplicationFields implements topo.Server.
func (*Server) UpdateSrvKeyspace ¶
func (s *Server) UpdateSrvKeyspace(cellName, keyspace string, srvKeyspace *topo.SrvKeyspace) error
UpdateSrvKeyspace implements topo.Server.
func (*Server) UpdateSrvShard ¶
UpdateSrvShard implements topo.Server.
func (*Server) UpdateTablet ¶
UpdateTablet implements topo.Server.
func (*Server) UpdateTabletEndpoint ¶
func (s *Server) UpdateTabletEndpoint(cell, keyspace, shard string, tabletType topo.TabletType, addr *topo.EndPoint) error
UpdateTabletEndpoint implements topo.Server.
func (*Server) UpdateTabletFields ¶
func (s *Server) UpdateTabletFields(tabletAlias topo.TabletAlias, updateFunc func(*topo.Tablet) error) error
UpdateTabletFields implements topo.Server.
func (*Server) ValidateShard ¶
ValidateShard implements topo.Server.
func (*Server) ValidateTablet ¶
func (s *Server) ValidateTablet(tabletAlias topo.TabletAlias) error
ValidateTablet implements topo.Server.
func (*Server) WatchEndPoints ¶
func (s *Server) WatchEndPoints(cellName, keyspace, shard string, tabletType topo.TabletType) (<-chan *topo.EndPoints, chan<- struct{}, error)
WatchEndPoints is part of the topo.Server interface