aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-25 16:18:31 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-25 16:18:31 +0200
commit4dc79497d7f745996068e62e973e34d220580323 (patch)
treee6d429d3cf2240ec3459f1d4533201dc40b27015 /src/namestore/plugin_namestore_postgres.c
parentbdbb7c684f2c9711989d2543ecc08a95be23e6c4 (diff)
downloadgnunet-4dc79497d7f745996068e62e973e34d220580323.tar.gz
gnunet-4dc79497d7f745996068e62e973e34d220580323.zip
extend namestore API to enable faster iterations by returning more than one result at a time
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r--src/namestore/plugin_namestore_postgres.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index e38fcafb1..4a24ddf88 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -149,22 +149,28 @@ database_setup (struct Plugin *plugin)
149 struct GNUNET_PQ_PreparedStatement ps[] = { 149 struct GNUNET_PQ_PreparedStatement ps[] = {
150 GNUNET_PQ_make_prepare ("store_records", 150 GNUNET_PQ_make_prepare ("store_records",
151 "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES " 151 "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES "
152 "($1, $2, $3, $4, $5, $6)", 6), 152 "($1, $2, $3, $4, $5, $6)",
153 6),
153 GNUNET_PQ_make_prepare ("delete_records", 154 GNUNET_PQ_make_prepare ("delete_records",
154 "DELETE FROM ns097records " 155 "DELETE FROM ns097records "
155 "WHERE zone_private_key=$1 AND label=$2", 2), 156 "WHERE zone_private_key=$1 AND label=$2",
157 2),
156 GNUNET_PQ_make_prepare ("zone_to_name", 158 GNUNET_PQ_make_prepare ("zone_to_name",
157 "SELECT record_count,record_data,label FROM ns097records" 159 "SELECT record_count,record_data,label FROM ns097records"
158 " WHERE zone_private_key=$1 AND pkey=$2", 2), 160 " WHERE zone_private_key=$1 AND pkey=$2",
161 2),
159 GNUNET_PQ_make_prepare ("iterate_zone", 162 GNUNET_PQ_make_prepare ("iterate_zone",
160 "SELECT record_count,record_data,label FROM ns097records " 163 "SELECT record_count,record_data,label FROM ns097records "
161 "WHERE zone_private_key=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2), 164 "WHERE zone_private_key=$1 ORDER BY rvalue OFFSET $2 LIMIT $3",
165 3),
162 GNUNET_PQ_make_prepare ("iterate_all_zones", 166 GNUNET_PQ_make_prepare ("iterate_all_zones",
163 "SELECT record_count,record_data,label,zone_private_key" 167 "SELECT record_count,record_data,label,zone_private_key"
164 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET $1", 1), 168 " FROM ns097records ORDER BY rvalue OFFSET $1 LIMIT $2",
169 2),
165 GNUNET_PQ_make_prepare ("lookup_label", 170 GNUNET_PQ_make_prepare ("lookup_label",
166 "SELECT record_count,record_data,label " 171 "SELECT record_count,record_data,label "
167 "FROM ns097records WHERE zone_private_key=$1 AND label=$2", 2), 172 "FROM ns097records WHERE zone_private_key=$1 AND label=$2",
173 2),
168 GNUNET_PQ_PREPARED_STATEMENT_END 174 GNUNET_PQ_PREPARED_STATEMENT_END
169 }; 175 };
170 176
@@ -278,6 +284,12 @@ struct ParserContext
278 * Zone key, NULL if part of record. 284 * Zone key, NULL if part of record.
279 */ 285 */
280 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; 286 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key;
287
288 /**
289 * Number of results still to return (counted down by
290 * number of results given to iterator).
291 */
292 uint64_t limit;
281}; 293};
282 294
283 295
@@ -360,6 +372,7 @@ parse_result_call_iterator (void *cls,
360 } 372 }
361 GNUNET_PQ_cleanup_result (rs); 373 GNUNET_PQ_cleanup_result (rs);
362 } 374 }
375 pc->limit -= num_results;
363} 376}
364 377
365 378
@@ -410,14 +423,16 @@ namestore_postgres_lookup_records (void *cls,
410 * @param cls closure (internal context for the plugin) 423 * @param cls closure (internal context for the plugin)
411 * @param zone hash of public key of the zone, NULL to iterate over all zones 424 * @param zone hash of public key of the zone, NULL to iterate over all zones
412 * @param offset offset in the list of all matching records 425 * @param offset offset in the list of all matching records
426 * @param limit maximum number of results to fetch
413 * @param iter function to call with the result 427 * @param iter function to call with the result
414 * @param iter_cls closure for @a iter 428 * @param iter_cls closure for @a iter
415 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 429 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
416 */ 430 */
417static int 431static int
418namestore_postgres_iterate_records (void *cls, 432namestore_postgres_iterate_records (void *cls,
419 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 433 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
420 uint64_t offset, 434 uint64_t offset,
435 uint64_t limit,
421 GNUNET_NAMESTORE_RecordIterator iter, 436 GNUNET_NAMESTORE_RecordIterator iter,
422 void *iter_cls) 437 void *iter_cls)
423{ 438{
@@ -428,10 +443,12 @@ namestore_postgres_iterate_records (void *cls,
428 pc.iter = iter; 443 pc.iter = iter;
429 pc.iter_cls = iter_cls; 444 pc.iter_cls = iter_cls;
430 pc.zone_key = zone; 445 pc.zone_key = zone;
446 pc.limit = limit;
431 if (NULL == zone) 447 if (NULL == zone)
432 { 448 {
433 struct GNUNET_PQ_QueryParam params_without_zone[] = { 449 struct GNUNET_PQ_QueryParam params_without_zone[] = {
434 GNUNET_PQ_query_param_uint64 (&offset), 450 GNUNET_PQ_query_param_uint64 (&offset),
451 GNUNET_PQ_query_param_uint64 (&limit),
435 GNUNET_PQ_query_param_end 452 GNUNET_PQ_query_param_end
436 }; 453 };
437 454
@@ -446,6 +463,7 @@ namestore_postgres_iterate_records (void *cls,
446 struct GNUNET_PQ_QueryParam params_with_zone[] = { 463 struct GNUNET_PQ_QueryParam params_with_zone[] = {
447 GNUNET_PQ_query_param_auto_from_type (zone), 464 GNUNET_PQ_query_param_auto_from_type (zone),
448 GNUNET_PQ_query_param_uint64 (&offset), 465 GNUNET_PQ_query_param_uint64 (&offset),
466 GNUNET_PQ_query_param_uint64 (&limit),
449 GNUNET_PQ_query_param_end 467 GNUNET_PQ_query_param_end
450 }; 468 };
451 469
@@ -458,9 +476,9 @@ namestore_postgres_iterate_records (void *cls,
458 if (res < 0) 476 if (res < 0)
459 return GNUNET_SYSERR; 477 return GNUNET_SYSERR;
460 478
461 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) 479 if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) ||
480 (pc.limit > 0) )
462 return GNUNET_NO; 481 return GNUNET_NO;
463
464 return GNUNET_OK; 482 return GNUNET_OK;
465} 483}
466 484