patch 4.0
This commit is contained in:
@ -14,86 +14,92 @@
|
||||
#define OCEANBASE_SHARE_OB_UNIT_GETTER_H_
|
||||
|
||||
#include "lib/container/ob_array.h"
|
||||
#include "share/partition_table/ob_partition_table_operator.h"
|
||||
#include "share/ob_unit_table_operator.h"
|
||||
#include "share/ob_unit_stat_table_operator.h"
|
||||
#include "share/ob_unit_stat.h"
|
||||
#include "share/ob_check_stop_provider.h"
|
||||
#include "share/rc/ob_tenant_base.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace common {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
class ObMySQLProxy;
|
||||
class ObServerConfig;
|
||||
} // namespace common
|
||||
}
|
||||
|
||||
namespace share {
|
||||
class ObUnitInfoGetter {
|
||||
namespace share
|
||||
{
|
||||
class ObUnitInfoGetter
|
||||
{
|
||||
public:
|
||||
enum ObUnitStatus {
|
||||
enum ObUnitStatus // remember to modify unit_status_strs_[] if this enum changed
|
||||
{
|
||||
UNIT_NORMAL = 0,
|
||||
UNIT_MIGRATE_IN,
|
||||
UNIT_MIGRATE_OUT,
|
||||
UNIT_DELETING,
|
||||
UNIT_MARK_DELETING, // mark deleting in __all_unit
|
||||
UNIT_WAIT_GC_IN_OBSERVER, // already deleted in __all_unit, but gc of unit in observer is not finished
|
||||
UNIT_DELETING_IN_OBSERVER, // gc is finish and start to delete the unit on obsever
|
||||
UNIT_ERROR_STAT,
|
||||
};
|
||||
struct ObTenantConfig {
|
||||
static const char* get_unit_status_str(const ObUnitStatus status) { return unit_status_strs_[status]; }
|
||||
|
||||
struct ObTenantConfig
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
|
||||
public:
|
||||
ObTenantConfig()
|
||||
: tenant_id_(common::OB_INVALID_ID),
|
||||
unit_stat_(UNIT_ERROR_STAT),
|
||||
config_(),
|
||||
mode_(ObWorker::CompatMode::INVALID),
|
||||
create_timestamp_(0),
|
||||
has_memstore_(true),
|
||||
is_removed_(false)
|
||||
{}
|
||||
~ObTenantConfig()
|
||||
{}
|
||||
ObTenantConfig();
|
||||
|
||||
void reset()
|
||||
ObTenantConfig(const ObTenantConfig &) = default;
|
||||
ObTenantConfig &operator=(const ObTenantConfig &) = default;
|
||||
|
||||
~ObTenantConfig() {}
|
||||
|
||||
int init(const uint64_t tenant_id,
|
||||
const uint64_t unit_id,
|
||||
const ObUnitStatus unit_status,
|
||||
const ObUnitConfig &config,
|
||||
lib::Worker::CompatMode compat_mode,
|
||||
const int64_t create_timestamp,
|
||||
const bool has_memstore,
|
||||
const bool is_remove);
|
||||
|
||||
int divide_meta_tenant(ObTenantConfig& meta_tenant_config);
|
||||
|
||||
void reset();
|
||||
bool operator==(const ObTenantConfig &other) const;
|
||||
int assign(const ObTenantConfig &other);
|
||||
|
||||
TO_STRING_KV(K_(tenant_id), K_(unit_id), K_(has_memstore),
|
||||
"unit_status", get_unit_status_str(unit_status_),
|
||||
K_(config), K_(mode), K_(create_timestamp), K_(is_removed));
|
||||
|
||||
bool is_valid() const
|
||||
{
|
||||
tenant_id_ = common::OB_INVALID_ID;
|
||||
config_.reset();
|
||||
mode_ = ObWorker::CompatMode::INVALID;
|
||||
create_timestamp_ = 0;
|
||||
is_removed_ = false;
|
||||
return tenant_id_ != common::OB_INVALID_TENANT_ID &&
|
||||
unit_id_ != common::OB_INVALID_ID &&
|
||||
unit_status_ != UNIT_ERROR_STAT &&
|
||||
config_.is_valid() && mode_ != lib::Worker::CompatMode::INVALID;
|
||||
}
|
||||
bool operator==(const ObTenantConfig& other) const
|
||||
{
|
||||
return tenant_id_ == other.tenant_id_ && unit_stat_ == other.unit_stat_ && config_ == other.config_ &&
|
||||
mode_ == other.mode_ && create_timestamp_ == other.create_timestamp_ &&
|
||||
has_memstore_ == other.has_memstore_ && is_removed_ == other.is_removed_;
|
||||
}
|
||||
TO_STRING_KV(
|
||||
K_(tenant_id), K_(has_memstore), K_(unit_stat), K_(config), K_(mode), K_(create_timestamp), K_(is_removed));
|
||||
|
||||
uint64_t tenant_id_;
|
||||
ObUnitStatus unit_stat_;
|
||||
uint64_t unit_id_;
|
||||
ObUnitStatus unit_status_;
|
||||
ObUnitConfig config_;
|
||||
ObWorker::CompatMode mode_;
|
||||
lib::Worker::CompatMode mode_;
|
||||
int64_t create_timestamp_;
|
||||
bool has_memstore_; // make if the unit contains replicas have memstore(Logonly replicas have no memstore)
|
||||
bool is_removed_;
|
||||
};
|
||||
|
||||
struct ObServerConfig {
|
||||
ObServerConfig() : server_(), config_()
|
||||
{}
|
||||
~ObServerConfig()
|
||||
{}
|
||||
struct ObServerConfig
|
||||
{
|
||||
ObServerConfig() : server_(), config_() {}
|
||||
~ObServerConfig() {}
|
||||
|
||||
bool is_valid() const
|
||||
{
|
||||
return server_.is_valid() && config_.is_valid();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
server_.reset();
|
||||
config_.reset();
|
||||
}
|
||||
bool is_valid() const { return server_.is_valid() && config_.is_valid(); }
|
||||
void reset() { server_.reset(); config_.reset(); }
|
||||
TO_STRING_KV(K_(server), K_(config));
|
||||
|
||||
common::ObAddr server_;
|
||||
@ -102,62 +108,75 @@ public:
|
||||
|
||||
ObUnitInfoGetter();
|
||||
virtual ~ObUnitInfoGetter();
|
||||
int init(common::ObMySQLProxy& proxy, common::ObServerConfig* config = NULL);
|
||||
virtual int get_tenants(common::ObIArray<uint64_t>& tenants);
|
||||
virtual int get_server_tenant_configs(const common::ObAddr& server, common::ObIArray<ObTenantConfig>& tenant_configs);
|
||||
virtual int get_tenant_server_configs(const uint64_t tenant_id, common::ObIArray<ObServerConfig>& server_configs);
|
||||
virtual int get_tenant_servers(const uint64_t tenant_id, common::ObIArray<common::ObAddr>& servers);
|
||||
virtual int check_tenant_small(const uint64_t tenant_id, bool& small_tenant);
|
||||
int get_pools_of_tenant(const uint64_t tenant_id, common::ObIArray<ObResourcePool>& pools);
|
||||
|
||||
int init(common::ObMySQLProxy &proxy, common::ObServerConfig *config = NULL);
|
||||
virtual int get_tenants(common::ObIArray<uint64_t> &tenants);
|
||||
virtual int get_server_tenant_configs(const common::ObAddr &server,
|
||||
common::ObIArray<ObTenantConfig> &tenant_configs);
|
||||
virtual int get_tenant_server_configs(const uint64_t tenant_id,
|
||||
common::ObIArray<ObServerConfig> &server_configs);
|
||||
virtual int get_sys_unit_count(int64_t &sys_unit_cnt);
|
||||
virtual int get_tenant_servers(const uint64_t tenant_id,
|
||||
common::ObIArray<common::ObAddr> &servers);
|
||||
virtual int check_tenant_small(const uint64_t tenant_id, bool &small_tenant);
|
||||
int get_pools_of_tenant(const uint64_t tenant_id,
|
||||
common::ObIArray<ObResourcePool> &pools);
|
||||
private:
|
||||
int get_units_of_server(const common::ObAddr& server, common::ObIArray<ObUnit>& units);
|
||||
int get_pools_of_units(const common::ObIArray<ObUnit>& units, common::ObIArray<ObResourcePool>& pools);
|
||||
int get_configs_of_pools(const common::ObIArray<ObResourcePool>& pools, common::ObIArray<ObUnitConfig>& configs);
|
||||
int get_units_of_pools(const common::ObIArray<ObResourcePool>& pools, common::ObIArray<ObUnit>& units);
|
||||
int get_units_of_server(const common::ObAddr &server,
|
||||
common::ObIArray<ObUnit> &units);
|
||||
int get_pools_of_units(const common::ObIArray<ObUnit> &units,
|
||||
common::ObIArray<ObResourcePool> &pools);
|
||||
int get_configs_of_pools(const common::ObIArray<ObResourcePool> &pools,
|
||||
common::ObIArray<ObUnitConfig> &configs);
|
||||
int get_units_of_pools(const common::ObIArray<ObResourcePool> &pools,
|
||||
common::ObIArray<ObUnit> &units);
|
||||
|
||||
int build_unit_infos(const common::ObIArray<ObUnit>& units, const common::ObIArray<ObUnitConfig>& configs,
|
||||
const common::ObIArray<ObResourcePool>& pools, common::ObIArray<ObUnitInfo>& unit_infos) const;
|
||||
int build_unit_infos(const common::ObIArray<ObUnit> &units,
|
||||
const common::ObIArray<ObUnitConfig> &configs,
|
||||
const common::ObIArray<ObResourcePool> &pools,
|
||||
common::ObIArray<ObUnitInfo> &unit_infos) const;
|
||||
|
||||
int add_server_config(const ObServerConfig& server_config, common::ObIArray<ObServerConfig>& server_configs);
|
||||
int find_pool_idx(const common::ObIArray<ObResourcePool>& pools, const uint64_t pool_id, int64_t& index) const;
|
||||
int find_config_idx(const common::ObIArray<ObUnitConfig>& configs, const uint64_t config_id, int64_t& index) const;
|
||||
int find_tenant_config_idx(
|
||||
const common::ObIArray<ObTenantConfig>& tenant_configs, const uint64_t tenant_id, int64_t& index) const;
|
||||
int find_server_config_idx(
|
||||
const common::ObIArray<ObServerConfig>& server_configs, const common::ObAddr& server, int64_t& index) const;
|
||||
void build_unit_stat(const common::ObAddr& server, const ObUnit& unit, ObUnitStatus& unit_stat) const;
|
||||
int add_server_config(const ObServerConfig &server_config,
|
||||
common::ObIArray<ObServerConfig> &server_configs);
|
||||
int find_pool_idx(const common::ObIArray<ObResourcePool> &pools,
|
||||
const uint64_t pool_id, int64_t &index) const;
|
||||
int find_config_idx(const common::ObIArray<ObUnitConfig> &configs,
|
||||
const uint64_t config_id, int64_t &index) const;
|
||||
int find_tenant_config_idx(const common::ObIArray<ObTenantConfig> &tenant_configs,
|
||||
const uint64_t tenant_id, int64_t &index) const;
|
||||
int find_server_config_idx(const common::ObIArray<ObServerConfig> &server_configs,
|
||||
const common::ObAddr &server, int64_t &index) const;
|
||||
void build_unit_stat(const common::ObAddr &server, const ObUnit &unit, ObUnitStatus &unit_stat) const;
|
||||
|
||||
int get_compat_mode(const int64_t tenant_id, ObWorker::CompatMode& compat_mode) const;
|
||||
int get_compat_mode(const int64_t tenant_id, lib::Worker::CompatMode &compat_mode) const;
|
||||
|
||||
private:
|
||||
bool inited_;
|
||||
ObUnitTableOperator ut_operator_;
|
||||
|
||||
static const char* unit_status_strs_[];
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObUnitInfoGetter);
|
||||
};
|
||||
|
||||
typedef common::ObSEArray<ObUnitInfoGetter::ObTenantConfig, 16> TenantUnits;
|
||||
|
||||
class ObUnitStatGetter {
|
||||
class ObUnitStatGetter
|
||||
{
|
||||
public:
|
||||
ObUnitStatGetter();
|
||||
virtual ~ObUnitStatGetter();
|
||||
int init(share::ObPartitionTableOperator& pt_operator, share::schema::ObMultiVersionSchemaService& schema_service,
|
||||
share::ObCheckStopProvider& check_stop_provider);
|
||||
virtual int get_unit_stat(uint64_t tenant_id, uint64_t unit_id, ObUnitStat& unit_stat) const;
|
||||
virtual int get_unit_stat(uint64_t tenant_id, share::ObUnitStatMap& unit_stat_map) const;
|
||||
|
||||
int init(share::ObCheckStopProvider &check_stop_provider);
|
||||
virtual int get_unit_stat(uint64_t tenant_id, uint64_t unit_id, ObUnitStat &unit_stat) const;
|
||||
virtual int get_unit_stat(uint64_t tenant_id, share::ObUnitStatMap &unit_stat_map) const;
|
||||
private:
|
||||
bool inited_;
|
||||
ObUnitStatTableOperator ut_stat_operator_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObUnitStatGetter);
|
||||
};
|
||||
|
||||
} // end namespace share
|
||||
} // end namespace oceanbase
|
||||
}//end namespace share
|
||||
}//end namespace oceanbase
|
||||
|
||||
#endif // OCEANBASE_SHARE_OB_UNIT_GETTER_H_
|
||||
#endif //OCEANBASE_SHARE_OB_UNIT_GETTER_H_
|
||||
|
||||
Reference in New Issue
Block a user