[SCM] CTDB repository - branch master updated - ctdb-1.10-76-g52ee2b3

Ronnie Sahlberg sahlberg at samba.org
Mon Jan 17 20:46:30 MST 2011


The branch, master has been updated
       via  52ee2b3ce822344d0f55ac040fe25f6ec5c0d7c2 (commit)
       via  d09fa845bd848d04507853809acf42e0471b44bf (commit)
       via  ac2afe9c25753b837d5f6396020e0f3c65ef3628 (commit)
       via  fd8d54292f10b35bc4960d64cfa6843ce9aba225 (commit)
      from  9463e04038ba36792583f83bd95c1af322dc283a (commit)

http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 52ee2b3ce822344d0f55ac040fe25f6ec5c0d7c2
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Jan 18 13:33:24 2011 +1100

    ctdb: hold transaction locks during freeze, mark during recover.
    
    Make the ctdb parent "mark" the transaction lock once the child process
    has frozen/locked the entire database.
    This stops the ctdb daemon from using  a blocking fcntl() locking on the tdb during the
    read traverse during recovery.
    
    CQ 1021388

commit d09fa845bd848d04507853809acf42e0471b44bf
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Tue Jan 18 10:47:11 2011 +1030

    tdb: expose transaction lock infrastructure for ctdb
    
    tdb_traverse_read() grabs the transaction lock.  This can cause ctdbd
    (which uses it) to block when it should not; expose mark and normal
    variants of this lock, so ctdbd's child (the recovery daemon) can
    acquire it and the ctdbd parent can mark it was held.

commit ac2afe9c25753b837d5f6396020e0f3c65ef3628
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Jan 17 12:00:18 2011 +1100

    change Christinas previous patch to only perform the check/logging
    if we are the main ctdb daemon.
    Other daemons/child processes are not guaranteed to get events on regular basis
    so those should not be checked.

commit fd8d54292f10b35bc4960d64cfa6843ce9aba225
Author: Christian Ambach <christian.ambach at de.ibm.com>
Date:   Fri Jan 14 13:55:28 2011 +0100

    improve timing issue detections
    
    the original "Time jumped" messages are too coarse to interpret
    exactly what was going wrong inside of CTDB.
    
    This patch removes the original logs and adds two other logs that
    differentiate between the time it took to work on an event and
    the time it took to get the next event.

-----------------------------------------------------------------------

Summary of changes:
 lib/tdb/common/lock.c        |   20 ++++++++++++++++
 lib/tdb/include/tdb.h        |    4 +++
 lib/tevent/tevent.c          |   17 --------------
 lib/tevent/tevent_epoll.c    |    4 +++
 lib/tevent/tevent_select.c   |    4 +++
 lib/tevent/tevent_standard.c |    4 +++
 lib/tevent/tevent_util.c     |   51 ++++++++++++++++++++++++++++++++++++++++++
 lib/tevent/tevent_util.h     |    4 +++
 server/ctdb_recover.c        |    9 +++++++
 9 files changed, 100 insertions(+), 17 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c
index 803feee..f0da881 100644
--- a/lib/tdb/common/lock.c
+++ b/lib/tdb/common/lock.c
@@ -861,3 +861,23 @@ void tdb_release_transaction_locks(struct tdb_context *tdb)
 		SAFE_FREE(tdb->lockrecs);
 	}
 }
+
+int tdb_transaction_write_lock_mark(struct tdb_context *tdb)
+{
+	return tdb_transaction_lock(tdb, F_WRLCK, TDB_LOCK_MARK_ONLY);
+}
+
+int tdb_transaction_write_lock(struct tdb_context *tdb)
+{
+	return tdb_transaction_lock(tdb, F_WRLCK, 0);
+}
+
+int tdb_transaction_write_unlock(struct tdb_context *tdb)
+{
+	return tdb_transaction_unlock(tdb, F_WRLCK);
+}
+
+int tdb_transaction_write_lock_unmark(struct tdb_context *tdb)
+{
+	return tdb_nest_unlock(tdb, TRANSACTION_LOCK, F_WRLCK, true);
+}
diff --git a/lib/tdb/include/tdb.h b/lib/tdb/include/tdb.h
index aac7c92..536a0b3 100644
--- a/lib/tdb/include/tdb.h
+++ b/lib/tdb/include/tdb.h
@@ -161,6 +161,10 @@ _PUBLIC_ int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
+_PUBLIC_ int tdb_transaction_write_lock(struct tdb_context *tdb);
+_PUBLIC_ int tdb_transaction_write_unlock(struct tdb_context *tdb);
+_PUBLIC_ int tdb_transaction_write_lock_mark(struct tdb_context *tdb);
+_PUBLIC_ int tdb_transaction_write_lock_unmark(struct tdb_context *tdb);
 
 _PUBLIC_ void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr);
 
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index 2f6e591..5eec5cc 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -582,16 +582,12 @@ done:
 }
 
 
-extern pid_t ctdbd_pid;
-
 /*
   return on failure or (with 0) if all fd events are removed
 */
 int tevent_common_loop_wait(struct tevent_context *ev,
 			    const char *location)
 {
-	static time_t t=0;
-	time_t new_t;
 
 	/*
 	 * loop as long as we have events pending
@@ -608,19 +604,6 @@ int tevent_common_loop_wait(struct tevent_context *ev,
 				     ret, strerror(errno));
 			return ret;
 		}
-		if (getpid() == ctdbd_pid) {
-			new_t=time(NULL);
-			if (t != 0) {
-				if (t > new_t) {
-					tevent_debug(ev, TEVENT_DEBUG_FATAL, __location__ " ERROR Time skipped backward by %d seconds\n", (int)(t-new_t));
-				}
-				/* We assume here that we get at least one event every 3 seconds */
-				if (new_t > (t+3)) {
-					tevent_debug(ev, TEVENT_DEBUG_FATAL, __location__ " ERROR Time jumped forward by %d seconds\n", (int)(new_t-t));
-				}
-			}
-			t=new_t;
-		}
 	}
 
 	tevent_debug(ev, TEVENT_DEBUG_WARNING,
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index 3abb0e6..1c3396e 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -228,6 +228,8 @@ static void epoll_change_event(struct epoll_event_context *epoll_ev, struct teve
 	}
 }
 
+extern pid_t ctdbd_pid;
+
 /*
   event loop handling using epoll
 */
@@ -250,7 +252,9 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval
 		return 0;
 	}
 
+	if (getpid() == ctdbd_pid) tevent_before_wait(epoll_ev->ev);
 	ret = epoll_wait(epoll_ev->epoll_fd, events, MAXEVENTS, timeout);
+	if (getpid() == ctdbd_pid) tevent_after_wait(epoll_ev->ev);
 
 	if (ret == -1 && errno == EINTR && epoll_ev->ev->signal_events) {
 		if (tevent_common_check_signal(epoll_ev->ev)) {
diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c
index 128a7d6..1671198 100644
--- a/lib/tevent/tevent_select.c
+++ b/lib/tevent/tevent_select.c
@@ -125,6 +125,8 @@ static struct tevent_fd *select_event_add_fd(struct tevent_context *ev, TALLOC_C
 	return fde;
 }
 
+extern pid_t ctdbd_pid;
+
 /*
   event loop handling using select()
 */
@@ -157,7 +159,9 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
 		return 0;
 	}
 
+	if (getpid() == ctdbd_pid) tevent_before_wait(select_ev->ev);
 	selrtn = select(select_ev->maxfd+1, &r_fds, &w_fds, NULL, tvalp);
+	if (getpid() == ctdbd_pid) tevent_after_wait(select_ev->ev);
 
 	if (selrtn == -1 && errno == EINTR &&
 	    select_ev->ev->signal_events) {
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index 3f2d6d5..05d734a 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -239,6 +239,8 @@ static void epoll_change_event(struct std_event_context *std_ev, struct tevent_f
 	}
 }
 
+extern pid_t ctdbd_pid;
+
 /*
   event loop handling using epoll
 */
@@ -261,7 +263,9 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv
 		return 0;
 	}
 
+	if (getpid() == ctdbd_pid) tevent_before_wait(std_ev->ev);
 	ret = epoll_wait(std_ev->epoll_fd, events, MAXEVENTS, timeout);
+	if (getpid() == ctdbd_pid) tevent_after_wait(std_ev->ev);
 
 	if (ret == -1 && errno == EINTR && std_ev->ev->signal_events) {
 		if (tevent_common_check_signal(std_ev->ev)) {
diff --git a/lib/tevent/tevent_util.c b/lib/tevent/tevent_util.c
index f78cd8f..28c9da3 100644
--- a/lib/tevent/tevent_util.c
+++ b/lib/tevent/tevent_util.c
@@ -88,3 +88,54 @@ int ev_set_blocking(int fd, bool set)
 	return fcntl( fd, F_SETFL, val);
 #undef FLAG_TO_SET
 }
+
+static struct timeval tevent_before_wait_ts;
+static struct timeval tevent_after_wait_ts;
+
+/*
+ * measure the time difference between multiple arrivals
+ * to the point where we wait for new events to come in
+ *
+ * allows to measure how long it takes to work on a 
+ * event
+ */
+void tevent_before_wait(struct event_context *ev) {
+
+	struct timeval diff;
+	struct timeval now = tevent_timeval_current();
+
+	if (!tevent_timeval_is_zero(&tevent_after_wait_ts)) {
+		diff = tevent_timeval_until(&tevent_after_wait_ts, &now);
+		if (diff.tv_sec > 3) {
+			tevent_debug(ev, TEVENT_DEBUG_FATAL,  __location__ 
+				     " Handling event took %d seconds!",
+				     (int) diff.tv_sec);
+		}
+	}
+
+	tevent_before_wait_ts = tevent_timeval_current();
+
+}
+
+/*
+ * measure how long the select()/epoll() call took
+ *
+ * allows to measure how long we are waiting for new events
+ */
+void tevent_after_wait(struct event_context *ev) {
+
+	struct timeval diff;
+	struct timeval now = tevent_timeval_current();
+
+	if (!tevent_timeval_is_zero(&tevent_before_wait_ts)) {
+		diff = tevent_timeval_until(&tevent_before_wait_ts, &now);
+		if (diff.tv_sec > 3) {
+			tevent_debug(ev, TEVENT_DEBUG_FATAL,  __location__
+				     " No event for %d seconds!",
+				     (int) diff.tv_sec);
+		}
+	}
+
+	tevent_after_wait_ts = tevent_timeval_current();
+
+}
diff --git a/lib/tevent/tevent_util.h b/lib/tevent/tevent_util.h
index 46a4506..2852e9f 100644
--- a/lib/tevent/tevent_util.h
+++ b/lib/tevent/tevent_util.h
@@ -184,6 +184,10 @@ const char **ev_str_list_add(const char **list, const char *s);
 int ev_set_blocking(int fd, bool set);
 size_t ev_str_list_length(const char **list);
 
+void tevent_before_wait(struct event_context *ev);
+void tevent_after_wait(struct event_context *ev);
+
+
 /* Defined here so we can build against older talloc versions that don't
  * have this define yet. */
 #ifndef TALLOC_FREE
diff --git a/server/ctdb_recover.c b/server/ctdb_recover.c
index fe4275c..4db4d97 100644
--- a/server/ctdb_recover.c
+++ b/server/ctdb_recover.c
@@ -57,7 +57,11 @@ static int ctdb_lock_all_databases_mark(struct ctdb_context *ctdb, uint32_t prio
 		if (strstr(ctdb_db->db_name, "notify") != NULL) {
 			continue;
 		}
+		if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
+			return -1;
+		}
 		if (tdb_lockall_mark(ctdb_db->ltdb->tdb) != 0) {
+			tdb_transaction_write_lock_unmark(ctdb_db->ltdb->tdb);
 			return -1;
 		}
 	}
@@ -68,7 +72,11 @@ static int ctdb_lock_all_databases_mark(struct ctdb_context *ctdb, uint32_t prio
 		if (strstr(ctdb_db->db_name, "notify") == NULL) {
 			continue;
 		}
+		if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
+			return -1;
+		}
 		if (tdb_lockall_mark(ctdb_db->ltdb->tdb) != 0) {
+			tdb_transaction_write_lock_unmark(ctdb_db->ltdb->tdb);
 			return -1;
 		}
 	}
@@ -95,6 +103,7 @@ static int ctdb_lock_all_databases_unmark(struct ctdb_context *ctdb, uint32_t pr
 		if (ctdb_db->priority != priority) {
 			continue;
 		}
+		tdb_transaction_write_lock_unmark(ctdb_db->ltdb->tdb);
 		if (tdb_lockall_unmark(ctdb_db->ltdb->tdb) != 0) {
 			return -1;
 		}


-- 
CTDB repository


More information about the samba-cvs mailing list