SQLite

Check-in [65fa1164f0]
Login

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

Overview
Comment:Fix to xTruncate and more journal mode tests for the multiplex VFS.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 65fa1164f035d270db48db6474da888aacfba3bd
User & Date: shaneh 2010-11-05 20:50:44.000
Context
2010-11-08
19:16
Changes to the multiplex VFS to optionally (compiler define) allow the "chunk extension" to overwrite the right-most chars of the filename instead of simply being appended. (check-in: 07da0a0bef user: shaneh tags: trunk)
19:01
Experimental changes to EXPLAIN QUERY PLAN. (check-in: f4747eb83d user: dan tags: experimental)
2010-11-05
20:50
Fix to xTruncate and more journal mode tests for the multiplex VFS. (check-in: 65fa1164f0 user: shaneh tags: trunk)
18:07
Fix os_unix.c so that it works with the test_multiplex module. (check-in: 72ba3e368b user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/test_multiplex.c.
24
25
26
27
28
29
30

31
32
33
34
35
36
37
#include <assert.h>
#include "sqliteInt.h"

/************************ Shim Definitions ******************************/

#define SQLITE_MULTIPLEX_CHUNK_SIZE 0x40000000
#define SQLITE_MULTIPLEX_MAX_CHUNKS 32


/************************ Object Definitions ******************************/

/* Forward declaration of all object types */
typedef struct multiplexGroup multiplexGroup;
typedef struct multiplexConn multiplexConn;








>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <assert.h>
#include "sqliteInt.h"

/************************ Shim Definitions ******************************/

#define SQLITE_MULTIPLEX_CHUNK_SIZE 0x40000000
#define SQLITE_MULTIPLEX_MAX_CHUNKS 32
#define SQLITE_MULTIPLEX_EXT_FMT    "-%04d"

/************************ Object Definitions ******************************/

/* Forward declaration of all object types */
typedef struct multiplexGroup multiplexGroup;
typedef struct multiplexConn multiplexConn;

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
static sqlite3_file *multiplexSubOpen(multiplexConn *pConn, int iChunk, int *rc, int *pOutFlags){
  multiplexGroup *pGroup = pConn->pGroup;
  sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs;        /* Real VFS */
  if( iChunk<gMultiplex.nMaxChunks ){
    sqlite3_file *pSubOpen = pGroup->pReal[iChunk];    /* Real file descriptor */
    if( !pGroup->bOpen[iChunk] ){
      pGroup->zName[pGroup->nName] = '\0';
      if( iChunk ) sqlite3_snprintf(pGroup->nName+6, pGroup->zName+pGroup->nName, "-%04d", iChunk);
      *rc = pOrigVfs->xOpen(pOrigVfs, pGroup->zName, pSubOpen, pGroup->flags, pOutFlags);
      if( *rc==SQLITE_OK ){
        pGroup->bOpen[iChunk] = -1;
        return pSubOpen;
      }
      return NULL;
    }







|







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
static sqlite3_file *multiplexSubOpen(multiplexConn *pConn, int iChunk, int *rc, int *pOutFlags){
  multiplexGroup *pGroup = pConn->pGroup;
  sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs;        /* Real VFS */
  if( iChunk<gMultiplex.nMaxChunks ){
    sqlite3_file *pSubOpen = pGroup->pReal[iChunk];    /* Real file descriptor */
    if( !pGroup->bOpen[iChunk] ){
      pGroup->zName[pGroup->nName] = '\0';
      if( iChunk ) sqlite3_snprintf(pGroup->nName+6, pGroup->zName+pGroup->nName, SQLITE_MULTIPLEX_EXT_FMT, iChunk);
      *rc = pOrigVfs->xOpen(pOrigVfs, pGroup->zName, pSubOpen, pGroup->flags, pOutFlags);
      if( *rc==SQLITE_OK ){
        pGroup->bOpen[iChunk] = -1;
        return pSubOpen;
      }
      return NULL;
    }
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  UNUSED_PARAMETER(pVfs);

  multiplexEnter();
  memcpy(gMultiplex.zName, zName, nName+1);
  for(i=0; i<gMultiplex.nMaxChunks; i++){
    int rc2;
    int exists = 0;
    if( i ) sqlite3_snprintf(nName+6, gMultiplex.zName+nName, "-%04d", i);
    rc2 = pOrigVfs->xAccess(pOrigVfs, gMultiplex.zName, SQLITE_ACCESS_EXISTS, &exists);
    if( rc2==SQLITE_OK && exists){
      /* if it exists, delete it */
      rc2 = pOrigVfs->xDelete(pOrigVfs, gMultiplex.zName, syncDir);
      if( rc2!=SQLITE_OK ) rc = rc2;
    }else{
      /* stop at first "gap" */







|







238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  UNUSED_PARAMETER(pVfs);

  multiplexEnter();
  memcpy(gMultiplex.zName, zName, nName+1);
  for(i=0; i<gMultiplex.nMaxChunks; i++){
    int rc2;
    int exists = 0;
    if( i ) sqlite3_snprintf(nName+6, gMultiplex.zName+nName, SQLITE_MULTIPLEX_EXT_FMT, i);
    rc2 = pOrigVfs->xAccess(pOrigVfs, gMultiplex.zName, SQLITE_ACCESS_EXISTS, &exists);
    if( rc2==SQLITE_OK && exists){
      /* if it exists, delete it */
      rc2 = pOrigVfs->xDelete(pOrigVfs, gMultiplex.zName, syncDir);
      if( rc2!=SQLITE_OK ) rc = rc2;
    }else{
      /* stop at first "gap" */
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388
389
  /* delete the chunks above the truncate limit */
  for(i=(int)(size/gMultiplex.nChunkSize)+1; i<gMultiplex.nMaxChunks; i++){
    /* close any open chunks before deleting them */
    if( pGroup->bOpen[i] ){
      pSubOpen = pGroup->pReal[i];
      rc2 = pSubOpen->pMethods->xClose(pSubOpen);
      if( rc2!=SQLITE_OK ) rc = SQLITE_IOERR_TRUNCATE;

    }
    sqlite3_snprintf(pGroup->nName+6, pGroup->zName+pGroup->nName, "-%04d", i);
    rc2 = pOrigVfs->xDelete(pOrigVfs, pGroup->zName, 0);
    if( rc2!=SQLITE_OK ) rc = SQLITE_IOERR_TRUNCATE;
  }
  pSubOpen = multiplexSubOpen(p, (int)(size/gMultiplex.nChunkSize), &rc2, NULL);
  if( pSubOpen ){
    rc2 = pSubOpen->pMethods->xTruncate(pSubOpen, size%gMultiplex.nChunkSize);
    if( rc2!=SQLITE_OK ) rc = rc2;







>

|







375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  /* delete the chunks above the truncate limit */
  for(i=(int)(size/gMultiplex.nChunkSize)+1; i<gMultiplex.nMaxChunks; i++){
    /* close any open chunks before deleting them */
    if( pGroup->bOpen[i] ){
      pSubOpen = pGroup->pReal[i];
      rc2 = pSubOpen->pMethods->xClose(pSubOpen);
      if( rc2!=SQLITE_OK ) rc = SQLITE_IOERR_TRUNCATE;
      pGroup->bOpen[i] = 0;
    }
    sqlite3_snprintf(pGroup->nName+6, pGroup->zName+pGroup->nName, SQLITE_MULTIPLEX_EXT_FMT, i);
    rc2 = pOrigVfs->xDelete(pOrigVfs, pGroup->zName, 0);
    if( rc2!=SQLITE_OK ) rc = SQLITE_IOERR_TRUNCATE;
  }
  pSubOpen = multiplexSubOpen(p, (int)(size/gMultiplex.nChunkSize), &rc2, NULL);
  if( pSubOpen ){
    rc2 = pSubOpen->pMethods->xTruncate(pSubOpen, size%gMultiplex.nChunkSize);
    if( rc2!=SQLITE_OK ) rc = rc2;
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
    /* if not opened already, check to see if the chunk exists */
    if( pGroup->bOpen[i] ){
      pSubOpen = pGroup->pReal[i];
    }else{
      sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs;   /* Real VFS */
      int exists = 0;
      pGroup->zName[pGroup->nName] = '\0';
      if( i ) sqlite3_snprintf(pGroup->nName+6, pGroup->zName+pGroup->nName, "-%04d", i);
      rc2 = pOrigVfs->xAccess(pOrigVfs, pGroup->zName, SQLITE_ACCESS_EXISTS, &exists);
      if( rc2==SQLITE_OK && exists){
        /* if it exists, open it */
        pSubOpen = multiplexSubOpen(p, i, &rc, NULL);
      }else{
        /* stop at first "gap" */
        break;







|







432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
    /* if not opened already, check to see if the chunk exists */
    if( pGroup->bOpen[i] ){
      pSubOpen = pGroup->pReal[i];
    }else{
      sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs;   /* Real VFS */
      int exists = 0;
      pGroup->zName[pGroup->nName] = '\0';
      if( i ) sqlite3_snprintf(pGroup->nName+6, pGroup->zName+pGroup->nName, SQLITE_MULTIPLEX_EXT_FMT, i);
      rc2 = pOrigVfs->xAccess(pOrigVfs, pGroup->zName, SQLITE_ACCESS_EXISTS, &exists);
      if( rc2==SQLITE_OK && exists){
        /* if it exists, open it */
        pSubOpen = multiplexSubOpen(p, i, &rc, NULL);
      }else{
        /* stop at first "gap" */
        break;
Changes to test/multiplex.test.
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
#   multiplex-2.4.*: Try to shutdown the multiplex system before closing the db
#                file. Check that this fails and the multiplex system still works
#                afterwards. Then close the database and successfully shut
#                down the multiplex system.
#
#   multiplex-2.5.*: More reading/writing.
#
#   multiplex-2.6.*: More reading/writing with varying small chunk sizes.


sqlite3_multiplex_initialize "" 1
multiplex_set 32768 16

do_test multiplex-2.1.2 {
  sqlite3 db test.db
  execsql {







|
>







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#   multiplex-2.4.*: Try to shutdown the multiplex system before closing the db
#                file. Check that this fails and the multiplex system still works
#                afterwards. Then close the database and successfully shut
#                down the multiplex system.
#
#   multiplex-2.5.*: More reading/writing.
#
#   multiplex-2.6.*: More reading/writing with varying small chunk sizes, as
#                well as varying journal mode.

sqlite3_multiplex_initialize "" 1
multiplex_set 32768 16

do_test multiplex-2.1.2 {
  sqlite3 db test.db
  execsql {
176
177
178
179
180
181
182


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229

do_test multiplex-2.5.99 {
  db close
  sqlite3_multiplex_shutdown
} {SQLITE_OK}




for {set sz 151} {$sz<8000} {set sz [expr $sz+419]} {

  do_test multiplex-2.6.1.$sz {
    multiplex_delete test.db
    sqlite3_multiplex_initialize "" 1
    multiplex_set $sz 32
  } {SQLITE_OK}

  do_test multiplex-2.6.2.$sz {
    sqlite3 db test.db
    execsql {
      PRAGMA page_size = 1024;
      PRAGMA journal_mode = delete;
      PRAGMA auto_vacuum = off;
      CREATE TABLE t1(a PRIMARY KEY, b);
    }

  } {delete}

  do_test multiplex-2.6.3.$sz { 
    execsql { 

      INSERT INTO t1 VALUES(1, 'one');
      INSERT INTO t1 VALUES(2, randomblob($g_chunk_size));
    }
  } {}

  do_test multiplex-2.6.4.$sz {
    db eval {SELECT b FROM t1 WHERE a=1}
  } {one}

  do_test multiplex-2.6.5.$sz {
    db eval {SELECT length(b) FROM t1 WHERE a=2}
  } [list $g_chunk_size]

  do_test multiplex-2.6.6.$sz { file size test.db } [list $g_chunk_size]

  do_test multiplex-2.6.99.$sz {
    db close
    sqlite3_multiplex_shutdown
  } {SQLITE_OK}


}

#-------------------------------------------------------------------------
# Try some tests with more than one connection to a database file. Still
# in rollback mode.
#
#   multiplex-3.1.*: Two connections to a single database file.







>
>
|

|
|
|
|
|

|
|
|
|
<
|
<
|
>
|

|
|
>
|
|
|
|

|
|
|

|
|
|

|

|
|
|
|

>







177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

do_test multiplex-2.5.99 {
  db close
  sqlite3_multiplex_shutdown
} {SQLITE_OK}


set all_journal_modes {delete persist truncate memory off}
foreach jmode $all_journal_modes {
  for {set sz 151} {$sz<8000} {set sz [expr $sz+419]} {

    do_test multiplex-2.6.1.$sz.$jmode {
      multiplex_delete test.db
      sqlite3_multiplex_initialize "" 1
      multiplex_set $sz 32
    } {SQLITE_OK}

    do_test multiplex-2.6.2.$sz.$jmode {
      sqlite3 db test.db
      db eval {
        PRAGMA page_size = 1024;

        PRAGMA auto_vacuum = off;

      }
      db eval "PRAGMA journal_mode = $jmode;"
    } $jmode

    do_test multiplex-2.6.3.$sz.$jmode { 
      execsql { 
        CREATE TABLE t1(a PRIMARY KEY, b);
        INSERT INTO t1 VALUES(1, 'one');
        INSERT INTO t1 VALUES(2, randomblob($g_chunk_size));
      }
    } {}

    do_test multiplex-2.6.4.$sz.$jmode {
      db eval {SELECT b FROM t1 WHERE a=1}
    } {one}

    do_test multiplex-2.6.5.$sz.$jmode {
      db eval {SELECT length(b) FROM t1 WHERE a=2}
    } [list $g_chunk_size]

    do_test multiplex-2.6.6.$sz.$jmode { file size test.db } [list $g_chunk_size]

    do_test multiplex-2.6.99.$sz.$jmode {
      db close
      sqlite3_multiplex_shutdown
    } {SQLITE_OK}

  }
}

#-------------------------------------------------------------------------
# Try some tests with more than one connection to a database file. Still
# in rollback mode.
#
#   multiplex-3.1.*: Two connections to a single database file.