summaryrefslogtreecommitdiff
path: root/source4/cluster/ctdb/direct
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-04-21 07:23:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:51:17 -0500
commit650d81b252cc669ef848448afad7e9bb79c4f20e (patch)
tree7108ada18c4d7fff581470791832850c17eab6bf /source4/cluster/ctdb/direct
parent66a9f1e2764900a2c22a4bfad9f9caf3db729385 (diff)
downloadsamba-650d81b252cc669ef848448afad7e9bb79c4f20e.tar.gz
samba-650d81b252cc669ef848448afad7e9bb79c4f20e.tar.bz2
samba-650d81b252cc669ef848448afad7e9bb79c4f20e.zip
r22421: merged in latest ctdb changes from bzr
(This used to be commit 3633f862b966866819c9a0a6ad0238a858e15e62)
Diffstat (limited to 'source4/cluster/ctdb/direct')
-rw-r--r--source4/cluster/ctdb/direct/ctdbd.c51
-rwxr-xr-xsource4/cluster/ctdb/direct/ctdbd.sh4
-rw-r--r--source4/cluster/ctdb/direct/ctdbd_test.c92
3 files changed, 21 insertions, 126 deletions
diff --git a/source4/cluster/ctdb/direct/ctdbd.c b/source4/cluster/ctdb/direct/ctdbd.c
index 700416e5e9..674b54d47a 100644
--- a/source4/cluster/ctdb/direct/ctdbd.c
+++ b/source4/cluster/ctdb/direct/ctdbd.c
@@ -23,6 +23,7 @@
#include "system/filesys.h"
#include "popt.h"
#include "system/wait.h"
+#include "cmdline.h"
static void block_signal(int signum)
{
@@ -43,21 +44,12 @@ static void block_signal(int signum)
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;
const char *db_list = "test.tdb";
char *s, *tok;
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_CTDB_CMDLINE
{ "dblist", 0, POPT_ARG_STRING, &db_list, 0, "list of databases", NULL },
POPT_TABLEEND
};
@@ -86,48 +78,11 @@ int main(int argc, const char *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);
- }
-
block_signal(SIGPIPE);
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);
- }
+ ctdb = ctdb_cmdline_init(ev);
/* attach to the list of databases */
s = talloc_strdup(ctdb, db_list);
diff --git a/source4/cluster/ctdb/direct/ctdbd.sh b/source4/cluster/ctdb/direct/ctdbd.sh
index 366226260b..7224bdec6d 100755
--- a/source4/cluster/ctdb/direct/ctdbd.sh
+++ b/source4/cluster/ctdb/direct/ctdbd.sh
@@ -3,6 +3,6 @@
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 &
+bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.2:9001 &
+bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.1:9001 &
diff --git a/source4/cluster/ctdb/direct/ctdbd_test.c b/source4/cluster/ctdb/direct/ctdbd_test.c
index 019cdad30d..00b9f967df 100644
--- a/source4/cluster/ctdb/direct/ctdbd_test.c
+++ b/source4/cluster/ctdb/direct/ctdbd_test.c
@@ -184,78 +184,32 @@ uint32_t ctdb_hash(const TDB_DATA *key)
return (1103515243 * value + 12345);
}
-void fetch_lock(int fd, uint32_t db_id, TDB_DATA key)
-{
- struct ctdb_req_fetch_lock *req;
- struct ctdb_reply_fetch_lock *rep;
- uint32_t length;
- int len, cnt, tot;
-
- len = offsetof(struct ctdb_req_fetch_lock, key) + key.dsize;
- req = malloc(len);
-
- req->hdr.length = len;
- req->hdr.ctdb_magic = CTDB_MAGIC;
- req->hdr.ctdb_version = CTDB_VERSION;
- req->hdr.operation = CTDB_REQ_FETCH_LOCK;
- req->hdr.reqid = 1;
- req->db_id = db_id;
- req->keylen = key.dsize;
- memcpy(&req->key[0], key.dptr, key.dsize);
+/* ask the daemon to migrate a record over so that the local node is the dmaster the client must not have the record locked when performing this call.
- cnt=write(fd, req, len);
-
-
- /* wait fot the reply */
- /* read the 4 bytes of length for the pdu */
- cnt=0;
- tot=4;
- while(cnt!=tot){
- int numread;
- numread=read(fd, ((char *)&length)+cnt, tot-cnt);
- if(numread>0){
- cnt+=numread;
- }
- }
- /* read the rest of the pdu */
- rep = malloc(length);
- tot=length;
- while(cnt!=tot){
- int numread;
- numread=read(fd, ((char *)rep)+cnt, tot-cnt);
- if(numread>0){
- cnt+=numread;
- }
- }
- printf("fetch lock reply: state:%d datalen:%d\n",rep->state,rep->datalen);
- if(!rep->datalen){
- printf("no data\n");
- } else {
- printf("data:[%s]\n",rep->data);
- }
-
-}
-
-void store_unlock(int fd, uint32_t db_id, TDB_DATA key, TDB_DATA data)
+ when the daemon has responded this node should be the dmaster (unless it has migrated off again)
+ */
+void fetch_record(int fd, uint32_t db_id, TDB_DATA key)
{
- struct ctdb_req_store_unlock *req;
- struct ctdb_reply_store_unlock *rep;
+ struct ctdb_req_call *req;
+ struct ctdb_reply_call *rep;
uint32_t length;
int len, cnt, tot;
- len = offsetof(struct ctdb_req_store_unlock, data) + key.dsize + data.dsize;
+ len = offsetof(struct ctdb_req_call, data) + key.dsize;
req = malloc(len);
req->hdr.length = len;
req->hdr.ctdb_magic = CTDB_MAGIC;
req->hdr.ctdb_version = CTDB_VERSION;
- req->hdr.operation = CTDB_REQ_STORE_UNLOCK;
+ req->hdr.operation = CTDB_REQ_CALL;
req->hdr.reqid = 1;
+
+ req->flags = CTDB_IMMEDIATE_MIGRATION;
req->db_id = db_id;
+ req->callid = CTDB_NULL_FUNC;
req->keylen = key.dsize;
- req->datalen = data.dsize;
+ req->calldatalen = 0;
memcpy(&req->data[0], key.dptr, key.dsize);
- memcpy(&req->data[key.dsize], data.dptr, data.dsize);
cnt=write(fd, req, len);
@@ -281,7 +235,7 @@ void store_unlock(int fd, uint32_t db_id, TDB_DATA key, TDB_DATA data)
cnt+=numread;
}
}
- printf("store unlock reply: state:%d\n",rep->state);
+ printf("fetch record reply: operation:%d state:%d\n",rep->hdr.operation,rep->status);
}
int main(int argc, const char *argv[])
@@ -291,8 +245,7 @@ int main(int argc, const char *argv[])
struct ctdb_req_message *reply;
TDB_DATA dbname;
uint32_t db_id;
- TDB_DATA key, data;
- char str[256];
+ TDB_DATA key;
/* open the socket to talk to the local ctdb daemon */
fd=ux_socket_connect(CTDB_SOCKET);
@@ -338,25 +291,12 @@ int main(int argc, const char *argv[])
printf("the has for the database id is 0x%08x\n",db_id);
printf("\n");
- /* send a fetch lock */
+ /* send a request to migrate a record to the local node */
key.dptr=discard_const("TestKey");
key.dsize=strlen((const char *)(key.dptr));
printf("fetch the test key:[%s]\n",key.dptr);
- fetch_lock(fd, db_id, key);
- printf("\n");
-
- /* send a store unlock */
- sprintf(str,"TestData_%d",getpid());
- data.dptr=discard_const(str);
- data.dsize=strlen((const char *)(data.dptr));
- printf("store new data==[%s] for this record\n",data.dptr);
- store_unlock(fd, db_id, key, data);
- printf("\n");
-
- /* send a fetch lock */
- printf("fetch the test key:[%s]\n",key.dptr);
- fetch_lock(fd, db_id, key);
+ fetch_record(fd, db_id, key);
printf("\n");