-
Notifications
You must be signed in to change notification settings - Fork 6.2k
ddl: prevent partial ADD INDEX plans after transient TSO errors #69834
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -352,7 +352,7 @@ func generatePlanForPhysicalTable( | |
| return nil, errors.Trace(err) | ||
| } | ||
|
|
||
| subTaskMetas := make([][]byte, 0, 4) | ||
| var subTaskMetas [][]byte | ||
| backoffer := backoff.NewExponential(scanRegionBackoffBase, 2, scanRegionBackoffMax) | ||
| err = handle.RunWithRetry(ctx, 8, backoffer, logutil.DDLLogger(), func(_ context.Context) (bool, error) { | ||
| regionCache := store.(helper.Storage).GetRegionCache() | ||
|
|
@@ -364,7 +364,8 @@ func generatePlanForPhysicalTable( | |
| return bytes.Compare(recordRegionMetas[i].StartKey(), recordRegionMetas[j].StartKey()) < 0 | ||
| }) | ||
|
|
||
| // Check if regions are continuous. | ||
| // LoadRegionsInKeyRange can combine multiple PD scans. A concurrent region | ||
| // split or merge can make those scans discontinuous, so retry the full scan. | ||
| shouldRetry := false | ||
| cur := recordRegionMetas[0] | ||
| for _, m := range recordRegionMetas[1:] { | ||
|
|
@@ -374,11 +375,15 @@ func generatePlanForPhysicalTable( | |
| } | ||
| cur = m | ||
| } | ||
| failpoint.Inject("mockPhysicalTableRegionDiscontinuity", func() { | ||
| shouldRetry = true | ||
| }) | ||
|
|
||
| if shouldRetry { | ||
| return true, nil | ||
| return true, errors.New("regions are not continuous") | ||
| } | ||
|
|
||
| attemptMetas := make([][]byte, 0, 4) | ||
| regionBatch := CalculateRegionBatch(len(recordRegionMetas), nodeCnt, !useCloud) | ||
| logger.Info("calculate region batch", | ||
| zap.Int("totalRegionCnt", len(recordRegionMetas)), | ||
|
|
@@ -391,7 +396,7 @@ func generatePlanForPhysicalTable( | |
| // It should be different for each subtask to determine if there are duplicate entries. | ||
| importTS, err := allocNewTS(ctx, store.(kv.StorageWithPD)) | ||
| if err != nil { | ||
| return true, nil | ||
| return true, err | ||
| } | ||
| end := min(i+regionBatch, len(recordRegionMetas)) | ||
| batch := recordRegionMetas[i:end] | ||
|
|
@@ -411,8 +416,9 @@ func generatePlanForPhysicalTable( | |
| if err != nil { | ||
| return false, err | ||
| } | ||
| subTaskMetas = append(subTaskMetas, metaBytes) | ||
| attemptMetas = append(attemptMetas, metaBytes) | ||
| } | ||
| subTaskMetas = attemptMetas | ||
|
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. ℹ️ [Info] No invariant comment guards the per-attempt
|
||
| return false, nil | ||
| }) | ||
| if err != nil { | ||
|
|
@@ -537,6 +543,11 @@ func generateGlobalSortIngestPlan( | |
| } | ||
|
|
||
| func allocNewTS(ctx context.Context, store kv.StorageWithPD) (uint64, error) { | ||
| failpoint.Inject("mockAllocNewTSError", func(val failpoint.Value) { | ||
| if val.(bool) { | ||
| failpoint.Return(0, errors.New("mock alloc new TS error")) | ||
| } | ||
| }) | ||
| pdCli := store.GetPDClient() | ||
| p, l, err := pdCli.GetTS(ctx) | ||
| if err != nil { | ||
|
|
@@ -890,7 +901,7 @@ func genMergeTempPlanForOneIndex( | |
| pid := tbl.GetPhysicalID() | ||
| start, end := encodeTempIndexRange(pid, idxInfo.ID, idxInfo.ID) | ||
|
|
||
| subTaskMetas := make([][]byte, 0, 4) | ||
| var subTaskMetas [][]byte | ||
| backoffer := backoff.NewExponential(scanRegionBackoffBase, 2, scanRegionBackoffMax) | ||
| err := handle.RunWithRetry(ctx, 8, backoffer, logutil.DDLLogger(), func(_ context.Context) (bool, error) { | ||
| regionCache := store.(helper.Storage).GetRegionCache() | ||
|
|
@@ -902,7 +913,8 @@ func genMergeTempPlanForOneIndex( | |
| return bytes.Compare(regionMetas[i].StartKey(), regionMetas[j].StartKey()) < 0 | ||
| }) | ||
|
|
||
| // Check if regions are continuous. | ||
| // LoadRegionsInKeyRange can combine multiple PD scans. A concurrent region | ||
| // split or merge can make those scans discontinuous, so retry the full scan. | ||
| shouldRetry := false | ||
| cur := regionMetas[0] | ||
| for _, m := range regionMetas[1:] { | ||
|
|
@@ -912,11 +924,15 @@ func genMergeTempPlanForOneIndex( | |
| } | ||
| cur = m | ||
| } | ||
| failpoint.Inject("mockMergeTempIndexRegionDiscontinuity", func() { | ||
| shouldRetry = true | ||
| }) | ||
|
|
||
| if shouldRetry { | ||
| return true, nil | ||
| return true, errors.New("regions are not continuous") | ||
| } | ||
|
|
||
| attemptMetas := make([][]byte, 0, 4) | ||
| regionBatch := calculateTempIndexRegionBatch(len(regionMetas), nodeCnt) | ||
| logger.Info("calculate temp index region batch", | ||
| zap.Int64("physicalTableID", pid), | ||
|
|
@@ -945,8 +961,9 @@ func genMergeTempPlanForOneIndex( | |
| if err != nil { | ||
| return false, err | ||
| } | ||
| subTaskMetas = append(subTaskMetas, metaBytes) | ||
| attemptMetas = append(attemptMetas, metaBytes) | ||
| } | ||
| subTaskMetas = attemptMetas | ||
| return false, nil | ||
| }) | ||
| if err != nil { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.