1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

merge from tridge

(This used to be ctdb commit 8d424b41d6cf2973b28a749d1b8e6a028dad9ffe)
This commit is contained in:
Ronnie Sahlberg 2007-05-16 11:12:28 +10:00
commit 4b8ddfccad
10 changed files with 66 additions and 91 deletions

View File

@ -29,7 +29,8 @@ CTDB_COMMON_OBJ = common/ctdb.o common/ctdb_daemon.o common/ctdb_client.o \
common/ctdb_io.o common/util.o common/ctdb_util.o \
common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_lockwait.o \
common/ctdb_message.o common/cmdline.o common/ctdb_control.o \
lib/util/debug.o common/ctdb_recover.o common/ctdb_freeze.o common/ctdb_traverse.o
lib/util/debug.o common/ctdb_recover.o common/ctdb_recoverd.o \
common/ctdb_freeze.o common/ctdb_traverse.o
CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
@ -37,7 +38,7 @@ CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TCP_OBJ) $(POPT_OBJ)
OBJS = @TDB_OBJ@ @TALLOC_OBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) @EVENTS_OBJ@ $(CTDB_OBJ) $(UTIL_OBJ)
BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait bin/ctdb_control bin/ctdb_dump bin/ctdb_recoverd @INFINIBAND_BINS@
BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait bin/ctdb_control bin/ctdb_dump @INFINIBAND_BINS@
DIRS = lib bin
@ -72,10 +73,6 @@ bin/ctdb_dump: $(OBJS) tools/ctdb_dump.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ tools/ctdb_dump.o $(OBJS) $(LIB_FLAGS)
bin/ctdb_recoverd: $(OBJS) direct/ctdb_recoverd.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ direct/ctdb_recoverd.o $(OBJS) $(LIB_FLAGS)
bin/ctdbd_test: $(OBJS) direct/ctdbd_test.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ direct/ctdbd_test.o

View File

@ -38,7 +38,6 @@ static struct {
int torture;
const char *logfile;
const char *events;
int recovery_daemon;
} ctdb_cmdline = {
.nlist = NULL,
.transport = "tcp",
@ -48,7 +47,6 @@ static struct {
.db_dir = NULL,
.torture = 0,
.logfile = NULL,
.recovery_daemon = 0,
};
enum {OPT_EVENTSYSTEM=1};
@ -73,7 +71,6 @@ struct poptOption popt_ctdb_cmdline[] = {
{ "socket", 0, POPT_ARG_STRING, &ctdb_cmdline.socketname, 0, "local socket name", "filename" },
{ "transport", 0, POPT_ARG_STRING, &ctdb_cmdline.transport, 0, "protocol transport", NULL },
{ "self-connect", 0, POPT_ARG_NONE, &ctdb_cmdline.self_connect, 0, "enable self connect", "boolean" },
{ "recovery-daemon", 0, POPT_ARG_NONE, &ctdb_cmdline.recovery_daemon, 0, "enable recovery daemon", "boolean" },
{ "debug", 'd', POPT_ARG_INT, &LogLevel, 0, "debug level"},
{ "dbdir", 0, POPT_ARG_STRING, &ctdb_cmdline.db_dir, 0, "directory for the tdb files", NULL },
{ "torture", 0, POPT_ARG_NONE, &ctdb_cmdline.torture, 0, "enable nastiness in library", NULL },
@ -115,9 +112,6 @@ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev)
if (ctdb_cmdline.torture) {
ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE);
}
if (ctdb_cmdline.recovery_daemon) {
ctdb_set_flags(ctdb, CTDB_FLAG_RECOVERY);
}
ret = ctdb_set_transport(ctdb, ctdb_cmdline.transport);
if (ret == -1) {

View File

@ -735,6 +735,12 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
block_signal(SIGPIPE);
block_signal(SIGCHLD);
/* start the recovery daemon process */
if (ctdb_start_recoverd(ctdb) != 0) {
DEBUG(0,("Failed to start recovery daemon\n"));
exit(11);
}
/* ensure the socket is deleted on exit of the daemon */
domain_socket_name = talloc_strdup(talloc_autofree_context(), ctdb->daemon.name);
talloc_set_destructor(domain_socket_name, unlink_destructor);
@ -743,14 +749,6 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
ctdb_accept_client, ctdb);
/* start the recovery daemon */
if (ctdb->flags & CTDB_FLAG_RECOVERY) {
char cmdstr[256];
sprintf(cmdstr, "ctdb_recoverd --socket=%s &",domain_socket_name);
system(cmdstr);
}
ctdb_main_loop(ctdb);
return 0;

View File

@ -170,9 +170,11 @@ static void queue_io_write(struct ctdb_queue *queue)
}
if (n == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
talloc_free(queue->fde);
queue->fde = NULL;
queue->fd = -1;
event_add_timed(queue->ctdb->ev, queue, timeval_zero(),
queue_dead, queue);
EVENT_FD_NOT_WRITEABLE(queue->fde);
return;
}
if (n <= 0) return;
@ -232,6 +234,9 @@ int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length)
!(queue->ctdb->flags & CTDB_FLAG_TORTURE)) {
ssize_t n = write(queue->fd, data, length2);
if (n == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
talloc_free(queue->fde);
queue->fde = NULL;
queue->fd = -1;
event_add_timed(queue->ctdb->ev, queue, timeval_zero(),
queue_dead, queue);
/* yes, we report success, as the dead node is

View File

@ -29,17 +29,6 @@
static int timed_out = 0;
/*
show usage message
*/
static void usage(void)
{
printf(
"Usage: recoverd\n"
);
exit(1);
}
static void timeout_func(struct event_context *ev, struct timed_event *te,
struct timeval t, void *private_data)
{
@ -320,7 +309,7 @@ static int update_vnnmap_on_all_nodes(struct ctdb_context *ctdb, struct ctdb_nod
}
static int do_recovery(struct ctdb_context *ctdb, struct event_context *ev,
static int do_recovery(struct ctdb_context *ctdb,
TALLOC_CTX *mem_ctx, uint32_t vnn, uint32_t num_active,
struct ctdb_node_map *nodemap, struct ctdb_vnn_map *vnnmap)
{
@ -572,7 +561,7 @@ static void force_election(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, uint3
}
void monitor_cluster(struct ctdb_context *ctdb, struct event_context *ev)
void monitor_cluster(struct ctdb_context *ctdb)
{
uint32_t vnn, num_active, recmode, recmaster;
TALLOC_CTX *mem_ctx=NULL;
@ -597,7 +586,7 @@ again:
timed_out = 0;
event_add_timed(ctdb->ev, mem_ctx, timeval_current_ofs(1, 0), timeout_func, ctdb);
while (!timed_out) {
event_loop_once(ev);
event_loop_once(ctdb->ev);
}
@ -696,7 +685,7 @@ again:
}
if (recmode!=CTDB_RECOVERY_NORMAL) {
DEBUG(0, (__location__ " Node:%d was in recovery mode. Restart recovery process\n", nodemap->nodes[j].vnn));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
}
@ -724,7 +713,7 @@ again:
*/
if (remote_nodemap->num != nodemap->num) {
DEBUG(0, (__location__ " Remote node:%d has different node count. %d vs %d of the local node\n", nodemap->nodes[j].vnn, remote_nodemap->num, nodemap->num));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
@ -735,7 +724,7 @@ again:
if ((remote_nodemap->nodes[i].vnn != nodemap->nodes[i].vnn)
|| (remote_nodemap->nodes[i].flags != nodemap->nodes[i].flags)) {
DEBUG(0, (__location__ " Remote node:%d has different nodemap.\n", nodemap->nodes[j].vnn));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
}
@ -748,7 +737,7 @@ again:
*/
if (vnnmap->size != num_active) {
DEBUG(0, (__location__ " The vnnmap count is different from the number of active nodes. %d vs %d\n", vnnmap->size, num_active));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
@ -770,7 +759,7 @@ again:
}
if (i==vnnmap->size) {
DEBUG(0, (__location__ " Node %d is active in the nodemap but did not exist in the vnnmap\n", nodemap->nodes[j].vnn));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
}
@ -796,14 +785,14 @@ again:
/* verify the vnnmap generation is the same */
if (vnnmap->generation != remote_vnnmap->generation) {
DEBUG(0, (__location__ " Remote node %d has different generation of vnnmap. %d vs %d (ours)\n", nodemap->nodes[j].vnn, remote_vnnmap->generation, vnnmap->generation));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
/* verify the vnnmap size is the same */
if (vnnmap->size != remote_vnnmap->size) {
DEBUG(0, (__location__ " Remote node %d has different size of vnnmap. %d vs %d (ours)\n", nodemap->nodes[j].vnn, remote_vnnmap->size, vnnmap->size));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
@ -811,7 +800,7 @@ again:
for (i=0;i<vnnmap->size;i++) {
if (remote_vnnmap->map[i] != vnnmap->map[i]) {
DEBUG(0, (__location__ " Remote node %d has different vnnmap.\n", nodemap->nodes[j].vnn));
do_recovery(ctdb, ev, mem_ctx, vnn, num_active, nodemap, vnnmap);
do_recovery(ctdb, mem_ctx, vnn, num_active, nodemap, vnnmap);
goto again;
}
}
@ -821,68 +810,58 @@ again:
}
/*
main program
*/
int main(int argc, const char *argv[])
static void ctdb_recoverd_parent(struct event_context *ev, struct fd_event *fde,
uint16_t flags, void *private_data)
{
DEBUG(0,("recovery daemon parent died - exiting\n"));
_exit(1);
}
int ctdb_start_recoverd(struct ctdb_context *ctdb)
{
struct ctdb_context *ctdb;
struct poptOption popt_options[] = {
POPT_AUTOHELP
POPT_CTDB_CMDLINE
POPT_TABLEEND
};
int opt;
const char **extra_argv;
int extra_argc = 0;
int ret;
poptContext pc;
struct event_context *ev;
uint64_t srvid;
int fd[2];
pid_t child;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
default:
fprintf(stderr, "Invalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
exit(1);
}
if (pipe(fd) != 0) {
return -1;
}
/* setup the remaining options for the main program to use */
extra_argv = poptGetArgs(pc);
if (extra_argv) {
extra_argv++;
while (extra_argv[extra_argc]) extra_argc++;
child = fork();
if (child == -1) {
return -1;
}
#if 0
if (extra_argc < 1) {
usage();
if (child != 0) {
close(fd[0]);
return 0;
}
#endif
close(fd[1]);
event_add_fd(ctdb->ev, ctdb, fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
ctdb_recoverd_parent, &fd[0]);
close(ctdb->daemon.sd);
ctdb->daemon.sd = -1;
srandom(getpid() ^ time(NULL));
ev = event_context_init(NULL);
/* initialise ctdb */
ctdb = ctdb_cmdline_client(ev);
if (ctdb == NULL) {
ret = ctdb_socket_connect(ctdb);
if (ret != 0) {
DEBUG(0, (__location__ " Failed to init ctdb\n"));
exit(1);
}
/* register a message port for recovery elections */
srvid = CTDB_SRVTYPE_RECOVERY;
srvid <<= 32;
ctdb_set_message_handler(ctdb, srvid, election_handler, NULL);
monitor_cluster(ctdb);
monitor_cluster(ctdb, ev);
return ret;
DEBUG(0,("ERROR: ctdb_recoverd finished!?\n"));
return -1;
}

View File

@ -51,8 +51,6 @@ struct ctdb_call_info {
*/
#define CTDB_FLAG_SELF_CONNECT (1<<0)
#define CTDB_FLAG_TORTURE (1<<1)
#define CTDB_FLAG_RECOVERY (1<<2)
/*
a message handler ID meaning "give me all messages"

View File

@ -799,4 +799,6 @@ void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_contr
int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
int ctdb_start_recoverd(struct ctdb_context *ctdb);
#endif

View File

@ -49,9 +49,7 @@ void ctdb_tcp_tnode_cb(uint8_t *data, size_t cnt, void *private_data)
/* start a new connect cycle to try to re-establish the
link */
close(tnode->fd);
ctdb_queue_set_fd(tnode->queue, -1);
tnode->fd = -1;
event_add_timed(node->ctdb->ev, node, timeval_zero(),
ctdb_tcp_node_connect, node);
}
@ -84,6 +82,7 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f
talloc_free(fde);
setsockopt(tnode->fd,IPPROTO_TCP,TCP_NODELAY,(char *)&one,sizeof(one));
setsockopt(tnode->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one));
ctdb_queue_set_fd(tnode->queue, tnode->fd);
@ -157,6 +156,7 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
errno != EINPROGRESS) {
/* try again once a second */
close(tnode->fd);
tnode->fd = -1;
event_add_timed(ctdb->ev, node, timeval_current_ofs(1, 0),
ctdb_tcp_node_connect, node);
return;
@ -181,6 +181,7 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde,
socklen_t len;
int fd;
struct ctdb_incoming *in;
int one = 1;
ctdb = talloc_get_type(private_data, struct ctdb_context);
ctcp = talloc_get_type(ctdb->private_data, struct ctdb_tcp);
@ -195,6 +196,8 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde,
set_nonblocking(in->fd);
setsockopt(in->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one));
in->queue = ctdb_queue_setup(ctdb, in, in->fd, CTDB_TCP_ALIGNMENT,
ctdb_tcp_read_cb, in);
}

View File

@ -1,7 +1,6 @@
#!/bin/sh
killall -q ctdbd
killall -q ctdb_recoverd
echo "Starting 4 ctdb daemons"
bin/ctdbd --recovery-daemon --nlist direct/4nodes.txt

View File

@ -1,6 +1,6 @@
#!/bin/sh
CTDB_CONTROL=./bin/ctdb_control
CTDB_CONTROL="./bin/ctdb_control"
export CTDB_CONTROL
$CTDB_CONTROL getnodemap 0 | egrep "^vnn:" | sed -e "s/^vnn://" -e "s/ .*$//" | while read NODE; do