()
| 519 | } |
| 520 | |
| 521 | func (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 |
| 551 | ERROR_MSG="$GH_OST_LAST_BATCH_COPY_ERROR" |
| 552 | SOCKET_PATH="/tmp/gh-ost.sock" |
| 553 | |
| 554 | if ! [[ "$ERROR_MSG" =~ "max_binlog_cache_size" ]]; then |
| 555 | echo "Nothing to do for error: $ERROR_MSG" |
| 556 | exit 0 |
| 557 | fi |
| 558 | |
| 559 | CHUNK_SIZE=$(echo "chunk-size=?" | nc -U $SOCKET_PATH | tr -d '\n') |
| 560 | |
| 561 | MIN_CHUNK_SIZE=10 |
| 562 | NEW_CHUNK_SIZE=$(( CHUNK_SIZE * 8 / 10 )) |
| 563 | if [ $NEW_CHUNK_SIZE -lt $MIN_CHUNK_SIZE ]; then |
| 564 | NEW_CHUNK_SIZE=$MIN_CHUNK_SIZE |
| 565 | fi |
| 566 | |
| 567 | if [ $CHUNK_SIZE -eq $NEW_CHUNK_SIZE ]; then |
| 568 | echo "Chunk size unchanged: $CHUNK_SIZE" |
| 569 | exit 0 |
| 570 | fi |
| 571 | |
| 572 | echo "[gh-ost-on-batch-copy-retry]: Changing chunk size from $CHUNK_SIZE to $NEW_CHUNK_SIZE" |
| 573 | echo "chunk-size=$NEW_CHUNK_SIZE" | nc -U $SOCKET_PATH |
| 574 | echo "[gh-ost-on-batch-copy-retry]: Done, exiting..." |
| 575 | ` |
| 576 | err = os.WriteFile(hookScript, []byte(hookContent), 0755) |
| 577 | suite.Require().NoError(err) |
| 578 |
nothing calls this directly
no test coverage detected