Skip to content

Commit 7702adb

Browse files
committed
install failpoint
1 parent eed0793 commit 7702adb

19 files changed

Lines changed: 2114 additions & 0 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ require (
5555
github.com/opencontainers/go-digest v1.0.0 // indirect
5656
github.com/opencontainers/image-spec v1.1.1 // indirect
5757
github.com/pingcap/errors v0.11.5-0.20260310054046-9c8b3586e4b2 // indirect
58+
github.com/pingcap/failpoint v0.0.0-20260521055755-e7642935314f // indirect
5859
github.com/pingcap/log v1.1.1-0.20260227082333-572e590d08f1 // indirect
5960
github.com/pingcap/tidb/pkg/parser v0.0.0-20260504140133-511dba1dbe17 // indirect
6061
github.com/pkg/errors v0.9.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb h1:3pSi4EDG6hg0o
117117
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
118118
github.com/pingcap/errors v0.11.5-0.20260310054046-9c8b3586e4b2 h1:cLgCk5mwDG9lDH+dPK8TmEliTjyGJwwKN0qevWAl8IY=
119119
github.com/pingcap/errors v0.11.5-0.20260310054046-9c8b3586e4b2/go.mod h1:ktAJCA9lxrHHjVyVl2pKJFvzBnq2eZbb+CUOjBRPlXo=
120+
github.com/pingcap/failpoint v0.0.0-20260521055755-e7642935314f h1:cDo4qNgaQc2POMWTXjNrMA7yySdIF/d1AaW8kOA7qOs=
121+
github.com/pingcap/failpoint v0.0.0-20260521055755-e7642935314f/go.mod h1:jimwlLpI/XtwQdlZML15HS+j4rirvwZM0GLY07wwgOo=
120122
github.com/pingcap/log v1.1.1-0.20230317032135-a0d097d16e22 h1:2SOzvGvE8beiC1Y4g9Onkvu6UmuBBOeWRGQEjJaT/JY=
121123
github.com/pingcap/log v1.1.1-0.20230317032135-a0d097d16e22/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
122124
github.com/pingcap/log v1.1.1-0.20260227082333-572e590d08f1 h1:A2bEfgSb7hLwR9mxDszgGKweF+xY9YoTDG+8RjdFjDE=

go/base/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ type MigrationContext struct {
305305
DrainGTID mysql.BinlogCoordinates // Source @@gtid_executed captured immediately after the source RENAME TABLE; the applier drains until it reaches this coordinate (move-tables only).
306306
}
307307

308+
UnsafeFailPointsEnabled bool
309+
308310
Log Logger
309311
}
310312

go/cmd/gh-ost/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ func main() {
197197
flag.StringVar(&migrationContext.MoveTables.TargetDatabase, "target-database", "", "Target MySQL database name for --move-tables mode. If not provided, uses the same database name as the source connection")
198198
flag.BoolVar(&migrationContext.MoveTables.AllowOnSourcePrimary, "allow-on-source-primary", false, "allow --move-tables to read (schema, row copy, binlog) from the source cluster's primary. By default gh-ost stops if --host is the primary; prefer pointing --host at a replica to spare the primary the copy load.")
199199

200+
// unsafe fail points, for integration testing purposes
201+
flag.BoolVar(&migrationContext.UnsafeFailPointsEnabled, "unsafe-fail-points-enabled", false, "UNSAFE: Enable fail points for integration testing purposes. Do not use in production.")
202+
200203
flag.CommandLine.SetOutput(os.Stdout)
201204
flag.Parse()
202205
cutOverLockTimeoutUserSpecified := false

go/logic/migrator.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ 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"
2426
)
2527

2628
var (
@@ -2869,3 +2871,13 @@ func (mgtr *Migrator) teardown() {
28692871
mgtr.sourcePrimaryDB.Close()
28702872
}
28712873
}
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# Usage: localtests/test/sh [filter]
88
# By default, runs all move-tables tests. Given filter, will only run tests matching given regep
99

10+
set -x
11+
1012
repo_root=$(git rev-parse --show-toplevel)
1113
script_path="$repo_root/script/move-tables"
1214
tests_path=$(dirname $0)/move-tables
@@ -453,6 +455,26 @@ test_single() {
453455
done
454456
}
455457

458+
install_failpoint() {
459+
pushd $repo_root/../..
460+
461+
if [ ! -d "pingcap/failpoint" ]; then
462+
echo "⚙️ Installing failpoint"
463+
mkdir -p pingcap/failpoint
464+
git clone https://github.com/pingcap/failpoint.git pingcap/failpoint
465+
cd pingcap/failpoint
466+
make
467+
else
468+
bin/failpoint-ctl disable
469+
fi
470+
471+
echo "⚙️ Enabling failpoint"
472+
bin/failpoint-ctl enable
473+
474+
echo "✅ Successfully enabled failpoint"
475+
popd
476+
}
477+
456478
build_binary() {
457479
echo "Building"
458480
rm -f $default_ghost_binary
@@ -471,6 +493,7 @@ build_binary() {
471493
}
472494

473495
test_all() {
496+
install_failpoint
474497
build_binary
475498
test_dirs=$(find "$tests_path" -mindepth 1 -maxdepth 1 ! -path . -type d | grep "$test_pattern" | sort)
476499
while read -r test_dir; do

vendor/github.com/pingcap/failpoint/.codecov.yml

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pingcap/failpoint/.gitignore

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pingcap/failpoint/CONTRIBUTING.md

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)