tidb

package module
v1.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2018 License: Apache-2.0 Imports: 48 Imported by: 0

README

Build Status Go Report Card Project Status CircleCI Status Coverage Status

What is TiDB?

TiDB (The pronunciation is: /'taɪdiːbi:/ tai-D-B, etymology: titanium) is a Hybrid Transactional/Analytical Processing (HTAP) database. Inspired by the design of Google F1 and Google Spanner, TiDB features infinite horizontal scalability, strong consistency, and high availability. The goal of TiDB is to serve as a one-stop solution for online transactions and analyses.

  • Horizontal scalability

Grow TiDB as your business grows. You can increase the capacity for storage and computation simply by adding more machines.

  • Compatible with MySQL protocol

Use TiDB as MySQL. You can replace MySQL with TiDB to power your application without changing a single line of code in most cases.

  • Automatic Failover and high availability

Your data and applications are always-on. TiDB automatically handles malfunctions and protects your applications from machine failures or even downtime of an entire data-center.

  • Consistent distributed transactions

Think of TiDB as a single-machine RDBMS. You can start a transaction that crosses multiple machines without worrying about consistency. TiDB makes your application code simple and robust.

  • Online DDL

Evolve TiDB schemas as your requirement changes. You can add new columns and indexes without stopping or affecting the on-going operations.

  • Multiple storage engine support

Power TiDB with your most favorite engines. TiDB supports local storage engines such as GolevelDB and BoltDB, as well as TiKV, a distributed storage engine.

For more details, see How we build TiDB.

Roadmap

Read the Roadmap.

Quick start

Read the Quick Start.

Documentation

Architecture

architecture

Contributing

Contributions are welcomed and greatly appreciated. See CONTRIBUTING.md for details on submitting patches and the contribution workflow.

Connect with us

License

TiDB is under the Apache 2.0 license. See the LICENSE file for details.

Acknowledgments

Documentation

Index

Constants

View Source
const (
	// CreateUserTable is the SQL statement creates User table in system db.
	CreateUserTable = `` /* 1365-byte string literal not displayed */

	// CreateDBPrivTable is the SQL statement creates DB scope privilege table in system db.
	CreateDBPrivTable = `` /* 1127-byte string literal not displayed */

	// CreateTablePrivTable is the SQL statement creates table scope privilege table in system db.
	CreateTablePrivTable = `` /* 380-byte string literal not displayed */

	// CreateColumnPrivTable is the SQL statement creates column scope privilege table in system db.
	CreateColumnPrivTable = `` /* 300-byte string literal not displayed */

	// CreateGloablVariablesTable is the SQL statement creates global variable table in system db.
	// TODO: MySQL puts GLOBAL_VARIABLES table in INFORMATION_SCHEMA db.
	// INFORMATION_SCHEMA is a virtual db in TiDB. So we put this table in system db.
	// Maybe we will put it back to INFORMATION_SCHEMA.
	CreateGloablVariablesTable = `` /* 147-byte string literal not displayed */

	// CreateTiDBTable is the SQL statement creates a table in system db.
	// This table is a key-value struct contains some information used by TiDB.
	// Currently we only put bootstrapped in it which indicates if the system is already bootstrapped.
	CreateTiDBTable = `` /* 160-byte string literal not displayed */

	// CreateHelpTopic is the SQL statement creates help_topic table in system db.
	// See: https://dev.mysql.com/doc/refman/5.5/en/system-database.html#system-database-help-tables
	CreateHelpTopic = `` /* 392-byte string literal not displayed */

	// CreateStatsMetaTable stores the meta of table statistics.
	CreateStatsMetaTable = `` /* 270-byte string literal not displayed */

	// CreateStatsColsTable stores the statistics of table columns.
	CreateStatsColsTable = `` /* 394-byte string literal not displayed */

	// CreateStatsBucketsTable stores the histogram info for every table columns.
	CreateStatsBucketsTable = `` /* 349-byte string literal not displayed */

	// CreateGCDeleteRangeTable stores schemas which can be deleted by DeleteRange.
	CreateGCDeleteRangeTable = `` /* 390-byte string literal not displayed */

)

Variables

View Source
var (
	// SchemaOutOfDateRetryInterval is the sleeping time when we fail to try.
	SchemaOutOfDateRetryInterval = int64(500 * time.Millisecond)
	// SchemaOutOfDateRetryTimes is upper bound of retry times when the schema is out of date.
	SchemaOutOfDateRetryTimes = int32(10)
)
View Source
var SchemaChangedWithoutRetry bool

SchemaChangedWithoutRetry is used for testing.

Functions

func BootstrapSession

func BootstrapSession(store kv.Storage) (*domain.Domain, error)

BootstrapSession runs the first time when the TiDB server start.

func Compile

func Compile(goCtx goctx.Context, ctx context.Context, stmtNode ast.StmtNode) (ast.Statement, error)

Compile is safe for concurrent use by multiple goroutines.

func DialPumpClientWithRetry

func DialPumpClientWithRetry(binlogSocket string, maxRetries int, dialerOpt grpc.DialOption) (*grpc.ClientConn, error)

DialPumpClientWithRetry tries to dial to binlogSocket, if any error happens, it will try to re-dial, or return this error when timeout.

func GetDomain

func GetDomain(store kv.Storage) (*domain.Domain, error)

GetDomain gets the associated domain for store.

func GetRows4Test

func GetRows4Test(goCtx goctx.Context, rs ast.RecordSet) ([]types.Row, error)

GetRows4Test gets all the rows from a RecordSet, only used for test.

func IsQuery

func IsQuery(sql string) bool

IsQuery checks if a sql statement is a query statement.

func NewStore

func NewStore(path string) (kv.Storage, error)

NewStore creates a kv Storage with path.

The path must be a URL format 'engine://path?params' like the one for tidb.Open() but with the dbname cut off. Examples:

goleveldb://relative/path
boltdb:///absolute/path

The engine should be registered before creating storage.

func Parse

func Parse(ctx context.Context, src string) ([]ast.StmtNode, error)

Parse parses a query string to raw ast.StmtNode.

func RegisterStore

func RegisterStore(name string, driver kv.Driver) error

RegisterStore registers a kv storage with unique name and its associated Driver.

func SetCommitRetryLimit

func SetCommitRetryLimit(limit int)

SetCommitRetryLimit setups the maximum number of retries when trying to recover from retryable errors. Retryable errors are generally refer to temporary errors that are expected to be reinstated by retry, including network interruption, transaction conflicts, and so on.

func SetSchemaLease

func SetSchemaLease(lease time.Duration)

SetSchemaLease changes the default schema lease time for DDL. This function is very dangerous, don't use it if you really know what you do. SetSchemaLease only affects not local storage after bootstrapped.

func SetStatsLease

func SetStatsLease(lease time.Duration)

SetStatsLease changes the default stats lease time for loading stats info.

Types

type Session

type Session interface {
	context.Context
	Status() uint16                                         // Flag of current status, such as autocommit.
	LastInsertID() uint64                                   // LastInsertID is the last inserted auto_increment ID.
	AffectedRows() uint64                                   // Affected rows by latest executed stmt.
	Execute(goctx.Context, string) ([]ast.RecordSet, error) // Execute a sql statement.
	String() string                                         // String is used to debug.
	CommitTxn(goctx.Context) error
	RollbackTxn(goctx.Context) error
	// PrepareStmt executes prepare statement in binary protocol.
	PrepareStmt(sql string) (stmtID uint32, paramCount int, fields []*ast.ResultField, err error)
	// ExecutePreparedStmt executes a prepared statement.
	ExecutePreparedStmt(goCtx goctx.Context, stmtID uint32, param ...interface{}) (ast.RecordSet, error)
	DropPreparedStmt(stmtID uint32) error
	SetClientCapability(uint32) // Set client capability flags.
	SetConnectionID(uint64)
	SetTLSState(*tls.ConnectionState)
	SetCollation(coID int) error
	SetSessionManager(util.SessionManager)
	Close()
	Auth(user *auth.UserIdentity, auth []byte, salt []byte) bool
	ShowProcess() util.ProcessInfo
	// PrePareTxnCtx is exported for test.
	PrepareTxnCtx(goctx.Context)
	// FieldList returns fields list of a table.
	FieldList(tableName string) (fields []*ast.ResultField, err error)
}

Session context

func CreateSession

func CreateSession(store kv.Storage) (Session, error)

CreateSession creates a new session environment.

func CreateSession4Test

func CreateSession4Test(store kv.Storage) (Session, error)

CreateSession4Test creates a new session environment for test.

type StmtHistory

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

StmtHistory holds all histories of statements in a txn.

func GetHistory

func GetHistory(ctx context.Context) *StmtHistory

GetHistory get all stmtHistory in current txn. Exported only for test.

func (*StmtHistory) Add

func (h *StmtHistory) Add(stmtID uint32, st ast.Statement, stmtCtx *stmtctx.StatementContext, params ...interface{})

Add appends a stmt to history list.

func (*StmtHistory) Count added in v1.0.7

func (h *StmtHistory) Count() int

Count returns the count of the history.

Directories

Path Synopsis
Package ast is the abstract syntax tree parsed from a SQL statement by parser.
Package ast is the abstract syntax tree parsed from a SQL statement by parser.
cmd
ddl
goyacc
Goyacc is a version of yacc generating Go parsers.
Goyacc is a version of yacc generating Go parsers.
sessionctx
store
tikv
Package tikv provides tcp connection to kvserver.
Package tikv provides tcp connection to kvserver.
mock
Package mock is just for test only.
Package mock is just for test only.

Jump to

Keyboard shortcuts

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