-
Notifications
You must be signed in to change notification settings - Fork 2.3k
vttablet: wait on _vt.dt_state in WaitForPreparedTwoPCTransactions #20060
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
base: main
Are you sure you want to change the base?
Changes from all commits
24171b0
d253725
2740118
b932cda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -771,20 +771,43 @@ func (tsv *TabletServer) RollbackPrepared(ctx context.Context, target *querypb.T | |
| ) | ||
| } | ||
|
|
||
| // WaitForPreparedTwoPCTransactions waits for all the prepared transactions to complete. | ||
| // hasUnresolvedTwoPCTransactions checks if this tablet has any unresolved 2PC transactions. | ||
| func (tsv *TabletServer) hasUnresolvedTwoPCTransactions(ctx context.Context) (bool, error) { | ||
| if !tsv.te.preparedPool.IsEmpty() { | ||
| return true, nil | ||
| } | ||
| if !tsv.te.twopcEnabled { | ||
| return false, nil | ||
| } | ||
| count, err := tsv.te.twoPC.CountUnresolvedTransaction(ctx, time.Now().Add(365*24*time.Hour)) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return count > 0, nil | ||
|
Comment on lines
+782
to
+786
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should make the time as configurable.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we return |
||
| } | ||
|
|
||
| // WaitForPreparedTwoPCTransactions waits for all unresolved 2PC transactions on this tablet to be resolved. | ||
| func (tsv *TabletServer) WaitForPreparedTwoPCTransactions(ctx context.Context) error { | ||
| if tsv.te.preparedPool.IsEmpty() { | ||
| hasUnresolved, lastErr := tsv.hasUnresolvedTwoPCTransactions(ctx) | ||
| if lastErr == nil && !hasUnresolved { | ||
| return nil | ||
| } | ||
| ticker := time.NewTicker(100 * time.Millisecond) | ||
| defer ticker.Stop() | ||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| if lastErr != nil { | ||
| log.Error(fmt.Sprintf("Error reading unresolved transactions during wait: %v", lastErr)) | ||
| } | ||
| // Return an error if we run out of time. | ||
| return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "Prepared transactions have not been resolved yet") | ||
| case <-ticker.C: | ||
| if tsv.te.preparedPool.IsEmpty() { | ||
| var err error | ||
| hasUnresolved, err = tsv.hasUnresolvedTwoPCTransactions(ctx) | ||
| if err != nil { | ||
| lastErr = err | ||
| } else if !hasUnresolved { | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the message in the e2e test since it's a misleading message. If it's better to keep the misleading message for backwards compatibility I can flip to that direction instead.