Skip to content

Commit

Permalink
create a trigger to remove tasks from enqueued task table on update
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Mar 4, 2024
1 parent 23838ee commit f4ed60b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions libsql-server/src/namespace/meta_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ fn setup_connection(conn: &rusqlite::Connection) -> Result<()> {
(),
)?;

// create a trigger that removes the task from enqueued tasks whenever it's status was updated.
// The assumption is that the status of the task is only ever updated if work on it is
// finished.
conn.execute(
"
CREATE TEMPORARY TRIGGER IF NOT EXISTS remove_from_enqueued_tasks
AFTER UPDATE OF status ON migration_job_pending_tasks
BEGIN
DELETE FROM enqueued_tasks WHERE task_id = old.task_id;
END
",
(),
)?;

Ok(())
}

Expand Down Expand Up @@ -426,11 +440,6 @@ impl MetaStoreInner {
"UPDATE migration_job_pending_tasks SET status = ?, error = ? WHERE task_id = ?",
(task.status as u64, error, task.task_id),
)?;
// remove task from pending tasks
txn.execute(
"DELETE FROM enqueued_tasks WHERE task_id = ?",
[task.task_id],
)?;
txn.commit()?;
Ok(())
}
Expand Down

0 comments on commit f4ed60b

Please sign in to comment.