go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/srvtopo Index | Files | Directories

package srvtopo

import "gopkg.in/src-d/go-vitess.v1/vt/srvtopo"

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

Index

Package Files

discover.go keyspace_filtering_server.go resilient_server.go resolver.go server.go target_stats.go

Constants

const (
    TopoTemplate = "" /* 1449 byte string literal not displayed */

)

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")

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

func FindAllTargets Uses

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 Uses

func ResolvedShardEqual(rs1, rs2 *ResolvedShard) bool

ResolvedShardEqual is an equality check on *ResolvedShard.

func ResolvedShardsEqual Uses

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

ResolvedShardsEqual is an equality check on []*ResolvedShard.

func ValuesEqual Uses

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

ValuesEqual is a helper method to compare arrays of values.

type ResilientServer Uses

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 Uses

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

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

func (*ResilientServer) CacheStatus Uses

func (server *ResilientServer) CacheStatus() *ResilientServerCacheStatus

CacheStatus returns a displayable version of the cache

func (*ResilientServer) GetSrvKeyspace Uses

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 Uses

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

GetSrvKeyspaceNames returns all keyspace names for the given cell.

func (*ResilientServer) GetTopoServer Uses

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

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

func (*ResilientServer) WatchSrvVSchema Uses

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

WatchSrvVSchema is part of the srvtopo.Server interface.

type ResilientServerCacheStatus Uses

type ResilientServerCacheStatus struct {
    SrvKeyspaceNames SrvKeyspaceNamesCacheStatusList
    SrvKeyspaces     SrvKeyspaceCacheStatusList
}

ResilientServerCacheStatus has the full status of the cache

type ResolvedShard Uses

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 Uses

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 Uses

func NewResolver(topoServ Server, stats TargetStats, localCell string) *Resolver

NewResolver creates a new Resolver.

func (*Resolver) GetAllKeyspaces Uses

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

GetAllKeyspaces returns all the known keyspaces in the local cell.

func (*Resolver) GetAllShards Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type SrvKeyspaceCacheStatusList []*SrvKeyspaceCacheStatus

SrvKeyspaceCacheStatusList is used for sorting

func (SrvKeyspaceCacheStatusList) Len Uses

func (skcsl SrvKeyspaceCacheStatusList) Len() int

Len is part of sort.Interface

func (SrvKeyspaceCacheStatusList) Less Uses

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

Less is part of sort.Interface

func (SrvKeyspaceCacheStatusList) Swap Uses

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

Swap is part of sort.Interface

type SrvKeyspaceNamesCacheStatus Uses

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 Uses

type SrvKeyspaceNamesCacheStatusList []*SrvKeyspaceNamesCacheStatus

SrvKeyspaceNamesCacheStatusList is used for sorting

func (SrvKeyspaceNamesCacheStatusList) Len Uses

func (skncsl SrvKeyspaceNamesCacheStatusList) Len() int

Len is part of sort.Interface

func (SrvKeyspaceNamesCacheStatusList) Less Uses

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

Less is part of sort.Interface

func (SrvKeyspaceNamesCacheStatusList) Swap Uses

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

Swap is part of sort.Interface

type TargetStats Uses

type TargetStats interface {
    // GetAggregateStats returns the aggregate stats for the given Target.
    // The srvtopo module will use that information to route queries
    // to the right cell. Also returns the QueryService to use to
    // reach that target.
    // Can return topo.ErrNoNode if the target has no stats.
    GetAggregateStats(target *querypb.Target) (*querypb.AggregateStats, queryservice.QueryService, error)

    // GetMasterCell returns the master location for a keyspace/shard.
    // Since there is only one master for a shard, we only need to
    // know its cell to complete the Target. Also returns the QueryService
    // to use to reach that target.
    GetMasterCell(keyspace, shard string) (cell string, qs queryservice.QueryService, err error)
}

TargetStats is an interface that the srvtopo module uses to handle routing of queries. - discovery.TabletStatsCache will implement the discovery part of the

interface, and discoverygateway will have the QueryService.

type TargetStatsEntry Uses

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

    // Stats is the aggregate stats for this entry.
    Stats *querypb.AggregateStats

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

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 Uses

func NewTargetStatsMultiplexer() TargetStatsMultiplexer

NewTargetStatsMultiplexer returns an initialized TargetStatsMultiplexer.

func (*TargetStatsMultiplexer) Broadcast Uses

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

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

func (*TargetStatsMultiplexer) HasSubscribers Uses

func (tsm *TargetStatsMultiplexer) HasSubscribers() bool

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

func (*TargetStatsMultiplexer) Subscribe Uses

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

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

func (*TargetStatsMultiplexer) Unsubscribe Uses

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

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

Directories

PathSynopsis
srvtopotest

Package srvtopo imports 20 packages (graph) and is imported by 13 packages. Updated 2019-06-13. Refresh now. Tools for package owners.