34 #include "core/os/vdso.h"
35 #include "core/os/process_utilities.h"
36 #include "core/os/thread_local_storage.h"
37 #include "core/os/hangup_signal_handler.h"
38 #include "core/os/virtual_memory.h"
40 #ifdef LLFIX_ENABLE_NUMA // VOLTRON_EXCLUDE
41 #include "core/os/numa_utilities.h"
42 #endif // VOLTRON_EXCLUDE
44 #ifdef LLFIX_ENABLE_TCPDIRECT // VOLTRON_EXCLUDE
45 #include "core/solarflare_tcpdirect/tcpdirect_api.h"
46 #endif // VOLTRON_EXCLUDE
48 #ifdef LLFIX_ENABLE_OPENSSL // VOLTRON_EXCLUDE
49 #include "core/ssl/ssl_api.h"
50 #endif // VOLTRON_EXCLUDE
52 #include "core/os/socket.h"
53 #include "core/utilities/logger.h"
54 #include "core/utilities/version.h"
55 #include "core/utilities/allocator.h"
57 #include "engine_settings.h"
59 #include "management_server/management_server_settings.h"
60 #include "management_server/management_server.h"
84 static void on_start(
const std::string& config_file_path =
"",
const std::string& config_group_name =
"ENGINE")
86 if(m_engine_initialised.load() ==
true)
91 m_application_start_timestamp = VDSO::nanoseconds_monotonic();
93 EngineSettings engine_settings;
95 if(config_file_path.length()>0)
97 if(engine_settings.load_from_config_file(config_file_path, config_group_name) ==
false)
99 fprintf(stderr,
"Failed to load %s : %s \n", config_file_path.c_str(), engine_settings.config_load_error.c_str());
104 if(engine_settings.validate() ==
false)
106 fprintf(stderr,
"llfix engine : Failed to verify %s : %s \n", config_file_path.c_str(), engine_settings.validation_error.c_str());
110 HangupSignalHandler::set_ignore(engine_settings.ignore_sighup);
112 if( Logger<>::get_instance().initialise(engine_settings.log_file, Logger<>::convert_string_to_log_level(engine_settings.log_level), engine_settings.logger_async, engine_settings.logger_buffer_capacity) ==
false)
114 fprintf(stderr,
"llfix engine : Logger initialisation failed\n");
118 if(engine_settings.numa_bind_node >= 0)
121 fprintf(stderr,
"WARNING : numa_bind_node is specified however NUMA features supported only on Linux.\n");
123 #ifdef LLFIX_ENABLE_NUMA
124 if(NumaUtilities::get_current_numa_node() == -1)
126 fprintf(stderr,
"WARNING : numa_bind_node is set however there is no NUMA node on the system, therefore it won't take affect\n");
130 if( NumaUtilities::bind_to_numa_node(engine_settings.numa_bind_node) ==
false)
132 fprintf(stderr,
"llfix engine : Failed to bind to NUMA node %d \n", engine_settings.numa_bind_node);
136 LLFIX_LOG_INFO(
"Bound NUMA node : " + std::to_string(NumaUtilities::get_current_numa_node()));
137 Allocator::set_numa_aware(engine_settings.numa_aware_allocations);
140 fprintf(stderr,
"WARNING : numa_bind_node is set however this build not built with LLFIX_ENABLE_NUMA flag, therefore it won't take affect\n");
145 if(engine_settings.lock_pages)
148 if (ProcessUtilities::has_root_privileges() ==
false)
150 fprintf(stderr,
"llfix engine : lock_pages option requires root privileges on Linux.\n");
153 auto page_lock_success = VirtualMemory::lock_all_pages();
154 LLFIX_LOG_INFO(
"VM pages locked : " + std::string( (page_lock_success?
"1":
"0") ));
158 if (ThreadLocalStorage::get_instance().create() ==
false)
160 LLFIX_LOG_ERROR(
"Failed to create thread local storage");
164 Socket<>::socket_library_initialise();
166 ManagementServerSettings management_server_settings;
168 if (management_server_settings.specified_by_user(config_file_path, config_group_name))
170 if (management_server_settings.load_from_config_file(config_file_path, config_group_name) ==
true)
172 if (management_server_settings.validate() ==
true)
174 std::filesystem::path cwd = std::filesystem::current_path();
175 std::filesystem::path full_log_path = cwd / engine_settings.log_file;
177 if (m_management_server.create(management_server_settings, m_application_start_timestamp, m_version.to_string(), full_log_path.string()))
179 m_management_server_started =
true;
180 LLFIX_LOG_INFO(
"Started management server , port : " + std::to_string(management_server_settings.management_server_port) +
" nic : " + management_server_settings.management_server_nic_ip);
184 LLFIX_LOG_ERROR(
"Failed to create management server");
189 LLFIX_LOG_ERROR(
"Failed to validate management server settings. Error : " + management_server_settings.validation_error);
194 LLFIX_LOG_INFO(
"LLFIX ENGINE Loaded config =>\n" + engine_settings.to_string());
196 #ifndef LLFIX_BUILD_CONFIG_GENERATED
197 LLFIX_LOG_INFO(
"LLFIX ENGINE LIBRARY TYPE=HEADER-ONLY , version : " + m_version.to_string());
199 LLFIX_LOG_INFO(
"LLFIX ENGINE LIBRARY TYPE=STATIC-LIB , version : " + m_version.to_string());
202 #ifdef LLFIX_ENABLE_TCPDIRECT
203 LLFIX_LOG_INFO(
"LLFIX ENGINE TCPDIRECT=ON , TCPDirect library version : " + std::string(TCPDirectApi::get_version()));
205 LLFIX_LOG_INFO(
"LLFIX ENGINE TCPDIRECT=OFF");
208 #ifdef LLFIX_ENABLE_NUMA
209 LLFIX_LOG_INFO(
"LLFIX ENGINE LIBNUMA=ON");
211 LLFIX_LOG_INFO(
"LLFIX ENGINE LIBNUMA=OFF");
214 #ifdef LLFIX_ENABLE_OPENSSL
215 LLFIX_LOG_INFO(
"LLFIX ENGINE OPENSSL=ON , OpenSSL library version : " + std::string(SSLApi::get_version()));
217 if (SSLApi::get_version_major_number() < 3)
219 LLFIX_LOG_ERROR(
"OpenSSL major version >= 3.0.0 required");
223 if ( !(SSLApi::get_version_major_number() == 3 && SSLApi::get_version_minor_number() == 6) )
225 fprintf(stderr,
"WARNING : Supported OpenSSL version is 3.6.\n");
228 LLFIX_LOG_INFO(
"LLFIX ENGINE OPENSSL=ON , OpenSSL initialisation : " + std::string(SSLApi::initialise()?
"true":
"false"));
230 LLFIX_LOG_INFO(
"LLFIX ENGINE OPENSSL=OFF");
233 #ifdef LLFIX_ENABLE_DICTIONARY
234 LLFIX_LOG_INFO(
"LLFIX ENGINE DICTIONARY=ON");
236 LLFIX_LOG_INFO(
"LLFIX ENGINE DICTIONARY=OFF");
239 #ifdef LLFIX_ENABLE_BINARY_FIELDS
240 LLFIX_LOG_INFO(
"LLFIX BINARY FIELDS SUPPORT=ON");
242 LLFIX_LOG_INFO(
"LLFIX BINARY FIELDS SUPPORT=OFF");
245 LLFIX_LOG_INFO(
"LLFIX ENGINE initialised successfully");
247 m_engine_initialised.store(
true);
259 ThreadLocalStorage::get_instance().destroy();
261 #ifdef LLFIX_ENABLE_OPENSSL
262 SSLApi::uninitialise();
265 #ifdef LLFIX_ENABLE_TCPDIRECT
266 TCPDirectApi::uninitialise();
277 if(m_management_server_stopped ==
false)
279 if (m_management_server_started ==
true)
281 LLFIX_LOG_INFO(
"Stopping management server");
282 m_management_server.stop();
284 m_management_server_stopped =
true;
295 return m_management_server;
298 static bool initialised() {
return m_engine_initialised.load(); }
299 static const Version& get_version() {
return m_version; }
300 static uint64_t get_application_start_timestamp() {
return m_application_start_timestamp; }
302 static inline Version m_version{
"1.0.4"};
303 static inline uint64_t m_application_start_timestamp = 0;
304 static inline std::atomic<bool> m_engine_initialised =
false;
306 static inline ManagementServer m_management_server;
307 static inline bool m_management_server_started =
false;
308 static inline bool m_management_server_stopped =
false;