common: Debug ctdb_addr_to_str() using new function ctdb_external_trace()
authorMartin Schwenke <martin@meltin.net>
Thu, 6 Sep 2012 10:22:38 +0000 (20:22 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Wed, 12 Sep 2012 04:57:53 +0000 (14:57 +1000)
We've seen this function report "Unknown family, 0" and then CTDB
disappeared without a trace.  If we can reproduce it then this might
help us to debug it.

The idea is that you do something like the following in /etc/sysconfig/ctdb:

  export CTDB_EXTERNAL_TRACE="/etc/ctdb/config/gcore_trace.sh"

When we hit this error than we call out to gcore to get a core file so
we can do forensics.  This might block CTDB for a few seconds.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Makefile.in
common/ctdb_util.c
config/gcore_trace.sh [new file with mode: 0755]
include/ctdb_private.h
packaging/RPM/ctdb.spec.in

index c97a9caf4d814fd691d2f3e809ac6989fe85835e..e3d6d5bfab37c4eb1f749ccbda17d6a89e9d4e81 100755 (executable)
@@ -291,6 +291,7 @@ install: all
        if [ -f doc/ltdbtool.1 ]; then ${INSTALLCMD} -m 644 doc/ltdbtool.1 $(DESTDIR)$(mandir)/man1; fi
        if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.sh ];then ${INSTALLCMD} -m 755 config/notify.sh $(DESTDIR)$(etcdir)/ctdb; fi
        if [ ! -f $(DESTDIR)$(etcdir)/ctdb/ctdb-crash-cleanup.sh ];then ${INSTALLCMD} -m 755 config/ctdb-crash-cleanup.sh $(DESTDIR)$(etcdir)/ctdb; fi
+       if [ ! -f $(DESTDIR)$(etcdir)/ctdb/gcore_trace.sh ];then ${INSTALLCMD} -m 755 config/gcore_trace.sh $(DESTDIR)$(etcdir)/ctdb; fi
 
 test: all
        tests/run_tests.sh
index 061c16d2c4c62d7c1398449896e7a7f002509ede..bb212f58f62c04d738d9a981a586a53058f8eccc 100644 (file)
@@ -60,6 +60,30 @@ void ctdb_fatal(struct ctdb_context *ctdb, const char *msg)
        abort();
 }
 
+/* Invoke an external program to do some sort of tracing on the CTDB
+ * process.  This might block for a little while.  The external
+ * program is specified by the environment variable
+ * CTDB_EXTERNAL_TRACE.  This program should take one argument: the
+ * pid of the process to trace.  Commonly, the program would be a
+ * wrapper script around gcore.
+ */
+void ctdb_external_trace(void)
+{
+
+       const char * t = getenv("CTDB_EXTERNAL_TRACE");
+       char * cmd;
+
+       if (t == NULL) {
+               return;
+       }
+
+       cmd = talloc_asprintf(NULL, "%s %lu", t, (unsigned long) getpid());
+       DEBUG(DEBUG_WARNING,("begin external trace: %s\n", cmd));
+       system(cmd);
+       DEBUG(DEBUG_WARNING,("end external trace: %s\n", cmd));
+       talloc_free(cmd);
+}
+
 /*
   parse a IP:port pair
 */
@@ -574,6 +598,7 @@ char *ctdb_addr_to_str(ctdb_sock_addr *addr)
                break;
        default:
                DEBUG(DEBUG_ERR, (__location__ " ERROR, unknown family %u\n", addr->sa.sa_family));
+               ctdb_external_trace();
        }
 
        return cip;
diff --git a/config/gcore_trace.sh b/config/gcore_trace.sh
new file mode 100755 (executable)
index 0000000..4d3e1d1
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+gcore -o "/var/log/core" "$1" 2>&1 | logger -t "ctdb:gcore_trace"
index 3a5d3cf65c25eb5234fd457cb9f195340f4eb83b..b5bd45c16b5b4d79be4e00605e9436842b2e1bc3 100644 (file)
@@ -655,6 +655,7 @@ struct ctdb_fetch_handle {
 /* 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);
+void ctdb_external_trace(void);
 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
 int ctdb_parse_address(struct ctdb_context *ctdb,
                       TALLOC_CTX *mem_ctx, const char *str,
index 2d744b20e399ed8073a8f4e05dea4cf62f284093..cb58a5baa684330c0c54e20ce66e58ac5037f94e 100644 (file)
@@ -89,6 +89,7 @@ rm -rf $RPM_BUILD_ROOT
 %config(noreplace) %{_sysconfdir}/sysconfig/ctdb
 %config(noreplace) %{_sysconfdir}/ctdb/notify.sh
 %config(noreplace) %{_sysconfdir}/ctdb/ctdb-crash-cleanup.sh
+%config(noreplace) %{_sysconfdir}/ctdb/gcore_trace.sh
 %config(noreplace) %{_sysconfdir}/ctdb/functions
 %attr(755,root,root) %{initdir}/ctdb