mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Revise the checksumming algorithm in wal.c. More variable refactoring.
FossilOrigin-Name: 542b90eba6440a0bccef329788fd17a2d3fbeee6
This commit is contained in:
18
manifest
18
manifest
@@ -1,8 +1,8 @@
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C Refactoring\ssome\svariable\snames\sin\swal.c.
|
||||
D 2010-05-19T17:49:50
|
||||
C Revise\sthe\schecksumming\salgorithm\sin\swal.c.\s\sMore\svariable\srefactoring.
|
||||
D 2010-05-19T18:08:11
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@@ -227,7 +227,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
|
||||
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
|
||||
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
|
||||
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
|
||||
F src/wal.c 105bad789a23a495fe134f5ef9dac6d8c06f971d
|
||||
F src/wal.c 5fd5853973652f8a8d81ab1ab7577559f46f3622
|
||||
F src/wal.h 434f76f51225bb614e43ccb6bd2341541ba6a06e
|
||||
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
|
||||
F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
|
||||
@@ -816,14 +816,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P a71a22b52f4570e934063553a81b39268127dc44
|
||||
R 1c999fd53b1df4ca8173c8fb4d6b6989
|
||||
P 1d201ff51f7c5ecdf71a91ed25204b7130894282
|
||||
R d0346b793d27da12b31b3a8952af1c86
|
||||
U drh
|
||||
Z cc4a12a1a16f8ebec7597d63ade72388
|
||||
Z 747ef9a34e0e8619bf7584ee288d56f6
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFL9CTBoxKgR168RlERAlCKAJ4zOxPBD9LXWpD6J1dW7wmEg9tn5QCfTw1j
|
||||
bOeNi5aQREq9/zvmCMu2nsA=
|
||||
=EdxO
|
||||
iD8DBQFL9CkOoxKgR168RlERApEDAJ9DtZ/mpw6bX3TwJ7fVkL3EMPB9pACdF5w5
|
||||
cV3Imcsdjc3PNTWb9PaNKzw=
|
||||
=YSri
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@@ -1 +1 @@
|
||||
1d201ff51f7c5ecdf71a91ed25204b7130894282
|
||||
542b90eba6440a0bccef329788fd17a2d3fbeee6
|
61
src/wal.c
61
src/wal.c
@@ -270,49 +270,24 @@ struct WalIterator {
|
||||
|
||||
/*
|
||||
** Generate an 8 byte checksum based on the data in array aByte[] and the
|
||||
** initial values of aCksum[0] and aCksum[1]. The checksum is written into
|
||||
** aCksum[] before returning.
|
||||
**
|
||||
** The range of bytes to checksum is treated as an array of 32-bit
|
||||
** little-endian unsigned integers. For each integer X in the array, from
|
||||
** start to finish, do the following:
|
||||
**
|
||||
** aCksum[0] += X;
|
||||
** aCksum[1] += aCksum[0];
|
||||
**
|
||||
** For the calculation above, use 64-bit unsigned accumulators. Before
|
||||
** returning, truncate the values to 32-bits as follows:
|
||||
**
|
||||
** aCksum[0] = (u32)(aCksum[0] + (aCksum[0]>>24));
|
||||
** aCksum[1] = (u32)(aCksum[1] + (aCksum[1]>>24));
|
||||
** initial values of aCksum[0] and aCksum[1]. The checksum is written
|
||||
** back into aCksum[] before returning.
|
||||
*/
|
||||
static void walChecksumBytes(u8 *aByte, int nByte, u32 *aCksum){
|
||||
u64 sum1 = aCksum[0];
|
||||
u64 sum2 = aCksum[1];
|
||||
u32 *a32 = (u32 *)aByte;
|
||||
u32 *aEnd = (u32 *)&aByte[nByte];
|
||||
static void walChecksumBytes(u8 *a, int nByte, u32 *aCksum){
|
||||
u32 s1 = aCksum[0];
|
||||
u32 s2 = aCksum[1];
|
||||
u8 *aEnd = (u8*)&a[nByte];
|
||||
|
||||
assert( nByte>=8 );
|
||||
assert( (nByte&0x00000003)==0 );
|
||||
|
||||
if( SQLITE_LITTLEENDIAN ){
|
||||
#ifdef SQLITE_DEBUG
|
||||
u8 *a = (u8 *)a32;
|
||||
assert( *a32==(a[0] + (a[1]<<8) + (a[2]<<16) + (a[3]<<24)) );
|
||||
#endif
|
||||
do {
|
||||
sum1 += *a32;
|
||||
sum2 += sum1;
|
||||
} while( ++a32<aEnd );
|
||||
}else{
|
||||
do {
|
||||
u8 *a = (u8*)a32;
|
||||
sum1 += a[0] + (a[1]<<8) + (a[2]<<16) + (a[3]<<24);
|
||||
sum2 += sum1;
|
||||
} while( ++a32<aEnd );
|
||||
}
|
||||
|
||||
aCksum[0] = sum1 + (sum1>>24);
|
||||
aCksum[1] = sum2 + (sum2>>24);
|
||||
s1 += (a[0]<<24) + (a[2]<<16) + (a[2]<<8) + a[3] + s2;
|
||||
s2 += (a[3]<<24) + (a[5]<<16) + (a[6]<<8) + a[7] + s1;
|
||||
a += 8;
|
||||
}while( a<aEnd );
|
||||
aCksum[0] = s1;
|
||||
aCksum[1] = s2;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -645,7 +620,7 @@ static int walIndexRecover(Wal *pWal){
|
||||
if( nSize>WAL_FRAME_HDRSIZE ){
|
||||
u8 aBuf[WAL_FRAME_HDRSIZE]; /* Buffer to load first frame header into */
|
||||
u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */
|
||||
int nFrame; /* Number of bytes at aFrame */
|
||||
int szFrame; /* Number of bytes in buffer aFrame[] */
|
||||
u8 *aData; /* Pointer to data part of aFrame buffer */
|
||||
int iFrame; /* Index of last frame read */
|
||||
i64 iOffset; /* Next offset to read from log file */
|
||||
@@ -671,8 +646,8 @@ static int walIndexRecover(Wal *pWal){
|
||||
aCksum[1] = sqlite3Get4byte(&aBuf[8]);
|
||||
|
||||
/* Malloc a buffer to read frames into. */
|
||||
nFrame = szPage + WAL_FRAME_HDRSIZE;
|
||||
aFrame = (u8 *)sqlite3_malloc(nFrame);
|
||||
szFrame = szPage + WAL_FRAME_HDRSIZE;
|
||||
aFrame = (u8 *)sqlite3_malloc(szFrame);
|
||||
if( !aFrame ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -680,13 +655,13 @@ static int walIndexRecover(Wal *pWal){
|
||||
|
||||
/* Read all frames from the log file. */
|
||||
iFrame = 0;
|
||||
for(iOffset=WAL_HDRSIZE; (iOffset+nFrame)<=nSize; iOffset+=nFrame){
|
||||
for(iOffset=WAL_HDRSIZE; (iOffset+szFrame)<=nSize; iOffset+=szFrame){
|
||||
u32 pgno; /* Database page number for frame */
|
||||
u32 nTruncate; /* dbsize field from frame header */
|
||||
int isValid; /* True if this frame is valid */
|
||||
|
||||
/* Read and decode the next log frame. */
|
||||
rc = sqlite3OsRead(pWal->pWalFd, aFrame, nFrame, iOffset);
|
||||
rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
|
||||
if( rc!=SQLITE_OK ) break;
|
||||
isValid = walDecodeFrame(aCksum, &pgno, &nTruncate, szPage, aData, aFrame);
|
||||
if( !isValid ) break;
|
||||
|
Reference in New Issue
Block a user