Documentation ¶
Index ¶
- Constants
- Variables
- func NewMySQLDatastore(ctx context.Context, uri string, options ...Option) (datastore.Datastore, error)
- func NewReadOnlyMySQLDatastore(ctx context.Context, url string, index uint32, options ...Option) (datastore.ReadOnlyDatastore, error)
- type Datastore
- func (mds *Datastore) CheckRevision(ctx context.Context, revision datastore.Revision) error
- func (mds *Datastore) Close() error
- func (mds *Datastore) DeleteBeforeTx(ctx context.Context, txID datastore.Revision) (removed common.DeletionCounts, err error)
- func (mds *Datastore) Features(_ context.Context) (*datastore.Features, error)
- func (mds *Datastore) HasGCRun() bool
- func (mds *Datastore) HeadRevision(ctx context.Context) (datastore.Revision, error)
- func (mds *Datastore) MarkGCCompleted()
- func (mds *Datastore) Now(ctx context.Context) (time.Time, error)
- func (mds *Datastore) OfflineFeatures() (*datastore.Features, error)
- func (mds *Datastore) ReadWriteTx(ctx context.Context, fn datastore.TxUserFunc, opts ...options.RWTOptionsOption) (datastore.Revision, error)
- func (mds *Datastore) ReadyState(ctx context.Context) (datastore.ReadyState, error)
- func (mds *Datastore) ResetGCCompleted()
- func (mds *Datastore) SnapshotReader(rev datastore.Revision) datastore.Reader
- func (mds *Datastore) Statistics(ctx context.Context) (datastore.Stats, error)
- func (mds *Datastore) TxIDBefore(ctx context.Context, before time.Time) (datastore.Revision, error)
- func (mds *Datastore) Watch(ctx context.Context, afterRevisionRaw datastore.Revision, ...) (<-chan *datastore.RevisionChanges, <-chan error)
- type Option
- func ConnMaxIdleTime(idle time.Duration) Option
- func ConnMaxLifetime(lifetime time.Duration) Option
- func CredentialsProviderName(credentialsProviderName string) Option
- func DebugAnalyzeBeforeStatistics() Option
- func FilterMaximumIDCount(filterMaximumIDCount uint16) Option
- func GCEnabled(isGCEnabled bool) Option
- func GCInterval(interval time.Duration) Option
- func GCMaxOperationTime(time time.Duration) Option
- func GCWindow(window time.Duration) Option
- func MaxOpenConns(conns int) Option
- func MaxRetries(maxRetries uint8) Option
- func MaxRevisionStalenessPercent(stalenessPercent float64) Option
- func OverrideLockWaitTimeout(seconds uint8) Option
- func RevisionQuantization(quantization time.Duration) Option
- func TablePrefix(prefix string) Option
- func WatchBufferLength(watchBufferLength uint16) Option
- func WatchBufferWriteTimeout(watchBufferWriteTimeout time.Duration) Option
- func WithEnablePrometheusStats(enablePrometheusStats bool) Option
- type QueryBuilder
Constants ¶
const (
Engine = "mysql"
)
Variables ¶
var ParseRevisionString = revisions.RevisionParser(revisions.TransactionID)
Functions ¶
func NewMySQLDatastore ¶
func NewMySQLDatastore(ctx context.Context, uri string, options ...Option) (datastore.Datastore, error)
NewMySQLDatastore creates a new mysql.Datastore value configured with the MySQL instance specified in through the URI parameter. Supports customization via the various options available in this package.
URI: [scheme://][user[:[password]]@]host[:port][/schema][?attribute1=value1&attribute2=value2... See https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html
func NewReadOnlyMySQLDatastore ¶ added in v1.35.0
Types ¶
type Datastore ¶
type Datastore struct { *QueryBuilder *revisions.CachedOptimizedRevisions revisions.CommonDecoder // contains filtered or unexported fields }
Datastore is a MySQL-based implementation of the datastore.Datastore interface
func (*Datastore) CheckRevision ¶
func (*Datastore) DeleteBeforeTx ¶ added in v1.10.0
func (mds *Datastore) DeleteBeforeTx( ctx context.Context, txID datastore.Revision, ) (removed common.DeletionCounts, err error)
- implementation misses metrics
func (*Datastore) HeadRevision ¶
func (*Datastore) MarkGCCompleted ¶ added in v1.27.0
func (mds *Datastore) MarkGCCompleted()
func (*Datastore) OfflineFeatures ¶ added in v1.36.0
func (*Datastore) ReadWriteTx ¶ added in v1.8.0
func (mds *Datastore) ReadWriteTx( ctx context.Context, fn datastore.TxUserFunc, opts ...options.RWTOptionsOption, ) (datastore.Revision, error)
ReadWriteTx starts a read/write transaction, which will be committed if no error is returned and rolled back if an error is returned.
func (*Datastore) ReadyState ¶ added in v1.18.1
ReadyState returns whether the datastore is ready to accept data. Datastores that require database schema creation will return false until the migrations have been run to create the necessary tables.
fundamentally different from PSQL implementation:
- checking if the current migration version is compatible is implemented with IsHeadCompatible
- Database seeding is handled here, so that we can decouple schema migration from data migration and support skeema-based migrations.
func (*Datastore) ResetGCCompleted ¶ added in v1.27.0
func (mds *Datastore) ResetGCCompleted()
func (*Datastore) SnapshotReader ¶ added in v1.8.0
func (*Datastore) Statistics ¶
func (*Datastore) TxIDBefore ¶ added in v1.10.0
- main difference is how the PSQL driver handles null values
func (*Datastore) Watch ¶
func (mds *Datastore) Watch(ctx context.Context, afterRevisionRaw datastore.Revision, options datastore.WatchOptions) (<-chan *datastore.RevisionChanges, <-chan error)
Watch notifies the caller about all changes to tuples.
All events following afterRevision will be sent to the caller.
type Option ¶
type Option func(*mysqlOptions)
Option provides the facility to configure how clients within the MySQL datastore interact with the running MySQL database.
func ConnMaxIdleTime ¶
ConnMaxIdleTime is the duration after which an idle connection will be automatically closed. See https://pkg.go.dev/database/sql#DB.SetConnMaxIdleTime/
This value defaults to having no maximum.
func ConnMaxLifetime ¶
ConnMaxLifetime is the duration since creation after which a connection will be automatically closed. See https://pkg.go.dev/database/sql#DB.SetConnMaxLifetime
This value defaults to having no maximum.
func CredentialsProviderName ¶ added in v1.32.0
CredentialsProviderName is the name of the CredentialsProvider implementation to use for dynamically retrieving the datastore credentials at runtime
Empty by default.
func DebugAnalyzeBeforeStatistics ¶
func DebugAnalyzeBeforeStatistics() Option
DebugAnalyzeBeforeStatistics signals to the Statistics method that it should run Analyze Table on the relationships table before returning statistics. This should only be used for debug and testing.
Disabled by default.
func FilterMaximumIDCount ¶ added in v1.35.0
FilterMaximumIDCount is the maximum number of IDs that can be used to filter IDs in queries
func GCEnabled ¶ added in v1.13.0
GCEnabled indicates whether garbage collection is enabled.
GC is enabled by default.
func GCInterval ¶
GCInterval is the interval at which garbage collection will occur.
This value defaults to 3 minutes.
func GCMaxOperationTime ¶ added in v1.13.0
GCMaxOperationTime is the maximum operation time of a garbage collection pass before it times out.
This value defaults to 1 minute.
func GCWindow ¶
GCWindow is the maximum age of a passed revision that will be considered valid.
This value defaults to 24 hours.
func MaxOpenConns ¶
MaxOpenConns is the maximum size of the connection pool. See https://pkg.go.dev/database/sql#DB.SetMaxOpenConns
This value defaults to having no maximum.
func MaxRetries ¶ added in v1.8.0
MaxRetries is the maximum number of times a retriable transaction will be client-side retried.
Default: 10
func MaxRevisionStalenessPercent ¶ added in v1.8.0
MaxRevisionStalenessPercent is the amount of time, expressed as a percentage of the revision quantization window, that a previously computed rounded revision can still be advertised after the next rounded revision would otherwise be ready.
This value defaults to 0.1 (10%).
func OverrideLockWaitTimeout ¶ added in v1.8.0
OverrideLockWaitTimeout sets the lock wait timeout on each new connection established with the databases. As an OLTP service, the default of 50s is unbearably long to block a write for our service, so we suggest setting this value to the minimum of 1 second.
Uses server default by default.
func RevisionQuantization ¶ added in v1.8.0
RevisionQuantization is the time bucket size to which advertised revisions will be rounded.
This value defaults to 5 seconds.
func TablePrefix ¶
TablePrefix allows defining a MySQL table name prefix.
No prefix is set by default
func WatchBufferLength ¶ added in v1.8.0
WatchBufferLength is the number of entries that can be stored in the watch buffer while awaiting read by the client.
This value defaults to 128.
func WatchBufferWriteTimeout ¶ added in v1.29.0
WatchBufferWriteTimeout is the maximum timeout for writing to the watch buffer, after which the caller to the watch will be disconnected.
func WithEnablePrometheusStats ¶
WithEnablePrometheusStats marks whether Prometheus metrics provided by Go's database/sql package are enabled.
Prometheus metrics are disabled by default.
type QueryBuilder ¶
type QueryBuilder struct { GetLastRevision sq.SelectBuilder LoadRevisionRange sq.SelectBuilder WriteNamespaceQuery sq.InsertBuilder ReadNamespaceQuery sq.SelectBuilder DeleteNamespaceQuery sq.UpdateBuilder DeleteNamespaceTuplesQuery sq.UpdateBuilder ReadCounterQuery sq.SelectBuilder InsertCounterQuery sq.InsertBuilder DeleteCounterQuery sq.UpdateBuilder UpdateCounterQuery sq.UpdateBuilder QueryTuplesWithIdsQuery sq.SelectBuilder QueryTuplesQuery sq.SelectBuilder DeleteTupleQuery sq.UpdateBuilder QueryTupleExistsQuery sq.SelectBuilder WriteTupleQuery sq.InsertBuilder QueryChangedQuery sq.SelectBuilder CountTupleQuery sq.SelectBuilder WriteCaveatQuery sq.InsertBuilder ReadCaveatQuery sq.SelectBuilder ListCaveatsQuery sq.SelectBuilder DeleteCaveatQuery sq.UpdateBuilder }
QueryBuilder captures all parameterizable queries used by the MySQL datastore implementation
func NewQueryBuilder ¶
func NewQueryBuilder(driver *migrations.MySQLDriver) *QueryBuilder
NewQueryBuilder returns a new QueryBuilder instance. The migration driver is used to determine the names of the tables.