Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite: fix error 'database is locked' #19

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

elv-gilles
Copy link
Collaborator

@elv-gilles elv-gilles commented May 24, 2023

The fix add retries for the case where multiple connections are used simultaneously and uses a mutex for multiple write calls made concurrently with a single SQLiteConnection (note that the code in the fabric uses a single connection for the server, the client and the inspector).


sample error messages found in logs

2023-05-23T19:37:37.642Z DEBUG enqueue errors: rqlite.enqueueMessages 
  - rqlite error: unexpected result count: 1, expected: 2  -> database is locked "INSERT INTO ltaskq_asynq_queues (queue_name, state) VALUES(dist:livepart, 'active')  ON CONFLICT(queue_name) DO NOTHING;", state: pending, type: dist:livepart, id: hqt_CUZL75rJyNh2vXWrSGLemQeBaEaJXHpKr44rPvVT logger=/store/localTaskq gid=9435900

2023-05-23T19:39:42.915Z WARN  Could not move task id=hqt_9PXGZrwAkWCYDYdduxYq5tAEjXhRz8GUngcNShHD:inod21LrUiai85M8hq24yana53KNdY9i 
  type="dist:livenode" from "asynq:{dist:livenode}:active" to "asynq:{dist:livenode}:completed":  rqlite.setTaskCompleted: NOT_FOUND: error 
  (UPDATE ltaskq_asynq_tasks SET state=completed, task_msg=0a0d6...8f9acb4a306, deadline=NULL, sid=inodKnnpcZjRT65FLteMrULXBme4xS9, done_at=1684870777, cleanup_at=1692646777, retain_until=1687462777 WHERE task_uuid=hqt_9PXGZrwAkWCYDYdduxYq5tAEjXhRz8GUngcNShHD:inod21LrUiai85M8hq24yana53KNdY9i AND state='active'): 
  database is locked; Will retry syncing logger=/store/localTaskq gid=9438871

* use option '_txlock=immediate' when opening a rw conn in db.DB
* add lock around SQLiteConnection.Execute
* add retries for sqlite_busy (when using multiple connections)
* improve rqlite errors (report caller)
Copy link
Collaborator

@jslching jslching left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as far as I can tell

@elv-gilles elv-gilles merged commit e507721 into rqlite-support Jun 9, 2023
@elv-gilles elv-gilles deleted the fix-sqlite-busy branch June 9, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants