init.cpp 2.6 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2010
//

#include "common/seda/init.h"

#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <iostream>
#include <map>
#include <string>

#include "common/io/io.h"
#include "common/log/log.h"
#include "common/time/datetime.h"
#include "common/seda/kill_thread.h"
#include "common/seda/seda_config.h"
#include "common/seda/stage_factory.h"
#include "common/seda/metrics_stage.h"
#include "common/seda/thread_pool.h"
#include "common/seda/timer_stage.h"
namespace common {

40 41
int init_seda(ProcessParam *process_cfg)
{
羽飞's avatar
羽飞 已提交
42 43 44 45
  // Initialize the static data structures of threadpool
  Threadpool::create_pool_key();

  // initialize class factory instances here
46
  static StageFactory kill_thread_factory("KillThreads", &KillThreadStage::make_stage);
羽飞's avatar
羽飞 已提交
47
  static StageFactory timer_factory("TimerStage", &TimerStage::make_stage);
48
  static StageFactory seda_stats_factory("MetricsStage", &MetricsStage::make_stage);
羽飞's avatar
羽飞 已提交
49 50 51 52 53 54 55

  // try to parse the seda configuration files
  SedaConfig *config = SedaConfig::get_instance();
  SedaConfig::status_t config_stat;

  config_stat = config->parse();
  if (config_stat != SedaConfig::SUCCESS) {
56
    LOG_ERROR("Error: unable to parse file %s", process_cfg->get_process_name().c_str());
羽飞's avatar
羽飞 已提交
57 58 59 60 61 62
    return errno;
  }

  // Log a message to indicate that we are restarting, when looking
  // at a log we can see if mmon is restarting us because we keep
  // crashing.
63
  LOG_INFO("(Re)Starting State: Pid: %u Time: %s", (unsigned int)getpid(), DateTime::now().to_string_local().c_str());
羽飞's avatar
羽飞 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77
  LOG_INFO("The process Name is %s", process_cfg->get_process_name().c_str());

  // try to initialize the seda configuration
  config_stat = config->init();
  if (config_stat != SedaConfig::SUCCESS) {
    LOG_ERROR("SedaConfig: unable to initialize seda stages");
    return errno;
  }

  get_seda_config() = config;

  return 0;
}

78 79
void cleanup_seda()
{
羽飞's avatar
羽飞 已提交
80 81 82 83 84
  SedaConfig *seda_config = SedaConfig::get_instance();
  delete seda_config;
  SedaConfig::get_instance() = NULL;
}

85
}  // namespace common