Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into support-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
espresso98 committed May 18, 2022
2 parents cc4326a + eae2ae8 commit 657ca63
Show file tree
Hide file tree
Showing 28 changed files with 5,554 additions and 4,283 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ var defaultConf = Config{
TCPNoDelay: true,
CrossJoin: true,
StatsLease: "3s",
RunAutoAnalyze: true,
StmtCountLimit: 5000,
FeedbackProbability: 0.0,
QueryFeedbackLimit: 512,
Expand Down Expand Up @@ -957,6 +956,8 @@ var deprecatedConfig = map[string]struct{}{
"log.query-log-max-len": {},
"performance.committer-concurrency": {},
"experimental.enable-global-kill": {},
"performance.run-auto-analyze": {}, //use tidb_enable_auto_analyze

}

func isAllDeprecatedConfigItems(items []string) bool {
Expand Down
3 changes: 0 additions & 3 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ cross-join = true
# Stats lease duration, which influences the time of analyze and stats load.
stats-lease = "3s"

# Run auto analyze worker on this tidb-server.
run-auto-analyze = true

# Probability to use the query feedback to update stats, 0.0 or 1.0 for always false/true.
feedback-probability = 0.0

Expand Down
15 changes: 2 additions & 13 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,9 +1292,6 @@ func (do *Domain) SetStatsUpdating(val bool) {
}
}

// RunAutoAnalyze indicates if this TiDB server starts auto analyze worker and can run auto analyze job.
var RunAutoAnalyze = true

// LoadAndUpdateStatsLoop loads and updates stats info.
func (do *Domain) LoadAndUpdateStatsLoop(ctxs []sessionctx.Context) error {
if err := do.UpdateTableStatsLoop(ctxs[0]); err != nil {
Expand Down Expand Up @@ -1329,9 +1326,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx sessionctx.Context) error {
}
do.SetStatsUpdating(true)
do.wg.Run(func() { do.updateStatsWorker(ctx, owner) })
if RunAutoAnalyze {
do.wg.Run(func() { do.autoAnalyzeWorker(owner) })
}
do.wg.Run(func() { do.autoAnalyzeWorker(owner) })
do.wg.Run(func() { do.gcAnalyzeHistory(owner) })
return nil
}
Expand Down Expand Up @@ -1510,7 +1505,7 @@ func (do *Domain) autoAnalyzeWorker(owner owner.Manager) {
for {
select {
case <-analyzeTicker.C:
if owner.IsOwner() {
if variable.RunAutoAnalyze.Load() && owner.IsOwner() {
statsHandle.HandleAutoAnalyze(do.InfoSchema())
}
case <-do.exit:
Expand Down Expand Up @@ -1836,12 +1831,6 @@ func (do *Domain) serverIDKeeper() {
}
}

// MockInfoCacheAndLoadInfoSchema only used in unit test
func (do *Domain) MockInfoCacheAndLoadInfoSchema(is infoschema.InfoSchema) {
do.infoCache = infoschema.NewCache(16)
do.infoCache.Insert(is, 0)
}

func init() {
initByLDFlagsForGlobalKill()
telemetry.GetDomainInfoSchema = func(ctx sessionctx.Context) infoschema.InfoSchema {
Expand Down
50 changes: 50 additions & 0 deletions domain/test_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package domain

import (
"testing"

"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/parser/model"
"github.com/stretchr/testify/require"
)

// This file contains utilities for easier testing.

// MockInfoCacheAndLoadInfoSchema only used in unit tests.
func (do *Domain) MockInfoCacheAndLoadInfoSchema(is infoschema.InfoSchema) {
do.infoCache = infoschema.NewCache(16)
do.infoCache.Insert(is, 0)
}

// MustGetTableInfo returns the table info. Only used in unit tests.
func (do *Domain) MustGetTableInfo(t *testing.T, dbName, tableName string) *model.TableInfo {
tbl, err := do.InfoSchema().TableByName(model.NewCIStr(dbName), model.NewCIStr(tableName))
require.Nil(t, err)
return tbl.Meta()
}

// MustGetTableID returns the table ID. Only used in unit tests.
func (do *Domain) MustGetTableID(t *testing.T, dbName, tableName string) int64 {
ti := do.MustGetTableInfo(t, dbName, tableName)
return ti.ID
}

// MustGetPartitionAt returns the partition ID. Only used in unit tests.
func (do *Domain) MustGetPartitionAt(t *testing.T, dbName, tableName string, idx int) int64 {
ti := do.MustGetTableInfo(t, dbName, tableName)
return ti.Partition.Definitions[idx].ID
}
23 changes: 23 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/timeutil"
"github.com/pingcap/tipb/go-tipb"
"github.com/tikv/client-go/v2/tikv"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -312,6 +313,8 @@ func (b *executorBuilder) build(p plannercore.Plan) Executor {
return b.buildCTE(v)
case *plannercore.PhysicalCTETable:
return b.buildCTETableReader(v)
case *plannercore.CompactTable:
return b.buildCompactTable(v)
default:
if mp, ok := p.(MockPhysicalPlan); ok {
return mp.GetExecutor()
Expand Down Expand Up @@ -5006,3 +5009,23 @@ func (b *executorBuilder) getCacheTable(tblInfo *model.TableInfo, startTS uint64
}
return nil
}

func (b *executorBuilder) buildCompactTable(v *plannercore.CompactTable) Executor {
if v.ReplicaKind != ast.CompactReplicaKindTiFlash {
b.err = errors.Errorf("compact %v replica is not supported", strings.ToLower(string(v.ReplicaKind)))
return nil
}

store := b.ctx.GetStore()
tikvStore, ok := store.(tikv.Storage)
if !ok {
b.err = errors.New("compact tiflash replica can only run with tikv compatible storage")
return nil
}

return &CompactTableTiFlashExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ID()),
tableInfo: v.TableInfo,
tikvStore: tikvStore,
}
}
Loading

0 comments on commit 657ca63

Please sign in to comment.