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/fs/gnunet-service-fs_put.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/fs/gnunet-service-fs_put.c')
-rw-r--r-- | src/fs/gnunet-service-fs_put.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index bb4cb4ecb..cd062bf2b 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c | |||
@@ -72,9 +72,14 @@ struct PutOperator | |||
72 | uint64_t zero_anonymity_count_estimate; | 72 | uint64_t zero_anonymity_count_estimate; |
73 | 73 | ||
74 | /** | 74 | /** |
75 | * Current offset when iterating the database. | 75 | * Count of results received from the database. |
76 | */ | 76 | */ |
77 | uint64_t current_offset; | 77 | uint64_t result_count; |
78 | |||
79 | /** | ||
80 | * Next UID to request when iterating the database. | ||
81 | */ | ||
82 | uint64_t next_uid; | ||
78 | }; | 83 | }; |
79 | 84 | ||
80 | 85 | ||
@@ -177,37 +182,43 @@ delay_dht_put_task (void *cls) | |||
177 | */ | 182 | */ |
178 | static void | 183 | static void |
179 | process_dht_put_content (void *cls, | 184 | process_dht_put_content (void *cls, |
180 | const struct GNUNET_HashCode * key, | 185 | const struct GNUNET_HashCode * key, |
181 | size_t size, | 186 | size_t size, |
182 | const void *data, | 187 | const void *data, |
183 | enum GNUNET_BLOCK_Type type, | 188 | enum GNUNET_BLOCK_Type type, |
184 | uint32_t priority, uint32_t anonymity, | 189 | uint32_t priority, |
185 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 190 | uint32_t anonymity, |
191 | struct GNUNET_TIME_Absolute expiration, | ||
192 | uint64_t uid) | ||
186 | { | 193 | { |
187 | struct PutOperator *po = cls; | 194 | struct PutOperator *po = cls; |
188 | 195 | ||
189 | po->dht_qe = NULL; | 196 | po->dht_qe = NULL; |
190 | if (key == NULL) | 197 | if (key == NULL) |
191 | { | 198 | { |
192 | po->zero_anonymity_count_estimate = po->current_offset - 1; | 199 | po->zero_anonymity_count_estimate = po->result_count; |
193 | po->current_offset = 0; | 200 | po->result_count = 0; |
201 | po->next_uid = 0; | ||
194 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); | 202 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); |
195 | return; | 203 | return; |
196 | } | 204 | } |
205 | po->result_count++; | ||
206 | po->next_uid = uid + 1; | ||
197 | po->zero_anonymity_count_estimate = | 207 | po->zero_anonymity_count_estimate = |
198 | GNUNET_MAX (po->current_offset, po->zero_anonymity_count_estimate); | 208 | GNUNET_MAX (po->result_count, po->zero_anonymity_count_estimate); |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
200 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), | 210 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), |
201 | type); | 211 | type); |
202 | po->dht_put = GNUNET_DHT_put (GSF_dht, | 212 | po->dht_put = GNUNET_DHT_put (GSF_dht, |
203 | key, | 213 | key, |
204 | DEFAULT_PUT_REPLICATION, | 214 | DEFAULT_PUT_REPLICATION, |
205 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 215 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
206 | type, | 216 | type, |
207 | size, | 217 | size, |
208 | data, | 218 | data, |
209 | expiration, | 219 | expiration, |
210 | &delay_dht_put_blocks, po); | 220 | &delay_dht_put_blocks, |
221 | po); | ||
211 | } | 222 | } |
212 | 223 | ||
213 | 224 | ||
@@ -223,10 +234,13 @@ gather_dht_put_blocks (void *cls) | |||
223 | 234 | ||
224 | po->dht_task = NULL; | 235 | po->dht_task = NULL; |
225 | po->dht_qe = | 236 | po->dht_qe = |
226 | GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, po->current_offset++, 0, | 237 | GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, |
238 | po->next_uid, | ||
239 | 0, | ||
227 | UINT_MAX, | 240 | UINT_MAX, |
228 | po->dht_put_type, | 241 | po->dht_put_type, |
229 | &process_dht_put_content, po); | 242 | &process_dht_put_content, |
243 | po); | ||
230 | if (NULL == po->dht_qe) | 244 | if (NULL == po->dht_qe) |
231 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); | 245 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); |
232 | } | 246 | } |