srvtopo

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: Apache-2.0 Imports: 20 Imported by: 7

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 Gateway

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

	// QueryServiceByAlias returns a QueryService
	QueryServiceByAlias(alias *topodatapb.TabletAlias) (queryservice.QueryService, error)
}

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

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

	// 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.

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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