Skip to content

Commit b27fd04

Browse files
committed
address comment about time
Signed-off-by: Wenqi Mou <[email protected]>
1 parent 48bf9da commit b27fd04

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

br/pkg/registry/registration.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const (
6363
// resumeTaskByIDSQLTemplate is the SQL template for resuming a paused task by its ID
6464
resumeTaskByIDSQLTemplate = `
6565
UPDATE %s.%s
66-
SET status = 'running', last_heartbeat = %%?
66+
SET status = 'running', last_heartbeat_ts = %%?
6767
WHERE id = %%?`
6868

6969
// deleteRegistrationSQLTemplate is the SQL template for deleting a registration
@@ -81,7 +81,7 @@ const (
8181
createNewTaskSQLTemplate = `
8282
INSERT INTO %s.%s
8383
(filter_strings, filter_hash, start_ts, restored_ts, upstream_cluster_id,
84-
with_sys_table, status, cmd, start_timestamp, last_heartbeat)
84+
with_sys_table, status, cmd, task_start_ts, last_heartbeat_ts)
8585
VALUES (%%?, MD5(%%?), %%?, %%?, %%?, %%?, 'running', %%?, %%?, %%?)`
8686
)
8787

@@ -126,6 +126,11 @@ type Registry struct {
126126
heartbeatManager *HeartbeatManager
127127
}
128128

129+
// getCurrentTimestamp returns the current time as time.Time
130+
func getCurrentTimestamp() time.Time {
131+
return time.Now()
132+
}
133+
129134
// NewRestoreRegistry creates a new registry using TiDB's session
130135
func NewRestoreRegistry(g glue.Glue, dom *domain.Domain) (*Registry, error) {
131136
se, err := g.CreateSession(dom.Store())
@@ -236,7 +241,7 @@ func (r *Registry) ResumeOrCreateRegistration(ctx context.Context, info Registra
236241

237242
// strictly check for paused status
238243
if status == string(TaskStatusPaused) {
239-
currentTime := uint64(time.Now().Unix())
244+
currentTime := getCurrentTimestamp()
240245
updateSQL := fmt.Sprintf(resumeTaskByIDSQLTemplate, RestoreRegistryDBName, RestoreRegistryTableName)
241246
_, _, err = execCtx.ExecRestrictedSQL(ctx, sessionOpts, updateSQL, currentTime, existingTaskID)
242247
if err != nil {
@@ -260,7 +265,7 @@ func (r *Registry) ResumeOrCreateRegistration(ctx context.Context, info Registra
260265
}
261266

262267
// no existing task found, create a new one
263-
currentTime := uint64(time.Now().Unix())
268+
currentTime := getCurrentTimestamp()
264269
insertSQL := fmt.Sprintf(createNewTaskSQLTemplate, RestoreRegistryDBName, RestoreRegistryTableName)
265270
_, _, err = execCtx.ExecRestrictedSQL(ctx, sessionOpts, insertSQL,
266271
filterStrings, filterStrings, info.StartTS, info.RestoredTS,

pkg/session/bootstrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@ const (
741741
with_sys_table BOOLEAN NOT NULL DEFAULT TRUE,
742742
status VARCHAR(20) NOT NULL DEFAULT 'running',
743743
cmd TEXT,
744-
start_timestamp BIGINT UNSIGNED NOT NULL,
745-
last_heartbeat BIGINT UNSIGNED NOT NULL,
744+
task_start_ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
745+
last_heartbeat_ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
746746
UNIQUE KEY unique_registration_params (
747747
filter_hash,
748748
start_ts,

0 commit comments

Comments
 (0)