IF the error codes are checked AND two writers are simultaneously able to write 
to the db file, THEN the file locking is probably broken in the file system 
layer (e.g. network file systems), which SQLite can do nothing about.

In Journal mode, the first process to acquire a RESERVED lock will continue, 
and the other one will have to wait or return SQLITE_BUSY. When the process is 
ready to actually write to the file (as opposed to in-memory copies of pages), 
it needs to acquire a PENDING and then an EXCLUSIVE lock.

In WAL mode, only one process may append data to the WAL file at one time.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von Kees Nuyt
Gesendet: Mittwoch, 07. Februar 2018 10:55
An: sqlite-users@mailinglists.sqlite.org
Betreff: [EXTERNAL] Re: [sqlite] Question about threadsafe

On Tue, 6 Feb 2018 19:33:10 -0700 (MST), Nick <haveagoodtime2...@gmail.com> 
wrote:

>>  (a) an error result of some kind or (b) a corrupt database.
>
> I did not see any info about errmsg.

Your code doesn't check the returncode of the sqlite3_* calls.

>>  Are your processes using the same database connection or does each
>> one have its own ?
>
> Two processes have two sqlite3_open(). So each one has its own.
>
>>  Are you checking the result codes returned by all the API calls ?
>
> Yes. I use speedtest1.c as model code.
>      speedtest1_exec("BEGIN");
>      speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2,?3); --  %d
> times", n);
>      for(i=1; i<=n; i++){
>        rc = sqlite3_bind_int64(g.pStmt, 1, i);
>        rc = sqlite3_bind_int(g.pStmt, 2, i);
>        rc = sqlite3_bind_text(g.pStmt, 3, "hello", -1, SQLITE_STATIC);
>        speedtest1_run();
>      }
>      speedtest1_exec("COMMIT");
>
> And I have checked rc = SQLITE_OK.

I assume speedtest1_run() calls sqlite3_step(), but does it check the return 
code? I suspect _step() returns SQLITE_BUSY sometimes.

>
>>  Can you reliably get less than 20000 rows ?
>
> Yes, always less than 20000.
> Process A inserts 1-10000 and process B inserts 10001-20000. I found
> that the first few rows is missing in the result. I mean there is no 
> 10001-10xxx.
>
>>  Does the problem go away if you use threadsafe = 2 ?
>
> The problem is still here.

Because the test uses two processes, every process is single-threaded, no risc 
of concurrency between threads.

PRAGMA busy_timeout might be helpful.


--
Regards,
Kees Nuyt
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick | Software Engineer | Scientific Games International GmbH | 
Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 
1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to