1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

create a standalone ctdb daemon and a script ./direct/ctdbd.sh to start two such daemons in a 2 node cluster.

create a small test application that connects to the ctdb daemon at /tmp/ctdb.socket.127.0.0.1 and do some commands to the daemon.
currently this test tool only opens the socket and registers its pid with the daemon
(the daemon needs to know the pid so that it can forward messages to the correct client)

the test will be extended with additional ctdb commands

(This used to be ctdb commit 801f6127cdd50c5b2d0e64dd8db08500af9dadc9)
This commit is contained in:
Ronnie sahlberg 2007-04-11 18:54:22 +10:00
parent a7a1de7bf2
commit 4b6fbe7be1
6 changed files with 241 additions and 1 deletions

View File

@ -30,7 +30,7 @@ CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TCP_OBJ)
OBJS = @TDBOBJ@ @TALLOCOBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) $(EVENTS_OBJ) $(CTDB_OBJ) OBJS = @TDBOBJ@ @TALLOCOBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) $(EVENTS_OBJ) $(CTDB_OBJ)
BINS = bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch @INFINIBAND_BINS@ BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch @INFINIBAND_BINS@
DIRS = lib bin DIRS = lib bin
@ -53,6 +53,14 @@ bin/ctdb_test: $(OBJS) tests/ctdb_test.o
@echo Linking $@ @echo Linking $@
@$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o $(OBJS) $(LIB_FLAGS) @$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o $(OBJS) $(LIB_FLAGS)
bin/ctdbd: $(OBJS) direct/ctdbd.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ direct/ctdbd.o $(OBJS) $(LIB_FLAGS)
bin/ctdbd_test: $(OBJS) direct/ctdbd_test.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ direct/ctdbd_test.o
bin/ctdb_bench: $(OBJS) tests/ctdb_bench.o bin/ctdb_bench: $(OBJS) tests/ctdb_bench.o
@echo Linking $@ @echo Linking $@
@$(CC) $(CFLAGS) -o $@ tests/ctdb_bench.o $(OBJS) $(LIB_FLAGS) @$(CC) $(CFLAGS) -o $@ tests/ctdb_bench.o $(OBJS) $(LIB_FLAGS)

12
ctdb/direct/README Normal file
View File

@ -0,0 +1,12 @@
Run ./direct/ctdbd.sh to start a cluster with two ctdb nodes
They will listen for clients on the unix domain sockets
/tmp/ctdb.socket.127.0.0.1
/tmp/ctdb.socket.127.0.0.2
In order for this to work you must have an interface with the address 127.0.0.2 available.
Just create this as an alias for loopback.
Then run ./direct/ctdbd_test to connect a client to the ctdbd daemon on /tmp/ctdb.socket.127.0.0.1 and do some commands to it across the domain socket.

124
ctdb/direct/ctdbd.c Normal file
View File

@ -0,0 +1,124 @@
/*
standalone ctdb daemon
Copyright (C) Andrew Tridgell 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "includes.h"
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
/*
main program
*/
int main(int argc, const char *argv[])
{
struct ctdb_context *ctdb;
const char *nlist = NULL;
const char *transport = "tcp";
const char *myaddress = NULL;
int self_connect=0;
int daemon_mode=0;
struct poptOption popt_options[] = {
POPT_AUTOHELP
{ "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" },
{ "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" },
{ "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL },
{ "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
{ "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" },
POPT_TABLEEND
};
int opt;
const char **extra_argv;
int extra_argc = 0;
int ret;
poptContext pc;
struct event_context *ev;
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);
}
}
/* 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++;
}
if (nlist == NULL || myaddress == NULL) {
printf("You must provide a node list with --nlist and an address with --listen\n");
exit(1);
}
ev = event_context_init(NULL);
/* initialise ctdb */
ctdb = ctdb_init(ev);
if (ctdb == NULL) {
printf("Failed to init ctdb\n");
exit(1);
}
if (self_connect) {
ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT);
}
if (daemon_mode) {
ctdb_set_flags(ctdb, CTDB_FLAG_DAEMON_MODE);
}
ret = ctdb_set_transport(ctdb, transport);
if (ret == -1) {
printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
/* tell ctdb what address to listen on */
ret = ctdb_set_address(ctdb, myaddress);
if (ret == -1) {
printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
/* tell ctdb what nodes are available */
ret = ctdb_set_nlist(ctdb, nlist);
if (ret == -1) {
printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
/* start the protocol running */
ret = ctdb_start(ctdb);
while (1) {
event_loop_once(ev);
}
/* shut it down */
talloc_free(ctdb);
return 0;
}

8
ctdb/direct/ctdbd.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
killall -q ctdbd
echo "Starting 2 ctdb daemons"
bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.2:9001 --daemon &
bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.1:9001 --daemon &

86
ctdb/direct/ctdbd_test.c Normal file
View File

@ -0,0 +1,86 @@
/*
test of messaging
Copyright (C) Andrew Tridgell 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "includes.h"
#include "system/network.h"
#include "../include/ctdb.h"
#include "../include/ctdb_private.h"
#define CTDB_SOCKET "/tmp/ctdb.socket.127.0.0.1"
/*
connect to the unix domain socket
*/
static int ux_socket_connect(const char *name)
{
struct sockaddr_un addr;
int fd;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, name, sizeof(addr.sun_path));
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
return -1;
}
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
close(fd);
return -1;
}
return fd;
}
void register_svid_with_daemon(int fd, int pid)
{
struct ctdb_req_register r;
bzero(&r, sizeof(r));
r.hdr.length = sizeof(r);
r.hdr.ctdb_magic = CTDB_MAGIC;
r.hdr.ctdb_version = CTDB_VERSION;
r.hdr.operation = CTDB_REQ_REGISTER;
r.srvid = pid;
/* XXX must deal with partial writes here */
write(fd, &r, sizeof(r));
}
int main(int argc, const char *argv[])
{
int fd, pid;
/* open the socket to talk to the local ctdb daemon */
fd=ux_socket_connect(CTDB_SOCKET);
if (fd==-1) {
printf("failed to open domain socket\n");
exit(10);
}
/* register our local server id with the daemon */
pid=getpid();
register_svid_with_daemon(fd, pid);
return 0;
}

2
ctdb/direct/nodes.txt Normal file
View File

@ -0,0 +1,2 @@
127.0.0.1:9001
127.0.0.2:9001