/ Check-in [ca757c86]
Login

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

Overview
Comment:Fix further OOM handling cases in LSM.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ca757c8665e27de884086b2aab2bd1db481e2d12f2afe136ec151bf5a0e65b91
User & Date: dan 2017-07-04 19:23:32
Context
2017-07-04
19:34
Add the count-of-view optimization when compiled using SQLITE_COUNTOFVIEW_OPTIMIZATION. check-in: d1ba2002 user: drh tags: trunk
19:23
Fix further OOM handling cases in LSM. check-in: ca757c86 user: dan tags: trunk
17:25
Fix a couple of problems in handling OOM conditions within LSM. check-in: 989a5c17 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/lsm1/lsm_ckpt.c.

  1089   1089   
  1090   1090     assert( n<=LSM_META_RW_PAGE_SIZE );
  1091   1091     memcpy(pShm->aSnap2, p, n);
  1092   1092     lsmShmBarrier(pDb);
  1093   1093     memcpy(pShm->aSnap1, p, n);
  1094   1094     lsmFree(pDb->pEnv, p);
  1095   1095   
  1096         -  assert( lsmFsIntegrityCheck(pDb) );
         1096  +  /* assert( lsmFsIntegrityCheck(pDb) ); */
  1097   1097     return LSM_OK;
  1098   1098   }
  1099   1099   
  1100   1100   /*
  1101   1101   ** This function is used to determine the snapshot-id of the most recently
  1102   1102   ** checkpointed snapshot. Variable ShmHeader.iMetaPage indicates which of
  1103   1103   ** the two meta-pages said snapshot resides on (if any). 

Changes to ext/lsm1/lsm_log.c.

   373    373     rc = lsmFsOpenLog(pDb, 0);
   374    374     if( pDb->pLogWriter==0 ){
   375    375       pNew = lsmMallocZeroRc(pDb->pEnv, sizeof(LogWriter), &rc);
   376    376       if( pNew ){
   377    377         lsmStringInit(&pNew->buf, pDb->pEnv);
   378    378         rc = lsmStringExtend(&pNew->buf, 2);
   379    379       }
          380  +    pDb->pLogWriter = pNew;
   380    381     }else{
   381    382       pNew = pDb->pLogWriter;
   382    383       assert( (u8 *)(&pNew[1])==(u8 *)(&((&pNew->buf)[1])) );
   383    384       memset(pNew, 0, ((u8 *)&pNew->buf) - (u8 *)pNew);
   384    385       pNew->buf.n = 0;
   385    386     }
   386    387   
................................................................................
   464    465       assert( pNew->jump.iStart>pNew->iOff );
   465    466   
   466    467       iRound = firstByteOnSector(pNew, pNew->jump.iStart);
   467    468       if( iRound>pNew->iOff ) pNew->jump.iStart = iRound;
   468    469       pNew->jump.iEnd = lastByteOnSector(pNew, pNew->jump.iEnd);
   469    470     }
   470    471   
   471         -  pDb->pLogWriter = pNew;
          472  +  assert( pDb->pLogWriter==pNew );
   472    473     return rc;
   473    474   }
   474    475   
   475    476   /*
   476    477   ** This function is called when a write-transaction is being closed.
   477    478   ** Parameter bCommit is true if the transaction is being committed,
   478    479   ** or false otherwise. The caller must hold the client-mutex to call

Changes to ext/lsm1/lsm_main.c.

   222    222         pDb->pClient = 0;
   223    223   
   224    224         assertRwclientLockValue(pDb);
   225    225   
   226    226         lsmDbDatabaseRelease(pDb);
   227    227         lsmLogClose(pDb);
   228    228         lsmFsClose(pDb->pFS);
   229         -      assert( pDb->mLock==0 );
          229  +      /* assert( pDb->mLock==0 ); */
   230    230         
   231    231         /* Invoke any destructors registered for the compression or 
   232    232         ** compression factory callbacks.  */
   233    233         if( pDb->factory.xFree ) pDb->factory.xFree(pDb->factory.pCtx);
   234    234         if( pDb->compress.xFree ) pDb->compress.xFree(pDb->compress.pCtx);
   235    235   
   236    236         lsmFree(pDb->pEnv, pDb->rollback.aArray);
................................................................................
   916    916     assert_db_state( pDb );
   917    917   
   918    918     /* A value less than zero means close the innermost nested transaction. */
   919    919     if( iLevel<0 ) iLevel = LSM_MAX(0, pDb->nTransOpen - 1);
   920    920   
   921    921     if( iLevel<pDb->nTransOpen ){
   922    922       if( iLevel==0 ){
          923  +      int rc2;
   923    924         /* Commit the transaction to disk. */
   924    925         if( rc==LSM_OK ) rc = lsmLogCommit(pDb);
   925    926         if( rc==LSM_OK && pDb->eSafety==LSM_SAFETY_FULL ){
   926    927           rc = lsmFsSyncLog(pDb->pFS);
   927    928         }
   928         -      lsmFinishWriteTrans(pDb, (rc==LSM_OK));
          929  +      rc2 = lsmFinishWriteTrans(pDb, (rc==LSM_OK));
          930  +      if( rc==LSM_OK ) rc = rc2;
   929    931       }
   930    932       pDb->nTransOpen = iLevel;
   931    933     }
   932    934     dbReleaseClientSnapshot(pDb);
   933    935     return rc;
   934    936   }
   935    937   

Changes to ext/lsm1/lsm_sorted.c.

  3870   3870     int iFPtr,                      /* Footer ptr for new pages */
  3871   3871     u8 *aWrite,                     /* Write data from this buffer */
  3872   3872     int nWrite                      /* Size of aWrite[] in bytes */
  3873   3873   ){
  3874   3874     int rc = LSM_OK;                /* Return code */
  3875   3875     int nRem = nWrite;              /* Number of bytes still to write */
  3876   3876   
  3877         -  while( nRem>0 ){
         3877  +  while( rc==LSM_OK && nRem>0 ){
  3878   3878       Merge *pMerge = pMW->pLevel->pMerge;
  3879   3879       int nCopy;                    /* Number of bytes to copy */
  3880   3880       u8 *aData;                    /* Pointer to buffer of current output page */
  3881   3881       int nData;                    /* Size of aData[] in bytes */
  3882   3882       int nRec;                     /* Number of records on current output page */
  3883   3883       int iOff;                     /* Offset in aData[] to write to */
  3884   3884   
................................................................................
  5402   5402       rc = doLsmWork(pDb, pDb->nMerge, nRemaining, 0);
  5403   5403       if( rc==LSM_BUSY ) rc = LSM_OK;
  5404   5404   
  5405   5405       if( bRestore && pDb->pCsr ){
  5406   5406         lsmMCursorFreeCache(pDb);
  5407   5407         lsmFreeSnapshot(pDb->pEnv, pDb->pClient);
  5408   5408         pDb->pClient = 0;
  5409         -      rc = lsmCheckpointLoad(pDb, 0);
         5409  +      if( rc==LSM_OK ){
         5410  +        rc = lsmCheckpointLoad(pDb, 0);
         5411  +      }
  5410   5412         if( rc==LSM_OK ){
  5411   5413           rc = lsmCheckpointDeserialize(pDb, 0, pDb->aSnapshot, &pDb->pClient);
  5412   5414         }
  5413   5415         if( rc==LSM_OK ){
  5414   5416           rc = lsmRestoreCursors(pDb);
  5415   5417         }
  5416   5418       }