Ejemplo n.º 1
0
int CInsertTools::LoadPeers()
{
	CMysql Mysql;
	char szSqlBuf[1024];
	struct timespec tm1, tm2;

	try
	{
		Mysql.Init();
		Mysql.Connect(m_conf.GetConfItem().vecDbItems[0].strIp, m_conf.GetConfItem().vecDbItems[0].strUserName, m_conf.GetConfItem().vecDbItems[0].strPasswd);
		snprintf(szSqlBuf, sizeof(szSqlBuf), "select * from %s.%s;", m_conf.GetConfItem().strDbName.c_str(), ONLINE_PEER_TABLE.c_str());
		Mysql.Query(szSqlBuf);

		clock_gettime(CLOCK_MONOTONIC, &tm1);
		int nIndex = 0;
		long lUseTime = 0;
		int nSleepTime = (int)((1000 / (float)m_conf.GetConfItem().nSpeedPerSec) * 0.85 * 100 * 1000);
		string strPeerId;
		while(Mysql.FetchRow())
		{
			strPeerId = Mysql.GetField("fpeerid");

			CInsertPeerCmd reqCmd(strPeerId);
			reqCmd.Process();
			TransMsg(reqCmd.GetBuf(), reqCmd.GetBufLen(), 0, MACHINE_TYPE, ONLINE_SYN);
			nIndex ++;
			if(nIndex % 100 == 0)
			{
				usleep(nSleepTime);
			}
			if(nIndex >= m_conf.GetConfItem().nSpeedPerSec)
			{
				clock_gettime(CLOCK_MONOTONIC, &tm2);
				lUseTime =  (tm2.tv_sec - tm1.tv_sec) * 1000000000 + (tm2.tv_nsec - tm1.tv_nsec);
				lUseTime = lUseTime / 1000;
				WRITE_ALL_LOG(DEBUG_LOG_TYPE, "send %d peer info, use time %ld microsec", nIndex, lUseTime);
				nIndex = 0;
				lUseTime = 0;
				clock_gettime(CLOCK_MONOTONIC, &tm1);
			}
		}
		Mysql.FreeResult();
	}
	catch (CMysqlException& e)
	{
		WriteRunInfo::WriteError("CInsertTools::LoadPeers, sql %s, error %s", szSqlBuf, e.GetErrMsg());
		return -1;
	}
	return 0;
}
Ejemplo n.º 2
0
int MysqlUpdateTest(CMysql &hMySql)
{
    char szSql[] =
            "update gslbcc2.Tbl_Domain_Info set ulAux='100' where strDomain='www.qq.com.';";
    try
    {
        hMySql.Query(szSql);
    } catch (CCommonException & ex)
    {
        Err("[MysqlUpdateTest] Fail!");
        return -1;
    }
    Info("[MysqlUpdateTest] OK!");
    return 0;
}
Ejemplo n.º 3
0
int MysqlSelectTest(CMysql &hMySql)
{
    char szSql[] =
            "select * from gslbcc2.Tbl_Domain_Info where strDomain='www.qq.com.';";
    try
    {
        hMySql.Query(szSql);
        hMySql.StoreResult();
        while (NULL != hMySql.FetchRow())
        {
            char * pszDomain = hMySql.GetField("strDomain");
            char * pszAux = hMySql.GetField("ulAux");
            size_t nAux = (pszAux) ? atoi(pszAux) : 0;

            Info("[MysqlSelectTest] OK! strDomain[%s], ulAux[%u]",pszDomain, nAux);
        }
    } catch (exception &ex)
    {
        Err("[MysqlSelectTest] Fail!");
        return -1;
    }

    return 0;
}
Ejemplo n.º 4
0
int CInsertTools::LoadRc()
{
	CMysql Mysql;
	char szSqlBuf[1024];
	string strPeerId;
	long long llFileSize;
	string strGcid;
	int nCapability;
	unsigned char nDownloadScale;
	struct timespec tm1, tm2;
	int nIndex = 0;
	long lUseTime = 0;
	int nSleepTime = (int)((1000 / (float)m_conf.GetConfItem().nSpeedPerSec) * 0.85 * 100 * 1000);
	clock_gettime(CLOCK_MONOTONIC, &tm1);

	for (int i = 0; i < m_conf.GetConfItem().nDbNum; i ++)
	{
		try
		{
			Mysql.Init();
			Mysql.Connect(m_conf.GetConfItem().vecDbItems[i].strIp, m_conf.GetConfItem().vecDbItems[i].strUserName, m_conf.GetConfItem().vecDbItems[i].strPasswd);

			for (int j = 0; j < m_conf.GetConfItem().nTableNum; j ++)
			{
				stringstream strTableName;
				strTableName << RC_PEER_TABLE;
				strTableName << j;
				snprintf(szSqlBuf, sizeof(szSqlBuf), "select * from %s.%s;", m_conf.GetConfItem().strDbName.c_str(), strTableName.str().c_str());
				strTableName.clear();
				Mysql.Query(szSqlBuf);

				while(Mysql.FetchRow())
				{
					strGcid = Mysql.GetField("fcid");
					strPeerId = Mysql.GetField("fpeerid");
					llFileSize = strtoul(Mysql.GetField("ffilesize"), 0, 10);
					nCapability = strtoul(Mysql.GetField("fcapability"), 0, 10);
					nDownloadScale = strtoul(Mysql.GetField("downpercent"), 0, 10);

					CInsertRcCmd reqCmd(strGcid, strPeerId, llFileSize, nCapability, nDownloadScale);
					reqCmd.Process();
					TransMsg(reqCmd.GetBuf(), reqCmd.GetBufLen(), 0, MACHINE_TYPE, CONNECT_SERVER_COMMON);

					nIndex ++;
					if(nIndex % 100 == 0)
					{
						usleep(nSleepTime);
					}
					if(nIndex >= m_conf.GetConfItem().nSpeedPerSec)
					{
						clock_gettime(CLOCK_MONOTONIC, &tm2);
						lUseTime =  (tm2.tv_sec - tm1.tv_sec) * 1000000000 + (tm2.tv_nsec - tm1.tv_nsec);
						lUseTime = lUseTime / 1000;
						WRITE_ALL_LOG(DEBUG_LOG_TYPE, "send %d rc info, use time %ld microsec", nIndex, lUseTime);
						nIndex = 0;
						lUseTime = 0;
						clock_gettime(CLOCK_MONOTONIC, &tm1);
					}
				}
				Mysql.FreeResult();
			}

			for (int j = 0; j < m_conf.GetConfItem().nTableNum; j ++)
			{
				stringstream strTableName;
				strTableName << RC_PEER_TEMP_TABLE;
				strTableName << j;
				snprintf(szSqlBuf, sizeof(szSqlBuf), "select * from %s.%s;", m_conf.GetConfItem().strDbName.c_str(), strTableName.str().c_str());
				strTableName.clear();
				Mysql.Query(szSqlBuf);

				while(Mysql.FetchRow())
				{
					strGcid = Mysql.GetField("fcid");
					strPeerId = Mysql.GetField("fpeerid");
					llFileSize = strtoul(Mysql.GetField("ffilesize"), 0, 10);
					nCapability = strtoul(Mysql.GetField("fcapability"), 0, 10);
					nDownloadScale = strtoul(Mysql.GetField("downpercent"), 0, 10);

					CInsertRcCmd reqCmd(strGcid, strPeerId, llFileSize, nCapability, nDownloadScale);
					reqCmd.Process();
					TransMsg(reqCmd.GetBuf(), reqCmd.GetBufLen(), 0, MACHINE_TYPE, CONNECT_SERVER_COMMON);

					nIndex ++;
					if(nIndex % 100 == 0)
					{
						usleep(nSleepTime);
					}
					if(nIndex >= m_conf.GetConfItem().nSpeedPerSec)
					{
						clock_gettime(CLOCK_MONOTONIC, &tm2);
						lUseTime =  (tm2.tv_sec - tm1.tv_sec) * 1000000000 + (tm2.tv_nsec - tm1.tv_nsec);
						lUseTime = lUseTime / 1000;
						WRITE_ALL_LOG(DEBUG_LOG_TYPE, "send %d rc temp info, use time %ld microsec", nIndex, lUseTime);
						nIndex = 0;
						lUseTime = 0;
						clock_gettime(CLOCK_MONOTONIC, &tm1);
					}
				}
				Mysql.FreeResult();
			}
		}
		catch (CMysqlException& e)
		{
			WriteRunInfo::WriteError("CInsertTools::LoadPeers, sql %s, error %s", szSqlBuf, e.GetErrMsg());
			return -1;
		}
	}
	
	return 0;
}