Merge branch '1.3' of 10.1.1.27:/shared/ctdb/ctdb-git into 1.3
[sahlberg/ctdb.git] / server / ctdb_daemon.c
index 12ad9543c46005f65ae272f47d0e79c7371ac024..362f1cee5768a4fc098c59b36b3d25bb7973af07 100644 (file)
@@ -43,6 +43,33 @@ static void print_exit_message(void)
        DEBUG(DEBUG_NOTICE,("CTDB daemon shutting down\n"));
 }
 
+
+
+static void ctdb_time_tick(struct event_context *ev, struct timed_event *te, 
+                                 struct timeval t, void *private_data)
+{
+       struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
+
+       if (getpid() != ctdbd_pid) {
+               return;
+       }
+
+       event_add_timed(ctdb->ev, ctdb, 
+                       timeval_current_ofs(1, 0), 
+                       ctdb_time_tick, ctdb);
+}
+
+/* Used to trigger a dummy event once per second, to make
+ * detection of hangs more reliable.
+ */
+static void ctdb_start_time_tickd(struct ctdb_context *ctdb)
+{
+       event_add_timed(ctdb->ev, ctdb, 
+                       timeval_current_ofs(1, 0), 
+                       ctdb_time_tick, ctdb);
+}
+
+
 /* called when the "startup" event script has finished */
 static void ctdb_start_transport(struct ctdb_context *ctdb)
 {
@@ -77,6 +104,9 @@ static void ctdb_start_transport(struct ctdb_context *ctdb)
 
        /* start listening for recovery daemon pings */
        ctdb_control_recd_ping(ctdb);
+
+       /* start listening to timer ticks */
+       ctdb_start_time_tickd(ctdb);
 }
 
 static void block_signal(int signum)
@@ -704,7 +734,7 @@ static void ctdb_setup_event_callback(struct ctdb_context *ctdb, int status,
 /*
   start the protocol going as a daemon
 */
-int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
+int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog, const char *public_address_list)
 {
        int res, ret = -1;
        struct fd_event *fde;
@@ -742,7 +772,10 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
 
        DEBUG(DEBUG_ERR, ("Starting CTDBD as pid : %u\n", ctdbd_pid));
 
-       ctdb_high_priority(ctdb);
+       if (ctdb->do_setsched) {
+               /* try to set us up as realtime */
+               ctdb_set_scheduler(ctdb);
+       }
 
        /* ensure the socket is deleted on exit of the daemon */
        domain_socket_name = talloc_strdup(talloc_autofree_context(), ctdb->daemon.name);
@@ -791,6 +824,14 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
        if (ctdb->methods->initialise(ctdb) != 0) {
                ctdb_fatal(ctdb, "transport failed to initialise");
        }
+       if (public_address_list) {
+               ret = ctdb_set_public_addresses(ctdb, public_address_list);
+               if (ret == -1) {
+                       DEBUG(DEBUG_ALERT,("Unable to setup public address list\n"));
+                       exit(1);
+               }
+       }
+
 
        /* attach to existing databases */
        if (ctdb_attach_databases(ctdb) != 0) {
@@ -815,7 +856,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
        tevent_fd_set_auto_close(fde);
 
        /* release any IPs we hold from previous runs of the daemon */
-       ctdb_release_all_ips(ctdb);
+       if (ctdb->tunable.disable_ip_failover == 0) {
+               ctdb_release_all_ips(ctdb);
+       }
 
        /* start the transport going */
        ctdb_start_transport(ctdb);
@@ -874,7 +917,7 @@ struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
        size = (length+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
 
        if (ctdb->methods == NULL) {
-               DEBUG(DEBUG_ERR,(__location__ " Unable to allocate transport packet for operation %u of length %u. Transport is DOWN.\n",
+               DEBUG(DEBUG_INFO,(__location__ " Unable to allocate transport packet for operation %u of length %u. Transport is DOWN.\n",
                         operation, (unsigned)length));
                return NULL;
        }
@@ -1099,7 +1142,7 @@ int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t pnn,
        int len;
 
        if (ctdb->methods == NULL) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to send message. Transport is DOWN\n"));
+               DEBUG(DEBUG_INFO,(__location__ " Failed to send message. Transport is DOWN\n"));
                return -1;
        }