From 61709d92431065a962e4d89457986fdd8956fb6e Mon Sep 17 00:00:00 2001 From: klirichek Date: Tue, 24 Aug 2010 13:25:05 +0000 Subject: [PATCH] Managing MVA persistent update's cache (.mvp) when indexing/rotating git-svn-id: http://sphinxsearch.googlecode.com/svn/trunk@2464 8b96e2b9-35c5-2c16-bc47-5122d61876d4 --- src/searchd.cpp | 33 ++++++++++++++++++++++++++++++--- src/sphinx.cpp | 5 ++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/searchd.cpp b/src/searchd.cpp index bfbe9111..d8d5d141 100644 --- a/src/searchd.cpp +++ b/src/searchd.cpp @@ -471,9 +471,10 @@ static CSphSharedBuffer g_tFlushBuffer; #endif // USE_WINDOWS const int EXT_COUNT = 8; +const int EXT_MVP = 8; const char * g_dNewExts[EXT_COUNT] = { ".new.sph", ".new.spa", ".new.spi", ".new.spd", ".new.spp", ".new.spm", ".new.spk", ".new.sps" }; -const char * g_dOldExts[EXT_COUNT] = { ".old.sph", ".old.spa", ".old.spi", ".old.spd", ".old.spp", ".old.spm", ".old.spk", ".old.sps" }; -const char * g_dCurExts[EXT_COUNT] = { ".sph", ".spa", ".spi", ".spd", ".spp", ".spm", ".spk", ".sps" }; +const char * g_dOldExts[] = { ".old.sph", ".old.spa", ".old.spi", ".old.spd", ".old.spp", ".old.spm", ".old.spk", ".old.sps", ".old.mvp" }; +const char * g_dCurExts[] = { ".sph", ".spa", ".spi", ".spd", ".spp", ".spm", ".spk", ".sps", ".mvp" }; ///////////////////////////////////////////////////////////////////////////// // MISC @@ -8664,6 +8665,27 @@ bool RotateIndexGreedy ( ServedIndex_t & tIndex, const char * sIndex ) sphWarning ( "rotating index '%s': rename to .old failed; using old index", sIndex ); return false; } + + // holding the persistent MVA updates (.mvp). + for ( ;; ) + { + char sBuf [ SPH_MAX_FILENAME_LEN ]; + snprintf ( sBuf, sizeof(sBuf), "%s%s", sPath, g_dCurExts[EXT_MVP] ); + + CSphString sFakeError; + CSphAutofile fdTest ( sBuf, SPH_O_READ, sFakeError ); + if ( fdTest.GetFD()<0 ) + break; ///< no file, nothing to hold + + if ( TryRename ( sIndex, sPath, g_dCurExts[EXT_MVP], g_dOldExts[EXT_MVP], false ) ) + break; + + // rollback + for ( int j=0; jPrealloc ( tIndex.m_bMlock, false, sWarning ) || !tIndex.m_pIndex->Preread() ) @@ -8760,12 +8783,16 @@ bool RotateIndexGreedy ( ServedIndex_t & tIndex, const char * sIndex ) // unlink .old if ( g_bUnlinkOld && !tIndex.m_bOnlyNew ) + { for ( int i=0; i class CSphAutoArray public: explicit CSphAutoArray ( int iCount ) #ifndef NDEBUG - : m_iLength (iCount) + : m_iLength ( iCount ) #endif { m_pData = ( iCount>0 ) ? new T [ iCount ] : NULL; } ~CSphAutoArray () { Reset (); } @@ -10027,6 +10027,9 @@ int CSphIndex_VLN::Build ( const CSphVector & dSources, int iMemory fdTmpFieldMVAs.GetFD (), nFieldMVAs, iMaxPoolFieldMVAs ) ) return 0; + // reset persistent mva update pool + ::unlink ( GetIndexFileName("mvp").cstr() ); + // reset hits pool dHits.Reset ();