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/datastore/plugin_datastore_template.c | |
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/datastore/plugin_datastore_template.c')
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index a1e03e8ee..187221798 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c | |||
@@ -89,8 +89,8 @@ template_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t siz | |||
89 | * Get one of the results for a particular key in the datastore. | 89 | * Get one of the results for a particular key in the datastore. |
90 | * | 90 | * |
91 | * @param cls closure | 91 | * @param cls closure |
92 | * @param offset offset of the result (modulo num-results); | 92 | * @param next_uid return the result with lowest uid >= next_uid |
93 | * specific ordering does not matter for the offset | 93 | * @param random if true, return a random result instead of using next_uid |
94 | * @param key maybe NULL (to match all entries) | 94 | * @param key maybe NULL (to match all entries) |
95 | * @param vhash hash of the value, maybe NULL (to | 95 | * @param vhash hash of the value, maybe NULL (to |
96 | * match all values that have the right key). | 96 | * match all values that have the right key). |
@@ -104,7 +104,7 @@ template_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t siz | |||
104 | * @param proc_cls closure for proc | 104 | * @param proc_cls closure for proc |
105 | */ | 105 | */ |
106 | static void | 106 | static void |
107 | template_plugin_get_key (void *cls, uint64_t offset, | 107 | template_plugin_get_key (void *cls, uint64_t next_uid, bool random, |
108 | const struct GNUNET_HashCode * key, | 108 | const struct GNUNET_HashCode * key, |
109 | const struct GNUNET_HashCode * vhash, | 109 | const struct GNUNET_HashCode * vhash, |
110 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, | 110 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, |
@@ -185,16 +185,15 @@ template_plugin_update (void *cls, uint64_t uid, uint32_t delta, | |||
185 | * Call the given processor on an item with zero anonymity. | 185 | * Call the given processor on an item with zero anonymity. |
186 | * | 186 | * |
187 | * @param cls our "struct Plugin*" | 187 | * @param cls our "struct Plugin*" |
188 | * @param offset offset of the result (modulo num-results); | 188 | * @param next_uid return the result with lowest uid >= next_uid |
189 | * specific ordering does not matter for the offset | ||
190 | * @param type entries of which type should be considered? | 189 | * @param type entries of which type should be considered? |
191 | * Use 0 for any type. | 190 | * Must not be zero (ANY). |
192 | * @param proc function to call on each matching value; | 191 | * @param proc function to call on the matching value; |
193 | * will be called with NULL if no value matches | 192 | * will be called with NULL if no value matches |
194 | * @param proc_cls closure for proc | 193 | * @param proc_cls closure for proc |
195 | */ | 194 | */ |
196 | static void | 195 | static void |
197 | template_plugin_get_zero_anonymity (void *cls, uint64_t offset, | 196 | template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, |
198 | enum GNUNET_BLOCK_Type type, | 197 | enum GNUNET_BLOCK_Type type, |
199 | PluginDatumProcessor proc, void *proc_cls) | 198 | PluginDatumProcessor proc, void *proc_cls) |
200 | { | 199 | { |