aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-04-26 18:19:15 +0000
committerChristian Grothoff <christian@grothoff.org>2011-04-26 18:19:15 +0000
commit27ed8fcbc85a361864948edb517d47804c2b5a56 (patch)
tree01626713ea5b2ead4691f13eb66a1574b1c0c7fd /src/include
parentb6c71d97d2a4bb3cb0e0e0ac1cd2a4e145748cc6 (diff)
downloadgnunet-27ed8fcbc85a361864948edb517d47804c2b5a56.tar.gz
gnunet-27ed8fcbc85a361864948edb517d47804c2b5a56.zip
datastore and fs fixes from Easter
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_datastore_plugin.h143
-rw-r--r--src/include/gnunet_datastore_service.h109
2 files changed, 104 insertions, 148 deletions
diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h
index a5c548146..4d717996d 100644
--- a/src/include/gnunet_datastore_plugin.h
+++ b/src/include/gnunet_datastore_plugin.h
@@ -78,26 +78,9 @@ struct GNUNET_DATASTORE_PluginEnvironment
78 78
79 79
80/** 80/**
81 * Function invoked on behalf of a "PluginIterator" 81 * An processor over a set of items stored in the datastore.
82 * asking the database plugin to call the iterator
83 * with the next item.
84 *
85 * @param next_cls whatever argument was given
86 * to the PluginIterator as "next_cls".
87 * @param end_it set to GNUNET_YES if we
88 * should terminate the iteration early
89 * (iterator should be still called once more
90 * to signal the end of the iteration).
91 */
92typedef void (*PluginNextRequest)(void *next_cls,
93 int end_it);
94
95
96/**
97 * An iterator over a set of items stored in the datastore.
98 * 82 *
99 * @param cls closure 83 * @param cls closure
100 * @param next_cls closure to pass to the "next" function.
101 * @param key key for the content 84 * @param key key for the content
102 * @param size number of bytes in data 85 * @param size number of bytes in data
103 * @param data content stored 86 * @param data content stored
@@ -105,24 +88,21 @@ typedef void (*PluginNextRequest)(void *next_cls,
105 * @param priority priority of the content 88 * @param priority priority of the content
106 * @param anonymity anonymity-level for the content 89 * @param anonymity anonymity-level for the content
107 * @param expiration expiration time for the content 90 * @param expiration expiration time for the content
108 * @param uid unique identifier for the datum; 91 * @param uid unique identifier for the datum
109 * maybe 0 if no unique identifier is available
110 * 92 *
111 * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue 93 * @return GNUNET_OK to keep the item
112 * (continue on call to "next", of course), 94 * GNUNET_NO to delete the item
113 * GNUNET_NO to delete the item and continue (if supported)
114 */ 95 */
115typedef int (*PluginIterator) (void *cls, 96typedef int (*PluginDatumProcessor) (void *cls,
116 void *next_cls, 97 const GNUNET_HashCode * key,
117 const GNUNET_HashCode * key, 98 uint32_t size,
118 uint32_t size, 99 const void *data,
119 const void *data, 100 enum GNUNET_BLOCK_Type type,
120 enum GNUNET_BLOCK_Type type, 101 uint32_t priority,
121 uint32_t priority, 102 uint32_t anonymity,
122 uint32_t anonymity, 103 struct GNUNET_TIME_Absolute
123 struct GNUNET_TIME_Absolute 104 expiration,
124 expiration, 105 uint64_t uid);
125 uint64_t uid);
126 106
127/** 107/**
128 * Get an estimate of how much space the database is 108 * Get an estimate of how much space the database is
@@ -131,7 +111,7 @@ typedef int (*PluginIterator) (void *cls,
131 * @param cls closure 111 * @param cls closure
132 * @return number of bytes used on disk 112 * @return number of bytes used on disk
133 */ 113 */
134typedef unsigned long long (*PluginGetSize) (void *cls); 114typedef unsigned long long (*PluginEstimateSize) (void *cls);
135 115
136 116
137/** 117/**
@@ -165,10 +145,11 @@ typedef int (*PluginPut) (void *cls,
165 145
166 146
167/** 147/**
168 * Iterate over the results for a particular key 148 * Get one of the results for a particular key in the datastore.
169 * in the datastore.
170 * 149 *
171 * @param cls closure 150 * @param cls closure
151 * @param offset offset of the result (mod #num-results);
152 * specific ordering does not matter for the offset
172 * @param key key to match, never NULL 153 * @param key key to match, never NULL
173 * @param vhash hash of the value, maybe NULL (to 154 * @param vhash hash of the value, maybe NULL (to
174 * match all values that have the right key). 155 * match all values that have the right key).
@@ -177,34 +158,31 @@ typedef int (*PluginPut) (void *cls,
177 * there may be! 158 * there may be!
178 * @param type entries of which type are relevant? 159 * @param type entries of which type are relevant?
179 * Use 0 for any type. 160 * Use 0 for any type.
180 * @param iter function to call on each matching value; however, 161 * @param proc function to call on the matching value;
181 * after the first call to "iter", the plugin must wait 162 * proc should be called with NULL if there is no result
182 * until "NextRequest" was called before giving the iterator 163 * @param proc_cls closure for proc
183 * the next item; finally, the "iter" should be called once
184 * once with a NULL value at the end ("next_cls" should be NULL
185 * for that last call)
186 * @param iter_cls closure for iter
187 */ 164 */
188typedef void (*PluginGet) (void *cls, 165typedef void (*PluginGetKey) (void *cls,
189 const GNUNET_HashCode *key, 166 uint64_t offset,
190 const GNUNET_HashCode *vhash, 167 const GNUNET_HashCode *key,
191 enum GNUNET_BLOCK_Type type, 168 const GNUNET_HashCode *vhash,
192 PluginIterator iter, void *iter_cls); 169 enum GNUNET_BLOCK_Type type,
170 PluginDatumProcessor proc, void *proc_cls);
193 171
194 172
195 173
196/** 174/**
197 * Get a random item (additional constraints may apply depending on 175 * Get a random item (additional constraints may apply depending on
198 * the specific implementation). Calls 'iter' with all values ZERO or 176 * the specific implementation). Calls 'proc' with all values ZERO or
199 * NULL if no item applies, otherwise 'iter' is called once and only 177 * NULL if no item applies, otherwise 'proc' is called once and only
200 * once with an item, with the 'next_cls' argument being NULL. 178 * once with an item, with the 'next_cls' argument being NULL.
201 * 179 *
202 * @param cls closure 180 * @param cls closure
203 * @param iter function to call the value (once only). 181 * @param proc function to call the value (once only).
204 * @param iter_cls closure for iter 182 * @param proc_cls closure for proc
205 */ 183 */
206typedef void (*PluginRandomGet) (void *cls, 184typedef void (*PluginGetRandom) (void *cls,
207 PluginIterator iter, void *iter_cls); 185 PluginDatumProcessor proc, void *proc_cls);
208 186
209 187
210/** 188/**
@@ -238,26 +216,22 @@ typedef int (*PluginUpdate) (void *cls,
238 216
239 217
240/** 218/**
241 * Select a subset of the items in the datastore and call the given 219 * Select a single item from the datastore at the specified offset
242 * iterator for the first item; then allow getting more items by 220 * (among those applicable).
243 * calling the 'next_request' callback with the given 'next_cls'
244 * argument passed to 'iter'.
245 * 221 *
246 * @param cls closure 222 * @param cls closure
223 * @param offset offset of the result (mod #num-results);
224 * specific ordering does not matter for the offset
247 * @param type entries of which type should be considered? 225 * @param type entries of which type should be considered?
248 * Myst not be zero (ANY). 226 * Must not be zero (ANY).
249 * @param iter function to call on each matching value; however, 227 * @param proc function to call on the matching value
250 * after the first call to "iter", the plugin must wait 228 * @param proc_cls closure for proc
251 * until "NextRequest" was called before giving the iterator
252 * the next item; finally, the "iter" should be called once
253 * once with a NULL value at the end ("next_cls" should be NULL
254 * for that last call)
255 * @param iter_cls closure for iter
256 */ 229 */
257typedef void (*PluginSelector) (void *cls, 230typedef void (*PluginGetType) (void *cls,
258 enum GNUNET_BLOCK_Type type, 231 uint64_t offset,
259 PluginIterator iter, 232 enum GNUNET_BLOCK_Type type,
260 void *iter_cls); 233 PluginDatumProcessor proc,
234 void *proc_cls);
261 235
262 236
263/** 237/**
@@ -283,10 +257,10 @@ struct GNUNET_DATASTORE_PluginFunctions
283 void *cls; 257 void *cls;
284 258
285 /** 259 /**
286 * Get the current on-disk size of the SQ store. Estimates are 260 * Calculate the current on-disk size of the SQ store. Estimates
287 * fine, if that's the only thing available. 261 * are fine, if that's the only thing available.
288 */ 262 */
289 PluginGetSize get_size; 263 PluginEstimateSize estimate_size;
290 264
291 /** 265 /**
292 * Function to store an item in the datastore. 266 * Function to store an item in the datastore.
@@ -304,23 +278,14 @@ struct GNUNET_DATASTORE_PluginFunctions
304 PluginUpdate update; 278 PluginUpdate update;
305 279
306 /** 280 /**
307 * Function called by iterators whenever they want the next value; 281 * Get a particular datum matching a given hash from the datastore.
308 * note that unlike all of the other callbacks, this one does get a
309 * the "next_cls" closure which is usually different from the "cls"
310 * member of this struct!
311 */
312 PluginNextRequest next_request;
313
314 /**
315 * Function to iterate over the results for a particular key
316 * in the datastore.
317 */ 282 */
318 PluginGet get; 283 PluginGetKey get_key;
319 284
320 /** 285 /**
321 * Iterate over content with anonymity level zero. 286 * Get datum (of the specified type) with anonymity level zero.
322 */ 287 */
323 PluginSelector iter_zero_anonymity; 288 PluginGetType get_zero_anonymity;
324 289
325 /** 290 /**
326 * Function to get a random item with high replication score from 291 * Function to get a random item with high replication score from
@@ -329,13 +294,13 @@ struct GNUNET_DATASTORE_PluginFunctions
329 * counters. The item's replication counter is decremented by one 294 * counters. The item's replication counter is decremented by one
330 * IF it was positive before. 295 * IF it was positive before.
331 */ 296 */
332 PluginRandomGet replication_get; 297 PluginGetRandom get_replication;
333 298
334 /** 299 /**
335 * Function to get a random expired item or, if none are expired, one 300 * Function to get a random expired item or, if none are expired, one
336 * with a low priority. 301 * with a low priority.
337 */ 302 */
338 PluginRandomGet expiration_get; 303 PluginGetRandom get_expiration;
339 304
340 /** 305 /**
341 * Delete the database. The next operation is 306 * Delete the database. The next operation is
diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h
index 53d04e517..c563e5cc9 100644
--- a/src/include/gnunet_datastore_service.h
+++ b/src/include/gnunet_datastore_service.h
@@ -262,7 +262,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
262 262
263 263
264/** 264/**
265 * An iterator over a set of items stored in the datastore. 265 * Process a datum that was stored in the datastore.
266 * 266 *
267 * @param cls closure 267 * @param cls closure
268 * @param key key for the content 268 * @param key key for the content
@@ -275,87 +275,79 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
275 * @param uid unique identifier for the datum; 275 * @param uid unique identifier for the datum;
276 * maybe 0 if no unique identifier is available 276 * maybe 0 if no unique identifier is available
277 */ 277 */
278typedef void (*GNUNET_DATASTORE_Iterator) (void *cls, 278typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
279 const GNUNET_HashCode * key, 279 const GNUNET_HashCode * key,
280 size_t size, 280 size_t size,
281 const void *data, 281 const void *data,
282 enum GNUNET_BLOCK_Type type, 282 enum GNUNET_BLOCK_Type type,
283 uint32_t priority, 283 uint32_t priority,
284 uint32_t anonymity, 284 uint32_t anonymity,
285 struct GNUNET_TIME_Absolute 285 struct GNUNET_TIME_Absolute
286 expiration, uint64_t uid); 286 expiration, uint64_t uid);
287 287
288 288
289/** 289/**
290 * Iterate over the results for a particular key 290 * Get a result for a particular key from the datastore. The processor
291 * in the datastore. The iterator will only be called 291 * will only be called once.
292 * once initially; if the first call did contain a
293 * result, further results can be obtained by calling
294 * "GNUNET_DATASTORE_iterate_get_next" with the given argument.
295 * 292 *
296 * @param h handle to the datastore 293 * @param h handle to the datastore
294 * @param offset offset of the result (mod #num-results); set to
295 * a random 64-bit value initially; then increment by
296 * one each time; detect that all results have been found by uid
297 * being again the first uid ever returned.
297 * @param key maybe NULL (to match all entries) 298 * @param key maybe NULL (to match all entries)
298 * @param type desired type, 0 for any 299 * @param type desired type, 0 for any
299 * @param queue_priority ranking of this request in the priority queue 300 * @param queue_priority ranking of this request in the priority queue
300 * @param max_queue_size at what queue size should this request be dropped 301 * @param max_queue_size at what queue size should this request be dropped
301 * (if other requests of higher priority are in the queue) 302 * (if other requests of higher priority are in the queue)
302 * @param timeout how long to wait at most for a response 303 * @param timeout how long to wait at most for a response
303 * @param iter function to call on each matching value; 304 * @param proc function to call on each matching value;
304 * will be called once with a NULL value at the end 305 * will be called once with a NULL value at the end
305 * @param iter_cls closure for iter 306 * @param proc_cls closure for proc
306 * @return NULL if the entry was not queued, otherwise a handle that can be used to 307 * @return NULL if the entry was not queued, otherwise a handle that can be used to
307 * cancel; note that even if NULL is returned, the callback will be invoked 308 * cancel
308 * (or rather, will already have been invoked)
309 */ 309 */
310struct GNUNET_DATASTORE_QueueEntry * 310struct GNUNET_DATASTORE_QueueEntry *
311GNUNET_DATASTORE_iterate_key (struct GNUNET_DATASTORE_Handle *h, 311GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
312 const GNUNET_HashCode * key, 312 uint64_t offset,
313 enum GNUNET_BLOCK_Type type, 313 const GNUNET_HashCode * key,
314 unsigned int queue_priority, 314 enum GNUNET_BLOCK_Type type,
315 unsigned int max_queue_size, 315 unsigned int queue_priority,
316 struct GNUNET_TIME_Relative timeout, 316 unsigned int max_queue_size,
317 GNUNET_DATASTORE_Iterator iter, 317 struct GNUNET_TIME_Relative timeout,
318 void *iter_cls); 318 GNUNET_DATASTORE_DatumProcessor proc,
319 void *proc_cls);
319 320
320 321
321/** 322/**
322 * Get all zero-anonymity values from the datastore. 323 * Get a single zero-anonymity value from the datastore.
323 * 324 *
324 * @param h handle to the datastore 325 * @param h handle to the datastore
326 * @param offset offset of the result (mod #num-results); set to
327 * a random 64-bit value initially; then increment by
328 * one each time; detect that all results have been found by uid
329 * being again the first uid ever returned.
325 * @param queue_priority ranking of this request in the priority queue 330 * @param queue_priority ranking of this request in the priority queue
326 * @param max_queue_size at what queue size should this request be dropped 331 * @param max_queue_size at what queue size should this request be dropped
327 * (if other requests of higher priority are in the queue) 332 * (if other requests of higher priority are in the queue)
328 * @param timeout how long to wait at most for a response 333 * @param timeout how long to wait at most for a response
329 * @param type allowed type for the operation (never zero) 334 * @param type allowed type for the operation (never zero)
330 * @param iter function to call on a random value; it 335 * @param proc function to call on a random value; it
331 * will be called once with a value (if available) 336 * will be called once with a value (if available)
332 * and always once with a value of NULL at the end. 337 * or with NULL if none value exists.
333 * @param iter_cls closure for iter 338 * @param proc_cls closure for proc
334 * @return NULL if the entry was not queued, otherwise a handle that can be used to 339 * @return NULL if the entry was not queued, otherwise a handle that can be used to
335 * cancel; note that even if NULL is returned, the callback will be invoked 340 * cancel
336 * (or rather, will already have been invoked)
337 */ 341 */
338struct GNUNET_DATASTORE_QueueEntry * 342struct GNUNET_DATASTORE_QueueEntry *
339GNUNET_DATASTORE_iterate_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, 343GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
340 unsigned int queue_priority, 344 uint64_t offset,
341 unsigned int max_queue_size, 345 unsigned int queue_priority,
342 struct GNUNET_TIME_Relative timeout, 346 unsigned int max_queue_size,
343 enum GNUNET_BLOCK_Type type, 347 struct GNUNET_TIME_Relative timeout,
344 GNUNET_DATASTORE_Iterator iter, 348 enum GNUNET_BLOCK_Type type,
345 void *iter_cls); 349 GNUNET_DATASTORE_DatumProcessor proc,
346 350 void *proc_cls);
347
348/**
349 * Function called to trigger obtaining the next result
350 * from the datastore. ONLY applies for 'GNUNET_DATASTORE_iterate_*'
351 * calls, not for 'get' calls. FIXME: how much mixing of iterate
352 * calls with other operations can we permit!? Should we pass
353 * the 'QueueEntry' instead of the datastore handle here instead?
354 *
355 * @param h handle to the datastore
356 */
357void
358GNUNET_DATASTORE_iterate_get_next (struct GNUNET_DATASTORE_Handle *h);
359 351
360 352
361/** 353/**
@@ -370,21 +362,20 @@ GNUNET_DATASTORE_iterate_get_next (struct GNUNET_DATASTORE_Handle *h);
370 * @param max_queue_size at what queue size should this request be dropped 362 * @param max_queue_size at what queue size should this request be dropped
371 * (if other requests of higher priority are in the queue) 363 * (if other requests of higher priority are in the queue)
372 * @param timeout how long to wait at most for a response 364 * @param timeout how long to wait at most for a response
373 * @param iter function to call on a random value; it 365 * @param proc function to call on a random value; it
374 * will be called once with a value (if available) 366 * will be called once with a value (if available)
375 * and always once with a value of NULL. 367 * and always once with a value of NULL.
376 * @param iter_cls closure for iter 368 * @param proc_cls closure for proc
377 * @return NULL if the entry was not queued, otherwise a handle that can be used to 369 * @return NULL if the entry was not queued, otherwise a handle that can be used to
378 * cancel; note that even if NULL is returned, the callback will be invoked 370 * cancel
379 * (or rather, will already have been invoked)
380 */ 371 */
381struct GNUNET_DATASTORE_QueueEntry * 372struct GNUNET_DATASTORE_QueueEntry *
382GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h, 373GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
383 unsigned int queue_priority, 374 unsigned int queue_priority,
384 unsigned int max_queue_size, 375 unsigned int max_queue_size,
385 struct GNUNET_TIME_Relative timeout, 376 struct GNUNET_TIME_Relative timeout,
386 GNUNET_DATASTORE_Iterator iter, 377 GNUNET_DATASTORE_DatumProcessor proc,
387 void *iter_cls); 378 void *proc_cls);
388 379
389 380
390 381