]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Additional test cases; Round chunk size up to a multiple of max page size;
authorshaneh <shaneh@noemail.net>
Thu, 31 Mar 2011 05:31:24 +0000 (05:31 +0000)
committershaneh <shaneh@noemail.net>
Thu, 31 Mar 2011 05:31:24 +0000 (05:31 +0000)
FossilOrigin-Name: 36e364a3fe7d3a9a521189ff0262611a492c21dc

manifest
manifest.uuid
src/test_multiplex.c
src/test_multiplex.h
test/multiplex.test

index 66152d91b4037af0ff36c7fc4e627a6b4776ce95..266e9254d8db88c7f6ad6c20ff37d22749be0de8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Updates\sto\smultiplex.test\sscript;\s\smisc.\sbug\sfixes;
-D 2011-03-30T21:03:07.666
+C Additional\stest\scases;\s\sRound\schunk\ssize\sup\sto\sa\smultiple\sof\smax\spage\ssize;
+D 2011-03-31T05:31:24.274
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -209,8 +209,8 @@ F src/test_intarray.h 489edb9068bb926583445cb02589344961054207
 F src/test_journal.c 785edd54f963aefb3c1628124170a56697c68c70
 F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e
 F src/test_malloc.c fd6188b1501c0010fb4241ddc9f0d5ac402c688d
-F src/test_multiplex.c aa5da1f2847d6d6e69a41a6d8a9242860549258f
-F src/test_multiplex.h 22238a3286817918f1975a7c523827ea45d9fbb4
+F src/test_multiplex.c 6edf785c1ca9468f7d5ead21e73aeec350931588
+F src/test_multiplex.h 7bb4e7505e38996125d346177eab7ac4f8a2cbef
 F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e
 F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec
 F src/test_osinst.c f408c6a181f2fb04c56273afd5c3e1e82f60392c
@@ -576,7 +576,7 @@ F test/misc5.test 45b2e3ed5f79af2b4f38ae362eaf4c49674575bd
 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
 F test/misc7.test 29032efcd3d826fbd409e2a7af873e7939f4a4e3
 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
-F test/multiplex.test 5e03b40ebdee38d5a75ebbf38a469abede9414de
+F test/multiplex.test e58dbe5b5a3b84a1f5b96408e29efdcd6f833f16
 F test/mutex1.test 78b2b9bb320e51d156c4efdb71b99b051e7a4b41
 F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
 F test/nan.test a44e04df1486fcfb02d32468cbcd3c8e1e433723
@@ -914,7 +914,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P bc02d0c193225bd49a8d8a3295aeac752d3c2e30
-R 48cf934a82b0a69cbaf131357eaf96fa
+P c41ff2358e8af0fe2186ab4173b81fba204a57ab
+R 038c75157e031b60cfa85be2f04c19c6
 U shaneh
-Z e448ef64d054580e4db4bcfd141ad84b
+Z 4af569247c03e0c4e633f1be2df20cf9
index 78855b3796fe6a2833c07264cdb4ca3b8763dcf1..661c0bd7e0709833164fa0cb8911c566d560671c 100644 (file)
@@ -1 +1 @@
-c41ff2358e8af0fe2186ab4173b81fba204a57ab
\ No newline at end of file
+36e364a3fe7d3a9a521189ff0262611a492c21dc
\ No newline at end of file
index a1768f0c4b24e127d1897f1dd3926c02df2a3cf5..ff3be685093f573c5ea198f3cc7b6e2bb9914e7b 100644 (file)
 #include "sqliteInt.h"
 #include "test_multiplex.h"
 
+#ifndef SQLITE_CORE
+  #define SQLITE_CORE 1  /* Disable the API redefinition in sqlite3ext.h */
+#endif
+#include "sqlite3ext.h"
+
 /*
 ** For a build without mutexes, no-op the mutex calls.
 */
 #define SQLITE_MULTIPLEX_VFS_NAME "multiplex"
 
 /* This is the limit on the chunk size.  It may be changed by calling
-** the xFileControl() interface.
+** the xFileControl() interface.  It will be rounded up to a 
+** multiple of SQLITE_MAX_PAGE_SIZE.
 */
-#define SQLITE_MULTIPLEX_CHUNK_SIZE 0x40000000
+#define SQLITE_MULTIPLEX_CHUNK_SIZE (SQLITE_MAX_PAGE_SIZE*32)
 /* Default limit on number of chunks.  Care should be taken
 ** so that values for chunks numbers fit in the SQLITE_MULTIPLEX_EXT_FMT
 ** format specifier. It may be changed by calling
@@ -199,12 +205,28 @@ static void multiplexControlFunc(
 ){
   extern const char *sqlite3TestErrorName(int);
   extern int multiplexFileControl(sqlite3_file *, int, void *);
-  sqlite3_file *db = (sqlite3_file *)sqlite3_user_data(context);
+  // pPager->fd
+  sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
   int op = sqlite3_value_int(argv[0]);
   int iVal = sqlite3_value_int(argv[1]);
-  int rc = multiplexFileControl(db, op, &iVal);
-  if( rc== 0 ){
-    sqlite3_result_text(context, (char *)sqlite3TestErrorName(rc), -1, SQLITE_TRANSIENT);
+  int rc = SQLITE_OK;
+  switch( op ){
+    case 1: 
+      op = MULTIPLEX_CTRL_ENABLE; 
+      break;
+    case 2: 
+      op = MULTIPLEX_CTRL_SET_CHUNK_SIZE; 
+      break;
+    case 3: 
+      op = MULTIPLEX_CTRL_SET_MAX_CHUNKS; 
+      break;
+    default:
+      rc = SQLITE_ERROR;
+      break;
+  }
+  if( rc==SQLITE_OK ){
+    sqlite3_file *f = (sqlite3_file *)db;
+    rc = multiplexFileControl(f, op, &iVal);
   }
   sqlite3_result_text(context, (char *)sqlite3TestErrorName(rc), -1, SQLITE_TRANSIENT);
 }
@@ -213,7 +235,9 @@ static void multiplexControlFunc(
 ** This is the entry point to register the extension for the multiplex_control() function.
 */
 static int multiplexFuncInit(
-  sqlite3 *db
+  sqlite3 *db, 
+  char **pzErrMsg, 
+  const sqlite3_api_routines *pApi
 ){
   int rc;
   rc = sqlite3_create_function(db, "multiplex_control", 2, SQLITE_ANY, 
@@ -663,9 +687,12 @@ static int multiplexFileControl(sqlite3_file *pConn, int op, void *pArg){
     case MULTIPLEX_CTRL_SET_CHUNK_SIZE:
       if( pArg ) {
         int nChunkSize = *(int *)pArg;
-        if( nChunkSize<32 ){ 
+        if( nChunkSize<1 ){
           rc = SQLITE_MISUSE;
         }else{
+          /* Round up to nearest multiple of SQLITE_MAX_PAGE_SIZE. */
+          nChunkSize = (nChunkSize + (SQLITE_MAX_PAGE_SIZE-1));
+          nChunkSize &= ~(SQLITE_MAX_PAGE_SIZE-1);
           pGroup->nChunkSize = nChunkSize;
           rc = SQLITE_OK;
         }
@@ -674,7 +701,7 @@ static int multiplexFileControl(sqlite3_file *pConn, int op, void *pArg){
     case MULTIPLEX_CTRL_SET_MAX_CHUNKS:
       if( pArg ) {
         int nMaxChunks = *(int *)pArg;
-        if(( nMaxChunks<1 ) || ( nMaxChunks>99 )){
+        if(( nMaxChunks<1 ) || ( nMaxChunks>SQLITE_MULTIPLEX_MAX_CHUNKS )){
           rc = SQLITE_MISUSE;
         }else{
           pGroup->nMaxChunks = nMaxChunks;
@@ -781,9 +808,10 @@ static int multiplexShmUnmap(sqlite3_file *pConn, int deleteFlag){
 
 /************************** Public Interfaces *****************************/
 /*
-** Initialize the multiplex VFS shim.  Use the VFS named zOrigVfsName
-** as the VFS that does the actual work.  Use the default if
-** zOrigVfsName==NULL.  
+** CAPI: Initialize the multiplex VFS shim - sqlite3_multiplex_initialize()
+**
+** Use the VFS named zOrigVfsName as the VFS that does the actual work.  
+** Use the default if zOrigVfsName==NULL.  
 **
 ** The multiplex VFS shim is named "multiplex".  It will become the default
 ** VFS if makeDefault is non-zero.
@@ -853,7 +881,7 @@ int sqlite3_multiplex_initialize(const char *zOrigVfsName, int makeDefault){
 }
 
 /*
-** Shutdown the multiplex system.
+** CAPI: Shutdown the multiplex system - sqlite3_multiplex_shutdown()
 **
 ** All SQLite database connections must be closed before calling this
 ** routine.
index cc56ee92e455c54e2d98f063f3e78983214ccef0..a277e7afdb5949279898c0da028285f66ad71829 100644 (file)
@@ -34,7 +34,9 @@
 **
 ** MULTIPLEX_CTRL_SET_CHUNK_SIZE:
 **   This file control is used to set the maximum allowed chunk 
-**   size for a multiplex file set.
+**   size for a multiplex file set.  The chunk size should be 
+**   a multiple of SQLITE_MAX_PAGE_SIZE, and will be rounded up
+**   if not.
 **
 ** MULTIPLEX_CTRL_SET_MAX_CHUNKS:
 **   This file control is used to set the maximum number of chunks
 #define MULTIPLEX_CTRL_SET_CHUNK_SIZE  214015
 #define MULTIPLEX_CTRL_SET_MAX_CHUNKS  214016
 
+/*
+** CAPI: Initialize the multiplex VFS shim - sqlite3_multiplex_initialize()
+**
+** Use the VFS named zOrigVfsName as the VFS that does the actual work.  
+** Use the default if zOrigVfsName==NULL.  
+**
+** The multiplex VFS shim is named "multiplex".  It will become the default
+** VFS if makeDefault is non-zero.
+**
+** An auto-extension is registered which will make the function 
+** multiplex_control() available to open database connections.  This
+** function gives access to the xFileControl interface of the 
+** multiplex VFS shim.
+**
+** multiplex_control(<op>,<val>) 
+** 
+**   <op>=1 MULTIPLEX_CTRL_ENABLE
+**   <val>=1 enable
+**   <val>=2 disable
+** 
+**   <op>=1 MULTIPLEX_CTRL_SET_CHUNK_SIZE
+**   <val> int, chunk size
+** 
+**   <op>=1 MULTIPLEX_CTRL_SET_MAX_CHUNKS
+**   <val> int, max chunks
+**
+** THIS ROUTINE IS NOT THREADSAFE.  Call this routine exactly once
+** during start-up.
+*/
+extern int sqlite3_multiplex_initialize(const char *zOrigVfsName, int makeDefault);
+
+/*
+** CAPI: Shutdown the multiplex system - sqlite3_multiplex_shutdown()
+**
+** All SQLite database connections must be closed before calling this
+** routine.
+**
+** THIS ROUTINE IS NOT THREADSAFE.  Call this routine exactly once while
+** shutting down in order to free all remaining multiplex groups.
+*/
+extern int sqlite3_multiplex_shutdown(void);
 
 #endif
index ce76fdfeaba535105cb64f676b200a6fb94a6130..ab84c1e72c017004e2b69a77db9fec3fe3155146 100644 (file)
@@ -36,7 +36,7 @@ proc multiplex_name {name chunk} {
 proc multiplex_set {db name chunk_size max_chunks} {
   global g_chunk_size
   global g_max_chunks
-  set g_chunk_size $chunk_size
+  set g_chunk_size [ expr (($chunk_size+($::SQLITE_MAX_PAGE_SIZE-1)) & ~($::SQLITE_MAX_PAGE_SIZE-1)) ]
   set g_max_chunks $max_chunks
   set rc [catch {sqlite3_multiplex_control $db $name chunk_size $chunk_size} msg]
   if { $rc==0 } { 
@@ -74,15 +74,27 @@ do_test multiplex-1.6 { sqlite3_multiplex_shutdown }               {SQLITE_OK}
 do_test multiplex-1.7 { sqlite3_multiplex_initialize "" 1 }        {SQLITE_OK}
 do_test multiplex-1.8 { sqlite3_multiplex_shutdown }               {SQLITE_OK}
 
-do_test multiplex-1.9  { sqlite3_multiplex_initialize "" 1 }       {SQLITE_OK}
-sqlite3 db test.db
-do_test multiplex-1.10.1 { multiplex_set db main 32768 16 }        {SQLITE_OK}
-do_test multiplex-1.10.2 { multiplex_set db main 32768 -1 }        {SQLITE_MISUSE}
-do_test multiplex-1.10.3 { multiplex_set db main -1 16 }           {SQLITE_MISUSE}
-do_test multiplex-1.10.4 { multiplex_set db main 31 16 }           {SQLITE_MISUSE}
-do_test multiplex-1.10.5 { multiplex_set db main 32768 100 }       {SQLITE_MISUSE}
-db close
-do_test multiplex-1.11 { sqlite3_multiplex_shutdown }              {SQLITE_OK}
+do_test multiplex-1.9.1 { sqlite3_multiplex_initialize "" 1 }     {SQLITE_OK}
+do_test multiplex-1.9.2 { sqlite3 db test.db }                    {}
+do_test multiplex-1.9.3 { multiplex_set db main 32768 16 }        {SQLITE_OK}
+do_test multiplex-1.9.4 { multiplex_set db main 32768 -1 }        {SQLITE_MISUSE}
+do_test multiplex-1.9.5 { multiplex_set db main -1 16 }           {SQLITE_MISUSE}
+do_test multiplex-1.9.6 { multiplex_set db main 31 16 }           {SQLITE_OK}
+do_test multiplex-1.9.7 { multiplex_set db main 32768 100 }       {SQLITE_MISUSE}
+do_test multiplex-1.9.8 { db close }                              {}
+do_test multiplex-1.9.9 { sqlite3_multiplex_shutdown }            {SQLITE_OK}
+
+do_test multiplex-1.10.1 { sqlite3_multiplex_initialize "" 1 }                {SQLITE_OK}
+do_test multiplex-1.10.2 { sqlite3 db test.db }                               {}
+if { 0 } {
+do_test multiplex-1.10.3 { execsql { SELECT multiplex_control(2, 32768); } }  {SQLITE_OK}
+do_test multiplex-1.10.4 { execsql { SELECT multiplex_control(3, -1); } }     {SQLITE_MISUSE}
+do_test multiplex-1.10.5 { execsql { SELECT multiplex_control(2, -1); } }     {SQLITE_MISUSE}
+do_test multiplex-1.10.6 { execsql { SELECT multiplex_control(2, 31); } }     {SQLITE_OK}
+do_test multiplex-1.10.7 { execsql { SELECT multiplex_control(3, 100); } }    {SQLITE_MISUSE}
+}
+do_test multiplex-1.10.8 { db close }                                         {}
+do_test multiplex-1.10.9 { sqlite3_multiplex_shutdown }                       {SQLITE_OK}
 
 #-------------------------------------------------------------------------
 # Some simple warm-body tests with a single database file in rollback 
@@ -171,7 +183,9 @@ do_test multiplex-2.5.3 {
     INSERT INTO t1 VALUES(2, randomblob(4000));
     INSERT INTO t1 VALUES(3, 'three');
     INSERT INTO t1 VALUES(4, randomblob(4000));
-    INSERT INTO t1 VALUES(5, 'five') 
+    INSERT INTO t1 VALUES(5, 'five');
+    INSERT INTO t1 VALUES(6, randomblob($g_chunk_size));
+    INSERT INTO t1 VALUES(7, randomblob($g_chunk_size));
   }
 } {}
 
@@ -479,11 +493,11 @@ if {0==[info exists ::G(perm:presql)] || $::G(perm:presql) == ""} {
     do_test multiplex-5.6.2.$jmode {
       execsql {
         CREATE TABLE t1(a, b);
-        INSERT INTO t1 VALUES(1, randomblob(1100));
-        INSERT INTO t1 VALUES(2, randomblob(1100));
-        INSERT INTO t1 VALUES(3, randomblob(1100));
-        INSERT INTO t1 VALUES(4, randomblob(1100));
-        INSERT INTO t1 VALUES(5, randomblob(1100));
+        INSERT INTO t1 VALUES(1, randomblob(15000));
+        INSERT INTO t1 VALUES(2, randomblob(15000));
+        INSERT INTO t1 VALUES(3, randomblob(15000));
+        INSERT INTO t1 VALUES(4, randomblob(15000));
+        INSERT INTO t1 VALUES(5, randomblob(15000));
       }
       db close
       sqlite3_multiplex_initialize "" 1
@@ -492,7 +506,7 @@ if {0==[info exists ::G(perm:presql)] || $::G(perm:presql) == ""} {
     } {SQLITE_OK}
     do_test multiplex-5.6.3.$jmode {
       catchsql {
-        INSERT INTO t1 VALUES(6, randomblob(1100));
+        INSERT INTO t1 VALUES(6, randomblob(15000));
       }
     } {1 {disk I/O error}}
     do_test multiplex-5.6.4.$jmode {