diff --git a/conf/stellar.toml b/conf/stellar.toml index 0ba7fba..4e5fcbb 100644 --- a/conf/stellar.toml +++ b/conf/stellar.toml @@ -1,6 +1,6 @@ -[id_generator] -snowflake_worker_id_base = 1 # [0, 31] -snowflake_worker_id_offset = 2 # [0, 127] +[snowflake] +snowflake_base = 1 # [0, 31] +snowflake_offset = 2 # [0, 127] [packet_io] mode = dumpfile # dumpfile, marsio diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 167a6e8..567aea2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ add_subdirectory(log) add_subdirectory(tuple) add_subdirectory(packet) add_subdirectory(packet_io) -add_subdirectory(id_generator) +add_subdirectory(snowflake) add_subdirectory(ip_reassembly) add_subdirectory(tcp_reassembly) add_subdirectory(duplicated_packet_filter) diff --git a/src/id_generator/CMakeLists.txt b/src/id_generator/CMakeLists.txt deleted file mode 100644 index 7a7068e..0000000 --- a/src/id_generator/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_library(id_generator id_generator.cpp) -target_include_directories(id_generator PUBLIC ${CMAKE_CURRENT_LIST_DIR}) -target_include_directories(id_generator PUBLIC ${CMAKE_SOURCE_DIR}/src/utils) -target_include_directories(id_generator PUBLIC ${CMAKE_SOURCE_DIR}/include/stellar) -target_link_libraries(id_generator stellar_core) \ No newline at end of file diff --git a/src/id_generator/id_generator.cpp b/src/id_generator/id_generator.cpp deleted file mode 100644 index c9029c2..0000000 --- a/src/id_generator/id_generator.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include - -#include "log.h" -#include "utils.h" -#include "stellar.h" -#include "id_generator.h" - -#define ID_GENERATOR_LOG_ERROR(format, ...) LOG_ERROR("id generator", format, ##__VA_ARGS__) -#define ID_GENERATOR_LOG_DEBUG(format, ...) LOG_DEBUG("id generator", format, ##__VA_ARGS__) - -struct id_generator -{ - uint8_t snowflake_worker_id_base; // 5bit [0, 31] - uint8_t snowflake_worker_id_offset; // 7bit [0, 127] - uint64_t device_id; // 12bit [0, 4095] ( base << 7 | offset ) - uint64_t thread_volatile[MAX_THREAD_NUM]; -}; - -struct id_generator global_id_generator = {}; - -// return 0: success -// return -1: failed -int id_generator_init(const struct id_generator_options *opts) -{ - memset(&global_id_generator, 0, sizeof(struct id_generator)); - - if (opts == NULL) - { - ID_GENERATOR_LOG_ERROR("opts is NULL"); - return -1; - } - - if (opts->snowflake_worker_id_base > 31) - { - ID_GENERATOR_LOG_ERROR("snowflake_worker_id_base %u is invalid, range [0, 31]", opts->snowflake_worker_id_base); - return -1; - } - - if (opts->snowflake_worker_id_offset > 127) - { - ID_GENERATOR_LOG_ERROR("snowflake_worker_id_offset %u is invalid, range [0, 127]", opts->snowflake_worker_id_offset); - return -1; - } - - global_id_generator.snowflake_worker_id_base = opts->snowflake_worker_id_base; - global_id_generator.snowflake_worker_id_offset = opts->snowflake_worker_id_offset; - global_id_generator.device_id = ((global_id_generator.snowflake_worker_id_base << 7) | global_id_generator.snowflake_worker_id_offset) & 0xFFF; - - ID_GENERATOR_LOG_DEBUG("snowflake_worker_id_base: %u, snowflake_worker_id_offset: %u, device_id: %u", - global_id_generator.snowflake_worker_id_base, - global_id_generator.snowflake_worker_id_offset, - global_id_generator.device_id); - return 0; -} - -/* - * high -> low - * - * +------+------------------+----------------+------------------------+---------------------------+ - * | 1bit | 12bit device_id | 8bit thread_id | 28bit timestamp in sec | 15bit sequence per thread | - * +------+------------------+----------------+------------------------+---------------------------+ - */ -uint64_t id_generator_alloc(uint64_t now_sec) -{ -#define MAX_ID_PER_THREAD (32768) -#define MAX_ID_BASE_TIME (268435456L) - - uint64_t thr_idx = (uint16_t)stellar_get_current_thread_index(); - - uint64_t global_id = 0; - uint64_t id_per_thread = (global_id_generator.thread_volatile[thr_idx]++) % MAX_ID_PER_THREAD; - uint64_t id_base_time = now_sec % MAX_ID_BASE_TIME; - global_id = (global_id_generator.device_id << 51) | - (thr_idx << 43) | - (id_base_time << 15) | - (id_per_thread); - - return global_id; -} diff --git a/src/id_generator/id_generator.h b/src/id_generator/id_generator.h deleted file mode 100644 index b3a2d60..0000000 --- a/src/id_generator/id_generator.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include - -struct id_generator_options -{ - uint8_t snowflake_worker_id_base; - uint8_t snowflake_worker_id_offset; -}; - -// return 0: success -// return -1: failed -int id_generator_init(const struct id_generator_options *opts); -uint64_t id_generator_alloc(uint64_t now_sec); - -#ifdef __cplusplus -} -#endif diff --git a/src/session/CMakeLists.txt b/src/session/CMakeLists.txt index ce2ef15..397b71e 100644 --- a/src/session/CMakeLists.txt +++ b/src/session/CMakeLists.txt @@ -10,6 +10,6 @@ target_include_directories(session_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/src/stellar) target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/include) target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/src/utils) -target_link_libraries(session_manager timeout id_generator duplicated_packet_filter evicted_session_filter log tcp_reassembly) +target_link_libraries(session_manager timeout snowflake duplicated_packet_filter evicted_session_filter log tcp_reassembly) add_subdirectory(test) \ No newline at end of file diff --git a/src/session/session_manager.cpp b/src/session/session_manager.cpp index 14e7afa..bbbabb6 100644 --- a/src/session/session_manager.cpp +++ b/src/session/session_manager.cpp @@ -8,7 +8,7 @@ #include "udp_utils.h" #include "packet_layer.h" #include "packet_utils.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_def.h" #include "session_utils.h" #include "session_pool.h" @@ -539,7 +539,7 @@ static void session_update(struct session_manager *mgr, struct session *sess, en { if (session_get_current_state(sess) == SESSION_STATE_INIT) { - session_set_id(sess, id_generator_alloc(mgr->now_ms / 1000)); + session_set_id(sess, snowflake_id_generate(mgr->now_ms / 1000)); session_set_tuple6(sess, key); session_set_tuple_direction(sess, dir); diff --git a/src/session/test/gtest_case_tcp_fast_open.cpp b/src/session/test/gtest_case_tcp_fast_open.cpp index b3c27ed..d836dfb 100644 --- a/src/session/test/gtest_case_tcp_fast_open.cpp +++ b/src/session/test/gtest_case_tcp_fast_open.cpp @@ -3,7 +3,7 @@ #include "tuple.h" #include "packet_def.h" #include "packet_parse.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "tcp_reassembly.h" @@ -421,11 +421,11 @@ TEST(CASE, TCP_FAST_OPEN) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_tcp_active_to_closing.cpp b/src/session/test/gtest_state_tcp_active_to_closing.cpp index f34097b..f5fc887 100644 --- a/src/session/test/gtest_state_tcp_active_to_closing.cpp +++ b/src/session/test/gtest_state_tcp_active_to_closing.cpp @@ -6,7 +6,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -555,11 +555,11 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_tcp_init_to_opening.cpp b/src/session/test/gtest_state_tcp_init_to_opening.cpp index f5ff428..347c9f4 100644 --- a/src/session/test/gtest_state_tcp_init_to_opening.cpp +++ b/src/session/test/gtest_state_tcp_init_to_opening.cpp @@ -6,7 +6,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -776,11 +776,11 @@ TEST(TCP_INIT_TO_OPENING, BY_S2C_ASMMETRIC) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp b/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp index 84719e9..2b11649 100644 --- a/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp +++ b/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp @@ -5,7 +5,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -445,11 +445,11 @@ TEST(TCP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING_TO_CLOSED, TEST) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_tcp_opening_to_active.cpp b/src/session/test/gtest_state_tcp_opening_to_active.cpp index 9bb9efe..4a9aed1 100644 --- a/src/session/test/gtest_state_tcp_opening_to_active.cpp +++ b/src/session/test/gtest_state_tcp_opening_to_active.cpp @@ -5,7 +5,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -232,11 +232,11 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYNACK_S2C_DATA) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_tcp_opening_to_closing.cpp b/src/session/test/gtest_state_tcp_opening_to_closing.cpp index e37523f..21087e1 100644 --- a/src/session/test/gtest_state_tcp_opening_to_closing.cpp +++ b/src/session/test/gtest_state_tcp_opening_to_closing.cpp @@ -6,7 +6,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -773,11 +773,11 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_HALF_FIN) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp b/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp index 16f54b3..890bcda 100644 --- a/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp +++ b/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp @@ -5,7 +5,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -157,11 +157,11 @@ TEST(UDP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING, TEST) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp b/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp index 1f2270c..69a7f0f 100644 --- a/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp +++ b/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp @@ -5,7 +5,7 @@ #include "packet_def.h" #include "packet_parse.h" #include "packet_layer.h" -#include "id_generator.h" +#include "snowflake.h" #include "session_utils.h" #include "session_manager.h" #include "test_packets.h" @@ -212,11 +212,11 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_S2C) int main(int argc, char **argv) { - struct id_generator_options opt = { - .snowflake_worker_id_base = 1, - .snowflake_worker_id_offset = 2, + struct snowflake_options opt = { + .snowflake_base = 1, + .snowflake_offset = 2, }; - id_generator_init(&opt); + snowflake_id_init(&opt); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/snowflake/CMakeLists.txt b/src/snowflake/CMakeLists.txt new file mode 100644 index 0000000..10da58d --- /dev/null +++ b/src/snowflake/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(snowflake snowflake.cpp) +target_include_directories(snowflake PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +target_include_directories(snowflake PUBLIC ${CMAKE_SOURCE_DIR}/src/utils) +target_include_directories(snowflake PUBLIC ${CMAKE_SOURCE_DIR}/include/stellar) +target_link_libraries(snowflake stellar_core) \ No newline at end of file diff --git a/src/snowflake/snowflake.cpp b/src/snowflake/snowflake.cpp new file mode 100644 index 0000000..bea562a --- /dev/null +++ b/src/snowflake/snowflake.cpp @@ -0,0 +1,80 @@ +#include +#include + +#include "log.h" +#include "utils.h" +#include "stellar.h" +#include "snowflake.h" + +#define snowflake_LOG_ERROR(format, ...) LOG_ERROR("snowflake", format, ##__VA_ARGS__) +#define snowflake_LOG_DEBUG(format, ...) LOG_DEBUG("snowflake", format, ##__VA_ARGS__) + +struct snowflake +{ + uint8_t snowflake_base; // 5bit [0, 31] + uint8_t snowflake_offset; // 7bit [0, 127] + uint64_t device_id; // 12bit [0, 4095] ( base << 7 | offset ) + uint64_t thread[MAX_THREAD_NUM]; +}; + +struct snowflake g_snowflake = {}; + +// return 0: success +// return -1: failed +int snowflake_id_init(const struct snowflake_options *opts) +{ + memset(&g_snowflake, 0, sizeof(struct snowflake)); + + if (opts == NULL) + { + snowflake_LOG_ERROR("opts is NULL"); + return -1; + } + + if (opts->snowflake_base > 31) + { + snowflake_LOG_ERROR("snowflake_base %u is invalid, range [0, 31]", opts->snowflake_base); + return -1; + } + + if (opts->snowflake_offset > 127) + { + snowflake_LOG_ERROR("snowflake_offset %u is invalid, range [0, 127]", opts->snowflake_offset); + return -1; + } + + g_snowflake.snowflake_base = opts->snowflake_base; + g_snowflake.snowflake_offset = opts->snowflake_offset; + g_snowflake.device_id = ((g_snowflake.snowflake_base << 7) | g_snowflake.snowflake_offset) & 0xFFF; + + snowflake_LOG_DEBUG("snowflake_base: %u, snowflake_offset: %u, device_id: %u", + g_snowflake.snowflake_base, + g_snowflake.snowflake_offset, + g_snowflake.device_id); + return 0; +} + +/* + * high -> low + * + * +------+------------------+----------------+------------------------+---------------------------+ + * | 1bit | 12bit device_id | 8bit thread_id | 28bit timestamp in sec | 15bit sequence per thread | + * +------+------------------+----------------+------------------------+---------------------------+ + */ +uint64_t snowflake_id_generate(uint64_t now_sec) +{ +#define MAX_ID_PER_THREAD (32768) +#define MAX_ID_BASE_TIME (268435456L) + + uint64_t thr_idx = (uint16_t)stellar_get_current_thread_index(); + + uint64_t global_id = 0; + uint64_t id_per_thread = (g_snowflake.thread[thr_idx]++) % MAX_ID_PER_THREAD; + uint64_t id_base_time = now_sec % MAX_ID_BASE_TIME; + global_id = (g_snowflake.device_id << 51) | + (thr_idx << 43) | + (id_base_time << 15) | + (id_per_thread); + + return global_id; +} diff --git a/src/snowflake/snowflake.h b/src/snowflake/snowflake.h new file mode 100644 index 0000000..b0b10dd --- /dev/null +++ b/src/snowflake/snowflake.h @@ -0,0 +1,23 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +struct snowflake_options +{ + uint8_t snowflake_base; + uint8_t snowflake_offset; +}; + +// return 0: success +// return -1: failed +int snowflake_id_init(const struct snowflake_options *opts); +uint64_t snowflake_id_generate(uint64_t now_sec); + +#ifdef __cplusplus +} +#endif diff --git a/src/stellar/stellar_config.cpp b/src/stellar/stellar_config.cpp index 3126424..93bf6c0 100644 --- a/src/stellar/stellar_config.cpp +++ b/src/stellar/stellar_config.cpp @@ -11,33 +11,33 @@ // return 0: success // retuun -1: failed -static int parse_id_generator_section(toml_table_t *root, struct id_generator_options *opts) +static int parse_snowflake_section(toml_table_t *root, struct snowflake_options *opts) { const char *ptr; toml_table_t *table; - table = toml_table_in(root, "id_generator"); + table = toml_table_in(root, "snowflake"); if (table == NULL) { - CONFIG_LOG_ERROR("config file missing id_generator section"); + CONFIG_LOG_ERROR("config file missing snowflake section"); return -1; } - ptr = toml_raw_in(table, "snowflake_worker_id_base"); + ptr = toml_raw_in(table, "snowflake_base"); if (ptr == NULL) { - CONFIG_LOG_ERROR("config file missing id_generator->snowflake_worker_id_base"); + CONFIG_LOG_ERROR("config file missing snowflake->snowflake_base"); return -1; } - opts->snowflake_worker_id_base = atoi(ptr); + opts->snowflake_base = atoi(ptr); - ptr = toml_raw_in(table, "snowflake_worker_id_offset"); + ptr = toml_raw_in(table, "snowflake_offset"); if (ptr == NULL) { - CONFIG_LOG_ERROR("config file missing id_generator->snowflake_worker_id_offset"); + CONFIG_LOG_ERROR("config file missing snowflake->snowflake_offset"); return -1; } - opts->snowflake_worker_id_offset = atoi(ptr); + opts->snowflake_offset = atoi(ptr); return 0; } @@ -536,7 +536,7 @@ int stellar_config_load(struct stellar_config *config, const char *file) goto error_out; } - if (parse_id_generator_section(table, &config->id_gen_opts) != 0) + if (parse_snowflake_section(table, &config->snowflake_opts) != 0) { goto error_out; } @@ -585,13 +585,13 @@ void stellar_config_print(const struct stellar_config *config) } const struct packet_io_options *pkt_io_opts = &config->pkt_io_opts; - const struct id_generator_options *id_gen_opts = &config->id_gen_opts; + const struct snowflake_options *snowflake_opts = &config->snowflake_opts; const struct ip_reassembly_options *ip_reass_opts = &config->ip_reass_opts; const struct session_manager_options *sess_mgr_opts = &config->sess_mgr_opts; - // id_generator config - CONFIG_LOG_DEBUG("id_generator->snowflake_worker_id_base : %d", id_gen_opts->snowflake_worker_id_base); - CONFIG_LOG_DEBUG("id_generator->snowflake_worker_id_offset : %d", id_gen_opts->snowflake_worker_id_offset); + // snowflake config + CONFIG_LOG_DEBUG("snowflake->snowflake_base : %d", snowflake_opts->snowflake_base); + CONFIG_LOG_DEBUG("snowflake->snowflake_offset : %d", snowflake_opts->snowflake_offset); // packet io config CONFIG_LOG_DEBUG("packet_io->mode : %s", pkt_io_opts->mode == PACKET_IO_DUMPFILE ? "dumpfile" : "marsio"); diff --git a/src/stellar/stellar_config.h b/src/stellar/stellar_config.h index 3fde27f..d4d622e 100644 --- a/src/stellar/stellar_config.h +++ b/src/stellar/stellar_config.h @@ -6,7 +6,7 @@ extern "C" #endif #include "packet_io.h" -#include "id_generator.h" +#include "snowflake.h" #include "ip_reassembly.h" #include "session_manager.h" @@ -29,7 +29,7 @@ struct schedule_options struct stellar_config { struct packet_io_options pkt_io_opts; - struct id_generator_options id_gen_opts; + struct snowflake_options snowflake_opts; struct ip_reassembly_options ip_reass_opts; struct session_manager_options sess_mgr_opts; struct schedule_options sched_opts; diff --git a/src/stellar/stellar_core.cpp b/src/stellar/stellar_core.cpp index fd87470..7ebf11f 100644 --- a/src/stellar/stellar_core.cpp +++ b/src/stellar/stellar_core.cpp @@ -15,7 +15,7 @@ #include "packet_def.h" #include "packet_utils.h" #include "session_utils.h" -#include "id_generator.h" +#include "snowflake.h" #include "stellar_stat.h" #include "stellar_core.h" #include "stellar_config.h" @@ -511,7 +511,7 @@ int stellar_run(int argc __attribute__((unused)), char **argv __attribute__((unu } stellar_config_print(config); - if (id_generator_init(&config->id_gen_opts) != 0) + if (snowflake_id_init(&config->snowflake_opts) != 0) { STELLAR_LOG_ERROR("unable to init id generator"); goto error_out; diff --git a/src/utils/utils.h b/src/utils/utils.h index d5f6c83..38514ca 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -10,7 +10,7 @@ extern "C" #include #define RX_BURST_MAX 32 -#define MAX_THREAD_NUM 256 // limit by id_generator +#define MAX_THREAD_NUM 256 // limit by snowflake #define ATOMIC_INC(x) __atomic_fetch_add(x, 1, __ATOMIC_RELAXED) #define ATOMIC_DEC(x) __atomic_fetch_sub(x, 1, __ATOMIC_RELAXED) diff --git a/test/packet_inject/conf/stellar.toml b/test/packet_inject/conf/stellar.toml index 2fa1f9d..7c5b279 100644 --- a/test/packet_inject/conf/stellar.toml +++ b/test/packet_inject/conf/stellar.toml @@ -1,6 +1,6 @@ -[id_generator] -snowflake_worker_id_base = 1 # [0, 31] -snowflake_worker_id_offset = 2 # [0, 127] +[snowflake] +snowflake_base = 1 # [0, 31] +snowflake_offset = 2 # [0, 127] [packet_io] mode = marsio # dumpfile, marsio