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

Overview
Comment:Add a checksum to the database header.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cba26fd7ccc5d66908713926f8eae03e0dc11a9b
User & Date: dan 2013-11-15 09:44:58.991
Context
2013-11-15
18:47
Various fixes so that the "bt" permutation test passes. check-in: 0866df185c user: dan tags: trunk
09:44
Add a checksum to the database header. check-in: cba26fd7cc user: dan tags: trunk
2013-11-14
19:29
Fix various savepoint-related problems in bt. check-in: c633d85c33 user: dan tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btInt.h.
43
44
45
46
47
48
49


50
51
52
53
54
55
56
** Database header fields.
*/
typedef struct BtDbhdr BtDbhdr;
struct BtDbhdr {
  u32 pgsz;                       /* Page size in bytes */
  u32 nPg;                        /* Number of pages in database */
  u32 cookie;                     /* User cookie value (SQL schema cookie) */


};

/*************************************************************************
** Interface to bt_pager.c functionality.
*/
typedef struct BtPage BtPage;
typedef struct BtPager BtPager;







>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
** Database header fields.
*/
typedef struct BtDbhdr BtDbhdr;
struct BtDbhdr {
  u32 pgsz;                       /* Page size in bytes */
  u32 nPg;                        /* Number of pages in database */
  u32 cookie;                     /* User cookie value (SQL schema cookie) */
  u32 padding;                    /* Unused */
  u32 aCksum[2];                  /* Checksum over other fields */
};

/*************************************************************************
** Interface to bt_pager.c functionality.
*/
typedef struct BtPage BtPage;
typedef struct BtPager BtPager;
Changes to src/bt_log.c.
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818

819


820
821
822
823
824

825
826












827
828

829
830
831
832
833
834
835

  aLog[5] = iLast;
  return btLogHashRollback(pLog, btLogFrameHash(pLog, iLast), iLast);
}

static int btLogReadDbhdr(BtLog *pLog, BtDbhdr *pHdr){
  BtLock *p = pLog->pLock;
  int rc;
  i64 nByte;

  rc = p->pVfs->xSize(p->pFd, &nByte);
  if( rc==SQLITE4_OK && nByte>0 ){
    rc = p->pVfs->xRead(p->pFd, 0, pHdr, sizeof(BtDbhdr));
    if( BTLOG_LITTLE_ENDIAN ){
      pHdr->cookie = BYTESWAP32(pHdr->cookie);
      pHdr->nPg = BYTESWAP32(pHdr->nPg);
      pHdr->pgsz = BYTESWAP32(pHdr->pgsz);

    }


    assert( pHdr->pgsz>0 );
  }else{
    memset(pHdr, 0, sizeof(BtDbhdr));
    pHdr->pgsz = BT_DEFAULT_PGSZ;
    pHdr->nPg = 1;

  }













  return rc;
}


/*
** Run log recovery. In other words, read the log file from disk and 
** initialize the shared-memory accordingly.
*/
static int btLogRecover(BtLog *pLog){
  bt_env *pVfs = pLog->pLock->pVfs;







|
|




|
|
|
|
>
|
>
>
|
<
|
|
|
>
|

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

>







802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823

824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851

  aLog[5] = iLast;
  return btLogHashRollback(pLog, btLogFrameHash(pLog, iLast), iLast);
}

static int btLogReadDbhdr(BtLog *pLog, BtDbhdr *pHdr){
  BtLock *p = pLog->pLock;
  int rc;                         /* Return code */
  i64 nByte;                      /* Size of database file in byte */

  rc = p->pVfs->xSize(p->pFd, &nByte);
  if( rc==SQLITE4_OK && nByte>0 ){
    rc = p->pVfs->xRead(p->pFd, 0, pHdr, sizeof(BtDbhdr));
    if( rc==SQLITE4_OK ){
      u32 aCksum[2];
      btLogChecksum(1, pHdr, offsetof(BtDbhdr, aCksum), 0, aCksum);
      if( aCksum[0]==pHdr->aCksum[0] && aCksum[1]==pHdr->aCksum[1] ){
        return SQLITE4_OK;
      }
    }
  }


  memset(pHdr, 0, sizeof(BtDbhdr));
  pHdr->pgsz = BT_DEFAULT_PGSZ;
  pHdr->nPg = 1;
  return rc;
}

static int btLogUpdateDbhdr(BtLog *pLog, u8 *aData){
  BtDbhdr dbhdr;

  dbhdr.cookie = pLog->snapshot.iCookie;
  dbhdr.nPg = pLog->snapshot.nPg;
  dbhdr.pgsz = pLog->snapshot.pgsz;
  dbhdr.padding = 0;
  btLogChecksum(1, &dbhdr, offsetof(BtDbhdr, aCksum), 0, dbhdr.aCksum);

  assert( dbhdr.pgsz>0 );
  memcpy(aData, &dbhdr, sizeof(BtDbhdr));

  return SQLITE4_OK;
}


/*
** Run log recovery. In other words, read the log file from disk and 
** initialize the shared-memory accordingly.
*/
static int btLogRecover(BtLog *pLog){
  bt_env *pVfs = pLog->pLock->pVfs;
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
    + (int)pLog->snapshot.aLog[3] - (int)pLog->snapshot.aLog[2]
    + (pLog->snapshot.aLog[3]!=0)
    + (int)pLog->snapshot.aLog[5] - (int)pLog->snapshot.aLog[4]
    + (pLog->snapshot.aLog[5]!=0)
  ;
}

static int btLogUpdateDbhdr(BtLog *pLog, u8 *aData){
  BtDbhdr dbhdr;

  dbhdr.cookie = pLog->snapshot.iCookie;
  dbhdr.nPg = pLog->snapshot.nPg;
  dbhdr.pgsz = pLog->snapshot.pgsz;

  if( BTLOG_LITTLE_ENDIAN ){
    dbhdr.cookie = BYTESWAP32(dbhdr.cookie);
    dbhdr.nPg = BYTESWAP32(dbhdr.nPg);
    dbhdr.pgsz = BYTESWAP32(dbhdr.pgsz);
    assert( dbhdr.pgsz>0 );
  }
  memcpy(aData, &dbhdr, sizeof(BtDbhdr));

  return SQLITE4_OK;
}

int sqlite4BtLogCheckpoint(BtLog *pLog, int nFrameBuffer){
  BtLock *pLock = pLog->pLock;
  int rc;

  /* Take the CHECKPOINTER lock. */
  rc = sqlite4BtLockCkpt(pLock);
  if( rc==SQLITE4_OK ){







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1712
1713
1714
1715
1716
1717
1718


















1719
1720
1721
1722
1723
1724
1725
    + (int)pLog->snapshot.aLog[3] - (int)pLog->snapshot.aLog[2]
    + (pLog->snapshot.aLog[3]!=0)
    + (int)pLog->snapshot.aLog[5] - (int)pLog->snapshot.aLog[4]
    + (pLog->snapshot.aLog[5]!=0)
  ;
}



















int sqlite4BtLogCheckpoint(BtLog *pLog, int nFrameBuffer){
  BtLock *pLock = pLog->pLock;
  int rc;

  /* Take the CHECKPOINTER lock. */
  rc = sqlite4BtLockCkpt(pLock);
  if( rc==SQLITE4_OK ){
Changes to test/permutations.test.
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#   bt
#   veryquick
#   quick
#   full
#
lappend ::testsuitelist xxx

  # attach.test attach3.test 
  # fkey2.test 
test_suite "bt" -prefix "" -description {
} -files {
  simple3.test

  alter.test alter3.test alter4.test
  analyze.test analyze3.test analyze4.test analyze5.test 
  analyze6.test analyze7.test analyze8.test
  auth.test auth2.test auth3.test auth4.test
  aggerror.test
  attach4.test
  autoindex1.test
  badutf.test badutf2.test
  between.test
  bigrow.test
  bind.test
  blob.test
  boundary1.test boundary2.test boundary3.test boundary4.test







<










|







128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#   bt
#   veryquick
#   quick
#   full
#
lappend ::testsuitelist xxx


  # fkey2.test 
test_suite "bt" -prefix "" -description {
} -files {
  simple3.test

  alter.test alter3.test alter4.test
  analyze.test analyze3.test analyze4.test analyze5.test 
  analyze6.test analyze7.test analyze8.test
  auth.test auth2.test auth3.test auth4.test
  aggerror.test
  attach.test attach3.test attach4.test
  autoindex1.test
  badutf.test badutf2.test
  between.test
  bigrow.test
  bind.test
  blob.test
  boundary1.test boundary2.test boundary3.test boundary4.test