Skip to content

Commit

Permalink
ttl: fix a wrong ttl's job schedule for TTL table upgraded from 6.5 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Oct 14, 2024
1 parent b5c0f24 commit 963344f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
restoreCtx.WriteKeyWord("TTL_JOB_INTERVAL")
restoreCtx.WritePlain("=")
if len(tableInfo.TTLInfo.JobInterval) == 0 {
restoreCtx.WriteString(model.DefaultJobInterval.String())
restoreCtx.WriteString(model.DefaultJobIntervalStr)
} else {
restoreCtx.WriteString(tableInfo.TTLInfo.JobInterval)
}
Expand Down
3 changes: 2 additions & 1 deletion parser/model/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ go_test(
],
embed = [":model"],
flaky = True,
shard_count = 20,
shard_count = 21,
deps = [
"//parser/charset",
"//parser/duration",
"//parser/mysql",
"//parser/terror",
"//parser/types",
Expand Down
3 changes: 3 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,9 @@ func (p *PolicyInfo) Clone() *PolicyInfo {
// DefaultJobInterval sets the default interval between TTL jobs
const DefaultJobInterval = time.Hour

// DefaultJobIntervalStr is the string representation of DefaultJobInterval
const DefaultJobIntervalStr = "1h"

// TTLInfo records the TTL config
type TTLInfo struct {
ColumnName CIStr `json:"column"`
Expand Down
8 changes: 8 additions & 0 deletions parser/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/pingcap/tidb/parser/charset"
"github.com/pingcap/tidb/parser/duration"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -818,3 +819,10 @@ func TestTTLJobInterval(t *testing.T) {
require.NoError(t, err)
require.Equal(t, time.Hour*200, interval)
}

func TestTTLDefaultJobInterval(t *testing.T) {
// test const `DefaultJobIntervalStr` and `DefaultJobInterval` are consistent.
d, err := duration.ParseDuration(DefaultJobIntervalStr)
require.NoError(t, err)
require.Equal(t, DefaultJobInterval, d)
}

0 comments on commit 963344f

Please sign in to comment.