Esempio n. 1
0
void patcher_list_reset(codeinfo *code)
{
	STATISTICS(size_patchref -= sizeof(patchref_t) * code->patchers->size());

	// Free all elements of the list.
	code->patchers->clear();
}
Esempio n. 2
0
void emit_bccz(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options)
{
	s4 branchmpc;
	s4 disp;

	/* Target basic block already has an PC, so we can generate the
	   branch immediately. */

	if ((target->mpc >= 0)) {
		STATISTICS(count_branches_resolved++);

		/* calculate the mpc of the branch instruction */

		branchmpc = cd->mcodeptr - cd->mcodebase;
		disp      = target->mpc - branchmpc;

		emit_branch(cd, disp, condition, reg, options);
	}
	else {
		/* current mcodeptr is the correct position,
		   afterwards emit the NOPs */

		codegen_add_branch_ref(cd, target, condition, reg, options);

		/* generate NOPs as placeholder for branch code */

		BRANCH_NOPS;
	}
}
Esempio n. 3
0
int ReplicationImpl::InitFakeMaster() {
    MasterInfo info;
    int ret = master_manager_->GetMasterInfo(&info);
    if (ret) {
        ColorLogError("%s get master info fail, ret %d", __func__, ret);
        return ret;
    }

    string ip = Utils::GetIP(info.svr_id());
    if (info.svr_id() == option_->GetBinLogSvrConfig()->GetEngineSvrID()) {
        LogVerbose("%s get other ip %s", __func__, ip.c_str());
    } else {
        ctx_->SelfConn(false);
    }

    MySqlManager* mysql_manager = MySqlManager::GetGlobalMySqlManager(option_);
    if (mysql_manager->IsReplicaProcess()) {
        ip = Utils::GetIP(option_->GetBinLogSvrConfig()->GetEngineSvrID());
        ctx_->SelfConn(true);
    }

    LogVerbose("%s connect ip %s port %d", __func__, ip.c_str(), info.port());

    int master_fd = NetIO::Connect(ip.c_str(), info.port());
    if (master_fd < 0) {
		STATISTICS(ReplMySqlConnectFail());
        return SOCKET_FAIL;
    }
    return master_fd;
}
Esempio n. 4
0
patchref_t *patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp)
{
	codegendata *cd   = jd->cd;
	codeinfo    *code = jd->code;

#if defined(ALIGN_PATCHER_TRAP)
	emit_patcher_alignment(cd);
#endif

	int32_t patchmpc = cd->mcodeptr - cd->mcodebase;

#if !defined(NDEBUG)
	if (patcher_list_find(code, (void*) (intptr_t) patchmpc) != NULL)
		os::abort("patcher_add_patch_ref: different patchers at same position.");
#endif

#if defined(USES_PATCHABLE_MEMORY_BARRIER)
	PATCHER_NOPS;
#endif

	// Set patcher information (mpc is resolved later).
	patchref_t pr;

	pr.mpc         = patchmpc;
	pr.datap       = 0;
	pr.disp        = disp;
	pr.disp_mb     = 0;
	pr.patch_align = 0;
	pr.patcher     = patcher;
	pr.ref         = ref;
	pr.mcode       = 0;
	pr.done        = false;

	// Store patcher in the list (NOTE: structure is copied).
	code->patchers->push_back(pr);

	STATISTICS(size_patchref += sizeof(patchref_t));

#if defined(ENABLE_JIT) && (defined(__I386__) || defined(__SPARC_64__) || defined(__X86_64__))

	/* XXX We can remove that when we don't use UD2 anymore on i386
	   and x86_64. */

	/* On some architectures the patcher stub call instruction might
	   be longer than the actual instruction generated.  On this
	   architectures we store the last patcher call position and after
	   the basic block code generation is completed, we check the
	   range and maybe generate some nop's. */
	/* The nops are generated in codegen_emit in each codegen */

	cd->lastmcodeptr = cd->mcodeptr + PATCHER_CALL_SIZE;
#endif

	return &code->patchers->back();
}
Esempio n. 5
0
bool ExecuterBase::Execute(const int group_idx, const uint64_t instanceid, const string &paxos_value, SMCtx *sm_ctx) {
    PhxTimer timer;
    int result = SMExecute(instanceid, paxos_value);
    if (result < 0)
        return false;

    if (sm_ctx)
        *(int *) (sm_ctx->m_pCtx) = result;
	STATISTICS(PaxosExecuteTime(timer.GetTime()));
    return true;
}
Esempio n. 6
0
bool DefaultHandler::handle(MatchHandlerParamter& para, AdResultMap& result) {
  MCE_DEBUG("[MAIN_PROCESS] DefaultHandler::handle ==>NO DEFAULT  line:"<<__LINE__<<",uid " << para.userProfile_.id()<<",adzone:"<< para.adzone_->id()<<",pick_count:"<< para.PickCount())
  TimeStat ts;
  if(100000000075 == para.adzone_->id()) {
    return true;
  }

  if((100000000070 == para.adzone_->id() || 100000000072 == para.adzone_->id()) && para.is_selected_vip_) {
   // para.is_selected_vip_ = false;
    return true;
  }
  if (para.PickCount() > 0) {
    set<AdGroupPtr> default_groups;
    /*if(100000000072 != para.adzone_->id() && 100000000070 != para.adzone_->id()
      && 100000000063 != para.adzone_->id() && 100000000001 != para.adzone_->id()) {
      AdZonePtr adzone = AdZonePool::instance().GetAdZone(100000000072);
   //   MCE_DEBUG("[MAIN_PROCESS] DefaultHandler::handle ==>NO DEFAULT  line:"<<__LINE__<<",adzone:" << adzone->id())
      if(adzone) {
        default_groups = adzone->GetDefaultGroups(para.PickCount());
    //    MCE_DEBUG("[MAIN_PROCESS] DefaultHandler::handle ==>NO DEFAULT  line:"<<__LINE__)
      }
    } else {
      default_groups = para.adzone_->GetDefaultGroups(para.PickCount());
     // MCE_DEBUG("[MAIN_PROCESS] DefaultHandler::handle ==>NO DEFAULT  line:"<<__LINE__)
    }*/
    /*if(100000000072 == para.adzone_->id() || 100000000070 == para.adzone_->id()
      || 100000000063 == para.adzone_->id() || 100000000001 == para.adzone_->id()) {
      default_groups = para.adzone_->GetDefaultGroups(para.PickCount());
    }*/
    default_groups = para.adzone_->GetDefaultGroups(para.PickCount());
    if (default_groups.empty()) {
      MCE_INFO("[MAIN_PROCESS] DefaultHandler::handle ==>NO DEFAULT ads  is got, needed ad count = "
          << para.PickCount());
    } else {
      MCE_INFO("[MAIN_PROCESS] DefaultHandler::handle ==>Get DEFAULT ad from AdZone : get default_groups.size() = "
          << default_groups.size() << ", needed ad count = " << para.PickCount());
    }

    for(set<AdGroupPtr>::iterator it = default_groups.begin(); it != default_groups.end(); ++it) {
      SelectedAdGroupPtr p = new SelectedAdGroup(*it);
      p->pos_ = para.zone_selected_groups_.size() + 1;  //cost = 0
      para.zone_selected_groups_.insert(p);
      para.total_selected_groups_.insert(p);
    }

//    para.zone_selected_groups_.insert(default_groups.begin(), default_groups.end());
//    para.total_selected_groups_.insert(default_groups.begin(), default_groups.end());
  }

  STATISTICS("DefaultHandler::handle --> time = " << ts.getTime());
  return true;
}
Esempio n. 7
0
// 调整广告展示位置
bool PosAdjustHandler::handle(MatchHandlerParamter& para, AdResultMap& result) {
  TimeStat ts;
  // 调整广告展示的位置
  vector<SelectedAdGroupPtr> zone_selected(para.zone_selected_groups_.begin(), para.zone_selected_groups_.end());
  MCE_DEBUG("ads num " <<  zone_selected.size());
  /*  if(para.adzone_->id() == 100000000001) {
      Adjust(zone_selected, para.zone_selected_groups_);
    } else if ((para.adzone_->id() == 100000000063) && para.has_re_) {
      AdjustForInner(zone_selected, para.zone_selected_groups_);
    }*/
   //调整后的
  para.final_selected_groups_.swap(zone_selected);
  STATISTICS("PosAdjustHandler::handle --> time = " << ts.getTime());
  return true;
}
int ReplicationTransfer::Process() {
    ctx_->Wait();

    ColorLogInfo("dc process begin");

    if (ctx_->GetSlaveFD() < 0) {
        ColorLogError("%s slave has closed, exit", __func__);
        return SLAVE_FAIL;
    }

    int ret = OK;
    //init the gtid to get the data pos
    while (!ctx_->IsClose()) {
        vector < string > recv_buff;
        ret = ReadDataFromDC(&recv_buff);
        if (ret != OK && ret != DATA_EMPTY)
            break;

        if (ctx_->GetSlaveFD() < 0) {
            ColorLogError("%s slave has closed, exit", __func__);
            break;
        }

        if (recv_buff.size() == 0)
            continue;

        for (size_t i = 0; i < recv_buff.size(); ++i) {
            int seq = ctx_->GetSeq();
            ret = NetIO::SendWithSeq(ctx_->GetSlaveFD(), recv_buff[i], seq++);
            ctx_->SetSeq(seq);
            if (ret) {
                ColorLogError("%s send buffer fail len %zu ret %d seq %d", "slave", recv_buff[i].size(), ret, seq);
                STATISTICS(ReplSendDataFail()); 
                break;
            }
        }

        if (ret)
            break;

        LogVerbose("%s recv buffer list size %zu ret %d", "dc", recv_buff.size(), ret);
    }

    ColorLogInfo("%s transfer done, ret %d", __func__, ret);
    return ret;
}
Esempio n. 9
0
bool StyleHandler::handle(MatchHandlerParamter& para, AdResultMap& result) {
  if((100000000070 == para.adzone_->id() || 100000000072 == para.adzone_->id()) && para.is_selected_vip_) {
    para.is_selected_vip_ = false;
    return true;
  }
  TimeStat ts;
  MCE_DEBUG("StyleHandler::handle() --> user_id = " << para.userProfile_.id()
            << ", adzone_id = " << para.adzone_->id()
            << ", para.final_selected_groups_.size() = " << para.final_selected_groups_.size());
  AdStylePtr style = para.style_;
  if( style ){
    MCE_DEBUG("style replace with styleId=" << style->style_id());
	  int abs_pos = 0;
	    vector<int> bigs = style->big_widgets();
	    vector<int> smalls = style->small_widgets();
	    for(vector<SelectedAdGroupPtr>::iterator sit = para.final_selected_groups_.begin();
	        sit != para.final_selected_groups_.end(); ++sit, ++abs_pos){
	    	AdGroupPtr group_ptr = (*sit)->group_;
        if(group_ptr->member_id() == 999) {
          continue;
        }
        int widget_id = 0;
	    	map<Ice::Long, Ice::Long> creative2widget = group_ptr->creative2widget();
        if(!creative2widget.empty()) {
          (*sit)->selected_creative_id_ = creative2widget.begin()->first;
          widget_id = creative2widget.begin()->second;
        }
	    	int newId = 0;
	    	if( StyleHandler::isBig(widget_id) ){
	    		if( abs_pos < bigs.size() && bigs[abs_pos] > 0 )
	    		  newId = bigs[abs_pos];
	    	}else{
	    		if( abs_pos < smalls.size() && smalls[abs_pos] > 0)
	    		  newId = smalls[abs_pos];
	    	}
        MCE_DEBUG("adgroup_id " << group_ptr->group_id() << " widget replace: " << widget_id <<" --> " << newId);
	    	if( newId != 0 ){
          (*sit)->selected_widget_id_ = newId;
          (*sit)->extra_ = "style_test";
        }
	    }
  }
  STATISTICS("StyleHandler::handle --> time = " << ts.getTime());
  return true;
}
int ReplicationTransfer::GetEvents(vector<string> *event_list) {
    uint32_t get_num = 0;
    if (checksum_ == 0) {
        get_num = 1;
    }

    string event_data;
    int ret = event_manager_->GetEvents(&event_data, get_num);
    if (ret) {
        return ret;
    }
    STATISTICS(GtidEventTransferNum(event_list->size()));

    std::string max_gtid;
    ret = GtidHandler::ParseEventList(event_data, event_list, true, &max_gtid);

    CountCheckSum(*event_list, max_gtid);
    return ret;
}
void ReplicationTransfer::CountCheckSum(const vector<string> &event_list, const string &max_gtid) {
    LogVerbose("%s count check sum %llu, event size %zu", __func__, checksum_, event_list.size());
    if (checksum_ == 0) {
        EventDataInfo info;
        event_manager_->GetGTIDInfo(max_gtid, &info);
        checksum_ = info.checksum();
        LogVerbose("%s get data check sum %llu for init", __func__, checksum_);
    } else {
        vector < size_t > checksum_for_log;
        checksum_for_log.push_back(checksum_);
        size_t datasize = 0;
        size_t header_size = GtidHandler::GetEventHeaderSize();
        for (size_t i = 0; i < event_list.size(); ++i) {
            checksum_ = Utils::GetCheckSum(checksum_, event_list[i].c_str() + header_size,
                                           event_list[i].size() - header_size);
            datasize += event_list[i].size() - header_size;
            checksum_for_log.push_back(checksum_);
        }

        EventDataInfo info;
        int ret = event_manager_->GetGTIDInfo(max_gtid, &info);
        if (ret) {
            ColorLogError("%s get gtid data %s info fail", __func__, max_gtid.c_str());
            assert(ret == 0);
            return;
        }

        ColorLogInfo("%s get data check sum %llu, max gtid %s, gtid check sum %llu data size %zu", __func__, checksum_,
                    max_gtid.c_str(), info.checksum(), datasize);

        if (checksum_ != info.checksum()) {
            ColorLogError("%s get data check sum %llu, check fail, should be %llu", __func__, checksum_,
                           info.checksum());
            for (size_t i = 0; i < checksum_for_log.size(); ++i)
                ColorLogError("%s get check sum %llu", __func__, checksum_for_log[i]);
            checksum_for_log.push_back(checksum_);
            STATISTICS(ReplCheckSumFail());
            assert(checksum_ == info.checksum());
        }
    }
}
Esempio n. 12
0
bool RotationHandler::handle(MatchHandlerParamter& para, AdResultMap& result) {
  TimeStat ts;
  //查找轮播广告
  //轮播广告支持不止一个,需要支持指定个数的函数接口(优先级低)
  if (para.PickCount() > 0) {
    AdGroupPtr rotate_group_ptr = para.adzone_->GetRotateGroups(para.rotate_index_, para.userProfile_);

    if(rotate_group_ptr){
      set<AdGroupPtr> rotate_set;
      rotate_set.insert(rotate_group_ptr);
      Filter::instance().FilterCompete(para.userProfile_.id(), rotate_set, para.zone_selected_groups_);
      if(!rotate_set.empty()){

        //update selected
        SelectedAdGroupPtr p = new SelectedAdGroup(rotate_group_ptr);
        p->pos_ = 1;
//        para.zone_selected_groups_.insert(rotate_set.begin(), rotate_set.end());
//        para.total_selected_groups_.insert(rotate_set.begin(), rotate_set.end());
        para.zone_selected_groups_.insert(p);
        para.total_selected_groups_.insert(p);
      } else{
      }
    } else{
      MCE_INFO("[MAIN_PROCESS] RotationHandler::handle --> Get ROTATE ad from AdZone : failed");
      if ((para.adzone_->member_type() == 0) && ((para.adzone_->GetRotateSize()- para.rotate_index_) <= para.adzone_->self_rotation_number())) {
        MCE_INFO("AdMatchNManagerI::GetAds --> need ad from AdEngine/Tw: uid = " << para.userProfile_.id() 
            << ", zone_id = " << para.adzone_->id() << ", rotate_index = " << para.rotate_index_);
        AdInfoSeq ad_info_seq;
        AdInfo ad_info;
        ad_info.groupid = -1;
        ad_info_seq.push_back(ad_info);
        result[para.adzone_->id()] = ad_info_seq;
        // ans[9999963] = AdInfoSeq(); // old code, to delete
        // continue;
        return false;
      }
    }
  }
  STATISTICS("RotationHandler::handle --> time = " << ts.getTime());
  return true;
}
Esempio n. 13
0
bool LogHandler::handle(MatchHandlerParamter& para, AdResultMap& result) {
  TimeStat ts;
  TimeStat subts;
  AdInfoSeq ad_info_seq;

  ::MyUtil::StrSeq pv_log_seq;
  //::MyUtil::StrSeq engine_log_seq;
  ::MyUtil::StrSeq cpm_log_seq;

  UserProfile & profile = para.userProfile_;
  ostringstream log;
  //ostringstream engine_log;
  ostringstream cpm_log;
  MyUtil::LongSeq group_id_seq;
  vector<SelectedAdGroupPtr> zone_selected  =para.final_selected_groups_;
  std::sort(zone_selected.begin(), zone_selected.end(), sortByPos);
  for(vector<SelectedAdGroupPtr>::iterator sit = zone_selected.begin();
      sit != zone_selected.end(); ++sit){
    AdInfo ad_info;
    MyUtil::Date date(time(NULL));
    AdGroupPtr group_ptr = (*sit)->group_;
    group_id_seq.push_back(group_ptr->group_id());
    map<Ice::Long,Ice::Long> creative2widget = group_ptr->creative2widget();
    if(!group_ptr->creative_ids().empty()){
      ad_info.creativeid = *(group_ptr->creative_ids().begin());
    } else{
      ad_info.creativeid = 0;
    }
    ad_info.groupid = group_ptr->group_id();
    ad_info.updateTime = 0;
    LogParas log_para;
    log_para.cost_ = (*sit)->cost_;
    log_para.user_profile_ = para.userProfile_; //profile;
    log_para.pv_time_ = Date(time(NULL)).time();
    log_para.creative_id_ = ad_info.creativeid;
    log_para.zone_id_ = para.adzone_->id();
    log_para.max_price_ = group_ptr->max_price(log_para.zone_id_);
    log_para.ad_count_ = para.count();
    log_para.next_load_time_ = para.next_load_time_;
    log_para.refresh_idx_ = para.refresh_idx_;
    Ice::Long group_id = ad_info.creativeid / 100000;
    ostringstream append_info;
    if(!para.tag_.empty()) {
      append_info << para.tag_;
    } else {
      append_info << "rr_0";
    }
    //展示的绝对位置
    log_para.pos_ = (*sit)->pos_;
    log_para.demo_state_ = (*sit)->demo_state_;
    log_para.demo_ctr_ = (*sit)->demo_ctr_;
    log_para.widget_id_ = (*sit)->selected_widget_id_;    
    append_info << '_' << log_para.widget_id_;
    log_para.append_info_ = append_info.str();
    log_para.session_id_ = LogHelper::instance().MakeSessionId(log_para);
    log_para.demo_ctr_ = LogHelper::instance().TransCtr(log_para); //隐藏点击率
    ad_info.text = LogHelper::instance().MakeText(log_para);
    if(!(*sit)->extra_.empty()) {
      ad_info.updateTime = -1;
    } else {
      ad_info.updateTime = 0;
    }
    ad_info_seq.push_back(ad_info);

    //call AdLogAdapter
    Ice::Long zone_id = log_para.zone_id_;
    Ice::Long creativeid = log_para.creative_id_;
    string http = LogHelper::instance().MakeHttp(log_para);
    string ip = LogHelper::instance().MakeIp(profile.ip());
    int uid = profile.id();

    string deal_referer = para.referer_;
    LogHelper::instance().Process(deal_referer);
    MCE_DEBUG("LogHandler::handle-->gid:"<<(*sit)->group_->group_id()<<",pos:" <<(*sit)->pos_);

    //int sort_type = EngineConfig::instance().sort_type();
    int sort_type = EngineConfig::instance().server_index();
    //transtype修改,现在写的是数据库里读出来的,不再是写死的
    //display_type:1=轮播, 2= cpm ,3=余量, 4= cpc, 5=产品
    double cost = log_para.cost_;
    if(group_ptr->IsCpm()){
      log << setprecision(5);
    } else if(group_ptr->IsCpc()){//cpc的pv cost=0,cpm为相应扣费
      log << setprecision(0);
      cost = 0;
    }

    log << EngineConfig::instance().server_name() << "||" << ip << "||" << date.toDateTime() << "||\"GET "
        << http << " HTTP/1.0\"||200||undefined||" << log_para.session_id_ << "||undefined||" << group_ptr->trans_type() << "||" << sort_type << "||none||"
        << deal_referer << "||" << zone_id << "^B^B^B^B^B^B^B||" << creativeid << "^B" << group_ptr->member_id()
        << "^B" << group_ptr->bid_unit_id() << "^B" <<  setiosflags(ios::fixed) << cost  << setiosflags(ios::scientific) << setprecision(6)
        << "^B" << group_ptr->max_price(zone_id) << "^B" << deal_referer
        << "^B" << log_para.pos_ <<"^B" << log_para.demo_state_ << "^B2^B"<<log_para.demo_ctr_<<"||" << group_ptr->display_type();
    if((!log_para.append_info_.empty()) && (log_para.append_info_.compare("-") != 0)) {
      log << "||" << log_para.append_info_;
    }
    pv_log_seq.push_back(log.str());
    log.str("");

    if(group_ptr->IsCpm()){//cpm
     //cpm价格具体逻辑写在caculate_cost里面,要/1000
      cpm_log << log_para.creative_id_ << ',' << group_id << ',' 
              << group_ptr->campaign_id() << ',' << group_ptr->member_id() << ',' << log_para.zone_id_ << ','
	      << LogHelper::instance().FormatedClickTime(time(NULL)) << ',' << setiosflags(ios::fixed) << setprecision(5)
	      << log_para.cost_ << ',' << group_ptr->bid_unit_id() << ',' << uid << ',' << '0';
      cpm_log_seq.push_back(cpm_log.str());
      cpm_log.str("");
    }
  }
  /*engine_log << "pvlog=1\tuserid=" << profile.id() << "\tage="<< profile.age()
    << "\tgender="<< profile.gender() << "\tstage=" << profile.stage()
    << "\tgrade=" << profile.grade() << "\tcurrent_area="
    <<  ((profile.current_area().empty()) ? "-" : profile.current_area())
    << "\tip_area=" << ((profile.ip_area().empty()) ? "-" : profile.ip_area())
    << "\tschool=" << profile.school() << "\tzone_id=" << para.adzone_->id()
    << "\tgroup_id=" << group_ptr->group_id() << "\tmax_price=" << group_ptr->max_price(zone_id)
    << "\tapp_id=" << LogHelper::instance().GetAppId(para.referer_)
    << "\tmember_id=" << group_ptr->member_id() << "\tsystem_time=" << date.toDateTime();
    engine_log_seq.push_back(engine_log.str());
    engine_log.str("");*/

  result[para.adzone_->id()] = ad_info_seq;
  try {
    subts.reset();
    AdLogAdapter::instance().PvBatch(pv_log_seq);
    STATISTICS("LogHandler::handle --> TIME_TEST write pv_log : " << subts.getTime());
  } catch (Ice::Exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.PvBatch ERR line:" << __LINE__ << " err:" << e);
  } catch (std::exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.PvBatch ERR line:" << __LINE__ << " err:" << e.what());
  }
  ////////////////
  if(!cpm_log_seq.empty()){//cpm单独打charge_pv
    try {
      AdLogAdapter::instance().PvForCharge(cpm_log_seq);
    } catch (Ice::Exception& e) {
      MCE_WARN("LogHandler::handle AdLogAdapter.CpmBatch ERR line:" << __LINE__ << " err:" << e);
    } catch (std::exception& e) {
      MCE_WARN("LogHandler::handle AdLogAdapter.CpmBatch ERR line:" << __LINE__ << " err:" << e.what());
    }
  }

  /*try {
    subts.reset();
    AdLogAdapter::instance().EngineLogBatch(engine_log_seq);
    STATISTICS("LogHandler::handle --> TIME_TEST write engine_log : "
    << subts.getTime());
    } catch (Ice::Exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.EngineLogBatch ERR line:"
    << __LINE__ << " err:" << e);
    } catch (std::exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.EngineLogBatch ERR line:"
    << __LINE__ << " err:" << e.what());
    }*/

  //STATISTICS("LogHandler::handle --> time = " << ts.getTime());
  return true;
}