Skip to content

Commit edd6080

Browse files
authored
ddl: do not switch to import mode during adding index (#48083) (#48460)
close #48259
1 parent 4bddd59 commit edd6080

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

pkg/ddl/ddl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func (d *ddl) Start(ctxPool *pools.ResourcePool) error {
810810
}
811811
defer d.sessPool.Put(ctx)
812812

813-
ingest.InitGlobalLightningEnv(d.ctx, ctx)
813+
ingest.InitGlobalLightningEnv()
814814

815815
return nil
816816
}

pkg/ddl/ingest/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ go_library(
4040
"//pkg/util/dbterror",
4141
"//pkg/util/generic",
4242
"//pkg/util/logutil",
43+
"//pkg/util/memory",
4344
"//pkg/util/size",
4445
"@com_github_google_uuid//:uuid",
4546
"@com_github_pingcap_errors//:errors",

pkg/ddl/ingest/backend_mgr.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323

2424
"github.com/pingcap/tidb/br/pkg/lightning/backend/local"
2525
"github.com/pingcap/tidb/br/pkg/lightning/config"
26-
"github.com/pingcap/tidb/pkg/ddl/util"
27-
"github.com/pingcap/tidb/pkg/sessionctx"
2826
"github.com/pingcap/tidb/pkg/util/generic"
2927
"github.com/pingcap/tidb/pkg/util/logutil"
3028
kvutil "github.com/tikv/client-go/v2/util"
@@ -42,12 +40,11 @@ type BackendCtxMgr interface {
4240

4341
type litBackendCtxMgr struct {
4442
generic.SyncMap[int64, *litBackendCtx]
45-
memRoot MemRoot
46-
diskRoot DiskRoot
47-
isRaftKV2 bool
43+
memRoot MemRoot
44+
diskRoot DiskRoot
4845
}
4946

50-
func newLitBackendCtxMgr(ctx context.Context, sctx sessionctx.Context, path string, memQuota uint64) BackendCtxMgr {
47+
func newLitBackendCtxMgr(path string, memQuota uint64) BackendCtxMgr {
5148
mgr := &litBackendCtxMgr{
5249
SyncMap: generic.NewSyncMap[int64, *litBackendCtx](10),
5350
memRoot: nil,
@@ -62,11 +59,6 @@ func newLitBackendCtxMgr(ctx context.Context, sctx sessionctx.Context, path stri
6259
if err != nil {
6360
logutil.BgLogger().Warn("ingest backfill may not be available", zap.String("category", "ddl-ingest"), zap.Error(err))
6461
}
65-
isRaftKV2, err := util.IsRaftKv2(ctx, sctx)
66-
if err != nil {
67-
logutil.BgLogger().Warn("failed to get 'storage.engine'", zap.String("category", "ddl-ingest"), zap.Error(err))
68-
}
69-
mgr.isRaftKV2 = isRaftKV2
7062
return mgr
7163
}
7264

@@ -95,7 +87,7 @@ func (m *litBackendCtxMgr) Register(ctx context.Context, unique bool, jobID int6
9587
if !ok {
9688
return nil, genBackendAllocMemFailedErr(ctx, m.memRoot, jobID)
9789
}
98-
cfg, err := genConfig(ctx, m.memRoot, jobID, unique, m.isRaftKV2)
90+
cfg, err := genConfig(ctx, m.memRoot, jobID, unique)
9991
if err != nil {
10092
logutil.Logger(ctx).Warn(LitWarnConfigError, zap.Int64("job ID", jobID), zap.Error(err))
10193
return nil, err
@@ -130,10 +122,9 @@ func createLocalBackend(ctx context.Context, cfg *Config, resourceGroupName stri
130122
regionSizeGetter := &local.TableRegionSizeGetterImpl{
131123
DB: nil,
132124
}
125+
// We disable the switch TiKV mode feature for now,
126+
// because the impact is not fully tested.
133127
var raftKV2SwitchModeDuration time.Duration
134-
if cfg.IsRaftKV2 {
135-
raftKV2SwitchModeDuration = config.DefaultSwitchTiKVModeInterval
136-
}
137128
backendConfig := local.NewBackendConfig(cfg.Lightning, int(LitRLimit), cfg.KeyspaceName, resourceGroupName, kvutil.ExplicitTypeDDL, raftKV2SwitchModeDuration)
138129
return local.NewBackend(ctx, tls, backendConfig, regionSizeGetter)
139130
}

pkg/ddl/ingest/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Config struct {
3939
IsRaftKV2 bool
4040
}
4141

42-
func genConfig(ctx context.Context, memRoot MemRoot, jobID int64, unique bool, isRaftKV2 bool) (*Config, error) {
42+
func genConfig(ctx context.Context, memRoot MemRoot, jobID int64, unique bool) (*Config, error) {
4343
tidbCfg := tidb.GetGlobalConfig()
4444
cfg := lightning.NewConfig()
4545
cfg.TikvImporter.Backend = lightning.BackendLocal
@@ -75,7 +75,7 @@ func genConfig(ctx context.Context, memRoot MemRoot, jobID int64, unique bool, i
7575
c := &Config{
7676
Lightning: cfg,
7777
KeyspaceName: tidb.GetGlobalKeyspaceName(),
78-
IsRaftKV2: isRaftKV2,
78+
IsRaftKV2: false,
7979
}
8080

8181
return c, err

pkg/ddl/ingest/env.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
package ingest
1616

1717
import (
18-
"context"
1918
"os"
2019
"path/filepath"
2120
"strconv"
2221

2322
"github.com/pingcap/tidb/br/pkg/lightning/log"
2423
"github.com/pingcap/tidb/pkg/config"
25-
"github.com/pingcap/tidb/pkg/sessionctx"
2624
"github.com/pingcap/tidb/pkg/util"
2725
"github.com/pingcap/tidb/pkg/util/logutil"
26+
"github.com/pingcap/tidb/pkg/util/memory"
2827
"github.com/pingcap/tidb/pkg/util/size"
2928
"go.uber.org/zap"
3029
)
@@ -44,10 +43,10 @@ var (
4443
LitInitialized bool
4544
)
4645

47-
const maxMemoryQuota = 2 * size.GB
46+
const defaultMemoryQuota = 2 * size.GB
4847

4948
// InitGlobalLightningEnv initialize Lightning backfill environment.
50-
func InitGlobalLightningEnv(ctx context.Context, sctx sessionctx.Context) {
49+
func InitGlobalLightningEnv() {
5150
log.SetAppLogger(logutil.BgLogger())
5251
globalCfg := config.GetGlobalConfig()
5352
if globalCfg.Store != "tikv" {
@@ -66,12 +65,19 @@ func InitGlobalLightningEnv(ctx context.Context, sctx sessionctx.Context) {
6665
return
6766
}
6867
LitSortPath = sPath
69-
LitBackCtxMgr = newLitBackendCtxMgr(ctx, sctx, LitSortPath, maxMemoryQuota)
68+
memTotal, err := memory.MemTotal()
69+
if err != nil {
70+
logutil.BgLogger().Warn("get total memory fail", zap.Error(err))
71+
memTotal = defaultMemoryQuota
72+
} else {
73+
memTotal = memTotal / 2
74+
}
75+
LitBackCtxMgr = newLitBackendCtxMgr(LitSortPath, memTotal)
7076
LitRLimit = util.GenRLimit("ddl-ingest")
7177
LitInitialized = true
7278
logutil.BgLogger().Info(LitInfoEnvInitSucc,
7379
zap.String("category", "ddl-ingest"),
74-
zap.Uint64("memory limitation", maxMemoryQuota),
80+
zap.Uint64("memory limitation", memTotal),
7581
zap.String("disk usage info", LitDiskRoot.UsageInfo()),
7682
zap.Uint64("max open file number", LitRLimit),
7783
zap.Bool("lightning is initialized", LitInitialized))

pkg/ddl/util/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func WrapKey2String(key []byte) string {
328328
}
329329

330330
const (
331-
getRaftKvVersionSQL = "show config where type = 'tikv' and name = 'storage.engine'"
331+
getRaftKvVersionSQL = "select `value` from information_schema.cluster_config where type = 'tikv' and `key` = 'storage.engine'"
332332
raftKv2 = "raft-kv2"
333333
)
334334

@@ -359,6 +359,6 @@ func IsRaftKv2(ctx context.Context, sctx sessionctx.Context) (bool, error) {
359359
}
360360

361361
// All nodes should have the same type of engine
362-
raftVersion := rows[0].GetString(3)
362+
raftVersion := rows[0].GetString(0)
363363
return raftVersion == raftKv2, nil
364364
}

0 commit comments

Comments
 (0)