Пример #1
0
void ProcessSlaveActivity::main() 
{ 
#ifdef TIME_ACTIVITIES
    if (timeActivities)
        lastCycles = get_cycles_now();
#endif
    try { process(); }
    catch (IException *_e)
    {
        IThorException *e = QUERYINTERFACE(_e, IThorException);
        if (e)
        {
            if (!e->queryActivityId())
            {
                e->setGraphId(container.queryOwner().queryGraphId());
                e->setActivityKind(container.getKind());
                e->setActivityId(container.queryId());
            }
        }
        else
        {
            e = MakeActivityException(this, _e);
            if (QUERYINTERFACE(_e, ISEH_Exception))
            {
                IThorException *e2 = MakeThorFatal(e, TE_SEH, "FATAL: (SEH)");
                e->Release();
                e = e2;
            }
            _e->Release();
        }
        ActPrintLog(e, NULL);
        exception.setown(e);
    }
    catch (std::exception & es)
    {
        StringBuffer m("FATAL std::exception ");
        if(dynamic_cast<std::bad_alloc *>(&es))
            m.append("out of memory (std::bad_alloc)");
        else
            m.append("standard library exception (std::exception ").append(es.what()).append(")");
        m.appendf(" in %"ACTPF"d",container.queryId());
        ActPrintLogEx(&queryContainer(), thorlog_null, MCerror, "%s", m.str());
        exception.setown(MakeThorFatal(NULL, TE_UnknownException, "%s", m.str()));
    }
    catch (CATCHALL)
    {
        ActPrintLogEx(&queryContainer(), thorlog_null, MCerror, "Unknown exception thrown in process()");
        exception.setown(MakeThorFatal(NULL, TE_UnknownException, "FATAL: Unknown exception thrown by ProcessThread"));
    }
    try { endProcess(); }
    catch (IException *_e)
    {
        ActPrintLog(_e, "Exception calling activity endProcess");
        fireException(_e);
        exception.set(_e);
        _e->Release();
    }
}
Пример #2
0
void CDiskWriteSlaveActivityBase::removeFiles()
{
    if (!fName.length())
        return;
    Owned<IFile> primary = createIFile(fName);
    try { primary->remove(); }
    catch (IException *e) { ActPrintLogEx(&queryContainer(), e, thorlog_null, MCwarning, "Failed to remove file: %s", fName.get()); }
    catch (CATCHALL) { ActPrintLogEx(&queryContainer(), thorlog_null, MCwarning, "Failed to remove: %s", fName.get()); }
}
Пример #3
0
void CDiskWriteSlaveActivityBase::close()
{
    try
    {
        if (out) {
            uncompressedBytesWritten = out->getPosition();
            if (calcFileCrc) {
                if (diskHelperBase->getFlags() & TDWextend) {
                    assertex(!"TBD need to merge CRC");
                }   
                else
                    out->flush(&fileCRC);
            }
            else if (!abortSoon)
                out->flush();
            out.clear();
        }
        else if (outraw) {
            outraw->flush();
            uncompressedBytesWritten = outraw->tell();
            outraw.clear();
        }

        {
            CriticalBlock block(statsCs);
            mergeStats(fileStats, outputIO);
            outputIO.clear();
        }

        if (!rfsQueryParallel && dlfn.isExternal() && !lastNode())
        {
            rowcount_t rows = processed & THORDATALINK_COUNT_MASK;
            ActPrintLog("External write done, signalling next (row count = %" RCPF "d)", rows);
            CMessageBuffer msg;
            msg.append(rows);
            msg.append(tempExternalName);
            queryJobChannel().queryJobComm().send(msg, queryJobChannel().queryMyRank()+1, mpTag);
        }
    }
    catch (IException *e)
    { 
        ActPrintLogEx(&queryContainer(), e, thorlog_null, MCwarning, "Error closing file: %s", fName.get());
        abortSoon = true;
        removeFiles();
        throw e;
    }
    if (abortSoon)
        removeFiles();
}
Пример #4
0
    void stop()
    {
#ifdef _FULL_TRACE
        ActPrintLog(activity, "SmartBuffer stop %x",(unsigned)(memsize_t)this);
#endif
        SpinBlock block(lock);
#ifdef _DEBUG
        if (waiting)
        {
            ActPrintLogEx(&activity->queryContainer(), thorlog_null, MCwarning, "CSmartRowBuffer::stop while nextRow waiting");
            PrintStackReport();
        }
#endif
        eoi = true;

        while (out&&out->ordinality()) 
            ReleaseThorRow(out->dequeue());
        while (NULL == in)
        {
            waiting = true;
            SpinUnblock unblock(lock);
            waitsem.wait();
        }
        while (out&&out->ordinality()) 
            ReleaseThorRow(out->dequeue());
        while (in&&in->ordinality()) 
            ReleaseThorRow(in->dequeue());
        diskin.kill();
        if (waiting) {
            waitsem.signal();
            waiting = false;
        }
        if (waitflush) {
            waitflushsem.signal();
            waitflush = false;
        }
    }
Пример #5
0
    void flush()
    {
        // I think flush should wait til all rows read or stopped
#ifdef _FULL_TRACE
        ActPrintLog(activity, "SmartBuffer flush %x",(unsigned)(memsize_t)this);
#endif
        SpinBlock block(lock);
        if (eoi) return;
        loop {
            assertex(in);  // reentry check
            diskflush();
            eoi = true;
            if (waiting) {
                waitsem.signal();
                waiting = false;
            }
            if (out&&!out->ordinality()&&!diskin.ordinality()&&!in->ordinality()) 
                break;
            waitflush = true;
            SpinUnblock unblock(lock);
            while (!waitflushsem.wait(1000*60))
                ActPrintLogEx(&activity->queryContainer(), thorlog_null, MCwarning, "CSmartRowBuffer::flush stalled");
        }
    }
Пример #6
0
 void start()
 {
     ActivityTimer s(totalCycles, timeActivities);
     input = inputs.item(0);
     try
     {
         try { 
             startInput(input); 
         }
         catch (IException *e)
         {
             fireException(e);
             barrier->cancel();
             throw;
         }
         catch (CATCHALL)
         {
             Owned<IException> e = MakeActivityException(this, 0, "Unknown exception starting sort input");
             fireException(e);
             barrier->cancel();
             throw;
         }
         dataLinkStart();
         
         Linked<IRowInterfaces> rowif = queryRowInterfaces(input);
         Owned<IRowInterfaces> auxrowif = createRowInterfaces(helper->querySortedRecordSize(),queryActivityId(),queryCodeContext());
         sorter->Gather(
             rowif,
             input,
             helper->queryCompare(),
             helper->queryCompareLeftRight(),
             NULL,helper->querySerialize(),
             NULL,
             false,
             isUnstable(),
             abortSoon,
             auxrowif);
         stopInput(input);
         input = NULL;
         if (abortSoon)
         {
             ActPrintLogEx(&queryContainer(), thorlog_null, MCwarning, "MSortSlaveActivity::start aborting");
             barrier->cancel();
             return;
         }
     }
     catch (IException *e)
     {
         fireException(e);
         barrier->cancel();
         throw;
     }
     catch (CATCHALL)
     {
         Owned<IException> e = MakeActivityException(this, 0, "Unknown exception gathering sort input");
         fireException(e);
         barrier->cancel();
         throw;
     }
     ActPrintLog("SORT waiting barrier.1");
     if (!barrier->wait(false)) {
         Sleep(1000); // let original error through
         throw MakeThorException(TE_BarrierAborted,"SORT: Barrier Aborted");
     }
     ActPrintLog("SORT barrier.1 raised");
     output.setown(sorter->startMerge(totalrows));
 }
Пример #7
0
 ~CRowStreamLookAhead()
 {
     if (!thread.join(1000*60))
         ActPrintLogEx(&activity.queryContainer(), thorlog_all, MCuserWarning, "CRowStreamLookAhead join timedout");
 }
Пример #8
0
 ~ThorLookaheadCache()
 {
     if (!thread.join(1000*60))
         ActPrintLogEx(&activity.queryContainer(), thorlog_all, MCuserWarning, "ThorLookaheadCache join timedout");
 }