SQLite

Check-in [8745530b9a]
Login

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

Overview
Comment:Fix a failing assert() in wal.c.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8745530b9a877db77fe2ca3ea9c6bc99ce033055
User & Date: dan 2012-10-15 11:28:24.947
Context
2012-10-15
16:24
Dequote column names generated by the query flattener. (check-in: 5526e0aa3c user: drh tags: trunk)
14:25
Merge all the latest core changes into the sessions branch. (check-in: 76767d651f user: drh tags: sessions)
11:28
Fix a failing assert() in wal.c. (check-in: 8745530b9a user: dan tags: trunk)
2012-10-13
23:16
Ensure that when the source of a backup is a database that is zero bytes in size, the final destination database consists of at least one page. Truncating it to zero bytes is equivalent to zeroing the schema cookie and change counter, which can cause problems for existing clients. (check-in: ca86138bda user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/wal.c.
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
      ** are no outstanding references to any page other than page 1. And
      ** page 1 is never written to the log until the transaction is
      ** committed. As a result, the call to xUndo may not fail.
      */
      assert( walFramePgno(pWal, iFrame)!=1 );
      rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
    }
    walCleanupHash(pWal);
  }
  assert( rc==SQLITE_OK );
  return rc;
}

/* 
** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32 







|







2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
      ** are no outstanding references to any page other than page 1. And
      ** page 1 is never written to the log until the transaction is
      ** committed. As a result, the call to xUndo may not fail.
      */
      assert( walFramePgno(pWal, iFrame)!=1 );
      rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
    }
    if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
  }
  assert( rc==SQLITE_OK );
  return rc;
}

/* 
** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32 
Added test/wal9.test.




















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 2012 October 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# 
# This test case tests that a problem causing a failing assert() has
# been fixed. The problem occurred if a writer process with a subset
# of the *shm file mapped rolled back a transaction begun after the
# entire WAL file was checkpointed into the db file (i.e. a transaction
# that would have restarted the WAL file from the beginning).
#

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

sqlite3 db2 test.db

do_execsql_test 1.0 {
  PRAGMA page_size = 1024;
  PRAGMA journal_mode = WAL;
  PRAGMA wal_autocheckpoint = 0;
  CREATE TABLE t(x);
} {wal 0}

do_test 1.1 { 
  execsql "SELECT * FROM t" db2
} {}

do_execsql_test 1.2 {
  BEGIN;
    INSERT INTO t VALUES(randomblob(100));
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;

    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;

    INSERT INTO t SELECT randomblob(100) FROM t;
    INSERT INTO t SELECT randomblob(100) FROM t;
  COMMIT;
} {}

# Check file sizes are as expected. The real requirement here is that 
# the *shm file is now more than one chunk (>32KiB).
do_test 1.3 { file size test.db     } {1024}
do_test 1.4 { file size test.db-wal } {15421352}
do_test 1.5 { file size test.db-shm } {131072}

do_execsql_test 1.6 { PRAGMA wal_checkpoint } {0 14715 14715}

# At this point connection [db2] has mapped the first 32KB of the *shm file
# only. Because the entire WAL file has been checkpointed, it is not 
# necessary to map any more of the *-shm file to read or write the database
# (since all data will be read directly from the db file). 
#
# However, at one point if a transaction that had not yet written to the 
# WAL file was rolled back an assert() attempting to verify that the entire 
# *-shm file was mapped would fail. If NDEBUG was defined (and the assert() 
# disabled) this bug caused SQLite to ignore the return code of a mmap() 
# call.
#
do_test 1.7 {
  execsql { 
    BEGIN;
      INSERT INTO t VALUES('hello');
    ROLLBACK;
  } db2
} {}
db2 close

finish_test