vacuum: add ctdb_local_schedule_for_deletion()
authorMichael Adam <obnox@samba.org>
Tue, 28 Dec 2010 12:13:34 +0000 (13:13 +0100)
committerMichael Adam <obnox@samba.org>
Wed, 9 Mar 2011 23:37:52 +0000 (00:37 +0100)
include/ctdb_private.h
server/ctdb_vacuum.c

index c2a448088d93c87131288cad10b4f3446ead1d50..6e5911204cbec7b62e4232c7642a513f0e68b6e5 100644 (file)
@@ -1397,4 +1397,9 @@ struct ctdb_control_schedule_for_deletion {
 int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
                                           TDB_DATA indata);
 
+
+int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
+                                        const struct ctdb_ltdb_header *hdr,
+                                        TDB_DATA key);
+
 #endif
index ec3b5f29f2815b2de0786f86a995e59e5e57ee3d..822c9056b083d588f7c89647e3e560335444c052 100644 (file)
@@ -1333,3 +1333,64 @@ int32_t ctdb_control_schedule_for_deletion(struct ctdb_context *ctdb,
 
        return 0;
 }
+
+int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
+                                        const struct ctdb_ltdb_header *hdr,
+                                        TDB_DATA key)
+{
+       int ret;
+       struct ctdb_control_schedule_for_deletion *dd;
+       TDB_DATA indata;
+       int32_t status;
+
+       if (ctdb_db->ctdb->ctdbd_pid == getpid()) {
+               /* main daemon - directly queue */
+               ret = insert_delete_record_data_into_tree(ctdb_db->ctdb,
+                                                         ctdb_db,
+                                                         ctdb_db->delete_queue,
+                                                         hdr, key);
+               if (ret != 0) {
+                       return -1;
+               }
+               return 0;
+       }
+
+       /* child process: send the main daemon a control */
+
+       indata.dsize = offsetof(struct ctdb_control_schedule_for_deletion, key) + key.dsize;
+       indata.dptr = talloc_zero_array(ctdb_db, uint8_t, indata.dsize);
+       if (indata.dptr == NULL) {
+               DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
+               return -1;
+       }
+       dd = (struct ctdb_control_schedule_for_deletion *)(void *)indata.dptr;
+       dd->db_id = ctdb_db->db_id;
+       dd->hdr = *hdr;
+       dd->keylen = key.dsize;
+       memcpy(dd->key, key.dptr, key.dsize);
+
+       ret = ctdb_control(ctdb_db->ctdb,
+                          CTDB_CURRENT_NODE,
+                          ctdb_db->db_id,
+                          CTDB_CONTROL_SCHEDULE_FOR_DELETION,
+                          CTDB_CTRL_FLAG_NOREPLY, /* flags */
+                          indata,
+                          NULL, /* mem_ctx */
+                          NULL, /* outdata */
+                          &status,
+                          NULL, /* timeout : NULL == wait forever */
+                          NULL); /* error message */
+
+       talloc_free(indata.dptr);
+
+       if (ret != 0 || status != 0) {
+               DEBUG(DEBUG_ERR, (__location__ " Error sending "
+                                 "SCHEDULE_FOR_DELETION "
+                                 "control.\n"));
+               if (status != 0) {
+                       ret = -1;
+               }
+       }
+
+       return ret;
+}