better datastore API
authorChristian Grothoff <christian@grothoff.org>
Fri, 11 Sep 2009 14:21:00 +0000 (14:21 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 11 Sep 2009 14:21:00 +0000 (14:21 +0000)
src/datastore/datastore_api.c
src/datastore/perf_datastore_api.c
src/datastore/test_datastore_api.c
src/datastore/test_datastore_api_management.c
src/include/gnunet_datastore_service.h

index 7b674087ecc60a50f76c33b15aff30ae923e7c03..58fb5a79592544cd39808a8726b1d2e95870e1dd 100644 (file)
@@ -566,10 +566,6 @@ with_result_response_handler (void *cls,
        ntohl(dm->anonymity),
        GNUNET_TIME_absolute_ntoh(dm->expiration),      
        GNUNET_ntohll(dm->uid));
-  GNUNET_CLIENT_receive (h->client,
-                        &with_result_response_handler,
-                        h,
-                        GNUNET_TIME_absolute_get_remaining (h->timeout));
 }
 
 
@@ -618,6 +614,39 @@ transmit_get_result (void *cls,
 }
 
 
+
+/**
+ * Function called to trigger obtaining the next result
+ * from the datastore.
+ * 
+ * @param h handle to the datastore
+ * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
+ *        iteration (with a final call to "iter" with key/data == NULL).
+ */
+void 
+GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
+                          int more)
+{
+  GNUNET_DATASTORE_Iterator cont;
+
+  if (GNUNET_YES == more)
+    {
+      GNUNET_CLIENT_receive (h->client,
+                            &with_result_response_handler,
+                            h,
+                            GNUNET_TIME_absolute_get_remaining (h->timeout));
+      return;
+    }
+  cont = h->response_proc;
+  h->response_proc = NULL;
+  GNUNET_CLIENT_disconnect (h->client);
+  h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
+  cont (h->response_proc_cls, 
+       NULL, 0, NULL, 0, 0, 0, 
+       GNUNET_TIME_UNIT_ZERO_ABS, 0);
+}
+
+
 /**
  * Helper function that will initiate the
  * transmission of a message to the datastore
index 626fbcf73d848bba2776581d3a8a67d7ffaa5c0a..4ba8216bf89bd8a4e292034b44e2ce5619edf35b 100644 (file)
@@ -230,10 +230,14 @@ delete_value (void *cls,
     }
   stored_ops++;
   if (stored_bytes < MAX_SIZE)
-    return;     
+    {
+      GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
+      return;     
+    }
   crc->key = *key;
   crc->esize = size;
   memcpy (crc->data, data, size);
+  GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
 }
 
 
index e8e303436dcfff8b97c1d2a87a941d2b2a1ebe76..a63f0425f85d09749b29c12acc54d2be092ea01c 100644 (file)
@@ -207,6 +207,7 @@ check_value (void *cls,
   GNUNET_assert (priority == get_priority (i));
   GNUNET_assert (anonymity == get_anonymity(i));
   GNUNET_assert (expiration.value == get_expiration(i).value);
+  GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
 }
 
 
@@ -237,6 +238,7 @@ delete_value (void *cls,
   crc->key = *key;
   crc->data = GNUNET_malloc (size);
   memcpy (crc->data, data, size);
+  GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
 }
 
 
@@ -292,6 +294,7 @@ check_multiple (void *cls,
   crc->phase++;
   if (priority == get_priority (42))
     crc->uid = uid;
+  GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
 }
 
 
@@ -327,6 +330,7 @@ check_update (void *cls,
     }
   else
     GNUNET_assert (size == get_size (43));
+  GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
 }
 
 
index fadb77131b3be9912fe0423bdff3a61d34efc406..54289dd7b3905b4f05546890bbc2701f565b6b20 100644 (file)
@@ -186,6 +186,7 @@ check_value (void *cls,
   GNUNET_assert (priority == get_priority (i));
   GNUNET_assert (anonymity == get_anonymity(i));
   GNUNET_assert (expiration.value == get_expiration(i).value);
+  GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
 }
 
 
index 7c1fd196162eec45c43632caa9c2b502d66b7f9a..bcc89a8e17ec557e508db0a19e5b044ba5e47a9f 100644 (file)
@@ -218,7 +218,10 @@ typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
 
 /**
  * Iterate over the results for a particular key
- * in the datastore.
+ * in the datastore.  The iterator will only be called
+ * once initially; if the first call did contain a
+ * result, further results can be obtained by calling
+ * "GNUNET_DATASTORE_get_next" with the given argument.
  *
  * @param h handle to the datastore
  * @param key maybe NULL (to match all entries)
@@ -232,10 +235,24 @@ void
 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
                       const GNUNET_HashCode * key,
                      uint32_t type,
-                      GNUNET_DATASTORE_Iterator iter, void *iter_cls,
+                      GNUNET_DATASTORE_Iterator iter, 
+                     void *iter_cls,
                      struct GNUNET_TIME_Relative timeout);
 
 
+/**
+ * Function called to trigger obtaining the next result
+ * from the datastore.
+ * 
+ * @param h handle to the datastore
+ * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
+ *        iteration (with a final call to "iter" with key/data == NULL).
+ */
+void
+GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
+                          int more);
+
+
 /**
  * Get a random value from the datastore.
  *