2
* Copyright (c) 2021 OceanBase
3
* OceanBase CE is licensed under Mulan PubL v2.
4
* You can use this software according to the terms and conditions of the Mulan PubL v2.
5
* You may obtain a copy of Mulan PubL v2 at:
6
* http://license.coscl.org.cn/MulanPubL-2.0
7
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
* See the Mulan PubL v2 for more details.
13
#define USING_LOG_PREFIX SERVER
15
#include "ob_server_reload_config.h"
16
#include "lib/alloc/alloc_func.h"
17
#include "lib/alloc/ob_malloc_allocator.h"
18
#include "lib/alloc/ob_malloc_sample_struct.h"
19
#include "lib/allocator/ob_tc_malloc.h"
20
#include "lib/allocator/ob_mem_leak_checker.h"
21
#include "share/scheduler/ob_tenant_dag_scheduler.h"
22
#include "rpc/obrpc/ob_rpc_handler.h"
23
#include "share/ob_cluster_version.h"
24
#include "share/ob_task_define.h"
25
#include "share/ob_resource_limit.h"
26
#include "rootserver/ob_root_service.h"
27
#include "observer/ob_server_struct.h"
28
#include "observer/ob_server.h"
29
#include "observer/ob_server_utils.h"
30
#include "observer/ob_service.h"
31
#include "share/allocator/ob_shared_memory_allocator_mgr.h"
32
#include "storage/tx_storage/ob_tenant_freezer.h"
33
#include "storage/compaction/ob_tenant_tablet_scheduler.h"
34
#include "storage/slog/ob_storage_logger_manager.h"
35
#include "share/ob_ddl_sim_point.h"
37
using namespace oceanbase::lib;
38
using namespace oceanbase::common;
39
using namespace oceanbase::observer;
40
using namespace oceanbase::storage;
41
using namespace oceanbase::share;
48
int set_cluster_name_hash(const ObString &cluster_name)
51
uint64_t cluster_name_hash = obrpc::ObRpcPacket::INVALID_CLUSTER_NAME_HASH;
53
if (OB_FAIL(calc_cluster_name_hash(cluster_name, cluster_name_hash))) {
54
LOG_WARN("failed to calc_cluster_name_hash", KR(ret), K(cluster_name));
56
obrpc::ObRpcNetHandler::CLUSTER_NAME_HASH = cluster_name_hash;
57
LOG_INFO("set cluster_name_hash", KR(ret), K(cluster_name), K(cluster_name_hash));
62
int calc_cluster_name_hash(const ObString &cluster_name, uint64_t &cluster_name_hash)
65
cluster_name_hash = obrpc::ObRpcPacket::INVALID_CLUSTER_NAME_HASH;
67
if (0 == cluster_name.length()) {
68
cluster_name_hash = obrpc::ObRpcPacket::INVALID_CLUSTER_NAME_HASH;
69
LOG_INFO("set cluster_name_hash to invalid", K(cluster_name));
71
cluster_name_hash = common::murmurhash(cluster_name.ptr(), cluster_name.length(), 0);
72
LOG_INFO("calc cluster_name_hash for rpc", K(cluster_name), K(cluster_name_hash));
79
ObServerReloadConfig::ObServerReloadConfig(ObServerConfig &config, ObGlobalContext &gctx)
80
: ObReloadConfig(&config),
85
ObServerReloadConfig::~ObServerReloadConfig()
90
int ObServerReloadConfig::operator()()
92
int tmp_ret = OB_SUCCESS;
94
const bool is_arbitration_mode = OBSERVER.is_arbitration_mode();
96
if (!gctx_.is_inited()) {
97
ret = tmp_ret = OB_INNER_STAT_ERROR;
98
LOG_WARN("gctx not init", "gctx inited", gctx_.is_inited(), K(tmp_ret));
100
if (OB_TMP_FAIL(ObReloadConfig::operator()())) {
101
LOG_WARN("ObReloadConfig operator() failed", K(tmp_ret));
103
if (OB_TMP_FAIL(gctx_.root_service_->reload_config())) {
104
LOG_WARN("root_service_ reload_config failed", K(tmp_ret));
106
if (OB_TMP_FAIL(gctx_.location_service_->reload_config())) {
107
LOG_WARN("location service reload config failed", KR(tmp_ret));
109
if (OB_TMP_FAIL(ObClusterVersion::get_instance().reload_config())) {
110
LOG_WARN("cluster version reload config failed", K(tmp_ret));
113
if (OB_TMP_FAIL(OBSERVER.reload_config())) {
114
LOG_WARN("reload configuration for ob service fail", K(tmp_ret));
116
if (OB_TMP_FAIL(OBSERVER.get_net_frame().reload_config())) {
117
LOG_WARN("reload configuration for net frame fail", K(tmp_ret));
119
if (OB_TMP_FAIL(OBSERVER.get_net_frame().reload_ssl_config())) {
120
LOG_WARN("reload ssl config for net frame fail", K(tmp_ret));
122
if (OB_TMP_FAIL(OBSERVER.get_rl_mgr().reload_config())) {
123
LOG_WARN("reload config for ratelimit manager fail", K(tmp_ret));
125
if (OB_TMP_FAIL(ObTdeEncryptEngineLoader::get_instance().reload_config())) {
126
LOG_WARN("reload config for tde encrypt engine fail", K(tmp_ret));
128
if (OB_TMP_FAIL(ObSrvNetworkFrame::reload_rpc_auth_method())) {
129
LOG_WARN("reload config for rpc auth method fail", K(tmp_ret));
133
GMEMCONF.reload_config(GCONF);
134
const int64_t limit_memory = GMEMCONF.get_server_memory_limit();
135
OB_LOGGER.set_info_as_wdiag(GET_MIN_CLUSTER_VERSION() < CLUSTER_VERSION_4_1_0_0);
136
// reload log config again after get MIN_CLUSTER_VERSION
137
if (OB_TMP_FAIL(ObReloadConfig::operator()())) {
138
LOG_WARN("ObReloadConfig operator() failed", K(tmp_ret));
140
const int64_t reserved_memory = GCONF.cache_wash_threshold;
141
const int64_t reserved_urgent_memory = GCONF.memory_reserved;
142
LOG_INFO("set limit memory", K(limit_memory));
143
set_memory_limit(limit_memory);
144
LOG_INFO("set reserved memory", K(reserved_memory));
145
ob_set_reserved_memory(reserved_memory);
146
LOG_INFO("set urgent memory", K(reserved_urgent_memory));
147
ob_set_urgent_memory(reserved_urgent_memory);
149
__MemoryContext__::set_enable_asan_allocator(GCONF.enable_asan_for_memory_context);
151
ObMallocSampleLimiter::set_interval(GCONF._max_malloc_sample_interval,
152
GCONF._min_malloc_sample_interval);
153
if (!is_arbitration_mode) {
154
ObIOConfig io_config;
155
int64_t cpu_cnt = GCONF.cpu_count;
157
cpu_cnt = common::get_cpu_num();
159
io_config.disk_io_thread_count_ = GCONF.disk_io_thread_count;
160
// In the 2.x version, reuse the sys_bkgd_io_timeout configuration item to indicate the data disk io timeout time
161
// After version 3.1, use the data_storage_io_timeout configuration item.
162
io_config.data_storage_io_timeout_ms_ = GCONF._data_storage_io_timeout / 1000L;
163
io_config.data_storage_warning_tolerance_time_ = GCONF.data_storage_warning_tolerance_time;
164
io_config.data_storage_error_tolerance_time_ = GCONF.data_storage_error_tolerance_time;
165
if (!is_arbitration_mode
166
&& OB_TMP_FAIL(ObIOManager::get_instance().set_io_config(io_config))) {
167
LOG_WARN("reload io manager config fail, ", K(tmp_ret));
170
(void)reload_diagnose_info_config(GCONF.enable_perf_event);
171
(void)reload_trace_log_config(GCONF.enable_record_trace_log);
173
reload_tenant_freezer_config_();
174
reload_tenant_scheduler_config_();
178
ObMallocAllocator *malloc_allocator = ObMallocAllocator::get_instance();
179
const bool reserve = true;
180
malloc_allocator->set_tenant_ctx_idle(OB_SERVER_TENANT_ID, ObCtxIds::LIBEASY,
181
(GCONF.__easy_memory_limit * GCONF.__easy_memory_reserved_percentage) / 100,
187
int64_t cache_size = GCONF.memory_chunk_cache_size;
188
if (0 == cache_size) {
189
cache_size = GMEMCONF.get_server_memory_limit();
190
if (cache_size >= (32L<<30)) {
191
cache_size -= (4L<<30);
194
int64_t large_cache_size = GCONF._memory_large_chunk_cache_size;
195
if (0 == large_cache_size) {
196
large_cache_size = lib::AChunkMgr::DEFAULT_LARGE_CHUNK_CACHE_SIZE;
198
lib::AChunkMgr::instance().set_max_chunk_cache_size(cache_size);
199
lib::AChunkMgr::instance().set_max_large_chunk_cache_size(large_cache_size);
201
if (!is_arbitration_mode) {
202
// Refresh cluster_id, cluster_name_hash for non arbitration mode
203
if (GCONF.cluster_id.get_value() > 0) {
204
obrpc::ObRpcNetHandler::CLUSTER_ID = GCONF.cluster_id.get_value();
205
LOG_INFO("set CLUSTER_ID for rpc", "cluster_id", GCONF.cluster_id.get_value());
208
if (FAILEDx(set_cluster_name_hash(GCONF.cluster.str()))) {
209
LOG_WARN("failed to set_cluster_name_hash", KR(ret), "cluster_name", GCONF.cluster.str(),
210
"cluster_name_len", strlen(GCONF.cluster.str()));
216
static common::ObMemLeakChecker::TCharArray last_value;
217
static bool do_once __attribute__((unused)) = [&]() {
218
STRNCPY(&last_value[0], GCONF.leak_mod_to_check.str(), sizeof(last_value));
221
if (0 == STRNCMP(last_value, GCONF.leak_mod_to_check.str(), sizeof(last_value))) {
222
// At the end of the observer startup, the config will be reloaded once. If the status is not judged, the trace caught during the startup process will be flushed.
225
reset_mem_leak_checker_label(GCONF.leak_mod_to_check.str());
227
STRNCPY(last_value, GCONF.leak_mod_to_check.str(), sizeof(last_value));
228
last_value[sizeof(last_value) - 1] = '\0';
233
static char last_storage_check_mod[MAX_CACHE_NAME_LENGTH];
234
if (0 != STRNCMP(last_storage_check_mod, GCONF._storage_leak_check_mod.str(), sizeof(last_storage_check_mod))) {
235
ObKVGlobalCache::get_instance().set_storage_leak_check_mod(GCONF._storage_leak_check_mod.str());
236
STRNCPY(last_storage_check_mod, GCONF._storage_leak_check_mod.str(), sizeof(last_storage_check_mod));
241
ObMallocAllocator::get_instance()->force_explict_500_malloc_ =
242
GCONF._force_explict_500_malloc;
246
sanity_set_whitelist(GCONF.sanity_whitelist.str());
247
ObMallocAllocator::get_instance()->enable_tenant_leak_memory_protection_ =
248
GCONF._enable_tenant_leak_memory_protection;
253
int tmp_ret = rl.load_config(GCONF._resource_limit_spec.str());
254
if (OB_SUCCESS != tmp_ret) {
255
LOG_WARN("load _resource_limit_spec failed", K(tmp_ret), K(GCONF._resource_limit_spec.str()));
257
LOG_INFO("load _resource_limit_spec succeed", "origin", RL_CONF, "current", rl,
258
K(GCONF._resource_limit_spec.str()));
261
ObResourceLimit::IS_ENABLED = GCONF._enable_resource_limit_spec;
265
auto new_level = obrpc::get_rpc_checksum_check_level_from_string(GCONF._rpc_checksum.str());
266
auto orig_level = obrpc::get_rpc_checksum_check_level();
267
if (new_level != orig_level) {
268
LOG_INFO("rpc_checksum_check_level changed",
272
obrpc::set_rpc_checksum_check_level(new_level);
275
if (!is_arbitration_mode) {
276
auto new_upgrade_stage = obrpc::get_upgrade_stage(GCONF._upgrade_stage.str());
277
auto orig_upgrade_stage = GCTX.get_upgrade_stage();
278
if (new_upgrade_stage != orig_upgrade_stage) {
279
LOG_INFO("_upgrade_stage changed", K(new_upgrade_stage), K(orig_upgrade_stage));
281
(void)GCTX.set_upgrade_stage(new_upgrade_stage);
284
// syslog bandwidth limitation
285
share::ObTaskController::get().set_log_rate_limit(
286
GCONF.syslog_io_bandwidth_limit.get_value());
287
share::ObTaskController::get().set_diag_per_error_limit(
288
GCONF.diag_syslog_per_error_limit.get_value());
290
lib::g_runtime_enabled = true;
292
if (!is_arbitration_mode) {
293
common::ObKVGlobalCache::get_instance().reload_wash_interval();
294
int tmp_ret = OB_SUCCESS;
295
int64_t data_disk_size = 0;
296
int64_t data_disk_percentage = 0;
297
int64_t reserved_size = 0;
298
if (OB_TMP_FAIL(ObServerUtils::get_data_disk_info_in_config(data_disk_size,
299
data_disk_percentage))) {
300
LOG_ERROR("cal_all_part_disk_size failed", KR(tmp_ret));
301
} else if (OB_TMP_FAIL(SLOGGERMGR.get_reserved_size(reserved_size))) {
302
LOG_WARN("fail to get reserved size", KR(tmp_ret), K(reserved_size));
303
} else if (OB_TMP_FAIL(OB_SERVER_BLOCK_MGR.resize_file(data_disk_size,
304
data_disk_percentage,
306
LOG_WARN("fail to resize file", KR(tmp_ret),
307
K(data_disk_size), K(data_disk_percentage), K(reserved_size));
312
ObSysVariables::set_value("datadir", GCONF.data_dir);
316
common::g_enable_backtrace = GCONF._enable_backtrace_function;
320
ObMallocAllocator::get_instance()->force_malloc_for_absent_tenant_ = GCONF._force_malloc_for_absent_tenant;
325
void ObServerReloadConfig::reload_tenant_scheduler_config_()
327
int ret = OB_SUCCESS;
328
omt::ObMultiTenant *omt = GCTX.omt_;
329
if (OB_ISNULL(omt)) {
330
ret = OB_ERR_UNEXPECTED;
331
LOG_WARN("omt should not be null", K(ret));
334
(void)MTL(ObTenantDagScheduler *)->reload_config();
335
(void)MTL(compaction::ObTenantTabletScheduler *)->reload_tenant_config();
338
omt->operate_in_each_tenant(f);
342
int ObServerReloadConfig::ObReloadTenantFreezerConfOp::operator()()
344
int ret = OB_SUCCESS;
345
// NOTICE: tenant freezer should update before ObSharedMemAllocMgr.
346
MTL(ObTenantFreezer *)->reload_config();
347
MTL(ObSharedMemAllocMgr*)->update_throttle_config();
351
void ObServerReloadConfig::reload_tenant_freezer_config_()
353
int ret = OB_SUCCESS;
354
omt::ObMultiTenant *omt = GCTX.omt_;
355
if (OB_ISNULL(omt)) {
356
ret = OB_ERR_UNEXPECTED;
357
LOG_WARN("omt should not be null", K(ret));
359
ObReloadTenantFreezerConfOp f;
360
omt->operate_in_each_tenant(f);