refactor stellar config

This commit is contained in:
luwenpeng
2024-06-25 19:12:21 +08:00
parent 276bdd1b99
commit 83bffdd008
9 changed files with 113 additions and 118 deletions

View File

@@ -10,13 +10,13 @@
#include "log.h"
#include "logo.h"
#include "times.h"
#include "config.h"
#include "packet_def.h"
#include "packet_utils.h"
#include "session_utils.h"
#include "id_generator.h"
#include "stellar_stat.h"
#include "stellar_utils.h"
#include "stellar_config.h"
#include "plugin_manager.h"
#define STELLAR_LOG_STATE(format, ...) LOG_STATE("stellar", format, ##__VA_ARGS__)
@@ -319,7 +319,7 @@ static void signal_handler(int signo)
static int all_session_have_freed(struct stellar_runtime *runtime, struct stellar_config *config)
{
for (int i = 0; i < config->io_opts.nr_threads; i++)
for (int i = 0; i < config->pkt_io_opts.nr_threads; i++)
{
struct session_manager *sess_mgr = runtime->threads[i].sess_mgr;
struct session_manager_stat *sess_stat = session_manager_stat(sess_mgr);
@@ -341,7 +341,7 @@ static int all_session_have_freed(struct stellar_runtime *runtime, struct stella
static int stellar_thread_init(struct stellar_runtime *runtime, struct stellar_config *config)
{
uint64_t now = stellar_get_monotonic_time_msec();
for (uint16_t i = 0; i < config->io_opts.nr_threads; i++)
for (uint16_t i = 0; i < config->pkt_io_opts.nr_threads; i++)
{
struct stellar_thread *thread = &runtime->threads[i];
thread->idx = i;
@@ -353,7 +353,7 @@ static int stellar_thread_init(struct stellar_runtime *runtime, struct stellar_c
STELLAR_LOG_ERROR("unable to create session manager");
return -1;
}
thread->ip_mgr = ip_reassembly_new(&config->ip_opts);
thread->ip_mgr = ip_reassembly_new(&config->ip_reass_opts);
if (thread->ip_mgr == NULL)
{
STELLAR_LOG_ERROR("unable to create ip reassemble manager");
@@ -367,7 +367,7 @@ static int stellar_thread_init(struct stellar_runtime *runtime, struct stellar_c
static void stellar_thread_clean(struct stellar_runtime *runtime, struct stellar_config *config)
{
for (uint16_t i = 0; i < config->io_opts.nr_threads; i++)
for (uint16_t i = 0; i < config->pkt_io_opts.nr_threads; i++)
{
struct stellar_thread *thread = &runtime->threads[i];
if (ATOMIC_READ(&thread->is_runing) == 0)
@@ -381,7 +381,7 @@ static void stellar_thread_clean(struct stellar_runtime *runtime, struct stellar
static int stellar_thread_run(struct stellar_runtime *runtime, struct stellar_config *config)
{
for (uint16_t i = 0; i < config->io_opts.nr_threads; i++)
for (uint16_t i = 0; i < config->pkt_io_opts.nr_threads; i++)
{
struct stellar_thread *thread = &runtime->threads[i];
if (pthread_create(&thread->tid, NULL, work_thread, (void *)thread) < 0)
@@ -396,7 +396,7 @@ static int stellar_thread_run(struct stellar_runtime *runtime, struct stellar_co
static void stellar_thread_join(struct stellar_runtime *runtime, struct stellar_config *config)
{
for (uint16_t i = 0; i < config->io_opts.nr_threads; i++)
for (uint16_t i = 0; i < config->pkt_io_opts.nr_threads; i++)
{
struct stellar_thread *thread = &runtime->threads[i];
while (ATOMIC_READ(&thread->is_runing) == 1)
@@ -410,8 +410,8 @@ static void stellar_thread_join(struct stellar_runtime *runtime, struct stellar_
int stellar_main(int argc, char **argv)
{
static struct stellar st = {0};
static struct stellar_runtime *runtime = &st.runtime;
static struct stellar_config *config = &st.config;
struct stellar_runtime *runtime = &st.runtime;
struct stellar_config *config = &st.config;
stellar_update_time_cache();
@@ -430,20 +430,20 @@ int stellar_main(int argc, char **argv)
STELLAR_LOG_STATE("main config file : %s", main_config_file);
STELLAR_LOG_STATE("plugin config file : %s", plugin_config_file);
if (stellar_load_config(main_config_file, config) != 0)
if (stellar_config_load(config, main_config_file) != 0)
{
STELLAR_LOG_ERROR("unable to load config file");
goto error_out;
}
stellar_print_config(config);
stellar_config_print(config);
if (id_generator_init(config->dev_opts.base, config->dev_opts.offset) != 0)
if (id_generator_init(&config->id_gen_opts) != 0)
{
STELLAR_LOG_ERROR("unable to init id generator");
goto error_out;
}
runtime->stat = stellar_stat_new(config->io_opts.nr_threads);
runtime->stat = stellar_stat_new(config->pkt_io_opts.nr_threads);
if (runtime->stat == NULL)
{
STELLAR_LOG_ERROR("unable to create stellar stat");
@@ -456,7 +456,7 @@ int stellar_main(int argc, char **argv)
goto error_out;
}
runtime->packet_io = packet_io_new(&config->io_opts);
runtime->packet_io = packet_io_new(&config->pkt_io_opts);
if (runtime->packet_io == NULL)
{
STELLAR_LOG_ERROR("unable to create packet io");