I've already posted here question about getting SQLITE_BUSY when calling
sqlite3_prepare in single thread application dependent on database size.
Now I get more detailed diagnostic.

I have simple database but with considerable amount of records in some
tables. Sql commands looks like:

Begin transaction

delete from some_table (most of records)

select from sqlite_master

insert into some_table 

commit transaction

I get SQLITE_BUSY trying to select from sqlite_master. Looking into
sqlite code I found that sqlite get exclusive lock on database file when
database exceeds some limit. And after this it makes one more lock which
of cause ends with error. Here you can find two fragments of sqlite
trace. First is for smaller database:

First:

OPEN 1980

LOCK 1980 1 was 0(0)

UNLOCK 1980 to 0 was 1(0)

LOCK 1980 1 was 0(0)

UNLOCK 1980 to 0 was 1(0)

LOCK 1980 1 was 0(0)

LOCK 1980 2 was 1(0)

OPEN 1972                       - journal file

OPEN 1968

LOCK 1968 1 was 0(0)

TEST WR-LOCK 1968 1 (remote)

UNLOCK 1968 to 0 was 1(0)

LOCK 1968 1 was 0(0)

TEST WR-LOCK 1968 1 (remote)

UNLOCK 1968 to 0 was 1(0)

UNLOCK 1968 to 0 was 0(0)

CLOSE 1968

LOCK 1980 4 was 2(0)

unreadlock = 1

CLOSE 1972

UNLOCK 1980 to 1 was 4(0)

UNLOCK 1980 to 0 was 1(0)

UNLOCK 1980 to 0 was 0(0)

CLOSE 1980

 

And second:

OPEN 1980

LOCK 1980 1 was 0(0)

UNLOCK 1980 to 0 was 1(0)

LOCK 1980 1 was 0(0)

UNLOCK 1980 to 0 was 1(0)

LOCK 1980 1 was 0(0)

LOCK 1980 2 was 1(0)

OPEN 1972                       - journal file

LOCK 1980 4 was 2(0)       - exclusive lock

unreadlock = 1

OPEN 1968

LOCK 1968 1 was 0(0)

LOCK FAILED 1968 trying for 1 but got 0

UNLOCK 1968 to 0 was 0(0)

CLOSE 1968

CLOSE 1972

UNLOCK 1980 to 1 was 4(0)

UNLOCK 1980 to 0 was 1(0)

UNLOCK 1980 to 0 was 0(0)

CLOSE 1980

 

Reply via email to