Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
D3Hunter committed Sep 19, 2023
1 parent c7202f7 commit 8b59ff8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 3 additions & 8 deletions executor/importer/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (e *LoadDataController) checkFieldParams() error {
return nil
}

func (p *Plan) initDefaultOptions(cloudStorageURI string) {
func (p *Plan) initDefaultOptions() {
threadCnt := runtime.GOMAXPROCS(0)
failpoint.Inject("mockNumCpu", func(val failpoint.Value) {
threadCnt = val.(int)
Expand All @@ -503,19 +503,14 @@ func (p *Plan) initDefaultOptions(cloudStorageURI string) {
p.Detached = false
p.DisableTiKVImportMode = false
p.MaxEngineSize = config.ByteSize(defaultMaxEngineSize)
p.CloudStorageURI = cloudStorageURI
p.CloudStorageURI = variable.CloudStorageURI.Load()

v := "utf8mb4"
p.Charset = &v
}

func (p *Plan) initOptions(seCtx sessionctx.Context, options []*plannercore.LoadDataOpt) error {
cloudStorageURI, err1 := seCtx.GetSessionVars().GlobalVarsAccessor.
GetGlobalSysVar(variable.TiDBCloudStorageURI)
if err1 != nil {
return errors.Trace(err1)
}
p.initDefaultOptions(cloudStorageURI)
p.initDefaultOptions()

specifiedOptions := map[string]*plannercore.LoadDataOpt{}
for _, opt := range options {
Expand Down
13 changes: 10 additions & 3 deletions executor/importer/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import (
func TestInitDefaultOptions(t *testing.T) {
plan := &Plan{}
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/importer/mockNumCpu", "return(1)"))
plan.initDefaultOptions("s3://bucket/path")
variable.CloudStorageURI.Store("s3://bucket/path")
t.Cleanup(func() {
variable.CloudStorageURI.Store("")
})
plan.initDefaultOptions()
require.Equal(t, config.ByteSize(0), plan.DiskQuota)
require.Equal(t, config.OpLevelRequired, plan.Checksum)
require.Equal(t, int64(1), plan.ThreadCnt)
Expand All @@ -55,7 +59,7 @@ func TestInitDefaultOptions(t *testing.T) {
require.Equal(t, "s3://bucket/path", plan.CloudStorageURI)

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/importer/mockNumCpu", "return(10)"))
plan.initDefaultOptions("")
plan.initDefaultOptions()
require.Equal(t, int64(5), plan.ThreadCnt)
}

Expand Down Expand Up @@ -121,7 +125,10 @@ func TestInitOptionsPositiveCase(t *testing.T) {
require.Empty(t, plan.CloudStorageURI, sql)

// set cloud storage uri
require.NoError(t, ctx.SetGlobalSysVar(ctx, variable.TiDBCloudStorageURI, "s3://bucket/path"))
variable.CloudStorageURI.Store("s3://bucket/path")
t.Cleanup(func() {
variable.CloudStorageURI.Store("")
})
plan = &Plan{Format: DataFormatCSV}
err = plan.initOptions(ctx, convertOptions(stmt.(*ast.ImportIntoStmt).Options))
require.NoError(t, err, sql)
Expand Down

0 comments on commit 8b59ff8

Please sign in to comment.