/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/server.c.

327
328
329
330
331
332
333

334
335
336
337
338
339
340
** This routine implements the server.  To start the server, first
** make sure g.serverHalt is false, then create a new detached thread
** on this procedure.  See the sqlite3_server_start() routine below
** for an example.  This procedure loops until g.serverHalt becomes
** true.
*/
void *sqlite3_server(void *NotUsed){

  if( pthread_mutex_trylock(&g.serverMutex) ){
    return 0;  /* Another server is already running */
  }
  while( !g.serverHalt ){
    SqlMessage *pMsg;

    /* Remove the last message from the message queue.







>







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

    /* Remove the last message from the message queue.

Changes to test/server1.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120



121
122
123
124
125
126




127
128
129
130
131
132
133
134
135
136
137
138
139







140
141


142


143


144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the server mode of SQLite.
#
# This file is derived from thread1.test
#
# $Id: server1.test,v 1.1 2006/01/09 23:50:11 drh Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Skip this whole file if the server testing code is not enabled
#
................................................................................
} SQLITE_OK
do_test server1-1.12 {
  catchsql {SELECT name FROM sqlite_master}
  execsql {SELECT name FROM sqlite_master}
} {t1 t2}


#
# The following tests - server1-2.* - test the following scenario:
#
# 1:  Read-lock thread A
# 2:  Read-lock thread B
# 3:  Attempt to write in thread C -> SQLITE_BUSY
# 4:  Check db write failed from main thread.
# 5:  Unlock from thread A.
# 6:  Attempt to write in thread C -> SQLITE_BUSY
# 7:  Check db write failed from main thread.
# 8:  Unlock from thread B.
# 9:  Attempt to write in thread C -> SQLITE_DONE
# 10: Finalize the write from thread C
# 11: Check db write succeeded from main thread.
#
do_test server1-2.1 {
  client_halt *
  client_create A test.db
  client_compile A {SELECT a FROM t1}
  client_step A
  client_result A
} SQLITE_ROW



do_test server1-2.2 {
  client_create B test.db
  client_compile B {SELECT b FROM t1}
  client_step B
  client_result B
} SQLITE_ROW




do_test server1-2.3 {
  client_create C test.db
  client_compile C {INSERT INTO t2 VALUES(98,99)}
  client_step C
  client_result C
  client_finalize C
  client_result C
} SQLITE_BUSY

do_test server1-2.4 {
  execsql {SELECT * FROM t2}
} {}








do_test server1-2.5 {
  client_finalize A


  client_result A


} SQLITE_OK


do_test server1-2.6 {

  client_compile C {INSERT INTO t2 VALUES(98,99)}
  client_step C
  client_result C
  client_finalize C
  client_result C
} SQLITE_BUSY
do_test server1-2.7 {
  execsql {SELECT * FROM t2}
} {}
do_test server1-2.8 {
  client_finalize B
  client_result B
} SQLITE_OK
do_test server1-2.9 {
  client_compile C {INSERT INTO t2 VALUES(98,99)}
  client_step C
  client_result C
} SQLITE_DONE
do_test server1-2.10 {
  client_finalize C
  client_result C
} SQLITE_OK
do_test server1-2.11 {
  execsql {SELECT * FROM t2}
} {98 99}

client_halt *   
finish_test







|







 







|
|
<
<
<
<
<
<
<
<
<
<
<
<








>
>
>






>
>
>
>







|

|
<
<
|
>
>
>
>
>
>
>

|
>
>
|
>
>
|
>
>

>
|




<
<
<
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
92
93
94
95
96
97
98
99
100












101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156







157












158
159
160
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the server mode of SQLite.
#
# This file is derived from thread1.test
#
# $Id: server1.test,v 1.2 2006/01/10 02:30:33 drh Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Skip this whole file if the server testing code is not enabled
#
................................................................................
} SQLITE_OK
do_test server1-1.12 {
  catchsql {SELECT name FROM sqlite_master}
  execsql {SELECT name FROM sqlite_master}
} {t1 t2}


# Read from table t1.  Do not finalize the statement.  This
# will leave the lock pending.












#
do_test server1-2.1 {
  client_halt *
  client_create A test.db
  client_compile A {SELECT a FROM t1}
  client_step A
  client_result A
} SQLITE_ROW

# Read from the same table from another thread.  This is allows.
#
do_test server1-2.2 {
  client_create B test.db
  client_compile B {SELECT b FROM t1}
  client_step B
  client_result B
} SQLITE_ROW

# Write to a different table from another thread.  This is allowed
# becaus in server mode with a shared cache we have table-level locking.
#
do_test server1-2.3 {
  client_create C test.db
  client_compile C {INSERT INTO t2 VALUES(98,99)}
  client_step C
  client_result C
  client_finalize C
  client_result C
} SQLITE_OK

# But we cannot insert into table t1 because threads A and B have it locked.


#
do_test server1-2.4 {
  client_compile C {INSERT INTO t1 VALUES(98,99)}
  client_step C
  client_result C
  client_finalize C
  client_result C
} SQLITE_LOCKED
do_test server1-2.5 {
  client_finalize B
  client_compile C {INSERT INTO t1 VALUES(98,99)}
  client_step C
  client_result C
  client_finalize C
  client_result C
} SQLITE_LOCKED

# Insert into t1 is successful after finishing the other two threads.
do_test server1-2.6 {
  client_finalize A
  client_compile C {INSERT INTO t1 VALUES(98,99)}
  client_step C
  client_result C
  client_finalize C
  client_result C







} SQLITE_OK













client_halt *   
finish_test