Documentation ¶
Overview ¶
Package srvtopo contains a set of helper methods and classes to use the topology service in a serving environment.
Index ¶
- Constants
- Variables
- func FindAllTargets(ctx context.Context, ts Server, cell string, keyspaces []string, ...) ([]*querypb.Target, error)
- func ValuesEqual(vss1, vss2 [][]*querypb.Value) bool
- type Gateway
- type ResilientServer
- type ResilientServerCacheStatus
- type ResolvedShard
- type Resolver
- func (r *Resolver) GetAllKeyspaces(ctx context.Context) ([]string, error)
- func (r *Resolver) GetAllShards(ctx context.Context, keyspace string, tabletType topodatapb.TabletType) ([]*ResolvedShard, *topodatapb.SrvKeyspace, error)
- func (r *Resolver) GetGateway() Gateway
- func (r *Resolver) GetKeyspaceShards(ctx context.Context, keyspace string, tabletType topodatapb.TabletType) (string, *topodatapb.SrvKeyspace, []*topodatapb.ShardReference, error)
- func (r *Resolver) ResolveDestination(ctx context.Context, keyspace string, tabletType topodatapb.TabletType, ...) ([]*ResolvedShard, error)
- func (r *Resolver) ResolveDestinations(ctx context.Context, keyspace string, tabletType topodatapb.TabletType, ...) ([]*ResolvedShard, [][]*querypb.Value, error)
- func (r *Resolver) ResolveDestinationsMultiCol(ctx context.Context, keyspace string, tabletType topodatapb.TabletType, ...) ([]*ResolvedShard, [][][]sqltypes.Value, error)
- type Server
- type SrvKeyspaceCacheStatus
- type SrvKeyspaceCacheStatusList
- type SrvKeyspaceNamesCacheStatus
- type SrvKeyspaceNamesCacheStatusList
- type SrvKeyspaceNamesQuery
- type SrvKeyspaceWatcher
- type SrvVSchemaWatcher
Constants ¶
const TopoTemplate = `` /* 1296-byte string literal not displayed */
TopoTemplate is the HTML to use to display the ResilientServerCacheStatus object
Variables ¶
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") )
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 ¶
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 ¶
func (cached *ResolvedShard) CachedSize(alloc bool) int64
func (*ResolvedShard) WithKeyspace ¶
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 ¶
NewResolver creates a new Resolver.
func (*Resolver) GetAllKeyspaces ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type SrvKeyspaceNamesQuery struct {
// contains filtered or unexported fields
}
func NewSrvKeyspaceNamesQuery ¶
func NewSrvKeyspaceNamesQuery(topoServer *topo.Server, counts *stats.CountersWithSingleLabel, cacheRefresh, cacheTTL time.Duration) *SrvKeyspaceNamesQuery
func (*SrvKeyspaceNamesQuery) GetSrvKeyspaceNames ¶
type SrvKeyspaceWatcher ¶
type SrvKeyspaceWatcher struct {
// contains filtered or unexported fields
}
func NewSrvKeyspaceWatcher ¶
func NewSrvKeyspaceWatcher(ctx context.Context, topoServer *topo.Server, counts *stats.CountersWithSingleLabel, cacheRefresh, cacheTTL time.Duration) *SrvKeyspaceWatcher
func (*SrvKeyspaceWatcher) GetSrvKeyspace ¶
func (w *SrvKeyspaceWatcher) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodata.SrvKeyspace, error)
func (*SrvKeyspaceWatcher) WatchSrvKeyspace ¶
func (w *SrvKeyspaceWatcher) WatchSrvKeyspace(ctx context.Context, cell, keyspace string, callback func(*topodata.SrvKeyspace, error) bool)
type SrvVSchemaWatcher ¶
type SrvVSchemaWatcher struct {
// contains filtered or unexported fields
}
func NewSrvVSchemaWatcher ¶
func NewSrvVSchemaWatcher(ctx context.Context, topoServer *topo.Server, counts *stats.CountersWithSingleLabel, cacheRefresh, cacheTTL time.Duration) *SrvVSchemaWatcher
func (*SrvVSchemaWatcher) GetSrvVSchema ¶
func (w *SrvVSchemaWatcher) GetSrvVSchema(ctx context.Context, cell string) (*vschemapb.SrvVSchema, error)
func (*SrvVSchemaWatcher) WatchSrvVSchema ¶
func (w *SrvVSchemaWatcher) WatchSrvVSchema(ctx context.Context, cell string, callback func(*vschemapb.SrvVSchema, error) bool)