示例#1
0
   void stat_helper::run(tbsys::CThread *thread, void *arg)
   {
      init();

      while (_stop == false) {
         reset();
         TAIR_SLEEP(_stop, 10);
      }
   }
示例#2
0
 bool migrate_manager::send_packet(vector<uint64_t> dest_servers, P *packet, int db_id)
 {
    bool flag = true;
    bool ret;
   _Reput:
    for(vector<uint64_t>::iterator it = dest_servers.begin(); it < dest_servers.end()&& !is_stopped;){
       ret = true;
       uint64_t server_id = *it;
       P *temp_packet = new P(*packet);
       wait_object *cwo = wait_object_mgr.create_wait_object();
       if (conn_mgr->sendPacket(server_id, temp_packet, NULL, (void*)((long)cwo->get_id())) == false) {
          log_error("Send migrate put packet to %s failure, bucket: %d",
                    tbsys::CNetUtil::addrToString(server_id).c_str(), db_id);
          delete temp_packet;
          ret = false;
       } else {
          cwo->wait_done(1, timeout);
          base_packet *tpacket = cwo->get_packet();
          if (tpacket == NULL || tpacket->getPCode() != TAIR_RESP_RETURN_PACKET) {
             log_error("Send migrate put packet 2 failure, server: %s, bucket: %d",
                       tbsys::CNetUtil::addrToString(server_id).c_str(), db_id);
             ret = false;
          } else {
             response_return *rpacket = (response_return *)tpacket;
             if (rpacket->get_code() != TAIR_RETURN_SUCCESS) {
               log_error("migrate not return success, server: %s, ret: %d", tbsys::CNetUtil::addrToString(server_id).c_str(), rpacket->get_code());
               TAIR_SLEEP(_stop, 2);
                ret = false;
             }
          }
       }
       if (ret) {
          it = dest_servers.erase(it);
       } else{
          ++it;
       }
       wait_object_mgr.destroy_wait_object(cwo);
    }
    if (is_stopped || _stop){
       flag = false;
       return flag;
    } else {
       if (!dest_servers.empty()){
          goto _Reput;
       }
    }
    return flag;
 }
示例#3
0
 void migrate_manager::set_migrate_server_list(bucket_server_map migrate_server_list, uint32_t version)
 {
    // in this case:
    // 1. server A and B owns bucket 1
    // 2. when server C joins in cluster, cs will rebuild table: server C and B owns bucket 1
    // 3. when server A has migrated bucket 1 to server C, we touch group.conf. In server_table we see server C and A will own bucket 1.
    // 4. if server C receive server_table before server A, C will migrate bucket 1 to server A. when A receive server_table, A will close bucket 1. no.. bucket 1 lost data;
    // sleep heartbeat_time before migrate.
    TAIR_SLEEP(_stop, 1);
    tbsys::CThreadGuard guard(&get_data_mutex);
    migrate_servers.swap(migrate_server_list);
    this->version = version;
    log_error("my migrate version is %d", version);
    is_running = 0;
    signal();
 }
示例#4
0
   void heartbeat_thread::run(tbsys::CThread *thread, void *arg)
   {
      if (conn_mgr == NULL) {
         return;
      }
      vector<const char*> str_list = TBSYS_CONFIG.getStringList(TAIRPUBLIC_SECTION, TAIR_CONFIG_SERVER);
      if (str_list.size() == 0U) {
         log_warn("miss config item %s:%s", TAIRPUBLIC_SECTION, TAIR_CONFIG_SERVER);
         return;
      }
      int port = TBSYS_CONFIG.getInt(CONFSERVER_SECTION, TAIR_PORT, TAIR_CONFIG_SERVER_DEFAULT_PORT);
      uint64_t id;
      for (uint32_t i=0; i<str_list.size(); i++) {
         id = tbsys::CNetUtil::strToAddr(str_list[i], port);
         if (id == 0) continue;
         config_server_list.push_back(id);
         if (config_server_list.size() == 2U) break;
      }
      if (config_server_list.size() == 0U) {
         return;
      }

      string str_msg;
      double d;

      tzset();
      int log_rotate_time = (time(NULL)-timezone) % 86400;
      while (!_stop) {
         if (getloadavg(&d, 1) == 1) curr_load = (int)(d * 100);

         heartbeat_packet.loop_count ++;
         heartbeat_packet.config_version = server_version;
         heartbeat_packet.plugins_version = plugins_version;
         // set the proxying buckets to heartbeat packet
         heartbeat_packet.vec_bucket_no.clear();
         tair_mgr->get_proxying_buckets(heartbeat_packet.vec_bucket_no);
         heartbeat_packet.pull_migrated_info = tair_mgr->is_working() ? 0 : 1;

         int stat_size = TAIR_STAT.get_size();
         const char *stat_data = TAIR_STAT.get_and_reset();
         heartbeat_packet.set_stat_info(stat_data, stat_size);

         for (uint32_t i=0; i<config_server_list.size(); i++) {
            //if ((config_server_list[i] & TAIR_FLAG_CFG_DOWN)) continue;
            request_heartbeat *new_packet = new request_heartbeat(heartbeat_packet);
            if (conn_mgr->sendPacket(config_server_list[i], new_packet, NULL, (void*)((long)i)) == false) {
               delete new_packet;
            }
         }

         // rotate log
         log_rotate_time ++;
         if (log_rotate_time % 86400 == 86340) {
            log_info("rotateLog End");
            TBSYS_LOGGER.rotateLog(NULL, "%d");
            log_info("rotateLog start");
         }
         if (log_rotate_time % 3600 == 3000) {
            log_rotate_time = (time(NULL)-timezone) % 86400;
         }

         TAIR_SLEEP(_stop, 1);
      }
   }