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

Method TestRetryBatchCopyWithHooks

go/logic/migrator_test.go:521–639  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

519}
520
521func (suite *MigratorTestSuite) TestRetryBatchCopyWithHooks() {
522 ctx := context.Background()
523
524 _, err := suite.db.ExecContext(ctx, "CREATE TABLE test.test_retry_batch (id INT PRIMARY KEY AUTO_INCREMENT, name TEXT)")
525 suite.Require().NoError(err)
526
527 const initStride = 1000
528 const totalBatches = 3
529 for i := 0; i < totalBatches; i++ {
530 dataSize := 50 * i
531 for j := 0; j < initStride; j++ {
532 _, err = suite.db.ExecContext(ctx, fmt.Sprintf("INSERT INTO test.test_retry_batch (name) VALUES ('%s')", strings.Repeat("a", dataSize)))
533 suite.Require().NoError(err)
534 }
535 }
536
537 _, err = suite.db.ExecContext(ctx, fmt.Sprintf("SET GLOBAL max_binlog_cache_size = %d", 1024*8))
538 suite.Require().NoError(err)
539 defer func() {
540 _, err = suite.db.ExecContext(ctx, fmt.Sprintf("SET GLOBAL max_binlog_cache_size = %d", 1024*1024*1024))
541 suite.Require().NoError(err)
542 }()
543
544 tmpDir, err := os.MkdirTemp("", "gh-ost-hooks")
545 suite.Require().NoError(err)
546 defer os.RemoveAll(tmpDir)
547
548 hookScript := filepath.Join(tmpDir, "gh-ost-on-batch-copy-retry")
549 hookContent := `#!/bin/bash
550# Mock hook that reduces chunk size on binlog cache error
551ERROR_MSG="$GH_OST_LAST_BATCH_COPY_ERROR"
552SOCKET_PATH="/tmp/gh-ost.sock"
553
554if ! [[ "$ERROR_MSG" =~ "max_binlog_cache_size" ]]; then
555 echo "Nothing to do for error: $ERROR_MSG"
556 exit 0
557fi
558
559CHUNK_SIZE=$(echo "chunk-size=?" | nc -U $SOCKET_PATH | tr -d '\n')
560
561MIN_CHUNK_SIZE=10
562NEW_CHUNK_SIZE=$(( CHUNK_SIZE * 8 / 10 ))
563if [ $NEW_CHUNK_SIZE -lt $MIN_CHUNK_SIZE ]; then
564 NEW_CHUNK_SIZE=$MIN_CHUNK_SIZE
565fi
566
567if [ $CHUNK_SIZE -eq $NEW_CHUNK_SIZE ]; then
568 echo "Chunk size unchanged: $CHUNK_SIZE"
569 exit 0
570fi
571
572echo "[gh-ost-on-batch-copy-retry]: Changing chunk size from $CHUNK_SIZE to $NEW_CHUNK_SIZE"
573echo "chunk-size=$NEW_CHUNK_SIZE" | nc -U $SOCKET_PATH
574echo "[gh-ost-on-batch-copy-retry]: Done, exiting..."
575`
576 err = os.WriteFile(hookScript, []byte(hookContent), 0755)
577 suite.Require().NoError(err)
578

Callers

nothing calls this directly

Calls 8

SetConnectionConfigMethod · 0.95
SetDefaultNumRetriesMethod · 0.95
MigrateMethod · 0.95
NewMigrationContextFunction · 0.92
getTestConnectionConfigFunction · 0.85
NewMigratorFunction · 0.85
StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected