@@ -28,12 +28,14 @@ import (
28
28
"github.com/pingcap/tidb/pkg/errctx"
29
29
"github.com/pingcap/tidb/pkg/kv"
30
30
"github.com/pingcap/tidb/pkg/meta/model"
31
+ "github.com/pingcap/tidb/pkg/resourcegroup"
31
32
"github.com/pingcap/tidb/pkg/sessionctx"
32
33
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
33
34
"github.com/pingcap/tidb/pkg/sessionctx/variable"
34
35
"github.com/pingcap/tidb/pkg/table"
35
36
contextutil "github.com/pingcap/tidb/pkg/util/context"
36
37
"github.com/pingcap/tidb/pkg/util/execdetails"
38
+ "github.com/pingcap/tidb/pkg/util/intest"
37
39
"github.com/pingcap/tidb/pkg/util/memory"
38
40
"github.com/pingcap/tidb/pkg/util/mock"
39
41
decoder "github.com/pingcap/tidb/pkg/util/rowDecoder"
@@ -125,30 +127,34 @@ func NewReorgCopContext(
125
127
allIdxInfo []* model.IndexInfo ,
126
128
requestSource string ,
127
129
) (copr.CopContext , error ) {
128
- sessCtx , err := newSessCtx (store , reorgMeta )
130
+ warnHandler := contextutil .NewStaticWarnHandler (0 )
131
+ distSQLCtx , err := newReorgDistSQLCtxWithReorgMeta (store .GetClient (), reorgMeta , warnHandler )
132
+ if err != nil {
133
+ return nil , err
134
+ }
135
+
136
+ exprCtx , err := newReorgExprCtxWithReorgMeta (reorgMeta , warnHandler )
129
137
if err != nil {
130
138
return nil , err
131
139
}
140
+
141
+ evalCtx := exprCtx .GetEvalCtx ()
142
+ tc , ec := evalCtx .TypeCtx (), evalCtx .ErrCtx ()
143
+ pushDownFlags := stmtctx .PushDownFlagsWithTypeFlagsAndErrLevels (tc .Flags (), ec .LevelMap ())
144
+
132
145
return copr .NewCopContext (
133
- sessCtx . GetExprCtx () ,
134
- sessCtx . GetDistSQLCtx () ,
135
- sessCtx . GetSessionVars (). StmtCtx . PushDownFlags () ,
146
+ exprCtx ,
147
+ distSQLCtx ,
148
+ pushDownFlags ,
136
149
tblInfo ,
137
150
allIdxInfo ,
138
151
requestSource ,
139
152
)
140
153
}
141
154
142
- func newSessCtx (store kv.Storage , reorgMeta * model.DDLReorgMeta ) (sessionctx.Context , error ) {
143
- sessCtx := newReorgSessCtx (store )
144
- if err := initSessCtx (sessCtx , reorgMeta ); err != nil {
145
- return nil , errors .Trace (err )
146
- }
147
- return sessCtx , nil
148
- }
149
-
150
- func newDefaultReorgDistSQLCtx (kvClient kv.Client ) * distsqlctx.DistSQLContext {
151
- warnHandler := contextutil .NewStaticWarnHandler (0 )
155
+ func newDefaultReorgDistSQLCtx (kvClient kv.Client , warnHandler contextutil.WarnAppender ) * distsqlctx.DistSQLContext {
156
+ intest .AssertNotNil (kvClient )
157
+ intest .AssertNotNil (warnHandler )
152
158
var sqlKiller sqlkiller.SQLKiller
153
159
var execDetails execdetails.SyncExecDetails
154
160
return & distsqlctx.DistSQLContext {
@@ -168,10 +174,23 @@ func newDefaultReorgDistSQLCtx(kvClient kv.Client) *distsqlctx.DistSQLContext {
168
174
TiFlashMaxBytesBeforeExternalSort : variable .DefTiFlashMaxBytesBeforeExternalSort ,
169
175
TiFlashMaxQueryMemoryPerNode : variable .DefTiFlashMemQuotaQueryPerNode ,
170
176
TiFlashQuerySpillRatio : variable .DefTiFlashQuerySpillRatio ,
177
+ ResourceGroupName : resourcegroup .DefaultResourceGroupName ,
171
178
ExecDetails : & execDetails ,
172
179
}
173
180
}
174
181
182
+ func newReorgDistSQLCtxWithReorgMeta (kvClient kv.Client , reorgMeta * model.DDLReorgMeta , warnHandler contextutil.WarnAppender ) (* distsqlctx.DistSQLContext , error ) {
183
+ loc , err := reorgTimeZoneWithTzLoc (reorgMeta .Location )
184
+ if err != nil {
185
+ return nil , errors .Trace (err )
186
+ }
187
+ ctx := newDefaultReorgDistSQLCtx (kvClient , warnHandler )
188
+ ctx .Location = loc
189
+ ctx .ErrCtx = errctx .NewContextWithLevels (reorgErrLevelsWithSQLMode (reorgMeta .SQLMode ), ctx .WarnHandler )
190
+ ctx .ResourceGroupName = reorgMeta .ResourceGroupName
191
+ return ctx , nil
192
+ }
193
+
175
194
// initSessCtx initializes the session context. Be careful to the timezone.
176
195
func initSessCtx (sessCtx sessionctx.Context , reorgMeta * model.DDLReorgMeta ) error {
177
196
// Correct the initial timezone.
0 commit comments