示例#1
0
JobStatus FullSnapJob::onSyncData(bool bto, int res)
{
	if(bto || res != 0){
		return onFailure(bto,res);
	}else{
		for(std::vector<Meta>::const_iterator it = infos.begin(); it != infos.end(); ++it){
			const Meta& m = *it;
			if((m.serverId&0xFFF) == cli->nv->getUniqNodeId())
			{
				if(((m.serverId>>16) != 0))
				{
					LogTrace(Error, "NodeId conflict, please have a check,m.serverId = %lld,mynodeId = %d",m.serverId, cli->nv->getUniqNodeId());
					complete = true;
					cli->snapGameover = true;
					return JOBSTOP;
				}
				else
				{
					LogTrace(Warn, "meta about my service, serverId = %lld,  name = %s, groupId = %d", m.serverId, m.name.c_str(), m.groupId);
				}
			}
			
			log(Debug, "set metaId:%lld ts:%lld", m.serverId, m.timestamp);
			int ret = cli->mDao->set(m, false);
			if(ret < 0 ){
				LogTrace(Error, "meta set error, errno = %d", myerrno);
				if(myerrno == ETIMESTAMPLT)
				{
					LogTrace(Error, "this is empty node, meta should not be timeout");
					complete = true;
					cli->snapGameover = true;
					return JOBSTOP;					
				}
				
				ASYNC_CALL(System, sleep, &FullSnapJob::onWakeup, 1000 * 10);
				return SYSDEFAULT;
			}
			if(m.isDel == 0)
			{
				syncUndelMetaCount++;
			}
			else
			{
				syncDelMetaCount++;
			}
				
			lastServerId = it->serverId;
		}
		size_t sz = infos.size();
		LogTrace(Info, "sync meta data, size = %d,lastServerId = %lld ", infos.size(), lastServerId);
		infos.clear();
		if(sz < 1000){
			step = SyncLastLsn_C;
			ASYNC_CALL(SnapService, getLsns, &FullSnapJob::onSyncLsn, logs, sessionId);
		}else{
			ASYNC_CALL(SnapService, getMetas, &FullSnapJob::onSyncData, infos, sessionId, lastServerId, 1000);

		}
		return SYSDEFAULT;
	}
示例#2
0
JobStatus FullSnapJob::onSyncLog(bool bto, int res)
{
	if(bto || res != 0){
		return onFailure(bto,res);
	}else{
		size_t sz = logs.size();
		bool applyErr = false;
		size_t i = 0;
		for(; i < sz; ++i){
			const DLog& dlog = logs[i];
			int ret = cli->mDao->apply(dlog,false);
			if(ret<0)
			{
				LogTrace(Error, "sync log apply error, errno = %d", myerrno);
				applyErr = true;
				break;
			}
			lastLsnId = dlog.lsn;
		}
		syncLogCount += i; // count the stored DLog;
		LogTrace(Info, "sync log, sz = %d, total = %d", sz, syncLogCount);
		logs.clear();

		if(applyErr)
		{
			ASYNC_CALL(System, sleep, &FullSnapJob::onWakeup, 1000 * 10);
			return SYSDEFAULT;			
		}

		if(sz < 1000)
		{
			lsnVecIndex++;
			lastLsnId = 0;
			if(lsnVecIndex < cli->lastLsn.size()) // sync Dlog of next nodeid
			{
				ASYNC_CALL(SnapService, getDLogs, &FullSnapJob::onSyncLog, logs, sessionId,cli->lastLsn[lsnVecIndex].node,lastLsnId,1000);
			}
			else // sync finished, stop
			{
				ASYNC_CALL(SnapService, snapStop, &FullSnapJob::onStop, stop, sessionId);
				return SYSDEFAULT;
			}
		}
		else
		{
			ASYNC_CALL(SnapService, getDLogs, &FullSnapJob::onSyncLog, logs, sessionId,cli->lastLsn[lsnVecIndex].node,lastLsnId,1000);
		}

		return SYSDEFAULT;
	}
}
示例#3
0
JobStatus FullSnapJob::onSyncLsn(bool bto, int res)
{
	if(bto || res != 0){
		return onFailure(bto, res);
	}else{
		std::vector<Lsn> tmpLsns;
		for(std::vector<DLog>::const_iterator it = logs.begin(); it != logs.end(); ++it){
			Lsn tmp; 
			tmp.node = it->node;
			tmp.lsn = it->lsn;
			tmpLsns.push_back(tmp);
			LogTrace(Info, "node = %d, lsn = %lld",tmp.node, tmp.lsn);
		}
		logs.clear();
		cli->lastLsn.swap(tmpLsns);  // update session sync's lastlsns

		if(cli->lastLsn.empty())
		{
			LogTrace(Error,"last lsn is empty");
			complete = true;
			cli->snapGameover = true;
			return JOBSTOP;			
		}

		lsnVecIndex = 0;
		lastLsnId = 0;
		
		step = SyncDLog_C;
		ASYNC_CALL(SnapService, getDLogs, &FullSnapJob::onSyncLog, logs, sessionId,cli->lastLsn[lsnVecIndex].node,lastLsnId,1000);

		return SYSDEFAULT;
	}
}
示例#4
0
static void colo_proxy_wait_for_checkpoint(libxl__egc *egc,
                                           libxl__colo_save_state *css)
{
    libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css);

    ASYNC_CALL(egc, dss->cds.ao, &css->child, css,
               colo_proxy_async_wait_for_checkpoint,
               colo_proxy_async_call_done);
}
示例#5
0
JobStatus  FullSnapJob::doReconnect()
{
	LogTrace(Info,"Method Entry");
	failCount = 0;
	syncLogCount = 0;
	syncUndelMetaCount = 0;
	syncDelMetaCount = 0;
	
	cli->lastLsn.clear();
	
	int port = 0;
	curIp.clear();
	if(cli->cfg->isLocalDaemon())
	{
		if(ipIndex < cli->ipListFromDns.size())
		{
			curIp = cli->ipListFromDns[ipIndex];
			port = cli->cfg->cSnapPort;
		}
	}
	else  // daemon
	{
		if(ipIndex < cli->ipListFromXml.size()){  // after DNS,select a new ip;
			curIp = cli->ipListFromXml[ipIndex].ip;
			port = cli->ipListFromXml[ipIndex].port;
			targetNode = cli->ipListFromXml[ipIndex].gid;
		}
	}

	ipIndex++;
	if(curIp.empty())
	{
		LogTrace(Error,"failure from all daemons, please have a check");
		cli->snapGameover = true;
		return JOBSTOP;
	}

	LogTrace(Info,"curIP = %s, isLocalDaemon = %d", curIp.c_str(), cli->cfg->isLocalDaemon());
	IAsyncCenter *center = cli->center;

	TRowTransportFactory *to = new TRowTransportFactory();
	to->init(center->getClientConnFactory(), ctxMgr->getHandler(), curIp, port);
	to->setMainThreadQueue(center->getMainQueue());
	tf.reset(to);

	SETTRANSPORT(SnapService, tf);
	step = SyncNotStart_C;
	ASYNC_CALL(SnapService, snapStart, &FullSnapJob::onStarted, sessionId, cli->nv->getGid(), targetNode);

	return SYSDEFAULT;
}
示例#6
0
JobStatus FullSnapJob::onWakeup(bool bto, int res)
{
	if(step == SyncMetaData_C)
	{
		ASYNC_CALL(SnapService, getMetas, &FullSnapJob::onSyncData, infos, sessionId, lastServerId, 1000);
	}
	else if(step == SyncDLog_C)
	{
		ASYNC_CALL(SnapService, getDLogs, &FullSnapJob::onSyncLog, logs, sessionId,cli->lastLsn[lsnVecIndex].node,lastLsnId,1000);
	}
	else if(step == SyncLastLsn_C)
	{
		ASYNC_CALL(SnapService, getLsns, &FullSnapJob::onSyncLsn, logs, sessionId);
	}
	else
	{
		LogTrace(Error,"invalid step = %d", step);
		complete = true;
		cli->snapGameover = true;
		return JOBSTOP;		
	}
	return SYSDEFAULT;	
}
示例#7
0
JobStatus FullSnapJob::onStarted(bool bto, int res)
{	
	if(bto || res != 0){
		LogTrace(Warn, "time out or err, bto = %d, res = %d, mine = %d,targetNode = %d", bto, res, cli->nv->getGid(), targetNode);
		return doReconnect();
	}else{
		if(startCount >0)
		{
			LogTrace(Warn, "prev snap failure, truncate the DB");
			cli->mDao->truncate();
		}
		lastServerId = 0;
		step = SyncMetaData_C;
		startCount++;
		ASYNC_CALL(SnapService, getMetas, &FullSnapJob::onSyncData, infos, sessionId, lastServerId, 1000);
		return SYSDEFAULT;
	}
}