aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/datastore_api.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amat.us>2017-03-19 15:55:32 -0500
committerDavid Barksdale <amatus@amat.us>2017-03-19 17:38:36 -0500
commit2dde0202c5590eeb051c1346f2b66293d83b87ce (patch)
tree7997191912ee4c70959934d6c9783a0c9f450fec /src/datastore/datastore_api.c
parentd17d833dfd93a81f3540d472d1be4dfb7e9cbd03 (diff)
downloadgnunet-2dde0202c5590eeb051c1346f2b66293d83b87ce.tar.gz
gnunet-2dde0202c5590eeb051c1346f2b66293d83b87ce.zip
[datastore] Fix #3743
This change adds support for key == NULL to the datastore plugins and replaces the offset argument with a next_uid and random arguments to increase performance in the key == NULL case. With the offset argument a datastore plugin would have to count all matching keys before fetching the key at the right offset, which would iterate over the entire database in the case of key == NULL. The offset argument was used in two ways: to iterate over a set of matching values and to start iteration at a random matching value. The new API seperates these into two arguments: if random is true it will return a random matching value, otherwise next_uid can be set to uid + 1 to return the next matching value. The random argument was not added to get_zero_anonymity. This function is used to periodically insert zero anonymity values into the DHT. I don't think it's necessary to randomize this.
Diffstat (limited to 'src/datastore/datastore_api.c')
-rw-r--r--src/datastore/datastore_api.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index c677654aa..26e1e501d 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -1325,10 +1325,7 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
1325 * Get a single zero-anonymity value from the datastore. 1325 * Get a single zero-anonymity value from the datastore.
1326 * 1326 *
1327 * @param h handle to the datastore 1327 * @param h handle to the datastore
1328 * @param offset offset of the result (modulo num-results); set to 1328 * @param next_uid return the result with lowest uid >= next_uid
1329 * a random 64-bit value initially; then increment by
1330 * one each time; detect that all results have been found by uid
1331 * being again the first uid ever returned.
1332 * @param queue_priority ranking of this request in the priority queue 1329 * @param queue_priority ranking of this request in the priority queue
1333 * @param max_queue_size at what queue size should this request be dropped 1330 * @param max_queue_size at what queue size should this request be dropped
1334 * (if other requests of higher priority are in the queue) 1331 * (if other requests of higher priority are in the queue)
@@ -1342,7 +1339,7 @@ GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
1342 */ 1339 */
1343struct GNUNET_DATASTORE_QueueEntry * 1340struct GNUNET_DATASTORE_QueueEntry *
1344GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, 1341GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1345 uint64_t offset, 1342 uint64_t next_uid,
1346 unsigned int queue_priority, 1343 unsigned int queue_priority,
1347 unsigned int max_queue_size, 1344 unsigned int max_queue_size,
1348 enum GNUNET_BLOCK_Type type, 1345 enum GNUNET_BLOCK_Type type,
@@ -1357,13 +1354,12 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1357 GNUNET_assert (NULL != proc); 1354 GNUNET_assert (NULL != proc);
1358 GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); 1355 GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
1359 LOG (GNUNET_ERROR_TYPE_DEBUG, 1356 LOG (GNUNET_ERROR_TYPE_DEBUG,
1360 "Asked to get %llu-th zero-anonymity entry of type %d\n", 1357 "Asked to get a zero-anonymity entry of type %d\n",
1361 (unsigned long long) offset,
1362 type); 1358 type);
1363 env = GNUNET_MQ_msg (m, 1359 env = GNUNET_MQ_msg (m,
1364 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY); 1360 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
1365 m->type = htonl ((uint32_t) type); 1361 m->type = htonl ((uint32_t) type);
1366 m->offset = GNUNET_htonll (offset); 1362 m->next_uid = GNUNET_htonll (next_uid);
1367 qc.rc.proc = proc; 1363 qc.rc.proc = proc;
1368 qc.rc.proc_cls = proc_cls; 1364 qc.rc.proc_cls = proc_cls;
1369 qe = make_queue_entry (h, 1365 qe = make_queue_entry (h,
@@ -1392,10 +1388,8 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1392 * will only be called once. 1388 * will only be called once.
1393 * 1389 *
1394 * @param h handle to the datastore 1390 * @param h handle to the datastore
1395 * @param offset offset of the result (modulo num-results); set to 1391 * @param next_uid return the result with lowest uid >= next_uid
1396 * a random 64-bit value initially; then increment by 1392 * @param random if true, return a random result instead of using next_uid
1397 * one each time; detect that all results have been found by uid
1398 * being again the first uid ever returned.
1399 * @param key maybe NULL (to match all entries) 1393 * @param key maybe NULL (to match all entries)
1400 * @param type desired type, 0 for any 1394 * @param type desired type, 0 for any
1401 * @param queue_priority ranking of this request in the priority queue 1395 * @param queue_priority ranking of this request in the priority queue
@@ -1409,7 +1403,8 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1409 */ 1403 */
1410struct GNUNET_DATASTORE_QueueEntry * 1404struct GNUNET_DATASTORE_QueueEntry *
1411GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, 1405GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
1412 uint64_t offset, 1406 uint64_t next_uid,
1407 bool random,
1413 const struct GNUNET_HashCode *key, 1408 const struct GNUNET_HashCode *key,
1414 enum GNUNET_BLOCK_Type type, 1409 enum GNUNET_BLOCK_Type type,
1415 unsigned int queue_priority, 1410 unsigned int queue_priority,
@@ -1433,14 +1428,16 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
1433 env = GNUNET_MQ_msg (gm, 1428 env = GNUNET_MQ_msg (gm,
1434 GNUNET_MESSAGE_TYPE_DATASTORE_GET); 1429 GNUNET_MESSAGE_TYPE_DATASTORE_GET);
1435 gm->type = htonl (type); 1430 gm->type = htonl (type);
1436 gm->offset = GNUNET_htonll (offset); 1431 gm->next_uid = GNUNET_htonll (next_uid);
1432 gm->random = random;
1437 } 1433 }
1438 else 1434 else
1439 { 1435 {
1440 env = GNUNET_MQ_msg (gkm, 1436 env = GNUNET_MQ_msg (gkm,
1441 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY); 1437 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY);
1442 gkm->type = htonl (type); 1438 gkm->type = htonl (type);
1443 gkm->offset = GNUNET_htonll (offset); 1439 gkm->next_uid = GNUNET_htonll (next_uid);
1440 gkm->random = random;
1444 gkm->key = *key; 1441 gkm->key = *key;
1445 } 1442 }
1446 qc.rc.proc = proc; 1443 qc.rc.proc = proc;