Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic Transactions handling with Online DDL #16585

Merged
merged 14 commits into from
Aug 28, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ type Executor struct {
ts *topo.Server
lagThrottler *throttle.Throttler
toggleBufferTableFunc func(cancelCtx context.Context, tableName string, timeout time.Duration, bufferQueries bool)
IsPreparedPoolEmpty func(tableName string) bool
isPreparedPoolEmpty func(tableName string) bool
requestGCChecksFunc func()
tabletAlias *topodatapb.TabletAlias

Expand Down Expand Up @@ -257,7 +257,7 @@ func NewExecutor(env tabletenv.Env, tabletAlias *topodatapb.TabletAlias, ts *top
ts: ts,
lagThrottler: lagThrottler,
toggleBufferTableFunc: toggleBufferTableFunc,
IsPreparedPoolEmpty: isPreparedPoolEmpty,
isPreparedPoolEmpty: isPreparedPoolEmpty,
requestGCChecksFunc: requestGCChecksFunc,
ticks: timer.NewTimer(migrationCheckInterval),
// Gracefully return an error if any caller tries to execute
Expand Down Expand Up @@ -1110,7 +1110,7 @@ func (e *Executor) cutOverVReplMigration(ctx context.Context, s *VReplStream, sh
if shouldForceCutOver {
// We should only proceed with forceful cut over if there is no pending atomic transaction for the table.
// This will help in keeping the atomicity guarantee of a prepared transaction.
if err := e.checkOnPreparedPool(onlineDDL.Table, 100*time.Millisecond, 1); err != nil {
if err := e.checkOnPreparedPool(ctx, onlineDDL.Table, 100*time.Millisecond); err != nil {
return err
}
if err := e.killTableLockHoldersAndAccessors(ctx, onlineDDL.Table); err != nil {
Expand Down Expand Up @@ -5356,14 +5356,19 @@ func (e *Executor) OnSchemaMigrationStatus(ctx context.Context,
return e.onSchemaMigrationStatus(ctx, uuidParam, status, dryRun, progressPct, etaSeconds, rowsCopied, hint)
}

func (e *Executor) checkOnPreparedPool(table string, waitTime time.Duration, retries int) error {
for i := 0; i <= retries; i++ {
if e.IsPreparedPoolEmpty(table) {
func (e *Executor) checkOnPreparedPool(ctx context.Context, table string, waitTime time.Duration) error {
if e.isPreparedPoolEmpty(table) {
return nil
}

select {
case <-ctx.Done():
// Return context error if context is done
return ctx.Err()
case <-time.After(waitTime):
if e.isPreparedPoolEmpty(table) {
return nil
}
if i < retries {
time.Sleep(waitTime)
}
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "cannot force cut-over on non-empty prepared pool for table: %s", table)
harshit-gangal marked this conversation as resolved.
Show resolved Hide resolved
}
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "cannot force cut-over on non-empty prepared pool for table: %s", table)
}
Loading