int ObUpsLeaseTask::init(common::ObRoleMgr *role_mgr, ObUpsRpcStub * rpc_stub, common::ObServer &root_server, ObUpsLogMgr *log_mgr, const int64_t inner_port, common::ObServer &self_server, const int64_t timeout_us)
{
  int err = OB_SUCCESS;
  self_lease_ = 0;
  if (NULL == role_mgr || NULL == rpc_stub || NULL == log_mgr)
  {
    err = OB_INVALID_ARGUMENT;
    TBSYS_LOG(WARN, "invalid argument. role_mgr=%p", role_mgr);
  }
  else
  {
    role_mgr_ = role_mgr;
    rpc_stub_ = rpc_stub;
    log_mgr_ = log_mgr;
    root_server_.set_ipv4_addr(root_server.get_ipv4(), root_server.get_port());
    inner_port_ = inner_port;
    self_addr_.set_ipv4_addr(self_server.get_ipv4(), self_server.get_port());
    timeout_us_ = timeout_us;
  }
  return err;
}
Exemple #2
0
 void ObUpsBlackList::fail(const int32_t server_index, const common::ObServer & server)
 {
   if ((server_index < server_count_) && (fail_counter_[server_index].server_ == server))
   {
     // no need thread safe
     if (0 == fail_counter_[server_index].fail_count_)
     {
       fail_counter_[server_index].fail_timestamp_ = tbsys::CTimeUtil::getTime();
     }
     ++fail_counter_[server_index].fail_count_;
   }
   else
   {
     TBSYS_LOG(WARN, "check param failed:index[%d], count[%d], server[%u], port[%d]",
         server_index, server_count_, server.get_ipv4(), server.get_port());
   }
 }
int ObRootTableService::remove_replicas(ObScanHelper &scan_helper, const common::ObServer &cs)
{
    int ret = OB_SUCCESS;
    if (0 == cs.get_port())
    {
        TBSYS_LOG(WARN, "invalid cs port");
        ret = OB_INVALID_ARGUMENT;
    }
    else if (OB_SUCCESS != (ret = check_integrity()))
    {
        TBSYS_LOG(ERROR, "integrity error");
    }
    else
    {
        // @todo for each table
        remove_replicas_in_table(scan_helper, cs, 0);
    }
    return ret;
}
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;
}