Skip to content

Commit 43acf58

Browse files
committed
stash
1 parent 7702adb commit 43acf58

5 files changed

Lines changed: 42 additions & 17 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
/.vendor/
55
.idea/
66
*.tmp
7+
8+
tools/
9+
*__failpoint_binding__.go
10+
*.go__failpoint_stash__

go/base/context.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
"github.com/github/gh-ost/go/metrics"
2323
"github.com/github/gh-ost/go/mysql"
2424
"github.com/github/gh-ost/go/sql"
25-
"github.com/openark/golib/log"
2625

2726
"github.com/go-ini/ini"
27+
"github.com/openark/golib/log"
28+
"github.com/pingcap/failpoint"
2829
)
2930

3031
// RowsEstimateMethod is the type of row number estimation
@@ -1152,3 +1153,14 @@ func SendWithContext[T any](ctx context.Context, ch chan<- T, val T) error {
11521153
return ctx.Err()
11531154
}
11541155
}
1156+
1157+
func (mctx *MigrationContext) NewFailPoint(name string) {
1158+
if mctx.UnsafeFailPointsEnabled {
1159+
mctx.Log.Debugf("Injecting fail point: %s", name)
1160+
1161+
failpoint.Inject(name, func(val failpoint.Value) {
1162+
mctx.Log.Debugf("Encountered fail point: %s", name)
1163+
panic(fmt.Sprintf("encountered fail point: '%s'", name))
1164+
})
1165+
}
1166+
}

go/logic/applier.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/github/gh-ost/go/mysql"
3030
drivermysql "github.com/go-sql-driver/mysql"
3131
"github.com/openark/golib/sqlutils"
32+
"github.com/pingcap/failpoint"
3233
)
3334

3435
const (
@@ -1451,6 +1452,17 @@ func (apl *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected i
14511452
// ApplyIterationMoveTableCopyQueries issues a SELECT query on the original table and an INSERT query on the target table,
14521453
// copying a chunk of rows. It is used when `--move-tables` is specified, instead of ApplyIterationInsertQuery.
14531454
func (apl *Applier) ApplyIterationMoveTableCopyQueries(sourceDB *gosql.DB) (chunkSize int64, rowsAffected int64, duration time.Duration, err error) {
1455+
//apl.migrationContext.NewFailPoint("panic-on-row-copy")
1456+
if apl.migrationContext.UnsafeFailPointsEnabled {
1457+
name := "panic-on-row-copy"
1458+
apl.migrationContext.Log.Debugf("Injecting fail point: %s", name)
1459+
1460+
failpoint.Inject(name, func(val failpoint.Value) {
1461+
apl.migrationContext.Log.Debugf("Encountered fail point: %s", name)
1462+
panic(fmt.Sprintf("encountered fail point: '%s'", name))
1463+
})
1464+
}
1465+
14541466
startTime := time.Now()
14551467
chunkSize = atomic.LoadInt64(&apl.migrationContext.ChunkSize)
14561468
if sourceDB == nil {

go/logic/migrator.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"github.com/github/gh-ost/go/binlog"
2222
"github.com/github/gh-ost/go/mysql"
2323
"github.com/github/gh-ost/go/sql"
24-
25-
"github.com/pingcap/failpoint"
2624
)
2725

2826
var (
@@ -2871,13 +2869,3 @@ func (mgtr *Migrator) teardown() {
28712869
mgtr.sourcePrimaryDB.Close()
28722870
}
28732871
}
2874-
2875-
func (mgtr *Migrator) newFailPoint(name string) {
2876-
if mgtr.migrationContext.UnsafeFailPointsEnabled {
2877-
mgtr.migrationContext.Log.Debugf("Injecting fail point: %s", name)
2878-
2879-
failpoint.Inject(name, func(val failpoint.Value) {
2880-
panic(fmt.Sprintf("encountered fail point: '%s'", name))
2881-
})
2882-
}
2883-
}

localtests/move-tables-test.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ original_sql_mode=
3838
current_gtid_mode=
3939
test_timeout=120
4040
test_failure_log_tail_lines=50
41+
tables_to_migrate=()
4142

4243
OPTIND=1
4344
while getopts "b:s:dg" OPTION; do
@@ -177,8 +178,16 @@ build_ghost_command() {
177178
# Build gh-ost command with all standard options
178179
#
179180
# expected $1 to be a comma-separated list of tables to move
180-
cmd="GOTRACEBACK=crash $ghost_binary \
181-
--move-tables=$1 \
181+
182+
# build comma-separated list of tables to move
183+
move_tables_arg=$(IFS=, ; echo "${tables_to_migrate[*]}")
184+
185+
# NOTE(chriskirkland): fully qualified package name + failpoint name
186+
FAILPOINT="github.com/github/gh-ost/go/logic/panic-on-row-copy=return(true)"
187+
cmd="GOTRACEBACK=crash \
188+
GO_FAILPOINTS='github.com/github/gh-ost/go/logic/panic-on-row-copy=return(true)' \
189+
$ghost_binary \
190+
--move-tables=$move_tables_arg \
182191
--user=root \
183192
--password=opensesame \
184193
--host=$source_replica_host \
@@ -199,6 +208,7 @@ build_ghost_command() {
199208
--stack \
200209
--checkpoint \
201210
--postpone-cut-over-flag-file=$postpone_cutover_flag_file \
211+
--unsafe-fail-points-enabled \
202212
--execute ${extra_args[@]}"
203213
}
204214

@@ -371,8 +381,7 @@ test_single() {
371381
) &
372382

373383
# Build and execute gh-ost command
374-
move_tables_arg=$(IFS=, ; echo "${tables_to_migrate[*]}")
375-
build_ghost_command "$move_tables_arg"
384+
build_ghost_command
376385
echo_dot
377386
echo $cmd >$exec_command_file
378387
echo_dot

0 commit comments

Comments
 (0)