Documentation ¶
Overview ¶
Package discovery provides a way to discover all tablets e.g. within a specific shard and monitor their current health.
Use the HealthCheck object to query for tablets and their health.
For an example how to use the HealthCheck object, see vtgate/tabletgateway.go
Tablets have to be manually added to the HealthCheck using AddTablet(). Alternatively, use a Watcher implementation which will constantly watch a source (e.g. the topology) and add and remove tablets as they are added or removed from the source. For a Watcher example have a look at NewTopologyWatcher().
Internally, the HealthCheck module is connected to each tablet and has a streaming RPC (StreamHealth) open to receive periodic health infos.
Index ¶
- Constants
- Variables
- func FilterTargetsByKeyspaces(keyspaces []string, targets []*query.Target) []*query.Target
- func FilteringKeyspaces() bool
- func GetHighReplicationLagMinServing() time.Duration
- func GetLowReplicationLag() time.Duration
- func GetMinNumTablets() int
- func GetTabletPickerRetryDelay() time.Duration
- func IsReplicationLagHigh(tabletHealth *TabletHealth) bool
- func IsReplicationLagVeryHigh(tabletHealth *TabletHealth) bool
- func ParseTabletTypesAndOrder(tabletTypesStr string) ([]topodatapb.TabletType, bool, error)
- func ParseTabletURLTemplateFromFlag()
- func SetHighReplicationLagMinServing(lag time.Duration)
- func SetLowReplicationLag(lag time.Duration)
- func SetMinNumTablets(numTablets int)
- func SetTabletPickerRetryDelay(delay time.Duration)
- func TabletToMapKey(tablet *topodata.Tablet) string
- type FakeHealthCheck
- func (fhc *FakeHealthCheck) AddFakeTablet(cell, host string, port int32, keyspace, shard string, ...) queryservice.QueryService
- func (fhc *FakeHealthCheck) AddTablet(tablet *topodatapb.Tablet)
- func (fhc *FakeHealthCheck) AddTestTablet(cell, host string, port int32, keyspace, shard string, ...) *sandboxconn.SandboxConn
- func (fhc *FakeHealthCheck) Broadcast(tablet *topodatapb.Tablet)
- func (fhc *FakeHealthCheck) BroadcastAll()
- func (fhc *FakeHealthCheck) CacheStatus() TabletsCacheStatusList
- func (fhc *FakeHealthCheck) CacheStatusMap() map[string]*TabletsCacheStatus
- func (fhc *FakeHealthCheck) Close() error
- func (fhc *FakeHealthCheck) GetAllTablets() map[string]*topodatapb.Tablet
- func (fhc *FakeHealthCheck) GetHealthyTabletStats(target *querypb.Target) []*TabletHealth
- func (fhc *FakeHealthCheck) GetLoadTabletsTrigger() chan struct{}
- func (fhc *FakeHealthCheck) GetPrimaryTablet() *topodatapb.Tablet
- func (fhc *FakeHealthCheck) GetTabletHealth(kst KeyspaceShardTabletType, alias *topodatapb.TabletAlias) (*TabletHealth, error)
- func (fhc *FakeHealthCheck) GetTabletHealthByAlias(alias *topodatapb.TabletAlias) (*TabletHealth, error)
- func (fhc *FakeHealthCheck) HealthyStatus() TabletsCacheStatusList
- func (fhc *FakeHealthCheck) RegisterStats()
- func (fhc *FakeHealthCheck) RemoveTablet(tablet *topodatapb.Tablet)
- func (fhc *FakeHealthCheck) ReplaceTablet(old, new *topodatapb.Tablet)
- func (fhc *FakeHealthCheck) Reset()
- func (fhc *FakeHealthCheck) SetServing(tablet *topodatapb.Tablet, serving bool)
- func (fhc *FakeHealthCheck) SetTabletType(tablet *topodatapb.Tablet, tabletType topodatapb.TabletType)
- func (fhc *FakeHealthCheck) Subscribe() chan *TabletHealth
- func (fhc *FakeHealthCheck) TabletConnection(alias *topodatapb.TabletAlias, target *querypb.Target) (queryservice.QueryService, error)
- func (fhc *FakeHealthCheck) Unsubscribe(c chan *TabletHealth)
- func (fhc *FakeHealthCheck) UpdateHealth(th *TabletHealth)
- func (fhc *FakeHealthCheck) WaitForAllServingTablets(ctx context.Context, targets []*querypb.Target) error
- type FilterByKeyspace
- type FilterByShard
- type HealthCheck
- type HealthCheckImpl
- func (hc *HealthCheckImpl) AddTablet(tablet *topodata.Tablet)
- func (hc *HealthCheckImpl) CacheStatus() TabletsCacheStatusList
- func (hc *HealthCheckImpl) CacheStatusMap() map[string]*TabletsCacheStatus
- func (hc *HealthCheckImpl) Close() error
- func (hc *HealthCheckImpl) GetHealthyTabletStats(target *query.Target) []*TabletHealth
- func (hc *HealthCheckImpl) GetLoadTabletsTrigger() chan struct{}
- func (hc *HealthCheckImpl) GetTabletHealth(kst KeyspaceShardTabletType, alias *topodata.TabletAlias) (*TabletHealth, error)
- func (hc *HealthCheckImpl) GetTabletHealthByAlias(alias *topodata.TabletAlias) (*TabletHealth, error)
- func (hc *HealthCheckImpl) GetTabletStats(target *query.Target) []*TabletHealth
- func (hc *HealthCheckImpl) HealthyStatus() TabletsCacheStatusList
- func (hc *HealthCheckImpl) HealthyStatusMap() map[string]*TabletsCacheStatus
- func (hc *HealthCheckImpl) RegisterStats()
- func (hc *HealthCheckImpl) RemoveTablet(tablet *topodata.Tablet)
- func (hc *HealthCheckImpl) ReplaceTablet(old, new *topodata.Tablet)
- func (hc *HealthCheckImpl) ServeHTTP(w http.ResponseWriter, _ *http.Request)
- func (hc *HealthCheckImpl) Subscribe() chan *TabletHealth
- func (hc *HealthCheckImpl) TabletConnection(alias *topodata.TabletAlias, target *query.Target) (queryservice.QueryService, error)
- func (hc *HealthCheckImpl) Unsubscribe(c chan *TabletHealth)
- func (hc *HealthCheckImpl) WaitForAllServingTablets(ctx context.Context, targets []*query.Target) error
- func (hc *HealthCheckImpl) WaitForTablets(ctx context.Context, keyspace, shard string, tabletType topodata.TabletType) error
- type KeyspaceEvent
- type KeyspaceEventWatcher
- func (kew *KeyspaceEventWatcher) GetServingKeyspaces() []string
- func (kew *KeyspaceEventWatcher) PrimaryIsNotServing(ctx context.Context, target *querypb.Target) (*topodatapb.TabletAlias, bool)
- func (kew *KeyspaceEventWatcher) Subscribe() chan *KeyspaceEvent
- func (kew *KeyspaceEventWatcher) TargetIsBeingResharded(ctx context.Context, target *querypb.Target) bool
- func (kew *KeyspaceEventWatcher) Unsubscribe(c chan *KeyspaceEvent)
- type KeyspaceShardTabletType
- type MoveTablesState
- type MoveTablesStatus
- type MoveTablesType
- type ShardEvent
- type TabletFilter
- type TabletHealth
- type TabletPicker
- type TabletPickerCellPreference
- type TabletPickerOptions
- type TabletPickerTabletOrder
- type TabletStatsList
- type TabletsCacheStatus
- type TabletsCacheStatusList
- type TopologyWatcher
Constants ¶
const ( DefaultHealthCheckRetryDelay = 5 * time.Second DefaultHealthCheckTimeout = 1 * time.Minute )
See the documentation for NewHealthCheck below for an explanation of these parameters.
Variables ¶
var ( // TabletURLTemplateString is a flag to generate URLs for the tablets that vtgate discovers. TabletURLTemplateString = "http://{{.GetTabletHostPort}}" // AllowedTabletTypes is the list of allowed tablet types. e.g. {PRIMARY, REPLICA}. AllowedTabletTypes []topodata.TabletType // KeyspacesToWatch - if provided this specifies which keyspaces should be // visible to the healthcheck. By default the healthcheck will watch all keyspaces. KeyspacesToWatch []string // HealthCheckCacheTemplate uses healthCheckTemplate with the `HealthCheck Tablet - Cache` title to create the // HTML code required to render the cache of the HealthCheck. HealthCheckCacheTemplate = fmt.Sprintf(healthCheckTemplate, "HealthCheck - Cache") // HealthCheckHealthyTemplate uses healthCheckTemplate with the `HealthCheck Tablet - Healthy Tablets` title to // create the HTML code required to render the list of healthy tablets from the HealthCheck. HealthCheckHealthyTemplate = fmt.Sprintf(healthCheckTemplate, "HealthCheck - Healthy Tablets") )
Functions ¶
func FilterTargetsByKeyspaces ¶ added in v0.8.0
FilterTargetsByKeyspaces only returns the targets that are part of the provided keyspaces
func FilteringKeyspaces ¶ added in v0.10.0
func FilteringKeyspaces() bool
FilteringKeyspaces returns true if any keyspaces have been configured to be filtered.
func GetHighReplicationLagMinServing ¶ added in v0.11.0
GetHighReplicationLagMinServing getter for use by debugenv
func GetLowReplicationLag ¶ added in v0.11.0
GetLowReplicationLag getter for use by debugenv
func GetMinNumTablets ¶ added in v0.11.0
func GetMinNumTablets() int
GetMinNumTablets getter for use by debugenv
func GetTabletPickerRetryDelay ¶ added in v0.8.0
GetTabletPickerRetryDelay synchronizes changes to tabletPickerRetryDelay. Used in tests only at the moment
func IsReplicationLagHigh ¶
func IsReplicationLagHigh(tabletHealth *TabletHealth) bool
IsReplicationLagHigh verifies that the given TabletHealth refers to a tablet with high replication lag, i.e. higher than the configured discovery_low_replication_lag flag.
func IsReplicationLagVeryHigh ¶
func IsReplicationLagVeryHigh(tabletHealth *TabletHealth) bool
IsReplicationLagVeryHigh verifies that the given TabletHealth refers to a tablet with very high replication lag, i.e. higher than the configured discovery_high_replication_lag_minimum_serving flag.
func ParseTabletTypesAndOrder ¶ added in v0.14.0
func ParseTabletTypesAndOrder(tabletTypesStr string) ([]topodatapb.TabletType, bool, error)
func ParseTabletURLTemplateFromFlag ¶
func ParseTabletURLTemplateFromFlag()
ParseTabletURLTemplateFromFlag loads or reloads the URL template.
func SetHighReplicationLagMinServing ¶ added in v0.11.0
SetHighReplicationLagMinServing setter for use by debugenv
func SetLowReplicationLag ¶ added in v0.11.0
SetLowReplicationLag setter for use by debugenv
func SetMinNumTablets ¶ added in v0.11.0
func SetMinNumTablets(numTablets int)
SetMinNumTablets setter for use by debugenv
func SetTabletPickerRetryDelay ¶ added in v0.8.0
SetTabletPickerRetryDelay synchronizes reads for tabletPickerRetryDelay. Used in tests only at the moment
func TabletToMapKey ¶
TabletToMapKey creates a key to the map from tablet's host and ports. It should only be used in discovery and related module.
Types ¶
type FakeHealthCheck ¶
type FakeHealthCheck struct {
// contains filtered or unexported fields
}
FakeHealthCheck implements discovery.HealthCheck.
func NewFakeHealthCheck ¶
func NewFakeHealthCheck(ch chan *TabletHealth) *FakeHealthCheck
NewFakeHealthCheck returns the fake healthcheck object.
func (*FakeHealthCheck) AddFakeTablet ¶
func (fhc *FakeHealthCheck) AddFakeTablet(cell, host string, port int32, keyspace, shard string, tabletType topodatapb.TabletType, serving bool, reparentTS int64, err error, connFactory func(*topodatapb.Tablet) queryservice.QueryService) queryservice.QueryService
AddFakeTablet inserts a fake entry into FakeHealthCheck. The Tablet can be talked to using the provided connection. The Listener is called, as if AddTablet had been called. For flexibility the connection is created via a connFactory callback
func (*FakeHealthCheck) AddTablet ¶
func (fhc *FakeHealthCheck) AddTablet(tablet *topodatapb.Tablet)
AddTablet adds the tablet.
func (*FakeHealthCheck) AddTestTablet ¶
func (fhc *FakeHealthCheck) AddTestTablet(cell, host string, port int32, keyspace, shard string, tabletType topodatapb.TabletType, serving bool, reparentTS int64, err error) *sandboxconn.SandboxConn
AddTestTablet adds a fake tablet for tests using the SandboxConn and returns the fake connection
func (*FakeHealthCheck) Broadcast ¶ added in v0.13.0
func (fhc *FakeHealthCheck) Broadcast(tablet *topodatapb.Tablet)
Broadcast broadcasts the healthcheck for the given tablet
func (*FakeHealthCheck) BroadcastAll ¶ added in v0.18.0
func (fhc *FakeHealthCheck) BroadcastAll()
BroadcastAll broadcasts all the tablets' healthchecks
func (*FakeHealthCheck) CacheStatus ¶
func (fhc *FakeHealthCheck) CacheStatus() TabletsCacheStatusList
CacheStatus returns the status for each tablet
func (*FakeHealthCheck) CacheStatusMap ¶ added in v0.14.0
func (fhc *FakeHealthCheck) CacheStatusMap() map[string]*TabletsCacheStatus
CacheStatusMap returns a map of the health check cache.
func (*FakeHealthCheck) GetAllTablets ¶
func (fhc *FakeHealthCheck) GetAllTablets() map[string]*topodatapb.Tablet
GetAllTablets returns all the tablets we have.
func (*FakeHealthCheck) GetHealthyTabletStats ¶
func (fhc *FakeHealthCheck) GetHealthyTabletStats(target *querypb.Target) []*TabletHealth
GetHealthyTabletStats returns only the healthy tablets - Serving true and LastError is not nil
func (*FakeHealthCheck) GetLoadTabletsTrigger ¶ added in v0.17.0
func (fhc *FakeHealthCheck) GetLoadTabletsTrigger() chan struct{}
GetLoadTabletsTrigger is not implemented.
func (*FakeHealthCheck) GetPrimaryTablet ¶ added in v0.13.0
func (fhc *FakeHealthCheck) GetPrimaryTablet() *topodatapb.Tablet
GetPrimaryTablet gets the primary tablet from the tablets that healthcheck has seen so far
func (*FakeHealthCheck) GetTabletHealth ¶ added in v0.14.0
func (fhc *FakeHealthCheck) GetTabletHealth(kst KeyspaceShardTabletType, alias *topodatapb.TabletAlias) (*TabletHealth, error)
GetTabletHealth results the TabletHealth of the tablet that matches the given alias
func (*FakeHealthCheck) GetTabletHealthByAlias ¶ added in v0.14.0
func (fhc *FakeHealthCheck) GetTabletHealthByAlias(alias *topodatapb.TabletAlias) (*TabletHealth, error)
GetTabletHealthByAlias results the TabletHealth of the tablet that matches the given alias
func (*FakeHealthCheck) HealthyStatus ¶ added in v0.19.0
func (fhc *FakeHealthCheck) HealthyStatus() TabletsCacheStatusList
HealthyStatus returns the status for each healthy tablet
func (*FakeHealthCheck) RegisterStats ¶
func (fhc *FakeHealthCheck) RegisterStats()
RegisterStats is not implemented.
func (*FakeHealthCheck) RemoveTablet ¶
func (fhc *FakeHealthCheck) RemoveTablet(tablet *topodatapb.Tablet)
RemoveTablet removes the tablet.
func (*FakeHealthCheck) ReplaceTablet ¶
func (fhc *FakeHealthCheck) ReplaceTablet(old, new *topodatapb.Tablet)
ReplaceTablet removes the old tablet and adds the new.
func (*FakeHealthCheck) Reset ¶
func (fhc *FakeHealthCheck) Reset()
Reset cleans up the internal state.
func (*FakeHealthCheck) SetServing ¶ added in v0.13.0
func (fhc *FakeHealthCheck) SetServing(tablet *topodatapb.Tablet, serving bool)
SetServing sets the serving variable for the given tablet
func (*FakeHealthCheck) SetTabletType ¶ added in v0.13.0
func (fhc *FakeHealthCheck) SetTabletType(tablet *topodatapb.Tablet, tabletType topodatapb.TabletType)
SetTabletType sets the tablet type for the given tablet
func (*FakeHealthCheck) Subscribe ¶
func (fhc *FakeHealthCheck) Subscribe() chan *TabletHealth
Subscribe returns the channel in the struct. Subscribe should only be called in one place for this fake health check
func (*FakeHealthCheck) TabletConnection ¶
func (fhc *FakeHealthCheck) TabletConnection(alias *topodatapb.TabletAlias, target *querypb.Target) (queryservice.QueryService, error)
TabletConnection returns the TabletConn of the given tablet.
func (*FakeHealthCheck) Unsubscribe ¶
func (fhc *FakeHealthCheck) Unsubscribe(c chan *TabletHealth)
Unsubscribe is not implemented.
func (*FakeHealthCheck) UpdateHealth ¶ added in v0.14.0
func (fhc *FakeHealthCheck) UpdateHealth(th *TabletHealth)
UpdateHealth adds a TabletHealth for the tablet defined in th.
func (*FakeHealthCheck) WaitForAllServingTablets ¶
func (fhc *FakeHealthCheck) WaitForAllServingTablets(ctx context.Context, targets []*querypb.Target) error
WaitForAllServingTablets is not implemented.
type FilterByKeyspace ¶
type FilterByKeyspace struct {
// contains filtered or unexported fields
}
FilterByKeyspace is a filter that filters tablets by keyspace.
func NewFilterByKeyspace ¶
func NewFilterByKeyspace(selectedKeyspaces []string) *FilterByKeyspace
NewFilterByKeyspace creates a new FilterByKeyspace. Each filter is a keyspace entry. All tablets that match a keyspace will be forwarded to the TopologyWatcher's consumer.
func (*FilterByKeyspace) IsIncluded ¶
func (fbk *FilterByKeyspace) IsIncluded(tablet *topodata.Tablet) bool
IsIncluded returns true if the tablet's keyspace matches what we have.
type FilterByShard ¶
type FilterByShard struct {
// contains filtered or unexported fields
}
FilterByShard is a filter that filters tablets by keyspace/shard.
func NewFilterByShard ¶
func NewFilterByShard(filters []string) (*FilterByShard, error)
NewFilterByShard creates a new FilterByShard for use by a TopologyWatcher. Each filter is a keyspace|shard entry, where shard can either be a shard name, or a keyrange. All tablets that match at least one keyspace|shard tuple will be forwarded by the TopologyWatcher to its consumer.
func (*FilterByShard) IsIncluded ¶
func (fbs *FilterByShard) IsIncluded(tablet *topodata.Tablet) bool
IsIncluded returns true iff the tablet's keyspace and shard match what we have.
type HealthCheck ¶
type HealthCheck interface { // AddTablet adds the tablet. AddTablet(tablet *topodata.Tablet) // RemoveTablet removes the tablet. RemoveTablet(tablet *topodata.Tablet) // ReplaceTablet does an AddTablet and RemoveTablet in one call, effectively replacing the old tablet with the new. ReplaceTablet(old, new *topodata.Tablet) // CacheStatus returns a displayable version of the health check cache. CacheStatus() TabletsCacheStatusList // HealthyStatus returns a displayable version of the health check healthy list. HealthyStatus() TabletsCacheStatusList // CacheStatusMap returns a map of the health check cache. CacheStatusMap() map[string]*TabletsCacheStatus // Close stops the healthcheck. Close() error // WaitForAllServingTablets waits for at least one healthy serving tablet in // each given target before returning. // It will return ctx.Err() if the context is canceled. // It will return an error if it can't read the necessary topology records. WaitForAllServingTablets(ctx context.Context, targets []*query.Target) error // TabletConnection returns the TabletConn of the given tablet. TabletConnection(alias *topodata.TabletAlias, target *query.Target) (queryservice.QueryService, error) // RegisterStats registers the connection counts stats RegisterStats() // GetHealthyTabletStats returns only the healthy tablets. // The returned array is owned by the caller. // For TabletType_PRIMARY, this will only return at most one entry, // the most recent tablet of type primary. // This returns a copy of the data so that callers can access without // synchronization GetHealthyTabletStats(target *query.Target) []*TabletHealth // GetTabletHealth results the TabletHealth of the tablet that matches the given alias GetTabletHealth(kst KeyspaceShardTabletType, alias *topodata.TabletAlias) (*TabletHealth, error) // GetTabletHealthByAlias results the TabletHealth of the tablet that matches the given alias GetTabletHealthByAlias(alias *topodata.TabletAlias) (*TabletHealth, error) // Subscribe adds a listener. Used by vtgate buffer to learn about primary changes. Subscribe() chan *TabletHealth // Unsubscribe removes a listener. Unsubscribe(c chan *TabletHealth) // GetLoadTabletsTrigger returns a channel that is used to inform when to load tablets. GetLoadTabletsTrigger() chan struct{} }
HealthCheck declares what the TabletGateway needs from the HealthCheck
type HealthCheckImpl ¶
type HealthCheckImpl struct {
// contains filtered or unexported fields
}
HealthCheckImpl performs health checking and stores the results. The goal of this object is to maintain a StreamHealth RPC to a lot of tablets. Tablets are added / removed by calling the AddTablet / RemoveTablet methods (other discovery module objects can for instance watch the topology and call these). It contains a map of tabletHealthCheck objects by Alias. Each tabletHealthCheck object stores the health information for one tablet. A checkConn goroutine is spawned for each tabletHealthCheck, which is responsible for keeping that tabletHealthCheck up-to-date. If checkConn terminates for any reason, then the corresponding tabletHealthCheck object is removed from the map. When a tabletHealthCheck gets removed from the map, its cancelFunc gets called, which ensures that the associated checkConn goroutine eventually terminates.
func NewHealthCheck ¶
func NewHealthCheck(ctx context.Context, retryDelay, healthCheckTimeout time.Duration, topoServer *topo.Server, localCell, cellsToWatch string) *HealthCheckImpl
NewHealthCheck creates a new HealthCheck object. Parameters: retryDelay.
The duration to wait before retrying to connect (e.g. after a failed connection attempt).
healthCheckTimeout.
The duration for which we consider a health check response to be 'fresh'. If we don't get a health check response from a tablet for more than this duration, we consider the tablet not healthy.
topoServer.
The topology server that this healthcheck object can use to retrieve cell or tablet information
localCell.
The localCell for this healthcheck
callback.
A function to call when there is a primary change. Used to notify vtgate's buffer to stop buffering.
func (*HealthCheckImpl) AddTablet ¶
func (hc *HealthCheckImpl) AddTablet(tablet *topodata.Tablet)
AddTablet adds the tablet, and starts health check. It does not block on making connection. name is an optional tag for the tablet, e.g. an alternative address.
func (*HealthCheckImpl) CacheStatus ¶
func (hc *HealthCheckImpl) CacheStatus() TabletsCacheStatusList
CacheStatus returns a displayable version of the cache.
func (*HealthCheckImpl) CacheStatusMap ¶ added in v0.14.0
func (hc *HealthCheckImpl) CacheStatusMap() map[string]*TabletsCacheStatus
func (*HealthCheckImpl) Close ¶
func (hc *HealthCheckImpl) Close() error
Close stops the healthcheck.
func (*HealthCheckImpl) GetHealthyTabletStats ¶
func (hc *HealthCheckImpl) GetHealthyTabletStats(target *query.Target) []*TabletHealth
GetHealthyTabletStats returns only the healthy tablets. The returned array is owned by the caller. For TabletType_PRIMARY, this will only return at most one entry, the most recent tablet of type primary. This returns a copy of the data so that callers can access without synchronization
func (*HealthCheckImpl) GetLoadTabletsTrigger ¶ added in v0.17.0
func (hc *HealthCheckImpl) GetLoadTabletsTrigger() chan struct{}
GetLoadTabletsTrigger returns a channel that is used to inform when to load tablets.
func (*HealthCheckImpl) GetTabletHealth ¶ added in v0.14.0
func (hc *HealthCheckImpl) GetTabletHealth(kst KeyspaceShardTabletType, alias *topodata.TabletAlias) (*TabletHealth, error)
GetTabletHealth results the TabletHealth of the tablet that matches the given alias and KeyspaceShardTabletType The data is retrieved from the healthData map.
func (*HealthCheckImpl) GetTabletHealthByAlias ¶ added in v0.14.0
func (hc *HealthCheckImpl) GetTabletHealthByAlias(alias *topodata.TabletAlias) (*TabletHealth, error)
GetTabletHealthByAlias results the TabletHealth of the tablet that matches the given alias
func (*HealthCheckImpl) GetTabletStats ¶ added in v0.15.0
func (hc *HealthCheckImpl) GetTabletStats(target *query.Target) []*TabletHealth
GetTabletStats returns all tablets for the given target. The returned array is owned by the caller. For TabletType_PRIMARY, this will only return at most one entry, the most recent tablet of type primary.
func (*HealthCheckImpl) HealthyStatus ¶ added in v0.19.0
func (hc *HealthCheckImpl) HealthyStatus() TabletsCacheStatusList
HealthyStatus returns a displayable version of the cache.
func (*HealthCheckImpl) HealthyStatusMap ¶ added in v0.19.0
func (hc *HealthCheckImpl) HealthyStatusMap() map[string]*TabletsCacheStatus
func (*HealthCheckImpl) RegisterStats ¶
func (hc *HealthCheckImpl) RegisterStats()
RegisterStats registers the connection counts stats
func (*HealthCheckImpl) RemoveTablet ¶
func (hc *HealthCheckImpl) RemoveTablet(tablet *topodata.Tablet)
RemoveTablet removes the tablet, and stops the health check. It does not block.
func (*HealthCheckImpl) ReplaceTablet ¶
func (hc *HealthCheckImpl) ReplaceTablet(old, new *topodata.Tablet)
ReplaceTablet removes the old tablet and adds the new tablet.
func (*HealthCheckImpl) ServeHTTP ¶
func (hc *HealthCheckImpl) ServeHTTP(w http.ResponseWriter, _ *http.Request)
ServeHTTP is part of the http.Handler interface. It renders the current state of the discovery gateway tablet cache into json.
func (*HealthCheckImpl) Subscribe ¶
func (hc *HealthCheckImpl) Subscribe() chan *TabletHealth
Subscribe adds a listener. Used by vtgate buffer to learn about primary changes.
func (*HealthCheckImpl) TabletConnection ¶
func (hc *HealthCheckImpl) TabletConnection(alias *topodata.TabletAlias, target *query.Target) (queryservice.QueryService, error)
TabletConnection returns the Connection to a given tablet.
func (*HealthCheckImpl) Unsubscribe ¶
func (hc *HealthCheckImpl) Unsubscribe(c chan *TabletHealth)
Unsubscribe removes a listener.
func (*HealthCheckImpl) WaitForAllServingTablets ¶
func (hc *HealthCheckImpl) WaitForAllServingTablets(ctx context.Context, targets []*query.Target) error
WaitForAllServingTablets waits for at least one healthy serving tablet in each given target before returning. It will return ctx.Err() if the context is canceled. It will return an error if it can't read the necessary topology records.
func (*HealthCheckImpl) WaitForTablets ¶
func (hc *HealthCheckImpl) WaitForTablets(ctx context.Context, keyspace, shard string, tabletType topodata.TabletType) error
WaitForTablets waits for at least one tablet in the given keyspace / shard / tablet type before returning. The tablets do not have to be healthy. It will return ctx.Err() if the context is canceled.
type KeyspaceEvent ¶ added in v0.12.0
type KeyspaceEvent struct { // Cell is the cell where the keyspace lives Cell string // Keyspace is the name of the keyspace which was (partially) unavailable and is now fully healthy Keyspace string // Shards is a list of all the shards in the keyspace, including their state after the event is resolved Shards []ShardEvent // MoveTablesState records the current state of an ongoing MoveTables workflow MoveTablesState MoveTablesState }
KeyspaceEvent is yielded to all watchers when an availability event for a keyspace has been resolved
type KeyspaceEventWatcher ¶ added in v0.12.0
type KeyspaceEventWatcher struct {
// contains filtered or unexported fields
}
KeyspaceEventWatcher is an auxiliary watcher that watches all availability incidents for all keyspaces in a Vitess cell and notifies listeners when the events have been resolved. Right now this is capable of detecting the end of failovers, both planned and unplanned, and the end of resharding operations.
The KeyspaceEventWatcher works by consolidating TabletHealth events from a HealthCheck stream, which is a peer-to-peer check between nodes via GRPC, with events from a Topology Server, which are global to the cluster and stored in an external system like etcd.
func NewKeyspaceEventWatcher ¶ added in v0.12.0
func NewKeyspaceEventWatcher(ctx context.Context, topoServer srvtopo.Server, hc HealthCheck, localCell string) *KeyspaceEventWatcher
NewKeyspaceEventWatcher returns a new watcher for all keyspace events in the given cell. It requires access to a topology server, and an existing HealthCheck implementation which will be used to detect unhealthy nodes.
func (*KeyspaceEventWatcher) GetServingKeyspaces ¶ added in v0.18.0
func (kew *KeyspaceEventWatcher) GetServingKeyspaces() []string
GetServingKeyspaces gets the serving keyspaces from the keyspace event watcher.
func (*KeyspaceEventWatcher) PrimaryIsNotServing ¶ added in v0.13.0
func (kew *KeyspaceEventWatcher) PrimaryIsNotServing(ctx context.Context, target *querypb.Target) (*topodatapb.TabletAlias, bool)
PrimaryIsNotServing checks if the reason why the given target is not accessible right now is that the primary tablet for that shard is not serving. This is possible during a Planned Reparent Shard operation. Just as the operation completes, a new primary will be elected, and it will send its own healthcheck stating that it is serving. We should buffer requests until that point. There are use cases where people do not run with a Primary server at all, so we must verify that we only start buffering when a primary was present, and it went not serving. The shard state keeps track of the current primary and the last externally reparented time, which we can use to determine that there was a serving primary which now became non serving. This is only possible in a DemotePrimary RPC which are only called from ERS and PRS. So buffering will stop when these operations succeed. We return the tablet alias of the primary if it is serving.
func (*KeyspaceEventWatcher) Subscribe ¶ added in v0.12.0
func (kew *KeyspaceEventWatcher) Subscribe() chan *KeyspaceEvent
Subscribe returns a channel that will receive any KeyspaceEvents for all keyspaces in the current cell
func (*KeyspaceEventWatcher) TargetIsBeingResharded ¶ added in v0.12.0
func (kew *KeyspaceEventWatcher) TargetIsBeingResharded(ctx context.Context, target *querypb.Target) bool
TargetIsBeingResharded checks if the reason why the given target is not accessible right now is because the keyspace where it resides is (potentially) undergoing a resharding operation. This is not a fully accurate heuristic, but it's good enough that we'd want to buffer the request for the given target under the assumption that the reason why it cannot be completed right now is transitory.
func (*KeyspaceEventWatcher) Unsubscribe ¶ added in v0.12.0
func (kew *KeyspaceEventWatcher) Unsubscribe(c chan *KeyspaceEvent)
Unsubscribe removes a listener previously returned from Subscribe
type KeyspaceShardTabletType ¶ added in v0.14.0
type KeyspaceShardTabletType string
func KeyFromTarget ¶ added in v0.14.0
func KeyFromTarget(target *query.Target) KeyspaceShardTabletType
KeyFromTarget includes cell which we ignore here because tabletStatsCache is intended to be per-cell
type MoveTablesState ¶ added in v0.18.0
type MoveTablesState struct { Typ MoveTablesType State MoveTablesStatus }
type MoveTablesStatus ¶ added in v0.18.0
type MoveTablesStatus int
const ( MoveTablesUnknown MoveTablesStatus = iota // MoveTablesSwitching is set when the write traffic is the middle of being switched from the source to the target MoveTablesSwitching // MoveTablesSwitched is set when write traffic has been completely switched to the target MoveTablesSwitched )
type MoveTablesType ¶ added in v0.18.0
type MoveTablesType int
const ( MoveTablesNone MoveTablesType = iota MoveTablesRegular MoveTablesShardByShard )
type ShardEvent ¶ added in v0.12.0
type ShardEvent struct { Tablet *topodatapb.TabletAlias Target *querypb.Target Serving bool }
type TabletFilter ¶
type TabletFilter interface { // IsIncluded returns whether tablet is included in this filter IsIncluded(tablet *topodata.Tablet) bool }
TabletFilter is an interface that can be given to a TopologyWatcher to be applied as an additional filter on the list of tablets returned by its getTablets function.
type TabletHealth ¶
type TabletHealth struct { Conn queryservice.QueryService Tablet *topodata.Tablet Target *query.Target Stats *query.RealtimeStats PrimaryTermStartTime int64 LastError error Serving bool }
TabletHealth represents simple tablet health data that is returned to users of healthcheck. No synchronization is required because we always return a copy.
func FilterStatsByReplicationLag ¶
func FilterStatsByReplicationLag(tabletHealthList []*TabletHealth) []*TabletHealth
FilterStatsByReplicationLag filters the list of TabletHealth by TabletHealth.Stats.ReplicationLagSeconds. Note that TabletHealth that is non-serving or has error is ignored.
The simplified logic: - Return tablets that have lag <= lowReplicationLag. - Make sure we return at least minNumTablets tablets, if there are enough one with lag <= highReplicationLagMinServing. For example, with the default of 30s / 2h / 2, this means: - lags of (5s, 10s, 15s, 120s) return the first three - lags of (30m, 35m, 40m, 45m) return the first two - lags of (2h, 3h, 4h, 5h) return the first one
The legacy algorithm (default for now): - Return the list if there is 0 or 1 tablet. - Return the list if all tablets have <=30s lag. - Filter by replication lag: for each tablet, if the mean value without it is more than 0.7 of the mean value across all tablets, it is valid. - Make sure we return at least minNumTablets tablets (if there are enough one with only low replication lag). - If one tablet is removed, run above steps again in case there are two tablets with high replication lag. (It should cover most cases.) For example, lags of (5s, 10s, 15s, 120s) return the first three; lags of (30m, 35m, 40m, 45m) return all.
One thing to know about this code: vttablet also has a couple flags that impact the logic here:
- unhealthy_threshold: if replication lag is higher than this, a tablet will be reported as unhealthy. The default for this is 2h, same as the discovery_high_replication_lag_minimum_serving here.
- degraded_threshold: this is only used by vttablet for display. It should match discovery_low_replication_lag here, so the vttablet status display matches what vtgate will do of it.
func RemoveUnhealthyTablets ¶
func RemoveUnhealthyTablets(tabletStatsList []TabletHealth) []TabletHealth
RemoveUnhealthyTablets filters all unhealthy tablets out. NOTE: Non-serving tablets are considered healthy.
func TabletHealthReferenceListToValue ¶ added in v0.15.0
func TabletHealthReferenceListToValue(thl []*TabletHealth) []TabletHealth
func (*TabletHealth) DeepEqual ¶
func (th *TabletHealth) DeepEqual(other *TabletHealth) bool
DeepEqual compares two TabletHealth. Since we include protos, we need to use proto.Equal on these.
func (*TabletHealth) GetHostNameLevel ¶
func (th *TabletHealth) GetHostNameLevel(level int) string
GetHostNameLevel returns the specified hostname level. If the level does not exist it will pick the closest level. This seems unused but can be utilized by certain url formatting templates. See getTabletDebugURL for more details.
func (*TabletHealth) GetTabletHostPort ¶
func (th *TabletHealth) GetTabletHostPort() string
GetTabletHostPort formats a tablet host port address.
func (*TabletHealth) MarshalJSON ¶ added in v0.14.0
func (th *TabletHealth) MarshalJSON() ([]byte, error)
type TabletPicker ¶
type TabletPicker struct {
// contains filtered or unexported fields
}
TabletPicker gives a simplified API for picking tablets.
func NewTabletPicker ¶
func NewTabletPicker( ctx context.Context, ts *topo.Server, cells []string, localCell, keyspace, shard, tabletTypesStr string, options TabletPickerOptions, ignoreTablets ...*topodatapb.TabletAlias, ) (*TabletPicker, error)
NewTabletPicker returns a TabletPicker.
func (*TabletPicker) GetMatchingTablets ¶ added in v0.11.0
func (tp *TabletPicker) GetMatchingTablets(ctx context.Context) []*topo.TabletInfo
GetMatchingTablets returns a list of TabletInfo for healthy serving tablets that match the cells, keyspace, shard and tabletTypes for this TabletPicker.
func (*TabletPicker) PickForStreaming ¶
func (tp *TabletPicker) PickForStreaming(ctx context.Context) (*topodatapb.Tablet, error)
PickForStreaming picks a tablet that is healthy and serving. Selection is based on CellPreference. See prioritizeTablets for prioritization logic.
type TabletPickerCellPreference ¶ added in v0.17.0
type TabletPickerCellPreference int
const ( // PreferLocalWithAlias gives preference to the local cell first, then specified cells, if any. // This is the default when no other option is provided. TabletPickerCellPreference_PreferLocalWithAlias TabletPickerCellPreference = iota // OnlySpecified only picks tablets from the list of cells given. TabletPickerCellPreference_OnlySpecified )
type TabletPickerOptions ¶ added in v0.17.0
type TabletPickerTabletOrder ¶ added in v0.17.0
type TabletPickerTabletOrder int
const ( // All provided tablet types are given equal priority. This is the default. TabletPickerTabletOrder_Any TabletPickerTabletOrder = iota // Provided tablet types are expected to be prioritized in the given order. TabletPickerTabletOrder_InOrder InOrderHint = "in_order:" )
type TabletStatsList ¶
type TabletStatsList []*TabletHealth
TabletStatsList is used for sorting.
func (TabletStatsList) Less ¶
func (tsl TabletStatsList) Less(i, j int) bool
Less is part of sort.Interface
func (TabletStatsList) Swap ¶
func (tsl TabletStatsList) Swap(i, j int)
Swap is part of sort.Interface
type TabletsCacheStatus ¶
type TabletsCacheStatus struct { Cell string Target *querypb.Target TabletsStats TabletStatsList }
TabletsCacheStatus is the current tablets for a cell/target.
func (*TabletsCacheStatus) StatusAsHTML ¶
func (tcs *TabletsCacheStatus) StatusAsHTML() safehtml.HTML
StatusAsHTML returns an HTML version of the status.
type TabletsCacheStatusList ¶
type TabletsCacheStatusList []*TabletsCacheStatus
TabletsCacheStatusList is used for sorting.
func (TabletsCacheStatusList) Len ¶
func (tcsl TabletsCacheStatusList) Len() int
Len is part of sort.Interface.
func (TabletsCacheStatusList) Less ¶
func (tcsl TabletsCacheStatusList) Less(i, j int) bool
Less is part of sort.Interface
func (TabletsCacheStatusList) Swap ¶
func (tcsl TabletsCacheStatusList) Swap(i, j int)
Swap is part of sort.Interface
type TopologyWatcher ¶
type TopologyWatcher struct {
// contains filtered or unexported fields
}
TopologyWatcher polls the topology periodically for changes to the set of tablets. When tablets are added / removed / modified, it calls the AddTablet / RemoveTablet interface appropriately.
func NewTopologyWatcher ¶
func NewTopologyWatcher(ctx context.Context, topoServer *topo.Server, hc HealthCheck, f TabletFilter, cell string, refreshInterval time.Duration, refreshKnownTablets bool, topoReadConcurrency int) *TopologyWatcher
NewTopologyWatcher returns a TopologyWatcher that monitors all the tablets in a cell, and reloads them as needed.
func (*TopologyWatcher) RefreshLag ¶
func (tw *TopologyWatcher) RefreshLag() time.Duration
RefreshLag returns the time since the last refresh.
func (*TopologyWatcher) Start ¶
func (tw *TopologyWatcher) Start()
Start starts the topology watcher.
func (*TopologyWatcher) Stop ¶
func (tw *TopologyWatcher) Stop()
Stop stops the watcher. It does not clean up the tablets added to HealthCheck.
func (*TopologyWatcher) TopoChecksum ¶
func (tw *TopologyWatcher) TopoChecksum() uint32
TopoChecksum returns the checksum of the current state of the topo.