Skip to content

Commit 963344f

Browse files
authored
ttl: fix a wrong ttl's job schedule for TTL table upgraded from 6.5 (#56540) (#56591)
close #56539
1 parent b5c0f24 commit 963344f

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

executor/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
13091309
restoreCtx.WriteKeyWord("TTL_JOB_INTERVAL")
13101310
restoreCtx.WritePlain("=")
13111311
if len(tableInfo.TTLInfo.JobInterval) == 0 {
1312-
restoreCtx.WriteString(model.DefaultJobInterval.String())
1312+
restoreCtx.WriteString(model.DefaultJobIntervalStr)
13131313
} else {
13141314
restoreCtx.WriteString(tableInfo.TTLInfo.JobInterval)
13151315
}

parser/model/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ go_test(
3030
],
3131
embed = [":model"],
3232
flaky = True,
33-
shard_count = 20,
33+
shard_count = 21,
3434
deps = [
3535
"//parser/charset",
36+
"//parser/duration",
3637
"//parser/mysql",
3738
"//parser/terror",
3839
"//parser/types",

parser/model/model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,9 @@ func (p *PolicyInfo) Clone() *PolicyInfo {
17571757
// DefaultJobInterval sets the default interval between TTL jobs
17581758
const DefaultJobInterval = time.Hour
17591759

1760+
// DefaultJobIntervalStr is the string representation of DefaultJobInterval
1761+
const DefaultJobIntervalStr = "1h"
1762+
17601763
// TTLInfo records the TTL config
17611764
type TTLInfo struct {
17621765
ColumnName CIStr `json:"column"`

parser/model/model_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/pingcap/tidb/parser/charset"
23+
"github.com/pingcap/tidb/parser/duration"
2324
"github.com/pingcap/tidb/parser/mysql"
2425
"github.com/pingcap/tidb/parser/types"
2526
"github.com/stretchr/testify/require"
@@ -818,3 +819,10 @@ func TestTTLJobInterval(t *testing.T) {
818819
require.NoError(t, err)
819820
require.Equal(t, time.Hour*200, interval)
820821
}
822+
823+
func TestTTLDefaultJobInterval(t *testing.T) {
824+
// test const `DefaultJobIntervalStr` and `DefaultJobInterval` are consistent.
825+
d, err := duration.ParseDuration(DefaultJobIntervalStr)
826+
require.NoError(t, err)
827+
require.Equal(t, DefaultJobInterval, d)
828+
}

0 commit comments

Comments
 (0)