Exemplo n.º 1
0
MessageQueueClient* sendCSEP(CalpontSelectExecutionPlan* csep)
{
	scoped_ptr<CalpontSelectExecutionPlan> cleaner(csep);

	ByteStream bs;

	MessageQueueClient* mqc=0;

	mqc = new MessageQueueClient("ExeMgr1");
	auto_ptr<MessageQueueClient> smqc(mqc);

	bs.reset();
	ByteStream::quadbyte wantTuples=4;
	bs << wantTuples;
	mqc->write(bs);

	bs.reset();
	csep->serialize(bs);
	mqc->write(bs);

	SBS sbs;
	sbs = mqc->read();
	*sbs >> wantTuples;
	//cerr << "got flag: " << wantTuples << endl;
	string msg;
	sbs = mqc->read();
	*sbs >> msg;
	//cerr << "got msg: " << msg << endl;

	if (wantTuples != 0)
		throw runtime_error(msg);

	smqc.release();
	return mqc;
}
Exemplo n.º 2
0
void WECpiFeederThread::add2MsgQueue(ByteStream& Ibs)
{

	//TODO creating copy is NOT good; later read from socket using a SBS
	messageqcpp::SBS aSbs(new messageqcpp::ByteStream(Ibs));
	Ibs.reset();	//forcefully clearing it
	mutex::scoped_lock aLock(fMsgQMutex);
	//cout << "pushing to the MsgQueue" << endl;
	fMsgQueue.push(aSbs);
	fFeederCond.notify_one();	// as per preference of Damon
	aLock.unlock();

}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
// Perform column projection and serialization for the given delivery step
//------------------------------------------------------------------------------
void runStep(DeliveryStep& dstep, const string& message)
{
		string nextBandMsg  (message );
		nextBandMsg      += " - nextBand()";
		string serializeMsg (message );
		serializeMsg     += " - serialize()";
		int nextBandCount = 0;

		ByteStream bs;
		TableBand  tb;

//...Perform table band projection and serialization in succession
#if 0
		while (1)
		{
			// timer.start(nextBandMsg);
			tb = dstep.nextBand();
			nextBandCount++;
			// timer.stop (nextBandMsg);

			// timer.start(serializeMsg);
			bs.reset();
			tb.serialize(bs);                
			// timer.stop( serializeMsg);

			if (tb.getRowCount() == 0)
				break;
		}
//...Perform table band projection and serialization in parallel
#else
		string thrCreateMsg (message );
		thrCreateMsg     += " - serialize-thrCreate";
		string thrJoinMsg   (message );
		thrJoinMsg       += " - serialize-thrJoin";
		string serializeWaitMsg(message );
		serializeWaitMsg += " - serialize-Wait";

		//...Would prefer to record this label in projectThreadWrapper, but
		//...Stopwatch is not threadsafe, so safer to put here in main thread,
		//...where the other Stopwatch times are recorded.  Note that this
		//...time will overlap the other timestamps we are recording.
		// timer.start(nextBandMsg);

		//...Start a second thread that will allow us to perform
		//...table projections in parallel with band serialization
		// timer.start(thrCreateMsg);
		TableBandQueueMgr tableBandMgr(&dstep,1);
		pthread_t projectionThread;
		pthread_create(&projectionThread, 0, 
			projectThreadWrapper, &tableBandMgr );
		// timer.stop (thrCreateMsg);

		while (1)
		{
			//...The amount of time we spend waiting will help tell us how
			//...much extra time is being spent constructing the table bands
			// timer.start(serializeWaitMsg);
			boost::scoped_ptr<TableBand> band(tableBandMgr.getNextTableBand());
			nextBandCount++;
			// timer.stop (serializeWaitMsg);

			// timer.start(serializeMsg);
			bs.reset();
			band->serialize(bs);                
			// timer.stop( serializeMsg);

			if (band->getRowCount() == 0)
				break;
		}
		// timer.stop(nextBandMsg);

		// timer.start(thrJoinMsg);
		pthread_join(projectionThread, 0);
		// timer.stop (thrJoinMsg);
#endif
		cout << nextBandCount << " table bands delivered" << endl;
}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
    vflg = false;
    uint32_t tlvl = 0;
    bool dflg = false;
    int c;
    int32_t sid = -1;
    bool Bflg = false;

    opterr = 0;

    while ((c = getopt(argc, argv, "vt:ds:Bh")) != EOF)
        switch (c)
        {
        case 't':
            tlvl = static_cast<uint32_t>(strtoul(optarg, 0, 0));
            break;
        case 'v':
            vflg = true;
            break;
        case 'd':
            dflg = true;
            break;
        case 's':
            sid = static_cast<int32_t>(strtol(optarg, 0, 0));
            break;
        case 'B':
            Bflg = true;
            break;
        case 'h':
        case '?':
        default:
            usage();
            return (c == 'h' ? 0 : 1);
            break;
        }

    if (dflg)
        vflg = true;

    if ((argc - optind) < 1)
    {
        usage();
        return 1;
    }

    ifstream inputf;
    ByteStream bs;
    ByteStream dbs;
    ByteStream eoq;
    ByteStream tbs;
    ByteStream statsStream;
    ByteStream::quadbyte q = 0;
    eoq << q;
    uint32_t sessionid;
    time_t t;
    SJLP jl;
    DeliveredTableMap tm;
    DeliveredTableMap::iterator iter;
    DeliveredTableMap::iterator end;
    CalpontSelectExecutionPlan csep;
    struct timeval start_time;
    struct timeval end_time;

    MessageQueueClient* mqc = 0;

    if (!dflg)
        mqc = new MessageQueueClient("ExeMgr1");

    if (sid == -1)
    {
        time(&t);
        sessionid = static_cast<uint32_t>(t);
    }
    else
    {
        sessionid = static_cast<uint32_t>(sid);
    }
    sessionid &= 0x7fffffff;
    logging::ErrorCodes errorCodes;
    for ( ; optind < argc; optind++)
    {

        inputf.open(argv[optind]);

        if (!inputf.good())
        {
            cerr << "error opening plan stream " << argv[optind] << endl;
            return 1;
        }

        bs.reset();
        inputf >> bs;

        inputf.close();

        csep.unserialize(bs);

        csep.sessionID(sessionid);
        SessionManager sm;
        csep.verID(sm.verID());

        csep.traceFlags(0);
        ResourceManager rm;
        jl = JobListFactory::makeJobList(&csep, rm);
        csep.traceFlags(tlvl);

        if (vflg)
        {
            if (dflg)
                cout << endl << "Query:" << endl;
            else
            {
                cout << endl << "Session: " << sessionid <<
                     ", Sending Query";
                if (Bflg)
                    cout << " (" << argv[optind] << ')';
                cout << ':' << endl;
            }

            if (!Bflg)
                cout << csep.data() << endl << endl;
        }

        if (dflg)
            continue;

        try
        {
            dbs.reset();
            csep.serialize(dbs);

            gettimeofday(&start_time, 0);

            //try tuples first, but expect the worst...
            bool expectTuples = false;
            ByteStream tbs;
            ByteStream::quadbyte tqb = 4;
            tbs << tqb;
            mqc->write(tbs);

            //send the CSEP
            mqc->write(dbs);

            //read the response to the tuple request
            tbs = mqc->read();
            idbassert(tbs.length() == 4);
            tbs >> tqb;
            if (tqb == 4)
                expectTuples = true;

            if (!expectTuples)
                cout << "Using TableBand I/F" << endl;
            else
                cout << "Using tuple I/F" << endl;

            tm = jl->deliveredTables();

            iter = tm.begin();
            end = tm.end();

            OID toid;
            uint64_t rowTot;
            bool reported = false;
            bool needRGCtor = true;
            while (iter != end)
            {
                toid = iter->first;
                q = static_cast<ByteStream::quadbyte>(toid);
                tbs.reset();
                tbs << q;
                mqc->write(tbs);

                ByteStream tbbs;
                TableBand tb;
                RowGroup rg;
                rowTot = 0;
                uint16_t status = 0;
                TableBand::VBA::size_type rc;
                ofstream out;
                for (;;)
                {
                    tbbs = mqc->read();
#if 0
                    cout << tbbs.length() << endl;
                    out.open("bs1.dat");
                    idbassert(out.good());
                    out << tbbs;
                    out.close();
                    tbbs = mqc->read();
                    cout << tbbs.length() << endl;
                    out.open("bs2.dat");
                    idbassert(out.good());
                    out << tbbs;
                    out.close();
                    tbbs = mqc->read();
                    cout << tbbs.length() << endl;
                    out.open("bs3.dat");
                    idbassert(out.good());
                    out << tbbs;
                    out.close();
#endif
                    if(tbbs.length())
                    {
                        if (!expectTuples)
                            tb.unserialize(tbbs);
                        else
                        {
                            if (needRGCtor)
                            {
                                rg.deserialize(tbbs);
                                needRGCtor = false;
                                tbbs = mqc->read();
                            }
                            rg.setData((uint8_t*)tbbs.buf());
                        }
                    }
                    else
                    {   //@bug 1346
                        if (!status)
                            status = logging::makeJobListErr;
                        break;
                    }
                    if (!expectTuples)
                    {
                        rc = tb.getRowCount();
                        status = tb.getStatus();
                    }
                    else
                    {
                        rc = rg.getRowCount();
                        status = rg.getStatus();
                        if (rc == 0) status = 0;
                    }
                    if (rc == 0)
                        break;
                    rowTot += rc;
                }
                BatchPrimitive* step = dynamic_cast<BatchPrimitive*>( iter->second.get() );
                if (vflg && step)
                {
                    cout << "For table " << step->tableName();
                    if (!Bflg)
                        cout << " " << toid;
                    cout << ": read " << rowTot << " rows" << endl;
                }
                if (status && !reported)
                {
                    cout << "### Query failed: " << errorCodes.errorString(status) << "  Check crit.log\n";
                    reported = true;
                }
                if (!step && !reported)
                {
                    cout << "### Query failed: Did not return project BatchPrimitive. Check crit.log\n";
                    reported = true;
                }

                ++iter;
            }

            if (vflg)
            {
                gettimeofday(&end_time, 0);
                cout << "Query time: " << fixed << setprecision(1) << tm_diff(&start_time, &end_time) <<
                     " secs" << endl;

                //...Ask for query stats through special table id of 3
                const OID TABLE_ID_TO_GET_QUERY_STATS = 3;
                if (!Bflg)
                    cout << "Retrieving stats..." << endl;
                toid = TABLE_ID_TO_GET_QUERY_STATS;
                q = static_cast<ByteStream::quadbyte>(toid);
                statsStream.reset();
                statsStream << q;
                mqc->write(statsStream);

                ByteStream bs_statsString;
                bs_statsString = mqc->read();
                string statsString;
                bs_statsString >> statsString;

                string printStatsString;
                struct timeval startRunTime;
                parseStatsString (statsString, printStatsString, startRunTime);
                cout << printStatsString << "; QuerySetupTime-" <<
                     tm_diff(&start_time, &startRunTime) << "secs" << endl;
            }
            //...Close this query/session
            mqc->write(eoq);
            jl.reset();
        }
        catch(const exception& ex)
        {
            cout << "### SendPlan caught an exception: " << ex.what() << endl;
        }
    }
// 	jl.reset();
    CalpontSystemCatalog::removeCalpontSystemCatalog( sessionid );
    config::Config::deleteInstanceMap();

    delete mqc;

    return 0;
}
Exemplo n.º 5
0
int main (int	argc,	char   *argv[]	)
{
	g_sndbuf = 126976;
	g_sqns = 1000;

/* parse program arguments */
	const char* binary_name = strrchr (argv[0], '/');
	int c;
	while ((c = getopt (argc, argv, "b:m:t:s:n:p:r:f:k:g:w:q:lh")) != -1)
	{
		switch (c) {
		case 'b':	g_blocks = atoi(optarg); break;
		case 'm':	g_messages = atoi(optarg); break;
		case 't':	g_max_rte = atoi(optarg) * 400; break;

		case 'n':	g_network = optarg; break;
		case 's':	g_port = atoi (optarg); break;
		case 'p':	g_udp_encap_port = atoi (optarg); break;
		case 'r':	g_max_rte = atoi (optarg); break;

		case 'f':	g_fec = TRUE; break;
		case 'k':	g_k = atoi (optarg); break;
		case 'g':	g_n = atoi (optarg); break;
		case 'w':	g_sndbuf = atoi (optarg); break;
		case 'q':	g_sqns = atoi (optarg); break;

		case 'l':	g_multicast_loop = TRUE; break;

		case 'h':
		case '?': usage (binary_name);
		}
	}

	if (g_fec && ( !g_k || !g_n )) {
		puts ("Invalid Reed-Solomon parameters.");
		usage (binary_name);
	}

	log_init ();
	pgm_init ();

/* setup signal handlers */
	signal (SIGSEGV, on_sigsegv);
	signal (SIGHUP, SIG_IGN);

	ByteStream obs;
	ByteStream psbs;
	uint w = createData(obs, psbs);
	ByteStream::octbyte bytes_written = 0;
	time_t start_time = 0;
	if (!create_transport ())
	{
		start_time = time(0);
// Send total length for error check and to start timer on receive side
		gssize e = pgm_transport_send (g_transport, psbs.buf(), psbs.length(), 0);
		if (e < 0) 
			g_warning ("pgm_transport_send datasize failed.");
		for (uint i = 0; i < g_messages; ++i)
		{
			gsize e = pgm_transport_send (g_transport, obs.buf(), obs.length(), 0);
		        if (e < 0) 
				g_warning ("pgm_transport_send data failed.");

			bytes_written +=w;
		}
	}
	obs.reset();
//Send 0 length to indicate transmission finished.
	gssize e = pgm_transport_send (g_transport, &obs, 0, 0);
 	if (e < 0) 
		g_warning ("pgm_transport_send failed.");
	
	double elapsed_time = time(0) - start_time;

/* cleanup */
	if (g_transport) 
	{
		pgm_transport_destroy (g_transport, TRUE);
		g_transport = NULL;
	}

	std::cout << "pgmsend wrote " << bytes_written << " bytes with " << g_messages << " messages of " << w << " bytes in " << elapsed_time << " seconds ";
	if (elapsed_time)
		std::cout <<  bytes_written/elapsed_time/1024 << " Kbytes/second\n";
	else
		std::cout << std::endl;

	return 0;
}