add a new ctdb_ltdb function to delete a record in a normal database
[metze/ctdb/wip.git] / common / ctdb_ltdb.c
index b2fd189943251fc3db6fe93b9c663ef67d63e9e5..35723714d0c9c6b8e886cf6990c1e4825e569381 100644 (file)
@@ -18,7 +18,7 @@
 */
 
 #include "includes.h"
-#include "lib/events/events.h"
+#include "lib/tevent/tevent.h"
 #include "lib/tdb/include/tdb.h"
 #include "system/network.h"
 #include "system/filesys.h"
@@ -191,7 +191,26 @@ int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key)
 {
        int ret = tdb_chainunlock(ctdb_db->ltdb->tdb, key);
        if (ret != 0) {
-               DEBUG(DEBUG_ERR,("tdb_chainunlock failed\n"));
+               DEBUG(DEBUG_ERR,("tdb_chainunlock failed on db %s [%s]\n", ctdb_db->db_name, tdb_errorstr(ctdb_db->ltdb->tdb)));
        }
        return ret;
 }
+
+
+/*
+  delete a record from a normal database
+*/
+int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key)
+{
+       struct ctdb_context *ctdb = ctdb_db->ctdb;
+
+       if (ctdb_db->persistent != 0) {
+               DEBUG(DEBUG_ERR,("Trying to delete emty record in persistent database\n"));
+               return 0;
+       }
+       if (tdb_delete(ctdb_db->ltdb->tdb, key) != 0) {
+               DEBUG(DEBUG_ERR,("Failed to delete empty record."));
+               return -1;
+       }
+       return 0;
+}