save works

This commit is contained in:
Rongsong Shen 2026-02-28 17:55:50 +08:00
parent b1faeb94b6
commit b748e30d20
35 changed files with 1247 additions and 2149 deletions

View file

@ -1,12 +1,14 @@
#include "config.h"
#include <errno.h>
#include <rtti.h>
#include <string.h>
#include <unistd.h>
#include "cluster.h"
#include "dataq.h"
#include "htab.h"
#include "kvmgr.h"
#include "mylock.h"
#include "request.h"
#include "vtaskmgr.h"
@ -15,6 +17,7 @@
#include "xce/types.h"
#include "resobj.h"
#include "utils.h"
#include "worker.h"
#include "xce/errnox.h"
@ -368,8 +371,7 @@ int cluster_build_resources(cluster_t* c)
for (i = 0; i < c->myconf->cluster_config->nres; i++) {
xce_resource_t* res;
res = create_obj_by_typename(&(c->objmgr), "xresource",
c->myconf->cluster_config->resources[i]);
res = makeResource(c->myconf->cluster_config->resources[i]);
if (res == NULL) {
return -errno;
}
@ -458,10 +460,82 @@ static int run_delay_tasks(delay_task_entry_fn_t entry, void* arg)
return entry(arg);
}
static void res_obj_killer(xce_resource_t* r)
{
if (r == NULL) {
return;
}
}
static void job_obj_killer(void* arg)
{
if (arg == NULL) {
return;
}
}
static void worker_obj_killer(void* arg)
{
if (arg == NULL) {
return;
}
}
static void queue_obj_killer(void* arg)
{
if (arg == NULL) {
return;
}
}
static void resval_obj_killer(void* arg)
{
if (arg == NULL) {
return;
}
}
static void config_obj_killer(void* arg)
{
if (arg == NULL) {
return;
}
}
int cluster_init(cluster_t* c)
{
int i, rc;
SSL_CTX* ssl_ctx = NULL;
int i, rc;
SSL_CTX* ssl_ctx = NULL;
kvmgr_params_t config_mgr_params
= { .key_type = KVMGR_KEY_STRING,
.dynamic = 1,
.nslots = 128,
.delta = 128,
.datakiller = (destroy_fn_t)config_obj_killer };
kvmgr_params_t resmgr_params
= { .key_type = KVMGR_KEY_STRING,
.dynamic = 1,
.nslots = c->myconf->cluster_config->resmgr->nhash_slots,
.delta = c->myconf->cluster_config->resmgr->delta,
.datakiller = (destroy_fn_t)res_obj_killer };
kvmgr_params_t jobmgr_params
= { .key_type = KVMGR_KEY_INT,
.dynamic = 1,
.nslots = c->myconf->cluster_config->jobmgr->nhash_slots,
.delta = c->myconf->cluster_config->jobmgr->delta,
.datakiller = (destroy_fn_t)job_obj_killer };
kvmgr_params_t workermgr_params
= { .key_type = KVMGR_KEY_STRING,
.dynamic = 1,
.nslots = c->myconf->cluster_config->workermgr->nhash_slots,
.delta = c->myconf->cluster_config->workermgr->delta,
.datakiller = (destroy_fn_t)worker_obj_killer };
kvmgr_params_t qmgr_params
= { .key_type = KVMGR_KEY_STRING,
.dynamic = 0,
.nslots = c->myconf->cluster_config->qmgr->nhash_slots,
.delta = c->myconf->cluster_config->qmgr->delta,
.datakiller = (destroy_fn_t)queue_obj_killer };
if (c == NULL) {
return -EINVAL;
@ -491,36 +565,21 @@ int cluster_init(cluster_t* c)
return -errno;
}
kvmgr_init(&(c->configmgr), string_hash_key, 128, 128,
(zarray_item_killer_t)config_obj_killer);
c->configmgr = makeInstance(&xkvmgr_type, &config_mgr_params);
objmgr_init(&(c->objmgr));
jobmgr_init(&(c->jobmgr), c->myconf->cluster_config->jobmgr->nhash_slots,
c->myconf->cluster_config->jobmgr->delta,
(zarray_item_killer_t)job_obj_killer);
resmgr_init(&(c->resmgr), c->myconf->cluster_config->resmgr->nhash_slots,
c->myconf->cluster_config->resmgr->delta,
(zarray_item_killer_t)res_obj_killer);
c->jobmgr = makeInstance(&xkvmgr_type, &jobmgr_params);
c->resmgr = makeInstance(&xkvmgr_type, &resmgr_params);
zarray_init(&(c->sharedinst), c->myconf->cluster_config->resmgr->inst_delta,
(zarray_item_killer_t)resval_obj_killer);
workermgr_init(&(c->workermgr),
c->myconf->cluster_config->workermgr->nhash_slots,
c->myconf->cluster_config->workermgr->delta,
(zarray_item_killer_t)worker_obj_killer);
qmgr_init(&(c->qmgr), c->myconf->cluster_config->qmgr->nhash_slots,
c->myconf->cluster_config->qmgr->delta,
(zarray_item_killer_t)queue_obj_killer);
c->workermgr = makeInstance(&xkvmgr_type, &workermgr_params);
c->qmgr = makeInstance(&xkvmgr_type, &qmgr_params);
iomgr_init(&(c->iomgr));
iomgr_set_ssl_ctx(&(c->iomgr), ssl_ctx);
xstring_table_init(c->myconf->cluster_config->xstrings->nhash_slots);
register_xstring(&(c->objmgr),
c->myconf->cluster_config->xstrings->nhash_slots,
c->myconf->cluster_config->xstrings->delta);
register_types(c);
zarray_init(&(c->endpoints), 16, endpoint_killer);
rc = endpoint_init(&(c->ep), AF_INET, SOCK_STREAM,
@ -557,10 +616,8 @@ static int make_heartbeat(cluster_t* c, endpoint_t* ep)
return xce_nop_req(ep);
}
static int check_worker_timeout_(void* arg1, void* arg2)
static int check_worker_timeout_(cluster_t* c, worker_t* w)
{
cluster_t* c = (cluster_t*)arg1;
worker_t* w = (worker_t*)arg2;
worker_t* w1 = NULL;
endpoint_t* ep;
time_t now = time(NULL);
@ -581,24 +638,19 @@ static int check_worker_timeout_(void* arg1, void* arg2)
}
/* grab lock on worker */
w1 = obj_ref(w, OBJREF_UPDATE);
if (w1 == NULL) {
return -EINVAL;
}
config = c->myconf->cluster_config;
timeout = config->heartbeat_interval * config->inactive_heartbeat_count;
if (now - ep->ts_last_in > timeout) {
TRACE("%s worker %s becomes UNAVAIL as heartbeat timeout", __func__,
w->host.name);
w->host->name);
mark_worker_unavail(c, w);
obj_deref(w1);
return 0;
} else {
if (IS_WORKER_UNAVAIL(w->host.status)) {
if (IS_WORKER_UNAVAIL(w->host->status)) {
mark_worker_back(c, w);
}
}
@ -607,34 +659,49 @@ static int check_worker_timeout_(void* arg1, void* arg2)
if (DATAQ_EMPTY(&(ep->outq))) {
int rc = 0;
TRACE("%s send heartbeat to %s", __func__, w->host.name);
TRACE("%s send heartbeat to %s", __func__, w->host->name);
rc = make_heartbeat(c, ep);
if (rc < 0) {
ERROR("%s make_heartbeat to %s failed", __func__, w->host.name);
ERROR("%s make_heartbeat to %s failed", __func__,
w->host->name);
obj_deref(w1);
return rc;
}
}
}
obj_deref(w1);
return 0;
}
static int check_workers_timeout(void* args)
{
xlist_t lst;
int rc;
cluster_t* c = (cluster_t*)args;
iterator_t it;
cluster_t* c = (cluster_t*)args;
int rc = 0;
xlist_init(&lst, 3);
xlist_store(&lst, check_worker_timeout_);
rc = workermgr_iter(&(c->workermgr), &lst, c);
rc = iter_make(&it, c->workermgr);
if (rc < 0) {
return rc;
}
xlist_fini(&lst);
for (;;) {
worker_t* w = NULL;
rc = iter_next(&it, (void**)&w);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
check_worker_timeout_(c, w);
}
if (rc == RTTI_ITER_NO_DATA) {
rc = 0;
}
iter_destroy(&it);
return rc;
}
@ -698,11 +765,11 @@ void cluster_fini(cluster_t* c)
cbuf_fini(&(c->wbuf));
iomgr_fini(&(c->iomgr));
jobmgr_fini(&(c->jobmgr));
workermgr_fini(&(c->workermgr));
qmgr_fini(&(c->qmgr));
resmgr_fini(&(c->resmgr));
kvmgr_fini(&(c->configmgr));
destroy(c->jobmgr);
destroy(c->workermgr);
destroy(c->qmgr);
destroy(c->resmgr);
destroy(c->configmgr);
mylock_fini(&(c->sched.lock));
zarray_fini(&(c->endpoints));