SQLite4
Check-in [2f8966cd9c]
Not logged in

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

Overview
Comment:Fixes to lsm_work() to bring it into line with documentation: (a) third argument is a number of KB, not a number of db pages, and (b) passing -1 as the third argument means "do as much work as possible".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2f8966cd9c167b06195a14821a5f8c78f4724a94
User & Date: dan 2013-02-05 18:06:45
Context
2013-02-05
18:32
Fix lsm_checkpoint() and some lsm_info() calls to match documented behaviour. check-in: 89e314d98b user: dan tags: trunk
18:06
Fixes to lsm_work() to bring it into line with documentation: (a) third argument is a number of KB, not a number of db pages, and (b) passing -1 as the third argument means "do as much work as possible". check-in: 2f8966cd9c user: dan tags: trunk
16:03
Change the BLOCK_SIZE, AUTOFLUSH and AUTOCHECKPOINT lsm_config() options to work in KB instead of bytes. This matches the user guide. check-in: 340c9dcd22 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to lsm-test/lsmtest_func.c.

     3      3   
     4      4   
     5      5   int do_work(int nArg, char **azArg){
     6      6     struct Option {
     7      7       const char *zName;
     8      8     } aOpt [] = {
     9      9       { "-nmerge" },
    10         -    { "-npage" },
           10  +    { "-nkb" },
    11     11       { 0 }
    12     12     };
    13     13   
    14     14     lsm_db *pDb;
    15     15     int rc;
    16     16     int i;
    17     17     const char *zDb;
    18     18     int nMerge = 1;
    19         -  int nWork = (1<<30);
           19  +  int nKB = (1<<30);
    20     20   
    21     21     if( nArg==0 ) goto usage;
    22     22     zDb = azArg[nArg-1];
    23     23     for(i=0; i<(nArg-1); i++){
    24     24       int iSel;
    25     25       rc = testArgSelect(aOpt, "option", azArg[i], &iSel);
    26     26       if( rc ) return rc;
................................................................................
    29     29           i++;
    30     30           if( i==(nArg-1) ) goto usage;
    31     31           nMerge = atoi(azArg[i]);
    32     32           break;
    33     33         case 1:
    34     34           i++;
    35     35           if( i==(nArg-1) ) goto usage;
    36         -        nWork = atoi(azArg[i]);
           36  +        nKB = atoi(azArg[i]);
    37     37           break;
    38     38       }
    39     39     }
    40     40   
    41     41     rc = lsm_new(0, &pDb);
    42     42     if( rc!=LSM_OK ){
    43     43       testPrintError("lsm_open(): rc=%d\n", rc);
................................................................................
    47     47         testPrintError("lsm_open(): rc=%d\n", rc);
    48     48       }else{
    49     49         int n = -1;
    50     50         lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &n);
    51     51         n = n*2;
    52     52         lsm_config(pDb, LSM_CONFIG_AUTOCHECKPOINT, &n);
    53     53   
    54         -      rc = lsm_work(pDb, nMerge, nWork, 0);
           54  +      rc = lsm_work(pDb, nMerge, nKB, 0);
    55     55         if( rc!=LSM_OK ){
    56     56           testPrintError("lsm_work(): rc=%d\n", rc);
    57     57         }
    58     58       }
    59     59     }
    60     60     if( rc==LSM_OK ){
    61     61       rc = lsm_checkpoint(pDb, 0);

Changes to src/lsm.h.

   487    487   );
   488    488   
   489    489   /*
   490    490   ** CAPI: Explicit Database Work and Checkpointing
   491    491   **
   492    492   ** This function is called by a thread to work on the database structure.
   493    493   */
   494         -int lsm_work(lsm_db *pDb, int nMerge, int nPage, int *pnWrite);
          494  +int lsm_work(lsm_db *pDb, int nMerge, int nKB, int *pnWrite);
   495    495   
   496    496   int lsm_flush(lsm_db *pDb);
   497    497   
   498    498   /*
   499    499   ** Attempt to checkpoint the current database snapshot. Return an LSM
   500    500   ** error code if an error occurs or LSM_OK otherwise.
   501    501   **

Changes to src/lsm_sorted.c.

  5196   5196   
  5197   5197   static int doLsmWork(lsm_db *pDb, int nMerge, int nPage, int *pnWrite){
  5198   5198     int rc = LSM_OK;                /* Return code */
  5199   5199     int nWrite = 0;                 /* Number of pages written */
  5200   5200   
  5201   5201     assert( nMerge>=1 );
  5202   5202   
  5203         -  if( nPage>0 ){
         5203  +  if( nPage!=0 ){
  5204   5204       int bCkpt = 0;
  5205   5205       do {
  5206   5206         int nThis = 0;
         5207  +      int nReq = (nPage>=0) ? (nPage-nWrite) : ((int)0x7FFFFFFF);
         5208  +
  5207   5209         bCkpt = 0;
  5208         -      rc = doLsmSingleWork(pDb, 0, nMerge, nPage-nWrite, &nThis, &bCkpt);
         5210  +      rc = doLsmSingleWork(pDb, 0, nMerge, nReq, &nThis, &bCkpt);
  5209   5211         nWrite += nThis;
  5210   5212         if( rc==LSM_OK && bCkpt ){
  5211   5213           rc = lsm_checkpoint(pDb, 0);
  5212   5214         }
  5213         -    }while( rc==LSM_OK && (nWrite<nPage && bCkpt) );
         5215  +    }while( rc==LSM_OK && bCkpt && (nWrite<nPage || nPage<0) );
  5214   5216     }
  5215   5217   
  5216   5218     if( pnWrite ){
  5217   5219       if( rc==LSM_OK ){
  5218   5220         *pnWrite = nWrite;
  5219   5221       }else{
  5220   5222         *pnWrite = 0;
................................................................................
  5222   5224     }
  5223   5225     return rc;
  5224   5226   }
  5225   5227   
  5226   5228   /*
  5227   5229   ** Perform work to merge database segments together.
  5228   5230   */
  5229         -int lsm_work(lsm_db *pDb, int nMerge, int nPage, int *pnWrite){
         5231  +int lsm_work(lsm_db *pDb, int nMerge, int nKB, int *pnWrite){
         5232  +  int rc;                         /* Return code */
         5233  +  int nPgsz;                      /* Nominal page size in bytes */
         5234  +  int nPage;                      /* Equivalent of nKB in pages */
         5235  +  int nWrite = 0;                 /* Number of pages written */
  5230   5236   
  5231   5237     /* This function may not be called if pDb has an open read or write
  5232   5238     ** transaction. Return LSM_MISUSE if an application attempts this.  */
  5233   5239     if( pDb->nTransOpen || pDb->pCsr ) return LSM_MISUSE_BKPT;
  5234         -
  5235   5240     if( nMerge<=0 ) nMerge = pDb->nMerge;
  5236         -  return doLsmWork(pDb, nMerge, nPage, pnWrite);
         5241  +
         5242  +  /* Convert from KB to pages */
         5243  +  nPgsz = lsmFsPageSize(pDb->pFS);
         5244  +  if( nKB>=0 ){
         5245  +    nPage = ((i64)nKB * 1024 + nPgsz - 1) / nPgsz;
         5246  +  }else{
         5247  +    nPage = -1;
         5248  +  }
         5249  +
         5250  +  rc = doLsmWork(pDb, nMerge, nPage, &nWrite);
         5251  +  
         5252  +  if( pnWrite ){
         5253  +    /* Convert back from pages to KB */
         5254  +    *pnWrite = (int)(((i64)nWrite * 1024 + nPgsz - 1) / nPgsz);
         5255  +  }
         5256  +  return rc;
  5237   5257   }
  5238   5258   
  5239   5259   int lsm_flush(lsm_db *db){
  5240   5260     int rc;
  5241   5261   
  5242   5262     if( db->nTransOpen>0 || db->pCsr ){
  5243   5263       rc = LSM_MISUSE_BKPT;
................................................................................
  5297   5317       int nRemaining;               /* Units of work to do before returning */
  5298   5318   
  5299   5319       nRemaining = nUnit * nDepth;
  5300   5320   #ifdef LSM_LOG_WORK
  5301   5321       lsmLogMessage(pDb, rc, "lsmSortedAutoWork(): %d*%d = %d pages", 
  5302   5322           nUnit, nDepth, nRemaining);
  5303   5323   #endif
         5324  +    assert( nRemaining>=0 );
  5304   5325       rc = doLsmWork(pDb, pDb->nMerge, nRemaining, 0);
  5305   5326       if( rc==LSM_BUSY ) rc = LSM_OK;
  5306   5327   
  5307   5328       if( bRestore && pDb->pCsr ){
  5308   5329         lsmFreeSnapshot(pDb->pEnv, pDb->pClient);
  5309   5330         pDb->pClient = 0;
  5310   5331         rc = lsmCheckpointLoad(pDb, 0);

Changes to tool/lsmview.tcl.

   397    397   
   398    398     set data [string trim [exec_lsmtest_show -c $myCfg $myDb array-pages $iFirst]]
   399    399     $myText delete 0.0 end
   400    400   
   401    401     # Delete the existing tree entries.
   402    402     $myTree delete [$myTree children {}]
   403    403   
   404         -  set nBlksz [exec_lsmtest_show -c $myCfg $myDb blocksize]
          404  +  set nBlksz [expr [exec_lsmtest_show -c $myCfg $myDb blocksize] * 1024]
   405    405     set nPgsz  [exec_lsmtest_show -c $myCfg $myDb pagesize]
   406    406   
   407    407     if {[regexp {c=1} $myCfg]          || [regexp {co=1} $myCfg]
   408    408      || [regexp {com=1} $myCfg]        || [regexp {comp=1} $myCfg]
   409    409      || [regexp {compr=1} $myCfg]      || [regexp {compres=1} $myCfg]
   410    410      || [regexp {compress=1} $myCfg]   || [regexp {compressi=1} $myCfg]
   411    411      || [regexp {compressio=1} $myCfg] || [regexp {compression=1} $myCfg]

Changes to www/lsmusr.wiki.

  1285   1285   
  1286   1286   <p>Database optimization transforms the contents of database file so that
  1287   1287   the following are true:
  1288   1288   
  1289   1289   <ul>
  1290   1290     <li> <p>All database content is stored in a single 
  1291   1291          <a href=#architectural_overview>segment</a>. This makes the
  1292         -       database effectively equivalent to an optimally packed b-tree stucture
         1292  +       data structure equivalent to an optimally packed b-tree stucture
  1293   1293          for search operations - minimizing the number of disk sectors that need
  1294   1294          to be visted when searching the database.
  1295   1295   
  1296   1296     <li> <p>The database file contains no (or as little as possible) free space.
  1297   1297          In other words, it is no larger than required to contain the single
  1298   1298          segment.
  1299   1299   </ul>
  1300   1300   
  1301   1301   <p>In order to optimize the database, lsm_work() should be called with 
  1302   1302   the nMerge argument set to 1 and the third parameter set to a negative value
  1303         -(interpreted as - keep working until there is no more work to do). For 
         1303  +(interpreted as "keep working until there is no more work to do"). For 
  1304   1304   example:
  1305   1305   
  1306   1306   <verbatim>
  1307   1307     rc = lsm_work(db, 1, -1, 0);
  1308   1308   </verbatim>
  1309   1309   
  1310         -<p><span style=color:red>todo: the -1 as the 3rd argument above is currently
  1311         -not supported</span>
  1312         -
  1313   1310   <p>When optimizing the database as above, either the LSM_CONFIG_AUTOCHECKPOINT
  1314   1311   parameter should be set to a non-zero value or lsm_checkpoint() should be
  1315   1312   called periodically. Otherwise, no checkpoints will be performed, preventing
  1316   1313   the library from reusing any space occupied by old segments even after their
  1317   1314   content has been merged into the new segment. The result - a database file that
  1318   1315   is optimized, except that it is up to twice as large as it otherwise would be.
  1319         -
  1320   1316   
  1321   1317   
  1322   1318