Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions sqle/model/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ func (s *Storage) GetLatestStartTimeAuditPlanSQLV2(sourceId uint, typ string) (s
info := struct {
StartTime string `gorm:"column:max_start_time"`
}{}
err := s.db.Raw(`SELECT MAX(STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(info, '$.start_time_of_last_scraped_sql')), '%Y-%m-%dT%H:%i:%s.%f'))
AS max_start_time FROM sql_manage_records WHERE source_id = ? AND source = ? AND deleted_at is NULL`, sourceId, typ).Scan(&info).Error
// Compatible with DATETIME(6) (space separator) and historical RFC3339-like values (T separator).
// Trailing timezone suffixes on RFC3339 are ignored once the format is exhausted.
err := s.db.Raw(`SELECT MAX(COALESCE(
STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(info, '$.start_time_of_last_scraped_sql')), '%Y-%m-%d %H:%i:%s.%f'),
STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(info, '$.start_time_of_last_scraped_sql')), '%Y-%m-%dT%H:%i:%s.%f'),
STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(info, '$.start_time_of_last_scraped_sql')), '%Y-%m-%d %H:%i:%s')
)) AS max_start_time FROM sql_manage_records WHERE source_id = ? AND source = ? AND deleted_at is NULL`, sourceId, typ).Scan(&info).Error
return info.StartTime, err
}

Expand Down
7 changes: 6 additions & 1 deletion sqle/server/auditplan/task_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type TaskWrapper struct {
sync.WaitGroup
isStarted bool
cancel chan struct{}
cancelOnce sync.Once
loopInterval func() time.Duration
}

Expand Down Expand Up @@ -219,7 +220,11 @@ func (at *TaskWrapper) stopCollect() error {
if !at.isStarted {
return nil
}
at.cancel <- struct{}{}
// S2 scheme B: close once so Stop is non-blocking while ExtractSQL is still running.
// loop's `select { case <-cancel: }` unblocks on close; avoid unbuffered send deadlock.
at.cancelOnce.Do(func() {
close(at.cancel)
})
at.isStarted = false
at.WaitGroup.Wait()
at.logger.Infof("stop task")
Expand Down
Loading