srvtopo

package
v0.20.4 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 24 Imported by: 17

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 = `` /* 1296-byte string literal not displayed */

TopoTemplate is the HTML to use to display the ResilientServerCacheStatus object

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")
)
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, keyspaces []string, tabletTypes []topodatapb.TabletType) ([]*querypb.Target, error)

FindAllTargets goes through all serving shards in the topology for the provided keyspaces and tablet types. If no keyspaces are provided all available keyspaces in the topo are fetched. It returns one Target object per keyspace/shard/matching TabletType.

func ValuesEqual

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

ValuesEqual is a helper method to compare arrays of values.

Types

type Gateway

type Gateway interface {
	// the query service that this Gateway wraps around
	queryservice.QueryService

	// QueryServiceByAlias returns a QueryService
	QueryServiceByAlias(ctx context.Context, alias *topodatapb.TabletAlias, target *querypb.Target) (queryservice.QueryService, error)

	// GetServingKeyspaces returns list of serving keyspaces.
	GetServingKeyspaces() []string
}

A Gateway is the query processing module for each shard, which is used by ScatterConn.

type ResilientServer

type ResilientServer struct {
	*SrvKeyspaceWatcher
	*SrvVSchemaWatcher
	*SrvKeyspaceNamesQuery
	// 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(ctx context.Context, base *topo.Server, counts *stats.CountersWithSingleLabel) *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) GetTopoServer

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

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

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

	// Gateway is the way to execute a query on this shard
	Gateway Gateway
}

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

func (*ResolvedShard) CachedSize added in v0.10.0

func (cached *ResolvedShard) CachedSize(alloc bool) int64

func (*ResolvedShard) WithKeyspace added in v0.15.0

func (rs *ResolvedShard) WithKeyspace(newKeyspace string) *ResolvedShard

WithKeyspace returns a ResolvedShard with a new keyspace keeping other parameters the same

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, gateway Gateway, 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) GetGateway

func (r *Resolver) GetGateway() Gateway

GetGateway returns the used gateway

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 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]

func (*Resolver) ResolveDestinationsMultiCol added in v0.13.0

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

ResolveDestinationsMultiCol resolves values and their destinations into their respective shards for multi col vindex.

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

Sample input / output: - destinations: dst1, dst2, dst3 - ids: [id1a,id1b], [id2a,id2b], [id3a,id3b] If dst1 is in shard1, and dst2 and dst3 are in shard2, the output will be: - []*ResolvedShard: shard1, shard2 - [][][]sqltypes.Value: [[id1a,id1b]], [[id2a,id2b], [id3a,id3b]]

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, staleOK bool) ([]string, error)

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

	WatchSrvKeyspace(ctx context.Context, cell, keyspace string, callback func(*topodatapb.SrvKeyspace, error) bool)

	// 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) bool)
}

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

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 only allow read-only access to the topo.Server to prevent updates that may corrupt the global VSchema keyspace.

func NewReadOnlyServer added in v0.13.0

func NewReadOnlyServer(underlying Server) (Server, error)

NewReadOnlyServer wraps the topo server passed by the provided implementation and prevents any changes from being made to it.

type SrvKeyspaceCacheStatus

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

SrvKeyspaceCacheStatus is the current value for a SrvKeyspace object

func (*SrvKeyspaceCacheStatus) StatusAsHTML

func (st *SrvKeyspaceCacheStatus) StatusAsHTML() safehtml.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 SrvKeyspaceNamesQuery added in v0.12.0

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

func NewSrvKeyspaceNamesQuery added in v0.12.0

func NewSrvKeyspaceNamesQuery(topoServer *topo.Server, counts *stats.CountersWithSingleLabel, cacheRefresh, cacheTTL time.Duration) *SrvKeyspaceNamesQuery

func (*SrvKeyspaceNamesQuery) GetSrvKeyspaceNames added in v0.12.0

func (q *SrvKeyspaceNamesQuery) GetSrvKeyspaceNames(ctx context.Context, cell string, staleOK bool) ([]string, error)

type SrvKeyspaceWatcher added in v0.12.0

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

func NewSrvKeyspaceWatcher added in v0.12.0

func NewSrvKeyspaceWatcher(ctx context.Context, topoServer *topo.Server, counts *stats.CountersWithSingleLabel, cacheRefresh, cacheTTL time.Duration) *SrvKeyspaceWatcher

func (*SrvKeyspaceWatcher) GetSrvKeyspace added in v0.12.0

func (w *SrvKeyspaceWatcher) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodata.SrvKeyspace, error)

func (*SrvKeyspaceWatcher) WatchSrvKeyspace added in v0.12.0

func (w *SrvKeyspaceWatcher) WatchSrvKeyspace(ctx context.Context, cell, keyspace string, callback func(*topodata.SrvKeyspace, error) bool)

type SrvVSchemaWatcher added in v0.12.0

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

func NewSrvVSchemaWatcher added in v0.12.0

func NewSrvVSchemaWatcher(ctx context.Context, topoServer *topo.Server, counts *stats.CountersWithSingleLabel, cacheRefresh, cacheTTL time.Duration) *SrvVSchemaWatcher

func (*SrvVSchemaWatcher) GetSrvVSchema added in v0.12.0

func (w *SrvVSchemaWatcher) GetSrvVSchema(ctx context.Context, cell string) (*vschemapb.SrvVSchema, error)

func (*SrvVSchemaWatcher) WatchSrvVSchema added in v0.12.0

func (w *SrvVSchemaWatcher) WatchSrvVSchema(ctx context.Context, cell string, callback func(*vschemapb.SrvVSchema, error) bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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