topotools

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: 18 Imported by: 0

Documentation

Overview

Package topotools contains high level functions based on vt/topo and vt/actionnode. It should not depend on anything else that's higher level. In particular, it cannot depend on:

  • vt/wrangler: much higher level, wrangler depends on topotools.
  • vt/tabletmanager/initiator: we don't want the various remote protocol dependencies here.

topotools is used by wrangler, so it ends up in all tools using wrangler (vtctl, vtctld, ...). It is also included by vttablet, so it contains:

  • most of the logic to rebuild a shard serving graph (helthcheck module)
  • some of the logic to perform a TabletExternallyReparented (RPC call to master vttablet to let it know it's the master).

Index

Constants

This section is empty.

Variables

View Source
var ClearHealthMap = make(map[string]string)

ClearHealthMap is a sentinel value that tells ChangeType to clear the health map, as opposed to passing nil, which will leave the health map unchanged.

Functions

func ChangeOwnType

func ChangeOwnType(ctx context.Context, ts topo.Server, oldTablet *topodatapb.Tablet, newType topodatapb.TabletType, health map[string]string) (*topodatapb.Tablet, error)

ChangeOwnType is like ChangeType, except it fails if you no longer own the tablet record, as determined by CheckOwnership().

Note that oldTablet is only used for its Alias, and to call CheckOwnership(). Other fields in oldTablet have no effect on the update, which will read the latest tablet record before setting the type and health info (just like ChangeType() does).

If successful, the updated tablet record is returned.

func ChangeType

func ChangeType(ctx context.Context, ts topo.Server, tabletAlias *topodatapb.TabletAlias, newType topodatapb.TabletType, health map[string]string) (*topodatapb.Tablet, error)

ChangeType changes the type of the tablet and possibly also updates the health information for it. Make this external, since these transitions need to be forced from time to time.

- if health is nil, we don't touch the Tablet's Health record. - if health is an empty map, we clear the Tablet's Health record. - if health has values, we overwrite the Tablet's Health record.

If successful, the updated tablet record is returned.

func CheckOwnership

func CheckOwnership(oldTablet, newTablet *topodatapb.Tablet) error

CheckOwnership returns nil iff the IP and port match on oldTablet and newTablet, which implies that no other tablet process has taken over the record.

func ConfigureTabletHook

func ConfigureTabletHook(hk *hook.Hook, tabletAlias *topodatapb.TabletAlias)

ConfigureTabletHook configures the right parameters for a hook running locally on a tablet.

func CopyMapKeys

func CopyMapKeys(m interface{}, typeHint interface{}) interface{}

CopyMapKeys copies keys from from map m into a new slice with the type specified by typeHint. Reflection can't make a new slice type just based on the key type AFAICT.

func CopyMapValues

func CopyMapValues(m interface{}, typeHint interface{}) interface{}

CopyMapValues copies values from from map m into a new slice with the type specified by typeHint. Reflection can't make a new slice type just based on the key type AFAICT.

func CreateShard

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

CreateShard will create the shard, while holding the keyspace lock

func DeleteTablet

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

DeleteTablet removes a tablet record from the topology: - the replication data record if any - the tablet record

func FindTabletByIPAddrAndPort

func FindTabletByIPAddrAndPort(tabletMap map[topodatapb.TabletAlias]*topo.TabletInfo, addr, portName string, port int32) (topodatapb.TabletAlias, error)

FindTabletByIPAddrAndPort searches within a tablet map for tablets

func GetAllTablets

func GetAllTablets(ctx context.Context, ts topo.Server, cell string) ([]*topo.TabletInfo, error)

GetAllTablets returns a sorted list of tablets.

func GetAllTabletsAcrossCells

func GetAllTabletsAcrossCells(ctx context.Context, ts topo.Server) ([]*topo.TabletInfo, error)

GetAllTabletsAcrossCells returns all tablets from known cells. If it returns topo.ErrPartialResult, then the list is valid, but partial.

func GetOrCreateShard

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

GetOrCreateShard will return the shard object, or create one if it doesn't already exist. Note the shard creation is protected by a keyspace Lock.

func MapKeys

func MapKeys(m interface{}) []interface{}

MapKeys returns an array with th provided map keys.

func RebuildKeyspace

func RebuildKeyspace(ctx context.Context, log logutil.Logger, ts topo.Server, keyspace string, cells []string, rebuildSrvShards bool) error

RebuildKeyspace rebuilds the serving graph data while locking out other changes.

func RebuildShard

func RebuildShard(ctx context.Context, log logutil.Logger, ts topo.Server, keyspace, shard string, cells []string) (*topo.ShardInfo, error)

RebuildShard updates the SrvShard objects and underlying serving graph.

Re-read from TopologyServer to make sure we are using the side effects of all actions.

This function will start each cell over from the beginning on ErrBadVersion, so it doesn't need a lock on the shard.

func RestartSlavesExternal

func RestartSlavesExternal(ts topo.Server, log logutil.Logger, slaveTabletMap, masterTabletMap map[topodatapb.TabletAlias]*topo.TabletInfo, masterElectTabletAlias *topodatapb.TabletAlias, slaveWasRestarted func(*topo.TabletInfo, *actionnode.SlaveWasRestartedArgs) error)

RestartSlavesExternal will tell all the slaves in the provided list that they have a new master, and also tell all the masters. The masters will be scrapped if they don't answer. We execute all the actions in parallel.

func SortedTabletMap

SortedTabletMap returns two maps:

  • The slaveMap contains all the non-master non-scrapped hosts. This can be used as a list of slaves to fix up for reparenting
  • The masterMap contains all the tablets without parents (scrapped or not). This can be used to special case the old master, and any tablet in a weird state, left over, ...

func UpdateAllSrvShards

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

UpdateAllSrvShards calls UpdateSrvShard for all cells concurrently.

func UpdateSrvShard

func UpdateSrvShard(ctx context.Context, ts topo.Server, cell string, si *topo.ShardInfo) error

UpdateSrvShard creates the SrvShard object based on the global ShardInfo, and writes it to the given cell.

func UpdateTabletEndpoints

func UpdateTabletEndpoints(ctx context.Context, ts topo.Server, tablet *topodatapb.Tablet) (err error)

UpdateTabletEndpoints fixes up any entries in the serving graph that relate to a given tablet.

Types

type OverlappingShards

type OverlappingShards struct {
	Left  []*topo.ShardInfo
	Right []*topo.ShardInfo
}

OverlappingShards contains sets of shards that overlap which each-other. With this library, there is no guarantee of which set will be left or right.

func FindOverlappingShards

func FindOverlappingShards(ctx context.Context, ts topo.Server, keyspace string) ([]*OverlappingShards, error)

FindOverlappingShards will return an array of OverlappingShards for the provided keyspace. We do not support more than two overlapping shards (for instance, having 40-80, 40-60 and 40-50 in the same keyspace is not supported and will return an error). If shards don't perfectly overlap, they are not returned.

func OverlappingShardsForShard

func OverlappingShardsForShard(os []*OverlappingShards, shardName string) *OverlappingShards

OverlappingShardsForShard returns the OverlappingShards object from the list that has he provided shard, or nil

func (*OverlappingShards) ContainsShard

func (os *OverlappingShards) ContainsShard(shardName string) bool

ContainsShard returns true if either Left or Right lists contain the provided Shard.

Directories

Path Synopsis
Package events defines the structures used for events dispatched from the wrangler package.
Package events defines the structures used for events dispatched from the wrangler package.

Jump to

Keyboard shortcuts

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