/ Check-in [47a7dd92]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix a problem with the deferred page allocation on this branch that could occur when the database file is just slightly smaller than the PENDING_BYTE page offset.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent
Files: files | file ages | folders
SHA3-256: 47a7dd92355ffd74645cf8da8186d5799c05a95907877a09c28de41135deeede
User & Date: dan 2017-05-25 21:02:00
Wiki:begin-concurrent
Context
2017-05-26
16:15
Fix a problem with deferred page allocation in transactions that revert page allocations by savepoint rollbacks. check-in: a4a3bbe6 user: dan tags: begin-concurrent
2017-05-25
21:02
Fix a problem with the deferred page allocation on this branch that could occur when the database file is just slightly smaller than the PENDING_BYTE page offset. check-in: 47a7dd92 user: dan tags: begin-concurrent
2017-05-23
19:23
Add experimental new API sqlite3_wal_info(). check-in: 5b9d498f user: dan tags: begin-concurrent
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/bitvec.c.

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
** and that the value for "i" is within range of the Bitvec object.
** Otherwise the behavior is undefined.
*/
int sqlite3BitvecSet(Bitvec *p, u32 i){
  u32 h;
  if( p==0 ) return SQLITE_OK;
  assert( i>0 );
  /* assert( i<=p->iSize ); */
  if( i>p->iSize ){
    sqlite3_log(SQLITE_ERROR, 
        "Bitvec: setting bit %d of bitvec size %d\n", (int)i, (int)p->iSize
    );
  }
  i--;
  while((p->iSize > BITVEC_NBIT) && p->iDivisor) {







|







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
** and that the value for "i" is within range of the Bitvec object.
** Otherwise the behavior is undefined.
*/
int sqlite3BitvecSet(Bitvec *p, u32 i){
  u32 h;
  if( p==0 ) return SQLITE_OK;
  assert( i>0 );
  assert( i<=p->iSize );
  if( i>p->iSize ){
    sqlite3_log(SQLITE_ERROR, 
        "Bitvec: setting bit %d of bitvec size %d\n", (int)i, (int)p->iSize
    );
  }
  i--;
  while((p->iSize > BITVEC_NBIT) && p->iDivisor) {

Changes to src/btree.c.

4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135

4136
4137
4138
4139
4140
4141
4142
        ** the transaction out to disk. Before doing so though, attempt to
        ** relocate some of the new pages to free locations within the body
        ** of the database file (i.e. free-list entries). */
        if( rc==SQLITE_OK ){
          assert( nCurrent!=PENDING_BYTE_PAGE(pBt) );
          sqlite3PagerSetDbsize(pBt->pPager, nCurrent);
          nFree = get4byte(&p1[36]);
          nFin = MAX(nCurrent-nFree, nHPage);
          if( nCurrent>PENDING_BYTE_PAGE(pBt) && nFin<=PENDING_BYTE_PAGE(pBt) ){
            nFin--;
          }

          rc = btreeRelocateRange(pBt, nFin+1, nCurrent, 0);
        }

        put4byte(&p1[28], nFin);
      }
    }
    sqlite3PagerSetDbsize(pPager, nFin);







|



>







4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
        ** the transaction out to disk. Before doing so though, attempt to
        ** relocate some of the new pages to free locations within the body
        ** of the database file (i.e. free-list entries). */
        if( rc==SQLITE_OK ){
          assert( nCurrent!=PENDING_BYTE_PAGE(pBt) );
          sqlite3PagerSetDbsize(pBt->pPager, nCurrent);
          nFree = get4byte(&p1[36]);
          nFin = nCurrent-nFree;
          if( nCurrent>PENDING_BYTE_PAGE(pBt) && nFin<=PENDING_BYTE_PAGE(pBt) ){
            nFin--;
          }
          nFin = MAX(nFin, nHPage);
          rc = btreeRelocateRange(pBt, nFin+1, nCurrent, 0);
        }

        put4byte(&p1[28], nFin);
      }
    }
    sqlite3PagerSetDbsize(pPager, nFin);

Changes to test/concurrent2.test.

572
573
574
575
576
577
578
579











580































581

  do_test 11.$tn.5 {
    sql1 { PRAGMA wal_checkpoint }
    sql2 { INSERT INTO t1 VALUES(3) }
    code2 { sqlite3_wal_info db2 main }
  } {0 1}
}












































finish_test








>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623

  do_test 11.$tn.5 {
    sql1 { PRAGMA wal_checkpoint }
    sql2 { INSERT INTO t1 VALUES(3) }
    code2 { sqlite3_wal_info db2 main }
  } {0 1}
}

reset_db
do_execsql_test 12.0 {
  PRAGMA journal_mode = wal;
  CREATE TABLE tx(a INTEGER PRIMARY KEY, b);
} {wal}
do_test 12.1 {
  for {set i 0} {$i < 50} {incr i} {
    execsql {
      BEGIN CONCURRENT;
      INSERT INTO tx(b) VALUES( randomblob( 1200 ) );
      COMMIT;
    }
  }
  execsql { PRAGMA page_size }
} {1024}
do_execsql_test 12.2 {
  DELETE FROM tx;
}
do_test 12.3 {
  for {set i 0} {$i < 50} {incr i} {
    execsql {
      BEGIN CONCURRENT;
      INSERT INTO tx(b) VALUES( randomblob( 1200 ) );
      COMMIT;
    }
  }
  execsql { PRAGMA page_size }
} {1024}
do_execsql_test 12.4 {
  DELETE FROM tx;
}
do_test 12.5 {
  execsql { BEGIN CONCURRENT }
  for {set i 0} {$i < 5000} {incr i} {
    execsql {
      INSERT INTO tx(b) VALUES( randomblob( 1200 ) );
    }
  }
  execsql { COMMIT }
  execsql { PRAGMA page_size }
} {1024}


finish_test