topo

package
v0.0.0-...-9a5932e Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2014 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// idle -  no keyspace, shard or type assigned
	TYPE_IDLE = TabletType("idle")

	// primary copy of data
	TYPE_MASTER = TabletType("master")

	// a slaved copy of the data ready to be promoted to master
	TYPE_REPLICA = TabletType("replica")

	// a slaved copy of the data for olap load patterns.
	// too many aliases for olap - need to pick one
	TYPE_RDONLY = TabletType("rdonly")
	TYPE_BATCH  = TabletType("batch")

	// a slaved copy of the data ready, but not serving query traffic
	// could be a potential master.
	TYPE_SPARE = TabletType("spare")

	// a slaved copy of the data ready, but not serving query traffic
	// implies something abnormal about the setup - don't consider it
	// a potential master and don't worry about lag when reparenting.
	TYPE_EXPERIMENTAL = TabletType("experimental")

	// a slaved copy of the data intentionally lagged for pseudo backup
	TYPE_LAG = TabletType("lag")
	// when a reparent occurs, the tablet goes into lag_orphan state until
	// it can be reparented properly
	TYPE_LAG_ORPHAN = TabletType("lag_orphan")

	// a slaved copy of the data that was serving but is now applying
	// a schema change. Will go bak to its serving type after the
	// upgrade
	TYPE_SCHEMA_UPGRADE = TabletType("schema_apply")

	// a slaved copy of the data, but offline to queries other than backup
	// replication sql thread may be stopped
	TYPE_BACKUP = TabletType("backup")

	// a slaved copy of the data, where mysqld is *not* running,
	// and we are serving our data files to clone slaves
	// use 'vtctl Snapshot -server-mode ...' to get in this mode
	// use 'vtctl SnapshotSourceEnd ...' to get out of this mode
	TYPE_SNAPSHOT_SOURCE = TabletType("snapshot_source")

	// A tablet that has not been in the replication graph and is restoring
	// from a snapshot.  idle -> restore -> spare
	TYPE_RESTORE = TabletType("restore")

	// A tablet that is running a checker process. It is probably
	// lagging in replication.
	TYPE_CHECKER = TabletType("checker")

	// a machine with data that needs to be wiped
	TYPE_SCRAP = TabletType("scrap")
)
View Source
const (
	// The normal state for a master
	STATE_READ_WRITE = TabletState("ReadWrite")

	// The normal state for a slave, or temporarily a master. Not
	// to be confused with type, which implies a workload.
	STATE_READ_ONLY = TabletState("ReadOnly")
)
View Source
const (
	// DefaultPortName is the port named used by SrvEntries
	// if "" is given as the named port.
	DefaultPortName = "_vtocc"
)
View Source
const (
	// According to docs, the tablet uid / (mysql server id) is uint32.
	// However, zero appears to be a sufficiently degenerate value to use
	// as a marker for not having a parent server id.
	// http://dev.mysql.com/doc/refman/5.1/en/replication-options.html
	NO_TABLET = 0
)
View Source
const SHARD_ZERO = "0"

This is the shard name for when the keyrange covers the entire space for unsharded database.

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")
)

Functions

func AddShardReplicationRecord

func AddShardReplicationRecord(ts Server, keyspace, shard string, tabletAlias, parent TabletAlias) error

AddShardReplicationRecord is a low level function to add an entry to the ShardReplication object.

func CloseServers

func CloseServers()

Close all registered Server.

func CreateShard

func CreateShard(ts Server, keyspace, shard string) error

CreateShard creates a new shard and tries to fill in the right information.

func CreateTablet

func CreateTablet(ts Server, tablet *Tablet) error

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

func CreateTabletReplicationData

func CreateTabletReplicationData(ts Server, tablet *Tablet) error

CreateTabletReplicationData creates the replication graph data for a tablet

func DecodeKeyspacePartitionMap

func DecodeKeyspacePartitionMap(buf *bytes.Buffer, kind byte) map[TabletType]*KeyspacePartition

func DecodeServedFrom

func DecodeServedFrom(buf *bytes.Buffer, kind byte) map[TabletType]string

func DeleteTabletReplicationData

func DeleteTabletReplicationData(ts Server, tablet *Tablet) error

DeleteTabletReplicationData deletes replication data.

func EncodeKeyspacePartitionMap

func EncodeKeyspacePartitionMap(buf *bytes2.ChunkedWriter, name string, values map[TabletType]*KeyspacePartition)

func EncodeServedFrom

func EncodeServedFrom(buf *bytes2.ChunkedWriter, name string, servedFrom map[TabletType]string)

func EncodeSrvShardArray

func EncodeSrvShardArray(buf *bytes2.ChunkedWriter, name string, values []SrvShard)

func EncodeTabletTypeArray

func EncodeTabletTypeArray(buf *bytes2.ChunkedWriter, name string, values []TabletType)

func EndPointEquality

func EndPointEquality(left, right *EndPoint) bool

func FindAllShardsInKeyspace

func FindAllShardsInKeyspace(ts Server, keyspace string) (map[string]*ShardInfo, error)

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

func FixShardReplication

func FixShardReplication(ts Server, cell, keyspace, shard string) error

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

func GetSubprocessFlags

func GetSubprocessFlags() []string

GetSubprocessFlags returns all the flags required to launch a subprocess with the exact same topology server as the current process.

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 IsInReplicationGraph

func IsInReplicationGraph(tt TabletType) bool

IsInReplicationGraph returns if this tablet appears in the replication graph Only IDLE and SCRAP are not in the replication graph. The other non-obvious types are BACKUP, SNAPSHOT_SOURCE, RESTORE and LAG_ORPHAN: these have had a master at some point (or were the master), so they are in the graph.

func IsInServingGraph

func IsInServingGraph(tt TabletType) bool

IsInServingGraph returns if a tablet appears in the serving graph

func IsRunningQueryService

func IsRunningQueryService(tt TabletType) bool

IsRunningQueryService returns if a tablet is running the query service

func IsSlaveType

func IsSlaveType(tt 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) IDLE and SCRAP are not either BACKUP, RESTORE, LAG_ORPHAN, TYPE_CHECKER may or may not be, but we don't know for sure

func IsTrivialTypeChange

func IsTrivialTypeChange(oldTabletType, newTabletType TabletType) bool

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

func IsTypeInList

func IsTypeInList(tabletType TabletType, types []TabletType) bool

IsTypeInList returns true if the given type is in the list. Use it with AllTabletType and SlaveTabletType for instance.

func IsValidTypeChange

func IsValidTypeChange(oldTabletType, newTabletType TabletType) bool

IsValidTypeChange returns if we should we allow this transition at all. Most transitions are allowed, but some don't make sense under any circumstances. If a transistion could be forced, don't disallow it here.

func LookupVtName

func LookupVtName(ts Server, cell, keyspace, shard string, tabletType TabletType, namedPort string) ([]*net.SRV, error)

func MakeStringTypeList

func MakeStringTypeList(types []TabletType) []string

MakeStringTypeList returns a list of strings that match the input list.

func ParseUid

func ParseUid(value string) (uint32, error)

func RegisterServer

func RegisterServer(name string, ts Server)

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 RegisterTopoReader

func RegisterTopoReader(tr TopoReader)

func RemoveShardReplicationRecord

func RemoveShardReplicationRecord(ts Server, keyspace, shard string, tabletAlias TabletAlias) error

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

func ResolveKeyspaceWildcard

func ResolveKeyspaceWildcard(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 SrvAddr

func SrvAddr(srv *net.SRV) string

func SrvEntries

func SrvEntries(addrs *EndPoints, namedPort string) (srvs []*net.SRV, err error)

FIXME(msolomon) merge with zkns

func UpdateTablet

func UpdateTablet(ts Server, tablet *TabletInfo) error

UpdateTablet updates the tablet data only - not associated replication paths.

func Validate

func Validate(ts Server, tabletAlias TabletAlias) error

func ValidateShardName

func ValidateShardName(shard string) (string, key.KeyRange, error)

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

Types

type EndPoint

type EndPoint struct {
	Uid          uint32         `json:"uid"` // Keep track of which tablet this corresponds to.
	Host         string         `json:"host"`
	NamedPortMap map[string]int `json:"named_port_map"`
}

func NewAddr

func NewAddr(uid uint32, host string) *EndPoint

type EndPoints

type EndPoints struct {
	Entries []EndPoint `json:"entries"`
}

func NewEndPoints

func NewEndPoints() *EndPoints

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

type GetEndPointsArgs

type GetEndPointsArgs struct {
	Cell       string
	Keyspace   string
	Shard      string
	TabletType TabletType
}

type GetSrvKeyspaceArgs

type GetSrvKeyspaceArgs struct {
	Cell     string
	Keyspace string
}

type GetSrvKeyspaceNamesArgs

type GetSrvKeyspaceNamesArgs struct {
	Cell string
}

type Keyspace

type Keyspace struct {
	// name of the column used for sharding
	// empty if the keyspace is not sharded
	ShardingColumnName string

	// type of the column used for sharding
	// KIT_UNSET if the keyspace is not sharded
	ShardingColumnType key.KeyspaceIdType

	// ServedFrom will redirect the appropriate traffic to
	// another keyspace
	ServedFrom map[TabletType]string
}

type KeyspaceInfo

type KeyspaceInfo struct {
	*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 NewKeyspaceInfo

func NewKeyspaceInfo(keyspace string, value *Keyspace) *KeyspaceInfo

NewKeyspaceInfo returns a KeyspaceInfo basing on keyspace with the keyspace. This function should be only used by Server implementations.

func (*KeyspaceInfo) KeyspaceName

func (ki *KeyspaceInfo) KeyspaceName() string

KeyspaceName returns the keyspace name

type KeyspacePartition

type KeyspacePartition struct {
	// List of non-overlapping continuous shards sorted by range.
	Shards []SrvShard
}

KeyspacePartition represents a continuous set of shards to serve an entire data set.

func (*KeyspacePartition) MarshalBson

func (kp *KeyspacePartition) MarshalBson(buf *bytes2.ChunkedWriter, key string)

func (*KeyspacePartition) UnmarshalBson

func (kp *KeyspacePartition) UnmarshalBson(buf *bytes.Buffer, kind byte)

type KeyspaceShard

type KeyspaceShard struct {
	Keyspace string
	Shard    string
}

KeyspaceShard is a type used by ResolveShardWildcard

func ResolveShardWildcard

func ResolveShardWildcard(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 ReplicationLink struct {
	TabletAlias TabletAlias
	Parent      TabletAlias
}

ReplicationLink describes a MySQL replication relationship

type Server

type Server 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() ([]string, error)

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

	// UpdateKeyspace unconditionnally 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.
	UpdateKeyspace(ki *KeyspaceInfo) error

	// GetKeyspace reads a keyspace and returns it. This returns an
	// object stored in the global cell.
	// Can return ErrNoNode
	GetKeyspace(keyspace string) (*KeyspaceInfo, error)

	// GetKeyspaces returns the known keyspaces. They shall be sorted.
	GetKeyspaces() ([]string, error)

	// DeleteKeyspaceShards deletes all the shards in a keyspace.
	// Use with caution.
	DeleteKeyspaceShards(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(keyspace, shard string, value *Shard) error

	// UpdateShard unconditionnally 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.
	UpdateShard(si *ShardInfo) error

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

	// GetShard reads a shard and returns it. This returns an
	// object stored in the global cell, and a topology
	// implementation may choose to return a value from some sort
	// of cache. If you need stronger consistency guarantees,
	// please use GetShardCritical.
	//
	// Can return ErrNoNode
	GetShard(keyspace, shard string) (*ShardInfo, error)

	// GetShardCritical is like GetShard, but it always returns
	// consistent data.
	GetShardCritical(keyspace, shard string) (si *ShardInfo, err 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(keyspace string) ([]string, error)

	// DeleteShard deletes the provided shard.
	// Can return ErrNoNode if the shard doesn't exist.
	DeleteShard(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(tablet *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.
	UpdateTablet(tablet *TabletInfo, existingVersion int64) (newVersion int64, err error)

	// UpdateTabletFields updates the current tablet record
	// with new values, independently of the version
	// Can return ErrNoNode if the tablet doesn't exist.
	UpdateTabletFields(tabletAlias TabletAlias, update func(*Tablet) error) 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(alias TabletAlias) error

	// ValidateTablet performs routine checks on the tablet.
	ValidateTablet(alias TabletAlias) error

	// GetTablet returns the tablet data (includes the current version).
	// Can return ErrNoNode if the tablet doesn't exist.
	GetTablet(alias TabletAlias) (*TabletInfo, error)

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

	// CreateShardReplication creates the ShardReplication object,
	// assuming it doesn't exist yet.
	// Can return ErrNodeExists if it already exists.
	CreateShardReplication(cell, keyspace, shard string, sr *ShardReplication) error

	// UpdateShardReplicationFields updates the current
	// ShardReplication record with new values
	// Can return ErrNoNode if the object doesn't exist.
	UpdateShardReplicationFields(cell, keyspace, shard string, update func(*ShardReplication) error) error

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

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

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

	// UpdateEndPoints updates the serving records for a cell,
	// keyspace, shard, tabletType.
	UpdateEndPoints(cell, keyspace, shard string, tabletType TabletType, addrs *EndPoints) error

	// GetEndPoints returns the EndPoints list of serving addresses
	// for a TabletType inside a shard.
	// Can return ErrNoNode.
	GetEndPoints(cell, keyspace, shard string, tabletType TabletType) (*EndPoints, error)

	// DeleteSrvTabletType deletes the serving records for a cell,
	// keyspace, shard, tabletType.
	// Can return ErrNoNode.
	DeleteSrvTabletType(cell, keyspace, shard string, tabletType TabletType) error

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

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

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

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

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

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

	// UpdateTabletEndpoint updates a single tablet record in the
	// already computed serving graph. The update has to be somewhat
	// atomic, so it requires Server intrisic knowledge.
	// If the node doesn't exist, it is not updated, this is not an error.
	UpdateTabletEndpoint(cell, keyspace, shard string, tabletType TabletType, addr *EndPoint) error

	// LockKeyspaceForAction locks the keyspace in order to
	// perform the action described by contents. It will wait for
	// the lock for at most duration. The wait can be interrupted
	// if the interrupted channel is closed. It returns the lock
	// path.
	// Can return ErrTimeout or ErrInterrupted
	LockKeyspaceForAction(keyspace, contents string, timeout time.Duration, interrupted chan struct{}) (string, error)

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

	// LockShardForAction locks the shard in order to
	// perform the action described by contents. It will wait for
	// the lock for at most duration. The wait can be interrupted
	// if the interrupted channel is closed. It returns the lock
	// path.
	// Can return ErrTimeout or ErrInterrupted
	LockShardForAction(keyspace, shard, contents string, timeout time.Duration, interrupted chan struct{}) (string, error)

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

	// WriteTabletAction initiates a remote action on the tablet.
	// Actions are queued up, and executed sequentially.  An
	// action is identified by the returned string, actionPath.
	WriteTabletAction(tabletAlias TabletAlias, contents string) (string, error)

	// WaitForTabletAction waits for a tablet action to complete. It
	// will wait for the result for at most duration. The wait can
	// be interrupted if the interrupted channel is closed.
	// Can return ErrTimeout or ErrInterrupted
	WaitForTabletAction(actionPath string, waitTime time.Duration, interrupted chan struct{}) (string, error)

	// PurgeTabletActions removes all queued actions for a tablet.
	// This might break the locking mechanism of the remote action
	// queue, used with caution.
	PurgeTabletActions(tabletAlias TabletAlias, canBePurged func(data string) bool) error

	// ValidateTabletActions checks a tablet can execute remote
	// actions.
	ValidateTabletActions(tabletAlias TabletAlias) error

	// CreateTabletPidNode will keep a PID node up to date with
	// this tablet's current PID, until 'done' is closed.
	CreateTabletPidNode(tabletAlias TabletAlias, contents string, done chan struct{}) error

	// ValidateTabletPidNode makes sure a PID file exists for the tablet
	ValidateTabletPidNode(tabletAlias TabletAlias) error

	// GetSubprocessFlags returns the flags required to run a
	// subprocess that uses the same Server parameters as
	// this process.
	GetSubprocessFlags() []string

	// ActionEventLoop is the main loop for the action processing engine.
	// It will feed events to the dispatchAction callback.
	// If dispatchAction returns an error, we'll wait a bit before trying
	// again.
	// If 'done' is closed, the loop returns.
	ActionEventLoop(tabletAlias TabletAlias, dispatchAction func(actionPath, data string) error, done chan struct{})

	// ReadTabletActionPath reads the actionPath and returns the
	// associated TabletAlias, the data (originally written by
	// WriteTabletAction), and its version
	ReadTabletActionPath(actionPath string) (TabletAlias, string, int64, error)

	// UpdateTabletAction updates the actionPath with the new data.
	// version is the current version we're expecting. Use -1 to set
	// any version.
	// Can return ErrBadVersion.
	UpdateTabletAction(actionPath, data string, version int64) error

	// StoreTabletActionResponse stores the data for the response.
	// This will not unblock the caller yet.
	StoreTabletActionResponse(actionPath, data string) error

	// UnblockTabletAction will let the client continue.
	// StoreTabletActionResponse must have been called already.
	UnblockTabletAction(actionPath string) error
}

topo.Server 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.

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

Returns a specific Server by name, or nil.

type Shard

type Shard struct {
	// There can be only at most one master, but there may be none. (0)
	MasterAlias TabletAlias

	// This must match the shard name based on our other conventions, but
	// helpful to have it decomposed here.
	KeyRange key.KeyRange

	// ServedTypes is a list of all the tablet types this shard will
	// serve. This is usually used with overlapping shards during
	// data shuffles like shard splitting.
	ServedTypes []TabletType

	// SourceShards is the list of shards we're replicating from,
	// using filtered replication.
	SourceShards []SourceShard

	// Cells is the list of cells that have tablets for this shard.
	// It is populated at InitTablet time when a tabelt is added
	// in a cell that is not in the list yet.
	Cells []string
}

A pure data struct for information stored in topology server. This node is used to present a controlled view of the shard, unaware of every management action. It also contains configuration data for a shard.

func (*Shard) HasCell

func (shard *Shard) HasCell(cell string) bool

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

type ShardInfo

type ShardInfo struct {
	*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 *Shard) *ShardInfo

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

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

type ShardReplication

type ShardReplication struct {
	// Note there can be only one ReplicationLink in this array
	// for a given Slave (each Slave can only have one parent)
	ReplicationLinks []ReplicationLink
}

ShardReplication describes the MySQL replication relationships whithin a cell.

func (sr *ShardReplication) GetReplicationLink(tabletAlias TabletAlias) (ReplicationLink, error)

type ShardReplicationInfo

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

ShardReplicationInfo is the companion structure for ShardReplication.

func NewShardReplicationInfo

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

For topo.Server implementations to create the structure

func (*ShardReplicationInfo) Cell

func (sri *ShardReplicationInfo) Cell() string

func (*ShardReplicationInfo) Keyspace

func (sri *ShardReplicationInfo) Keyspace() string

func (*ShardReplicationInfo) Shard

func (sri *ShardReplicationInfo) Shard() string

type SourceShard

type SourceShard struct {
	// Uid is the unique ID for this SourceShard object.
	// It is for instance used as a unique index in blp_checkpoint
	// when storing the position. It should be unique whithin a
	// destination Shard, but not globally unique.
	Uid uint32

	// the source keyspace
	Keyspace string

	// the source shard
	Shard string

	// The source shard keyrange
	// If partial, len(Tables) has to be zero
	KeyRange key.KeyRange

	// The source table list to replicate
	// If non-empty, KeyRange must not be partial (must be KeyRange{})
	Tables []string
}

SourceShard represents a data source for filtered replication accross shards. When this is used in a destination shard, the master of that shard will run filtered replication.

func (*SourceShard) String

func (source *SourceShard) String() string

type SrvKeyspace

type SrvKeyspace struct {
	// Shards to use per type, only contains complete partitions.
	Partitions map[TabletType]*KeyspacePartition

	// This list will be deprecated as soon as Partitions is used.
	// List of non-overlapping shards sorted by range.
	Shards []SrvShard

	// List of available tablet types for this keyspace in this cell.
	// May not have a server for every shard, but we have some.
	TabletTypes []TabletType

	// Copied from Keyspace
	ShardingColumnName string
	ShardingColumnType key.KeyspaceIdType
	ServedFrom         map[TabletType]string
	// contains filtered or unexported fields
}

A distilled serving copy of keyspace detail stored in the local cell for fast access. Derived from the global keyspace, shards and local details. In zk, it is in /zk/local/vt/ns/<keyspace>

func NewSrvKeyspace

func NewSrvKeyspace(version int64) *SrvKeyspace

func (*SrvKeyspace) MarshalBson

func (sk *SrvKeyspace) MarshalBson(buf *bytes2.ChunkedWriter, key string)

func (*SrvKeyspace) UnmarshalBson

func (sk *SrvKeyspace) UnmarshalBson(buf *bytes.Buffer, kind byte)

type SrvKeyspaceNames

type SrvKeyspaceNames struct {
	Entries []string
}

type SrvShard

type SrvShard struct {
	// Copied from Shard
	KeyRange    key.KeyRange
	ServedTypes []TabletType

	// TabletTypes represents the list of types we have serving tablets
	// for, in this cell only.
	TabletTypes []TabletType
	// contains filtered or unexported fields
}

SrvShard contains a roll-up of the shard in the local namespace. In zk, it is under /zk/<cell>/vt/ns/<keyspace>/<shard>

func DecodeSrvShardArray

func DecodeSrvShardArray(buf *bytes.Buffer, kind byte) []SrvShard

func NewSrvShard

func NewSrvShard(version int64) *SrvShard

func (*SrvShard) MarshalBson

func (ss *SrvShard) MarshalBson(buf *bytes2.ChunkedWriter, key string)

func (*SrvShard) ShardName

func (ss *SrvShard) ShardName() string

func (*SrvShard) UnmarshalBson

func (ss *SrvShard) UnmarshalBson(buf *bytes.Buffer, kind byte)

type SrvShardArray

type SrvShardArray []SrvShard

func (SrvShardArray) Len

func (sa SrvShardArray) Len() int

func (SrvShardArray) Less

func (sa SrvShardArray) Less(i, j int) bool

func (SrvShardArray) Sort

func (sa SrvShardArray) Sort()

func (SrvShardArray) Swap

func (sa SrvShardArray) Swap(i, j int)

type Tablet

type Tablet struct {
	Cell        string      // the cell this tablet is assigned to (doesn't change). DEPRECATED: use Alias
	Uid         uint32      // the server id for this instance. DEPRECATED: use Alias
	Parent      TabletAlias // the globally unique alias for our replication parent - zero if this is the global master
	Addr        string      // host:port for queryserver. DEPRECATED: use Hostname and Portmap
	SecureAddr  string      // host:port for queryserver using encrypted connection. DEPRECATED: use Hostname and Portmap
	MysqlAddr   string      // host:port for the mysql instance. DEPRECATED: use Hostname and Portmap
	MysqlIpAddr string      // ip:port for the mysql instance - needed to match slaves with tablets and preferable to relying on reverse dns. DEPRECATED: use IPAddr and Portmap

	// What is this tablet?
	Alias TabletAlias

	// Locaiton of the tablet
	Hostname string
	IPAddr   string

	// Named port names. Currently supported ports: vt, vts,
	// mysql.
	Portmap map[string]int

	// Tags contain freeform information about the tablet.
	Tags map[string]string

	// Information about the tablet inside a keyspace/shard
	Keyspace string
	Shard    string
	Type     TabletType

	// Is the tablet read-only?
	State TabletState

	// Normally the database name is implied by "vt_" + keyspace. I
	// really want to remove this but there are some databases that are
	// hard to rename.
	DbNameOverride string
	KeyRange       key.KeyRange

	// BlacklistedTables is a list of tables we're not going to serve
	// data for. This is used in vertical splits.
	BlacklistedTables []string
}

Tablet is a pure data struct for information serialized into json and stored into topo.Server

func (*Tablet) Complete

func (tablet *Tablet) Complete() error

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

func (*Tablet) DbName

func (tablet *Tablet) DbName() string

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

func (*Tablet) GetAddr

func (tablet *Tablet) GetAddr() string

func (*Tablet) GetMysqlAddr

func (tablet *Tablet) GetMysqlAddr() string

func (*Tablet) GetMysqlIpAddr

func (tablet *Tablet) GetMysqlIpAddr() string

func (*Tablet) IsAssigned

func (tablet *Tablet) IsAssigned() bool

Was this tablet ever assigned data? A "scrap" node will show up as assigned even though its data cannot be used for serving.

func (*Tablet) IsInReplicationGraph

func (tablet *Tablet) IsInReplicationGraph() bool

func (*Tablet) IsInServingGraph

func (tablet *Tablet) IsInServingGraph() bool

func (*Tablet) IsRunningQueryService

func (tablet *Tablet) IsRunningQueryService() bool

func (*Tablet) IsSlaveType

func (tablet *Tablet) IsSlaveType() bool

func (*Tablet) Json

func (tablet *Tablet) Json() string

func (*Tablet) String

func (tablet *Tablet) String() string

func (*Tablet) ValidatePortmap

func (tablet *Tablet) ValidatePortmap() error

ValidatePortmap returns an error if the tablet's portmap doesn't contain all the necessary ports for the tablet to be fully operational.

type TabletAlias

type TabletAlias struct {
	Cell string
	Uid  uint32
}

TabletAlias is the minimum required information to locate a tablet.

Tablets are really globally unique, but crawling every cell to find out where it lives is time consuming and expensive. This is only needed during complex operations. Tablet cell assignments don't change that often, thus using a TabletAlias is efficient.

func FindAllTabletAliasesInShard

func FindAllTabletAliasesInShard(ts Server, keyspace, shard string) ([]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.

func FindAllTabletAliasesInShardByCell

func FindAllTabletAliasesInShardByCell(ts Server, keyspace, shard string, cells []string) ([]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.

func ParseTabletAliasString

func ParseTabletAliasString(aliasStr string) (result TabletAlias, err error)

func (TabletAlias) IsZero

func (ta TabletAlias) IsZero() bool

func (TabletAlias) String

func (ta TabletAlias) String() string

func (TabletAlias) TabletUidStr

func (ta TabletAlias) TabletUidStr() string

type TabletAliasList

type TabletAliasList []TabletAlias

TabletAliasList is used mainly for sorting

func (TabletAliasList) Len

func (tal TabletAliasList) Len() int

func (TabletAliasList) Less

func (tal TabletAliasList) Less(i, j int) bool

func (TabletAliasList) Swap

func (tal TabletAliasList) Swap(i, j int)

type TabletInfo

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

func NewTabletInfo

func NewTabletInfo(tablet *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) Version

func (ti *TabletInfo) Version() int64

type TabletState

type TabletState string

TabletState describe if the tablet is read-only or read-write.

type TabletType

type TabletType string

TabletType is the main type for a tablet. It has an implication on: - the replication graph - the services run by vttablet on a tablet - the uptime expectancy

func DecodeTabletTypeArray

func DecodeTabletTypeArray(buf *bytes.Buffer, kind byte) []TabletType

func (TabletType) IsSlaveType

func (tt TabletType) IsSlaveType() bool

type TopoReader

type TopoReader interface {
	// GetSrvKeyspaces returns the names of all the keyspaces in
	// the topology for the cell.
	GetSrvKeyspaceNames(GetSrvKeyspaceNamesArgs, *SrvKeyspaceNames) error

	// GetSrvKeyspace returns information about a keyspace in a
	// particular cell (as specified by the GetSrvKeyspaceArgs).
	GetSrvKeyspace(GetSrvKeyspaceArgs, *SrvKeyspace) error

	// GetEndPoints returns addresses for a tablet type in a shard
	// in a keyspace (as specified in GetEndPointsArgs).
	GetEndPoints(GetEndPointsArgs, *EndPoints) error
}

TopoReader returns read only information about the topology.

type WildcardBackend

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

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

	// GetShardNames returns the known shards in a keyspace.
	// Can return ErrNoNode
	GetShardNames(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 test contains utilities to test topo.Server implementations.
package test contains utilities to test topo.Server implementations.

Jump to

Keyboard shortcuts

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