/ Check-in [8719f880]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enable shared cache on the server demonstration. (CVS 2899)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8719f880a395db8be65ea45615d8e55985306f1e
User & Date: drh 2006-01-10 02:30:33
Context
2006-01-10
07:14
If compiled with memory-debugging, write garbage to memory when it is freed. Fix for #1594. (CVS 2900) check-in: bd02a6fa user: danielk1977 tags: trunk
02:30
Enable shared cache on the server demonstration. (CVS 2899) check-in: 8719f880 user: drh tags: trunk
2006-01-09
23:50
Add the first simple tests of server mode. Get the Makefile generated from the configure script working again. (CVS 2898) check-in: 66f84068 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/server.c.

   327    327   ** This routine implements the server.  To start the server, first
   328    328   ** make sure g.serverHalt is false, then create a new detached thread
   329    329   ** on this procedure.  See the sqlite3_server_start() routine below
   330    330   ** for an example.  This procedure loops until g.serverHalt becomes
   331    331   ** true.
   332    332   */
   333    333   void *sqlite3_server(void *NotUsed){
          334  +  sqlite3_enable_shared_cache(1);
   334    335     if( pthread_mutex_trylock(&g.serverMutex) ){
   335    336       return 0;  /* Another server is already running */
   336    337     }
   337    338     while( !g.serverHalt ){
   338    339       SqlMessage *pMsg;
   339    340   
   340    341       /* Remove the last message from the message queue.

Changes to test/server1.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the server mode of SQLite.
    13     13   #
    14     14   # This file is derived from thread1.test
    15     15   #
    16         -# $Id: server1.test,v 1.1 2006/01/09 23:50:11 drh Exp $
           16  +# $Id: server1.test,v 1.2 2006/01/10 02:30:33 drh Exp $
    17     17   
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Skip this whole file if the server testing code is not enabled
    23     23   #
................................................................................
    92     92   } SQLITE_OK
    93     93   do_test server1-1.12 {
    94     94     catchsql {SELECT name FROM sqlite_master}
    95     95     execsql {SELECT name FROM sqlite_master}
    96     96   } {t1 t2}
    97     97   
    98     98   
    99         -#
   100         -# The following tests - server1-2.* - test the following scenario:
   101         -#
   102         -# 1:  Read-lock thread A
   103         -# 2:  Read-lock thread B
   104         -# 3:  Attempt to write in thread C -> SQLITE_BUSY
   105         -# 4:  Check db write failed from main thread.
   106         -# 5:  Unlock from thread A.
   107         -# 6:  Attempt to write in thread C -> SQLITE_BUSY
   108         -# 7:  Check db write failed from main thread.
   109         -# 8:  Unlock from thread B.
   110         -# 9:  Attempt to write in thread C -> SQLITE_DONE
   111         -# 10: Finalize the write from thread C
   112         -# 11: Check db write succeeded from main thread.
           99  +# Read from table t1.  Do not finalize the statement.  This
          100  +# will leave the lock pending.
   113    101   #
   114    102   do_test server1-2.1 {
   115    103     client_halt *
   116    104     client_create A test.db
   117    105     client_compile A {SELECT a FROM t1}
   118    106     client_step A
   119    107     client_result A
   120    108   } SQLITE_ROW
          109  +
          110  +# Read from the same table from another thread.  This is allows.
          111  +#
   121    112   do_test server1-2.2 {
   122    113     client_create B test.db
   123    114     client_compile B {SELECT b FROM t1}
   124    115     client_step B
   125    116     client_result B
   126    117   } SQLITE_ROW
          118  +
          119  +# Write to a different table from another thread.  This is allowed
          120  +# becaus in server mode with a shared cache we have table-level locking.
          121  +#
   127    122   do_test server1-2.3 {
   128    123     client_create C test.db
   129    124     client_compile C {INSERT INTO t2 VALUES(98,99)}
   130    125     client_step C
   131    126     client_result C
   132    127     client_finalize C
   133    128     client_result C
   134         -} SQLITE_BUSY
          129  +} SQLITE_OK
   135    130   
          131  +# But we cannot insert into table t1 because threads A and B have it locked.
          132  +#
   136    133   do_test server1-2.4 {
   137         -  execsql {SELECT * FROM t2}
   138         -} {}
   139         -
          134  +  client_compile C {INSERT INTO t1 VALUES(98,99)}
          135  +  client_step C
          136  +  client_result C
          137  +  client_finalize C
          138  +  client_result C
          139  +} SQLITE_LOCKED
   140    140   do_test server1-2.5 {
   141         -  client_finalize A
   142         -  client_result A
   143         -} SQLITE_OK
          141  +  client_finalize B
          142  +  client_compile C {INSERT INTO t1 VALUES(98,99)}
          143  +  client_step C
          144  +  client_result C
          145  +  client_finalize C
          146  +  client_result C
          147  +} SQLITE_LOCKED
          148  +
          149  +# Insert into t1 is successful after finishing the other two threads.
   144    150   do_test server1-2.6 {
   145         -  client_compile C {INSERT INTO t2 VALUES(98,99)}
          151  +  client_finalize A
          152  +  client_compile C {INSERT INTO t1 VALUES(98,99)}
   146    153     client_step C
   147    154     client_result C
   148    155     client_finalize C
   149    156     client_result C
   150         -} SQLITE_BUSY
   151         -do_test server1-2.7 {
   152         -  execsql {SELECT * FROM t2}
   153         -} {}
   154         -do_test server1-2.8 {
   155         -  client_finalize B
   156         -  client_result B
   157    157   } SQLITE_OK
   158         -do_test server1-2.9 {
   159         -  client_compile C {INSERT INTO t2 VALUES(98,99)}
   160         -  client_step C
   161         -  client_result C
   162         -} SQLITE_DONE
   163         -do_test server1-2.10 {
   164         -  client_finalize C
   165         -  client_result C
   166         -} SQLITE_OK
   167         -do_test server1-2.11 {
   168         -  execsql {SELECT * FROM t2}
   169         -} {98 99}
   170    158   
   171    159   client_halt *   
   172    160   finish_test