SQLite4
Check-in [80abdbea2d]
Not logged in

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

Overview
Comment:Fix a case in live-recovery from a writer crash.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | range-delete
Files: files | file ages | folders
SHA1: 80abdbea2d23287b5d28e8784d7a3801e9418d7e
User & Date: dan 2012-10-15 19:34:24
Context
2012-10-15
19:36
Merge range-delete branch back into trunk. check-in: a7de625f13 user: dan tags: trunk
19:34
Fix a case in live-recovery from a writer crash. Leaf check-in: 80abdbea2d user: dan tags: range-delete
16:42
Fix an assert() that can fail following an OOM condition. check-in: 8a713f17fc user: dan tags: range-delete
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to lsm-test/lsmtest8.c.

   301    301   }
   302    302   
   303    303   void do_writer_crash_test(const char *zPattern, int *pRc){
   304    304     struct Test {
   305    305       const char *zName;
   306    306       void (*xFunc)(int *);
   307    307     } aTest[] = {
   308         -    { "writercrash2.lsm", doWriterCrash2 },
   309    308       { "writercrash1.lsm", doWriterCrash1 },
          309  +    { "writercrash2.lsm", doWriterCrash2 },
   310    310     };
   311    311     int i;
   312    312     for(i=0; i<ArraySize(aTest); i++){
   313    313       struct Test *p = &aTest[i];
   314    314       if( testCaseBegin(pRc, zPattern, p->zName) ){
   315    315         p->xFunc(pRc);
   316    316         testCaseFinish(*pRc);
   317    317       }
   318    318     }
   319    319   
   320    320   }
   321    321   
   322    322   

Changes to src/lsm_tree.c.

  1173   1173     u32 iShmid;
  1174   1174     ShmChunk *p;
  1175   1175   
  1176   1176     p = treeShmChunkRc(db, db->treehdr.iFirst, &rc);
  1177   1177     iShmid = p->iShmid;
  1178   1178     while( rc==LSM_OK && p ){
  1179   1179       if( p->iNext ){
  1180         -      ShmChunk *pNext = treeShmChunkRc(db, p->iNext, &rc);
  1181         -      if( rc==LSM_OK ){
  1182         -        if( pNext->iShmid!=p->iShmid+1 ){
  1183         -          rc = LSM_CORRUPT_BKPT;
         1180  +      if( p->iNext>=db->treehdr.nChunk ){
         1181  +        rc = LSM_CORRUPT_BKPT;
         1182  +      }else{
         1183  +        ShmChunk *pNext = treeShmChunkRc(db, p->iNext, &rc);
         1184  +        if( rc==LSM_OK ){
         1185  +          if( pNext->iShmid!=p->iShmid+1 ){
         1186  +            rc = LSM_CORRUPT_BKPT;
         1187  +          }
         1188  +          p = pNext;
  1184   1189           }
  1185         -        p = pNext;
  1186   1190         }
  1187   1191       }else{
  1188   1192         p = 0;
  1189   1193       }
  1190   1194       nVisit++;
  1191   1195     }
  1192   1196   
................................................................................
  1262   1266       nSort = 1;
  1263   1267       while( nSort < (db->treehdr.nChunk-1) ) nSort = nSort * 2;
  1264   1268       nByte = sizeof(ShmChunkLoc) * nSort * 2;
  1265   1269       aSort = lsmMallocZeroRc(db->pEnv, nByte, &rc);
  1266   1270       iPrevShmid = pMin->iShmid;
  1267   1271   
  1268   1272       /* Fix all shm-ids, if required. */
  1269         -    if( rc==LSM_OK && iMin!=db->treehdr.iFirst ){
         1273  +    if( rc==LSM_OK ){
  1270   1274         iPrevShmid = pMin->iShmid-1;
  1271   1275         for(i=1; i<db->treehdr.nChunk; i++){
  1272   1276           p = treeShmChunk(db, i);
  1273   1277           aSort[i-1].pShm = p;
  1274   1278           aSort[i-1].iLoc = i;
  1275   1279           if( i!=db->treehdr.iFirst ){
  1276   1280             if( shm_sequence_ge(p->iShmid, db->treehdr.iNextShmid) ){
  1277   1281               p->iShmid = iPrevShmid--;
  1278   1282             }
  1279   1283           }
  1280   1284         }
  1281         -      p = treeShmChunk(db, db->treehdr.iFirst);
  1282         -      p->iShmid = iPrevShmid;
         1285  +      if( iMin!=db->treehdr.iFirst ){
         1286  +        p = treeShmChunk(db, db->treehdr.iFirst);
         1287  +        p->iShmid = iPrevShmid;
         1288  +      }
  1283   1289       }
  1284   1290   
  1285   1291       if( rc==LSM_OK ){
  1286   1292         ShmChunkLoc *aSpace = &aSort[nSort];
  1287   1293         for(i=0; i<nSort; i++){
  1288   1294           if( aSort[i].pShm ){
  1289   1295             assert( shm_sequence_ge(aSort[i].pShm->iShmid, iPrevShmid) );