/ Check-in [020a0bda]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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 | SQL 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
Context
2016-03-19
14:47
Add test file fts5multiclient.test. check-in: 7832466f 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: 020a0bda user: dan tags: fts5-data-version
2016-03-16
20:53
Merge the changes on the reusable-pragma branch into this one. check-in: 6c4a17b9 user: dan tags: fts5-data-version
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_index.c.

   986    986   
   987    987     return pRet;
   988    988   }
   989    989   
   990    990   static i64 fts5IndexDataVersion(Fts5Index *p){
   991    991     i64 iVersion = 0;
   992    992   
   993         -  if( p->pDataVersion==0 ){
   994         -    p->rc = fts5IndexPrepareStmt(p, &p->pDataVersion, 
   995         -        sqlite3_mprintf("PRAGMA %Q.data_version", p->pConfig->zDb)
   996         -    );
   997         -    if( p->rc ) return 0;
          993  +  if( p->rc==SQLITE_OK ){
          994  +    if( p->pDataVersion==0 ){
          995  +      p->rc = fts5IndexPrepareStmt(p, &p->pDataVersion, 
          996  +          sqlite3_mprintf("PRAGMA %Q.data_version", p->pConfig->zDb)
          997  +          );
          998  +      if( p->rc ) return 0;
          999  +    }
         1000  +
         1001  +    if( SQLITE_ROW==sqlite3_step(p->pDataVersion) ){
         1002  +      iVersion = sqlite3_column_int64(p->pDataVersion, 0);
         1003  +    }
         1004  +    p->rc = sqlite3_reset(p->pDataVersion);
   998   1005     }
   999   1006   
  1000         -  if( SQLITE_ROW==sqlite3_step(p->pDataVersion) ){
  1001         -    iVersion = sqlite3_column_int64(p->pDataVersion, 0);
  1002         -  }
  1003         -  p->rc = sqlite3_reset(p->pDataVersion);
  1004         -
  1005   1007     return iVersion;
  1006   1008   }
  1007   1009   
  1008   1010   /*
  1009   1011   ** Read, deserialize and return the structure record.
  1010   1012   **
  1011   1013   ** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
................................................................................
  1015   1017   ** If an error occurs, NULL is returned and an error code left in the
  1016   1018   ** Fts5Index handle. If an error has already occurred when this function
  1017   1019   ** is called, it is a no-op.
  1018   1020   */
  1019   1021   static Fts5Structure *fts5StructureRead(Fts5Index *p){
  1020   1022     Fts5Structure *pRet;            /* Object to return */
  1021   1023   
  1022         -  if( p->pStruct ){
  1023         -    pRet = p->pStruct;
         1024  +  if( p->pStruct==0 ){
         1025  +    p->iStructVersion = fts5IndexDataVersion(p);
         1026  +    if( p->rc==SQLITE_OK ){
         1027  +      p->pStruct = pRet = fts5StructureReadUncached(p);
         1028  +    }
         1029  +    if( p->rc!=SQLITE_OK ) return 0;
         1030  +    assert( p->iStructVersion!=0 );
         1031  +    assert( p->pStruct!=0 );
         1032  +  }
  1024   1033   #ifdef SQLITE_DEBUG
  1025         -    {
  1026         -      Fts5Structure *pTest = fts5StructureReadUncached(p);
  1027         -      if( pTest ){
  1028         -        int i, j;
  1029         -        assert_nc( pRet->nSegment==pTest->nSegment );
  1030         -        assert_nc( pRet->nLevel==pTest->nLevel );
  1031         -        for(i=0; i<pTest->nLevel; i++){
  1032         -          assert_nc( pRet->aLevel[i].nMerge==pTest->aLevel[i].nMerge );
  1033         -          assert_nc( pRet->aLevel[i].nSeg==pTest->aLevel[i].nSeg );
  1034         -          for(j=0; j<pTest->aLevel[i].nSeg; j++){
  1035         -            Fts5StructureSegment *p1 = &pTest->aLevel[i].aSeg[j];
  1036         -            Fts5StructureSegment *p2 = &pRet->aLevel[i].aSeg[j];
  1037         -            assert_nc( p1->iSegid==p2->iSegid );
  1038         -            assert_nc( p1->pgnoFirst==p2->pgnoFirst );
  1039         -            assert_nc( p1->pgnoLast==p2->pgnoLast );
  1040         -          }
  1041         -        }
  1042         -        fts5StructureRelease(pTest);
  1043         -      }
  1044         -    }
  1045         -#endif
  1046         -  }else{
  1047         -    pRet = fts5StructureReadUncached(p);
  1048         -  }
  1049         -
  1050         -  if( pRet ){
  1051         -    fts5StructureRef(pRet);
  1052         -    p->pStruct = pRet;
  1053         -    p->iStructVersion = fts5IndexDataVersion(p);
  1054         -  }
         1034  +  else{
         1035  +    Fts5Structure *pTest = fts5StructureReadUncached(p);
         1036  +    if( pTest ){
         1037  +      int i, j;
         1038  +      assert_nc( p->pStruct->nSegment==pTest->nSegment );
         1039  +      assert_nc( p->pStruct->nLevel==pTest->nLevel );
         1040  +      for(i=0; i<pTest->nLevel; i++){
         1041  +        assert_nc( p->pStruct->aLevel[i].nMerge==pTest->aLevel[i].nMerge );
         1042  +        assert_nc( p->pStruct->aLevel[i].nSeg==pTest->aLevel[i].nSeg );
         1043  +        for(j=0; j<pTest->aLevel[i].nSeg; j++){
         1044  +          Fts5StructureSegment *p1 = &pTest->aLevel[i].aSeg[j];
         1045  +          Fts5StructureSegment *p2 = &p->pStruct->aLevel[i].aSeg[j];
         1046  +          assert_nc( p1->iSegid==p2->iSegid );
         1047  +          assert_nc( p1->pgnoFirst==p2->pgnoFirst );
         1048  +          assert_nc( p1->pgnoLast==p2->pgnoLast );
         1049  +        }
         1050  +      }
         1051  +      fts5StructureRelease(pTest);
         1052  +    }
         1053  +  }
         1054  +#endif
         1055  +
         1056  +  pRet = p->pStruct;
         1057  +  fts5StructureRef(pRet);
  1055   1058     return pRet;
  1056   1059   }
  1057   1060   
  1058   1061   static void fts5StructureInvalidate(Fts5Index *p){
  1059   1062     if( p->pStruct ){
  1060   1063       fts5StructureRelease(p->pStruct);
  1061   1064       p->pStruct = 0;