sidecardb

package
v0.20.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	StatsKeyPrefix     = "SidecarDBDDL"
	StatsKeyQueryCount = StatsKeyPrefix + "QueryCount"
	StatsKeyErrorCount = StatsKeyPrefix + "ErrorCount"
	StatsKeyErrors     = StatsKeyPrefix + "Errors"
)

Variables

This section is empty.

Functions

func AddSchemaInitQueries

func AddSchemaInitQueries(db *fakesqldb.DB, populateTables bool, parser *sqlparser.Parser)

AddSchemaInitQueries adds sidecar database schema related queries to a mock db. This is for unit tests only!

func GetIdentifierForKeyspace added in v0.17.0

func GetIdentifierForKeyspace(keyspace string) (string, error)

GetIdentifierForKeyspace is a convenience function -- combining GetIdentifierCache() and IdentifierCache.Get(keyspace) -- which returns the sidecar database identifier as an sqlparser string for the provided keyspace.

func Init

func Init(ctx context.Context, env *vtenv.Environment, exec Exec) error

Init creates or upgrades the sidecar database based on the declarative schema defined for all tables.

func MatchesInitQuery

func MatchesInitQuery(query string) bool

MatchesInitQuery returns true if the query has one of the test patterns as a substring or it matches a provided regexp. This is for unit tests only!

Types

type Exec

type Exec func(ctx context.Context, query string, maxRows int, useDB bool) (*sqltypes.Result, error)

Exec is a callback that has to be passed to Init() to execute the specified query within the database.

type IdentifierCache added in v0.17.0

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

IdentifierCache provides a read through cache of sidecar database identifiers; loading the values from an opaque backend database using a provided load function.

func GetIdentifierCache added in v0.17.0

func GetIdentifierCache() (*IdentifierCache, error)

func NewIdentifierCache added in v0.17.0

func NewIdentifierCache(loadFunc func(context.Context, string) (string, error)) (*IdentifierCache, bool)

NewIdentifierCache returns an initialized cache. This is a singleton so if you call New multiple times you will get the same instance. If the cache has already been initialized then it will return false indicating that your New call did not create a new instance.

func (*IdentifierCache) Clear added in v0.17.0

func (ic *IdentifierCache) Clear()

Clear empties out the cache.

func (*IdentifierCache) Delete added in v0.17.0

func (ic *IdentifierCache) Delete(keyspace string)

Delete removes an entry from the cache. It is idempotent and will always delete the entry IF it exists.

func (*IdentifierCache) Destroy added in v0.17.0

func (ic *IdentifierCache) Destroy()

Destroy clears the existing cache and sets the singleton instance to nil so that a new cache can be created. NOTE: this should ONLY be used in unit tests and NOT in production as it breaks the singleton pattern!

func (*IdentifierCache) Get added in v0.17.0

func (ic *IdentifierCache) Get(keyspace string) (string, error)

Get returns an sqlparser string built from an IdentifierCS using the sidecar database name stored in the database. This provides a read through cache.

Jump to

Keyboard shortcuts

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