myxce/src/worker/include/xcecd.h
Rongsong Shen 331fa02423
feat(component-failover-adoption): fix worker startup ordering, add rejoin retry-on-failure
Thread cluster_cfg by value through xcecd_config_t -> xcecd_context_t ->
cc_ctx so it's populated before controller_connector_start() fires the
first join, instead of after xcecd_start() returns. checking_connection()
now retries a failed post-reconnect xcecli_join() on the next liveness
probe instead of leaving needs_rejoin cleared on mere attempt.
2026-08-11 06:21:36 +00:00

112 lines
3.5 KiB
C

#ifndef XCECD_H
#define XCECD_H
#include "controller_connector.h"
#include "hardware_monitor.h"
#include "job_information.h"
#include "node_information.h"
#include "process_manager.h"
#include "resource_sync.h"
#include "static_array.h"
#include "system_monitor.h"
#include "thread_pool.h"
#include "uv_ipc.h"
#include "xcecd_db.h"
#include "xcecd_dbus_manager.h"
#include "xcecd_worker_utils.h"
#include "xcectx.h"
#include "xcelog.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef _WIN32
#include <pdh.h>
#include <windows.h>
#include <winsock2.h>
typedef HANDLE process_handle_t;
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <unistd.h>
typedef pid_t process_handle_t;
#endif
#define REMOTE_PORT 6789
#define DEFAULT_PORT 0 // disable by default
#define BUFFER_SIZE 4096
#define RESTART_FLAG_FILE "/tmp/.xcecd.restarting"
typedef struct {
int thread_pool_size;
int resource_update_interval;
int job_status_update_interval;
uint16_t port;
const char* acct_file;
char* log_file;
const char* db_path;
const char* work_dir;
const char* domain_sock_file;
const char* remote_host;
const char* virutal_name;
int remote_port;
int join_interval;
int update_interval;
int domain_sock;
int debug_level;
/* HA candidate list parsed from --peers (component-failover-adoption,
* task 2.2, Req 1.4). Threaded through xcecd_init() -> xcecd_context_t
* -> controller_connector_init() so cc_ctx->cluster_cfg is populated
* before the first join, instead of main.c assigning it after
* xcecd_start() already ran. candidates_count == 0 means no --peers was
* given (single-host default). */
xce_cluster_config_t cluster_cfg;
} xcecd_config_t;
typedef struct {
thread_pool_t* thread_pool;
network_handler_t* network;
process_manager_t* process_manager;
system_monitor_t* system_monitor;
hardware_monitor_t* hardware_monitor;
resource_sync_t* resource_sync;
xcecd_worker_t* worker_list;
xcecd_db_t* db;
xce_ctx_t* xce_ctx;
bool running;
bool normal_restart;
char* remote_host;
int local_port;
int remote_port;
int update_interval;
int join_interval;
int domain_sock;
int debug_level;
char* work_dir;
char* log_dir;
char* db_path;
char* virtual_name;
/* Copied from xcecd_config_t by xcecd_init(); consumed by
* controller_connector_init() (xcecd_start()) to populate
* cc_ctx->cluster_cfg BEFORE controller_connector_start() fires the
* first join (component-failover-adoption, task 2.2, Req 1.4). */
xce_cluster_config_t cluster_cfg;
} xcecd_context_t;
extern xcecd_context_t xcecd_ctx;
extern hostattrs_t host_attrs;
int xcecd_config_init(xcecd_config_t* config);
int xcecd_init(const xcecd_config_t* config);
int xcecd_start(void);
void xcecd_stop(void);
void xcecd_cleanup(void);
void xcecd_process_command(void* arg);
const char* handle_network_request(const char* request, void* user_data);
bool xcecd_config_is_valid(const xcecd_config_t* config);
void xcecd_prepare_restart(void);
bool xcecd_check_restart_type(void);
#endif // XCECD_H