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

Overview
Comment:Fixes so that tcl tests run with bt.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b7f86e5617e8584549e512faef5e562da2b57875
User & Date: dan 2014-02-08 10:51:16.187
Context
2014-02-14
16:21
Run extra tests with the bt backend. check-in: 1aefe7ef1e user: dan tags: trunk
2014-02-08
10:51
Fixes so that tcl tests run with bt. check-in: b7f86e5617 user: dan tags: trunk
2014-02-05
20:05
Fix a buffer overrun occuring when many overflow pages are recycled by a merge operation. check-in: 28340557fc user: dan tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to lsm-test/lsmtest_main.c.
1

2
3
4
5
6
7
8


#include "lsmtest.h"
#include "stdio.h"
#include "assert.h"
#include "string.h"
#include "stdlib.h"

#include <sqlite3.h>

>







1
2
3
4
5
6
7
8
9

#include <stdarg.h>
#include "lsmtest.h"
#include "stdio.h"
#include "assert.h"
#include "string.h"
#include "stdlib.h"

#include <sqlite3.h>
Changes to src/btInt.h.
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
  /* These are used only by the bt_lock module. */
  BtShared *pShared;              /* Shared by all handles on this file */
  BtLock *pNext;                  /* Next connection using pShared */
  u32 mExclLock;                  /* Mask of exclusive locks held */
  u32 mSharedLock;                /* Mask of shared locks held */
  BtFile *pBtFile;                /* Used to defer close if necessary */

#ifndef NDEBUG
  u8 *aUsed;
#endif
};

struct BtReadSlot {
  u32 iFirst;
  u32 iLast;
};








<

<







332
333
334
335
336
337
338

339

340
341
342
343
344
345
346
  /* These are used only by the bt_lock module. */
  BtShared *pShared;              /* Shared by all handles on this file */
  BtLock *pNext;                  /* Next connection using pShared */
  u32 mExclLock;                  /* Mask of exclusive locks held */
  u32 mSharedLock;                /* Mask of shared locks held */
  BtFile *pBtFile;                /* Used to defer close if necessary */


  u8 *aUsed;

};

struct BtReadSlot {
  u32 iFirst;
  u32 iLast;
};

Changes to src/bt_main.c.
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158
1159
1160
1161
1162
** bNext is true) and Pref() (if bNext is false).
*/
static int btCsrStep(BtCursor *pCsr, int bNext){
  const int pgsz = sqlite4BtPagerPagesize(pCsr->base.pDb->pPager);
  int rc = SQLITE4_OK;
  int bRequireDescent = 0;

  pCsr->ovfl.nKey = 0;
  rc = btCsrReseek(pCsr);
  if( rc==SQLITE4_OK && pCsr->nPg==0 ){
    rc = SQLITE4_NOTFOUND;
  }


  if( (pCsr->bSkipNext && bNext) || (pCsr->bSkipPrev && bNext==0) ){
    pCsr->bSkipPrev = pCsr->bSkipNext = 0;
    return rc;
  }
  pCsr->bSkipPrev = pCsr->bSkipNext = 0;








<




>







1144
1145
1146
1147
1148
1149
1150

1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
** bNext is true) and Pref() (if bNext is false).
*/
static int btCsrStep(BtCursor *pCsr, int bNext){
  const int pgsz = sqlite4BtPagerPagesize(pCsr->base.pDb->pPager);
  int rc = SQLITE4_OK;
  int bRequireDescent = 0;


  rc = btCsrReseek(pCsr);
  if( rc==SQLITE4_OK && pCsr->nPg==0 ){
    rc = SQLITE4_NOTFOUND;
  }
  pCsr->ovfl.nKey = 0;

  if( (pCsr->bSkipNext && bNext) || (pCsr->bSkipPrev && bNext==0) ){
    pCsr->bSkipPrev = pCsr->bSkipNext = 0;
    return rc;
  }
  pCsr->bSkipPrev = pCsr->bSkipNext = 0;

4729
4730
4731
4732
4733
4734
4735

4736
4737
4738
4739
4740

4741
4742

4743
4744
4745
4746
4747
4748
4749
       && 0==btKeyCompare(pKey, nKey, pSKey, nSKey) 
       && btCsrOverflow(pSub)
      ){
        u32 pgno = sqlite4BtPagePgno(pSub->apPage[pSub->nPg-1]);
        int iCell = pSub->aiCell[pSub->nPg-1];

        if( p->aTrunk==0 ){

          rc = btNewBuffer(p->db, &p->aTrunk);
          if( rc==SQLITE4_OK ) memset(p->aTrunk, 0, 8);
          assert( p->nOvfl==0 );
        }else if( p->nOvflPerPage==p->nOvfl ){
          rc = fiWriterFlushOvfl(p, 0);

        }
        if( rc==SQLITE4_OK ){

          btPutU32(&p->aTrunk[8 + p->nOvfl*8], pgno);
          btPutU32(&p->aTrunk[8 + p->nOvfl*8 + 4], iCell);
          p->nOvfl++;
        }
      }
    }
  }







>


<


>


>







4729
4730
4731
4732
4733
4734
4735
4736
4737
4738

4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
       && 0==btKeyCompare(pKey, nKey, pSKey, nSKey) 
       && btCsrOverflow(pSub)
      ){
        u32 pgno = sqlite4BtPagePgno(pSub->apPage[pSub->nPg-1]);
        int iCell = pSub->aiCell[pSub->nPg-1];

        if( p->aTrunk==0 ){
          assert( p->nOvfl==0 );
          rc = btNewBuffer(p->db, &p->aTrunk);
          if( rc==SQLITE4_OK ) memset(p->aTrunk, 0, 8);

        }else if( p->nOvflPerPage==p->nOvfl ){
          rc = fiWriterFlushOvfl(p, 0);
          assert( p->nOvfl==0 );
        }
        if( rc==SQLITE4_OK ){
          assert( p->nOvfl<p->nOvflPerPage );
          btPutU32(&p->aTrunk[8 + p->nOvfl*8], pgno);
          btPutU32(&p->aTrunk[8 + p->nOvfl*8 + 4], iCell);
          p->nOvfl++;
        }
      }
    }
  }
4946
4947
4948
4949
4950
4951
4952

4953
4954
4955
4956
4957
4958
4959
  }

  btCheckPageRefs(db);
  db->bFastInsertOp = 0;
  return rc;
}


void sqlite4BtDebugTree(bt_db *db, int iCall, u32 iRoot){
  BtPage *pPg;
  sqlite4_buffer buf;
  int pgsz;

  pgsz = sqlite4BtPagerPagesize(db->pPager);
  sqlite4_buffer_init(&buf, 0);







>







4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
  }

  btCheckPageRefs(db);
  db->bFastInsertOp = 0;
  return rc;
}

#ifndef NDEBUG
void sqlite4BtDebugTree(bt_db *db, int iCall, u32 iRoot){
  BtPage *pPg;
  sqlite4_buffer buf;
  int pgsz;

  pgsz = sqlite4BtPagerPagesize(db->pPager);
  sqlite4_buffer_init(&buf, 0);
4982
4983
4984
4985
4986
4987
4988

4989
4990
4991
4992
4993
4994
4995
    if( rc!=SQLITE4_OK ) break;

    iSubRoot = btGetU32((const u8*)pK);
    sqlite4BtDebugTree(db, iCall, iSubRoot);
  }
  btCsrReset(&mcsr, 1);
}



/*
** Delete the entry that the cursor currently points to.
*/
int sqlite4BtDelete(bt_cursor *pBase){
  bt_db *db = pBase->pDb;







>







4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
    if( rc!=SQLITE4_OK ) break;

    iSubRoot = btGetU32((const u8*)pK);
    sqlite4BtDebugTree(db, iCall, iSubRoot);
  }
  btCsrReset(&mcsr, 1);
}
#endif   /* ifndef NDEBUG */


/*
** Delete the entry that the cursor currently points to.
*/
int sqlite4BtDelete(bt_cursor *pBase){
  bt_db *db = pBase->pDb;
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
    }

  }

  return rc;
}

#ifndef NDEBUG

static void markBlockAsUsed(
  bt_db *db,
  u32 iBlk,
  u8 *aUsed
){
  if( iBlk ){
    BtDbHdr *pHdr = sqlite4BtPagerDbhdr(db->pPager);







<
<







5216
5217
5218
5219
5220
5221
5222


5223
5224
5225
5226
5227
5228
5229
    }

  }

  return rc;
}



static void markBlockAsUsed(
  bt_db *db,
  u32 iBlk,
  u8 *aUsed
){
  if( iBlk ){
    BtDbHdr *pHdr = sqlite4BtPagerDbhdr(db->pPager);
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
      btControlTransactionDone(db, iCtx);
      pLock->aUsed = 0;
    }
  }

  return SQLITE4_OK;
}
#endif











<


<
<
5411
5412
5413
5414
5415
5416
5417

5418
5419


      btControlTransactionDone(db, iCtx);
      pLock->aUsed = 0;
    }
  }

  return SQLITE4_OK;
}





Changes to src/bt_pager.c.
375
376
377
378
379
380
381
382
383

384

385
386
387
388
389
390
391
  if( nReq<=p->nSavepoint ){
    int i;
    for(i=p->nSavepoint-1; i>=nReq; i--){
      BtSavepoint *pSavepoint = &p->aSavepoint[i];
      BtSavepage *pSavepg;
      BtSavepage *pNext;

      /* Restore the BtDbHdr object to the state it was in at the start of
      ** this savepoint.  */

      memcpy(p->pHdr, &pSavepoint->hdr, sizeof(BtDbHdr));


      /* Loop through each of the BtSavepage objects associated with this
      ** savepoint. Detach them from the BtPage objects and free all
      ** allocated memory.  */
      for(pSavepg=pSavepoint->pSavepage; pSavepg; pSavepg=pNext){
        BtPage *pPg = pSavepg->pPg;
        pNext = pSavepg->pNext;







|
|
>
|
>







375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
  if( nReq<=p->nSavepoint ){
    int i;
    for(i=p->nSavepoint-1; i>=nReq; i--){
      BtSavepoint *pSavepoint = &p->aSavepoint[i];
      BtSavepage *pSavepg;
      BtSavepage *pNext;

      /* If this is a rollback operation, restore the BtDbHdr object to the
      ** state it was in at the start of this savepoint.  */
      if( bRollback ){
        memcpy(p->pHdr, &pSavepoint->hdr, sizeof(BtDbHdr));
      }

      /* Loop through each of the BtSavepage objects associated with this
      ** savepoint. Detach them from the BtPage objects and free all
      ** allocated memory.  */
      for(pSavepg=pSavepoint->pSavepage; pSavepg; pSavepg=pNext){
        BtPage *pPg = pSavepg->pPg;
        pNext = pSavepg->pNext;
432
433
434
435
436
437
438
439

440
441


442
443
444
445
446
447
448


/*
** Close a pager database handle.
*/
int sqlite4BtPagerClose(BtPager *p){
  int rc;


  rc = sqlite4BtLockDisconnect((BtLock*)p, btCheckpoint, btCleanup);



  p->iTransactionLevel = 0;
  btCloseSavepoints(p, 0, 0);
  btPurgeCache(p);
  sqlite4BtLogClose(p->pLog, 0);
  sqlite4_free(p->btl.pEnv, p->zFile);
  sqlite4_free(p->btl.pEnv, p->aSavepoint);
  sqlite4_free(p->btl.pEnv, p);








>
|
|
>
>







434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453


/*
** Close a pager database handle.
*/
int sqlite4BtPagerClose(BtPager *p){
  int rc;

  if( p->btl.pFd ){
    sqlite4BtPagerRollback(p, 0);
  }

  rc = sqlite4BtLockDisconnect((BtLock*)p, btCheckpoint, btCleanup);
  p->iTransactionLevel = 0;
  btCloseSavepoints(p, 0, 0);
  btPurgeCache(p);
  sqlite4BtLogClose(p->pLog, 0);
  sqlite4_free(p->btl.pEnv, p->zFile);
  sqlite4_free(p->btl.pEnv, p->aSavepoint);
  sqlite4_free(p->btl.pEnv, p);
820
821
822
823
824
825
826

827
828
829
830
831
832
833
  if( pRet==0 ){
    rc = btAllocatePage(p, &pRet);
    if( rc==SQLITE4_OK ){
      pRet->pgno = pgno;
      if( pgno<=p->pHdr->nPg ){
        rc = btLoadPageData(p, pRet);
      }else{

        memset(pRet->aData, 0, p->pHdr->pgsz);
      }

      if( rc==SQLITE4_OK ){
        rc = btHashAdd(p, pRet);
      }








>







825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
  if( pRet==0 ){
    rc = btAllocatePage(p, &pRet);
    if( rc==SQLITE4_OK ){
      pRet->pgno = pgno;
      if( pgno<=p->pHdr->nPg ){
        rc = btLoadPageData(p, pRet);
      }else{
        assert( p->iTransactionLevel>=2 );
        memset(pRet->aData, 0, p->pHdr->pgsz);
      }

      if( rc==SQLITE4_OK ){
        rc = btHashAdd(p, pRet);
      }

Changes to test/manydb.test.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# many different databases at the same time without leaking memory.
#
# $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $

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

set N 300
set num_fd_per_openwrite_db 4

# First test how many file descriptors are available for use. To open a
# database for writing SQLite requires 3 file descriptors (the database, the
# journal and the directory).
set filehandles {}
catch {







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# many different databases at the same time without leaking memory.
#
# $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $

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

set N 200
set num_fd_per_openwrite_db 4

# First test how many file descriptors are available for use. To open a
# database for writing SQLite requires 3 file descriptors (the database, the
# journal and the directory).
set filehandles {}
catch {
Changes to test/src4.test.
11
12
13
14
15
16
17

set testdir [file dirname $argv0]
source $testdir/permutations.test

run_test_suite src4
run_test_suite bt

finish_test








>
11
12
13
14
15
16
17
18
set testdir [file dirname $argv0]
source $testdir/permutations.test

run_test_suite src4
run_test_suite bt

finish_test