Skip to content

Commit

Permalink
ttl: fix change status sql argument (#40234) (#40241)
Browse files Browse the repository at this point in the history
close #40231
  • Loading branch information
ti-chi-bot authored Jul 28, 2023
1 parent 65f6531 commit 449eb9c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions ttl/ttlworker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ go_test(
name = "ttlworker_test",
srcs = [
"del_test.go",
"job_integration_test.go",
"job_manager_integration_test.go",
"job_manager_test.go",
"job_test.go",
Expand Down
2 changes: 1 addition & 1 deletion ttl/ttlworker/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const finishJobTemplate = `UPDATE mysql.tidb_ttl_table_status
const updateJobStateTemplate = "UPDATE mysql.tidb_ttl_table_status SET current_job_state = %? WHERE table_id = %? AND current_job_id = %? AND current_job_owner_id = %?"

func updateJobCurrentStatusSQL(tableID int64, oldStatus cache.JobStatus, newStatus cache.JobStatus, jobID string) (string, []interface{}) {
return updateJobCurrentStatusTemplate, []interface{}{newStatus, tableID, oldStatus, jobID}
return updateJobCurrentStatusTemplate, []interface{}{string(newStatus), tableID, string(oldStatus), jobID}
}

func finishJobSQL(tableID int64, finishTime time.Time, summary string, jobID string) (string, []interface{}) {
Expand Down
41 changes: 41 additions & 0 deletions ttl/ttlworker/job_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 ttlworker_test

import (
"context"
"testing"

dbsession "github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/ttl/cache"
"github.com/pingcap/tidb/ttl/session"
"github.com/pingcap/tidb/ttl/ttlworker"
"github.com/stretchr/testify/require"
)

func TestChangeStatus(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

dbSession, err := dbsession.CreateSession4Test(store)
require.NoError(t, err)
se := session.NewSession(dbSession, dbSession, nil)

job := ttlworker.NewTTLJob(&cache.PhysicalTable{ID: 0}, "0", cache.JobStatusWaiting)
tk.MustExec("insert into mysql.tidb_ttl_table_status(table_id,current_job_id,current_job_status) VALUES(0, '0', 'waiting')")
require.NoError(t, job.ChangeStatus(context.Background(), se, cache.JobStatusRunning))
tk.MustQuery("select current_job_status from mysql.tidb_ttl_table_status").Check(testkit.Rows("running"))
}
15 changes: 15 additions & 0 deletions ttl/ttlworker/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@
package ttlworker

import (
"context"
"testing"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/ttl/cache"
"github.com/pingcap/tidb/ttl/session"
"github.com/stretchr/testify/assert"
)

func NewTTLJob(tbl *cache.PhysicalTable, id string, status cache.JobStatus) *ttlJob {
return &ttlJob{
tbl: tbl,
id: id,
status: status,
}
}

func (j *ttlJob) ChangeStatus(ctx context.Context, se session.Session, status cache.JobStatus) error {
return j.changeStatus(ctx, se, status)
}

func TestIterScanTask(t *testing.T) {
tbl := newMockTTLTbl(t, "t1")

Expand Down

0 comments on commit 449eb9c

Please sign in to comment.