SQLite

Check-in [020a0bda59]
Login

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

Overview
Comment:Fix some OOM-handling issues in the fts5 changes on this branch.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fts5-data-version
Files: files | file ages | folders
SHA1: 020a0bda59fe93b9361ceeed0d5a8ba4177380c8
User & Date: dan 2016-03-17 12:39:56.371
Context
2016-03-19
14:47
Add test file fts5multiclient.test. (check-in: 7832466f91 user: dan tags: fts5-data-version)
2016-03-17
12:39
Fix some OOM-handling issues in the fts5 changes on this branch. (check-in: 020a0bda59 user: dan tags: fts5-data-version)
2016-03-16
20:53
Merge the changes on the reusable-pragma branch into this one. (check-in: 6c4a17b963 user: dan tags: fts5-data-version)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts5/fts5_index.c.
986
987
988
989
990
991
992

993
994
995
996
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022






1023

1024
1025

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

  return pRet;
}

static i64 fts5IndexDataVersion(Fts5Index *p){
  i64 iVersion = 0;


  if( p->pDataVersion==0 ){
    p->rc = fts5IndexPrepareStmt(p, &p->pDataVersion, 
        sqlite3_mprintf("PRAGMA %Q.data_version", p->pConfig->zDb)
    );
    if( p->rc ) return 0;
  }

  if( SQLITE_ROW==sqlite3_step(p->pDataVersion) ){
    iVersion = sqlite3_column_int64(p->pDataVersion, 0);
  }
  p->rc = sqlite3_reset(p->pDataVersion);


  return iVersion;
}

/*
** Read, deserialize and return the structure record.
**
** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
** are over-allocated as described for function fts5StructureDecode() 
** above.
**
** If an error occurs, NULL is returned and an error code left in the
** Fts5Index handle. If an error has already occurred when this function
** is called, it is a no-op.
*/
static Fts5Structure *fts5StructureRead(Fts5Index *p){
  Fts5Structure *pRet;            /* Object to return */

  if( p->pStruct ){






    pRet = p->pStruct;

#ifdef SQLITE_DEBUG
    {

      Fts5Structure *pTest = fts5StructureReadUncached(p);
      if( pTest ){
        int i, j;
        assert_nc( pRet->nSegment==pTest->nSegment );
        assert_nc( pRet->nLevel==pTest->nLevel );
        for(i=0; i<pTest->nLevel; i++){
          assert_nc( pRet->aLevel[i].nMerge==pTest->aLevel[i].nMerge );
          assert_nc( pRet->aLevel[i].nSeg==pTest->aLevel[i].nSeg );
          for(j=0; j<pTest->aLevel[i].nSeg; j++){
            Fts5StructureSegment *p1 = &pTest->aLevel[i].aSeg[j];
            Fts5StructureSegment *p2 = &pRet->aLevel[i].aSeg[j];
            assert_nc( p1->iSegid==p2->iSegid );
            assert_nc( p1->pgnoFirst==p2->pgnoFirst );
            assert_nc( p1->pgnoLast==p2->pgnoLast );
          }
        }
        fts5StructureRelease(pTest);
      }
    }
#endif
  }else{
    pRet = fts5StructureReadUncached(p);
  }

  if( pRet ){
    fts5StructureRef(pRet);
    p->pStruct = pRet;
    p->iStructVersion = fts5IndexDataVersion(p);
  }
  return pRet;
}

static void fts5StructureInvalidate(Fts5Index *p){
  if( p->pStruct ){
    fts5StructureRelease(p->pStruct);
    p->pStruct = 0;







>
|
|
|
|
|
|

|
|
|
|
>


















|
>
>
>
>
>
>
|
>

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

<
<
|
<
|
|
<
<
<







986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033

1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054


1055

1056
1057



1058
1059
1060
1061
1062
1063
1064

  return pRet;
}

static i64 fts5IndexDataVersion(Fts5Index *p){
  i64 iVersion = 0;

  if( p->rc==SQLITE_OK ){
    if( p->pDataVersion==0 ){
      p->rc = fts5IndexPrepareStmt(p, &p->pDataVersion, 
          sqlite3_mprintf("PRAGMA %Q.data_version", p->pConfig->zDb)
          );
      if( p->rc ) return 0;
    }

    if( SQLITE_ROW==sqlite3_step(p->pDataVersion) ){
      iVersion = sqlite3_column_int64(p->pDataVersion, 0);
    }
    p->rc = sqlite3_reset(p->pDataVersion);
  }

  return iVersion;
}

/*
** Read, deserialize and return the structure record.
**
** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
** are over-allocated as described for function fts5StructureDecode() 
** above.
**
** If an error occurs, NULL is returned and an error code left in the
** Fts5Index handle. If an error has already occurred when this function
** is called, it is a no-op.
*/
static Fts5Structure *fts5StructureRead(Fts5Index *p){
  Fts5Structure *pRet;            /* Object to return */

  if( p->pStruct==0 ){
    p->iStructVersion = fts5IndexDataVersion(p);
    if( p->rc==SQLITE_OK ){
      p->pStruct = pRet = fts5StructureReadUncached(p);
    }
    if( p->rc!=SQLITE_OK ) return 0;
    assert( p->iStructVersion!=0 );
    assert( p->pStruct!=0 );
  }
#ifdef SQLITE_DEBUG

  else{
    Fts5Structure *pTest = fts5StructureReadUncached(p);
    if( pTest ){
      int i, j;
      assert_nc( p->pStruct->nSegment==pTest->nSegment );
      assert_nc( p->pStruct->nLevel==pTest->nLevel );
      for(i=0; i<pTest->nLevel; i++){
        assert_nc( p->pStruct->aLevel[i].nMerge==pTest->aLevel[i].nMerge );
        assert_nc( p->pStruct->aLevel[i].nSeg==pTest->aLevel[i].nSeg );
        for(j=0; j<pTest->aLevel[i].nSeg; j++){
          Fts5StructureSegment *p1 = &pTest->aLevel[i].aSeg[j];
          Fts5StructureSegment *p2 = &p->pStruct->aLevel[i].aSeg[j];
          assert_nc( p1->iSegid==p2->iSegid );
          assert_nc( p1->pgnoFirst==p2->pgnoFirst );
          assert_nc( p1->pgnoLast==p2->pgnoLast );
        }
      }
      fts5StructureRelease(pTest);
    }
  }
#endif




  pRet = p->pStruct;
  fts5StructureRef(pRet);



  return pRet;
}

static void fts5StructureInvalidate(Fts5Index *p){
  if( p->pStruct ){
    fts5StructureRelease(p->pStruct);
    p->pStruct = 0;