oceanbase

Форк
0
/
ob_server_reload_config.cpp 
362 строки · 13.4 Кб
1
/**
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.
11
 */
12

13
#define USING_LOG_PREFIX SERVER
14

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"
36

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;
42

43
namespace oceanbase
44
{
45
namespace observer
46
{
47

48
int set_cluster_name_hash(const ObString &cluster_name)
49
{
50
  int ret = OB_SUCCESS;
51
  uint64_t cluster_name_hash = obrpc::ObRpcPacket::INVALID_CLUSTER_NAME_HASH;
52

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));
55
  } else {
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));
58
  }
59
  return ret;
60
}
61

62
int calc_cluster_name_hash(const ObString &cluster_name, uint64_t &cluster_name_hash)
63
{
64
  int ret = OB_SUCCESS;
65
  cluster_name_hash = obrpc::ObRpcPacket::INVALID_CLUSTER_NAME_HASH;
66

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));
70
  } else {
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));
73
  }
74

75
  return ret;
76
}
77
}
78
}
79
ObServerReloadConfig::ObServerReloadConfig(ObServerConfig &config, ObGlobalContext &gctx)
80
  : ObReloadConfig(&config),
81
    gctx_(gctx)
82
{
83
}
84

85
ObServerReloadConfig::~ObServerReloadConfig()
86
{
87

88
}
89

90
int ObServerReloadConfig::operator()()
91
{
92
  int tmp_ret = OB_SUCCESS;
93
  int ret = tmp_ret;
94
  const bool is_arbitration_mode = OBSERVER.is_arbitration_mode();
95

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));
99
  } else {
100
    if (OB_TMP_FAIL(ObReloadConfig::operator()())) {
101
      LOG_WARN("ObReloadConfig operator() failed", K(tmp_ret));
102
    }
103
    if (OB_TMP_FAIL(gctx_.root_service_->reload_config())) {
104
      LOG_WARN("root_service_ reload_config failed", K(tmp_ret));
105
    }
106
    if (OB_TMP_FAIL(gctx_.location_service_->reload_config())) {
107
      LOG_WARN("location service reload config failed", KR(tmp_ret));
108
    }
109
    if (OB_TMP_FAIL(ObClusterVersion::get_instance().reload_config())) {
110
      LOG_WARN("cluster version reload config failed", K(tmp_ret));
111
    }
112

113
    if (OB_TMP_FAIL(OBSERVER.reload_config())) {
114
      LOG_WARN("reload configuration for ob service fail", K(tmp_ret));
115
    }
116
    if (OB_TMP_FAIL(OBSERVER.get_net_frame().reload_config())) {
117
      LOG_WARN("reload configuration for net frame fail", K(tmp_ret));
118
    }
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));
121
    }
122
    if (OB_TMP_FAIL(OBSERVER.get_rl_mgr().reload_config())) {
123
      LOG_WARN("reload config for ratelimit manager fail", K(tmp_ret));
124
    }
125
    if (OB_TMP_FAIL(ObTdeEncryptEngineLoader::get_instance().reload_config())) {
126
      LOG_WARN("reload config for tde encrypt engine fail", K(tmp_ret));
127
    }
128
    if (OB_TMP_FAIL(ObSrvNetworkFrame::reload_rpc_auth_method())) {
129
      LOG_WARN("reload config for rpc auth method fail", K(tmp_ret));
130
    }
131
  }
132
  {
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));
139
    }
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);
148
#ifdef OB_USE_ASAN
149
    __MemoryContext__::set_enable_asan_allocator(GCONF.enable_asan_for_memory_context);
150
#endif
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;
156
      if (cpu_cnt <= 0) {
157
        cpu_cnt = common::get_cpu_num();
158
      }
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));
168
      }
169

170
      (void)reload_diagnose_info_config(GCONF.enable_perf_event);
171
      (void)reload_trace_log_config(GCONF.enable_record_trace_log);
172

173
      reload_tenant_freezer_config_();
174
      reload_tenant_scheduler_config_();
175
    }
176
  }
177
  {
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,
182
        reserve);
183
  }
184

185

186

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);
192
    }
193
  }
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;
197
  }
198
  lib::AChunkMgr::instance().set_max_chunk_cache_size(cache_size);
199
  lib::AChunkMgr::instance().set_max_large_chunk_cache_size(large_cache_size);
200

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());
206
    }
207

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()));
211
    }
212
  }
213

214
  // reset mem leak
215
  {
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));
219
                            return false;
220
                          }();
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.
223
      // do-nothing
224
    } else {
225
      reset_mem_leak_checker_label(GCONF.leak_mod_to_check.str());
226

227
      STRNCPY(last_value, GCONF.leak_mod_to_check.str(), sizeof(last_value));
228
      last_value[sizeof(last_value) - 1] = '\0';
229
    }
230
  }
231

232
  {
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));
237
    }
238
  }
239
#ifndef ENABLE_SANITY
240
  {
241
    ObMallocAllocator::get_instance()->force_explict_500_malloc_ =
242
      GCONF._force_explict_500_malloc;
243
  }
244
#else
245
  {
246
    sanity_set_whitelist(GCONF.sanity_whitelist.str());
247
    ObMallocAllocator::get_instance()->enable_tenant_leak_memory_protection_ =
248
      GCONF._enable_tenant_leak_memory_protection;
249
  }
250
#endif
251
  {
252
    ObResourceLimit rl;
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()));
256
    } else {
257
      LOG_INFO("load _resource_limit_spec succeed", "origin", RL_CONF, "current", rl,
258
               K(GCONF._resource_limit_spec.str()));
259
      RL_CONF.assign(rl);
260
    }
261
    ObResourceLimit::IS_ENABLED = GCONF._enable_resource_limit_spec;
262
  }
263

264
  {
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",
269
               "orig", orig_level,
270
               "new", new_level);
271
    }
272
    obrpc::set_rpc_checksum_check_level(new_level);
273
  }
274

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));
280
    }
281
    (void)GCTX.set_upgrade_stage(new_upgrade_stage);
282
  }
283

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());
289

290
  lib::g_runtime_enabled = true;
291

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,
305
                                                           reserved_size))) {
306
      LOG_WARN("fail to resize file", KR(tmp_ret),
307
          K(data_disk_size), K(data_disk_percentage), K(reserved_size));
308
    }
309
  }
310

311
  {
312
    ObSysVariables::set_value("datadir", GCONF.data_dir);
313
  }
314

315
  {
316
    common::g_enable_backtrace = GCONF._enable_backtrace_function;
317
  }
318

319
  {
320
    ObMallocAllocator::get_instance()->force_malloc_for_absent_tenant_ = GCONF._force_malloc_for_absent_tenant;
321
  }
322
  return ret;
323
}
324

325
void ObServerReloadConfig::reload_tenant_scheduler_config_()
326
{
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));
332
  } else {
333
    auto f = [] () {
334
      (void)MTL(ObTenantDagScheduler *)->reload_config();
335
      (void)MTL(compaction::ObTenantTabletScheduler *)->reload_tenant_config();
336
      return OB_SUCCESS;
337
    };
338
    omt->operate_in_each_tenant(f);
339
  }
340
}
341

342
int ObServerReloadConfig::ObReloadTenantFreezerConfOp::operator()()
343
{
344
  int ret = OB_SUCCESS;
345
  // NOTICE: tenant freezer should update before ObSharedMemAllocMgr.
346
  MTL(ObTenantFreezer *)->reload_config();
347
  MTL(ObSharedMemAllocMgr*)->update_throttle_config();
348
  return ret;
349
}
350

351
void ObServerReloadConfig::reload_tenant_freezer_config_()
352
{
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));
358
  } else {
359
    ObReloadTenantFreezerConfOp f;
360
    omt->operate_in_each_tenant(f);
361
  }
362
}
363

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.