aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-12-02 15:17:32 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2023-12-02 15:17:32 +0100
commit23618e560d64f39fb4679a76eff90bdb5be58538 (patch)
treeefb96586cee0fb4bd5b7fdd93843d70e5a54d7e2
parent8c56942326368c1739b9e285e2e86d52b3e18e20 (diff)
downloadgnunet-dev/schanzen/namestore_db_softlocking.tar.gz
gnunet-dev/schanzen/namestore_db_softlocking.zip
NAMESTORE: Fix postgres plugin with new advisory lock APIdev/schanzen/namestore_db_softlocking
-rw-r--r--src/plugin/namestore/meson.build12
-rw-r--r--src/plugin/namestore/plugin_namestore_postgres.c78
-rw-r--r--src/service/namestore/.gitignore3
-rw-r--r--src/service/namestore/meson.build6
4 files changed, 60 insertions, 39 deletions
diff --git a/src/plugin/namestore/meson.build b/src/plugin/namestore/meson.build
index 4a077915d..86eeb37c5 100644
--- a/src/plugin/namestore/meson.build
+++ b/src/plugin/namestore/meson.build
@@ -14,6 +14,18 @@ configure_file(copy: true,
14 input: 'test_plugin_namestore_sqlite.conf', 14 input: 'test_plugin_namestore_sqlite.conf',
15 output: 'test_plugin_namestore_sqlite.conf') 15 output: 'test_plugin_namestore_sqlite.conf')
16 16
17configure_file(input : 'namestore-0001.sql',
18 output : 'namestore-0001.sql',
19 configuration : cdata,
20 install: true,
21 install_dir: get_option('datadir')/'gnunet'/'sql')
22
23configure_file(input : 'namestore-drop.sql',
24 output : 'namestore-drop.sql',
25 configuration : cdata,
26 install: true,
27 install_dir: get_option('datadir')/'gnunet'/'sql')
28
17if pq_dep.found() 29if pq_dep.found()
18 shared_module('gnunet_plugin_namestore_postgres', 30 shared_module('gnunet_plugin_namestore_postgres',
19 ['plugin_namestore_postgres.c'], 31 ['plugin_namestore_postgres.c'],
diff --git a/src/plugin/namestore/plugin_namestore_postgres.c b/src/plugin/namestore/plugin_namestore_postgres.c
index 0bc98a98a..ccf84dfa6 100644
--- a/src/plugin/namestore/plugin_namestore_postgres.c
+++ b/src/plugin/namestore/plugin_namestore_postgres.c
@@ -23,6 +23,7 @@
23 * @brief postgres-based namestore backend 23 * @brief postgres-based namestore backend
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet_db_lib.h"
26#include "gnunet_namestore_plugin.h" 27#include "gnunet_namestore_plugin.h"
27#include "gnunet_gnsrecord_lib.h" 28#include "gnunet_gnsrecord_lib.h"
28#include "gnunet_pq_lib.h" 29#include "gnunet_pq_lib.h"
@@ -145,13 +146,12 @@ database_prepare (struct Plugin *plugin)
145 GNUNET_PQ_make_prepare ("edit_set", 146 GNUNET_PQ_make_prepare ("edit_set",
146 "UPDATE namestore.ns098records" 147 "UPDATE namestore.ns098records"
147 " SET editor_hint=$3" 148 " SET editor_hint=$3"
148 " FROM ns098records AS old_ns098records" 149 " FROM namestore.ns098records AS old_ns098records"
149 " WHERE ns098records.zone_private_key=$1 AND ns098records.label=$2" 150 " WHERE ns098records.zone_private_key=$1 AND ns098records.label=$2"
150 " RETURNING ns098records.seq,ns098records.record_count,ns098records.record_data,ns098records.label,old_ns098records.editor_hint "), 151 " RETURNING ns098records.seq,ns098records.record_count,ns098records.record_data,ns098records.label,old_ns098records.editor_hint "),
151 GNUNET_PQ_make_prepare ("clear_editor_hint", 152 GNUNET_PQ_make_prepare ("clear_editor_hint",
152 "UPDATE namestore.ns098records" 153 "UPDATE namestore.ns098records"
153 " SET editor_hint=$4" 154 " SET editor_hint=$4"
154 " FROM namestore.ns098records"
155 " WHERE zone_private_key=$1 AND label=$2 AND editor_hint=$3"), 155 " WHERE zone_private_key=$1 AND label=$2 AND editor_hint=$3"),
156 GNUNET_PQ_PREPARED_STATEMENT_END 156 GNUNET_PQ_PREPARED_STATEMENT_END
157 }; 157 };
@@ -459,25 +459,21 @@ parse_result_call_iterator (void *cls,
459 * @param label name of the record in the zone 459 * @param label name of the record in the zone
460 * @param iter function to call with the result 460 * @param iter function to call with the result
461 * @param iter_cls closure for @a iter 461 * @param iter_cls closure for @a iter
462 * @param method the method to use "lookup_record" or "edit_set"
463 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 462 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
464 */ 463 */
465static enum GNUNET_GenericReturnValue 464static enum GNUNET_GenericReturnValue
466lookup_records (void *cls, 465namestore_postgres_lookup_records (void *cls,
467 const struct 466 const struct
468 GNUNET_CRYPTO_PrivateKey *zone, 467 GNUNET_CRYPTO_PrivateKey *zone,
469 const char *label, 468 const char *label,
470 GNUNET_NAMESTORE_RecordIterator iter, 469 GNUNET_NAMESTORE_RecordIterator iter,
471 void *iter_cls, 470 void *iter_cls)
472 const char *method,
473 const char *editor_hint)
474{ 471{
475 struct Plugin *plugin = cls; 472 struct Plugin *plugin = cls;
476 GNUNET_assert (GNUNET_OK == database_prepare (plugin)); 473 GNUNET_assert (GNUNET_OK == database_prepare (plugin));
477 struct GNUNET_PQ_QueryParam params[] = { 474 struct GNUNET_PQ_QueryParam params[] = {
478 GNUNET_PQ_query_param_auto_from_type (zone), 475 GNUNET_PQ_query_param_auto_from_type (zone),
479 GNUNET_PQ_query_param_string (label), 476 GNUNET_PQ_query_param_string (label),
480 GNUNET_PQ_query_param_string (editor_hint),
481 GNUNET_PQ_query_param_end 477 GNUNET_PQ_query_param_end
482 }; 478 };
483 struct ParserContext pc; 479 struct ParserContext pc;
@@ -492,7 +488,7 @@ lookup_records (void *cls,
492 pc.iter_cls = iter_cls; 488 pc.iter_cls = iter_cls;
493 pc.zone_key = zone; 489 pc.zone_key = zone;
494 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, 490 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
495 method, 491 "lookup_label",
496 params, 492 params,
497 &parse_result_call_iterator, 493 &parse_result_call_iterator,
498 &pc); 494 &pc);
@@ -505,28 +501,6 @@ lookup_records (void *cls,
505 501
506 502
507/** 503/**
508 * Lookup records in the datastore for which we are the authority.
509 *
510 * @param cls closure (internal context for the plugin)
511 * @param zone private key of the zone
512 * @param label name of the record in the zone
513 * @param iter function to call with the result
514 * @param iter_cls closure for @a iter
515 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
516 */
517static enum GNUNET_GenericReturnValue
518namestore_postgres_lookup_records (void *cls,
519 const struct
520 GNUNET_CRYPTO_PrivateKey *zone,
521 const char *label,
522 GNUNET_NAMESTORE_RecordIterator iter,
523 void *iter_cls)
524{
525 return lookup_records (cls, zone, label, iter, iter_cls, "lookup_label", "");
526}
527
528
529/**
530 * 504 *
531 * @param cls closure (internal context for the plugin) 505 * @param cls closure (internal context for the plugin)
532 * @param zone private key of the zone 506 * @param zone private key of the zone
@@ -564,7 +538,8 @@ namestore_postgres_clear_editor_hint (void *cls,
564 res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, 538 res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
565 "clear_editor_hint", 539 "clear_editor_hint",
566 params); 540 params);
567 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) 541 if ((GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res) &&
542 (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res))
568 return GNUNET_SYSERR; 543 return GNUNET_SYSERR;
569 } 544 }
570 return GNUNET_OK; 545 return GNUNET_OK;
@@ -590,8 +565,35 @@ namestore_postgres_edit_records (void *cls,
590 GNUNET_NAMESTORE_RecordIterator iter, 565 GNUNET_NAMESTORE_RecordIterator iter,
591 void *iter_cls) 566 void *iter_cls)
592{ 567{
593 return lookup_records (cls, zone, label, iter, iter_cls, "edit_set", 568 struct Plugin *plugin = cls;
594 (NULL == editor_hint) ? "" : editor_hint); 569 GNUNET_assert (GNUNET_OK == database_prepare (plugin));
570 struct GNUNET_PQ_QueryParam params[] = {
571 GNUNET_PQ_query_param_auto_from_type (zone),
572 GNUNET_PQ_query_param_string (label),
573 GNUNET_PQ_query_param_string (editor_hint),
574 GNUNET_PQ_query_param_end
575 };
576 struct ParserContext pc;
577 enum GNUNET_DB_QueryStatus res;
578
579 if (NULL == zone)
580 {
581 GNUNET_break (0);
582 return GNUNET_SYSERR;
583 }
584 pc.iter = iter;
585 pc.iter_cls = iter_cls;
586 pc.zone_key = zone;
587 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
588 "edit_set",
589 params,
590 &parse_result_call_iterator,
591 &pc);
592 if (res < 0)
593 return GNUNET_SYSERR;
594 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res)
595 return GNUNET_NO;
596 return GNUNET_OK;
595} 597}
596 598
597 599
diff --git a/src/service/namestore/.gitignore b/src/service/namestore/.gitignore
index 7b99c6163..2728811c9 100644
--- a/src/service/namestore/.gitignore
+++ b/src/service/namestore/.gitignore
@@ -1,3 +1,6 @@
1perf_namestore_api_zone_iteration_postgres
2perf_namestore_api_zone_iteration_sqlite
3test_namestore_api_edit_records_sqlite
1gnunet-service-namestore 4gnunet-service-namestore
2gnunet-namestore-fcfsd 5gnunet-namestore-fcfsd
3test_namestore_api_lookup_nick.nc 6test_namestore_api_lookup_nick.nc
diff --git a/src/service/namestore/meson.build b/src/service/namestore/meson.build
index 090ed1520..62512c405 100644
--- a/src/service/namestore/meson.build
+++ b/src/service/namestore/meson.build
@@ -64,6 +64,10 @@ configure_file(copy: true,
64 input: 'test_namestore_api_sqlite.conf', 64 input: 'test_namestore_api_sqlite.conf',
65 output: 'test_namestore_api_sqlite.conf') 65 output: 'test_namestore_api_sqlite.conf')
66 66
67configure_file(copy: true,
68 input: 'test_namestore_api_postgres.conf',
69 output: 'test_namestore_api_postgres.conf')
70
67namestoreapitestnames = [ 71namestoreapitestnames = [
68 'test_namestore_api_lookup_nick', 72 'test_namestore_api_lookup_nick',
69 'test_namestore_api_monitoring', 73 'test_namestore_api_monitoring',
@@ -109,7 +113,7 @@ foreach tn : namestoreapitestnames
109 libgnunetnamestore_dep], 113 libgnunetnamestore_dep],
110 include_directories: [incdir, configuration_inc], 114 include_directories: [incdir, configuration_inc],
111 install: false) 115 install: false)
112 test(tn + '_postgres', t, workdir: meson.current_build_dir(), 116 test(tn + '_postgres', t_pq, workdir: meson.current_build_dir(),
113 is_parallel: false, 117 is_parallel: false,
114 suite: 'namestore') 118 suite: 'namestore')
115 endif 119 endif