schemamanager

package
v3.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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.

func Run

func Run(ctx context.Context, controller Controller, executor Executor) error

Run applies schema changes on Vitess through VtGate.

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

func (*LocalController) Open

func (controller *LocalController) Open(ctx context.Context) error

Open goes through the schema change dir and find a keyspace with a pending schema change.

func (*LocalController) Read

func (controller *LocalController) Read(ctx context.Context) ([]string, error)

Read reads schema changes.

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) Close

func (controller *PlainController) Close()

Close is a no-op.

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.

func (*PlainController) Open

func (controller *PlainController) Open(ctx context.Context) error

Open is a no-op.

func (*PlainController) Read

func (controller *PlainController) Read(ctx context.Context) ([]string, error)

Read reads schema changes

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

type ShardWithError struct {
	Shard string
	Err   string
}

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

func (*TabletExecutor) Open

func (exec *TabletExecutor) Open(ctx context.Context, keyspace string) error

Open opens a connection to the master for every shard.

func (*TabletExecutor) Validate

func (exec *TabletExecutor) Validate(ctx context.Context, sqls []string) error

Validate validates a list of sql statements.

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) Close

func (controller *UIController) Close()

Close is a no-op.

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

func (*UIController) Open

func (controller *UIController) Open(ctx context.Context) error

Open is a no-op.

func (*UIController) Read

func (controller *UIController) Read(ctx context.Context) ([]string, error)

Read reads schema changes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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