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 NewCellTabletsWatcher().
Internally, the HealthCheck module is connected to each tablet and has a streaming RPC (StreamHealth) open to receive periodic health infos.
Package discovery provides a way to discover all tablets e.g. within a specific shard and monitor their current health. Deprecated Use the LegacyHealthCheck object to query for tablets and their health.
For an example how to use the LegacyHealthCheck object, see worker/topo_utils.go.
Tablets have to be manually added to the LegacyHealthCheck 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 NewLegacyShardReplicationWatcher().
Each LegacyHealthCheck has a LegacyHealthCheckStatsListener that will receive notification of when tablets go up and down. LegacyTabletStatsCache is one implementation, that caches the known tablets and the healthy ones per keyspace/shard/tabletType.
Internally, the LegacyHealthCheck 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 LegacyIsReplicationLagHigh(tabletStats *LegacyTabletStats) bool
- func LegacyIsReplicationLagVeryHigh(tabletStats *LegacyTabletStats) bool
- func ParseTabletURLTemplateFromFlag()
- func SetHighReplicationLagMinServing(lag time.Duration)
- func SetLowReplicationLag(lag time.Duration)
- func SetMinNumTablets(numTablets int)
- func SetTabletPickerRetryDelay(delay time.Duration)
- func TabletToMapKey(tablet *topodatapb.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) CacheStatus() TabletsCacheStatusList
- func (fhc *FakeHealthCheck) Close() error
- func (fhc *FakeHealthCheck) GetAllTablets() map[string]*topodatapb.Tablet
- func (fhc *FakeHealthCheck) GetHealthyTabletStats(target *querypb.Target) []*TabletHealth
- 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) 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) WaitForAllServingTablets(ctx context.Context, targets []*querypb.Target) error
- type FakeLegacyHealthCheck
- func (fhc *FakeLegacyHealthCheck) AddFakeTablet(cell, host string, port int32, keyspace, shard string, ...) queryservice.QueryService
- func (fhc *FakeLegacyHealthCheck) AddTablet(tablet *topodatapb.Tablet, name string)
- func (fhc *FakeLegacyHealthCheck) AddTestTablet(cell, host string, port int32, keyspace, shard string, ...) *sandboxconn.SandboxConn
- func (fhc *FakeLegacyHealthCheck) CacheStatus() LegacyTabletsCacheStatusList
- func (fhc *FakeLegacyHealthCheck) Close() error
- func (fhc *FakeLegacyHealthCheck) GetAllTablets() map[string]*topodatapb.Tablet
- func (fhc *FakeLegacyHealthCheck) GetConnection(key string) queryservice.QueryService
- func (fhc *FakeLegacyHealthCheck) RegisterStats()
- func (fhc *FakeLegacyHealthCheck) RemoveTablet(tablet *topodatapb.Tablet)
- func (fhc *FakeLegacyHealthCheck) ReplaceTablet(old, new *topodatapb.Tablet, name string)
- func (fhc *FakeLegacyHealthCheck) Reset()
- func (fhc *FakeLegacyHealthCheck) SetListener(listener LegacyHealthCheckStatsListener, sendDownEvents bool)
- func (fhc *FakeLegacyHealthCheck) WaitForInitialStatsUpdates()
- type FilterByKeyspace
- type FilterByShard
- type HealthCheck
- type HealthCheckImpl
- func (hc *HealthCheckImpl) AddTablet(tablet *topodata.Tablet)
- func (hc *HealthCheckImpl) CacheStatus() TabletsCacheStatusList
- func (hc *HealthCheckImpl) Close() error
- func (hc *HealthCheckImpl) GetHealthyTabletStats(target *query.Target) []*TabletHealth
- 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
- type LegacyFilterByKeyspace
- type LegacyFilterByShard
- type LegacyHealthCheck
- type LegacyHealthCheckImpl
- func (hc *LegacyHealthCheckImpl) AddTablet(tablet *topodatapb.Tablet, name string)
- func (hc *LegacyHealthCheckImpl) CacheStatus() LegacyTabletsCacheStatusList
- func (hc *LegacyHealthCheckImpl) Close() error
- func (hc *LegacyHealthCheckImpl) GetConnection(key string) queryservice.QueryService
- func (hc *LegacyHealthCheckImpl) RegisterStats()
- func (hc *LegacyHealthCheckImpl) RemoveTablet(tablet *topodatapb.Tablet)
- func (hc *LegacyHealthCheckImpl) ReplaceTablet(old, new *topodatapb.Tablet, name string)
- func (hc *LegacyHealthCheckImpl) ServeHTTP(w http.ResponseWriter, _ *http.Request)
- func (hc *LegacyHealthCheckImpl) SetListener(listener LegacyHealthCheckStatsListener, sendDownEvents bool)
- func (hc *LegacyHealthCheckImpl) WaitForInitialStatsUpdates()
- type LegacyHealthCheckStatsListener
- type LegacyTabletRecorder
- type LegacyTabletStats
- func (e *LegacyTabletStats) Copy() *LegacyTabletStats
- func (e *LegacyTabletStats) DeepEqual(f *LegacyTabletStats) bool
- func (e LegacyTabletStats) GetHostNameLevel(level int) string
- func (e LegacyTabletStats) GetTabletHostPort() string
- func (e LegacyTabletStats) NamedStatusURL() string
- func (e *LegacyTabletStats) String() string
- func (e *LegacyTabletStats) TrivialStatsUpdate(n *LegacyTabletStats) bool
- type LegacyTabletStatsCache
- func (tc *LegacyTabletStatsCache) GetHealthyTabletStats(keyspace, shard string, tabletType topodatapb.TabletType) []LegacyTabletStats
- func (tc *LegacyTabletStatsCache) GetTabletStats(keyspace, shard string, tabletType topodatapb.TabletType) []LegacyTabletStats
- func (tc *LegacyTabletStatsCache) ResetForTesting()
- func (tc *LegacyTabletStatsCache) StatsUpdate(ts *LegacyTabletStats)
- func (tc *LegacyTabletStatsCache) WaitByFilter(ctx context.Context, keyspace, shard string, ...) error
- func (tc *LegacyTabletStatsCache) WaitForAllServingTablets(ctx context.Context, targets []*querypb.Target) error
- func (tc *LegacyTabletStatsCache) WaitForTablets(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType) error
- type LegacyTabletStatsList
- type LegacyTabletsCacheStatus
- type LegacyTabletsCacheStatusList
- type LegacyTopologyWatcher
- func NewLegacyCellTabletsWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, ...) *LegacyTopologyWatcher
- func NewLegacyShardReplicationWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, ...) *LegacyTopologyWatcher
- func NewLegacyTopologyWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, ...) *LegacyTopologyWatcher
- type ShardEvent
- type TabletFilter
- type TabletHealth
- type TabletPicker
- type TabletRecorder
- type TabletStatsList
- type TabletsCacheStatus
- type TabletsCacheStatusList
- type TopologyWatcher
Constants ¶
const ( DefaultHealthCheckRetryDelay = 5 * time.Second DefaultHealthCheckTimeout = 1 * time.Minute // DefaultTopoReadConcurrency is used as the default value for the TopoReadConcurrency parameter of a TopologyWatcher. DefaultTopoReadConcurrency int = 5 // DefaultTopologyWatcherRefreshInterval is used as the default value for // the refresh interval of a topology watcher. DefaultTopologyWatcherRefreshInterval = 1 * time.Minute // HealthCheckTemplate is the HTML code to display a TabletsCacheStatusList HealthCheckTemplate = `` /* 652-byte string literal not displayed */ )
See the documentation for NewHealthCheck below for an explanation of these parameters.
const ( // LegacyHealthCheckTemplate is the HTML code to display a TabletsCacheStatusList LegacyHealthCheckTemplate = `` /* 651-byte string literal not displayed */ )
Variables ¶
var ( // TabletURLTemplateString is a flag to generate URLs for the tablets that vtgate discovers. TabletURLTemplateString = flag.String("tablet_url_template", "http://{{.GetTabletHostPort}}", "format string describing debug tablet url formatting. See the Go code for getTabletDebugURL() how to customize this.") // AllowedTabletTypes is the list of allowed tablet types. e.g. {PRIMARY, REPLICA} AllowedTabletTypes []topodata.TabletType // TabletFilters are the keyspace|shard or keyrange filters to apply to the full set of tablets TabletFilters flagutil.StringListValue // KeyspacesToWatch - if provided this specifies which keyspaces should be // visible to the healthcheck. By default the healthcheck will watch all keyspaces. KeyspacesToWatch flagutil.StringListValue // RefreshInterval is the interval at which healthcheck refreshes its list of tablets from topo RefreshInterval = flag.Duration("tablet_refresh_interval", 1*time.Minute, "tablet refresh interval") // RefreshKnownTablets tells us whether to process all tablets or only new tablets RefreshKnownTablets = flag.Bool("tablet_refresh_known_tablets", true, "tablet refresh reloads the tablet address/port map from topo in case it changes") // TopoReadConcurrency tells us how many topo reads are allowed in parallel TopoReadConcurrency = flag.Int("topo_read_concurrency", 32, "concurrent topo reads") )
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 LegacytabletHealth 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 LegacytabletHealth refers to a tablet with very high replication lag, i.e. higher than the configured discovery_high_replication_lag_minimum_serving flag.
func LegacyIsReplicationLagHigh ¶
func LegacyIsReplicationLagHigh(tabletStats *LegacyTabletStats) bool
LegacyIsReplicationLagHigh verifies that the given LegacyTabletStats refers to a tablet with high replication lag, i.e. higher than the configured discovery_low_replication_lag flag.
func LegacyIsReplicationLagVeryHigh ¶
func LegacyIsReplicationLagVeryHigh(tabletStats *LegacyTabletStats) bool
LegacyIsReplicationLagVeryHigh verifies that the given LegacyTabletStats refers to a tablet with very high replication lag, i.e. higher than the configured discovery_high_replication_lag_minimum_serving flag.
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 ¶
func TabletToMapKey(tablet *topodatapb.Tablet) string
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() *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) CacheStatus ¶
func (fhc *FakeHealthCheck) CacheStatus() TabletsCacheStatusList
CacheStatus returns the status for each tablet
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) 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) Subscribe ¶
func (fhc *FakeHealthCheck) Subscribe() chan *TabletHealth
Subscribe is not implemented.
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) WaitForAllServingTablets ¶
func (fhc *FakeHealthCheck) WaitForAllServingTablets(ctx context.Context, targets []*querypb.Target) error
WaitForAllServingTablets is not implemented.
type FakeLegacyHealthCheck ¶
type FakeLegacyHealthCheck struct {
// contains filtered or unexported fields
}
FakeLegacyHealthCheck implements discovery.LegacyHealthCheck.
func NewFakeLegacyHealthCheck ¶
func NewFakeLegacyHealthCheck() *FakeLegacyHealthCheck
NewFakeLegacyHealthCheck returns the fake healthcheck object.
func (*FakeLegacyHealthCheck) AddFakeTablet ¶
func (fhc *FakeLegacyHealthCheck) 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 FakeLegacyHealthCheck. 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 (*FakeLegacyHealthCheck) AddTablet ¶
func (fhc *FakeLegacyHealthCheck) AddTablet(tablet *topodatapb.Tablet, name string)
AddTablet adds the tablet and calls the listener.
func (*FakeLegacyHealthCheck) AddTestTablet ¶
func (fhc *FakeLegacyHealthCheck) 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 (*FakeLegacyHealthCheck) CacheStatus ¶
func (fhc *FakeLegacyHealthCheck) CacheStatus() LegacyTabletsCacheStatusList
CacheStatus returns the status for each tablet
func (*FakeLegacyHealthCheck) Close ¶
func (fhc *FakeLegacyHealthCheck) Close() error
Close is not implemented.
func (*FakeLegacyHealthCheck) GetAllTablets ¶
func (fhc *FakeLegacyHealthCheck) GetAllTablets() map[string]*topodatapb.Tablet
GetAllTablets returns all the tablets we have.
func (*FakeLegacyHealthCheck) GetConnection ¶
func (fhc *FakeLegacyHealthCheck) GetConnection(key string) queryservice.QueryService
GetConnection returns the TabletConn of the given tablet.
func (*FakeLegacyHealthCheck) RegisterStats ¶
func (fhc *FakeLegacyHealthCheck) RegisterStats()
RegisterStats is not implemented.
func (*FakeLegacyHealthCheck) RemoveTablet ¶
func (fhc *FakeLegacyHealthCheck) RemoveTablet(tablet *topodatapb.Tablet)
RemoveTablet removes the tablet.
func (*FakeLegacyHealthCheck) ReplaceTablet ¶
func (fhc *FakeLegacyHealthCheck) ReplaceTablet(old, new *topodatapb.Tablet, name string)
ReplaceTablet removes the old tablet and adds the new.
func (*FakeLegacyHealthCheck) Reset ¶
func (fhc *FakeLegacyHealthCheck) Reset()
Reset cleans up the internal state.
func (*FakeLegacyHealthCheck) SetListener ¶
func (fhc *FakeLegacyHealthCheck) SetListener(listener LegacyHealthCheckStatsListener, sendDownEvents bool)
SetListener is not implemented.
func (*FakeLegacyHealthCheck) WaitForInitialStatsUpdates ¶
func (fhc *FakeLegacyHealthCheck) WaitForInitialStatsUpdates()
WaitForInitialStatsUpdates 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 underlying LegacyTabletRecorder.
func (*FilterByKeyspace) IsIncluded ¶
func (fbk *FilterByKeyspace) IsIncluded(tablet *topodata.Tablet) bool
IsIncluded returns true if the tablet's keyspace should be forwarded to the underlying LegacyTabletRecorder.
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 on top of an existing LegacyTabletRecorder. 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 to the underlying LegacyTabletRecorder.
func (*FilterByShard) IsIncluded ¶
func (fbs *FilterByShard) IsIncluded(tablet *topodata.Tablet) bool
IsIncluded returns true iff the tablet's keyspace and shard should be forwarded to the underlying LegacyTabletRecorder.
type HealthCheck ¶
type HealthCheck interface { // CacheStatus returns a displayable version of the health check cache. CacheStatus() TabletsCacheStatusList // 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 // Subscribe adds a listener. Used by vtgate buffer to learn about primary changes. Subscribe() chan *TabletHealth // Unsubscribe removes a listener. Unsubscribe(c chan *TabletHealth) }
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) 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) 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 }
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) 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(target *query.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 LegacyFilterByKeyspace ¶
type LegacyFilterByKeyspace struct {
// contains filtered or unexported fields
}
LegacyFilterByKeyspace is a LegacyTabletRecorder filter that filters tablets by keyspace
func NewLegacyFilterByKeyspace ¶
func NewLegacyFilterByKeyspace(tr LegacyTabletRecorder, selectedKeyspaces []string) *LegacyFilterByKeyspace
NewLegacyFilterByKeyspace creates a new LegacyFilterByKeyspace on top of an existing LegacyTabletRecorder. Each filter is a keyspace entry. All tablets that match a keyspace will be forwarded to the underlying LegacyTabletRecorder.
func (*LegacyFilterByKeyspace) AddTablet ¶
func (fbk *LegacyFilterByKeyspace) AddTablet(tablet *topodatapb.Tablet, name string)
AddTablet is part of the LegacyTabletRecorder interface.
func (*LegacyFilterByKeyspace) RemoveTablet ¶
func (fbk *LegacyFilterByKeyspace) RemoveTablet(tablet *topodatapb.Tablet)
RemoveTablet is part of the LegacyTabletRecorder interface.
func (*LegacyFilterByKeyspace) ReplaceTablet ¶
func (fbk *LegacyFilterByKeyspace) ReplaceTablet(old *topodatapb.Tablet, new *topodatapb.Tablet, name string)
ReplaceTablet is part of the LegacyTabletRecorder interface.
type LegacyFilterByShard ¶
type LegacyFilterByShard struct {
// contains filtered or unexported fields
}
LegacyFilterByShard is a LegacyTabletRecorder filter that filters tablets by keyspace/shard.
func NewLegacyFilterByShard ¶
func NewLegacyFilterByShard(tr LegacyTabletRecorder, filters []string) (*LegacyFilterByShard, error)
NewLegacyFilterByShard creates a new LegacyFilterByShard on top of an existing LegacyTabletRecorder. 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 to the underlying LegacyTabletRecorder.
func (*LegacyFilterByShard) AddTablet ¶
func (fbs *LegacyFilterByShard) AddTablet(tablet *topodatapb.Tablet, name string)
AddTablet is part of the LegacyTabletRecorder interface.
func (*LegacyFilterByShard) RemoveTablet ¶
func (fbs *LegacyFilterByShard) RemoveTablet(tablet *topodatapb.Tablet)
RemoveTablet is part of the LegacyTabletRecorder interface.
func (*LegacyFilterByShard) ReplaceTablet ¶
func (fbs *LegacyFilterByShard) ReplaceTablet(old, new *topodatapb.Tablet, name string)
ReplaceTablet is part of the LegacyTabletRecorder interface.
type LegacyHealthCheck ¶
type LegacyHealthCheck interface { // LegacyTabletRecorder interface adds AddTablet and RemoveTablet methods. // AddTablet adds the tablet, and starts health check on it. // RemoveTablet removes the tablet, and stops its StreamHealth RPC. LegacyTabletRecorder // RegisterStats registers the connection counts and checksum stats. // It can only be called on one Healthcheck object per process. RegisterStats() // SetListener sets the listener for healthcheck // updates. sendDownEvents is used when a tablet changes type // (from replica to primary for instance). If the listener // wants two events (Up=false on old type, Up=True on new // type), sendDownEvents should be set. Otherwise, the // healthcheck will only send one event (Up=true on new type). // // Note that the default implementation requires to set the // listener before any tablets are added to the healthcheck. SetListener(listener LegacyHealthCheckStatsListener, sendDownEvents bool) // WaitForInitialStatsUpdates waits until all tablets added via // AddTablet() call were propagated to the listener via correspondingdiscovert // StatsUpdate() calls. Note that code path from AddTablet() to // corresponding StatsUpdate() is asynchronous but not cancelable, thus // this function is also non-cancelable and can't return error. Also // note that all AddTablet() calls should happen before calling this // method. WaitForInitialStatsUpdates won't wait for StatsUpdate() calls // corresponding to AddTablet() calls made during its execution. WaitForInitialStatsUpdates() // GetConnection returns the TabletConn of the given tablet. GetConnection(key string) queryservice.QueryService // CacheStatus returns a displayable version of the cache. CacheStatus() LegacyTabletsCacheStatusList // Close stops the healthcheck. Close() error }
LegacyHealthCheck defines the interface of health checking module. 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).
Updates to the health of all registered tablet can be watched by registering a listener. To get the underlying "TabletConn" object which is used for each tablet, use the "GetConnection()" method below and pass in the Key string which is also sent to the listener in each update (as it is part of LegacyTabletStats).
func NewLegacyDefaultHealthCheck ¶
func NewLegacyDefaultHealthCheck() LegacyHealthCheck
NewLegacyDefaultHealthCheck creates a new LegacyHealthCheck object with a default configuration.
func NewLegacyHealthCheck ¶
func NewLegacyHealthCheck(retryDelay, healthCheckTimeout time.Duration) LegacyHealthCheck
NewLegacyHealthCheck creates a new LegacyHealthCheck 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.
type LegacyHealthCheckImpl ¶
type LegacyHealthCheckImpl struct {
// contains filtered or unexported fields
}
LegacyHealthCheckImpl performs health checking and notifies downstream components about any changes. It contains a map of legacyTabletHealth objects, each of which stores the health information for a tablet. A checkConn goroutine is spawned for each legacyTabletHealth, which is responsible for keeping that legacyTabletHealth up-to-date. This is done through callbacks to updateHealth. If checkConn terminates for any reason, it updates legacyTabletHealth.Up as false. If a legacyTabletHealth gets removed from the map, its cancelFunc gets called, which ensures that the associated checkConn goroutine eventually terminates.
func (*LegacyHealthCheckImpl) AddTablet ¶
func (hc *LegacyHealthCheckImpl) AddTablet(tablet *topodatapb.Tablet, name string)
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 (*LegacyHealthCheckImpl) CacheStatus ¶
func (hc *LegacyHealthCheckImpl) CacheStatus() LegacyTabletsCacheStatusList
CacheStatus returns a displayable version of the cache.
func (*LegacyHealthCheckImpl) Close ¶
func (hc *LegacyHealthCheckImpl) Close() error
Close stops the healthcheck. After Close() returned, it's guaranteed that the listener isn't currently executing and won't be called again.
func (*LegacyHealthCheckImpl) GetConnection ¶
func (hc *LegacyHealthCheckImpl) GetConnection(key string) queryservice.QueryService
GetConnection returns the TabletConn of the given tablet.
func (*LegacyHealthCheckImpl) RegisterStats ¶
func (hc *LegacyHealthCheckImpl) RegisterStats()
RegisterStats registers the connection counts stats
func (*LegacyHealthCheckImpl) RemoveTablet ¶
func (hc *LegacyHealthCheckImpl) RemoveTablet(tablet *topodatapb.Tablet)
RemoveTablet removes the tablet, and stops the health check. It does not block.
func (*LegacyHealthCheckImpl) ReplaceTablet ¶
func (hc *LegacyHealthCheckImpl) ReplaceTablet(old, new *topodatapb.Tablet, name string)
ReplaceTablet removes the old tablet and adds the new tablet.
func (*LegacyHealthCheckImpl) ServeHTTP ¶
func (hc *LegacyHealthCheckImpl) 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 (*LegacyHealthCheckImpl) SetListener ¶
func (hc *LegacyHealthCheckImpl) SetListener(listener LegacyHealthCheckStatsListener, sendDownEvents bool)
SetListener sets the listener for healthcheck updates. It must be called after NewLegacyHealthCheck and before any tablets are added (either through AddTablet or through a Watcher).
func (*LegacyHealthCheckImpl) WaitForInitialStatsUpdates ¶
func (hc *LegacyHealthCheckImpl) WaitForInitialStatsUpdates()
WaitForInitialStatsUpdates waits until all tablets added via AddTablet() call were propagated to downstream via corresponding StatsUpdate() calls.
type LegacyHealthCheckStatsListener ¶
type LegacyHealthCheckStatsListener interface { // StatsUpdate is called when: // - a new tablet is known to the LegacyHealthCheck, and its first // streaming healthcheck is returned. (then ts.Up is true). // - a tablet is removed from the list of tablets we watch // (then ts.Up is false). // - a tablet dynamically changes its type. When registering the // listener, if sendDownEvents is true, two events are generated // (ts.Up false on the old type, ts.Up true on the new type). // If it is false, only one event is sent (ts.Up true on the new // type). StatsUpdate(*LegacyTabletStats) }
LegacyHealthCheckStatsListener is the listener to receive health check stats update.
type LegacyTabletRecorder ¶
type LegacyTabletRecorder interface { // AddTablet adds the tablet. // Name is an alternate name, like an address. AddTablet(tablet *topodatapb.Tablet, name string) // RemoveTablet removes the tablet. RemoveTablet(tablet *topodatapb.Tablet) // ReplaceTablet does an AddTablet and RemoveTablet in one call, effectively replacing the old tablet with the new. ReplaceTablet(old, new *topodatapb.Tablet, name string) }
LegacyTabletRecorder is the part of the LegacyHealthCheck interface that can add or remove tablets. We define it as a sub-interface here so we can add filters on tablets if needed.
type LegacyTabletStats ¶
type LegacyTabletStats struct { // Key uniquely identifies that serving tablet. It is computed // from the Tablet's record Hostname and PortMap. If a tablet // is restarted on different ports, its Key will be different. // Key is computed using the TabletToMapKey method below. // key can be used in GetConnection(). Key string // Tablet is the tablet object that was sent to LegacyHealthCheck.AddTablet. Tablet *topodatapb.Tablet // Name is an optional tag (e.g. alternative address) for the // tablet. It is supposed to represent the tablet as a task, // not as a process. For instance, it can be a // cell+keyspace+shard+tabletType+taskIndex value. Name string // Target is the current target as returned by the streaming // StreamHealth RPC. Target *querypb.Target // Up describes whether the tablet is added or removed. Up bool // Serving describes if the tablet can be serving traffic. Serving bool // TabletExternallyReparentedTimestamp is the last timestamp // that this tablet was either elected the primary, or received // a TabletExternallyReparented event. It is set to 0 if the // tablet doesn't think it's a primary. TabletExternallyReparentedTimestamp int64 // Stats is the current health status, as received by the // StreamHealth RPC (replication lag, ...). Stats *querypb.RealtimeStats // LastError is the error we last saw when trying to get the // tablet's healthcheck. LastError error }
LegacyTabletStats is returned when getting the set of tablets.
func FilterLegacyStatsByReplicationLag ¶
func FilterLegacyStatsByReplicationLag(tabletStatsList []*LegacyTabletStats) []*LegacyTabletStats
FilterLegacyStatsByReplicationLag filters the list of LegacyTabletStats by LegacyTabletStats.Stats.ReplicationLagSeconds. Note that LegacyTabletStats 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 []LegacyTabletStats) []LegacyTabletStats
RemoveUnhealthyTablets filters all unhealthy tablets out. NOTE: Non-serving tablets are considered healthy.
func (*LegacyTabletStats) Copy ¶
func (e *LegacyTabletStats) Copy() *LegacyTabletStats
Copy produces a copy of LegacyTabletStats.
func (*LegacyTabletStats) DeepEqual ¶
func (e *LegacyTabletStats) DeepEqual(f *LegacyTabletStats) bool
DeepEqual compares two LegacyTabletStats. Since we include protos, we need to use proto.Equal on these.
func (LegacyTabletStats) GetHostNameLevel ¶
func (e LegacyTabletStats) 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 (LegacyTabletStats) GetTabletHostPort ¶
func (e LegacyTabletStats) GetTabletHostPort() string
GetTabletHostPort formats a tablet host port address.
func (LegacyTabletStats) NamedStatusURL ¶
func (e LegacyTabletStats) NamedStatusURL() string
NamedStatusURL returns the URL for the case where a tablet server is named.
func (*LegacyTabletStats) String ¶
func (e *LegacyTabletStats) String() string
String is defined because we want to print a []*LegacyTabletStats array nicely.
func (*LegacyTabletStats) TrivialStatsUpdate ¶
func (e *LegacyTabletStats) TrivialStatsUpdate(n *LegacyTabletStats) bool
TrivialStatsUpdate returns true iff the old and new LegacyTabletStats haven't changed enough to warrant re-calling FilterLegacyStatsByReplicationLag.
type LegacyTabletStatsCache ¶
type LegacyTabletStatsCache struct {
// contains filtered or unexported fields
}
LegacyTabletStatsCache is a LegacyHealthCheckStatsListener that keeps both the current list of available LegacyTabletStats, and a serving list: - for primary tablets, only the current primary is kept. - for non-primary tablets, we filter the list using FilterLegacyStatsByReplicationLag. It keeps entries for all tablets in the cell(s) it's configured to serve for, and for the primary independently of which cell it's in. Note the healthy tablet computation is done when we receive a tablet update only, not at serving time. Also note the cache may not have the last entry received by the tablet. For instance, if a tablet was healthy, and is still healthy, we do not keep its new update.
func NewLegacyTabletStatsCache ¶
func NewLegacyTabletStatsCache(hc LegacyHealthCheck, ts *topo.Server, cell string) *LegacyTabletStatsCache
NewLegacyTabletStatsCache creates a LegacyTabletStatsCache, and registers it as LegacyHealthCheckStatsListener of the provided healthcheck. Note we do the registration in this code to guarantee we call SetListener with sendDownEvents=true, as we need these events to maintain the integrity of our cache.
func NewTabletStatsCacheDoNotSetListener ¶
func NewTabletStatsCacheDoNotSetListener(ts *topo.Server, cell string) *LegacyTabletStatsCache
NewTabletStatsCacheDoNotSetListener is identical to NewLegacyTabletStatsCache but does not automatically set the returned object as listener for "hc". Instead, it's up to the caller to ensure that LegacyTabletStatsCache.StatsUpdate() gets called properly. This is useful for chaining multiple listeners. When the caller sets its own listener on "hc", they must make sure that they set the parameter "sendDownEvents" to "true" or this cache won't properly remove tablets whose tablet type changes.
func (*LegacyTabletStatsCache) GetHealthyTabletStats ¶
func (tc *LegacyTabletStatsCache) GetHealthyTabletStats(keyspace, shard string, tabletType topodatapb.TabletType) []LegacyTabletStats
GetHealthyTabletStats returns only the healthy targets. 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 (*LegacyTabletStatsCache) GetTabletStats ¶
func (tc *LegacyTabletStatsCache) GetTabletStats(keyspace, shard string, tabletType topodatapb.TabletType) []LegacyTabletStats
GetTabletStats returns the full list of available targets. The returned array is owned by the caller.
func (*LegacyTabletStatsCache) ResetForTesting ¶
func (tc *LegacyTabletStatsCache) ResetForTesting()
ResetForTesting is for use in tests only.
func (*LegacyTabletStatsCache) StatsUpdate ¶
func (tc *LegacyTabletStatsCache) StatsUpdate(ts *LegacyTabletStats)
StatsUpdate is part of the LegacyHealthCheckStatsListener interface.
func (*LegacyTabletStatsCache) WaitByFilter ¶
func (tc *LegacyTabletStatsCache) WaitByFilter(ctx context.Context, keyspace, shard string, tabletTypes []topodatapb.TabletType, filter func([]LegacyTabletStats) []LegacyTabletStats) error
WaitByFilter waits for at least one tablet based on the filter function.
func (*LegacyTabletStatsCache) WaitForAllServingTablets ¶
func (tc *LegacyTabletStatsCache) WaitForAllServingTablets(ctx context.Context, targets []*querypb.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 (*LegacyTabletStatsCache) WaitForTablets ¶
func (tc *LegacyTabletStatsCache) WaitForTablets(ctx context.Context, keyspace, shard string, tabletType topodatapb.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 LegacyTabletStatsList ¶
type LegacyTabletStatsList []*LegacyTabletStats
LegacyTabletStatsList is used for sorting.
func (LegacyTabletStatsList) Len ¶
func (tsl LegacyTabletStatsList) Len() int
Len is part of sort.Interface.
func (LegacyTabletStatsList) Less ¶
func (tsl LegacyTabletStatsList) Less(i, j int) bool
Less is part of sort.Interface
func (LegacyTabletStatsList) Swap ¶
func (tsl LegacyTabletStatsList) Swap(i, j int)
Swap is part of sort.Interface
type LegacyTabletsCacheStatus ¶
type LegacyTabletsCacheStatus struct { Cell string Target *querypb.Target TabletsStats LegacyTabletStatsList }
LegacyTabletsCacheStatus is the current tablets for a cell/target.
func (*LegacyTabletsCacheStatus) StatusAsHTML ¶
func (tcs *LegacyTabletsCacheStatus) StatusAsHTML() template.HTML
StatusAsHTML returns an HTML version of the status.
type LegacyTabletsCacheStatusList ¶
type LegacyTabletsCacheStatusList []*LegacyTabletsCacheStatus
LegacyTabletsCacheStatusList is used for sorting.
func (LegacyTabletsCacheStatusList) Len ¶
func (tcsl LegacyTabletsCacheStatusList) Len() int
Len is part of sort.Interface.
func (LegacyTabletsCacheStatusList) Less ¶
func (tcsl LegacyTabletsCacheStatusList) Less(i, j int) bool
Less is part of sort.Interface
func (LegacyTabletsCacheStatusList) Swap ¶
func (tcsl LegacyTabletsCacheStatusList) Swap(i, j int)
Swap is part of sort.Interface
type LegacyTopologyWatcher ¶
type LegacyTopologyWatcher struct {
// contains filtered or unexported fields
}
LegacyTopologyWatcher polls tablet from a configurable set of tablets periodically. When tablets are added / removed, it calls the LegacyTabletRecorder AddTablet / RemoveTablet interface appropriately.
func NewLegacyCellTabletsWatcher ¶
func NewLegacyCellTabletsWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, cell string, refreshInterval time.Duration, refreshKnownTablets bool, topoReadConcurrency int) *LegacyTopologyWatcher
NewLegacyCellTabletsWatcher returns a LegacyTopologyWatcher that monitors all the tablets in a cell, and starts refreshing.
func NewLegacyShardReplicationWatcher ¶
func NewLegacyShardReplicationWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, cell, keyspace, shard string, refreshInterval time.Duration, topoReadConcurrency int) *LegacyTopologyWatcher
NewLegacyShardReplicationWatcher returns a LegacyTopologyWatcher that monitors the tablets in a cell/keyspace/shard, and starts refreshing.
func NewLegacyTopologyWatcher ¶
func NewLegacyTopologyWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, cell string, refreshInterval time.Duration, refreshKnownTablets bool, topoReadConcurrency int, getTablets func(tw *LegacyTopologyWatcher) ([]*topodatapb.TabletAlias, error)) *LegacyTopologyWatcher
NewLegacyTopologyWatcher returns a LegacyTopologyWatcher that monitors all the tablets in a cell, and starts refreshing.
func (*LegacyTopologyWatcher) RefreshLag ¶
func (tw *LegacyTopologyWatcher) RefreshLag() time.Duration
RefreshLag returns the time since the last refresh
func (*LegacyTopologyWatcher) Stop ¶
func (tw *LegacyTopologyWatcher) Stop()
Stop stops the watcher. It does not clean up the tablets added to LegacyTabletRecorder.
func (*LegacyTopologyWatcher) TopoChecksum ¶
func (tw *LegacyTopologyWatcher) TopoChecksum() uint32
TopoChecksum returns the checksum of the current state of the topo
func (*LegacyTopologyWatcher) WaitForInitialTopology ¶
func (tw *LegacyTopologyWatcher) WaitForInitialTopology() error
WaitForInitialTopology waits until the watcher reads all of the topology data for the first time and transfers the information to LegacyTabletRecorder via its AddTablet() method.
type ShardEvent ¶ added in v0.12.0
type ShardEvent struct { Tablet *topodatapb.TabletAlias Target *query.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 (*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.
type TabletPicker ¶
type TabletPicker struct {
// contains filtered or unexported fields
}
TabletPicker gives a simplified API for picking tablets.
func NewTabletPicker ¶
func NewTabletPicker(ts *topo.Server, cells []string, keyspace, shard, tabletTypesStr string) (*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 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 an available tablet All tablets that belong to tp.cells are evaluated and one is chosen at random
type TabletRecorder ¶
type TabletRecorder 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) }
TabletRecorder is a sub interface of HealthCheck. It is separated out to enable unit testing.
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() template.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 tablet from a configurable set of tablets periodically. When tablets are added / removed, it calls the LegacyTabletRecorder AddTablet / RemoveTablet interface appropriately.
func NewCellTabletsWatcher ¶
func NewCellTabletsWatcher(ctx context.Context, topoServer *topo.Server, tr TabletRecorder, f TabletFilter, cell string, refreshInterval time.Duration, refreshKnownTablets bool, topoReadConcurrency int) *TopologyWatcher
NewCellTabletsWatcher returns a TopologyWatcher that monitors all the tablets in a cell, and starts refreshing.
func NewTopologyWatcher ¶
func NewTopologyWatcher(ctx context.Context, topoServer *topo.Server, tr TabletRecorder, filter TabletFilter, cell string, refreshInterval time.Duration, refreshKnownTablets bool, topoReadConcurrency int, getTablets func(tw *TopologyWatcher) ([]*topodata.TabletAlias, error)) *TopologyWatcher
NewTopologyWatcher returns a TopologyWatcher that monitors all the tablets in a cell, and starts refreshing.
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 LegacyTabletRecorder.
func (*TopologyWatcher) TopoChecksum ¶
func (tw *TopologyWatcher) TopoChecksum() uint32
TopoChecksum returns the checksum of the current state of the topo
Source Files ¶
- fake_healthcheck.go
- fake_legacy_healthcheck.go
- healthcheck.go
- keyspace_events.go
- legacy_healthcheck.go
- legacy_replicationlag.go
- legacy_tablet_stats_cache.go
- legacy_tablet_stats_cache_wait.go
- legacy_topology_watcher.go
- replicationlag.go
- tablet_health.go
- tablet_health_check.go
- tablet_picker.go
- tablets_cache_status.go
- topology_watcher.go
- utils.go