symisc / unqlite

An Embedded NoSQL, Transactional Database Engine
https://unqlite.symisc.net
Other
2.11k stars 164 forks source link

Cannot acquire an exclusive lock on the database while journal rollback #148

Closed jmugan closed 1 year ago

jmugan commented 1 year ago

Hi, I get this error. Normally, I guess you would restart the database when it gets into a weird state like this, but for unqlite there is nothing to restart. What should I do?

I have another process that reads the database. Is it you can't have one process read the database and another write to it?

Here's the full stack trace

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/billenote/src/app_flask/explain_app.py", line 147, in process_umls_crud
    update_umls(umls_rec)
  File "/home/ubuntu/billenote/src/umls/umls_crud.py", line 52, in update_umls
    quick_umls.cuisem_db.insert(text, umls_rec.cui, umls_rec.semtypes, 1)
  File "/home/ubuntu/anaconda3/lib/python3.8/site-packages/quickumls/toolbox.py", line 262, in insert
    cuis = pickle.loads(self.cui_db_get(db_key_encode(term)))
  File "unqlite.pyx", line 408, in unqlite.UnQLite.fetch
  File "unqlite.pyx", line 414, in unqlite.UnQLite.fetch
  File "unqlite.pyx", line 490, in unqlite.UnQLite.check_call
unqlite.UnQLiteError: Another process or thread hold the requested lock
Cannot acquire an exclusive lock on the database while journal rollback
symisc commented 1 year ago

Hello,

UnQLite implements the Multiple readers, single writer paradigm, so while it OK for multiple process/threads to read the same database at once, only a single writer thread/process is allowed to write to the database at once. Your other process (hence the writer) must call unqlite_commit()in order to release the exclusive lock, and let other processes access the database again.

jmugan commented 1 year ago

Thanks for your response. There is only one writer and it does call commit. The other process is a reader not controlled by me. Is there anything I can do, like "hey, close any open sessions because I know they are readers and I'm the only writer."

I'll also look in the documentation more. Maybe I don't understand how unqlite decides to open a transaction. It seems more implicit than I'm used to.

symisc commented 1 year ago

Yes,

If your first read fail, just implement a timing loop (think of asyncio) that calls the database read function periodically until it succeed.

-----Original Message----- From: Jonathan Mugan @.> To: symisc/unqlite @.> Cc: PixLab | Symisc Systems @.>, State change @.> Sent: Sat, 11 Mar 2023 3:51 Subject: Re: [symisc/unqlite] Cannot acquire an exclusive lock on the database while journal rollback (Issue #148)

Thanks for your response. There is only one writer and it does call commit. The other process is a reader not controlled by me. Is there anything I can do, like "hey, close any open sessions because I know they are readers and I'm the only writer."

-- Reply to this email directly or view it on GitHub: https://github.com/symisc/unqlite/issues/148#issuecomment-1464244780 You are receiving this because you modified the open/close state.

Message ID: @.***>