add a function ctdb_writerecord() to write a record to the database.
[sahlberg/ctdb.git] / include / ctdb.h
index d44fca229d2da0dc6a8df865af9d84230b8c3ead..d0b9507711a63efdb6b8e681922162643c840c75 100644 (file)
@@ -68,11 +68,11 @@ typedef void ctdb_handle;
  * functions to attach to a database
  * if the database does not exist it will be created.
  *
- * Use ctdb_free() to release the returned ctdb_db_context when finished.
+ * You have to free the handle with ctdb_free() when finished with it.
  */
 struct ctdb_db_context;
 
-typedef void (*ctdb_attachdb_cb)(int32_t status, struct ctdb_db_context *ctdb_db, void *private_data);
+typedef void (*ctdb_attachdb_cb)(int32_t status, ctdb_handle *, struct ctdb_db_context *ctdb_db, void *private_data);
 
 ctdb_handle *
 ctdb_attachdb_send(struct ctdb_context *ctdb,
@@ -86,6 +86,47 @@ int ctdb_attachdb(struct ctdb_context *ctdb,
                  struct ctdb_db_context **);
 
 
+/*
+ * functions to read a record from the database
+ * when the callback is invoked, the client will hold an exclusive lock
+ * on the record, until the handle is ctdb_free()d.
+ * the client MUST NOT block during holding this lock and MUST
+ * release it quickly by performing ctdb_free(handle).
+ *
+ * When the handle is freed, data is freed too, so make sure to copy the data
+ * before freeing the handle.
+ */
+typedef void (*ctdb_readrecordlock_cb)(int32_t status, ctdb_handle *handle, TDB_DATA data, void *private_data);
+
+ctdb_handle *
+ctdb_readrecordlock_send(struct ctdb_context *ctdb,
+               struct ctdb_db_context *ctdb_db_context,
+               TDB_DATA key,
+               ctdb_readrecordlock_cb callback,
+               void *private_data);
+int ctdb_readrecordlock_recv(struct ctdb_context *ctdb,
+               ctdb_handle *handle,
+               TDB_DATA **data);
+int ctdb_readrecordlock(struct ctdb_context *ctdb,
+               struct ctdb_db_context *ctdb_db_context,
+               TDB_DATA key,
+               TDB_DATA **data);
+
+
+
+/*
+ * Function to write data to a record
+ * This function may ONLY be called while holding a lock to the record 
+ * created by ctdb_readrecordlock*
+ * Either from the callback provided to ctdb_readrecordlock_send()
+ * or after calling ctdb_readrecordlock_recv() but before calling
+ * ctdb_free() to release the handle.
+ */
+int ctdb_writerecord(ctdb_handle *handle,
+               TDB_DATA key,
+               TDB_DATA data);
+
+
 
 /*
  * messaging functions