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

Overview
Comment:Enable assert() checking for lost blocks in compressed database mode.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | compression-hooks
Files: files | file ages | folders
SHA1: 6e7bc9099c0dbd2ac84cc20de6d58889d3b8d963
User & Date: dan 2012-10-26 18:08:42.758
Context
2012-10-27
08:57
Change the format of compressed page records slightly so that the file format supports inserting padding records into sorted runs. check-in: 0b940bfe17 user: dan tags: compression-hooks
2012-10-26
18:08
Enable assert() checking for lost blocks in compressed database mode. check-in: 6e7bc9099c user: dan tags: compression-hooks
17:09
Fix a problem with snapshot initialization. check-in: 8ce567e8be user: dan tags: compression-hooks
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/lsm_file.c.
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
        if( iBlk!=iLastBlk ){
          fsBlockNext(pFS, iBlk, &iBlk);
        }else{
          iBlk = 0;
        }
      }

      if( bExtra && (pSeg->iLastPg % nPagePerBlock)==0 ){
        fsBlockNext(pFS, iLastBlk, &iBlk);
        aUsed[iBlk-1] = 1;
      }
    }
  }
}








|







1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
        if( iBlk!=iLastBlk ){
          fsBlockNext(pFS, iBlk, &iBlk);
        }else{
          iBlk = 0;
        }
      }

      if( pFS->pCompress==0 && bExtra && (pSeg->iLastPg % nPagePerBlock)==0 ){
        fsBlockNext(pFS, iLastBlk, &iBlk);
        aUsed[iBlk-1] = 1;
      }
    }
  }
}

2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
** out-of-range block numbers.
**
** If no errors are found, non-zero is returned. If an error is found, an
** assert() fails.
*/
int lsmFsIntegrityCheck(lsm_db *pDb){
  FileSystem *pFS = pDb->pFS;
  if( pFS->pCompress==0 ){
    int i;
    int j;
    Freelist freelist = {0, 0, 0};
    u8 *aUsed;
    Level *pLevel;
    Snapshot *pWorker = pDb->pWorker;
    int nBlock = pWorker->nBlock;

    aUsed = lsmMallocZero(pDb->pEnv, nBlock);
    if( aUsed==0 ){
      /* Malloc has failed. Since this function is only called within debug
       ** builds, this probably means the user is running an OOM injection test.
       ** Regardless, it will not be possible to run the integrity-check at this
       ** time, so assume the database is Ok and return non-zero. */
      return 1;
    }

    for(pLevel=pWorker->pLevel; pLevel; pLevel=pLevel->pNext){
      int i;
      checkBlocks(pFS, &pLevel->lhs, (pLevel->nRight!=0), nBlock, aUsed);
      for(i=0; i<pLevel->nRight; i++){
        checkBlocks(pFS, &pLevel->aRhs[i], 0, nBlock, aUsed);
      }
    }

    if( pWorker->nFreelistOvfl ){
      int rc = lsmCheckpointOverflowLoad(pDb, &freelist);
      assert( rc==LSM_OK || rc==LSM_NOMEM );
      if( rc!=LSM_OK ) return 1;
    }

    for(j=0; j<2; j++){
      Freelist *pFreelist;
      if( j==0 ) pFreelist = &pWorker->freelist;
      if( j==1 ) pFreelist = &freelist;

      for(i=0; i<pFreelist->nEntry; i++){
        u32 iBlk = pFreelist->aEntry[i].iBlk;
        assert( iBlk<=nBlock );
        assert( aUsed[iBlk-1]==0 );
        aUsed[iBlk-1] = 1;
      }
    }

    for(i=0; i<nBlock; i++) assert( aUsed[i]==1 );

    lsmFree(pDb->pEnv, aUsed);
    lsmFree(pDb->pEnv, freelist.aEntry);
  }

  return 1;
}

#ifndef NDEBUG
/*
** Return true if pPg happens to be the last page in segment pSeg. Or false







<
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|

|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|

|

|
|
<







2016
2017
2018
2019
2020
2021
2022

2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070

2071
2072
2073
2074
2075
2076
2077
** out-of-range block numbers.
**
** If no errors are found, non-zero is returned. If an error is found, an
** assert() fails.
*/
int lsmFsIntegrityCheck(lsm_db *pDb){
  FileSystem *pFS = pDb->pFS;

  int i;
  int j;
  Freelist freelist = {0, 0, 0};
  u8 *aUsed;
  Level *pLevel;
  Snapshot *pWorker = pDb->pWorker;
  int nBlock = pWorker->nBlock;

  aUsed = lsmMallocZero(pDb->pEnv, nBlock);
  if( aUsed==0 ){
    /* Malloc has failed. Since this function is only called within debug
     ** builds, this probably means the user is running an OOM injection test.
     ** Regardless, it will not be possible to run the integrity-check at this
     ** time, so assume the database is Ok and return non-zero. */
    return 1;
  }

  for(pLevel=pWorker->pLevel; pLevel; pLevel=pLevel->pNext){
    int i;
    checkBlocks(pFS, &pLevel->lhs, (pLevel->nRight!=0), nBlock, aUsed);
    for(i=0; i<pLevel->nRight; i++){
      checkBlocks(pFS, &pLevel->aRhs[i], 0, nBlock, aUsed);
    }
  }

  if( pWorker->nFreelistOvfl ){
    int rc = lsmCheckpointOverflowLoad(pDb, &freelist);
    assert( rc==LSM_OK || rc==LSM_NOMEM );
    if( rc!=LSM_OK ) return 1;
  }

  for(j=0; j<2; j++){
    Freelist *pFreelist;
    if( j==0 ) pFreelist = &pWorker->freelist;
    if( j==1 ) pFreelist = &freelist;

    for(i=0; i<pFreelist->nEntry; i++){
      u32 iBlk = pFreelist->aEntry[i].iBlk;
      assert( iBlk<=nBlock );
      assert( aUsed[iBlk-1]==0 );
      aUsed[iBlk-1] = 1;
    }
  }

  for(i=0; i<nBlock; i++) assert( aUsed[i]==1 );

  lsmFree(pDb->pEnv, aUsed);
  lsmFree(pDb->pEnv, freelist.aEntry);


  return 1;
}

#ifndef NDEBUG
/*
** Return true if pPg happens to be the last page in segment pSeg. Or false