srvtopo

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package srvtopo contains a set of helper methods and classes to use the topology service in a serving environment.

Index

Constants

View Source
const (

	// TopoTemplate is the HTML to use to display the
	// ResilientServerCacheStatus object
	TopoTemplate = `` /* 1447-byte string literal not displayed */

)

Variables

View Source
var (
	// ErrNilUnderlyingServer is returned when attempting to create a new keyspace
	// filtering server if a nil underlying server implementation is provided.
	ErrNilUnderlyingServer = fmt.Errorf("unable to construct filtering server without an underlying server")

	// ErrTopoServerNotAvailable is returned if a caller tries to access the
	// topo.Server supporting this srvtopo.Server.
	ErrTopoServerNotAvailable = fmt.Errorf("cannot access underlying topology server when keyspace filtering is enabled")
)
View Source
var StatusFuncs = template.FuncMap{
	"github_com_vitessio_vitess_srvtopo_ttl_time":   ttlTime,
	"github_com_vitessio_vitess_srvtopo_time_since": timeSince,
}

StatusFuncs is required for CacheStatus) to work properly. We don't register them inside servenv directly so we don't introduce a dependency here.

Functions

func FindAllTargets

func FindAllTargets(ctx context.Context, ts Server, cell string, tabletTypes []topodatapb.TabletType) ([]*querypb.Target, error)

FindAllTargets goes through all serving shards in the topology for the provided tablet types. It returns one Target object per keyspace / shard / matching TabletType.

func ResolvedShardEqual

func ResolvedShardEqual(rs1, rs2 *ResolvedShard) bool

ResolvedShardEqual is an equality check on *ResolvedShard.

func ResolvedShardsEqual

func ResolvedShardsEqual(rss1, rss2 []*ResolvedShard) bool

ResolvedShardsEqual is an equality check on []*ResolvedShard.

func ValuesEqual

func ValuesEqual(vss1, vss2 [][]*querypb.Value) bool

ValuesEqual is a helper method to compare arrays of values.

Types

type ResilientServer

type ResilientServer struct {
	// contains filtered or unexported fields
}

ResilientServer is an implementation of srvtopo.Server based on a topo.Server that uses a cache for two purposes: - limit the QPS to the underlying topo.Server - return the last known value of the data if there is an error

func NewResilientServer

func NewResilientServer(base *topo.Server, counterPrefix string) *ResilientServer

NewResilientServer creates a new ResilientServer based on the provided topo.Server.

func (*ResilientServer) CacheStatus

func (server *ResilientServer) CacheStatus() *ResilientServerCacheStatus

CacheStatus returns a displayable version of the cache

func (*ResilientServer) GetSrvKeyspace

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

GetSrvKeyspace returns SrvKeyspace object for the given cell and keyspace.

func (*ResilientServer) GetSrvKeyspaceNames

func (server *ResilientServer) GetSrvKeyspaceNames(ctx context.Context, cell string) ([]string, error)

GetSrvKeyspaceNames returns all keyspace names for the given cell.

func (*ResilientServer) GetTopoServer

func (server *ResilientServer) GetTopoServer() (*topo.Server, error)

GetTopoServer returns the topo.Server that backs the resilient server.

func (*ResilientServer) WatchSrvVSchema

func (server *ResilientServer) WatchSrvVSchema(ctx context.Context, cell string, callback func(*vschemapb.SrvVSchema, error))

WatchSrvVSchema is part of the srvtopo.Server interface.

type ResilientServerCacheStatus

type ResilientServerCacheStatus struct {
	SrvKeyspaceNames SrvKeyspaceNamesCacheStatusList
	SrvKeyspaces     SrvKeyspaceCacheStatusList
}

ResilientServerCacheStatus has the full status of the cache

type ResolvedShard

type ResolvedShard struct {
	// Target describes the target shard.
	Target *querypb.Target

	// QueryService is the actual way to execute the query.
	QueryService queryservice.QueryService
}

ResolvedShard contains everything we need to send a query to a shard.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

A Resolver can resolve keyspace ids and key ranges into ResolvedShard* objects. It uses an underlying srvtopo.Server to find the topology, and a TargetStats object to find the healthy destinations.

func NewResolver

func NewResolver(topoServ Server, queryService queryservice.QueryService, localCell string) *Resolver

NewResolver creates a new Resolver.

func (*Resolver) GetAllKeyspaces

func (r *Resolver) GetAllKeyspaces(ctx context.Context) ([]string, error)

GetAllKeyspaces returns all the known keyspaces in the local cell.

func (*Resolver) GetAllShards

func (r *Resolver) GetAllShards(ctx context.Context, keyspace string, tabletType topodatapb.TabletType) ([]*ResolvedShard, *topodatapb.SrvKeyspace, error)

GetAllShards returns the list of ResolvedShards associated with all the shards in a keyspace. FIXME(alainjobart) callers should convert to ResolveDestination(), and GetSrvKeyspace.

func (*Resolver) GetKeyspaceShards

func (r *Resolver) GetKeyspaceShards(ctx context.Context, keyspace string, tabletType topodatapb.TabletType) (string, *topodatapb.SrvKeyspace, []*topodatapb.ShardReference, error)

GetKeyspaceShards return all the shards in a keyspace. It follows redirection if ServedFrom is set. It is only valid for the local cell. Do not use it to further resolve shards, instead use the Resolve* methods.

func (*Resolver) ResolveDestination

func (r *Resolver) ResolveDestination(ctx context.Context, keyspace string, tabletType topodatapb.TabletType, destination key.Destination) ([]*ResolvedShard, error)

ResolveDestination is a shortcut to ResolveDestinations with only one Destination, and no ids.

func (*Resolver) ResolveDestinations

func (r *Resolver) ResolveDestinations(ctx context.Context, keyspace string, tabletType topodatapb.TabletType, ids []*querypb.Value, destinations []key.Destination) ([]*ResolvedShard, [][]*querypb.Value, error)

ResolveDestinations resolves values and their destinations into their respective shards.

If ids is nil, the returned [][]*querypb.Value is also nil. Otherwise, len(ids) has to match len(destinations), and then the returned [][]*querypb.Value is populated with all the values that go in each shard, and len([]*ResolvedShard) matches len([][]*querypb.Value).

Sample input / output: - destinations: dst1, dst2, dst3 - ids: id1, id2, id3 If dst1 is in shard1, and dst2 and dst3 are in shard2, the output will be: - []*ResolvedShard: shard1, shard2 - [][]*querypb.Value: [id1], [id2, id3]

type Server

type Server interface {
	// GetTopoServer returns the full topo.Server instance.
	GetTopoServer() (*topo.Server, error)

	// GetSrvKeyspaceNames returns the list of keyspaces served in
	// the provided cell.
	GetSrvKeyspaceNames(ctx context.Context, cell string) ([]string, error)

	// GetSrvKeyspace returns the SrvKeyspace for a cell/keyspace.
	GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error)

	// WatchSrvVSchema starts watching the SrvVSchema object for
	// the provided cell.  It will call the callback when
	// a new value or an error occurs.
	WatchSrvVSchema(ctx context.Context, cell string, callback func(*vschemapb.SrvVSchema, error))
}

Server is a subset of the topo.Server API that only contains the serving graph read-only calls used by clients to resolve serving addresses, and to get VSchema.

func NewKeyspaceFilteringServer added in v1.0.1

func NewKeyspaceFilteringServer(underlying Server, selectedKeyspaces []string) (Server, error)

NewKeyspaceFilteringServer constructs a new server based on the provided implementation that prevents the specified keyspaces from being exposed to consumers of the new Server.

A filtering server will not allow access to the topo.Server to prevent updates that may corrupt the global VSchema keyspace.

type SrvKeyspaceCacheStatus

type SrvKeyspaceCacheStatus struct {
	Cell           string
	Keyspace       string
	Value          *topodatapb.SrvKeyspace
	ExpirationTime time.Time
	LastErrorTime  time.Time
	LastError      error
	LastErrorCtx   context.Context
}

SrvKeyspaceCacheStatus is the current value for a SrvKeyspace object

func (*SrvKeyspaceCacheStatus) StatusAsHTML

func (st *SrvKeyspaceCacheStatus) StatusAsHTML() template.HTML

StatusAsHTML returns an HTML version of our status. It works best if there is data in the cache.

type SrvKeyspaceCacheStatusList

type SrvKeyspaceCacheStatusList []*SrvKeyspaceCacheStatus

SrvKeyspaceCacheStatusList is used for sorting

func (SrvKeyspaceCacheStatusList) Len

func (skcsl SrvKeyspaceCacheStatusList) Len() int

Len is part of sort.Interface

func (SrvKeyspaceCacheStatusList) Less

func (skcsl SrvKeyspaceCacheStatusList) Less(i, j int) bool

Less is part of sort.Interface

func (SrvKeyspaceCacheStatusList) Swap

func (skcsl SrvKeyspaceCacheStatusList) Swap(i, j int)

Swap is part of sort.Interface

type SrvKeyspaceNamesCacheStatus

type SrvKeyspaceNamesCacheStatus struct {
	Cell           string
	Value          []string
	ExpirationTime time.Time
	LastQueryTime  time.Time
	LastError      error
	LastErrorCtx   context.Context
}

SrvKeyspaceNamesCacheStatus is the current value for SrvKeyspaceNames

type SrvKeyspaceNamesCacheStatusList

type SrvKeyspaceNamesCacheStatusList []*SrvKeyspaceNamesCacheStatus

SrvKeyspaceNamesCacheStatusList is used for sorting

func (SrvKeyspaceNamesCacheStatusList) Len

func (skncsl SrvKeyspaceNamesCacheStatusList) Len() int

Len is part of sort.Interface

func (SrvKeyspaceNamesCacheStatusList) Less

func (skncsl SrvKeyspaceNamesCacheStatusList) Less(i, j int) bool

Less is part of sort.Interface

func (SrvKeyspaceNamesCacheStatusList) Swap

func (skncsl SrvKeyspaceNamesCacheStatusList) Swap(i, j int)

Swap is part of sort.Interface

type TargetStatsEntry

type TargetStatsEntry struct {
	// Target is what this entry applies to.
	Target *querypb.Target

	// TabletExternallyReparentedTimestamp is the latest timestamp
	// that was reported for this entry. It applies to masters only.
	TabletExternallyReparentedTimestamp int64
}

TargetStatsEntry has the updated information for a Target.

type TargetStatsMultiplexer

type TargetStatsMultiplexer struct {
	// contains filtered or unexported fields
}

TargetStatsMultiplexer is a helper class to help broadcast stats updates. It doesn't have any synchronization, as the container class will already have some and this can just use it.

func NewTargetStatsMultiplexer

func NewTargetStatsMultiplexer() TargetStatsMultiplexer

NewTargetStatsMultiplexer returns an initialized TargetStatsMultiplexer.

func (*TargetStatsMultiplexer) Broadcast

func (tsm *TargetStatsMultiplexer) Broadcast(tse *TargetStatsEntry)

Broadcast sends an update to the list. Will read the list.

func (*TargetStatsMultiplexer) HasSubscribers

func (tsm *TargetStatsMultiplexer) HasSubscribers() bool

HasSubscribers returns true if we have registered subscribers. Will read the list.

func (*TargetStatsMultiplexer) Subscribe

func (tsm *TargetStatsMultiplexer) Subscribe() (int, <-chan (*TargetStatsEntry))

Subscribe adds a channel to the list. Will change the list.

func (*TargetStatsMultiplexer) Unsubscribe

func (tsm *TargetStatsMultiplexer) Unsubscribe(i int) error

Unsubscribe removes a channel from the list. Will change the list.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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