コード例 #1
0
ファイル: ob_root_rpc_stub.cpp プロジェクト: Abioy/oceanbase
int ObRootRpcStub::get_ups_max_log_seq(const common::ObServer& ups, uint64_t &max_log_seq, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;      
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_RS_GET_MAX_LOG_SEQ, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to revoke lease, err=%d", result.result_code_);
      ret = result.result_code_;
    }
    else if (OB_SUCCESS != (ret = serialization::decode_vi64(msgbuf.get_data(), msgbuf.get_position(), 
                                                             pos, (int64_t*)&max_log_seq)))
    {
      TBSYS_LOG(WARN, "failed to deserialize, err=%d", ret);
    }
    else
    {
      TBSYS_LOG(INFO, "get ups max log seq, ups=%s seq=%lu", ups.to_cstring(), max_log_seq);
    }
  }
  return ret;

}
コード例 #2
0
int ObRootTableService::report_tablets(ObScanHelper &scan_helper, const common::ObServer& cs, const common::ObTabletReportInfoList& rtablets)
{
    int ret = OB_SUCCESS;
    if (OB_SUCCESS != (ret = check_integrity()))
    {
        TBSYS_LOG(ERROR, "integrity error");
    }
    else
    {
        TBSYS_LOG(INFO, "cs report tablets, cs=%s tablets_num=%ld", cs.to_cstring(), rtablets.get_tablet_size());
        const ObTabletReportInfo* tablets = rtablets.get_tablet();
        for (int64_t i = 0; i < rtablets.get_tablet_size(); ++i)
        {
            const ObTabletReportInfo &tablet = tablets[i];
            if (OB_SUCCESS != (ret = report_tablet(scan_helper, tablet)))
            {
                TBSYS_LOG(WARN, "failed to report");
            }
        }
    }
    return ret;
}
コード例 #3
0
ファイル: ob_root_rpc_stub.cpp プロジェクト: Abioy/oceanbase
int ObRootRpcStub::shutdown_cs(const common::ObServer& cs, bool is_restart, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;      
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = serialization::encode_i32(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), is_restart ? 1 : 0)))
  {
    TBSYS_LOG(ERROR, "encode is_restart fail:ret[%d], is_restart[%d]", ret, is_restart ? 1 : 0);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_STOP_SERVER, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to restart, err=%d server=%s", result.result_code_, cs.to_cstring());
      ret = result.result_code_;
    }
  }
  return ret;
}
コード例 #4
0
ファイル: ob_root_rpc_stub.cpp プロジェクト: Abioy/oceanbase
int ObRootRpcStub::get_split_range(const common::ObServer& ups, const int64_t timeout_us,
    const uint64_t table_id, const int64_t forzen_version, ObTabletInfoList &tablets)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
    {
      TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(),
            msgbuf.get_position(), forzen_version)))
    {
      TBSYS_LOG(WARN, "fail to encode forzen_version. forzen_version=%ld, ret=%d", forzen_version, ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(),
            msgbuf.get_position(), table_id)))
    {
      TBSYS_LOG(WARN, "fail to encode table_id. table_id=%lu, ret=%d", table_id, ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_RS_FETCH_SPLIT_RANGE, DEFAULT_VERSION, timeout_us, msgbuf)))
    {
      TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
    }
  }
  ObResultCode result;
  int64_t pos = 0;
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to fetch split range, err=%d", result.result_code_);
      ret = result.result_code_;
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = tablets.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(WARN, "failed to deserialize tablets, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    TBSYS_LOG(INFO, "fetch split range from ups succ.");
  }
  else
  {
    TBSYS_LOG(WARN, "fetch split range from ups fail, ups_addr=%s, version=%ld", ups.to_cstring(), forzen_version);
  }
  return ret;
}
コード例 #5
0
ファイル: ob_root_rpc_stub.cpp プロジェクト: Abioy/oceanbase
int ObRootRpcStub::request_report_tablet(const common::ObServer& chunkserver)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  if (OB_SUCCESS == ret)
  {
    ret = get_thread_buffer_(msgbuf);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(WARN, "fail to get thread buffer. err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    ret = client_mgr_->post_request(chunkserver, OB_RS_REQUEST_REPORT_TABLET, DEFAULT_VERSION, msgbuf);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(WARN, "fail to post request to chunkserver. err=%d, chunkserver_addr=%s", ret, chunkserver.to_cstring());
    }
  }
  return ret;
}
コード例 #6
0
ファイル: ob_root_rpc_stub.cpp プロジェクト: Abioy/oceanbase
int ObRootRpcStub::create_tablet(const common::ObServer& cs, const common::ObRange& range, const int64_t mem_version, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  static char buff[OB_MAX_PACKET_LENGTH];
  msgbuf.set_data(buff, OB_MAX_PACKET_LENGTH);
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = range.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serialize range, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), mem_version)))
  {
    TBSYS_LOG(ERROR, "failed to serialize key_src, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_CREATE_TABLE, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result;
    int64_t pos = 0;
    static char range_buff[OB_MAX_ROW_KEY_LENGTH * 2];
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      range.to_string(range_buff, OB_MAX_ROW_KEY_LENGTH * 2);
      TBSYS_LOG(WARN, "failed to create tablet, err=%d, cs=%s, range=%s", result.result_code_, cs.to_cstring(), range_buff);
      ret = result.result_code_;
    }
    else
    {
    }
  }
  return ret;
}
コード例 #7
0
int ObRootTableService::migrate_replica(ObScanHelper &scan_helper, const ObNewRange &range, const int64_t version,
                                        const common::ObServer &from, const common::ObServer &to, bool keep_src)
{
    int ret = OB_SUCCESS;
    ObRootTable3::ConstIterator *first;
    ObRootTable3 *root_table = NULL;
    const ObRootTable3::Value* crow = NULL;

    if (NULL == range.start_key_.ptr()
            || NULL == range.end_key_.ptr()
            || 0 >= version
            || 0 == from.get_port()
            || 0 == to.get_port())
    {
        TBSYS_LOG(WARN, "invalid tablet");
        ret = OB_INVALID_ARGUMENT;
    }
    else if (OB_SUCCESS != (ret = check_integrity()))
    {
        TBSYS_LOG(ERROR, "integrity error");
    }
    else if (OB_SUCCESS != (ret = aquire_root_table(scan_helper, root_table)))
    {
        TBSYS_LOG(ERROR, "failed to aquire root table, err=%d", ret);
    }
    else if (OB_SUCCESS != (ret = root_table->search(range, first)))
    {
        TBSYS_LOG(WARN, "failed to search tablet, err=%d", ret);
    }
    else if (OB_SUCCESS != (ret = first->next(crow)))
    {
        TBSYS_LOG(WARN, "tablet not exist, err=%d range=%s", ret, to_cstring(range));
        ret = OB_ENTRY_NOT_EXIST;
    }
    else if (!is_same_range(*crow, range))
    {
        ret = OB_ENTRY_NOT_EXIST;
        TBSYS_LOG(WARN, "tablet not exist, range=%s", to_cstring(range));
    }
    else
    {
        for (int32_t i = 0; i < crow->get_max_replica_count(); ++i)
        {
            const ObTabletReplica& replica = crow->get_replica(i);
            if (from == replica.cs_)
            {
                if (replica.version_ != version)
                {
                    TBSYS_LOG(WARN, "migrate tablet with wrong version, old_v=%ld new_v=%ld cs=%s range=%s",
                              replica.version_, version, from.to_cstring(), to_cstring(range));
                    ret = OB_CONFLICT_VALUE;
                }
                else
                {
                    ObTabletMetaTable::Value new_row = *crow; // copy
                    ObTabletReplica replica2(replica);
                    replica2.cs_ = to;
                    if (keep_src)
                    {
                        if (OB_SUCCESS != (ret = new_row.add_replica(replica2)))
                        {
                            TBSYS_LOG(WARN, "failed to add replica, err=%d", ret);
                        }
                    }
                    else
                    {
                        new_row.set_replica(i, replica2);
                    }
                    if (OB_SUCCESS == ret)
                    {
                        if (OB_SUCCESS != (ret = root_table->update(new_row)))
                        {
                            TBSYS_LOG(ERROR, "failed to update root table, err=%d", ret);
                        }
                        else if (OB_SUCCESS != (ret = root_table->commit()))
                        {
                            TBSYS_LOG(ERROR, "failed to commit change, err=%d", ret);
                        }
                    }
                }
                break;
            }
        } // end for
    }
    release_root_table(root_table);
    return ret;
}
コード例 #8
0
int ObRootTableService::remove_replicas_in_table(ObScanHelper &scan_helper, const common::ObServer &cs, const uint64_t tid)
{
    int ret = OB_SUCCESS;
    ObRootTable3 *root_table = NULL;
    ObNewRange range_min_max;
    range_min_max.table_id_ = tid;
    range_min_max.set_whole_range();
    ObRootTable3::ConstIterator* it = NULL;
    const ObRootTable3::Value* crow = NULL;
    if (OB_SUCCESS != (ret = aquire_root_table(scan_helper, root_table)))
    {
        TBSYS_LOG(ERROR, "failed to aquire root table, err=%d", ret);
    }
    else if (OB_SUCCESS != (ret = root_table->search(range_min_max, it)))
    {
        TBSYS_LOG(WARN, "failed to search tablet, err=%d tid=%lu", ret, tid);
    }
    else
    {
        int32_t deleted_replicas = 0;
        int32_t updated_count = 0;
        const int32_t batch_count = 512;
        while(OB_SUCCESS == ret && OB_SUCCESS == (ret = it->next(crow)))
        {
            for (int32_t i = 0; i < crow->get_max_replica_count(); ++i)
            {
                const ObTabletReplica& replica = crow->get_replica(i);
                if (replica.cs_ == cs)
                {
                    ObTabletReplica replica2; // remove the replica
                    ObRootTable3::Value mrow = *crow;
                    mrow.set_replica(i, replica2);
                    if (OB_SUCCESS != (ret = root_table->update(mrow)))
                    {
                        TBSYS_LOG(ERROR, "failed to update root table, err=%d", ret);
                    }
                    else
                    {
                        updated_count++;
                        if (updated_count % batch_count == 0)
                        {
                            if (OB_SUCCESS != (ret = root_table->commit()))
                            {
                                TBSYS_LOG(ERROR, "failed to commit change, err=%d", ret);
                            }
                            else
                            {
                                deleted_replicas += batch_count;
                            }
                        }
                    }
                    break;
                }
            } // end for
        } // end while

        if (OB_ITER_END != ret)
        {
            TBSYS_LOG(WARN, "failed to remove replicas, err=%d", ret);
        }
        else
        {
            ret = OB_SUCCESS;
        }
        if (updated_count != deleted_replicas)
        {
            if (OB_SUCCESS != (ret = root_table->commit()))
            {
                TBSYS_LOG(ERROR, "failed to commit change, err=%d", ret);
            }
        }
        TBSYS_LOG(INFO, "delete replicas by cs, cs=%s replicas_num=%d",
                  cs.to_cstring(), deleted_replicas);
    }
    release_root_table(root_table);
    return ret;
}