git » nmdb » commit 0b70fcf

Make the default operations asynchronous.

author Alberto Bertogli
2006-09-12 15:54:05 UTC
committer Alberto Bertogli
2006-09-12 15:54:05 UTC
parent 21038447f6eeb6220112f5e2b1ca597c30fc8533

Make the default operations asynchronous.
This patch makes the default set and del operations asynchronous, adds new
set_sync and del_sync variants and removes the async ones as they're no longer
useful. It also updates the documentation and the python bindings.

libnmdb/libnmdb.3 +17 -15
libnmdb/libnmdb.c +8 -8
libnmdb/net-const.h +2 -2
nmdb/db.c +2 -2
nmdb/net-const.h +2 -2
nmdb/tipc.c +4 -4
python/nmdb.py +3 -3
python/nmdb_ll.c +10 -10

diff --git a/libnmdb/libnmdb.3 b/libnmdb/libnmdb.3
index 756940c..7554862 100644
--- a/libnmdb/libnmdb.3
+++ b/libnmdb/libnmdb.3
@@ -12,7 +12,7 @@ libnmdb - Library for interacting with a nmdb server
 .BI "int nmdb_set(nmdb_t *" db ","
 .BI "             const unsigned char *" key ", size_t " ksize ","
 .BI "             const unsigned char *" val ", size_t " vsize ");"
-.BI "int nmdb_set_async(nmdb_t *" db ","
+.BI "int nmdb_set_sync(nmdb_t *" db ","
 .BI "             const unsigned char *" key ", size_t " ksize ","
 .BI "             const unsigned char *" val ", size_t " vsize ");"
 .BI "int nmdb_cache_set(nmdb_t *" db ","
@@ -28,7 +28,7 @@ libnmdb - Library for interacting with a nmdb server
 .sp
 .BI "int nmdb_del(nmdb_t *" db ","
 .BI "             const unsigned char *" key ", size_t " ksize ");"
-.BI "int nmdb_del_async(nmdb_t *" db ","
+.BI "int nmdb_del_sync(nmdb_t *" db ","
 .BI "             const unsigned char *" key ", size_t " ksize ");"
 .BI "int nmdb_cache_del(nmdb_t *" db ","
 .BI "             const unsigned char *" key ", size_t " ksize ");"
@@ -69,17 +69,19 @@ There are three kinds of operations:
 .I get
 and
 .IR del ,
-with their obvious meaning. Each operation has variants, that make it behave
-in a different way. All three have "cache" variants, that only affect the
-cache and not the database; and
+with their obvious meaning. The normal set and del operations return as soon
+as they've been queued on the server for asynchronous completion. Note that in
+this case no message is sent to the client when the operation completes.
+
+Each operation has variants, that make it behave in a different way. All three
+have "cache" variants, that only affect the cache and not the database; and
 .I set
 and
 .I del
-have "async" variants that make the operation return inmediately, leaving it
-queued on the server for asynchronous execution. Note that in this case no
-message is sent to the client when the operation completes. All variants
-behave the same way as the original operation unless noted, so the following
-descriptions document them implicitly.
+have "sync" variants that make the operation return only after it's been
+acknowledge complete by the database backend. All variants behave the same way
+as the original operation unless noted, so the following descriptions document
+them implicitly.
 
 .BR nmdb_set ()
 is used to set the value associated with the given key. It returns 1 on
@@ -99,11 +101,11 @@ at by
 0 if the requested key was not in the database (or cache, if the cache variant
 is used), or < 0 on failure.
 
-.BR nmdb_cache_del ()
-is used to remove a given key (and it's associated value). It returns 1 if it
-was removed successfuly, 0 if the key was not in the database/cache, or < 0 on
-failure. In the asynchronous variant, success is always indicated by 1, and no
-distinction is made if the key was not in the database/cache.
+.BR nmdb_del ()
+is used to remove a given key (and it's associated value). The normal variant
+returns 1 if it was queued successfuly, or < 0 on failure. The cache and
+synchronous variant return 1 if the key was removed successfuly, 0 if the key
+was not in the database/cache, or < 0 on failure.
 
 .SH SEE ALSO
 
diff --git a/libnmdb/libnmdb.c b/libnmdb/libnmdb.c
index 01f13b3..a649cdc 100644
--- a/libnmdb/libnmdb.c
+++ b/libnmdb/libnmdb.c
@@ -201,7 +201,7 @@ static int do_set(nmdb_t *db, const unsigned char *key, size_t ksize,
 		if (async)
 			request = REQ_SET_ASYNC;
 		else
-			request = REQ_SET;
+			request = REQ_SET_SYNC;
 	} else {
 		request = REQ_CACHE_SET;
 	}
@@ -251,13 +251,13 @@ exit:
 int nmdb_set(nmdb_t *db, const unsigned char *key, size_t ksize,
 		const unsigned char *val, size_t vsize)
 {
-	return do_set(db, key, ksize, val, vsize, 1, 0);
+	return do_set(db, key, ksize, val, vsize, 1, 1);
 }
 
-int nmdb_set_async(nmdb_t *db, const unsigned char *key, size_t ksize,
+int nmdb_set_sync(nmdb_t *db, const unsigned char *key, size_t ksize,
 		const unsigned char *val, size_t vsize)
 {
-	return do_set(db, key, ksize, val, vsize, 1, 1);
+	return do_set(db, key, ksize, val, vsize, 1, 0);
 }
 
 int nmdb_cache_set(nmdb_t *db, const unsigned char *key, size_t ksize,
@@ -280,7 +280,7 @@ int do_del(nmdb_t *db, const unsigned char *key, size_t ksize,
 		if (async)
 			request = REQ_DEL_ASYNC;
 		else
-			request = REQ_DEL;
+			request = REQ_DEL_SYNC;
 	} else {
 		request = REQ_CACHE_DEL;
 	}
@@ -328,12 +328,12 @@ exit:
 
 int nmdb_del(nmdb_t *db, const unsigned char *key, size_t ksize)
 {
-	return do_del(db, key, ksize, 1, 0);
+	return do_del(db, key, ksize, 1, 1);
 }
 
-int nmdb_del_async(nmdb_t *db, const unsigned char *key, size_t ksize)
+int nmdb_del_sync(nmdb_t *db, const unsigned char *key, size_t ksize)
 {
-	return do_del(db, key, ksize, 1, 1);
+	return do_del(db, key, ksize, 1, 0);
 }
 
 int nmdb_cache_del(nmdb_t *db, const unsigned char *key, size_t ksize)
diff --git a/libnmdb/net-const.h b/libnmdb/net-const.h
index 159de4b..d485085 100644
--- a/libnmdb/net-const.h
+++ b/libnmdb/net-const.h
@@ -19,8 +19,8 @@
 #define REQ_CACHE_SET		0x102
 #define REQ_CACHE_DEL		0x103
 #define REQ_GET			0x104
-#define REQ_SET			0x105
-#define REQ_DEL			0x106
+#define REQ_SET_SYNC		0x105
+#define REQ_DEL_SYNC		0x106
 #define REQ_SET_ASYNC		0x107
 #define REQ_DEL_ASYNC		0x108
 
diff --git a/nmdb/db.c b/nmdb/db.c
index d1b7a68..7fac2f7 100644
--- a/nmdb/db.c
+++ b/nmdb/db.c
@@ -78,7 +78,7 @@ static void *db_loop(void *arg)
 static void process_op(db_t *db, struct queue_entry *e)
 {
 	int rv;
-	if (e->operation == REQ_SET) {
+	if (e->operation == REQ_SET_SYNC) {
 		rv = db_set(db, e->key, e->ksize, e->val, e->vsize);
 		if (!rv) {
 			tipc_reply_err(e->req, ERR_DB);
@@ -107,7 +107,7 @@ static void process_op(db_t *db, struct queue_entry *e)
 		tipc_reply_get(e->req, REP_OK, val, vsize);
 		free(val);
 
-	} else if (e->operation == REQ_DEL) {
+	} else if (e->operation == REQ_DEL_SYNC) {
 		rv = db_del(db, e->key, e->ksize);
 		if (rv == 0) {
 			tipc_reply_del(e->req, REP_NOTIN);
diff --git a/nmdb/net-const.h b/nmdb/net-const.h
index 159de4b..d485085 100644
--- a/nmdb/net-const.h
+++ b/nmdb/net-const.h
@@ -19,8 +19,8 @@
 #define REQ_CACHE_SET		0x102
 #define REQ_CACHE_DEL		0x103
 #define REQ_GET			0x104
-#define REQ_SET			0x105
-#define REQ_DEL			0x106
+#define REQ_SET_SYNC		0x105
+#define REQ_DEL_SYNC		0x106
 #define REQ_SET_ASYNC		0x107
 #define REQ_DEL_ASYNC		0x108
 
diff --git a/nmdb/tipc.c b/nmdb/tipc.c
index 1715d93..2e38266 100644
--- a/nmdb/tipc.c
+++ b/nmdb/tipc.c
@@ -317,9 +317,9 @@ static void parse_msg(struct req_info *req, unsigned char *buf, size_t bsize)
 		parse_del(req, 0, 0);
 	else if (cmd == REQ_GET)
 		parse_get(req, 1);
-	else if (cmd == REQ_SET)
+	else if (cmd == REQ_SET_SYNC)
 		parse_set(req, 1, 0);
-	else if (cmd == REQ_DEL)
+	else if (cmd == REQ_DEL_SYNC)
 		parse_del(req, 1, 0);
 	else if (cmd == REQ_SET_ASYNC)
 		parse_set(req, 1, 1);
@@ -418,7 +418,7 @@ static void parse_set(struct req_info *req, int impact_db, int async)
 		struct queue_entry *e;
 		uint32_t request;
 
-		request = REQ_SET;
+		request = REQ_SET_SYNC;
 		if (async)
 			request = REQ_SET_ASYNC;
 
@@ -467,7 +467,7 @@ static void parse_del(struct req_info *req, int impact_db, int async)
 		struct queue_entry *e;
 		uint32_t request;
 
-		request = REQ_DEL;
+		request = REQ_DEL_SYNC;
 		if (async)
 			request = REQ_DEL_ASYNC;
 
diff --git a/python/nmdb.py b/python/nmdb.py
index d460e30..8f14b58 100644
--- a/python/nmdb.py
+++ b/python/nmdb.py
@@ -64,10 +64,10 @@ class DB (_nmdbDict):
 		_nmdbDict.__init__(self, db, db.get, db.set, db.delete)
 
 
-class AsyncDB (_nmdbDict):
+class SyncDB (_nmdbDict):
 	def __init__(self, port = -1):
 		db = nmdb_ll.connect(port)
-		_nmdbDict.__init__(self, db, db.get, db.set_async,
-					db.delete_async)
+		_nmdbDict.__init__(self, db, db.get, db.set_sync,
+					db.delete_sync)
 
 
diff --git a/python/nmdb_ll.c b/python/nmdb_ll.c
index b963bb7..aa1c196 100644
--- a/python/nmdb_ll.c
+++ b/python/nmdb_ll.c
@@ -180,38 +180,38 @@ static PyObject *db_delete(nmdbobject *db, PyObject *args)
 }
 
 
-/* db set async */
-static PyObject *db_set_async(nmdbobject *db, PyObject *args)
+/* db set sync */
+static PyObject *db_set_sync(nmdbobject *db, PyObject *args)
 {
 	unsigned char *key, *val;
 	int ksize, vsize;
 	int rv;
 
-	if (!PyArg_ParseTuple(args, "s#s#:set_async", &key, &ksize,
+	if (!PyArg_ParseTuple(args, "s#s#:set_sync", &key, &ksize,
 				&val, &vsize)) {
 		return NULL;
 	}
 
 	Py_BEGIN_ALLOW_THREADS
-	rv = nmdb_set_async(db->db, key, ksize, val, vsize);
+	rv = nmdb_set_sync(db->db, key, ksize, val, vsize);
 	Py_END_ALLOW_THREADS
 
 	return PyLong_FromLong(rv);
 }
 
-/* db delete async */
-static PyObject *db_delete_async(nmdbobject *db, PyObject *args)
+/* db delete sync */
+static PyObject *db_delete_sync(nmdbobject *db, PyObject *args)
 {
 	unsigned char *key;
 	int ksize;
 	int rv;
 
-	if (!PyArg_ParseTuple(args, "s#:delete_async", &key, &ksize)) {
+	if (!PyArg_ParseTuple(args, "s#:delete_sync", &key, &ksize)) {
 		return NULL;
 	}
 
 	Py_BEGIN_ALLOW_THREADS
-	rv = nmdb_del_async(db->db, key, ksize);
+	rv = nmdb_del_sync(db->db, key, ksize);
 	Py_END_ALLOW_THREADS
 
 	return PyLong_FromLong(rv);
@@ -228,8 +228,8 @@ static PyMethodDef nmdb_methods[] = {
 	{ "set", (PyCFunction) db_set, METH_VARARGS, NULL },
 	{ "get", (PyCFunction) db_get, METH_VARARGS, NULL },
 	{ "delete", (PyCFunction) db_delete, METH_VARARGS, NULL },
-	{ "set_async", (PyCFunction) db_set_async, METH_VARARGS, NULL },
-	{ "delete_async", (PyCFunction) db_delete_async, METH_VARARGS, NULL },
+	{ "set_sync", (PyCFunction) db_set_sync, METH_VARARGS, NULL },
+	{ "delete_sync", (PyCFunction) db_delete_sync, METH_VARARGS, NULL },
 
 	{ NULL }
 };