int ObSchemaServiceMsProvider::get_ms(const ObScanParam &scan_param, const int64_t retry_num, ObServer &ms)
{
  int ret = OB_SUCCESS;
  UNUSED(scan_param);
  if (0 < retry_num
      && 0 != ms.get_port()
      && 0 != ms.get_ipv4())
  {
    update_ms_retry(ms);
  }
  if (did_need_reset())
  {
    if (OB_SUCCESS != (ret = reset()))
    {
      TBSYS_LOG(WARN, "failed to init schema service ms provider, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (retry_num >= count_)
    {
      TBSYS_LOG(DEBUG, "no more ms for scan, retry=%ld count=%ld", retry_num, count_);
      ret = OB_MS_ITER_END;
    }
    else
    {
      tbsys::CRLockGuard guard(rwlock_);
      ms = ms_carray_[retry_num].ms_;
    }
  }
  return ret;
}
Esempio n. 2
0
     /**
     * post_packet is async version of send_packet. donot wait for response packet.
     */
    int ObClientManager::do_post_packet(const ObServer& server, ObPacket* packet,
        tbnet::IPacketHandler* handler, void* args) const
    {
      int rc = OB_SUCCESS;
      if (NULL == packet) 
      {
        rc = OB_INVALID_ARGUMENT;
      }
      else if (!inited_) 
      {
        rc = OB_NOT_INIT;
        TBSYS_LOG(ERROR, "cannot post packet, ClientManager not initialized.");
        packet->free();
      }
      else
      {
        bool send_ok = connmgr_->sendPacket(server.get_ipv4_server_id(), packet, handler, args);
        if (!send_ok)
        {
          rc = OB_PACKET_NOT_SENT;
          TBSYS_LOG(WARN, "cannot post packet, maybe send queue is full or disconnect.dest_server:%s",
              server.to_cstring());
          packet->free();
        }
      } 

      return rc;
    }
TEST_F(TestTabletLocationItem, test_serialize)
{
  ObMergerTabletLocation server;
  ObMergerTabletLocationList list;
  list.set_timestamp(1000); 
  ObTabletLocation temp_server;
  ObServer chunkserver;
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 300000, i + 1024);
    temp_server.tablet_version_ = i;
    temp_server.chunkserver_ = chunkserver;
    EXPECT_TRUE(OB_SUCCESS == list.add(temp_server));
    EXPECT_TRUE(i + 1 == list.size());
  }
  
  list.print_info();
  int64_t size = list.get_serialize_size();
  EXPECT_TRUE(size != 0);
  
  char * temp = new char[size];
  EXPECT_TRUE(NULL != temp);
  int64_t pos = 0;
  EXPECT_TRUE(OB_SUCCESS != list.serialize(temp, size - 1 , pos));
  pos = 0;
  EXPECT_TRUE(OB_SUCCESS == list.serialize(temp, size, pos));
  EXPECT_TRUE(pos == size);
  
  ObMergerTabletLocationList list2;
  pos = 0;
  EXPECT_TRUE(OB_SUCCESS == list2.deserialize(temp, size, pos));
  list2.print_info();
  list.print_info();
}
int ObSchemaServiceMsProvider::reset()
{
  int ret = OB_SUCCESS;
  tbsys::CWLockGuard guard(rwlock_);
  count_ = 0;
  ObChunkServerManager::const_iterator it;
  for (it = server_manager_.begin();
       server_manager_.end() != it && count_ < MAX_SERVER_COUNT;
       ++it)
  {
    if (ObServerStatus::STATUS_DEAD != it->ms_status_)
    {
      ObServer ms = it->server_;
      ms.set_port(it->port_ms_);
      ms_carray_[count_].ms_ = ms;
      ms_carray_[count_].retry_count_ = 0;
      ++count_;
      TBSYS_LOG(DEBUG, "schema service ms provider found count_=%ld, ms=%s", count_, to_cstring(ms));
    }
  } // end for
  // shuffle the server list after reset
  if (count_ > 0)
  {
    // std::random_shuffle(ms_carray_, ms_carray_ + count_);
  }
  return ret;
}
TEST_F(TestTabletLocationItem, test_deserialize)
{
  ObMergerTabletLocation server;
  ObMergerTabletLocationList list;
  list.set_timestamp(1000);
  ObTabletLocation temp_server;
  ObServer chunkserver;
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 300000, i + 1024);
    temp_server.tablet_version_ = i;
    temp_server.chunkserver_ = chunkserver;
    EXPECT_TRUE(OB_SUCCESS == list.add(temp_server));
    EXPECT_TRUE(i + 1 == list.size());
  }
  ObStringBuf buffer;
  list.set_buffer(buffer);
  list.print_info();
  char start[1024] = "0x00000000";
  char end[1024] = "0xFFFFFFFF";
  ObRange range;
  range.start_key_.assign(start, (int32_t)strlen(start));
  range.end_key_.assign(end, (int32_t)strlen(end));
  int ret = list.set_tablet_range(range);
  EXPECT_TRUE(OB_SUCCESS == ret);
  int64_t size = list.get_serialize_size();
  EXPECT_TRUE(size != 0);
  char * temp = new char[size];
  EXPECT_TRUE(NULL != temp);
  int64_t pos = 0;
  EXPECT_TRUE(OB_SUCCESS != list.serialize(temp, size - 1 , pos));
  pos = 0;
  EXPECT_TRUE(OB_SUCCESS == list.serialize(temp, size, pos));
  EXPECT_TRUE(pos == size);

  ObMergerTabletLocationList list2;
  list2.set_buffer(buffer);
  pos = 0;
  EXPECT_TRUE(OB_SUCCESS == list2.deserialize(temp, size, pos));
  list2.print_info();
  list.print_info();
  char start1[1024] = "0x0000000000";
  char end1[1024] = "0xFFFFFFFFFF";
  range.start_key_.assign(start1, (int32_t)strlen(start1));
  range.end_key_.assign(end1, (int32_t)strlen(end1));
  EXPECT_TRUE(OB_SUCCESS == list.set_tablet_range(range));
  size = list.get_serialize_size();
  EXPECT_TRUE(size != 0);
  delete []temp;
  temp = new char[size];
  EXPECT_TRUE(NULL != temp);
  pos = 0;
  EXPECT_TRUE(OB_SUCCESS == list.serialize(temp, size, pos));
  pos = 0;
  EXPECT_TRUE(OB_SUCCESS != list2.deserialize(temp, size, pos));
  //
  pos = 0;
  list2.reset();
  EXPECT_TRUE(OB_SUCCESS == list2.deserialize(temp, size, pos));
}
Esempio n. 6
0
int MockRootServer::handle_get_updater(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }
  
  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());
    
    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    
    // new version
    int32_t channel_id = ob_packet->getChannelId();
    ObServer server;
    server.set_ipv4_addr("localhost", MockUpdateServer::UPDATE_SERVER_PORT); 
    ret = server.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    ret = send_response(OB_REPORT_TABLETS_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  return ret;
}
Esempio n. 7
0
int ObClientServerStub::get_cs_and_ms()
{
  int                   ret = OB_SUCCESS;
  ObChunkServerManager  obcsm;
  ObChunkServerManager::const_iterator it;
  ObServer              server;
  
  ret = rs_dump_cs_info(obcsm);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr, "Get chunk server manager error!\n");
    return ret;
  }

  for (it = obcsm.begin(); it != obcsm.end(); ++it)
  {
    ObServer node;
    node = it->server_;
    node.set_port(it->port_cs_);
    chunk_server_list_.push_back(node);
    node.set_port(it->port_ms_);
    merge_server_list_.push_back(node);
  }

  return ret;
}
TEST_F(TestTabletLocationItem, test_valid)
{
  ObMergerTabletLocationList list;
  ObTabletLocation temp_server;
  ObServer chunkserver;
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 300000, i + 1024);
    temp_server.tablet_version_ = i;
    temp_server.chunkserver_ = chunkserver;
    EXPECT_TRUE(OB_SUCCESS == list.add(temp_server));
  }
  
  // all invalid 
  ObMergerTabletLocation server;
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 300000, i + 1024);
    server.server_.chunkserver_ = chunkserver;
    server.server_.tablet_version_ = i;
    EXPECT_TRUE(OB_SUCCESS == list.set_item_invalid(server));
    EXPECT_TRUE(list[i].err_times_ == ObMergerTabletLocation::MAX_ERR_TIMES);
  }
  
  list.set_item_valid(1100);
  EXPECT_TRUE(list.get_timestamp() == 1100);
  for (int64_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    EXPECT_TRUE(list[i].err_times_ == 0); 
  }
}
int ObScanHelperImpl::mutate(ObMutator& mutator)
{
  int ret = OB_SUCCESS;
  if (!check_inner_stat())
  {
    ret = OB_NOT_INIT;
    TBSYS_LOG(ERROR, "scan help not init");
  }
  else
  {
    ObServer ups;
    if (OB_SUCCESS != (ret = ups_provider_->get_ups(ups)))
    {
      TBSYS_LOG(WARN, "failed to get ups, err=%d", ret);
    }
    else if (0 == ups.get_port() || 0 == ups.get_ipv4())
    {
      ret = OB_INVALID_ARGUMENT;
      TBSYS_LOG(WARN, "invalid update server address");
    }
    else if (OB_SUCCESS != (ret = rpc_stub_->mutate(ups, mutator, mutate_timeout_us_)))
    {
      TBSYS_LOG(WARN, "failed to mutate, mutate_timeout_us_=%ld, ups=%s, err=%d",
          mutate_timeout_us_, to_cstring(ups), ret);
    }
    else
    {
      TBSYS_LOG(DEBUG, "ups mutate succ, ups=%s", to_cstring(ups));
    }
  }
  return ret;
}
    int ObAppStats::sum_cluster_stats(const ObRole server_type, const common::ObArrayHelper<common::ObServer>& server_array)
    {
      ObStatManager node_stats;
      node_stats.set_server_type(server_type);
      char addr_string[MAX_SERVER_NUM];
      int ret = OB_SUCCESS;

      for (int i = 0; i < server_array.get_array_index(); i++)
      {
        ObServer addr = *server_array.at(i);
        addr.to_string(addr_string, MAX_SERVER_NUM);
        ObClientRpcStub remote_stub;
        if (OB_SUCCESS != (ret = remote_stub.initialize(addr,
                &GFactory::get_instance().get_base_client().get_client_mgr())))
        {
          fprintf(stderr, "initialize server stub error\n");
          break;
        }
        else if (OB_SUCCESS != (ret = remote_stub.fetch_stats(node_stats)))
        {
          fprintf(stderr, "fetch server (%s) stats error\n", addr_string);
          break;
        }
        if (store_.current.begin(mod_) == store_.current.end(mod_))
          store_.current = node_stats;
        else
          store_.current.add(node_stats);
      }

      return ret;
    }
Esempio n. 11
0
void get_clog_master(MockClient &client)
{
  ObServer server;
  int err = client.get_clog_master(server, timeout);
  char addr[256];
  fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err);
  server.to_string(addr, sizeof(addr));
  fprintf(stdout, "%s\n", addr);
}
Esempio n. 12
0
int main(int argc, char* argv[])
{
  ObServer cs;
  cs.set_ipv4_addr("localhost", 3500);

  BaseClient client;
  client.initialize();
  
  ObServer root;
  root.set_ipv4_addr("10.232.35.40", 2500);

  ThreadSpecificBuffer buffer;
  ObRootServerRpcStub server;
  
  do
  {
    int ret = server.init(root, client.get_rpc());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "init failed");
      break;
    } 

    int64_t timeout = 2000;
    int64_t timestamp = 0;
    // heartbeat 
    ret = server.renew_heartbeat(timeout, cs, timestamp); 
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "renew heartbeat failed:ret[%d]", ret);
      break;
    }
    else
    {
      printf("get new lease time[%ld]\n", timestamp);
    }

    sleep(1);
    
    // fetch schema
    timestamp = 1282900503726484;
    ObSchemaManager schema;
    ret = server.fetch_schema(timeout, timestamp, schema);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "fetch schema failed:ret[%d]", ret);
      break;
    }
    else
    {
      printf("fetch schema succ:appname[%s]\n", schema.get_app_name());
      schema.print_info();
    }
  } while(0);
  client.destory();
  return 0;
}
Esempio n. 13
0
MockNodeServer::MockNodeServer(int32_t port, int64_t retry_time, int64_t timeout, ObServer monitor, char* app_name, char* instance_name, char* hostname)
{
  port_ = port;
  retry_times_ = retry_time;
  timeout_ = timeout;
  monitor_.set_ipv4_addr(monitor.get_ipv4(), monitor.get_port());

  app_name_ = app_name;
  instance_name_ = instance_name;
  hostname_ = hostname;
  status_ = UNKNOWN;
}
 ObAppStats::ObAppStats(ObClientRpcStub &stub, const ObRole server_type, const char* config_file_name)
   : ObServerStats(stub, server_type)
 {
   root_server_array_.init(MAX_SERVER_NUM, root_servers_, 0);
   tbsys::CConfig config;
   if(config.load(config_file_name))
   {
     fprintf(stderr, "load file %s error\n", config_file_name);
   }
   else
   {
     master_index_ = -1;
     int count = config.getInt(SERVER_SECTION, "cluster_count", 0);
     if (count <= 0)
     {
       fprintf(stderr, "cluster_count %d cannot < 0\n", count);
     }
     else
     {
       const int MAX_LEN = 64;
       char ipname[MAX_LEN];
       char portname[MAX_LEN];
       char ip[MAX_LEN];
       char mastername[MAX_LEN];
       int32_t port = 0;
       int is_master = 0;
       ObServer server;
       for (int i = 0; i < count ; ++i)
       {
         snprintf(ipname, MAX_LEN, "rs%d_ip", i);
         snprintf(portname, MAX_LEN, "rs%d_port", i);
         snprintf(mastername, MAX_LEN, "rs%d_is_master", i);
         if (OB_SUCCESS != load_string(config, ip, MAX_LEN, SERVER_SECTION, ipname, true))
         {
           fprintf(stderr, "%s is null\n", ipname);
           break;
         }
         port = config.getInt(SERVER_SECTION, portname, 0);
         if (port <= 0)
         {
           fprintf(stderr, "%s is 0\n", portname);
           break;
         }
         is_master = config.getInt(SERVER_SECTION, mastername, 0);
         if (is_master > 0) master_index_ = i;
         server.set_ipv4_addr(ip, port);
         root_server_array_.push_back(server);
       }
     }
   }
 }
Esempio n. 15
0
int ObMergerRpcStub::fetch_update_server(
    const int64_t timeout, const ObServer & root_server,
    ObServer & update_server, bool for_merge) const
{
    int ret = OB_SUCCESS;
    ObDataBuffer data_buff;
    ret = get_rpc_buffer(data_buff);
    // step 1. send get update server info request
    if (OB_SUCCESS == ret)
    {
        ret = rpc_frame_->send_request(root_server,
                                       for_merge ? OB_GET_UPDATE_SERVER_INFO_FOR_MERGE : OB_GET_UPDATE_SERVER_INFO,
                                       DEFAULT_VERSION, timeout, data_buff);
        if (ret != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "send request to root server for find update server failed:ret[%d]", ret);
        }
    }

    // step 2. deserialize restult code
    int64_t pos = 0;
    if (OB_SUCCESS == ret)
    {
        ObResultCode result_code;
        ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(WARN, "deserialize result_code failed:pos[%ld], ret[%d]", pos, ret);
        }
        else
        {
            ret = result_code.result_code_;
        }
    }

    // step 3. deserialize update server addr
    if (OB_SUCCESS == ret)
    {
        ret = update_server.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (ret != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "deserialize server failed:pos[%ld], ret[%d]", pos, ret);
        }
        else
        {
            TBSYS_LOG(DEBUG, "find update server succ:addr[%d], port[%d]", update_server.get_ipv4(),
                      update_server.get_port());
        }
    }
    return ret;
}
TEST_F(TestTabletLocationItem, test_invalid)
{
  ObMergerTabletLocationList list;
  ObTabletLocation temp_server;
  ObServer chunkserver;
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 300000, i + 1024);
    temp_server.tablet_version_ = i;
    temp_server.chunkserver_ = chunkserver;
    EXPECT_TRUE(OB_SUCCESS == list.add(temp_server));
  }
  
  ObMergerTabletLocation server;
  
  // not exist
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 200000, i + 1024);
    server.server_.chunkserver_ = chunkserver;
    server.server_.tablet_version_ = i;
    EXPECT_TRUE(OB_SUCCESS != list.set_item_invalid(server));
    EXPECT_TRUE(list[i].err_times_ != ObMergerTabletLocation::MAX_ERR_TIMES);
  }

  // set second invalid
  chunkserver.set_ipv4_addr(1 + 300000, 1 + 1024);
  server.server_.chunkserver_ = chunkserver;
  server.server_.tablet_version_ = 1;
  EXPECT_TRUE(OB_SUCCESS == list.set_item_invalid(server));
  EXPECT_TRUE(list[1].err_times_ == ObMergerTabletLocation::MAX_ERR_TIMES);
  EXPECT_TRUE(list[0].err_times_ != ObMergerTabletLocation::MAX_ERR_TIMES);
  EXPECT_TRUE(list[2].err_times_ != ObMergerTabletLocation::MAX_ERR_TIMES);
  
  // all invalid 
  for (int32_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    chunkserver.set_ipv4_addr(i + 300000, i + 1024);
    server.server_.chunkserver_ = chunkserver;
    server.server_.tablet_version_ = i;
    EXPECT_TRUE(OB_SUCCESS == list.set_item_invalid(server));
    EXPECT_TRUE(list[i].err_times_ == ObMergerTabletLocation::MAX_ERR_TIMES);
  }

  for (int64_t i = 0; i < ObMergerTabletLocationList::MAX_REPLICA_COUNT; ++i)
  {
    server.server_.tablet_version_ = i + 100;
    EXPECT_TRUE(OB_SUCCESS == list.set_item_invalid(server));
  }
}
TEST_F(TestTabletLocationItem, test_sort)
{
  ObMergerTabletLocationList list;
  ObServer root_server;
  const char * addr = "localhost";
  root_server.set_ipv4_addr(addr, 8888);
  int32_t server_ip = root_server.get_ipv4();
  
  // one server
  ObTabletLocation location;
  srand(100);
  ObServer temp;
  temp.set_ipv4_addr(rand() % 10245, 1023);
  //location.tablet_id_ = 1;
  location.chunkserver_ = temp;
  list.add(location);
  EXPECT_TRUE(OB_SUCCESS == list.sort(root_server));
  
  int64_t count = list.size();
  for (int64_t i = 0; i < count - 1; ++i)
  {
    EXPECT_TRUE(abs(list[i].server_.chunkserver_.get_ipv4() - server_ip) 
        <= abs(list[i+1].server_.chunkserver_.get_ipv4() - server_ip));
  } 

  // two server
  temp.set_ipv4_addr(rand() % 10245, 1024);
  location.chunkserver_ = temp;
  list.add(location);
  EXPECT_TRUE(OB_SUCCESS == list.sort(root_server));
  
  count = list.size();
  for (int64_t i = 0; i < count - 1; ++i)
  {
    EXPECT_TRUE(abs(list[i].server_.chunkserver_.get_ipv4() - server_ip) 
        <= abs(list[i+1].server_.chunkserver_.get_ipv4() - server_ip));
  } 
  
  // three server
  location.chunkserver_ = root_server;
  list.add(location);
  EXPECT_TRUE(OB_SUCCESS == list.sort(root_server));
  
  count = list.size();
  for (int64_t i = 0; i < count - 1; ++i)
  {
    EXPECT_TRUE(abs(list[i].server_.chunkserver_.get_ipv4() - server_ip) 
        <= abs(list[i+1].server_.chunkserver_.get_ipv4() - server_ip));
  } 
}
Esempio n. 18
0
    int ObUpsRpcStub :: send_freeze_memtable_resp(const ObServer& root_server,
        const ObServer& ups_master, const int64_t schema_timestamp, const int64_t timeout_us)
    {
      int err = OB_SUCCESS;
      ObDataBuffer data_buff;
      ObServer update_server;

      if (NULL == client_mgr_)
      {
        TBSYS_LOG(WARN, "invalid status, client_mgr_[%p]", client_mgr_);
        err = OB_ERROR;
      }
      else
      {
        err = get_thread_buffer_(data_buff);
      }

      // serialize ups_master
      if (OB_SUCCESS == err)
      {
        err = ups_master.serialize(data_buff.get_data(), data_buff.get_capacity(),
            data_buff.get_position());
      }

      // serialize timestamp
      if (OB_SUCCESS == err)
      {
        err = common::serialization::encode_vi64(data_buff.get_data(), 
            data_buff.get_capacity(), data_buff.get_position(), schema_timestamp);
      }

      // step 1. send freeze memtable resp
      if (OB_SUCCESS == err)
      {
        err = client_mgr_->send_request(root_server, 
            OB_WAITING_JOB_DONE, DEFAULT_VERSION, timeout_us, data_buff);
        if (err != OB_SUCCESS)
        {
          TBSYS_LOG(ERROR, "send freeze memtable failed, err[%d].", err);
        }
      }

      // step 2. deserialize the response code
      int64_t pos = 0;
      if (OB_SUCCESS == err)
      {
        ObResultCode result_code;
        err = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (OB_SUCCESS != err)
        {
          TBSYS_LOG(ERROR, "deserialize result_code failed:pos[%ld], err[%d].", pos, err);
        }
        else
        {
          err = result_code.result_code_;
        }
      }

      return err;
    }
Esempio n. 19
0
int ObRootServerRpcStub::async_heartbeat(const ObServer & client)
{
  int ret = OB_SUCCESS;
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

  // step 1. serialize client server addr to data_buff
  if (OB_SUCCESS == ret)
  {
    ret = client.serialize(data_buff.get_data(), 
        data_buff.get_capacity(), data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize client server addr failed:ret[%d].", ret);
    }
  }

  // step 2. rpc frame send request and receive the response
  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->post_request(root_server_, 
        OB_HEARTBEAT, DEFAULT_VERSION, data_buff);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "post request to root server "
          "for heartbeat failed:ret[%d].", ret);
    }
  }

  // step 3. dont care server's response packet.
  return ret;
}
Esempio n. 20
0
int ObMonitor::report_slave_failure(const int64_t timeout, const int64_t retry_times, const ObServer slave, const ObServer master)
{
  int err = OB_ERROR;
  for(int64_t i = 0; (i < retry_times) && (err != OB_SUCCESS); i++)
  {
    int64_t timeu = tbsys::CTimeUtil::getMonotonicTime();
    err = report_slave_failure_(timeout, slave, master);
    timeu = tbsys::CTimeUtil::getMonotonicTime() - timeu;
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "%ldth, report slave failure fail. err =%d", i, err);
    }
    else
    {
      TBSYS_LOG(INFO, "report slave failure to master succ!");
    }      
  }

  if(OB_SUCCESS != err)
  {
    TBSYS_LOG(ERROR, "can't report failure to master node. master addr =%d", master.get_ipv4());
    err = OB_ERROR;
  }
  return err;
}
Esempio n. 21
0
int ObMonitor::select_master(node_list_type *pnodelist, ObServer &new_master)
{
  int err = OB_ERROR;
  if(pnodelist == NULL)
  {
    TBSYS_LOG(WARN, "invalid argument");
    err = OB_INVALID_ARGUMENT;
  }
  if(OB_ERROR == err)
  {
    node_list_type::iterator it = (*pnodelist).begin();
    while(it != (*pnodelist).end())
    {
      if((*it)->status == SLAVE_SYNC)
      {
        new_master.set_ipv4_addr((*it)->node_server.get_ipv4(), (*it)->node_server.get_port());
        (*it)->status = MASTER_ACTIVE;
        err = OB_SUCCESS;
        break;
      }
      it ++;
    }
  }
  return err;
}
Esempio n. 22
0
int MockRootServer::handle_register_server(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  if (OB_SUCCESS == ret)
  {
    ObServer server;
    ret = server.deserialize(data->get_data(), data->get_capacity(), data->get_position());
  }

  if (OB_SUCCESS == ret)
  {
    bool is_merger = false;
    ret = serialization::decode_bool(data->get_data(), data->get_capacity(), data->get_position(), &is_merger);
    if ((ret == OB_SUCCESS) && is_merger)
    {
      TBSYS_LOG(INFO, "%s", "merge server registered");
    }
  }
  
  // response
  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());
    
    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    
    int32_t channel_id = ob_packet->getChannelId();
    ret = send_response(OB_REPORT_TABLETS_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle register server result:ret[%d]", ret);
  return ret;
}
Esempio n. 23
0
TEST_F(TestBlackList, init)
{
  ObMergerServerBlackList list;
  ObUpsList ups_list;
  EXPECT_TRUE(OB_SUCCESS != list.init(10, 10000, MERGE_SERVER, ups_list));
  ObUpsInfo info;
  ObServer server;
  for (int i = 0; i < MAX_COUNT; ++i)
  {
    server.set_ipv4_addr(i+1024, i+2048);
    info.addr_ = server;
    info.ms_read_percentage_ = 10;
    ups_list.ups_count_ = i + 1;
    ups_list.ups_array_[i] = info;
  }
  EXPECT_TRUE(OB_SUCCESS == list.init(10, 10000, MERGE_SERVER, ups_list));
}
ObServer &ObDeleteReplicasTest::get_addr(int32_t idx)
{
  char buff[128];
  snprintf(buff, 128, "10.10.10.%d", idx);
  int port = 26666;
  addr_.set_ipv4_addr(buff, port);
  return addr_;
}
Esempio n. 25
0
void* thread_run(void* arg)
{
  ParamSet *param = reinterpret_cast<ParamSet*>(arg);
  ObServer cs;
  cs.set_ipv4_addr(param->server_ip, param->port);
  
  BaseClient client;
  if (OB_SUCCESS != client.initialize())
  {
    TBSYS_LOG(ERROR, "initialize client failed.");
    //return OB_ERROR;
  }
  // get_test_case(client, cs, param->table_id, param->user_id, param->item_type, param->item_id);
  //scan_test_case(client, cs, param->table_id, param->user_id, param->item_type, param->column_count);
  // create_test_case(client, cs, param->table_id,param->user_id,param->item_type);
  // migrate_test_case();
  // merge_test_case();
  return (void *)0;
}
    int ObAppStats::sum_cs_cluster_stats(const ObServer& rs, const ObRole server_type)
    {
      ObClientRpcStub rs_stub;
      ObChunkServerManager obsm;
      int ret = rs_stub.initialize(rs, &GFactory::get_instance().get_base_client().get_client_mgr());
      if (OB_SUCCESS == ret)
      {
        ret = rs_stub.rs_dump_cs_info(obsm);
      }

      ObServer server_list[MAX_SERVER_NUM];
      ObArrayHelper<ObServer> server_array(MAX_SERVER_NUM, server_list, 0);
      if (OB_SUCCESS == ret)
      {
        ObChunkServerManager::const_iterator it = obsm.begin();
        ObServer node;
        while (it != obsm.end())
        {
          node = it->server_;
          if (server_type == OB_CHUNKSERVER)
            node.set_port(it->port_cs_);
          else
            node.set_port(it->port_ms_);

          /*
          node.to_string(ipstr, 64);
             fprintf(stderr, "dump server ip:%s, server status:%ld, serving:%d\n",
             ipstr, it->status_, ObServerStatus::STATUS_SERVING);
             */

          if (it->status_ != ObServerStatus::STATUS_DEAD)
          {
            server_array.push_back(node);
          }
          ++it;
        }

        ret = sum_cluster_stats(server_type, server_array);

      }

      return ret;
    }
Esempio n. 27
0
void run_scan_test_case(ParamSet& param, char * cmd)
{
  bool print_help = parse_param(param,cmd);
  if ( true == print_help )
    printhelp();
  else
  {
    printParam(param);
    ObServer cs;
    cs.set_ipv4_addr(param.server_ip, param.port);
    BaseClient client;
    if (OB_SUCCESS != client.initialize())
    {
      TBSYS_LOG(ERROR, "initialize client failed.");
    }
    scan_test_case(client, cs, param.table_id, param.user_id, static_cast<int8_t>(param.item_type), static_cast<int32_t>(param.column_count));
    client.destory();
    printf("================SCAN TEST DONE===============\n");
  }
}
Esempio n. 28
0
void run_get_test_case_common_hex(ParamSet& param, char * cmd)
{
  bool print_help = parse_param(param,cmd);
  if ( true == print_help )
    printhelp();
  else
  {
    printParam(param);
    ObServer cs;
    cs.set_ipv4_addr(param.server_ip, param.port);
    BaseClient client;
    if (OB_SUCCESS != client.initialize())
    {
      TBSYS_LOG(ERROR, "initialize client failed.");
    }
    get_test_case_common_hex(client, cs, param.table_id, param.user_id, param.item_id);
    client.destory();
    printf("===============GET TEST DONE==============\n");
  }
}
Esempio n. 29
0
void run_merge_scan_case(ParamSet& param, char * cmd)
{
  bool print_help = parse_param(param,cmd);
  if ( true == print_help )
    printhelp();
  else
  {
    printParam(param);
    ObServer cs;
    cs.set_ipv4_addr(param.server_ip, param.port);
    BaseClient client;
    if (OB_SUCCESS != client.initialize())
    {
      TBSYS_LOG(ERROR, "initialize client failed.");
    }
    merge_scan_case(client, cs, param.table_name, param.start_key, param.end_key, param.key_size, param.is_hex_key);
    client.destory();
    printf("===============GET TEST DONE==============\n");
  }
}
Esempio n. 30
0
void run_drop_test_case(ParamSet& param, char * cmd)
{
  bool print_help = parse_param(param,cmd);
  if ( true == print_help )
    printhelp();
  else
  {
    printParam(param);
    ObServer cs;
    cs.set_ipv4_addr(param.server_ip, param.port);
    BaseClient client;
    if (OB_SUCCESS != client.initialize())
    {
      TBSYS_LOG(ERROR, "initialize client failed.");
    }
    drop_test_case(client, cs, param.memtable_frozen_version);
    client.destory();
    printf("==============DROP TEST DONE==================\n");
  }
}