DEBUG(3,("ctdb_connect_wait: got all %d nodes\n", expected));
}
--/*
-- wait until we're the only node left
--*/
--void ctdb_wait_loop(struct ctdb_context *ctdb)
--{
-- int expected = 0;
-- if (ctdb->flags & CTDB_FLAG_SELF_CONNECT) {
-- expected++;
-- }
-- while (ctdb->num_connected > expected) {
-- event_loop_once(ctdb->ev);
-- }
--}
--
--
/*
queue a packet or die
*/
state->state = CTDB_FETCH_LOCK_DONE;
}
++/*
++ called in the client when we receive a CTDB_REPLY_SHUTDOWN from the daemon
++
++ This packet comes in response to a CTDB_REQ_SHUTDOWN request packet. It
++ contains any reply data from the call
++*/
++void ctdb_reply_shutdown(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
++{
++ printf("daemon:%d has completed shutdown. client will now terminate\n",ctdb_get_vnn(ctdb));
++ talloc_free(ctdb);
++
++ exit(10);
++}
++
/*
this is called in the client, when data comes in from the daemon
*/
ctdb_reply_fetch_lock(ctdb, hdr);
break;
++ case CTDB_REPLY_SHUTDOWN:
++ ctdb_reply_shutdown(ctdb, hdr);
++ break;
++
default:
DEBUG(0,("bogus operation code:%d\n",hdr->operation));
}
{
return ctdb_ltdb_store(h->ctdb_db, h->key, &h->header, data);
}
++
++/*
++ wait until we're the only node left.
++ this function never returns
++*/
++void ctdb_shutdown(struct ctdb_context *ctdb)
++{
++ struct ctdb_req_shutdown r;
++ int len;
++
++ /* if the domain socket is not yet open, open it */
++ if (ctdb->daemon.sd==-1) {
++ ux_socket_connect(ctdb);
++ }
++
++ len = sizeof(struct ctdb_req_shutdown);
++ ZERO_STRUCT(r);
++ r.hdr.length = len;
++ r.hdr.ctdb_magic = CTDB_MAGIC;
++ r.hdr.ctdb_version = CTDB_VERSION;
++ r.hdr.operation = CTDB_REQ_SHUTDOWN;
++ r.hdr.reqid = 0;
++
++ ctdb_client_queue_pkt(ctdb, &(req.hdr));
++
++ /* this event loop will terminate once we receive the reply */
++ while (1) {
++ event_loop_once(ctdb->ev);
++ }
++}
++
++
talloc_free(state);
}
++/*
++ called when the daemon gets a shutdown request from a client
++ */
++static void daemon_request_shutdown(struct ctdb_client *client,
++ struct ctdb_req_shutdown *f)
++{
++ struct ctdb_req_finished r;
++ int len;
++ uint32_t node;
++
++ len = sizeof(struct ctdb_req_finished);
++ ZERO_STRUCT(r);
++ r.hdr.length = len;
++ r.hdr.ctdb_magic = CTDB_MAGIC;
++ r.hdr.ctdb_version = CTDB_VERSION;
++ r.hdr.operation = CTDB_REQ_FINISHED;
++ r.hdr.srcnode = ctdb->vnn;
++ r.hdr.reqid = 0;
++
++ /* loop over all nodes of the cluster */
++ for (node=0; node<ctdb_num_nodes;node++) {
++ r.hdr.destnode = node;
++ ctdb_queue_packet(ctdb, &r->hdr);
++ }
++
++ /* send a shutdown reply back to the client */
++
++}
++
/*
called when the daemon gets a fetch lock request from a client
*/
case CTDB_REQ_FETCH_LOCK:
daemon_request_fetch_lock(client, (struct ctdb_req_fetch_lock *)hdr);
break;
++ case CTDB_REQ_SHUTDOWN:
++ daemon_request_shutdown(client, (struct ctdb_req_shutdown *)hdr);
++ break;
default:
DEBUG(0,(__location__ " daemon: unrecognized operation %d\n",
hdr->operation));
void ctdb_connect_wait(struct ctdb_context *ctdb);
/*
-- wait until we're the only node left
++ initiate an ordered ctdb cluster shutdown
++ this function will never return
*/
--void ctdb_wait_loop(struct ctdb_context *ctdb);
++void ctdb_shutdown(struct ctdb_context *ctdb);
/* return vnn of this node */
uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
CTDB_REPLY_CONNECT_WAIT = 1002,
CTDB_REQ_FETCH_LOCK = 1003,
CTDB_REPLY_FETCH_LOCK = 1004,
++ CTDB_REQ_SHUTDOWN = 1005,
++ CTDB_REPLY_SHUTDOWN = 1006,
};
#define CTDB_MAGIC 0x43544442 /* CTDB */
uint8_t data[1];
};
+ struct ctdb_req_finished {
+ struct ctdb_req_header hdr;
+ };
+
++struct ctdb_req_shutdown {
++ struct ctdb_req_header hdr;
++};
++
++struct ctdb_reply_shutdown {
++ struct ctdb_req_header hdr;
++};
++
struct ctdb_req_connect_wait {
struct ctdb_req_header hdr;
};
talloc_free(call.reply_data.dptr);
/* go into a wait loop to allow other nodes to complete */
-- ctdb_wait_loop(ctdb);
-
- /*talloc_report_full(ctdb, stdout);*/
-
- /* sleep for a while so that our daemon will remaining alive for the other nodes in the cluster */
- sleep(10);
++ ctdb_shutdown(ctdb);
-- /* shut it down */
-- talloc_free(ctdb);
return 0;
}