topo

package
v2.0.0-beta.1+incompat... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2016 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReplicationLag is the key in the health map to indicate high
	// replication lag
	ReplicationLag = "replication_lag"

	// ReplicationLagHigh is the value in the health map to indicate high
	// replication lag
	ReplicationLagHigh = "high"
)
View Source
const (
	// DefaultPortName is the port named used by SrvEntries
	// if "" is given as the named port.
	DefaultPortName = "vt"
)

Variables

View Source
var (
	// ErrNodeExists is returned by functions to specify the
	// requested resource already exists.
	ErrNodeExists = errors.New("node already exists")

	// ErrNoNode is returned by functions to specify the requested
	// resource does not exist.
	ErrNoNode = errors.New("node doesn't exist")

	// ErrNotEmpty is returned by functions to specify a child of the
	// resource is still present and prevents the action from completing.
	ErrNotEmpty = errors.New("node not empty")

	// ErrTimeout is returned by functions that wait for a result
	// when the timeout value is reached.
	ErrTimeout = errors.New("deadline exceeded")

	// ErrInterrupted is returned by functions that wait for a result
	// when they are interrupted.
	ErrInterrupted = errors.New("interrupted")

	// ErrBadVersion is returned by an update function that
	// failed to update the data because the version was different
	ErrBadVersion = errors.New("bad node version")

	// ErrPartialResult is returned by a function that could only
	// get a subset of its results
	ErrPartialResult = errors.New("partial result")

	// ErrNoUpdateNeeded can be returned by an 'UpdateFields' method
	// to skip any update.
	ErrNoUpdateNeeded = errors.New("no update needed")
)

Functions

func CloseServers

func CloseServers()

CloseServers closes all registered Server.

func DeleteTabletReplicationData

func DeleteTabletReplicationData(ctx context.Context, ts Server, tablet *topodatapb.Tablet) error

DeleteTabletReplicationData deletes replication data.

func EndPointEquality

func EndPointEquality(left, right *topodatapb.EndPoint) bool

EndPointEquality returns true iff two EndPoint are representing the same data

func FixShardReplication

func FixShardReplication(ctx context.Context, ts Server, logger logutil.Logger, cell, keyspace, shard string) error

FixShardReplication will fix the first problem it encounters within a ShardReplication object

func InCellList

func InCellList(cell string, cells []string) bool

InCellList returns true if the cell list is empty, or if the passed cell is in the cell list.

func IsHealthEqual

func IsHealthEqual(left, right map[string]string) bool

IsHealthEqual compares the two health maps, and returns true if they're equivalent.

func IsInServingGraph

func IsInServingGraph(tt topodatapb.TabletType) bool

IsInServingGraph returns if a tablet appears in the serving graph

func IsRunningQueryService

func IsRunningQueryService(tt topodatapb.TabletType) bool

IsRunningQueryService returns if a tablet is running the query service

func IsRunningUpdateStream

func IsRunningUpdateStream(tt topodatapb.TabletType) bool

IsRunningUpdateStream returns if a tablet is running the update stream RPC service.

func IsShardUsingRangeBasedSharding

func IsShardUsingRangeBasedSharding(shard string) bool

IsShardUsingRangeBasedSharding returns true if the shard name implies it is using range based sharding.

func IsSlaveType

func IsSlaveType(tt topodatapb.TabletType) bool

IsSlaveType returns if this type should be connected to a master db and actively replicating? MASTER is not obviously (only support one level replication graph) BACKUP, RESTORE, WORKER may or may not be, but we don't know for sure

func IsTrivialTypeChange

func IsTrivialTypeChange(oldTabletType, newTabletType topodatapb.TabletType) bool

IsTrivialTypeChange returns if this db type be trivially reassigned without changes to the replication graph

func NewEndPoint

func NewEndPoint(uid uint32, host string) *topodatapb.EndPoint

NewEndPoint returns a new empty EndPoint

func NewEndPoints

func NewEndPoints() *topodatapb.EndPoints

NewEndPoints creates a EndPoints with a pre-allocated slice for Entries.

func RegisterServer

func RegisterServer(name string, ts Impl)

RegisterServer adds an implementation for a Server. If an implementation with that name already exists, panics. Call this in the 'init' function in your module.

func RemoveShardReplicationRecord

func RemoveShardReplicationRecord(ctx context.Context, ts Server, cell, keyspace, shard string, tabletAlias *topodatapb.TabletAlias) error

RemoveShardReplicationRecord is a low level function to remove an entry from the ShardReplication object.

func ResolveKeyspaceWildcard

func ResolveKeyspaceWildcard(ctx context.Context, server WildcardBackend, param string) ([]string, error)

ResolveKeyspaceWildcard will resolve keyspace wildcards.

  • If the param is not a wildcard, it will just be returned (if the keyspace doesn't exist, it is still returned).
  • If the param is a wildcard, it will get all keyspaces and returns the ones which match the wildcard (which may be an empty list).

func TabletComplete

func TabletComplete(tablet *topodatapb.Tablet) error

TabletComplete validates and normalizes the tablet. If the shard name contains a '-' it is going to try to infer the keyrange from it.

func TabletEndPoint

func TabletEndPoint(tablet *topodatapb.Tablet) (*topodatapb.EndPoint, error)

TabletEndPoint returns an EndPoint associated with the tablet record

func TabletValidatePortMap

func TabletValidatePortMap(tablet *topodatapb.Tablet) error

TabletValidatePortMap returns an error if the tablet's portmap doesn't contain all the necessary ports for the tablet to be fully operational. We only care about vt port now, as mysql may not even be running.

func UpdateEndPoints

func UpdateEndPoints(ctx context.Context, ts Server, cell, keyspace, shard string, tabletType topodatapb.TabletType, addrs *topodatapb.EndPoints, existingVersion int64) error

UpdateEndPoints is a high level wrapper for TopoServer.UpdateEndPoints. It generates trace spans.

func UpdateShardReplicationRecord

func UpdateShardReplicationRecord(ctx context.Context, ts Server, keyspace, shard string, tabletAlias *topodatapb.TabletAlias) error

UpdateShardReplicationRecord is a low level function to add / update an entry to the ShardReplication object.

func UpdateTabletReplicationData

func UpdateTabletReplicationData(ctx context.Context, ts Server, tablet *topodatapb.Tablet) error

UpdateTabletReplicationData creates or updates the replication graph data for a tablet

func Validate

func Validate(ctx context.Context, ts Server, tabletAlias *topodatapb.TabletAlias) error

Validate makes sure a tablet is represented correctly in the topology server.

func ValidateShardName

func ValidateShardName(shard string) (string, *topodatapb.KeyRange, error)

ValidateShardName takes a shard name and sanitizes it, and also returns the KeyRange.

Types

type Impl

type Impl interface {
	// topo.Server management interface.
	Close()

	// GetKnownCells returns the list of known cells running our processes.
	// It is possible to find all tablets in the entire system
	// by then calling GetTabletsByCell on every cell, for instance.
	// They shall be sorted.
	GetKnownCells(ctx context.Context) ([]string, error)

	// CreateKeyspace creates the given keyspace, assuming it doesn't exist
	// yet. Can return ErrNodeExists if it already exists.
	CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error

	// UpdateKeyspace updates the keyspace information
	// pointed at by ki.keyspace to the *ki value.
	// This will only be called with a lock on the keyspace.
	// Can return ErrNoNode if the keyspace doesn't exist yet,
	// or ErrBadVersion if the version has changed.
	//
	// Do not use directly, but instead use topo.UpdateKeyspace.
	UpdateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace, existingVersion int64) (newVersion int64, err error)

	// DeleteKeyspace deletes the specified keyspace.
	// Can return ErrNoNode if the keyspace doesn't exist.
	DeleteKeyspace(ctx context.Context, keyspace string) error

	// GetKeyspace reads a keyspace and returns it, along with its version.
	// Can return ErrNoNode
	GetKeyspace(ctx context.Context, keyspace string) (*topodatapb.Keyspace, int64, error)

	// GetKeyspaces returns the known keyspace names. They shall be sorted.
	GetKeyspaces(ctx context.Context) ([]string, error)

	// DeleteKeyspaceShards deletes all the shards in a keyspace.
	// Use with caution.
	DeleteKeyspaceShards(ctx context.Context, keyspace string) error

	// CreateShard creates an empty shard, assuming it doesn't exist
	// yet. The contents of the shard will be a new Shard{} object,
	// with KeyRange populated by the result of ValidateShardName().
	// Can return ErrNodeExists if it already exists.
	CreateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard) error

	// UpdateShard updates the shard information
	// pointed at by si.keyspace / si.shard to the *si value.
	// This will only be called with a lock on the shard.
	// Can return ErrNoNode if the shard doesn't exist yet,
	// or ErrBadVersion if the version has changed.
	//
	// Do not use directly, but instead use topo.UpdateShard.
	UpdateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard, existingVersion int64) (newVersion int64, err error)

	// ValidateShard performs routine checks on the shard.
	ValidateShard(ctx context.Context, keyspace, shard string) error

	// GetShard reads a shard and returns it, along with its version.
	// Can return ErrNoNode
	GetShard(ctx context.Context, keyspace, shard string) (*topodatapb.Shard, int64, error)

	// GetShardNames returns the known shards in a keyspace.
	// Can return ErrNoNode if the keyspace wasn't created,
	// or if DeleteKeyspaceShards was called. They shall be sorted.
	GetShardNames(ctx context.Context, keyspace string) ([]string, error)

	// DeleteShard deletes the provided shard.
	// Can return ErrNoNode if the shard doesn't exist.
	DeleteShard(ctx context.Context, keyspace, shard string) error

	// CreateTablet creates the given tablet, assuming it doesn't exist
	// yet. It does *not* create the tablet replication paths.
	// Can return ErrNodeExists if it already exists.
	CreateTablet(ctx context.Context, tablet *topodatapb.Tablet) error

	// UpdateTablet updates a given tablet. The version is used
	// for atomic updates. UpdateTablet will return ErrNoNode if
	// the tablet doesn't exist and ErrBadVersion if the version
	// has changed.
	//
	// Do not use directly, but instead use topo.UpdateTablet.
	UpdateTablet(ctx context.Context, tablet *topodatapb.Tablet, existingVersion int64) (newVersion int64, err error)

	// DeleteTablet removes a tablet from the system.
	// We assume no RPC is currently running to it.
	// TODO(alainjobart) verify this assumption, link with RPC code.
	// Can return ErrNoNode if the tablet doesn't exist.
	DeleteTablet(ctx context.Context, alias *topodatapb.TabletAlias) error

	// GetTablet returns the tablet data (includes the current version).
	// Can return ErrNoNode if the tablet doesn't exist.
	GetTablet(ctx context.Context, alias *topodatapb.TabletAlias) (*topodatapb.Tablet, int64, error)

	// GetTabletsByCell returns all the tablets in the given cell.
	// Can return ErrNoNode if no tablet was ever created in that cell.
	GetTabletsByCell(ctx context.Context, cell string) ([]*topodatapb.TabletAlias, error)

	// UpdateShardReplicationFields updates the current
	// ShardReplication record with new values. If the
	// ShardReplication object does not exist, an empty one will
	// be passed to the update function. All necessary directories
	// need to be created by this method, if applicable.
	UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, update func(*topodatapb.ShardReplication) error) error

	// GetShardReplication returns the replication data.
	// Can return ErrNoNode if the object doesn't exist.
	GetShardReplication(ctx context.Context, cell, keyspace, shard string) (*ShardReplicationInfo, error)

	// DeleteShardReplication deletes the replication data.
	// Can return ErrNoNode if the object doesn't exist.
	DeleteShardReplication(ctx context.Context, cell, keyspace, shard string) error

	// DeleteKeyspaceReplication deletes the replication data for all shards.
	// Can return ErrNoNode if the object doesn't exist.
	DeleteKeyspaceReplication(ctx context.Context, cell, keyspace string) error

	// LockSrvShardForAction locks the serving shard in order to
	// perform the action described by contents. It will wait for
	// the lock until at most ctx.Done(). The wait can be interrupted
	// by cancelling the context. It returns the lock path.
	//
	// Can return ErrTimeout or ErrInterrupted.
	LockSrvShardForAction(ctx context.Context, cell, keyspace, shard, contents string) (string, error)

	// UnlockSrvShardForAction unlocks a serving shard.
	UnlockSrvShardForAction(ctx context.Context, cell, keyspace, shard, lockPath, results string) error

	// GetSrvTabletTypesPerShard returns the existing serving types
	// for a shard.
	// Can return ErrNoNode.
	GetSrvTabletTypesPerShard(ctx context.Context, cell, keyspace, shard string) ([]topodatapb.TabletType, error)

	// CreateEndPoints creates and sets the serving records for a cell,
	// keyspace, shard, tabletType.
	// It returns ErrNodeExists if the record already exists.
	CreateEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType, addrs *topodatapb.EndPoints) error

	// UpdateEndPoints updates the serving records for a cell,
	// keyspace, shard, tabletType.
	// If existingVersion is -1, it will set the value unconditionally,
	// creating it if necessary.
	// Otherwise, it will Compare-And-Set only if the version matches.
	// Can return ErrBadVersion.
	// Can return ErrNoNode only if existingVersion is not -1.
	UpdateEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType, addrs *topodatapb.EndPoints, existingVersion int64) error

	// GetEndPoints returns the EndPoints list of serving addresses
	// for a TabletType inside a shard, as well as the node version.
	// Can return ErrNoNode.
	GetEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType) (ep *topodatapb.EndPoints, version int64, err error)

	// DeleteEndPoints deletes the serving records for a cell,
	// keyspace, shard, tabletType.
	// If existingVersion is -1, it will delete the records unconditionally.
	// Otherwise, it will Compare-And-Delete only if the version matches.
	// Can return ErrNoNode or ErrBadVersion.
	DeleteEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType, existingVersion int64) error

	// WatchSrvKeyspace returns a channel that receives notifications
	// every time the SrvKeyspace for the given keyspace / cell changes.
	// It should receive a notification with the initial value fairly
	// quickly after this is set. A value of nil means the SrvKeyspace
	// object doesn't exist or is empty. To stop watching this
	// SrvKeyspace object, cancel the context.
	// If the underlying topo.Server encounters an error watching the node,
	// it should retry on a regular basis until it can succeed.
	// The initial error returned by this method is meant to catch
	// the obvious bad cases (invalid cell, invalid tabletType, ...)
	// that are never going to work. Mutiple notifications with the
	// same contents may be sent (for instance, when the serving graph
	// is rebuilt, but the content of SrvKeyspace is the same,
	// the object version will change, most likely triggering the
	// notification, but the content hasn't changed).
	WatchSrvKeyspace(ctx context.Context, cell, keyspace string) (notifications <-chan *topodatapb.SrvKeyspace, err error)

	// UpdateSrvShard updates the serving records for a cell,
	// keyspace, shard.
	UpdateSrvShard(ctx context.Context, cell, keyspace, shard string, srvShard *topodatapb.SrvShard) error

	// GetSrvShard reads a SrvShard record.
	// Can return ErrNoNode.
	GetSrvShard(ctx context.Context, cell, keyspace, shard string) (*topodatapb.SrvShard, error)

	// DeleteSrvShard deletes a SrvShard record.
	// Can return ErrNoNode.
	DeleteSrvShard(ctx context.Context, cell, keyspace, shard string) error

	// UpdateSrvKeyspace updates the serving records for a cell, keyspace.
	UpdateSrvKeyspace(ctx context.Context, cell, keyspace string, srvKeyspace *topodatapb.SrvKeyspace) error

	// DeleteSrvKeyspace deletes the cell-local serving records for a keyspace.
	// Can return ErrNoNode.
	DeleteSrvKeyspace(ctx context.Context, cell, keyspace string) error

	// GetSrvKeyspace reads a SrvKeyspace record.
	// Can return ErrNoNode.
	GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error)

	// GetSrvKeyspaceNames returns the list of visible Keyspaces
	// in this cell. They shall be sorted.
	GetSrvKeyspaceNames(ctx context.Context, cell string) ([]string, error)

	// LockKeyspaceForAction locks the keyspace in order to
	// perform the action described by contents. It will wait for
	// the lock until at most ctx.Done(). The wait can be interrupted
	// by cancelling the context. It returns the lock path.
	//
	// Can return ErrTimeout or ErrInterrupted
	LockKeyspaceForAction(ctx context.Context, keyspace, contents string) (string, error)

	// UnlockKeyspaceForAction unlocks a keyspace.
	UnlockKeyspaceForAction(ctx context.Context, keyspace, lockPath, results string) error

	// LockShardForAction locks the shard in order to
	// perform the action described by contents. It will wait for
	// the lock until at most ctx.Done(). The wait can be interrupted
	// by cancelling the context. It returns the lock path.
	//
	// Can return ErrTimeout or ErrInterrupted
	LockShardForAction(ctx context.Context, keyspace, shard, contents string) (string, error)

	// UnlockShardForAction unlocks a shard.
	UnlockShardForAction(ctx context.Context, keyspace, shard, lockPath, results string) error

	// SaveVSchema saves the provided schema in the topo server.
	SaveVSchema(context.Context, string) error

	// GetVSchema retrieves the schema from the topo server.
	//
	// If no schema has been previously saved, it should return "{}"
	GetVSchema(ctx context.Context) (string, error)
}

Impl is the interface used to talk to a persistent backend storage server and locking service.

Zookeeper is a good example of this, and zktopo contains the implementation for this using zookeeper.

Inside Google, we use Chubby.

type KeyspaceInfo

type KeyspaceInfo struct {
	*topodatapb.Keyspace
	// contains filtered or unexported fields
}

KeyspaceInfo is a meta struct that contains metadata to give the data more context and convenience. This is the main way we interact with a keyspace.

func (*KeyspaceInfo) CheckServedFromMigration

func (ki *KeyspaceInfo) CheckServedFromMigration(tabletType topodatapb.TabletType, cells []string, keyspace string, remove bool) error

CheckServedFromMigration makes sure a requested migration is safe

func (*KeyspaceInfo) ComputeCellServedFrom

func (ki *KeyspaceInfo) ComputeCellServedFrom(cell string) []*topodatapb.SrvKeyspace_ServedFrom

ComputeCellServedFrom returns the ServedFrom list for a cell

func (*KeyspaceInfo) GetServedFrom

func (ki *KeyspaceInfo) GetServedFrom(tabletType topodatapb.TabletType) *topodatapb.Keyspace_ServedFrom

GetServedFrom returns a Keyspace_ServedFrom record if it exists.

func (*KeyspaceInfo) KeyspaceName

func (ki *KeyspaceInfo) KeyspaceName() string

KeyspaceName returns the keyspace name

func (*KeyspaceInfo) UpdateServedFromMap

func (ki *KeyspaceInfo) UpdateServedFromMap(tabletType topodatapb.TabletType, cells []string, keyspace string, remove bool, allCells []string) error

UpdateServedFromMap handles ServedFromMap. It can add or remove records, cells, ...

type KeyspaceShard

type KeyspaceShard struct {
	Keyspace string
	Shard    string
}

KeyspaceShard is a type used by ResolveShardWildcard

func ResolveShardWildcard

func ResolveShardWildcard(ctx context.Context, server WildcardBackend, param string) ([]KeyspaceShard, error)

ResolveShardWildcard will resolve shard wildcards. Both keyspace and shard names can use wildcard. Errors talking to the topology server are returned. ErrNoNode is ignored if it's the result of resolving a wildcard. Examples:

  • */* returns all keyspace/shard pairs, or empty list if none.
  • user/* returns all shards in user keyspace (or error if user keyspace doesn't exist)
  • us*/* returns all shards in all keyspaces that start with 'us'. If no such keyspace exists, list is empty (it is not an error).

type Server

type Server struct {
	Impl
}

Server is a wrapper type that can have extra methods. Outside modules should just use the Server object.

func GetServer

func GetServer() Server

GetServer returns 'our' Server, going down this list:

  • If only one is registered, that's the one.
  • If more than one are registered, use the 'topo_implementation' flag (which defaults to zookeeper).
  • Then panics.

func GetServerByName

func GetServerByName(name string) Server

GetServerByName returns a specific Server by name, or nil.

func (Server) CreateKeyspace

func (ts Server) CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error

CreateKeyspace wraps the underlying Impl.DeleteKeyspaceShards and dispatches the event.

func (Server) CreateShard

func (ts Server) CreateShard(ctx context.Context, keyspace, shard string) error

CreateShard creates a new shard and tries to fill in the right information. This should be called while holding the keyspace lock for the shard. (call topotools.CreateShard to do that for you). In unit tests (that are not parallel), this function can be called directly.

func (Server) CreateTablet

func (ts Server) CreateTablet(ctx context.Context, tablet *topodatapb.Tablet) error

CreateTablet creates a new tablet and all associated paths for the replication graph.

func (Server) DeleteKeyspace

func (ts Server) DeleteKeyspace(ctx context.Context, keyspace string) error

DeleteKeyspace wraps the underlying Impl.DeleteKeyspace and dispatches the event.

func (Server) DeleteKeyspaceShards

func (ts Server) DeleteKeyspaceShards(ctx context.Context, keyspace string) error

DeleteKeyspaceShards wraps the underlying Impl.DeleteKeyspaceShards and dispatches the event.

func (Server) DeleteShard

func (ts Server) DeleteShard(ctx context.Context, keyspace, shard string) error

DeleteShard wraps the underlying Impl.DeleteShard and dispatches the event.

func (Server) DeleteTablet

func (ts Server) DeleteTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error

DeleteTablet wraps the underlying Impl.DeleteTablet and dispatches the event.

func (Server) FindAllShardsInKeyspace

func (ts Server) FindAllShardsInKeyspace(ctx context.Context, keyspace string) (map[string]*ShardInfo, error)

FindAllShardsInKeyspace reads and returns all the existing shards in a keyspace. It doesn't take any lock.

func (Server) FindAllTabletAliasesInShard

func (ts Server) FindAllTabletAliasesInShard(ctx context.Context, keyspace, shard string) ([]*topodatapb.TabletAlias, error)

FindAllTabletAliasesInShard uses the replication graph to find all the tablet aliases in the given shard.

It can return ErrPartialResult if some cells were not fetched, in which case the result only contains the cells that were fetched.

The tablet aliases are sorted by cell, then by UID.

func (Server) FindAllTabletAliasesInShardByCell

func (ts Server) FindAllTabletAliasesInShardByCell(ctx context.Context, keyspace, shard string, cells []string) ([]*topodatapb.TabletAlias, error)

FindAllTabletAliasesInShardByCell uses the replication graph to find all the tablet aliases in the given shard.

It can return ErrPartialResult if some cells were not fetched, in which case the result only contains the cells that were fetched.

The tablet aliases are sorted by cell, then by UID.

func (Server) GetKeyspace

func (ts Server) GetKeyspace(ctx context.Context, keyspace string) (*KeyspaceInfo, error)

GetKeyspace reads the given keyspace and returns it

func (Server) GetShard

func (ts Server) GetShard(ctx context.Context, keyspace, shard string) (*ShardInfo, error)

GetShard is a high level function to read shard data. It generates trace spans.

func (Server) GetTablet

func (ts Server) GetTablet(ctx context.Context, alias *topodatapb.TabletAlias) (*TabletInfo, error)

GetTablet is a high level function to read tablet data. It generates trace spans.

func (Server) GetTabletMap

func (ts Server) GetTabletMap(ctx context.Context, tabletAliases []*topodatapb.TabletAlias) (map[topodatapb.TabletAlias]*TabletInfo, error)

GetTabletMap tries to read all the tablets in the provided list, and returns them all in a map. If error is ErrPartialResult, the results in the dictionary are incomplete, meaning some tablets couldn't be read.

func (Server) GetTabletMapForShard

func (ts Server) GetTabletMapForShard(ctx context.Context, keyspace, shard string) (map[topodatapb.TabletAlias]*TabletInfo, error)

GetTabletMapForShard returns the tablets for a shard. It can return ErrPartialResult if it couldn't read all the cells, or all the individual tablets, in which case the map is valid, but partial.

func (Server) GetTabletMapForShardByCell

func (ts Server) GetTabletMapForShardByCell(ctx context.Context, keyspace, shard string, cells []string) (map[topodatapb.TabletAlias]*TabletInfo, error)

GetTabletMapForShardByCell returns the tablets for a shard. It can return ErrPartialResult if it couldn't read all the cells, or all the individual tablets, in which case the map is valid, but partial.

func (Server) UpdateKeyspace

func (ts Server) UpdateKeyspace(ctx context.Context, ki *KeyspaceInfo) error

UpdateKeyspace updates the keyspace data, with the right version

func (Server) UpdateShard

func (ts Server) UpdateShard(ctx context.Context, si *ShardInfo) error

UpdateShard updates the shard data, with the right version. It also creates a span, and dispatches the event.

func (Server) UpdateShardFields

func (ts Server) UpdateShardFields(ctx context.Context, keyspace, shard string, update func(*topodatapb.Shard) error) (*ShardInfo, error)

UpdateShardFields is a high level helper to read a shard record, call an update function on it, and then write it back. If the write fails due to a version mismatch, it will re-read the record and retry the update. If the update succeeds, it returns the updated ShardInfo. If the update method returns ErrNoUpdateNeeded, nothing is written, and nil,nil is returned.

func (Server) UpdateTablet

func (ts Server) UpdateTablet(ctx context.Context, tablet *TabletInfo) error

UpdateTablet updates the tablet data only - not associated replication paths. It also uses a span, and sends the event.

func (Server) UpdateTabletFields

func (ts Server) UpdateTabletFields(ctx context.Context, alias *topodatapb.TabletAlias, update func(*topodatapb.Tablet) error) (*topodatapb.Tablet, error)

UpdateTabletFields is a high level helper to read a tablet record, call an update function on it, and then write it back. If the write fails due to a version mismatch, it will re-read the record and retry the update. If the update succeeds, it returns the updated tablet. If the update method returns ErrNoUpdateNeeded, nothing is written, and nil,nil is returned.

type ShardInfo

type ShardInfo struct {
	*topodatapb.Shard
	// contains filtered or unexported fields
}

ShardInfo is a meta struct that contains metadata to give the data more context and convenience. This is the main way we interact with a shard.

func NewShardInfo

func NewShardInfo(keyspace, shard string, value *topodatapb.Shard, version int64) *ShardInfo

NewShardInfo returns a ShardInfo basing on shard with the keyspace / shard. This function should be only used by Server implementations.

func (*ShardInfo) CheckServedTypesMigration

func (si *ShardInfo) CheckServedTypesMigration(tabletType topodatapb.TabletType, cells []string, remove bool) error

CheckServedTypesMigration makes sure the provided migration is possible

func (*ShardInfo) GetServedType

func (si *ShardInfo) GetServedType(tabletType topodatapb.TabletType) *topodatapb.Shard_ServedType

GetServedType returns the Shard_ServedType for a TabletType, or nil

func (*ShardInfo) GetServedTypesPerCell

func (si *ShardInfo) GetServedTypesPerCell(cell string) []topodatapb.TabletType

GetServedTypesPerCell returns the list of types this shard is serving in the provided cell.

func (*ShardInfo) GetTabletControl

func (si *ShardInfo) GetTabletControl(tabletType topodatapb.TabletType) *topodatapb.Shard_TabletControl

GetTabletControl returns the Shard_TabletControl for the given tablet type, or nil if it is not in the map.

func (*ShardInfo) HasCell

func (si *ShardInfo) HasCell(cell string) bool

HasCell returns true if the cell is listed in the Cells for the shard.

func (*ShardInfo) HasMaster

func (si *ShardInfo) HasMaster() bool

HasMaster returns true if the Shard has an assigned Master.

func (*ShardInfo) Keyspace

func (si *ShardInfo) Keyspace() string

Keyspace returns the keyspace a shard belongs to.

func (*ShardInfo) ShardName

func (si *ShardInfo) ShardName() string

ShardName returns the shard name for a shard.

func (*ShardInfo) UpdateDisableQueryService

func (si *ShardInfo) UpdateDisableQueryService(tabletType topodatapb.TabletType, cells []string, disableQueryService bool) error

UpdateDisableQueryService will make sure the disableQueryService is set appropriately in the shard record. Note we don't support a lot of the corner cases:

  • we don't support DisableQueryService at the same time as BlacklistedTables, because it's not used in the same context (vertical vs horizontal sharding)

func (*ShardInfo) UpdateServedTypesMap

func (si *ShardInfo) UpdateServedTypesMap(tabletType topodatapb.TabletType, cells []string, remove bool) error

UpdateServedTypesMap handles ServedTypesMap. It can add or remove records, cells, ...

func (*ShardInfo) UpdateSourceBlacklistedTables

func (si *ShardInfo) UpdateSourceBlacklistedTables(tabletType topodatapb.TabletType, cells []string, remove bool, tables []string) error

UpdateSourceBlacklistedTables will add or remove the listed tables in the shard record's TabletControl structures. Note we don't support a lot of the corner cases:

  • only support one table list per shard. If we encounter a different table list that the provided one, we error out.
  • we don't support DisableQueryService at the same time as BlacklistedTables, because it's not used in the same context (vertical vs horizontal sharding)

func (*ShardInfo) Version

func (si *ShardInfo) Version() int64

Version returns the shard version from last time it was read or updated.

type ShardReplicationInfo

type ShardReplicationInfo struct {
	*topodatapb.ShardReplication
	// contains filtered or unexported fields
}

ShardReplicationInfo is the companion structure for ShardReplication.

func NewShardReplicationInfo

func NewShardReplicationInfo(sr *topodatapb.ShardReplication, cell, keyspace, shard string) *ShardReplicationInfo

NewShardReplicationInfo is for topo.Server implementations to create the structure

func (*ShardReplicationInfo) Cell

func (sri *ShardReplicationInfo) Cell() string

Cell returns the cell for a ShardReplicationInfo

func (*ShardReplicationInfo) GetShardReplicationNode

func (sri *ShardReplicationInfo) GetShardReplicationNode(tabletAlias *topodatapb.TabletAlias) (*topodatapb.ShardReplication_Node, error)

GetShardReplicationNode finds a node for a given tablet.

func (*ShardReplicationInfo) Keyspace

func (sri *ShardReplicationInfo) Keyspace() string

Keyspace returns the keyspace for a ShardReplicationInfo

func (*ShardReplicationInfo) Shard

func (sri *ShardReplicationInfo) Shard() string

Shard returns the shard for a ShardReplicationInfo

type SrvTopoServer

type SrvTopoServer interface {
	GetSrvKeyspaceNames(ctx context.Context, cell string) ([]string, error)

	GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error)

	GetSrvShard(ctx context.Context, cell, keyspace, shard string) (*topodatapb.SrvShard, error)

	GetEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType) (*topodatapb.EndPoints, int64, error)
}

SrvTopoServer is a subset of Server that only contains the serving graph read-only calls used by clients to resolve serving addresses.

type TabletInfo

type TabletInfo struct {
	*topodatapb.Tablet
	// contains filtered or unexported fields
}

TabletInfo is the container for a Tablet, read from the topology server.

func NewTabletInfo

func NewTabletInfo(tablet *topodatapb.Tablet, version int64) *TabletInfo

NewTabletInfo returns a TabletInfo basing on tablet with the version set. This function should be only used by Server implementations.

func (*TabletInfo) Addr

func (ti *TabletInfo) Addr() string

Addr returns hostname:vt port.

func (*TabletInfo) AliasString

func (ti *TabletInfo) AliasString() string

AliasString returns the string representation of the tablet alias

func (*TabletInfo) DbName

func (ti *TabletInfo) DbName() string

DbName is usually implied by keyspace. Having the shard information in the database name complicates mysql replication.

func (*TabletInfo) IsInServingGraph

func (ti *TabletInfo) IsInServingGraph() bool

IsInServingGraph returns if this tablet is in the serving graph

func (*TabletInfo) IsSlaveType

func (ti *TabletInfo) IsSlaveType() bool

IsSlaveType returns if this tablet's type is a slave

func (*TabletInfo) MysqlAddr

func (ti *TabletInfo) MysqlAddr() string

MysqlAddr returns hostname:mysql port.

func (*TabletInfo) String

func (ti *TabletInfo) String() string

String returns a string describing the tablet.

func (*TabletInfo) Version

func (ti *TabletInfo) Version() int64

Version returns the version of this tablet from last time it was read or updated.

type WildcardBackend

type WildcardBackend interface {
	// GetKeyspaces returns the known keyspaces. They shall be sorted.
	GetKeyspaces(ctx context.Context) ([]string, error)

	// GetShard reads a shard and returns it.
	// Can return ErrNoNode
	GetShard(ctx context.Context, keyspace, shard string) (*ShardInfo, error)

	// GetShardNames returns the known shards in a keyspace.
	// Can return ErrNoNode
	GetShardNames(ctx context.Context, keyspace string) ([]string, error)
}

WildcardBackend is a subset of Server for the methods used by the wildcard code. This lets us test with a very simple fake topo server.

Directories

Path Synopsis
Package events defines the structures used for events relating directly to individual topology elements, like keyspaces, shards, and tablets.
Package events defines the structures used for events relating directly to individual topology elements, like keyspaces, shards, and tablets.
Package helpers contains a few utility classes to handle topo.Server objects, and transitions from one topo implementation to another.
Package helpers contains a few utility classes to handle topo.Server objects, and transitions from one topo implementation to another.
Package test contains utilities to test topo.Impl implementations.
Package test contains utilities to test topo.Impl implementations.
faketopo
Package faketopo contains utitlities for tests that have to interact with a Vitess topology.
Package faketopo contains utitlities for tests that have to interact with a Vitess topology.
Package topoproto contains utility functions to deal with the proto3 structures defined in proto/topodata.
Package topoproto contains utility functions to deal with the proto3 structures defined in proto/topodata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL