diff options
author | David Barksdale <amatus@amat.us> | 2017-03-19 15:55:32 -0500 |
---|---|---|
committer | David Barksdale <amatus@amat.us> | 2017-03-19 17:38:36 -0500 |
commit | 2dde0202c5590eeb051c1346f2b66293d83b87ce (patch) | |
tree | 7997191912ee4c70959934d6c9783a0c9f450fec /src/include | |
parent | d17d833dfd93a81f3540d472d1be4dfb7e9cbd03 (diff) | |
download | gnunet-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/include')
-rw-r--r-- | src/include/gnunet_datastore_plugin.h | 41 | ||||
-rw-r--r-- | src/include/gnunet_datastore_service.h | 20 | ||||
-rw-r--r-- | src/include/platform.h | 1 |
3 files changed, 26 insertions, 36 deletions
diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h index 2295d4e72..b1c9cb7c3 100644 --- a/src/include/gnunet_datastore_plugin.h +++ b/src/include/gnunet_datastore_plugin.h | |||
@@ -204,9 +204,9 @@ typedef void | |||
204 | * Get one of the results for a particular key in the datastore. | 204 | * Get one of the results for a particular key in the datastore. |
205 | * | 205 | * |
206 | * @param cls closure | 206 | * @param cls closure |
207 | * @param offset offset of the result (modulo num-results); | 207 | * @param next_uid return the result with lowest uid >= next_uid |
208 | * specific ordering does not matter for the offset | 208 | * @param random if true, return a random result instead of using next_uid |
209 | * @param key key to match, never NULL | 209 | * @param key maybe NULL (to match all entries) |
210 | * @param vhash hash of the value, maybe NULL (to | 210 | * @param vhash hash of the value, maybe NULL (to |
211 | * match all values that have the right key). | 211 | * match all values that have the right key). |
212 | * Note that for DBlocks there is no difference | 212 | * Note that for DBlocks there is no difference |
@@ -215,17 +215,18 @@ typedef void | |||
215 | * @param type entries of which type are relevant? | 215 | * @param type entries of which type are relevant? |
216 | * Use 0 for any type. | 216 | * Use 0 for any type. |
217 | * @param proc function to call on the matching value; | 217 | * @param proc function to call on the matching value; |
218 | * proc should be called with NULL if there is no result | 218 | * will be called with NULL if nothing matches |
219 | * @param proc_cls closure for @a proc | 219 | * @param proc_cls closure for @a proc |
220 | */ | 220 | */ |
221 | typedef void | 221 | typedef void |
222 | (*PluginGetKey) (void *cls, | 222 | (*PluginGetKey) (void *cls, |
223 | uint64_t offset, | 223 | uint64_t next_uid, |
224 | const struct GNUNET_HashCode *key, | 224 | bool random, |
225 | const struct GNUNET_HashCode *vhash, | 225 | const struct GNUNET_HashCode *key, |
226 | enum GNUNET_BLOCK_Type type, | 226 | const struct GNUNET_HashCode *vhash, |
227 | PluginDatumProcessor proc, | 227 | enum GNUNET_BLOCK_Type type, |
228 | void *proc_cls); | 228 | PluginDatumProcessor proc, |
229 | void *proc_cls); | ||
229 | 230 | ||
230 | 231 | ||
231 | /** | 232 | /** |
@@ -285,23 +286,22 @@ typedef void | |||
285 | 286 | ||
286 | 287 | ||
287 | /** | 288 | /** |
288 | * Select a single item from the datastore at the specified offset | 289 | * Select a single item from the datastore (among those applicable). |
289 | * (among those applicable). | ||
290 | * | 290 | * |
291 | * @param cls closure | 291 | * @param cls closure |
292 | * @param offset offset of the result (modulo num-results); | 292 | * @param next_uid return the result with lowest uid >= next_uid |
293 | * specific ordering does not matter for the offset | ||
294 | * @param type entries of which type should be considered? | 293 | * @param type entries of which type should be considered? |
295 | * Must not be zero (ANY). | 294 | * Must not be zero (ANY). |
296 | * @param proc function to call on the matching value | 295 | * @param proc function to call on the matching value; |
296 | * will be called with NULL if no value matches | ||
297 | * @param proc_cls closure for @a proc | 297 | * @param proc_cls closure for @a proc |
298 | */ | 298 | */ |
299 | typedef void | 299 | typedef void |
300 | (*PluginGetType) (void *cls, | 300 | (*PluginGetType) (void *cls, |
301 | uint64_t offset, | 301 | uint64_t next_uid, |
302 | enum GNUNET_BLOCK_Type type, | 302 | enum GNUNET_BLOCK_Type type, |
303 | PluginDatumProcessor proc, | 303 | PluginDatumProcessor proc, |
304 | void *proc_cls); | 304 | void *proc_cls); |
305 | 305 | ||
306 | 306 | ||
307 | /** | 307 | /** |
@@ -354,9 +354,6 @@ struct GNUNET_DATASTORE_PluginFunctions | |||
354 | 354 | ||
355 | /** | 355 | /** |
356 | * Get datum (of the specified type) with anonymity level zero. | 356 | * Get datum (of the specified type) with anonymity level zero. |
357 | * This function is allowed to ignore the 'offset' argument | ||
358 | * and instead return a random result (with zero anonymity of | ||
359 | * the correct type) if implementing an offset is expensive. | ||
360 | */ | 357 | */ |
361 | PluginGetType get_zero_anonymity; | 358 | PluginGetType get_zero_anonymity; |
362 | 359 | ||
diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 233598667..830e7da86 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h | |||
@@ -261,10 +261,8 @@ typedef void | |||
261 | * will only be called once. | 261 | * will only be called once. |
262 | * | 262 | * |
263 | * @param h handle to the datastore | 263 | * @param h handle to the datastore |
264 | * @param offset offset of the result (modulo num-results); set to | 264 | * @param next_uid return the result with lowest uid >= next_uid |
265 | * a random 64-bit value initially; then increment by | 265 | * @param random if true, return a random result instead of using next_uid |
266 | * one each time; detect that all results have been found by uid | ||
267 | * being again the first uid ever returned. | ||
268 | * @param key maybe NULL (to match all entries) | 266 | * @param key maybe NULL (to match all entries) |
269 | * @param type desired type, 0 for any | 267 | * @param type desired type, 0 for any |
270 | * @param queue_priority ranking of this request in the priority queue | 268 | * @param queue_priority ranking of this request in the priority queue |
@@ -278,7 +276,8 @@ typedef void | |||
278 | */ | 276 | */ |
279 | struct GNUNET_DATASTORE_QueueEntry * | 277 | struct GNUNET_DATASTORE_QueueEntry * |
280 | GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | 278 | GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, |
281 | uint64_t offset, | 279 | uint64_t next_uid, |
280 | bool random, | ||
282 | const struct GNUNET_HashCode *key, | 281 | const struct GNUNET_HashCode *key, |
283 | enum GNUNET_BLOCK_Type type, | 282 | enum GNUNET_BLOCK_Type type, |
284 | unsigned int queue_priority, | 283 | unsigned int queue_priority, |
@@ -289,16 +288,9 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | |||
289 | 288 | ||
290 | /** | 289 | /** |
291 | * Get a single zero-anonymity value from the datastore. | 290 | * Get a single zero-anonymity value from the datastore. |
292 | * Note that some implementations can ignore the 'offset' and | ||
293 | * instead return a random zero-anonymity value. In that case, | ||
294 | * detecting the wrap-around based on a repeating UID is at best | ||
295 | * probabilistic. | ||
296 | * | 291 | * |
297 | * @param h handle to the datastore | 292 | * @param h handle to the datastore |
298 | * @param offset offset of the result (modulo num-results); set to | 293 | * @param next_uid return the result with lowest uid >= next_uid |
299 | * a random 64-bit value initially; then increment by | ||
300 | * one each time; detect that all results have been found by uid | ||
301 | * being again the first uid ever returned. | ||
302 | * @param queue_priority ranking of this request in the priority queue | 294 | * @param queue_priority ranking of this request in the priority queue |
303 | * @param max_queue_size at what queue size should this request be dropped | 295 | * @param max_queue_size at what queue size should this request be dropped |
304 | * (if other requests of higher priority are in the queue) | 296 | * (if other requests of higher priority are in the queue) |
@@ -312,7 +304,7 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | |||
312 | */ | 304 | */ |
313 | struct GNUNET_DATASTORE_QueueEntry * | 305 | struct GNUNET_DATASTORE_QueueEntry * |
314 | GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, | 306 | GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, |
315 | uint64_t offset, | 307 | uint64_t next_uid, |
316 | unsigned int queue_priority, | 308 | unsigned int queue_priority, |
317 | unsigned int max_queue_size, | 309 | unsigned int max_queue_size, |
318 | enum GNUNET_BLOCK_Type type, | 310 | enum GNUNET_BLOCK_Type type, |
diff --git a/src/include/platform.h b/src/include/platform.h index add58821f..6095d0258 100644 --- a/src/include/platform.h +++ b/src/include/platform.h | |||
@@ -110,6 +110,7 @@ | |||
110 | #include <stdlib.h> | 110 | #include <stdlib.h> |
111 | #include <stdint.h> | 111 | #include <stdint.h> |
112 | #include <stdarg.h> | 112 | #include <stdarg.h> |
113 | #include <stdbool.h> | ||
113 | #include <errno.h> | 114 | #include <errno.h> |
114 | #include <signal.h> | 115 | #include <signal.h> |
115 | #include <libgen.h> | 116 | #include <libgen.h> |