add server event for unit gc

This commit is contained in:
windye
2023-10-12 08:13:43 +00:00
committed by ob-robot
parent 55e4aac591
commit 729ab79348
2 changed files with 54 additions and 34 deletions

View File

@ -138,6 +138,7 @@
#endif
#include "observer/table/ob_htable_lock_mgr.h"
#include "observer/table/ob_table_session_pool.h"
#include "observer/ob_server_event_history_table_operator.h"
using namespace oceanbase;
using namespace oceanbase::lib;
@ -1762,15 +1763,22 @@ int ObMultiTenant::del_tenant(const uint64_t tenant_id)
ret = OB_ERR_UNEXPECTED;
LOG_WARN("hidden tenant can't be deleted", K(ret), K(tenant_id));
} else {
const ObUnitInfoGetter::ObTenantConfig local_unit = tenant->get_unit();
const ObUnitInfoGetter::ObUnitStatus local_unit_status = local_unit.unit_status_;
// add a event when try to gc for the first time
if (local_unit_status != ObUnitInfoGetter::ObUnitStatus::UNIT_WAIT_GC_IN_OBSERVER &&
local_unit_status != ObUnitInfoGetter::ObUnitStatus::UNIT_DELETING_IN_OBSERVER) {
SERVER_EVENT_ADD("unit", "start unit gc", "tenant_id", tenant_id,
"unit_id", local_unit.unit_id_, "unit_status", "DELETING");
}
// Ensure to write delete_tenant_prepare_slog only once
ObUnitInfoGetter::ObUnitStatus old_unit_status = tenant->get_unit_status();
if (old_unit_status != ObUnitInfoGetter::UNIT_DELETING_IN_OBSERVER) {
if (local_unit_status != ObUnitInfoGetter::UNIT_DELETING_IN_OBSERVER) {
tenant->set_unit_status(ObUnitInfoGetter::UNIT_DELETING_IN_OBSERVER);
tenant->set_create_status(ObTenantCreateStatus::DELETING);
if (OB_FAIL(write_delete_tenant_prepare_slog(tenant_id))) {
LOG_WARN("fail to write delete tenant slog", K(ret), K(tenant_id), K(old_unit_status));
tenant->set_unit_status(old_unit_status);
}
LOG_WARN("fail to write delete tenant slog", K(ret), K(tenant_id), K(local_unit_status));
tenant->set_unit_status(local_unit_status);
}
}
@ -1798,8 +1806,13 @@ int ObMultiTenant::del_tenant(const uint64_t tenant_id)
LOG_WARN("fail to write delete tenant commit slog", K(ret), K(tenant_id));
}
} while (OB_FAIL(ret));
if (OB_SUCC(ret)) {
lib::ObMallocAllocator::get_instance()->recycle_tenant_allocator(tenant_id);
// add a event when finish gc unit
SERVER_EVENT_ADD("unit", "finish unit gc", "tenant_id", tenant_id,
"unit_id", local_unit.unit_id_, "unit_status", "DELETED");
}
}
}

View File

@ -35,6 +35,7 @@
#include "storage/tx_storage/ob_ls_service.h"
#include "storage/meta_mem/ob_tenant_meta_mem_mgr.h"
#include "storage/slog_ckpt/ob_server_checkpoint_slog_handler.h"
#include "observer/ob_server_event_history_table_operator.h"
#ifdef OB_BUILD_TDE_SECURITY
#include "share/ob_master_key_getter.h"
#endif
@ -458,6 +459,7 @@ int ObTenantNodeBalancer::fetch_effective_tenants(const TenantUnits &old_tenants
for (int64_t i = 0; OB_SUCC(ret) && i < old_tenants.count(); i++) {
found = false;
const ObUnitInfoGetter::ObTenantConfig &tenant_config = old_tenants.at(i);
const ObUnitInfoGetter::ObUnitStatus local_unit_status = tenant_config.unit_status_;
for (int64_t j = 0; j < new_tenants.count(); j++) {
if (tenant_config.tenant_id_ == new_tenants.at(j).tenant_id_) {
new_tenants.at(j).create_timestamp_ = tenant_config.create_timestamp_;
@ -499,19 +501,24 @@ int ObTenantNodeBalancer::fetch_effective_tenants(const TenantUnits &old_tenants
// need wait gc in observer
// NOTE: only update unit status when can not release resource
if (!is_released) {
tenants.at(tenants.count() - 1).unit_status_ =
ObUnitInfoGetter::UNIT_WAIT_GC_IN_OBSERVER;
tenants.at(tenants.count() - 1).unit_status_ = ObUnitInfoGetter::UNIT_WAIT_GC_IN_OBSERVER;
// add a event when try to gc for the first time
if (local_unit_status != ObUnitInfoGetter::ObUnitStatus::UNIT_WAIT_GC_IN_OBSERVER &&
local_unit_status != ObUnitInfoGetter::ObUnitStatus::UNIT_DELETING_IN_OBSERVER) {
SERVER_EVENT_ADD("unit", "start unit gc", "tenant_id", tenant_config.tenant_id_,
"unit_id", tenant_config.unit_id_, "unit_status", "WAIT GC");
}
}
LOG_INFO("[DELETE_TENANT] tenant has been dropped. can not delete tenant",
K(is_released),
K(is_released), "local_unit_status", ObUnitInfoGetter::get_unit_status_str(local_unit_status),
"is_removed", tenant_config.is_removed_,
"create_timestamp", tenant_config.create_timestamp_,
K(life_time), K(tenant_config));
}
} else {
LOG_INFO("[DELETE_TENANT] tenant has been dropped. can delete tenant",
K(is_released),
K(is_released), "local_unit_status", ObUnitInfoGetter::get_unit_status_str(local_unit_status),
"is_removed", tenant_config.is_removed_,
"create_timestamp", tenant_config.create_timestamp_,
K(life_time), K(tenant_config));