cache

package
v1.1.0-beta.0...-2a72e7f Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TableRowStatsCache = &StatsTableRowCache{
	tableRows: make(map[int64]uint64),
	colLength: make(map[tableHistID]uint64),
}

TableRowStatsCache is the cache of table row count.

Functions

func NewStatsCacheImpl

func NewStatsCacheImpl(statsHandle types.StatsHandle) (types.StatsCache, error)

NewStatsCacheImpl creates a new StatsCache.

func NewStatsCacheImplForTest

func NewStatsCacheImplForTest() (types.StatsCache, error)

NewStatsCacheImplForTest creates a new StatsCache for test.

Types

type StatsCache

type StatsCache struct {
	// contains filtered or unexported fields
}

StatsCache caches the tables in memory for Handle. TODO: hide this structure or merge it into StatsCacheImpl.

func NewStatsCache

func NewStatsCache() (*StatsCache, error)

NewStatsCache creates a new StatsCacheWrapper.

func (*StatsCache) Close

func (sc *StatsCache) Close()

Close stops the cache.

func (*StatsCache) CopyAndUpdate

func (sc *StatsCache) CopyAndUpdate(tables []*statistics.Table, deletedIDs []int64) *StatsCache

CopyAndUpdate copies a new cache and updates the new statistics table cache. It is only used in the COW mode.

func (*StatsCache) Cost

func (sc *StatsCache) Cost() int64

Cost returns the memory usage of the cache.

func (*StatsCache) Get

func (sc *StatsCache) Get(id int64) (*statistics.Table, bool)

Get returns the statistics of the specified Table ID. The returned value should be read-only, if you update it, don't forget to use Put to put it back again, otherwise the memory trace can be inaccurate.

e.g. v := sc.Get(id); /* update the value */ v.Version = 123; sc.Put(id, v);

func (*StatsCache) Len

func (sc *StatsCache) Len() int

Len returns the number of tables in the cache.

func (*StatsCache) Put

func (sc *StatsCache) Put(id int64, t *statistics.Table)

Put puts the table statistics to the cache from query.

func (*StatsCache) SetCapacity

func (sc *StatsCache) SetCapacity(c int64)

SetCapacity sets the memory capacity of the cache.

func (*StatsCache) TriggerEvict

func (sc *StatsCache) TriggerEvict()

TriggerEvict triggers the cache to evict some items.

func (*StatsCache) Update

func (sc *StatsCache) Update(tables []*statistics.Table, deletedIDs []int64, skipMoveForwardStatsCache bool)

Update updates the new statistics table cache.

func (*StatsCache) Values

func (sc *StatsCache) Values() []*statistics.Table

Values returns all the cached statistics tables.

func (*StatsCache) Version

func (sc *StatsCache) Version() uint64

Version returns the version of the current cache, which is defined as the max table stats version the cache has in its lifecycle.

type StatsCacheImpl

type StatsCacheImpl struct {
	atomic.Pointer[StatsCache]
	// contains filtered or unexported fields
}

StatsCacheImpl implements util.StatsCache.

func (*StatsCacheImpl) Clear

func (s *StatsCacheImpl) Clear()

Clear clears this cache. Create a empty cache and replace the old one.

func (*StatsCacheImpl) Close

func (s *StatsCacheImpl) Close()

Close closes this cache.

func (*StatsCacheImpl) Get

func (s *StatsCacheImpl) Get(tableID int64) (*statistics.Table, bool)

Get returns the specified table's stats.

func (*StatsCacheImpl) GetNextCheckVersionWithOffset

func (s *StatsCacheImpl) GetNextCheckVersionWithOffset() uint64

GetNextCheckVersionWithOffset gets the last version with offset.

func (*StatsCacheImpl) Len

func (s *StatsCacheImpl) Len() int

Len returns the length of this cache.

func (*StatsCacheImpl) MaxTableStatsVersion

func (s *StatsCacheImpl) MaxTableStatsVersion() uint64

MaxTableStatsVersion returns the version of the current cache, which is defined as the max table stats version the cache has in its lifecycle.

func (*StatsCacheImpl) MemConsumed

func (s *StatsCacheImpl) MemConsumed() (size int64)

MemConsumed returns its memory usage.

func (*StatsCacheImpl) Put

func (s *StatsCacheImpl) Put(id int64, t *statistics.Table)

Put puts this table stats into the cache.

func (*StatsCacheImpl) Replace

func (s *StatsCacheImpl) Replace(cache types.StatsCache)

Replace replaces this cache.

func (*StatsCacheImpl) SetStatsCacheCapacity

func (s *StatsCacheImpl) SetStatsCacheCapacity(c int64)

SetStatsCacheCapacity sets the cache's capacity.

func (*StatsCacheImpl) TriggerEvict

func (s *StatsCacheImpl) TriggerEvict()

TriggerEvict triggers the cache to evict some items.

func (*StatsCacheImpl) Update

func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, tableAndPartitionIDs ...int64) error

Update reads stats meta from store and updates the stats map.

func (*StatsCacheImpl) UpdateStatsCache

func (s *StatsCacheImpl) UpdateStatsCache(cacheUpdate types.CacheUpdate)

UpdateStatsCache updates the cache with the new cache.

func (*StatsCacheImpl) UpdateStatsHealthyMetrics

func (s *StatsCacheImpl) UpdateStatsHealthyMetrics()

UpdateStatsHealthyMetrics updates stats healthy distribution metrics according to stats cache.

func (*StatsCacheImpl) Values

func (s *StatsCacheImpl) Values() []*statistics.Table

Values returns all values in this cache.

type StatsTableRowCache

type StatsTableRowCache struct {
	// contains filtered or unexported fields
}

StatsTableRowCache is used to cache the count of table rows.

func (*StatsTableRowCache) EstimateDataLength

func (c *StatsTableRowCache) EstimateDataLength(table *model.TableInfo) (
	rowCount uint64, avgRowLength uint64, dataLength uint64, indexLength uint64)

EstimateDataLength returns the estimated data length in bytes of a given table info. Returns row count, average row length, total data length, and all indexed column length.

func (*StatsTableRowCache) GetColLength

func (c *StatsTableRowCache) GetColLength(id tableHistID) uint64

GetColLength gets the length of the column.

func (*StatsTableRowCache) GetDataAndIndexLength

func (c *StatsTableRowCache) GetDataAndIndexLength(info *model.TableInfo, physicalID int64, rowCount uint64) (dataLength, indexLength uint64)

GetDataAndIndexLength gets the data and index length of the table.

func (*StatsTableRowCache) GetTableRows

func (c *StatsTableRowCache) GetTableRows(id int64) uint64

GetTableRows gets the count of table rows.

func (*StatsTableRowCache) Invalidate

func (c *StatsTableRowCache) Invalidate(tblID int64)

Invalidate invalidates the cache of the table with id.

func (*StatsTableRowCache) Update

func (c *StatsTableRowCache) Update(sctx sessionctx.Context) error

Update tries to update the cache.

func (*StatsTableRowCache) UpdateByID

func (c *StatsTableRowCache) UpdateByID(sctx sessionctx.Context, id int64) error

UpdateByID tries to update the cache by table ID.

Directories

Path Synopsis
lfu

Jump to

Keyboard shortcuts

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