merge job rusage and pending reason support

This commit is contained in:
Rongsong Shen 2025-12-16 14:36:28 +08:00
parent 30824ae5ea
commit cb0c7fe9e7
82 changed files with 4280 additions and 2561 deletions

View file

@ -52,8 +52,10 @@ int xcecd_job_ckpted(uint64_t jobid, int status, const char* info);
int xcecd_job_remote_start(uint64_t jobid, const char* hostname,
const char* command);
const cc_callbacks_t* get_cc_callbacks(void);
int xcecd_task_fail(uint64_t jobid, int clientidx, int taskidx, int code);
int xcecd_jobpost_done(uint64_t jobid);
int xcecd_notify_job_fail(uint64_t jobid, int stage, int code);
int xcecd_task_fail(uint64_t jobid, int clientidx, int taskidx, int code);
int xcecd_jobpost_done(uint64_t jobid);
int xcecd_notify_job_fail(uint64_t jobid, int stage, int code);
int xcecd_jobrusage_update(xce_job_rusages_t* rusages);
bool xcecd_send_load_indices(xce_resval_t** vals, int count);
#endif // CONTROL_CONNECTOR_H

View file

@ -18,99 +18,23 @@
#define DEFAULT_AFTER_HOUR "19:00-7:00 5:19:00-1:7:00"
struct time_window {
char* window_name; // 窗口名称
char* window_name;
windows_t* week[8];
time_t window_edge;
};
struct node_status {
short node_id; // 节点ID
int max_cpu_cores; // CPU核心数
int max_memory; // 内存大小
int num_disk; // 磁盘数量
int max_swap; // 交换空间大小
int max_network; // 网络带宽
unsigned short port_number; // 端口号
char node_type[MAXXCENAMELEN]; // 节点类型
char node_arch[MAXXCENAMELEN]; // 节点架构
};
typedef struct host_node host_node_t;
struct host_node {
char* node_name; // 节点名称
short node_number; // 节点编号
short node_model_number; // 节点型号编号
short node_type_number; // 节点类型编号
in_addr_t* node_ip; // 节点IP地址
struct node_status node_status; // 节点状态
char info_valid; // 信息是否有效
unsigned char protocol_version; // 协议版本
short available_high; // 高可用性
short available_low; // 低可用性
short use; // 使用情况
char* windows; // 时间窗口
windows_t* week[8]; // 一周的时间窗口
time_t window_edge; // 时间窗口边界
time_t last_jack_time; // 最后一次插入时间
int node_inactivity_count; // 节点不活动计数
int* status; // 状态
float* busy_threshold; // 繁忙阈值
float* load_index; // 负载指数
float* user_load_index; // 用户负载指数
int info_mask; // 信息掩码
int load_mask; // 负载掩码
int* resource_bitmap; // 资源位图
int* dynamic_resource_bitmap; // 动态资源位图
int number_of_instances; // 实例数量
host_node_t* next; // 下一个节点
time_t expire_time; // 过期时间
uint8_t migrant;
};
struct cluster_node {
short cluster_number; // 集群编号
char* cluster_name; // 集群名称
int status; // 状态
in_addr_t candidate_address_list[MAXCANDHOSTS]; // 候选地址列表
char* primary_node_name; // 主节点名称
unsigned short primary_address; // 主地址
unsigned short primary_port; // 主端口
char primary_known; // 主节点可识别
int primary_inactivity_count; // 主节点不活动计数
host_node_t* primary_pointer; // 主节点指针
host_node_t* previous_primary_pointer; // 上一个主节点指针
unsigned short checksum; // 校验和
int number_of_nodes; // 节点数量
int number_of_clients; // 客户端数量
host_node_t* node_list; // 节点列表
host_node_t* client_list; // 客户端列表
int manager_id; // 管理器ID
char* manager_name; // 管理器名称
int channel_fd; // 通道文件描述符
int number_of_index; // 索引数量
int number_of_user_index; // 用户索引数量
int user_index_class; // 用户索引类
char** load_index_names; // 负载指数名称
int number_of_admins; // 管理员数量
int* admin_ids; // 管理员ID
char** admin_names; // 管理员名称
int number_of_resouces; // 资源数量
int* resource_bitmaps; // 资源位图
int* hosttype_bitmaps; // 主机类型位图
int* hostmodel_bitmaps; // 主机模型位图
int number_of_shared_resources; // 共享资源数量
char** shared_resources; // 共享资源
struct cluster_node* next;
};
// client_node 和 minSLimConfData 数据结构需要添加吗?
host_node_t* host_node_create(void);
int host_node_update(host_node_t* node_ptr, host_node_t* new_node);
void free_host_node(host_node_t* node_ptr);
int get_cpu_usage(int total_cores, int used_cores);
char* node_info_get_15s(void);
char* node_info_get_1m(void);
char* node_info_get_15m(void);
char* node_info_get_ut(void);
char* node_info_get_pg(void);
char* node_info_get_ls(void);
char* node_info_get_it(void);
char* node_info_get_swap(void);
char* node_info_get_mem(void);
char* node_info_get_tmp(void);
char* node_info_get_io(void);
#endif // NODE_INFORMATION_H_

View file

@ -1,29 +1,22 @@
#ifndef RESOURCE_SYNC_H
#define RESOURCE_SYNC_H
#include "hardware_monitor.h"
#include "node_information.h"
#include <stdbool.h>
// 资源同步模块结构体
typedef struct resource_sync resource_sync_t;
// 创建资源同步模块
resource_sync_t* resource_sync_create(void);
// 销毁资源同步模块
void resource_sync_destroy(resource_sync_t* sync);
// 启动资源同步模块
bool resource_sync_start(resource_sync_t* sync);
// 停止资源同步模块
void resource_sync_stop(resource_sync_t* sync);
// 更新资源同步模块
bool resource_sync_update(resource_sync_t* sync);
// 读取资源同步模块
void resource_sync_read(resource_sync_t* sync, host_node_t** node);
#ifndef RESOURCE_SYNC_H
#define RESOURCE_SYNC_H
#include "hardware_monitor.h"
#include "node_information.h"
#include <stdbool.h>
typedef struct resource_sync resource_sync_t;
resource_sync_t* resource_sync_create(void);
void resource_sync_destroy(resource_sync_t* sync);
bool resource_sync_start(resource_sync_t* sync);
void resource_sync_stop(resource_sync_t* sync);
bool resource_sync_update(resource_sync_t* sync);
void resource_sync_read(resource_sync_t* sync, void* data);
bool resource_sync_register_load_index(const char* name, int valtype,
char* (*getter_func)(void),
bool is_builtin);
bool resource_sync_unregister_load_index(const char* name);
#endif // RESOURCE_SYNC_H

View file

@ -11,12 +11,13 @@
extern "C" {
#endif
#define HOSTNAME_LENGTH 256
#define MESSAGE_LENGTH 256
#define COMMAND_LENGTH 4096
#define METHOD_LENGTH 64
#define PATH_LENGTH 1024
#define EXDATA_LENGTH 16 * 1024
#define HOSTNAME_LENGTH 256
#define MESSAGE_LENGTH 256
#define COMMAND_LENGTH 4096
#define METHOD_LENGTH 64
#define PATH_LENGTH 1024
#define EXDATA_LENGTH 16 * 1024
#define MAX_RUSAGE_PAYLOAD 4096
typedef enum {
MSG_GET_JOB,
@ -30,10 +31,22 @@ typedef enum {
MSG_JOB_CKPT_RESULT,
MSG_REMOTE_START_JOB,
MSG_REMOTE_START_JOB_ACK,
MSG_JOB_RUSAGES,
MSG_HEARTBEAT,
MSG_ERROR
} message_type_t;
/**
* @brief IPC rusage message structure
* As rusage data is variable-sized, we define a maximum payload size.
* This structure will be serialized and sent.
*/
typedef struct {
uint64_t job_id;
size_t payload_size;
char payload[MAX_RUSAGE_PAYLOAD];
} ipc_job_rusages_t;
typedef struct {
int type;
} heartbeat_message_t;
@ -103,6 +116,7 @@ typedef struct {
job_ckpt_result_t ckpt_result;
remote_start_job_t remote_start;
remote_start_job_ack_t remote_start_ack;
ipc_job_rusages_t rusages;
char error_message[MESSAGE_LENGTH];
} data;
int worker_pid;
@ -129,6 +143,7 @@ typedef void (*job_ckpt_callback_t)(uint64_t job_id, int kill,
const char* method);
typedef void (*job_ckpt_result_callback_t)(uint64_t job_id, int status,
const char* restore_cmd);
typedef void (*job_rusages_callback_t)(xce_job_rusages_t* rusages);
bool ipc_master_init(const char* socket_path);
void ipc_master_run(uv_run_mode mode);
@ -141,6 +156,7 @@ bool ipc_master_send_job_signal(uint64_t job_id, int signal, bool force);
bool ipc_master_send_job_ckpt(uint64_t job_id, int kill, const char* method);
void ipc_master_set_ckpt_callback(job_ckpt_callback_t callback);
void ipc_master_set_ckpt_result_callback(job_ckpt_result_callback_t callback);
void ipc_master_set_rusages_callback(job_rusages_callback_t callback);
bool ipc_worker_init(const char* socket_path);
void ipc_worker_connect(connection_callback_t callback);
@ -160,6 +176,7 @@ bool ipc_worker_send_ckpt_ack(uint64_t job_id, int kill, const char* method);
void ipc_worker_set_ckpt_callback(job_ckpt_callback_t callback);
bool ipc_worker_send_ckpt_result(uint64_t job_id, int status,
const char* restore_cmd);
bool ipc_worker_send_rusages(xce_job_rusages_t* rusages);
void on_write_complete(uv_write_t* req, int status);

View file

@ -92,7 +92,6 @@ int xcecd_init(const xcecd_config_t* config);
int xcecd_start(void);
void xcecd_stop(void);
void xcecd_cleanup(void);
int send_status_and_receive_tasks(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);

View file

@ -1,6 +1,7 @@
#ifndef _XCECD_CGROUPS_H_
#define _XCECD_CGROUPS_H_
#include "xcecd_utils.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@ -93,4 +94,13 @@ int get_systemd_job_exit_code(const char* unit_name);
*/
char* get_systemd_job_status_text(const char* unit_name);
/**
* @brief Collect resource usage statistics for a systemd job.
* @param job_id The ID of the job.
* @return A pointer to an xce_job_rusages_t struct, or NULL on failure.
* The caller is responsible for freeing the returned struct
* using free_xce_job_rusages().
*/
xce_job_rusages_t* collect_job_rusages(uint64_t job_id);
#endif // _XCECD_CGROUPS_H_

View file

@ -1,8 +1,7 @@
#ifndef _XCECD_EXDATA_H
#define _XCECD_EXDATA_H
#include <cjson/cJSON.h>
#include "cjson/cJSON.h"
#include "xcecd_cgroups.h"
#include <stdbool.h>
#include <stdint.h>