vacuum: add ctdb_local_remove_from_delete_queue()
authorMichael Adam <obnox@samba.org>
Thu, 7 Apr 2011 10:17:16 +0000 (12:17 +0200)
committerAmitay Isaacs <amitay@gmail.com>
Thu, 18 Apr 2013 04:05:40 +0000 (14:05 +1000)
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit a5065b42a98c709173503e02d217f97792878625)

include/ctdb_private.h
server/ctdb_vacuum.c

index 0eef0e30f66673280ee078a3d6064d54c6f82831..0477628362362f2315115008eb0204fdcf10f332 100644 (file)
@@ -1441,6 +1441,10 @@ int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
                                         const struct ctdb_ltdb_header *hdr,
                                         TDB_DATA key);
 
+void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
+                                        const struct ctdb_ltdb_header *hdr,
+                                        const TDB_DATA key);
+
 struct ctdb_ltdb_header *ctdb_header_from_record_handle(struct ctdb_record_handle *h);
 
 /* For unit testing ctdb_transaction.c. */
index bb71be7437a5dea991c585ff1a017ebbbe4b9c95..62b74b3a3f14e80b2f5d1a1c5e80b79f1e059ae9 100644 (file)
@@ -1276,6 +1276,42 @@ int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db)
        return 0;
 }
 
+static void remove_record_from_delete_queue(struct ctdb_db_context *ctdb_db,
+                                           const struct ctdb_ltdb_header *hdr,
+                                           const TDB_DATA key)
+{
+       struct delete_record_data *kd;
+       uint32_t hash;
+
+       hash = (uint32_t)ctdb_hash(&key);
+
+       DEBUG(DEBUG_DEBUG, (__location__
+                           " remove_record_from_delete_queue: db[%s] "
+                           "db_id[0x%08x] "
+                           "key_hash[0x%08x] "
+                           "lmaster[%u] "
+                           "migrated_with_data[%s]\n",
+                            ctdb_db->db_name, ctdb_db->db_id,
+                            hash,
+                            ctdb_lmaster(ctdb_db->ctdb, &key),
+                            hdr->flags & CTDB_REC_FLAG_MIGRATED_WITH_DATA ? "yes" : "no"));
+
+       kd = (struct delete_record_data *)trbt_lookup32(ctdb_db->delete_queue, hash);
+       if (kd == NULL) {
+               return;
+       }
+       if (kd->key.dsize != key.dsize) {
+               return;
+       }
+       if (memcmp(kd->key.dptr, key.dptr, key.dsize) != 0) {
+               return;
+       }
+
+       talloc_free(kd);
+
+       return;
+}
+
 /**
  * Insert a record into the ctdb_db context's delete queue,
  * handling hash collisions.
@@ -1418,3 +1454,20 @@ int32_t ctdb_local_schedule_for_deletion(struct ctdb_db_context *ctdb_db,
 
        return ret;
 }
+
+void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db,
+                                        const struct ctdb_ltdb_header *hdr,
+                                        const TDB_DATA key)
+{
+       if (ctdb_db->ctdb->ctdbd_pid != getpid()) {
+               /*
+                * Only remove the record from the delete queue if called
+                * in the main daemon.
+                */
+               return;
+       }
+
+       remove_record_from_delete_queue(ctdb_db, hdr, key);
+
+       return;
+}