Reduce insert pressure in db. Increase sqlite timeout value

Entire-Checkpoint: a1e2931d4deb
This commit is contained in:
2026-03-16 11:17:47 +01:00
parent 0aad8f01c8
commit 51517f8031
9 changed files with 142 additions and 13 deletions

View File

@@ -92,20 +92,33 @@ func (r *JobRepository) SyncJobs() ([]*schema.Job, error) {
jobs = append(jobs, job)
}
// Transfer cached jobs to main table and clear cache in a single transaction.
tx, err := r.DB.Beginx()
if err != nil {
cclog.Errorf("SyncJobs: begin transaction: %v", err)
return nil, err
}
defer tx.Rollback()
// Use INSERT OR IGNORE to skip jobs already transferred by the stop path
_, err = r.DB.Exec(
_, err = tx.Exec(
"INSERT OR IGNORE INTO job (job_id, cluster, subcluster, start_time, hpc_user, project, cluster_partition, array_job_id, num_nodes, num_hwthreads, num_acc, shared, monitoring_status, smt, job_state, duration, walltime, footprint, energy, energy_footprint, resources, meta_data) SELECT job_id, cluster, subcluster, start_time, hpc_user, project, cluster_partition, array_job_id, num_nodes, num_hwthreads, num_acc, shared, monitoring_status, smt, job_state, duration, walltime, footprint, energy, energy_footprint, resources, meta_data FROM job_cache")
if err != nil {
cclog.Errorf("Error while Job sync: %v", err)
return nil, err
}
_, err = r.DB.Exec("DELETE FROM job_cache")
_, err = tx.Exec("DELETE FROM job_cache")
if err != nil {
cclog.Errorf("Error while Job cache clean: %v", err)
return nil, err
}
if err := tx.Commit(); err != nil {
cclog.Errorf("SyncJobs: commit transaction: %v", err)
return nil, err
}
// Resolve correct job.id from the job table. The IDs read from job_cache
// are from a different auto-increment sequence and must not be used to
// query the job table.