Skip to content

Commit

Permalink
Fix error when hitless 'all' in RT
Browse files Browse the repository at this point in the history
Only 'some' hitless must be marked with flag; doing so for 'all' causes
damaged disk chunks written.
Test case added.
That closes #2157
  • Loading branch information
klirichek committed Jun 29, 2021
1 parent 64047aa commit 47b9aeb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/sphinxrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,10 @@ struct RtWordWriter_t

bool m_bKeywordDict;
int m_iWordsCheckpoint;
const ESphHitless m_eHitlessMode = SPH_HITLESS_NONE;

RtWordWriter_t ( CSphTightVector<BYTE> * pWords, CSphVector<RtWordCheckpoint_t> * pCheckpoints,
CSphVector<BYTE> * pKeywordCheckpoints, bool bKeywordDict, int iWordsCheckpoint )
CSphVector<BYTE> * pKeywordCheckpoints, bool bKeywordDict, int iWordsCheckpoint, ESphHitless eHitlessMode )
: m_pWords ( pWords )
, m_pCheckpoints ( pCheckpoints )
, m_pKeywordCheckpoints ( pKeywordCheckpoints )
Expand All @@ -519,14 +520,15 @@ struct RtWordWriter_t
, m_iWords ( 0 )
, m_bKeywordDict ( bKeywordDict )
, m_iWordsCheckpoint ( iWordsCheckpoint )
, m_eHitlessMode ( eHitlessMode )
{
assert ( !m_pWords->GetLength() );
assert ( !m_pCheckpoints->GetLength() );
assert ( !m_pKeywordCheckpoints->GetLength() );
}

RtWordWriter_t ( RtSegment_t * pSeg, bool bKeywordDict, int iWordsCheckpoint )
: RtWordWriter_t ( &pSeg->m_dWords, &pSeg->m_dWordCheckpoints, &pSeg->m_dKeywordCheckpoints, bKeywordDict, iWordsCheckpoint )
RtWordWriter_t ( RtSegment_t * pSeg, bool bKeywordDict, int iWordsCheckpoint, ESphHitless eHitlessMode )
: RtWordWriter_t ( &pSeg->m_dWords, &pSeg->m_dWordCheckpoints, &pSeg->m_dKeywordCheckpoints, bKeywordDict, iWordsCheckpoint, eHitlessMode )
{}

void ZipWord ( const RtWord_t & tWord )
Expand Down Expand Up @@ -566,7 +568,7 @@ struct RtWordWriter_t
const BYTE * pBegin = pWords->Begin();

DWORD uDocs = tWord.m_uDocs;
if ( !tWord.m_bHasHitlist )
if ( !tWord.m_bHasHitlist && m_eHitlessMode==SPH_HITLESS_SOME )
uDocs |= HITLESS_DOC_FLAG;

ZipDword ( pEnd, uDocs );
Expand Down Expand Up @@ -1997,7 +1999,7 @@ void RtAccum_t::CreateSegmentHits ( RtSegment_t * pSeg, int iWordsCheckpoint, ES

RtWord_t tWord;
RtDocWriter_t tOutDoc ( pSeg );
RtWordWriter_t tOutWord ( pSeg, m_bKeywordDict, iWordsCheckpoint );
RtWordWriter_t tOutWord ( pSeg, m_bKeywordDict, iWordsCheckpoint, eHitless );
RtHitWriter_t tOutHit ( pSeg );

const BYTE * pPacketBase = m_bKeywordDict ? GetPackedKeywords() : nullptr;
Expand Down Expand Up @@ -2461,7 +2463,7 @@ void RtIndex_c::DeleteFieldFromDict ( RtSegment_t * pSeg, int iKillField )
dDocs.Reserve ( tInSeg.m_dDocs.GetLength () );
dHits.Reserve ( tInSeg.m_dHits.GetLength () );

RtWordWriter_t tOutWords ( &dWords, &dWordCheckpoints, &dKeywordCheckpoints, m_bKeywordDict, m_iWordsCheckpoint );
RtWordWriter_t tOutWords ( &dWords, &dWordCheckpoints, &dKeywordCheckpoints, m_bKeywordDict, m_iWordsCheckpoint, m_tSettings.m_eHitless );
RtWordReader_t tInWords ( &tInSeg, m_bKeywordDict, m_iWordsCheckpoint, m_tSettings.m_eHitless );

RtWord_t tInWord, tOutWord;
Expand Down Expand Up @@ -2683,7 +2685,7 @@ void RtIndex_c::MergeKeywords ( RtSegment_t & tSeg, const RtSegment_t & tSeg1, c
tSeg.m_dDocs.Reserve ( Max ( tSeg1.m_dDocs.GetLength(), tSeg2.m_dDocs.GetLength() ) );
tSeg.m_dHits.Reserve ( Max ( tSeg1.m_dHits.GetLength(), tSeg2.m_dHits.GetLength() ) );

RtWordWriter_t tOut ( &tSeg, m_bKeywordDict, m_iWordsCheckpoint );
RtWordWriter_t tOut ( &tSeg, m_bKeywordDict, m_iWordsCheckpoint, m_tSettings.m_eHitless );
RtWordReader_t tIn1 ( &tSeg1, m_bKeywordDict, m_iWordsCheckpoint, m_tSettings.m_eHitless );
RtWordReader_t tIn2 ( &tSeg2, m_bKeywordDict, m_iWordsCheckpoint, m_tSettings.m_eHitless );

Expand Down Expand Up @@ -3616,7 +3618,7 @@ bool RtIndex_c::WriteDocs ( SaveDiskDataContext_t & tCtx, CSphWriter & tWriterDi
}

DWORD iDocsCount = iDocs;
if ( !pWord->m_bHasHitlist )
if ( !pWord->m_bHasHitlist && m_tSettings.m_eHitless==SPH_HITLESS_SOME )
iDocsCount |= HITLESS_DOC_FLAG;

tWriterDict.ZipInt ( iDocsCount );
Expand Down
4 changes: 2 additions & 2 deletions test/test_408/model.bin

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test/test_408/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ insert into hit_1(id, title) values (1, 'protest, to teach, to feed, and'), (2,
SELECT * FROM some WHERE MATCH(' tin woodman ') order by id asc; SHOW META;
SELECT * FROM some WHERE MATCH(' "lowered his axe" ') order by id asc; SHOW META;
SELECT * FROM some WHERE MATCH(' "and lowered his axe" ') order by id asc; SHOW META;

flush ramchunk all;
SELECT * FROM all WHERE MATCH(' tin woodman '); SHOW META;
SELECT * FROM all WHERE MATCH(' lowered '); SHOW META;
</sphinxql></queries>

</test>

0 comments on commit 47b9aeb

Please sign in to comment.