forked from lei.chen/myxce
add kiro skills
This commit is contained in:
parent
e5fde7b55f
commit
86fe35e671
53 changed files with 8406 additions and 166 deletions
|
|
@ -32,12 +32,14 @@ static int handle_client_join(cluster_t* c, endpoint_t* ep,
|
|||
static int handle_worker_join(cluster_t* c, endpoint_t* ep,
|
||||
xce_request_t* request)
|
||||
{
|
||||
int idx;
|
||||
ep_private_t* priv = (ep_private_t*)ep->data;
|
||||
xce_reply_t reply;
|
||||
xce_peerinfo_t* from = request->from;
|
||||
int rc = 0;
|
||||
xce_joindata_t* joinmsg = NULL;
|
||||
int idx = 0;
|
||||
ep_private_t* priv = (ep_private_t*)ep->data;
|
||||
xce_reply_t reply;
|
||||
xce_peerinfo_t* from = request->from;
|
||||
int rc = 0;
|
||||
xce_joindata_t* joinmsg = NULL;
|
||||
worker_t* w = NULL;
|
||||
xce_hostconfig_t* hconfig = NULL;
|
||||
|
||||
TRACE("%s worker %s joining...", __func__, from->name);
|
||||
|
||||
|
|
@ -45,54 +47,70 @@ static int handle_worker_join(cluster_t* c, endpoint_t* ep,
|
|||
|
||||
if (!validate_host(c, from->name, from->key)) {
|
||||
ERROR("%s reject join of host %s", __func__, from->name);
|
||||
rc = -EPERM;
|
||||
|
||||
rc = -EPERM;
|
||||
reply.status = rc;
|
||||
reply.data_which = RequestReply_data_nodata;
|
||||
|
||||
xce_reply(ep, c->myhost, &reply);
|
||||
return rc;
|
||||
}
|
||||
|
||||
joinmsg = request->body.joinmsg;
|
||||
|
||||
lock(c->workermgr, RTTI_LOCK_WRITE);
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_WORKER_JOIN, c, from->name, 0);
|
||||
idx = add_worker(c, ep, from->name, joinmsg->data.attrs);
|
||||
|
||||
/* A worker recovered from WAL already occupies the slot (status=UNAVAIL).
|
||||
* Reconnecting after a controller restart will fail add_worker with -EEXIST.
|
||||
* Locate the existing slot, update its endpoint, and clear UNAVAIL. */
|
||||
if (idx == -EEXIST) {
|
||||
worker_t* existing = NULL;
|
||||
if (key_find(c->workermgr, (void*)from->name, (void**)&existing) > 0 &&
|
||||
existing != NULL) {
|
||||
lock(existing, RTTI_LOCK_WRITE);
|
||||
existing->ep = ep;
|
||||
existing->host.status &= ~XCE_WORKER_UNAVAIL;
|
||||
idx = existing->idx;
|
||||
unlock(existing);
|
||||
}
|
||||
/* Fail fast before any lock: reject if no hostconfig matches (req 4.4) */
|
||||
hconfig = find_matched_hostconfig(c, from->name);
|
||||
if (hconfig == NULL) {
|
||||
rc = (errno != 0) ? -errno : -EINVAL;
|
||||
reply.status = rc;
|
||||
reply.data_which = RequestReply_data_nodata;
|
||||
xce_reply(ep, c->myhost, &reply);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* BEFORE_EVENT fires before the existence check (req 5.1) */
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_WORKER_JOIN, c, from->name, (worker_t*)NULL);
|
||||
|
||||
/* Explicit existence check under brief READ lock (req 1.1) */
|
||||
lock(c->workermgr, RTTI_LOCK_READ);
|
||||
rc = key_find(c->workermgr, (void*)from->name, (void**)&w);
|
||||
if (w != NULL)
|
||||
reference(w);
|
||||
unlock(c->workermgr);
|
||||
|
||||
if (rc < 0 && rc != -ENOENT) {
|
||||
/* Non-ENOENT error: reject join (req 1.3) */
|
||||
ERROR("%s workermgr lookup error for %s, rc %d", __func__, from->name, rc);
|
||||
idx = rc;
|
||||
} else if (w == NULL) {
|
||||
/* Host not yet registered: first-time join (req 1.2, req 2) */
|
||||
idx = init_worker(c, ep, from->name, joinmsg->data.attrs, hconfig);
|
||||
if (idx < 0)
|
||||
ERROR("%s host %s first join failed, rc %d", __func__, from->name, -idx);
|
||||
} else {
|
||||
/* Host already registered: rejoin (req 1.2, req 3) */
|
||||
idx = rejoin_worker(c, w, ep, joinmsg->data.attrs, hconfig);
|
||||
dereference(w);
|
||||
w = NULL;
|
||||
if (idx < 0)
|
||||
ERROR("%s host %s rejoin failed, rc %d", __func__, from->name, -idx);
|
||||
}
|
||||
|
||||
/* Look up worker for AFTER_EVENT persist hook (w is NULL on error) */
|
||||
if (idx >= 0)
|
||||
vget(c->workermgr, idx, (void**)&w);
|
||||
|
||||
/* AFTER_EVENT fires after create/update, outside any lock (req 5.1) */
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_WORKER_JOIN, c, from->name, w);
|
||||
|
||||
reply.status = idx;
|
||||
reply.data_which = RequestReply_data_nodata;
|
||||
|
||||
/* Look up the worker so the persist hook can serialize it */
|
||||
worker_t* w = NULL;
|
||||
if (idx >= 0)
|
||||
vget(c->workermgr, idx, (void**)&w);
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_WORKER_JOIN, c, w);
|
||||
xce_reply(ep, c->myhost, &reply);
|
||||
unlock(c->workermgr);
|
||||
if (idx < 0) {
|
||||
ERROR("worker %s join failed, rc %d", from->name, idx);
|
||||
|
||||
if (idx < 0)
|
||||
return idx;
|
||||
}
|
||||
|
||||
/* Set priv->u.idx before on_worker_join (req 2.3, req 5.2) */
|
||||
priv->u.idx = idx;
|
||||
on_worker_join(c, ep);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue