Skip to content

Commit 5faeca4

Browse files
authored
*: use golang built-in functions rather than mathutil (#56818)
close #56594
1 parent a4d4582 commit 5faeca4

37 files changed

+64
-140
lines changed

br/cmd/br/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ go_library(
3737
"//pkg/util",
3838
"//pkg/util/gctuner",
3939
"//pkg/util/logutil",
40-
"//pkg/util/mathutil",
4140
"//pkg/util/memory",
4241
"//pkg/util/metricsutil",
4342
"//pkg/util/redact",

br/cmd/br/cmd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/pingcap/tidb/pkg/config"
2424
tidbutils "github.com/pingcap/tidb/pkg/util"
2525
"github.com/pingcap/tidb/pkg/util/logutil"
26-
"github.com/pingcap/tidb/pkg/util/mathutil"
2726
"github.com/pingcap/tidb/pkg/util/memory"
2827
"github.com/pingcap/tidb/pkg/util/redact"
2928
"github.com/pingcap/tidb/pkg/util/size"
@@ -205,7 +204,7 @@ func Init(cmd *cobra.Command) (err error) {
205204
memlimit := calculateMemoryLimit(memleft)
206205
// BR command needs 256 MiB at least, if the left memory is less than 256 MiB,
207206
// the memory limit cannot limit anyway and then finally OOM.
208-
memlimit = mathutil.Max(memlimit, quarterGiB)
207+
memlimit = max(memlimit, quarterGiB)
209208
log.Info("calculate the rest memory",
210209
zap.Uint64("memtotal", memtotal), zap.Uint64("memused", memused), zap.Uint64("memlimit", memlimit))
211210
// No need to set memory limit because the left memory is sufficient.

br/pkg/stream/stream_metas.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func MergeMigrations(m1 *pb.Migration, m2 *pb.Migration) *pb.Migration {
521521
out.EditMeta = mergeMetaEdits(m1.GetEditMeta(), m2.GetEditMeta())
522522
out.Compactions = append(out.Compactions, m1.GetCompactions()...)
523523
out.Compactions = append(out.Compactions, m2.GetCompactions()...)
524-
out.TruncatedTo = mathutil.Max(m1.GetTruncatedTo(), m2.GetTruncatedTo())
524+
out.TruncatedTo = max(m1.GetTruncatedTo(), m2.GetTruncatedTo())
525525
out.DestructPrefix = append(out.DestructPrefix, m1.GetDestructPrefix()...)
526526
out.DestructPrefix = append(out.DestructPrefix, m2.GetDestructPrefix()...)
527527
return out
@@ -583,7 +583,7 @@ func (m MigrationExt) Load(ctx context.Context) (Migrations, error) {
583583
if err != nil {
584584
return errors.Annotate(err, "failed to get the truncate safepoint for base migration")
585585
}
586-
t.Content.TruncatedTo = mathutil.Max(truncatedTs, t.Content.TruncatedTo)
586+
t.Content.TruncatedTo = max(truncatedTs, t.Content.TruncatedTo)
587587
}
588588
return t.Content.Unmarshal(b)
589589
})

cmd/importer/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ go_library(
2626
"//pkg/statistics/handle/storage",
2727
"//pkg/statistics/handle/util",
2828
"//pkg/types",
29-
"//pkg/util/mathutil",
3029
"@com_github_burntsushi_toml//:toml",
3130
"@com_github_go_sql_driver_mysql//:mysql",
3231
"@com_github_pingcap_errors//:errors",

cmd/importer/data.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"math/rand"
2020
"sync"
2121
"time"
22-
23-
"github.com/pingcap/tidb/pkg/util/mathutil"
2422
)
2523

2624
type datum struct {
@@ -75,8 +73,8 @@ func (d *datum) nextInt64() int64 {
7573
defer d.Unlock()
7674

7775
if d.useRange {
78-
d.intValue = mathutil.Min(d.intValue, d.maxIntValue)
79-
d.intValue = mathutil.Max(d.intValue, d.minIntValue)
76+
d.intValue = min(d.intValue, d.maxIntValue)
77+
d.intValue = max(d.intValue, d.minIntValue)
8078
}
8179
d.updateRemains()
8280
return d.intValue

pkg/autoid_service/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ go_library(
1616
"//pkg/owner",
1717
"//pkg/util/etcd",
1818
"//pkg/util/logutil",
19-
"//pkg/util/mathutil",
2019
"@com_github_pingcap_errors//:errors",
2120
"@com_github_pingcap_failpoint//:failpoint",
2221
"@com_github_pingcap_kvproto//pkg/autoid",

pkg/autoid_service/autoid.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/pingcap/tidb/pkg/owner"
3535
"github.com/pingcap/tidb/pkg/util/etcd"
3636
"github.com/pingcap/tidb/pkg/util/logutil"
37-
"github.com/pingcap/tidb/pkg/util/mathutil"
3837
clientv3 "go.etcd.io/etcd/client/v3"
3938
"go.uber.org/zap"
4039
"google.golang.org/grpc"
@@ -98,7 +97,7 @@ func (alloc *autoIDValue) alloc4Unsigned(ctx context.Context, store kv.Storage,
9897
if nextStep < n1 {
9998
nextStep = n1
10099
}
101-
tmpStep := int64(mathutil.Min(math.MaxUint64-uint64(newBase), uint64(nextStep)))
100+
tmpStep := int64(min(math.MaxUint64-uint64(newBase), uint64(nextStep)))
102101
// The global rest is not enough for alloc.
103102
if tmpStep < n1 {
104103
return errAutoincReadFailed
@@ -174,7 +173,7 @@ func (alloc *autoIDValue) alloc4Signed(ctx context.Context,
174173
if nextStep < n1 {
175174
nextStep = n1
176175
}
177-
tmpStep := mathutil.Min(math.MaxInt64-newBase, nextStep)
176+
tmpStep := min(math.MaxInt64-newBase, nextStep)
178177
// The global rest is not enough for alloc.
179178
if tmpStep < n1 {
180179
return errAutoincReadFailed
@@ -229,8 +228,8 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
229228
}
230229
oldValue = currentEnd
231230
uCurrentEnd := uint64(currentEnd)
232-
newBase = mathutil.Max(uCurrentEnd, requiredBase)
233-
newEnd = mathutil.Min(math.MaxUint64-uint64(batch), newBase) + uint64(batch)
231+
newBase = max(uCurrentEnd, requiredBase)
232+
newEnd = min(math.MaxUint64-uint64(batch), newBase) + uint64(batch)
234233
_, err1 = idAcc.Inc(int64(newEnd - uCurrentEnd))
235234
return err1
236235
})
@@ -270,8 +269,8 @@ func (alloc *autoIDValue) rebase4Signed(ctx context.Context, store kv.Storage, d
270269
return err1
271270
}
272271
oldValue = currentEnd
273-
newBase = mathutil.Max(currentEnd, requiredBase)
274-
newEnd = mathutil.Min(math.MaxInt64-batch, newBase) + batch
272+
newBase = max(currentEnd, requiredBase)
273+
newEnd = min(math.MaxInt64-batch, newBase) + batch
275274
_, err1 = idAcc.Inc(newEnd - currentEnd)
276275
return err1
277276
})

pkg/ddl/executor.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import (
6767
"github.com/pingcap/tidb/pkg/util/dbterror/exeerrors"
6868
"github.com/pingcap/tidb/pkg/util/domainutil"
6969
"github.com/pingcap/tidb/pkg/util/generic"
70-
"github.com/pingcap/tidb/pkg/util/mathutil"
7170
"github.com/pingcap/tidb/pkg/util/stringutil"
7271
"github.com/tikv/client-go/v2/oracle"
7372
pdhttp "github.com/tikv/pd/client/http"
@@ -2119,7 +2118,7 @@ func adjustNewBaseToNextGlobalID(ctx table.AllocatorContext, t table.Table, tp a
21192118
// If the user sends SQL `alter table t1 auto_increment = 100` to TiDB-B,
21202119
// and TiDB-B finds 100 < 30001 but returns without any handling,
21212120
// then TiDB-A may still allocate 99 for auto_increment column. This doesn't make sense for the user.
2122-
return int64(mathutil.Max(uint64(newBase), uint64(autoID))), nil
2121+
return int64(max(uint64(newBase), uint64(autoID))), nil
21232122
}
21242123

21252124
// ShardRowID shards the implicit row ID by adding shard value to the row ID's first few bits.
@@ -2378,12 +2377,12 @@ func getReplacedPartitionIDs(names []string, pi *model.PartitionInfo) (firstPart
23782377
if firstPartIdx == -1 {
23792378
firstPartIdx = partIdx
23802379
} else {
2381-
firstPartIdx = mathutil.Min[int](firstPartIdx, partIdx)
2380+
firstPartIdx = min(firstPartIdx, partIdx)
23822381
}
23832382
if lastPartIdx == -1 {
23842383
lastPartIdx = partIdx
23852384
} else {
2386-
lastPartIdx = mathutil.Max[int](lastPartIdx, partIdx)
2385+
lastPartIdx = max(lastPartIdx, partIdx)
23872386
}
23882387
}
23892388
switch pi.Type {

pkg/ddl/partition.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import (
6161
"github.com/pingcap/tidb/pkg/util/collate"
6262
"github.com/pingcap/tidb/pkg/util/dbterror"
6363
"github.com/pingcap/tidb/pkg/util/hack"
64-
"github.com/pingcap/tidb/pkg/util/mathutil"
6564
decoder "github.com/pingcap/tidb/pkg/util/rowDecoder"
6665
"github.com/pingcap/tidb/pkg/util/slice"
6766
"github.com/pingcap/tidb/pkg/util/stringutil"
@@ -1912,7 +1911,7 @@ func formatListPartitionValue(ctx expression.BuildContext, tblInfo *model.TableI
19121911

19131912
haveDefault := false
19141913
exprStrs := make([]string, 0)
1915-
inValueStrs := make([]string, 0, mathutil.Max(len(pi.Columns), 1))
1914+
inValueStrs := make([]string, 0, max(len(pi.Columns), 1))
19161915
for i := range defs {
19171916
inValuesLoop:
19181917
for j, vs := range defs[i].InValues {
@@ -2938,9 +2937,9 @@ func (w *worker) onExchangeTablePartition(jobCtx *jobContext, job *model.Job) (v
29382937
// TODO: Fix the issue of big transactions during EXCHANGE PARTITION with AutoID.
29392938
// Similar to https://github.com/pingcap/tidb/issues/46904
29402939
newAutoIDs := model.AutoIDGroup{
2941-
RowID: mathutil.Max(ptAutoIDs.RowID, ntAutoIDs.RowID),
2942-
IncrementID: mathutil.Max(ptAutoIDs.IncrementID, ntAutoIDs.IncrementID),
2943-
RandomID: mathutil.Max(ptAutoIDs.RandomID, ntAutoIDs.RandomID),
2940+
RowID: max(ptAutoIDs.RowID, ntAutoIDs.RowID),
2941+
IncrementID: max(ptAutoIDs.IncrementID, ntAutoIDs.IncrementID),
2942+
RandomID: max(ptAutoIDs.RandomID, ntAutoIDs.RandomID),
29442943
}
29452944
err = metaMut.GetAutoIDAccessors(ptSchemaID, pt.ID).Put(newAutoIDs)
29462945
if err != nil {
@@ -3779,7 +3778,7 @@ func newReorgPartitionWorker(i int, t table.PhysicalTable, decodeColMap map[int6
37793778
}
37803779
}
37813780
writeColOffsetMap[id] = offset
3782-
maxOffset = mathutil.Max[int](maxOffset, offset)
3781+
maxOffset = max(maxOffset, offset)
37833782
}
37843783
return &reorgPartitionWorker{
37853784
backfillCtx: bCtx,

pkg/ddl/sanity_check.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/pingcap/tidb/pkg/parser/ast"
2929
"github.com/pingcap/tidb/pkg/sessionctx"
3030
"github.com/pingcap/tidb/pkg/util/intest"
31-
"github.com/pingcap/tidb/pkg/util/mathutil"
3231
"go.uber.org/zap"
3332
)
3433

@@ -125,7 +124,7 @@ func expectedDeleteRangeCnt(ctx delRangeCntCtx, job *model.Job) (int, error) {
125124

126125
ret := 0
127126
for _, arg := range args.IndexArgs {
128-
num := mathutil.Max(len(args.PartitionIDs), 1) // Add temporary index to del-range table.
127+
num := max(len(args.PartitionIDs), 1) // Add temporary index to del-range table.
129128
if arg.IsGlobal {
130129
num = 1 // Global index only has one del-range.
131130
}
@@ -144,21 +143,21 @@ func expectedDeleteRangeCnt(ctx delRangeCntCtx, job *model.Job) (int, error) {
144143
if args.IndexArgs[0].IsVector {
145144
return 0, nil
146145
}
147-
return mathutil.Max(len(args.PartitionIDs), 1), nil
146+
return max(len(args.PartitionIDs), 1), nil
148147
case model.ActionDropColumn:
149148
args, err := model.GetTableColumnArgs(job)
150149
if err != nil {
151150
return 0, errors.Trace(err)
152151
}
153152

154-
physicalCnt := mathutil.Max(len(args.PartitionIDs), 1)
153+
physicalCnt := max(len(args.PartitionIDs), 1)
155154
return physicalCnt * len(args.IndexIDs), nil
156155
case model.ActionModifyColumn:
157156
args, err := model.GetFinishedModifyColumnArgs(job)
158157
if err != nil {
159158
return 0, errors.Trace(err)
160159
}
161-
physicalCnt := mathutil.Max(len(args.PartitionIDs), 1)
160+
physicalCnt := max(len(args.PartitionIDs), 1)
162161
return physicalCnt * ctx.deduplicateIdxCnt(args.IndexIDs), nil
163162
case model.ActionMultiSchemaChange:
164163
totalExpectedCnt := 0

0 commit comments

Comments
 (0)