Sabyasachi Ruj wrote:
Hi,
Hello there!
I have a very big table with around 40,00, 000 rows. 4 columns. 220 MB.
Now, I have two threads:-
Thread1: Is deleting 7,00, 000 rows from the table.
Thread2: Is doing SELECT on the same table.
Now the problem is sometimes the sqlite3_prepare for the SELECT query is
failing with SQLITE_BUSY error.
That's obviously not surprising - SQLite is doing the right thing here.
My questions: -
1. What is the best way to handle this error, and continue working normally?
You could either write a busy handler callback and set it via
sqlite3_busy_handler - http://sqlite.org/c3ref/busy_handler.html - or
you could use the builtin busy timeout handler set by
sqlite3_busy_timeout - http://sqlite.org/c3ref/busy_timeout.html - which
will put your thread to sleep and retry for up to the specified number
of milliseconds. The second solution might be simpler.
2. Is there any documentation in sqlite3.org, which discuses the locking
mechanism for DELETEs? Exacly in what phase of DELETE sqlite creates the
exclusive lock, so, the SELECT is failing?
The locking mechanism is explained in great detail in
http://www.sqlite.org/lockingv3.html and the atomic commits in
http://www.sqlite.org/atomiccommit.html . If those should not answer
your questions, you could try
http://www.google.com/search?q=site:sqlite.org+delete+lock :)
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users