ctdb-recoverd: Detach database from recovery daemon
authorAmitay Isaacs <amitay@gmail.com>
Tue, 22 Apr 2014 05:24:49 +0000 (15:24 +1000)
committerMichael Adam <obnox@samba.org>
Wed, 23 Apr 2014 15:05:45 +0000 (17:05 +0200)
As part of vacuuming, recoverd attaches to databases to migrate records.
When detaching a database from main daemon, it should be removed from
recovery daemon also.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Autobuild-User(master): Michael Adam <obnox@samba.org>
Autobuild-Date(master): Wed Apr 23 17:05:45 CEST 2014 on sn-devel-104

ctdb/include/ctdb_protocol.h
ctdb/server/ctdb_ltdb_server.c
ctdb/server/ctdb_recoverd.c

index f2d68f4c3a38dd461b86b51396d58d2c35fa72e8..629c91c0cd307222f1fe7990c4929c15ed0b8f5b 100644 (file)
@@ -113,6 +113,10 @@ struct ctdb_call_info {
  */
 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
 
+/*
+ * a message to tell recovery daemon to detach a database
+ */
+#define CTDB_SRVID_DETACH_DATABASE 0xF701000000000000LL
 /*
   a message to tell the recovery daemon to write a talloc memdump
   to the log
index 19c6a82b9c8cb1337159b6db05e4a138ec1cdf45..6ff92c54e31d4dfe6d3c98fbb1b6cb6008a3f97a 100644 (file)
@@ -1220,6 +1220,14 @@ int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
                return -1;
        }
 
+       /* Detach database from recoverd */
+       if (ctdb_daemon_send_message(ctdb, ctdb->pnn,
+                                    CTDB_SRVID_DETACH_DATABASE,
+                                    indata) != 0) {
+               DEBUG(DEBUG_ERR, ("Unable to detach DB from recoverd\n"));
+               return -1;
+       }
+
        /* Disable vacuuming and drop all vacuuming data */
        talloc_free(ctdb_db->vacuum_handle);
        talloc_free(ctdb_db->delete_queue);
index ac692ec5419f1309625ab505295bd5b898df550f..77586353c7ed8db5c8f63f5a2c80b9bda85cb7c0 100644 (file)
@@ -1094,6 +1094,47 @@ static void vacuum_fetch_handler(struct ctdb_context *ctdb, uint64_t srvid,
 }
 
 
+/*
+ * handler for database detach
+ */
+static void detach_database_handler(struct ctdb_context *ctdb, uint64_t srvid,
+                                   TDB_DATA data, void *private_data)
+{
+       struct ctdb_recoverd *rec = talloc_get_type(private_data,
+                                                   struct ctdb_recoverd);
+       uint32_t db_id;
+       struct vacuum_info *v, *vnext;
+       struct ctdb_db_context *ctdb_db;
+
+       if (data.dsize != sizeof(db_id)) {
+               return;
+       }
+       db_id = *(uint32_t *)data.dptr;
+
+       ctdb_db = find_ctdb_db(ctdb, db_id);
+       if (ctdb_db == NULL) {
+               /* database is not attached */
+               return;
+       }
+
+       /* Stop any active vacuum fetch */
+       v = rec->vacuum_info;
+       while (v != NULL) {
+               vnext = v->next;
+
+               if (v->ctdb_db->db_id == db_id) {
+                       talloc_free(v);
+               }
+               v = vnext;
+       }
+
+       DLIST_REMOVE(ctdb->db_list, ctdb_db);
+
+       DEBUG(DEBUG_NOTICE, ("Detached from database '%s'\n",
+                            ctdb_db->db_name));
+       talloc_free(ctdb_db);
+}
+
 /*
   called when ctdb_wait_timeout should finish
  */
@@ -4145,6 +4186,11 @@ static void monitor_cluster(struct ctdb_context *ctdb)
                                        CTDB_SRVID_DISABLE_TAKEOVER_RUNS,
                                        disable_takeover_runs_handler, rec);
 
+       /* register a message port for detaching database */
+       ctdb_client_set_message_handler(ctdb,
+                                       CTDB_SRVID_DETACH_DATABASE,
+                                       detach_database_handler, rec);
+
        for (;;) {
                TALLOC_CTX *mem_ctx = talloc_new(ctdb);
                struct timeval start;