Skip to content

Commit

Permalink
Reractor AquireAccum
Browse files Browse the repository at this point in the history
It is always called with 'this' pointer in params, so let it be included into the declaration of appropriate class instead.
  • Loading branch information
klirichek committed Sep 12, 2018
1 parent 39e5bc3 commit 9742f5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/sphinxrt.cpp
Expand Up @@ -1097,10 +1097,6 @@ CSphFixedVector<int> GetIndexNames ( const VEC & dIndexes, bool bAddNext )
return dNames;
}

/// acquire thread-local indexing accumulator
/// returns NULL if another index already uses it in an open txn
static RtAccum_t * AcquireAccum ( CSphString * sError, ISphRtAccum * pAccExt, bool bSetTLS, ISphRtIndex * pIndex, CSphDict * pDict, bool bWordDict );

/// RAM based index
struct RtQword_t;
struct RtIndex_t : public ISphRtIndex, public ISphNoncopyable, public ISphWordlist, public ISphWordlistSuggest
Expand Down Expand Up @@ -1533,7 +1529,7 @@ bool RtIndex_t::AddDocument ( ISphTokenizer * pTokenizer, int iFields, const cha
}
}

RtAccum_t * pAcc = AcquireAccum ( &sError, pAccExt, true, this, m_pDict, m_bKeywordDict );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt, m_bKeywordDict, true, &sError );
if ( !pAcc )
return false;

Expand Down Expand Up @@ -1604,18 +1600,12 @@ static void AccumCleanup ( void * pArg )
}


RtAccum_t * AcquireAccum ( CSphString * sError, ISphRtAccum * pAccExt, bool bSetTLS, ISphRtIndex * pIndex, CSphDict * pDict, bool bWordDict )
ISphRtAccum * ISphRtIndex::AcquireAccum ( CSphDict * pDict, ISphRtAccum * pAccExt,
bool bWordDict, bool bSetTLS, CSphString* sError )
{
RtAccum_t * pAcc = NULL;
//assert ( pAccExt && !bSetTLS );

// check that no other index is holding the acc
if ( !pAccExt )
pAcc = (RtAccum_t*) sphThreadGet ( g_tTlsAccumKey );
else
pAcc = (RtAccum_t *)pAccExt;
auto pAcc = ( RtAccum_t * ) ( pAccExt ? pAccExt : sphThreadGet ( g_tTlsAccumKey ) );

if ( pAcc && pAcc->GetIndex()!=NULL && pAcc->GetIndex()!=pIndex )
if ( pAcc && pAcc->GetIndex() && pAcc->GetIndex()!=this )
{
if ( sError )
sError->SetSprintf ( "current txn is working with another index ('%s')", pAcc->GetIndex()->GetName() );
Expand All @@ -1632,15 +1622,15 @@ RtAccum_t * AcquireAccum ( CSphString * sError, ISphRtAccum * pAccExt, bool bSet
}
}

assert ( pAcc->GetIndex()==NULL || pAcc->GetIndex()==pIndex );
pAcc->SetIndex ( pIndex );
pAcc->SetupDict ( pIndex, pDict, bWordDict );
assert ( pAcc->GetIndex()==nullptr || pAcc->GetIndex()==this );
pAcc->SetIndex ( this );
pAcc->SetupDict ( this, pDict, bWordDict );
return pAcc;
}

ISphRtAccum * RtIndex_t::CreateAccum ( CSphString & sError )
{
return AcquireAccum ( &sError, NULL, false, this, m_pDict, m_bKeywordDict );
return AcquireAccum ( m_pDict, nullptr, m_bKeywordDict, false, &sError);
}


Expand Down Expand Up @@ -2807,7 +2797,7 @@ void RtIndex_t::Commit ( int * pDeleted, ISphRtAccum * pAccExt )
assert ( g_bRTChangesAllowed );
MEMORY ( MEM_INDEX_RT );

RtAccum_t * pAcc = AcquireAccum ( NULL, pAccExt, true, this, m_pDict, m_bKeywordDict );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt, m_bKeywordDict );
if ( !pAcc )
return;

Expand Down Expand Up @@ -3231,7 +3221,7 @@ void RtIndex_t::RollBack ( ISphRtAccum * pAccExt )
{
assert ( g_bRTChangesAllowed );

RtAccum_t * pAcc = AcquireAccum ( NULL, pAccExt, true, this, m_pDict, m_bKeywordDict );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt, m_bKeywordDict );
if ( !pAcc )
return;

Expand All @@ -3254,7 +3244,7 @@ bool RtIndex_t::DeleteDocument ( const SphDocID_t * pDocs, int iDocs, CSphString
assert ( g_bRTChangesAllowed );
MEMORY ( MEM_RT_ACCUM );

RtAccum_t * pAcc = AcquireAccum ( &sError, pAccExt, true, this, m_pDict, m_bKeywordDict );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt, m_bKeywordDict, true, &sError );
if ( !pAcc )
return false;

Expand Down Expand Up @@ -11100,13 +11090,13 @@ PercolateIndex_c::~PercolateIndex_c ()

ISphRtAccum * PercolateIndex_c::CreateAccum ( CSphString & sError )
{
return AcquireAccum ( &sError, NULL, false, this, m_pDict, true );
return AcquireAccum ( m_pDict, nullptr, true, false, &sError );
}


bool PercolateIndex_c::AddDocument ( ISphTokenizer * pTokenizer, int iFields, const char ** ppFields, const CSphMatch & tDoc, bool , const CSphString & , const char ** ppStr, const CSphVector<DWORD> & dMvas, CSphString & sError, CSphString & sWarning, ISphRtAccum * pAccExt )
{
RtAccum_t * pAcc = AcquireAccum ( &sError, pAccExt, true, this, m_pDict, true );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt, true, true, &sError );
if ( !pAcc )
return false;

Expand Down Expand Up @@ -11854,7 +11844,7 @@ bool PercolateIndex_c::MatchDocuments ( ISphRtAccum * pAccExt, PercolateMatchRes
tRes.m_tmSetup = tmStart;
m_sLastWarning = "";

RtAccum_t * pAcc = AcquireAccum ( NULL, pAccExt, true, this, m_pDict, true );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt );
if ( !pAcc )
return false;

Expand Down Expand Up @@ -11902,7 +11892,7 @@ void PercolateIndex_c::RollBack ( ISphRtAccum * pAccExt )
{
assert ( g_bRTChangesAllowed );

RtAccum_t * pAcc = AcquireAccum ( NULL, pAccExt, true, this, m_pDict, true );
auto pAcc = ( RtAccum_t * ) AcquireAccum ( m_pDict, pAccExt );
if ( !pAcc )
return;

Expand Down
5 changes: 5 additions & 0 deletions src/sphinxrt.h
Expand Up @@ -81,6 +81,11 @@ class ISphRtIndex : public CSphIndex

// instead of cloning for each AddDocument() call we could just call this method and improve batch inserts speed
virtual ISphTokenizer * CloneIndexingTokenizer() const = 0;

/// acquire thread-local indexing accumulator
/// returns NULL if another index already uses it in an open txn
ISphRtAccum * AcquireAccum ( CSphDict * pDict, ISphRtAccum * pAccExt=nullptr,
bool bWordDict=true, bool bSetTLS = true, CSphString * sError=nullptr );
};

/// initialize subsystem
Expand Down

0 comments on commit 9742f5f

Please sign in to comment.