Documentation ¶
Index ¶
- Constants
- func RegisterControllerFactory(name string, factory ControllerFactory)
- func Run(ctx context.Context, controller Controller, executor Executor) error
- type Controller
- type ControllerFactory
- type ExecuteResult
- type Executor
- type LocalController
- func (controller *LocalController) Close()
- func (controller *LocalController) Keyspace() string
- func (controller *LocalController) OnExecutorComplete(ctx context.Context, result *ExecuteResult) error
- func (controller *LocalController) OnReadFail(ctx context.Context, err error) error
- func (controller *LocalController) OnReadSuccess(ctx context.Context) error
- func (controller *LocalController) OnValidationFail(ctx context.Context, err error) error
- func (controller *LocalController) OnValidationSuccess(ctx context.Context) error
- func (controller *LocalController) Open(ctx context.Context) error
- func (controller *LocalController) Read(ctx context.Context) ([]string, error)
- type PlainController
- func (controller *PlainController) Close()
- func (controller *PlainController) Keyspace() string
- func (controller *PlainController) OnExecutorComplete(ctx context.Context, result *ExecuteResult) error
- func (controller *PlainController) OnReadFail(ctx context.Context, err error) error
- func (controller *PlainController) OnReadSuccess(ctx context.Context) error
- func (controller *PlainController) OnValidationFail(ctx context.Context, err error) error
- func (controller *PlainController) OnValidationSuccess(ctx context.Context) error
- func (controller *PlainController) Open(ctx context.Context) error
- func (controller *PlainController) Read(ctx context.Context) ([]string, error)
- type ShardResult
- type ShardWithError
- type TabletExecutor
- func (exec *TabletExecutor) AllowBigSchemaChange()
- func (exec *TabletExecutor) Close()
- func (exec *TabletExecutor) DisallowBigSchemaChange()
- func (exec *TabletExecutor) Execute(ctx context.Context, sqls []string) *ExecuteResult
- func (exec *TabletExecutor) Open(ctx context.Context, keyspace string) error
- func (exec *TabletExecutor) Validate(ctx context.Context, sqls []string) error
- type UIController
- func (controller *UIController) Close()
- func (controller *UIController) Keyspace() string
- func (controller *UIController) OnExecutorComplete(ctx context.Context, result *ExecuteResult) error
- func (controller *UIController) OnReadFail(ctx context.Context, err error) error
- func (controller *UIController) OnReadSuccess(ctx context.Context) error
- func (controller *UIController) OnValidationFail(ctx context.Context, err error) error
- func (controller *UIController) OnValidationSuccess(ctx context.Context) error
- func (controller *UIController) Open(ctx context.Context) error
- func (controller *UIController) Read(ctx context.Context) ([]string, error)
Constants ¶
const ( // SchemaChangeDirName is the key name in the ControllerFactory params. // It specifies the schema change directory. SchemaChangeDirName = "schema_change_dir" // SchemaChangeUser is the key name in the ControllerFactory params. // It specifies the user who submits this schema change. SchemaChangeUser = "schema_change_user" )
Variables ¶
This section is empty.
Functions ¶
func RegisterControllerFactory ¶
func RegisterControllerFactory(name string, factory ControllerFactory)
RegisterControllerFactory register a control factory.
Types ¶
type Controller ¶
type Controller interface { Open(ctx context.Context) error Read(ctx context.Context) (sqls []string, err error) Close() Keyspace() string OnReadSuccess(ctx context.Context) error OnReadFail(ctx context.Context, err error) error OnValidationSuccess(ctx context.Context) error OnValidationFail(ctx context.Context, err error) error OnExecutorComplete(ctx context.Context, result *ExecuteResult) error }
Controller is responsible for getting schema change for a certain keyspace and also handling various events happened during schema change.
type ControllerFactory ¶
type ControllerFactory func(params map[string]string) (Controller, error)
ControllerFactory takes a set params and construct a Controller instance.
func GetControllerFactory ¶
func GetControllerFactory(name string) (ControllerFactory, error)
GetControllerFactory gets a ControllerFactory.
type ExecuteResult ¶
type ExecuteResult struct { FailedShards []ShardWithError SuccessShards []ShardResult CurSQLIndex int Sqls []string ExecutorErr string TotalTimeSpent time.Duration }
ExecuteResult contains information about schema management state
type Executor ¶
type Executor interface { Open(ctx context.Context, keyspace string) error Validate(ctx context.Context, sqls []string) error Execute(ctx context.Context, sqls []string) *ExecuteResult Close() }
Executor applies schema changes to underlying system
type LocalController ¶
type LocalController struct {
// contains filtered or unexported fields
}
LocalController listens to the specified schema change dir and applies schema changes. schema change dir lay out
| |----keyspace_01 |----input |---- create_test_table.sql |---- alter_test_table_02.sql |---- ... |----complete // contains completed schema changes in yyyy/MM/dd |----2015 |----01 |----01 |--- create_table_table_02.sql |----log // contains detailed execution information about schema changes |----2015 |----01 |----01 |--- create_table_table_02.sql |----error // contains failed schema changes |----2015 |----01 |----01 |--- create_table_table_03.sql
Schema Change Files: ${keyspace}/input/*.sql Error Files: ${keyspace}/error/${YYYY}/${MM}/${DD}/*.sql Log Files: ${keyspace}/log/${YYYY}/${MM}/${DD}/*.sql Complete Files: ${keyspace}/complete/${YYYY}/${MM}/${DD}/*.sql
func NewLocalController ¶
func NewLocalController(schemaChangeDir string) *LocalController
NewLocalController creates a new LocalController instance.
func (*LocalController) Close ¶
func (controller *LocalController) Close()
Close reset keyspace, sqlPath, errorDir, logDir and completeDir.
func (*LocalController) Keyspace ¶
func (controller *LocalController) Keyspace() string
Keyspace returns current keyspace that is ready for applying schema change.
func (*LocalController) OnExecutorComplete ¶
func (controller *LocalController) OnExecutorComplete(ctx context.Context, result *ExecuteResult) error
OnExecutorComplete is no-op
func (*LocalController) OnReadFail ¶
func (controller *LocalController) OnReadFail(ctx context.Context, err error) error
OnReadFail is no-op
func (*LocalController) OnReadSuccess ¶
func (controller *LocalController) OnReadSuccess(ctx context.Context) error
OnReadSuccess is no-op
func (*LocalController) OnValidationFail ¶
func (controller *LocalController) OnValidationFail(ctx context.Context, err error) error
OnValidationFail is no-op
func (*LocalController) OnValidationSuccess ¶
func (controller *LocalController) OnValidationSuccess(ctx context.Context) error
OnValidationSuccess is no-op
type PlainController ¶
type PlainController struct {
// contains filtered or unexported fields
}
PlainController implements Controller interface.
func NewPlainController ¶
func NewPlainController(sqlStr string, keyspace string) *PlainController
NewPlainController creates a new PlainController instance.
func (*PlainController) Keyspace ¶
func (controller *PlainController) Keyspace() string
Keyspace returns keyspace to apply schema.
func (*PlainController) OnExecutorComplete ¶
func (controller *PlainController) OnExecutorComplete(ctx context.Context, result *ExecuteResult) error
OnExecutorComplete is called when schemamanager finishes applying schema changes.
func (*PlainController) OnReadFail ¶
func (controller *PlainController) OnReadFail(ctx context.Context, err error) error
OnReadFail is called when schemamanager fails to read all sql statements.
func (*PlainController) OnReadSuccess ¶
func (controller *PlainController) OnReadSuccess(ctx context.Context) error
OnReadSuccess is called when schemamanager successfully reads all sql statements.
func (*PlainController) OnValidationFail ¶
func (controller *PlainController) OnValidationFail(ctx context.Context, err error) error
OnValidationFail is called when schemamanager fails to validate sql statements.
func (*PlainController) OnValidationSuccess ¶
func (controller *PlainController) OnValidationSuccess(ctx context.Context) error
OnValidationSuccess is called when schemamanager successfully validates all sql statements.
type ShardResult ¶
type ShardResult struct { Shard string Result *querypb.QueryResult // Position is a replication position that is guaranteed to be after the // schema change was applied. It can be used to wait for slaves to receive // the schema change via replication. Position string }
ShardResult contains sql execute information on a particular shard
type ShardWithError ¶
ShardWithError contains information why a shard failed to execute given sql
type TabletExecutor ¶
type TabletExecutor struct {
// contains filtered or unexported fields
}
TabletExecutor applies schema changes to all tablets.
func NewTabletExecutor ¶
func NewTabletExecutor(wr *wrangler.Wrangler, waitSlaveTimeout time.Duration) *TabletExecutor
NewTabletExecutor creates a new TabletExecutor instance
func (*TabletExecutor) AllowBigSchemaChange ¶
func (exec *TabletExecutor) AllowBigSchemaChange()
AllowBigSchemaChange changes TabletExecutor such that big schema changes will no longer be rejected.
func (*TabletExecutor) Close ¶
func (exec *TabletExecutor) Close()
Close clears tablet executor states
func (*TabletExecutor) DisallowBigSchemaChange ¶
func (exec *TabletExecutor) DisallowBigSchemaChange()
DisallowBigSchemaChange enables the check for big schema changes such that TabletExecutor will reject these.
func (*TabletExecutor) Execute ¶
func (exec *TabletExecutor) Execute(ctx context.Context, sqls []string) *ExecuteResult
Execute applies schema changes
type UIController ¶
type UIController struct {
// contains filtered or unexported fields
}
UIController handles schema events.
func NewUIController ¶
func NewUIController( sqlStr string, keyspace string, writer http.ResponseWriter) *UIController
NewUIController creates a UIController instance
func (*UIController) Keyspace ¶
func (controller *UIController) Keyspace() string
Keyspace returns keyspace to apply schema.
func (*UIController) OnExecutorComplete ¶
func (controller *UIController) OnExecutorComplete(ctx context.Context, result *ExecuteResult) error
OnExecutorComplete is no-op
func (*UIController) OnReadFail ¶
func (controller *UIController) OnReadFail(ctx context.Context, err error) error
OnReadFail is no-op
func (*UIController) OnReadSuccess ¶
func (controller *UIController) OnReadSuccess(ctx context.Context) error
OnReadSuccess is no-op
func (*UIController) OnValidationFail ¶
func (controller *UIController) OnValidationFail(ctx context.Context, err error) error
OnValidationFail is no-op
func (*UIController) OnValidationSuccess ¶
func (controller *UIController) OnValidationSuccess(ctx context.Context) error
OnValidationSuccess is no-op