Exemple #1
0
DateTime::DateTime(int year, int month, int day, int hour,
                   int minute, int second, int millisecond, int microsecond)
    : m_year(year)
    , m_month(month)
    , m_day(day)
    , m_hour(hour)
    , m_minute(minute)
    , m_second(second)
    , m_millisecond(millisecond)
    , m_microsecond(microsecond)
{
    FIRTEX_ASSERT2(year >= 0 && year <= 9999);
    FIRTEX_ASSERT2(month >= 1 && month <= 12);
    FIRTEX_ASSERT2(day >= 1 && day <= daysOfMonth(year, month));
    FIRTEX_ASSERT2(hour >= 0 && hour <= 23);
    FIRTEX_ASSERT2(minute >= 0 && minute <= 59);
    FIRTEX_ASSERT2(second >= 0 && second <= 59);
    FIRTEX_ASSERT2(millisecond >= 0 && millisecond <= 999);
    FIRTEX_ASSERT2(microsecond >= 0 && microsecond <= 999);

    m_utcTime = toUtcTime(toJulianDay(year, month, day)) + 
                10*(hour*Timespan::HOURS + minute*Timespan::MINUTES + 
                    second*Timespan::SECONDS + 
                    millisecond*Timespan::MILLISECONDS + microsecond);
}
Exemple #2
0
DateTime& DateTime::assign(int year, int month, int day, int hour,
                           int minute, int second, int millisecond,
                           int microsecond)
{
    FIRTEX_ASSERT2(year >= 0 && year <= 9999);
    FIRTEX_ASSERT2(month >= 1 && month <= 12);
    FIRTEX_ASSERT2(day >= 1 && day <= daysOfMonth(year, month));
    FIRTEX_ASSERT2(hour >= 0 && hour <= 23);
    FIRTEX_ASSERT2(minute >= 0 && minute <= 59);
    FIRTEX_ASSERT2(second >= 0 && second <= 59);
    FIRTEX_ASSERT2(millisecond >= 0 && millisecond <= 999);
    FIRTEX_ASSERT2(microsecond >= 0 && microsecond <= 999);

    m_utcTime     = toUtcTime(toJulianDay(year, month, day)) + 
                    10*(hour*Timespan::HOURS + minute*Timespan::MINUTES +
                            second*Timespan::SECONDS +
                            millisecond*Timespan::MILLISECONDS + microsecond);
    m_year        = year;
    m_month       = month;
    m_day         = day;
    m_hour        = hour;
    m_minute      = minute;
    m_second      = second;
    m_millisecond = millisecond;
    m_microsecond = microsecond;

    return *this;
}
Exemple #3
0
		void CReadWriteMutex::releaseWriterLock()
		{
			const DWORD dwCurrentThreadId = GetCurrentThreadId();
			EnterCriticalSection(&m_cs);

			CMapThreadToState::iterator ite = m_map.find(dwCurrentThreadId);
			FIRTEX_ASSERT2( (ite != m_map.end()) && (WRITER_RECURRENCE_UNIT <= ite->second));

			const DWORD dwThreadState = (ite->second -= WRITER_RECURRENCE_UNIT);
			if(0 == dwThreadState)
			{
				m_map.erase(ite);
				releaseWriterLock_i(false);
			}
			else if (WRITER_RECURRENCE_UNIT <= dwThreadState)
			{
				// Still be is a writer
				LeaveCriticalSection(&m_cs);
			}
			else
			{
				// Down-grading from writer to reader
				releaseWriterLock_i(true);
			}
		}
void ByteSliceOutputStream::newSlice()
{
    size_t nNewSize = getSliceSize(m_nTotalSize);
    void* begin = m_pPool->tryAllocate(nNewSize);
    ///allocate memory failed, decrease chunk size
    if(!begin)
    {
        ///Decrease allocate size
        nNewSize = DEFAULT_EXCEPTION_ALLOC_SIZE;
        begin = m_pPool->allocate(nNewSize);
        FIRTEX_ASSERT2(begin);
    }

    ByteSlice* pSlice = (ByteSlice*)begin;
    pSlice->size = nNewSize - sizeof(ByteSlice) + sizeof(uint8_t);
    pSlice->next = NULL;

    if(!m_pTailSlice)
    {
        m_pTailSlice = m_pHeadSlice = pSlice;
    }
    else
    {
        m_pTailSlice->next = pSlice;
        m_nTotalSize += m_pTailSlice->size;
        m_pTailSlice = pSlice;				
    }
    m_pWriteUpto = m_pTailSlice->data;		
}
Exemple #5
0
void MMapFile::open(const std::string& sFileName, std::size_t size, 
                    AccessMode mode, const void* pAddrHint, bool bServer)
{
    FIRTEX_ASSERT2(!m_pImpl);
    m_pImpl = new MMapFileImpl();
    m_pImpl->open(sFileName, size, mode, pAddrHint, bServer);
}
void SingleIndexBarrelReader::createTermReader(const std::string& sSuffix)
{
    FileSystemPtr& pFileSys = m_pFileSys;
    if (m_bMultiIndexFields)
    {
        MultiFieldTermReader* pMultiReader =
            new MultiFieldTermReader(m_pComponentBuilder);
        m_pTermReader.assign(pMultiReader);
        pMultiReader->open(pFileSys, m_pInStreamPool, sSuffix, getDocSchema(), m_pDocFilter);
    }
    else
    {
        DocumentSchema::Iterator iter = m_pDocSchema->iterator();
        while (iter.hasNext())
        {
            const FieldSchema* pFieldSchema = iter.next();
            if (pFieldSchema->isIndexed())
            {
                TermReader* pTermReader =
                    m_pComponentBuilder->buildTermReader(pFieldSchema->getId());
                FIRTEX_ASSERT2(pTermReader != NULL);

                m_pTermReader.assign(pTermReader);
                m_pTermReader->open(pFileSys, m_pInStreamPool, sSuffix,
                        pFieldSchema, m_pDocFilter);
                break;
            }
        }
    }
}
Exemple #7
0
void NumberFormatter::append(tstring& str, double value, int precision)
{
    FIRTEX_ASSERT2 (precision >= 0 && precision < 32);

    char buffer[64];
    std::sprintf(buffer, "%.*f", precision, value);
    str.append(buffer);
}
Exemple #8
0
void NumberFormatter::append(tstring& str, double value, int width, int precision)
{
    FIRTEX_ASSERT2 (width > 0 && width < 64 && precision >= 0 && precision < width);

    char buffer[64];
    std::sprintf(buffer, "%*.*f", width, precision, value);
    str.append(buffer);
}
Exemple #9
0
void NumberFormatter::append0(tstring& str, uint32_t value, int width)
{
    FIRTEX_ASSERT2 (width > 0 && width < 64);

    char buffer[64];
    std::sprintf(buffer, "%0*u", width, value);
    str.append(buffer);
}
Exemple #10
0
void NumberFormatter::append0(tstring& str, int64_t value, int width)
{
    FIRTEX_ASSERT2 (width > 0 && width < 64);

    char buffer[64];
    std::sprintf(buffer, "%0*" I64_FMT"d", width, (I64_VAL)value);
    str.append(buffer);
}
Exemple #11
0
void MMapFile::open(const FileHandle& fileHandle,
                    AccessMode mode,
                    size_t nMapSize,
                    const void* pAddrHint)
{
    FIRTEX_ASSERT2(!m_pImpl);
    m_pImpl = new MMapFileImpl();
    m_pImpl->open(fileHandle, mode, nMapSize, pAddrHint);
}
Exemple #12
0
const std::string& Path::operator [] (size_t n) const
{
    FIRTEX_ASSERT2 (0 <= n && n <= m_vDirs.size());
	
    if (n < m_vDirs.size())
        return m_vDirs[n];
    else
        return m_sName;	
}
Exemple #13
0
Field::Field(const FieldSchema* pFieldSchema, char* text, size_t len, bool bNoCopy)
    : m_pFieldSchema(pFieldSchema)
    , m_fBoost(1.0)
{
    FIRTEX_ASSERT2(m_pFieldSchema != NULL);
    if (text == NULL)
    {
        throw IllegalArgumentException(_T("Reader cannot be null."));
    }
    setValue(text, len, bNoCopy);
}
const ForwardIndexReader* 
SingleIndexBarrelReader::getForwardIndexReader(const std::string& sField) const
{
    FIRTEX_ASSERT2(m_pDocSchema != NULL);
    fieldid_t fieldId = m_pDocSchema->getFieldId(sField);
    if (fieldId < 0 || fieldId >= (fieldid_t)m_forwardIndexReaders.size())
    {
        return NULL;
    }
    return m_forwardIndexReaders[fieldId].get();
}
Exemple #15
0
Field::Field(const FieldSchema* pFieldSchema, const char* value)
    : m_pFieldSchema(pFieldSchema)
    , m_fBoost(1.0)
{
    FIRTEX_ASSERT2(m_pFieldSchema != NULL);
    if (!value)
    {
        throw IllegalArgumentException(_T("Value cannot be null."));
    }

    setValue(value, FX_NS(utility)::strLength(value));
}
Exemple #16
0
int DateTime::daysOfMonth(int year, int month)
{
    FIRTEX_ASSERT2(month >= 1 && month <= 12);

    static int daysOfMonthTable[] = {0, 31, 28, 31, 30, 31, 
                                     30, 31, 31, 30, 31, 30, 31};

    if (month == 2 && isLeapYear(year))
        return 29;
    else
        return daysOfMonthTable[month];
}
Exemple #17
0
Field::Field(const FieldSchema* pFieldSchema, Field::TokenView* value)
    : m_pFieldSchema(pFieldSchema)
    , m_fBoost(1.0)
{
    FIRTEX_ASSERT2(m_pFieldSchema != NULL);
    if (value == NULL)
    {
        throw IllegalArgumentException(_T("Value cannot be null."));
    }

    setTokenView(value);
}
Exemple #18
0
Field::Field(const FieldSchema* pFieldSchema,
             const Field::TokenViewPtr& value)
    : m_pFieldSchema(pFieldSchema)
    , m_fBoost(1.0)
{
    FIRTEX_ASSERT2(m_pFieldSchema != NULL);

    if (!value)
    {
        FIRTEX_THROW(IllegalArgumentException, _T("Value cannot be null."));
    }

    setTokenView(value);
}
Exemple #19
0
void StandardAnalyzer::doTokenize(TokenSourcePtr& tokenSource) const
{
    FIRTEX_ASSERT2(m_pSegmenter != NULL);

    TokenViewPtr pInTokenView = tokenSource->getLastView();
    TokenViewPtr pOutTokenView = tokenSource->acquireCustomView(_T("standard_view"));
    pOutTokenView->reserve(getMaxTokensToAnalyze());
    pOutTokenView->setTokenType(Token::TT_CWORD);

    TokenView::Iterator iter = pInTokenView->iterator();
    while(iter.hasNext())
    {
        const Token& token = iter.next();
        m_pSegmenter->segment(pOutTokenView,
                              token.getTextValue(),
                              token.getTextLength());
    }
}
Exemple #20
0
		void CReadWriteMutex::releaseReaderLock()
		{
			const DWORD dwCurrentThreadId = GetCurrentThreadId();
			EnterCriticalSection(&m_cs);

			CMapThreadToState::iterator ite = m_map.find(dwCurrentThreadId);
			FIRTEX_ASSERT2( (ite != m_map.end()) && (READER_RECURRENCE_MASK & ite->second));

			const DWORD dwThreadState = (ite->second -= READER_RECURRENCE_UNIT);
			if(0 == dwThreadState)
			{
				m_map.erase(ite);
				releaseReaderLock_i();
			}
			else
			{
				LeaveCriticalSection(&m_cs);
			}
		}	
TermReaderPtr SingleIndexBarrelReader::termReader(const std::string& sField) const 
{
    if (m_pTermReader.isNull())
        return TermReaderPtr();

    if (m_bMultiIndexFields)
    {
        MultiFieldTermReaderPtr pMultiFieldTermReader = 
            m_pTermReader.cast<MultiFieldTermReader>();
        FIRTEX_ASSERT2(!pMultiFieldTermReader.isNull());
        return pMultiFieldTermReader->termReader(sField);
    }
    else 
    {
        if (!strCompareNoCase(m_pTermReader->getFieldSchema()->getName().c_str(), sField.c_str()))
        {
            return TermReaderPtr(m_pTermReader->clone());
        }
    }
    return TermReaderPtr();
}
void SingleIndexBarrelReader::createForwardIndex(const std::string& sSuffix)
{
    DocumentSchema::Iterator iter = m_pDocSchema->iterator();
    while (iter.hasNext())
    {
        const FieldSchema* pFieldSchema = iter.next();
        if(pFieldSchema->hasForwardIndex())
        {
            fieldid_t fieldId = pFieldSchema->getId();
            ForwardIndexReader* pFDReader =
                m_pComponentBuilder->buildForwardIndexReader(fieldId);
            FIRTEX_ASSERT2(pFDReader != NULL);

            if (fieldId >= (fieldid_t)m_forwardIndexReaders.size())
            {
                m_forwardIndexReaders.resize(fieldId + 1);
            }
            m_forwardIndexReaders[fieldId].assign(pFDReader);
            pFDReader->open(m_pFileSys, pFieldSchema, FORWARD_INDEX_FILEEXT, sSuffix);
        }
    }
}
Exemple #23
0
void BM25DocScorer::init(const FeatureProvider* pProvider,
                         const QueryFeature& queryFeature,
                         const std::string& sField)
{
    const IndexFeature& indexFeature = pProvider->getIndexFeature();

    for (size_t i = 0; i < queryFeature.size(); ++i)
    {
        const TermQueryFeature& tqFeature = queryFeature[i];
        FIRTEX_ASSERT2(tqFeature.getNumSuccessors() < queryFeature.size() - i);

        const Term* pTerm = tqFeature.getTerm();
        if (!tqFeature.isProhibited() 
            && (sField.empty() || !strCompareNoCase(pTerm->getField().c_str(), sField.c_str())))
        {
            BM25Weight w;
            w.init(indexFeature, &tqFeature);
            
            BM25TermScorer* pDocScore = new BM25TermScorer(indexFeature, w, 
                    &tqFeature, (uint32_t)i);
            m_termScorers.push_back(pDocScore);
        }
    }
}
Exemple #24
0
File& File::operator = (const tchar* path)
{
    FIRTEX_ASSERT2(path);
    setPath(path);
    return *this;
}
Exemple #25
0
void Index::open(FileSystemPtr& pFileSys, AccessMode am,
                 const DocumentSchema* pDocSchema)
{
    FIRTEX_ASSERT2(m_pFileSys.isNull());
    m_pFileSys = pFileSys;
    m_accessMode = am;
	
    BarrelsInfoPtr pBarrelsInfo(new BarrelsInfo());
    pBarrelsInfo->read(pFileSys);//read barrels Info

    if (am == WRITE)
    {
        if (!pDocSchema)
        {
            FIRTEX_THROW(InvalidConfigException, "Schema is empty in write mode.");
        }

        m_pDocSchema = new DocumentSchema(*pDocSchema);
        writeSchema(m_pDocSchema, pFileSys);

        pBarrelsInfo->remove(m_pFileSys);

        m_pComponentBuilder = new ComponentBuilder();
        m_pComponentBuilder->init(m_pDocSchema);
        initAnalyzerMapper();

        m_pIndexBarrelKeeper = new IndexBarrelKeeper(m_pFileSys, m_pDocSchema.get(),
                m_pComponentBuilder.get(), m_pAnalyzerMapper.get());
        m_pIndexBarrelKeeper->init(pBarrelsInfo, IndexBarrelKeeper::WRITE);

        openWriter();
    }
    else // READ, APPEND or RDWR mode
    {
        if (pBarrelsInfo->getIndexVersion() != FX_INDEX_VERSION)
        {
            FIRTEX_THROW(VersionException, "Incompatible index version.");
        }
        if (pBarrelsInfo->getBarrelCount() > 0)
        {
            DocumentSchemaPtr pSchemaExist = readSchema(m_pFileSys);
            if (pSchemaExist.isNull())
            {
                FIRTEX_THROW(IndexCollapseException, "Read schema FAILED.");
            }
            if (pDocSchema && !pSchemaExist->isEqual(*pDocSchema))
            {
                FIRTEX_THROW(IllegalArgumentException,
                        "The given document schema is not equal to the existing schema.");
            }
            m_pDocSchema = pSchemaExist;
        }
        else
        {
            if (!pDocSchema)
            {
                FIRTEX_THROW(IllegalArgumentException,
                        "No document schema is specified.");
            }
            m_pDocSchema = new DocumentSchema(*pDocSchema);
        }

        m_pComponentBuilder = new ComponentBuilder();
        m_pComponentBuilder->init(m_pDocSchema);
        initAnalyzerMapper();

        m_pIndexBarrelKeeper = new IndexBarrelKeeper(m_pFileSys, m_pDocSchema.get(),
                m_pComponentBuilder.get(), m_pAnalyzerMapper.get());

        if (am == READ || am == RDWR)
        {
            m_pIndexBarrelKeeper->init(pBarrelsInfo, (am == READ) ?
                    IndexBarrelKeeper::READ : IndexBarrelKeeper::RDWR);

            openReader();
            if (am == RDWR)
            {
                openWriter();
            }
        }
        else if (am == APPEND)
        {
            m_pIndexBarrelKeeper->init(pBarrelsInfo, IndexBarrelKeeper::WRITE);
            openWriter();
        }
    }
}
Exemple #26
0
commitid_t IndexBarrelKeeper::refreshDataForRead()
{
    BarrelsInfoPtr pBarrelsInfo(new BarrelsInfo());
    pBarrelsInfo->read(m_pFileSys);
    commitid_t latestCommit = pBarrelsInfo->getCommitId();

    commitid_t prevCommit = INVALID_COMMIT;
    IndexBarrelPtr pLastBarrel;
    {
        ScopedRWLock lock(m_lock, false);
        if (!m_commitMap.empty())
        {
            pLastBarrel = m_commitMap.rbegin()->second;
            prevCommit = pLastBarrel->getBarrelsInfo()->getCommitId();
        }
    }
    if (latestCommit == prevCommit)
    {
        return prevCommit;
    }

    if (prevCommit == INVALID_COMMIT)
    {
        return createOnDiskBarrelReader(pBarrelsInfo);
    }

    FX_LOG(INFO, "Begin reopen index database, commitId: [%d]", latestCommit);

    IndexBarrelReaderPtr pReader;

    DeletedDocumentFilterPtr pDocFilter(pLastBarrel->getDeletedDocFilter()->clone());
    pDocFilter->reopen(pBarrelsInfo);

    PrimaryKeyIndexPtr pPrimKey;
    if (m_pOnDiskPrimKeyIndex)
    {
        pPrimKey.reset(m_pOnDiskPrimKeyIndex->clone());
        pPrimKey->reopen(pBarrelsInfo);
    }

    BarrelsInfoPtr pLastBarrelsInfo = pLastBarrel->getBarrelsInfo();
    IndexBarrelReaderPtr pLastReader = pLastBarrel->getReader();

    size_t bc = pBarrelsInfo->getBarrelCount();
    if (bc == 1)
    {
        if (pLastBarrelsInfo->getBarrelCount() > 1 
            || pBarrelsInfo->getCommitId() - pLastBarrelsInfo->getCommitId() > 1)
        {
            const BarrelInfo& lastBarrelInfo = pBarrelsInfo->getLastBarrel();
            const BitVector* pBitVector =
                pDocFilter->getDocFilter(lastBarrelInfo.getBaseDocId());
            SingleIndexBarrelReader* pSingleReader = new SingleIndexBarrelReader(
                    m_pFileSys, m_pDocSchema, m_pComponentBuilder);
            pReader.reset(pSingleReader);
            
            pSingleReader->open(&lastBarrelInfo, pBitVector);
        }
        else
        {
            const BarrelInfo& lastBarrelInfo = pBarrelsInfo->getLastBarrel();
            const BitVector* pBitVector =
                pDocFilter->getDocFilter(lastBarrelInfo.getBaseDocId());
                
            pReader.reset(pLastReader->clone());
            SingleIndexBarrelReaderPtr pSingleReader =
                std::dynamic_pointer_cast<SingleIndexBarrelReader>(pReader);

            FIRTEX_ASSERT2(pSingleReader);
            pSingleReader->reopen(&lastBarrelInfo, pBitVector);
        }
    }
    else if (bc > 1)
    {
        if (pLastBarrelsInfo->getBarrelCount() > 1)
        {
            pReader.reset(pLastReader->clone());
            MultiIndexBarrelReaderPtr pMultiReader =
                std::dynamic_pointer_cast<MultiIndexBarrelReader>(pReader);
            FIRTEX_ASSERT2(pMultiReader);
            pMultiReader->reopen(pBarrelsInfo, pDocFilter);
        }
        else
        {
            //TODO: optimize?
            MultiIndexBarrelReader* pMultiReader = new MultiIndexBarrelReader(
                    m_pFileSys, m_pDocSchema, m_pComponentBuilder);
            pReader.reset(pMultiReader);

            pMultiReader->open(pBarrelsInfo, pDocFilter);
        }
    }
    FX_LOG(INFO, "End reopen index database.");

    IndexBarrelPtr pBarrel(new IndexBarrel(pBarrelsInfo, pReader, pDocFilter));
    pBarrel->setEncoding(m_sEncoding);
    {
        ScopedRWLock lock(m_lock, true);
        bool bInserted = doInsertCommit(latestCommit, pBarrel);
        if (bInserted)
        {
            m_pOnDiskDocFilter = pDocFilter;
            m_pOnDiskPrimKeyIndex = pPrimKey;
            return latestCommit;
        }
        return prevCommit;
    }
}
Exemple #27
0
void IndexBarrelKeeper::sealBarrel(const IndexBarrelWriterPtr& pInMemBarrel)
{
    FX_DEBUG("Seal barrel");

    IndexBarrelWriterPtr pBarrelWriter = pInMemBarrel;
    InMemIndexMergerPtr pInMemBarrelMerger;
    pBarrelWriter->sealBarrel();

    {
        ScopedRWLock lock(m_lock, true);

        IndexBarrelPtr pLastBarrel;
        if (!m_commitMap.empty())
        {
            pLastBarrel = m_commitMap.rbegin()->second;
        }
    
        BarrelsInfoPtr pNewBarrelsInfo;
        if (pLastBarrel)
        {
            pNewBarrelsInfo.reset(pLastBarrel->getBarrelsInfo()->clone());
        }
        else 
        {
            pNewBarrelsInfo.reset(new BarrelsInfo);
        }

        /// Commit barrel to barrels info
        if (!pBarrelWriter->commitBarrelInfo(pNewBarrelsInfo))
        {
            FX_DEBUG("No barrel to commit");
            return ;
        }
        FX_DEBUG("Committed barrel info: commit: [%d], baseDocId: [%d]",
                 pNewBarrelsInfo->getLastBarrel().getCommitId(),
                 pNewBarrelsInfo->getLastBarrel().getBaseDocId());

        //TODO: implement real-time search
        IndexBarrelReaderPtr pReader;
        if (pLastBarrel)
        {
            pReader = pLastBarrel->getReader();
        }

        PrimaryKeyIndexPtr pPrimKey;
        if (m_pOnDiskPrimKeyIndex)
        {
            pPrimKey.reset(m_pOnDiskPrimKeyIndex->clone());
            if (pPrimKey)
            {
                const PrimaryKeyIndexPtr& pPkIndex = pBarrelWriter->getPrimaryKey();
                if (pPkIndex)
                {
                    pPrimKey->reopen(pNewBarrelsInfo, pPkIndex->getHashMap());
                }
            }
        }
        else
        {
            pPrimKey = createPrimaryKeyIndex();
            if (pPrimKey)
            {
                const PrimaryKeyIndexPtr& pPkIndex = pBarrelWriter->getPrimaryKey();
                FIRTEX_ASSERT2(pPkIndex);
                pPrimKey->open(m_pFileSys, pNewBarrelsInfo, pPkIndex->getHashMap());
            }
        }

        IndexBarrelPtr pBarrel(new IndexBarrel(pNewBarrelsInfo, pReader, m_pOnDiskDocFilter));
        pBarrel->setEncoding(m_sEncoding);
        
        bool bInserted = doInsertCommit(pNewBarrelsInfo->getCommitId(), pBarrel);
        (void)bInserted;
        FIRTEX_ASSERT2(bInserted);

        m_pOnDiskDocFilter.reset(m_pOnDiskDocFilter->clone());
        m_pOnDiskPrimKeyIndex = pPrimKey;

        if (!m_pInMemBarrelMerger)
        {
            m_pInMemBarrelMerger.reset(new InMemIndexMerger(this));
        }
        m_pInMemBarrelMerger->addToMerge(pNewBarrelsInfo->getLastBarrel(), 
                pBarrelWriter);
        if (m_pInMemBarrelMerger->getInMemBarrelCount() >= (size_t)GLOBAL_CONF().Build.buildThreadCount)
        {
            pInMemBarrelMerger = m_pInMemBarrelMerger;
            m_pInMemBarrelMerger.reset();
        }
    }
    
    if (pInMemBarrelMerger)
    {
        CommittablePtr pCommitObj = std::dynamic_pointer_cast<Committable>(pInMemBarrelMerger);
        m_pCommitScheduler->commit(pCommitObj);
    }
}
Exemple #28
0
commitid_t IndexBarrelKeeper::createOnDiskBarrelReader(const BarrelsInfoPtr& pBarrelsInfo)
{
    commitid_t latestCommit = pBarrelsInfo->getCommitId();
    FIRTEX_ASSERT2(latestCommit != INVALID_COMMIT);

    DeletedDocumentFilterPtr pDocFilter(new DeletedDocumentFilter(m_pFileSys));
    pDocFilter->open(pBarrelsInfo);

    PrimaryKeyIndexPtr pPrimKeyIndex = createPrimaryKeyIndex();

    IndexBarrelReaderPtr pReader;
    size_t bc = pBarrelsInfo->getBarrelCount();
    if (bc == 1)
    {
        const BarrelInfo& lastBarrel = pBarrelsInfo->getLastBarrel();
        const BitVector* pBitVector =
            pDocFilter->getDocFilter(lastBarrel.getBaseDocId());
        SingleIndexBarrelReader* pSingleReader = new SingleIndexBarrelReader(
                m_pFileSys, m_pDocSchema, m_pComponentBuilder);
        pReader.reset(pSingleReader);

        pSingleReader->open(&lastBarrel, pBitVector);

        if (pPrimKeyIndex)
        {
            TermReaderPtr pTermReader = pSingleReader->termReader(
                    pPrimKeyIndex->getPrimKeyField());
            PrimaryKeyTermReaderPtr pPrimKeyTermReader =
                dynamic_pointer_cast<PrimaryKeyTermReader>(pTermReader);
            FIRTEX_ASSERT2(pPrimKeyTermReader);
            
            pPrimKeyIndex->open(m_pFileSys, pBarrelsInfo,
                    pPrimKeyTermReader->getPostingTable());
        }
    }
    else if (bc > 1)
    {
        MultiIndexBarrelReader* pMultiReader = new MultiIndexBarrelReader(
                m_pFileSys, m_pDocSchema, m_pComponentBuilder);
        pReader.reset(pMultiReader);

        pMultiReader->open(pBarrelsInfo, pDocFilter);

        if (pPrimKeyIndex)
        {
            pPrimKeyIndex->open(m_pFileSys, pBarrelsInfo);
        }
    }

    {
        ScopedRWLock lock(m_lock, true);
        commitid_t lastCommit = INVALID_COMMIT;
        if (!m_commitMap.empty())
        {
            lastCommit = m_commitMap.rbegin()->second->getBarrelsInfo()->getCommitId();
        }

        if (lastCommit >= latestCommit)
        {
            return lastCommit;
        }

        IndexBarrelPtr pBarrel(new IndexBarrel(pBarrelsInfo, pReader, pDocFilter));
        pBarrel->setEncoding(m_sEncoding);
        m_commitMap.insert(make_pair(latestCommit, pBarrel));
        m_latestOnDiskCommit = latestCommit;
        m_pOnDiskDocFilter = pDocFilter;
        m_pOnDiskPrimKeyIndex = pPrimKeyIndex;
    }
    return latestCommit;
}
Exemple #29
0
Field::Field(const FieldSchema* pFieldSchema)
    : m_pFieldSchema(pFieldSchema)
    , m_fBoost(1.0)
{
    FIRTEX_ASSERT2(m_pFieldSchema != NULL);
}
Exemple #30
0
Path& Path::operator = (const char* szPath)
{
    FIRTEX_ASSERT2(szPath);
    return assign(szPath);
}