Rev 64: Merged tridge's code. in http://samba.org/~tridge/psomogyi/

psomogyi at gamax.hu psomogyi at gamax.hu
Mon Feb 12 14:13:22 GMT 2007


------------------------------------------------------------
revno: 64
revision-id: psomogyi at gamax.hu-20070212141322-0gzf7f99aghribw7
parent: psomogyi at gamax.hu-20070209170613-3vdva62qksacmu0h
parent: tridge at samba.org-20070209014616-852f8r8vjlkf1xml
parent: tridge at samba.org-20070209014616-852f8r8vjlkf1xml
committer: Peter Somogyi <psomogyi at gamax.hu>
branch nick: ctdb
timestamp: Mon 2007-02-12 15:13:22 +0100
message:
  Merged tridge's code.
  (I had error 206 at direct bzr merge, so 1st I did a "bzr branch" and merged that one.)
added:
  common/ctdb_message.c          ctdb_message.c-20070208224107-9dnio7x7z33prrmt-1
  tests/bench.sh                 bench.sh-20070209014602-vdolpr6esqsa58s7-1
modified:
  .bzrignore                     bzrignore-20061117235536-slq8jlz2b5161dfm-1
  Makefile.in                    makefile.in-20061117234101-o3qt14umlg9en8z0-1
  common/ctdb.c                  ctdb.c-20061127094323-t50f58d65iaao5of-2
  common/ctdb_call.c             ctdb_call.c-20061128065342-to93h6eejj5kon81-1
  ctdb_bench.c                   ctdb_bench.c-20061219052637-2liagoglohxb6p7s-1
  include/ctdb.h                 ctdb.h-20061117234101-o3qt14umlg9en8z0-11
  include/ctdb_private.h         ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13
    ------------------------------------------------------------
    revno: 44.1.14
    merged: tridge at samba.org-20070209014616-852f8r8vjlkf1xml
    parent: tridge at samba.org-20070209014558-ivbu2vfjhz0szafo
    committer: Andrew Tridgell <tridge at samba.org>
    branch nick: tridge
    timestamp: Fri 2007-02-09 12:46:16 +1100
    message:
      added a simple benchmark script
    ------------------------------------------------------------
    revno: 44.1.13
    merged: tridge at samba.org-20070209014558-ivbu2vfjhz0szafo
    parent: tridge at samba.org-20070208225421-3q7n9qgukzhqjtnz
    committer: Andrew Tridgell <tridge at samba.org>
    branch nick: tridge
    timestamp: Fri 2007-02-09 12:45:58 +1100
    message:
      changed ctdb_bench.c to use messages instead of calls
    ------------------------------------------------------------
    revno: 44.1.12
    merged: tridge at samba.org-20070208225421-3q7n9qgukzhqjtnz
    parent: tridge at samba.org-20070208224753-2z0gu1mo3kznxhib
    parent: psomogyi at gamax.hu-20070208180858-5g7ldz23vhs6l19r
    committer: Andrew Tridgell <tridge at samba.org>
    branch nick: tridge
    timestamp: Fri 2007-02-09 09:54:21 +1100
    message:
      merged ib work from peter
    ------------------------------------------------------------
    revno: 44.1.11
    merged: tridge at samba.org-20070208224753-2z0gu1mo3kznxhib
    parent: tridge at samba.org-20070208224204-8akha2l802ktt31e
    committer: Andrew Tridgell <tridge at samba.org>
    branch nick: tridge
    timestamp: Fri 2007-02-09 09:47:53 +1100
    message:
      ignore config.h*
    ------------------------------------------------------------
    revno: 44.1.10
    merged: tridge at samba.org-20070208224204-8akha2l802ktt31e
    parent: tridge at samba.org-20070207022607-0nx0fvt0aagc5pqx
    committer: Andrew Tridgell <tridge at samba.org>
    branch nick: tridge
    timestamp: Fri 2007-02-09 09:42:04 +1100
    message:
      merged ctdb messaging code from samba4
=== added file 'common/ctdb_message.c'
--- a/common/ctdb_message.c	1970-01-01 00:00:00 +0000
+++ b/common/ctdb_message.c	2007-02-09 01:45:58 +0000
@@ -0,0 +1,92 @@
+/* 
+   ctdb_message protocol code
+
+   Copyright (C) Andrew Tridgell  2007
+
+   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
+*/
+/*
+  see http://wiki.samba.org/index.php/Samba_%26_Clustering for
+  protocol design and packet details
+*/
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/tdb/include/tdb.h"
+#include "system/network.h"
+#include "system/filesys.h"
+#include "../include/ctdb_private.h"
+
+
+/*
+  called when a CTDB_REQ_MESSAGE packet comes in
+
+  this dispatches the messages to the registered ctdb message handler
+*/
+void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
+{
+	struct ctdb_req_message *c = (struct ctdb_req_message *)hdr;
+	TDB_DATA data;
+	if (ctdb->message_handler == NULL) {
+		printf("no msg handler\n");
+		/* no registered message handler */
+		talloc_free(hdr);
+		return;
+	}
+	data.dptr = &c->data[0];
+	data.dsize = c->datalen;
+	ctdb->message_handler(ctdb, c->srvid, data, ctdb->message_private);
+	talloc_free(hdr);
+}
+
+
+/*
+  send a ctdb message
+*/
+int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
+		      uint32_t srvid, TDB_DATA data)
+{
+	struct ctdb_req_message *r;
+	int len;
+
+	len = offsetof(struct ctdb_req_message, data) + data.dsize;
+	r = ctdb->methods->allocate_pkt(ctdb, len);
+	CTDB_NO_MEMORY(ctdb, r);
+
+	r->hdr.length    = len;
+	r->hdr.operation = CTDB_REQ_MESSAGE;
+	r->hdr.destnode  = vnn;
+	r->hdr.srcnode   = ctdb->vnn;
+	r->hdr.reqid     = 0;
+	r->srvid         = srvid;
+	r->datalen       = data.dsize;
+	memcpy(&r->data[0], data.dptr, data.dsize);
+	
+	ctdb_queue_packet(ctdb, &r->hdr);
+
+	talloc_free(r);
+	return 0;
+}
+
+/*
+  setup handler for receipt of ctdb messages from ctdb_send_message()
+*/
+int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
+			     void *private)
+{
+	ctdb->message_handler = handler;
+	ctdb->message_private = private;
+	return 0;
+}
+

=== added file 'tests/bench.sh'
--- a/tests/bench.sh	1970-01-01 00:00:00 +0000
+++ b/tests/bench.sh	2007-02-09 01:46:16 +0000
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+killall -q ctdb_bench
+
+echo "Trying 2 nodes"
+bin/ctdb_bench --nlist nodes.txt --listen 127.0.0.2:9001 $* &
+bin/ctdb_bench --nlist nodes.txt --listen 127.0.0.1:9001 $*
+
+killall -q ctdb_bench

=== modified file '.bzrignore'
--- a/.bzrignore	2007-01-25 13:22:03 +0000
+++ b/.bzrignore	2007-02-08 22:54:21 +0000
@@ -6,3 +6,5 @@
 ctdb_test
 config.cache
 configure
+config.h
+config.h.in

=== modified file 'Makefile.in'
--- a/Makefile.in	2007-01-25 04:10:40 +0000
+++ b/Makefile.in	2007-02-08 22:42:04 +0000
@@ -21,7 +21,8 @@
 EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
 
 CTDB_COMMON_OBJ = common/ctdb.o common/util.o common/ctdb_util.o \
-	common/ctdb_call.o common/ctdb_ltdb.o lib/util/idtree.o lib/util/db_wrap.o
+	common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_message.o \
+	lib/util/idtree.o lib/util/db_wrap.o
 
 CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
 

=== modified file 'common/ctdb.c'
--- a/common/ctdb.c	2007-02-08 18:08:58 +0000
+++ b/common/ctdb.c	2007-02-09 01:45:58 +0000
@@ -162,6 +162,15 @@
 }
 
 /*
+  return the number of nodes
+*/
+uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb)
+{
+	return ctdb->num_nodes;
+}
+
+
+/*
   start the protocol going
 */
 int ctdb_start(struct ctdb_context *ctdb)
@@ -212,6 +221,10 @@
 		ctdb_reply_dmaster(ctdb, hdr);
 		break;
 
+	case CTDB_REQ_MESSAGE:
+		ctdb_request_message(ctdb, hdr);
+		break;
+
 	default:
 		printf("Packet with unknown operation %d\n", hdr->operation);
 		talloc_free(hdr);
@@ -267,6 +280,20 @@
 	}
 }
 
+
+/*
+  queue a packet or die
+*/
+void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
+{
+	struct ctdb_node *node;
+	node = ctdb->nodes[hdr->destnode];
+	if (ctdb->methods->queue_pkt(node, (uint8_t *)hdr, hdr->length) != 0) {
+		ctdb_fatal(ctdb, "Unable to queue packet\n");
+	}
+}
+
+
 static const struct ctdb_upcalls ctdb_upcalls = {
 	.recv_pkt       = ctdb_recv_pkt,
 	.node_dead      = ctdb_node_dead,

=== modified file 'common/ctdb_call.c'
--- a/common/ctdb_call.c	2007-01-31 11:24:55 +0000
+++ b/common/ctdb_call.c	2007-02-08 22:54:21 +0000
@@ -29,19 +29,6 @@
 #include "../include/ctdb_private.h"
 
 /*
-  queue a packet or die
-*/
-static void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
-{
-	struct ctdb_node *node;
-	node = ctdb->nodes[hdr->destnode];
-	if (ctdb->methods->queue_pkt(node, (uint8_t *)hdr, hdr->length) != 0) {
-		ctdb_fatal(ctdb, "Unable to queue packet\n");
-	}
-}
-
-
-/*
   local version of ctdb_call
 */
 static int ctdb_call_local(struct ctdb_context *ctdb, struct ctdb_call *call,

=== modified file 'ctdb_bench.c'
--- a/ctdb_bench.c	2007-01-25 05:13:17 +0000
+++ b/ctdb_bench.c	2007-02-09 01:45:58 +0000
@@ -122,6 +122,65 @@
 	       num_repeats*loops/end_timer(), loops, *(uint32_t *)call.reply_data.dptr);
 }
 
+static int msg_count;
+static int msg_plus, msg_minus;
+
+/*
+  handler for messages in bench_ring()
+*/
+static void ring_message_handler(struct ctdb_context *ctdb, uint32_t srvid, 
+				 TDB_DATA data, void *private)
+{
+	int incr = *(int *)data.dptr;
+	int *count = (int *)private;
+	int dest;
+	(*count)++;
+	dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+	ctdb_send_message(ctdb, dest, srvid, data);
+	if (incr == 1) {
+		msg_plus++;
+	} else {
+		msg_minus++;
+	}
+}
+
+/*
+  benchmark sending messages in a ring around the nodes
+*/
+static void bench_ring(struct ctdb_context *ctdb, struct event_context *ev)
+{
+	TDB_DATA data;
+	int incr, vnn=ctdb_get_vnn(ctdb);
+
+	data.dptr = (uint8_t *)&incr;
+	data.dsize = sizeof(incr);
+
+	if (vnn == 0) {
+		/* two messages are injected into the ring, moving
+		   in opposite directions */
+		int dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+		incr = 1;
+		ctdb_send_message(ctdb, dest, 0, data);
+		incr = -1;
+		ctdb_send_message(ctdb, dest, 0, data);
+	}
+	
+	start_timer();
+
+	while (end_timer() < timelimit) {
+		if (vnn == 0 && msg_count % 1000 == 0) {
+			printf("Ring: %.2f msgs/sec (+ve=%d -ve=%d)\r", 
+			       msg_count/end_timer(), msg_plus, msg_minus);
+			fflush(stdout);
+		}
+		event_loop_once(ev);
+	}
+
+	printf("Ring: %.2f msgs/sec (+ve=%d -ve=%d)\n", 
+	       msg_count/end_timer(), msg_plus, msg_minus);
+}
+
+
 /*
   main program
 */
@@ -217,6 +276,8 @@
 		exit(1);
 	}
 
+	ctdb_set_message_handler(ctdb, ring_message_handler, &msg_count);
+
 	/* start the protocol running */
 	ret = ctdb_start(ctdb);
 
@@ -224,11 +285,8 @@
 	   outside of test code) */
 	ctdb_connect_wait(ctdb);
 
-	bench_incr(ctdb);
+	bench_ring(ctdb, ev);
        
-	/* go into a wait loop to allow other nodes to complete */
-	ctdb_wait_loop(ctdb);
-
 	/* shut it down */
 	talloc_free(ctdb);
 	return 0;

=== modified file 'include/ctdb.h'
--- a/include/ctdb.h	2007-01-29 11:30:06 +0000
+++ b/include/ctdb.h	2007-02-09 01:45:58 +0000
@@ -127,4 +127,19 @@
 /* return vnn of this node */
 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
 
+/*
+  return the number of nodes
+*/
+uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
+
+/* setup a handler for ctdb messages */
+typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid, 
+				  TDB_DATA data, void *);
+int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
+			     void *private);
+
+/* send a ctdb message */
+int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
+		      uint32_t srvid, TDB_DATA data);
+
 #endif

=== modified file 'include/ctdb_private.h'
--- a/include/ctdb_private.h	2007-01-31 11:24:55 +0000
+++ b/include/ctdb_private.h	2007-02-08 22:54:21 +0000
@@ -94,6 +94,8 @@
 	const struct ctdb_upcalls *upcalls; /* transport upcalls */
 	void *private; /* private to transport */
 	unsigned max_lacount;
+	ctdb_message_fn_t message_handler;
+	void *message_private;
 };
 
 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
@@ -138,7 +140,8 @@
 	CTDB_REPLY_REDIRECT = 2,
 	CTDB_REQ_DMASTER    = 3,
 	CTDB_REPLY_DMASTER  = 4,
-	CTDB_REPLY_ERROR    = 5
+	CTDB_REPLY_ERROR    = 5,
+	CTDB_REQ_MESSAGE    = 6
 };
 
 /*
@@ -193,6 +196,13 @@
 	uint8_t  data[1];
 };
 
+struct ctdb_req_message {
+	struct ctdb_req_header hdr;
+	uint32_t srvid;
+	uint32_t datalen;
+	uint8_t data[1];
+};
+
 /* internal prototypes */
 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
@@ -203,6 +213,7 @@
 uint32_t ctdb_hash(const TDB_DATA *key);
 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
@@ -213,6 +224,7 @@
 		    TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data);
 int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key, 
 		    struct ctdb_ltdb_header *header, TDB_DATA data);
+void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 
 
 #endif



More information about the samba-cvs mailing list