go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletserver/schema Index | Files | Directories

package schema

import "gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletserver/schema"


Package Files

engine.go load_table.go schema.go schemaz.go


const (
    NoType = iota

Table types


var TypeNames = []string{

TypeNames allows to fetch a the type name for a table. Count must match the number of table types.

type Engine Uses

type Engine struct {
    // contains filtered or unexported fields

Engine stores the schema info and performs operations that keep itself up-to-date.

func NewEngine Uses

func NewEngine(checker connpool.MySQLChecker, config tabletenv.TabletConfig) *Engine

NewEngine creates a new Engine.

func NewEngineForTests Uses

func NewEngineForTests() *Engine

NewEngineForTests creates a new engine, that can't query the database, and will not send notifications. It starts opened, and doesn't reload. Use SetTableForTests to set table schema.

func (*Engine) Close Uses

func (se *Engine) Close()

Close shuts down Engine and is idempotent. It can be re-opened after Close.

func (*Engine) GetSchema Uses

func (se *Engine) GetSchema() map[string]*Table

GetSchema returns the current The Tables are a shared data structure and must be treated as read-only.

func (*Engine) GetTable Uses

func (se *Engine) GetTable(tableName sqlparser.TableIdent) *Table

GetTable returns the info for a table.

func (*Engine) InitDBConfig Uses

func (se *Engine) InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

InitDBConfig must be called before Open.

func (*Engine) MakeNonMaster Uses

func (se *Engine) MakeNonMaster()

MakeNonMaster clears the sequence caches to make sure that they don't get accidentally reused after losing mastership.

func (*Engine) Open Uses

func (se *Engine) Open() error

Open initializes the Engine. Calling Open on an already open engine is a no-op.

func (*Engine) RegisterNotifier Uses

func (se *Engine) RegisterNotifier(name string, f notifier)

RegisterNotifier registers the function for schema change notification. It also causes an immediate notification to the caller. The notified function must not change the map or its contents. The only exception is the sequence table where the values can be changed using the lock.

func (*Engine) Reload Uses

func (se *Engine) Reload(ctx context.Context) error

Reload reloads the schema info from the db. Any tables that have changed since the last load are updated. This is a no-op if the Engine is closed.

func (*Engine) ReloadTime Uses

func (se *Engine) ReloadTime() time.Duration

ReloadTime returns schema info reload time.

func (*Engine) ServeHTTP Uses

func (se *Engine) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*Engine) SetReloadTime Uses

func (se *Engine) SetReloadTime(reloadTime time.Duration)

SetReloadTime changes how often the schema is reloaded. This call also triggers an immediate reload.

func (*Engine) SetTableForTests Uses

func (se *Engine) SetTableForTests(table *Table)

SetTableForTests puts a Table in the map directly.

func (*Engine) UnregisterNotifier Uses

func (se *Engine) UnregisterNotifier(name string)

UnregisterNotifier unregisters the notifier function.

type Index Uses

type Index struct {
    Name   sqlparser.ColIdent
    Unique bool
    // Columns are the columns comprising the index.
    Columns []sqlparser.ColIdent
    // Cardinality[i] is the number of distinct values of Columns[i] in the
    // table.
    Cardinality []uint64

Index contains info about a table index.

func NewIndex Uses

func NewIndex(name string, unique bool) *Index

NewIndex creates a new Index.

func (*Index) AddColumn Uses

func (idx *Index) AddColumn(name string, cardinality uint64)

AddColumn adds a column to the index.

func (*Index) FindColumn Uses

func (idx *Index) FindColumn(name sqlparser.ColIdent) int

FindColumn finds a column in the index. It returns the index if found. Otherwise, it returns -1.

type MessageInfo Uses

type MessageInfo struct {
    // IDPKIndex is the index of the ID column
    // in PKvalues. This is used to extract the ID
    // value for message tables to discard items
    // from the cache.
    IDPKIndex int

    // Fields stores the field info to be
    // returned for subscribers.
    Fields []*querypb.Field

    // AckWaitDuration specifies how long to wait after
    // the message was first sent. The back-off doubles
    // every attempt.
    AckWaitDuration time.Duration

    // PurgeAfterDuration specifies the time after which
    // a successfully acked message can be deleted.
    PurgeAfterDuration time.Duration

    // BatchSize specifies the max number of events to
    // send per response.
    BatchSize int

    // CacheSize specifies the number of messages to keep
    // in cache. Anything that cannot fit in the cache
    // is sent as best effort.
    CacheSize int

    // PollInterval specifies the polling frequency to
    // look for messages to be sent.
    PollInterval time.Duration

MessageInfo contains info specific to message tables.

type SequenceInfo Uses

type SequenceInfo struct {
    NextVal int64
    LastVal int64

SequenceInfo contains info specific to sequence tabels. It must be locked before accessing the values inside. If CurVal==LastVal, we have to cache new values. When the schema is first loaded, the values are all 0, which will trigger caching on first use.

type Table Uses

type Table struct {
    Name      sqlparser.TableIdent
    Columns   []TableColumn
    Indexes   []*Index
    PKColumns []int
    Type      int

    // SequenceInfo contains info for sequence tables.
    SequenceInfo *SequenceInfo

    // MessageInfo contains info for message tables.
    MessageInfo *MessageInfo

    // These vars can be accessed concurrently.
    TableRows     sync2.AtomicInt64
    DataLength    sync2.AtomicInt64
    IndexLength   sync2.AtomicInt64
    DataFree      sync2.AtomicInt64
    MaxDataLength sync2.AtomicInt64

Table contains info about a table.

func LoadTable Uses

func LoadTable(conn *connpool.DBConn, tableName string, tableType string, comment string) (*Table, error)

LoadTable creates a Table from the schema info in the database.

func NewTable Uses

func NewTable(name string) *Table

NewTable creates a new Table.

func (*Table) AddColumn Uses

func (ta *Table) AddColumn(name string, columnType querypb.Type, defval sqltypes.Value, extra string)

AddColumn adds a column to the Table.

func (*Table) AddIndex Uses

func (ta *Table) AddIndex(name string, unique bool) (index *Index)

AddIndex adds an index to the table.

func (*Table) Done Uses

func (ta *Table) Done()

Done must be called after columns and indexes are added to the table. It will build additional metadata like PKColumns.

func (*Table) FindColumn Uses

func (ta *Table) FindColumn(name sqlparser.ColIdent) int

FindColumn finds a column in the table. It returns the index if found. Otherwise, it returns -1.

func (*Table) GetPKColumn Uses

func (ta *Table) GetPKColumn(index int) *TableColumn

GetPKColumn returns the pk column specified by the index.

func (*Table) HasPrimary Uses

func (ta *Table) HasPrimary() bool

HasPrimary returns true if the table has a primary key.

func (*Table) SetMysqlStats Uses

func (ta *Table) SetMysqlStats(tr, dl, il, df, mdl sqltypes.Value)

SetMysqlStats receives the values found in the mysql information_schema.tables table

func (*Table) UniqueIndexes Uses

func (ta *Table) UniqueIndexes() int

UniqueIndexes returns the number of unique indexes on the table

type TableColumn Uses

type TableColumn struct {
    Name    sqlparser.ColIdent
    Type    querypb.Type
    IsAuto  bool
    Default sqltypes.Value

TableColumn contains info about a table's column.

func (*TableColumn) String Uses

func (c *TableColumn) String() string

String() pretty-prints TableColumn into a string.


schematestPackage schematest provides support for testing packages that depend on schema

Package schema imports 27 packages (graph) and is imported by 9 packages. Updated 2019-06-13. Refresh now. Tools for package owners.