Пример #1
0
void UserLoginData::setLoginMap(const MyUtil::Int2IntMap& loginMap) {
	IceUtil::RWRecMutex::WLock lock(_init_flag_mutex);

	for(Int2IntMap::const_iterator iter=loginMap.begin(); iter!=loginMap.end(); ++iter) {
		_userLoginMap[iter->first] = bitset<32>(iter->second);
	}
	MCE_INFO("[UserLoginData] setLoginMap _userLoginMap size(" << _userLoginMap.size() << ")");
}
Пример #2
0
void RecordHelper::RecordThread::run() {
	while (true){

		std::vector< pair<long,Ice::ObjectPtr> > to_be_record_;
		helper_.swap( to_be_record_ );
		if( to_be_record_.empty() ){
			MCE_INFO("[RecordThread] recordBatch: 0 users." );
		}
		std::map<Ice::Int,MyUtil::Int2IntMap> logMap;
		if (time(NULL)-_today>=(24*3600)){
			for ( std::vector< pair<long, Ice::ObjectPtr> >::iterator itObj = to_be_record_.begin();
					itObj != to_be_record_.end(); ++itObj ){
				MyUtil::Int2IntMap logs = LogNotePtr::dynamicCast( itObj->second )->popLogs();
				if( !logs.empty() ){
					logMap.insert( make_pair<Ice::Int,MyUtil::Int2IntMap>(itObj->first,logs) );
				}
			}

			MCE_INFO("[RecordThread] recordBatch: " << logMap.size() << " users." );
			tzset();
                        time_t time_ = time(NULL);

                        char year[10];
                        char month[10];
                        char day[10];
                        strftime(year, sizeof(year), "%Y", localtime(&time_));
                        strftime(month, sizeof(month), "%m", localtime(&time_));
                        strftime(day, sizeof(day), "%d", localtime(&time_));
                        _today_str = string(year) + "-" + string(month) + "-" + string(day);

			_today+=24*3600;

			for ( std::vector< pair<long, Ice::ObjectPtr> >::iterator itObj = to_be_record_.begin();
				itObj != to_be_record_.end(); ++itObj) 
			TaskManager::instance().execute( new RecordBatchTask( logMap, _today_str ) );
		} else {

			for ( std::vector< pair<long, Ice::ObjectPtr> >::iterator itObj = to_be_record_.begin();
					itObj != to_be_record_.end(); ++itObj ){
				MyUtil::Int2IntMap logs = LogNotePtr::dynamicCast( itObj->second )->getLogs();
				if( !logs.empty() ){
					logMap.insert( make_pair<Ice::Int,MyUtil::Int2IntMap>(itObj->first,logs) );
				}
			}
			MCE_INFO("[RecordThread] recordBatch: " << logMap.size() << " users." );

			for ( std::vector< pair<long, Ice::ObjectPtr> >::iterator itObj = to_be_record_.begin();

			itObj != to_be_record_.end(); ++itObj )
			TaskManager::instance().execute( new RecordBatchTask( logMap, _today_str ) );
		}   	
	//	sleep(3600);
		sleep(60);
	}
}
Пример #3
0
void
MyUtil::__writeInt2IntMap(::IceInternal::BasicStream* __os, const ::MyUtil::Int2IntMap& v)
{
    __os->writeSize(::Ice::Int(v.size()));
    ::MyUtil::Int2IntMap::const_iterator p;
    for(p = v.begin(); p != v.end(); ++p)
    {
        __os->write(p->first);
        __os->write(p->second);
    }
}
Пример #4
0
void OnlineStateFilterManagerI::updateOnlineStateBatch(const ::MyUtil::Int2IntMap& onlinestatemap, const Ice::Current& current) {
    ostringstream op;
    for (Int2IntMap::const_iterator it = onlinestatemap.begin(); it != onlinestatemap.end(); ++it) {
        if (it->second) {
            _online_state.set(it->first);
        }  else {
            _online_state.reset(it->first);
        }
        op << it->first << "(" << it->second << ") ";
    }
    MCE_INFO("OnlineStateFilterManagerI::updateOnlineStateBatch -> " << op.str() );
}
Пример #5
0
void StatusCacheManagerI::updateStatusBatch(const ::MyUtil::Int2IntMap& statusmap, const Ice::Current& current){
	ostringstream op;
        for (Int2IntMap::const_iterator it = statusmap.begin(); it != statusmap.end(); ++it) {
		if ( (it->second!=0)&&(it->second!=3) ) {
			_status.set(it->first);
		}  else {
			_status.reset(it->first);
		}
		op << it->first << "(" << it->second << ") ";
        }
	MCE_INFO("StatusCacheManagerI::updateStatusBatch -> " << op.str() );
}
Пример #6
0
void
MyUtil::__readInt2IntMap(::IceInternal::BasicStream* __is, ::MyUtil::Int2IntMap& v)
{
    ::Ice::Int sz;
    __is->readSize(sz);
    while(sz--)
    {
        ::std::pair<const  ::Ice::Int, ::Ice::Int> pair;
        __is->read(const_cast< ::Ice::Int&>(pair.first));
        ::MyUtil::Int2IntMap::iterator __i = v.insert(v.end(), pair);
        __is->read(__i->second);
    }
}
Пример #7
0
void FeedItemManagerI::addFeed(const FeedItem& item,
    const FeedConfigPtr& config, const MyUtil::Int2IntMap& id2weight,
    const Ice::Current&) {
  MCE_DEBUG("FeedItemManagerI::addFeed --> feed="<<item.feed);
  //	MCE_DEBUG("FeedItemManagerI::addFeed --> feed="<<item.feed << " merge="<<item.merge << " type="<<item.type << " time="<<item.time<<"\n\ttarget-->");
  for (MyUtil::Int2IntMap::const_iterator it = id2weight.begin(); it
      != id2weight.end(); ++it) {
    UserFeedSetPtr feedSet = locateUserFeedSet(it->first);
    if (feedSet) {

      FeedPtr f = new Feed(item, it->second);
      feedSet->addFeed(f, config);
    }
  }
}
Пример #8
0
void FeedItemManagerI::AddFeed(const FeedItem& fitem,
    const FeedConfigPtr& config, const MyUtil::Int2IntMap& id2weight,
    const Ice::Current&) {
	int stype = fitem.type & 0xFFFF;
	if(MergeConfig::instance().IsComment(stype)){
		MCE_INFO("FeedItemManager::AddFeed. is comment .not add. fid:" << fitem.feed
					<< " stype:" << stype
					<< " actor:" << fitem.actor
					<< " time:" << fitem.time
					<< " id2weight:" << id2weight.size() 	);
		return;

	}
	SharedFeedPtr hdl = SharedFeedCache::instance().Add(fitem);

	vector<int> uids, uids_mem;

	BOOST_FOREACH(const MyUtil::Int2IntMap::value_type & vt, id2weight){
		int uid = vt.first;
		UserInfoPtr uinfo = FindUserInfo(uid);
		if(uinfo){
			HeavyFeed hfeed(fitem,hdl);
			hfeed.SetUpdateTime(config->updateTime);
			hfeed.SetWeight(vt.second);
			uinfo->AddHeavyItem(uid,hfeed);
			uids_mem.push_back(uid);
			Trace t("FeedItemManagerI::AddFeed");
		}
		uids.push_back(uid);
	}
Пример #9
0
void FriendFinderByActiveUserI::setBitMap(const MyUtil::Int2IntMap& loginMap, const Ice::Current& current) {
	MCE_INFO("[FriendFinderByActiveUserI] setBitMap loginMap size = " << loginMap.size());

	if (g_userLoginData_ptr == NULL) {
		MCE_WARN("[FriendFinderByActiveUserI] setBitMap g_userLoginData_ptr is null");
		g_userLoginData_ptr = new UserLoginData();
	}

	g_userLoginData_ptr->setLoginMap( loginMap );
}
Пример #10
0
RelationshipEntryList BuddyRelationCacheManagerI::getRelationBatch(const MyUtil::Int2IntMap & ids,	const Ice::Current& current){
	ostringstream msg;
  msg << ids.size() ;
  InvokeClient client = InvokeClient::create(current, msg.str(), InvokeClient::INVOKE_LEVEL_INFO);
	
  RelationshipEntryList list;
	for(MyUtil::Int2IntMap::const_iterator it=ids.begin(); it!=ids.end(); ++it)
	{
		Relationship relation ;
		relation.from = it->first;
		relation.to = it->second;

	    BuddyDesc desc=BuddyRelationCacheLogic::instance().getRelation(relation);

		RelationshipEntry entry ;
		entry.relation = relation;
		entry.desc = desc;
		list.push_back(entry);
	}

	return list;
}
Пример #11
0
MyUtil::Int2IntMap BuddyByAddTimeCacheAdapter::getFriendCounts(const MyUtil::IntSeq& ids){
	if (ids.empty()){
		return MyUtil::Int2IntMap();
	}
	size_t numCluster_sizeT = getCluster();
	int numCluster = (int)numCluster_sizeT;
	if (numCluster < 0) {
		MCE_WARN("[BuddyByAddTimeCacheAdapter::getFriendCounts] this should not be seen! Why cluster=" << numCluster_sizeT << " ???" );
		return MyUtil::Int2IntMap();
	}
	if (numCluster == 0 || numCluster == 1) {
		try {
			return getProxy(ids.at(0))->getFriendCounts(ids);
		} catch (...) {
			return MyUtil::Int2IntMap();
		}
	} else {
		vector< vector<int> > seperatedIds;
		seperatedIds.resize(numCluster);
		for (MyUtil::IntSeq::const_iterator it = ids.begin(); it
				!= ids.end(); ++it) {
			seperatedIds.at(*it % numCluster).push_back(*it);
		}
		MyUtil::Int2IntMap result;
		for (int posCluster = 0; posCluster < numCluster; ++posCluster) {
			MyUtil::Int2IntMap someResult;
			if( seperatedIds.at(posCluster).size() > 0 ){
				try {
					someResult = getProxy(posCluster)->getFriendCounts(seperatedIds.at(posCluster));
				} catch (...) {
					MCE_WARN( "BuddyByAddTimeCacheAdapter::getFriendCounts from Proxy(" << posCluster << ") handle unknown exception." );
				}
				result.insert( someResult.begin(), someResult.end() );
			}
		}
		return result;
	}
}
Пример #12
0
void UserStateFilterManagerI::updateUserStateBatch(const ::MyUtil::Int2IntMap& statemap, const Ice::Current& current){
	ostringstream op;
        for (Int2IntMap::const_iterator it = statemap.begin(); it != statemap.end(); ++it) {
		op << " " << it->first;
		if (it->second&1) {
			_user_state_star.set(it->first);
			op << "(1:true)";
		} else {
			_user_state_star.reset(it->first);
			op << "(1:false)";
		}

		if (it->second&5) {
			_user_state_guide.reset(it->first);
			op << "(5:false)";
		} else {
			_user_state_guide.set(it->first);
			op << "(5:true)";
		}
        }
	MCE_INFO("UserStateFilterManagerI::updateUserStateBatch -> " << op.str()
                << " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
}
Пример #13
0
void SetDataHelper::SetDataThread::run() {
  while (true){
    std::vector< pair<long,Ice::ObjectPtr> > to_be_set_;
    helper_.swap( to_be_set_ );
    if( to_be_set_.empty() ){
      MCE_INFO("[SetDataHelper::SetDataThread::run] setData: 0 objs." );
      continue;
    }
    ostringstream idstr;
    MyUtil::ObjectResultPtr objs = new MyUtil::ObjectResult();
    MyUtil::Int2IntSeqMap lists;
    MyUtil::Int2IntMap counts;
    for ( std::vector< pair<long, Ice::ObjectPtr> >::iterator it = to_be_set_.begin();
        it != to_be_set_.end(); ++it ){
      objs->data.insert(*it);
      MyUtil::IntSeq& list = BuddyFriendsDataPtr::dynamicCast( it->second )->friends;
      lists.insert( make_pair<Ice::Int,MyUtil::IntSeq>(it->first,list) );
      counts.insert( make_pair<Ice::Int,Ice::Int>(it->first,list.size()) );
      idstr << " " << it->first << "(" << list.size() << ")";
    }
    MCE_INFO("[SetDataHelper::SetDataThread::run] setData:" << idstr.str() );
    BuddyFriendsCacheAdapter::instance().setData(objs);
  }
}
Пример #14
0
void DataNodeManager::putBatch(const FeedItem& feed, const MyUtil::Int2IntMap& usersWeight) {
    static const unsigned int MAX_MSG_SIZE = 5000;
    map<int, vector<pair<bool, BlockInfoSeq> > > blkInfoMap;
    Int2IntMap::const_iterator it = usersWeight.begin();
    //pair<bool, BlockInfoSeq> p = make_pair<bool, BlockInfoSeq>(false, BlockInfoSeq());
    for(; it!=usersWeight.end(); ++it) {
        //if((it->first%10 > 5)){
        //	continue;
        //}
        if(it->first == 0) {
            continue;
        }
        BlockInfoPtr blk = get(it->first, true);
        if(!blk) {
            MCE_WARN("DataNodeManager::putBatch --> can not get a block " << it->first);
            continue;
        }
        if(blk->userId==261947900 || blk->userId==227805680) {
            MCE_INFO("#put# userid:"<<it->first<<" file:"<<blk->fileId<<" index:"<<blk->blockIndex
                     <<" tc:"<<blk->totalCount<<" cc:"<<blk->curCount << " preF:" << blk->preFileId << " preB:" << blk->preBlockIndex
                     <<" -- " << " feed:" << feed.feed);
        }
        blk->weight = it->second;
        //MCE_INFO("@@get block " << userIds.at(i) << " " << blk->serverId);
        //Blk2FeedPtr tmp = new Blk2Feed;
        //tmp->blkInfo = blk;
        //tmp->feed = it->second;
        if(blkInfoMap[blk->serverId].empty() || blkInfoMap[blk->serverId].rbegin()->second.size() >= MAX_MSG_SIZE) {
            blkInfoMap[blk->serverId].push_back(pair<bool, BlockInfoSeq>(false, BlockInfoSeq()));
        }
        if(blk->curCount == 1) {
            blkInfoMap[blk->serverId].rbegin()->first = true;
        }
        blkInfoMap[blk->serverId].rbegin()->second.push_back(blk);
        //blkInfoMap[blk->serverId].push_back(blk);
    }
    map<int, vector<pair<bool, BlockInfoSeq> > >::iterator tmpIt = blkInfoMap.begin();
    for(; tmpIt!=blkInfoMap.end(); ++tmpIt) {
        for(size_t i=0; i<tmpIt->second.size(); i++) {
            //最多重试10次
            //for(int j=0; j<10; j++){
            TimeStat t;
            try {
                MCE_INFO("DataNodeManager::putBatch --> invoke SSDFeedDBData" << tmpIt->first << " size:" << tmpIt->second.at(i).second.size());
                SSDFeedDBDataAdapter::instance().putBatchBinary(feed, tmpIt->second.at(i).second);
            } catch(Ice::Exception& e) {
                MCE_WARN("DataNodeManager::putBatch --> invoke SSDFeedDBData" << tmpIt->first << " err, " << e);
                RetryTimer::instance().push(feed, tmpIt->second.at(i).second);
                //string tmp = e.what();
                //if(tmp.find("TimeoutException") != string::npos){
                //	break;
                //}
                //if(!tmpIt->second.at(i).first){
                //	break;
                //}
            }
            PerformanceStat::instance().stat("CallData", t.getTime());
            //}
        }
    }
    //MCE_INFO("batch put --> " << usersWeight.size() << " " << blkInfoMap.size());

}