MCPcopy
hub / github.com/github/gh-ost / CreateCheckpointTable

Method CreateCheckpointTable

go/logic/applier.go:619–657  ·  view source on GitHub ↗

Create the checkpoint table to store the chunk copy and applier state. There are two sets of columns with the same types as the shared unique key, one for IterationMinValues and one for IterationMaxValues.

()

Source from the content-addressed store, hash-verified

617// There are two sets of columns with the same types as the shared unique key,
618// one for IterationMinValues and one for IterationMaxValues.
619func (apl *Applier) CreateCheckpointTable() error {
620 if err := apl.DropCheckpointTable(); err != nil {
621 return err
622 }
623 colDefs := []string{
624 "`gh_ost_chk_id` bigint auto_increment primary key",
625 "`gh_ost_chk_timestamp` bigint",
626 "`gh_ost_chk_coords` text charset ascii",
627 "`gh_ost_chk_iteration` bigint",
628 "`gh_ost_rows_copied` bigint",
629 "`gh_ost_dml_applied` bigint",
630 "`gh_ost_is_cutover` tinyint(1) DEFAULT '0'",
631 }
632 for _, col := range apl.migrationContext.UniqueKey.Columns.Columns() {
633 if col.MySQLType == "" {
634 return fmt.Errorf("column %s has no type information. applyColumnTypes must be called", sql.EscapeName(col.Name))
635 }
636 minColName := sql.TruncateColumnName(col.Name, sql.MaxColumnNameLength-4) + "_min"
637 colDef := fmt.Sprintf("%s %s", sql.EscapeName(minColName), col.MySQLType)
638 colDefs = append(colDefs, colDef)
639 }
640
641 for _, col := range apl.migrationContext.UniqueKey.Columns.Columns() {
642 maxColName := sql.TruncateColumnName(col.Name, sql.MaxColumnNameLength-4) + "_max"
643 colDef := fmt.Sprintf("%s %s", sql.EscapeName(maxColName), col.MySQLType)
644 colDefs = append(colDefs, colDef)
645 }
646
647 query := fmt.Sprintf("create /* gh-ost */ table %s.%s (\n %s\n)",
648 sql.EscapeName(apl.migrationContext.DatabaseName),
649 sql.EscapeName(apl.migrationContext.GetCheckpointTableName()),
650 strings.Join(colDefs, ",\n "),
651 )
652 apl.migrationContext.Log.Infof("Created checkpoint table")
653 if _, err := sqlutils.ExecNoPrepare(apl.db, query); err != nil {
654 return err
655 }
656 return nil
657}
658
659// dropTable drops a given table on the applied host
660func (apl *Applier) dropTable(tableName string) error {

Callers 2

TestWriteCheckpointMethod · 0.95
MigrateMethod · 0.80

Calls 7

DropCheckpointTableMethod · 0.95
EscapeNameFunction · 0.92
TruncateColumnNameFunction · 0.92
ColumnsMethod · 0.80
ErrorfMethod · 0.65
InfofMethod · 0.65

Tested by 1

TestWriteCheckpointMethod · 0.76