summaryrefslogtreecommitdiff
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)
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,
input: 'test_plugin_namestore_sqlite.conf',
output: 'test_plugin_namestore_sqlite.conf')
+configure_file(input : 'namestore-0001.sql',
+ output : 'namestore-0001.sql',
+ configuration : cdata,
+ install: true,
+ install_dir: get_option('datadir')/'gnunet'/'sql')
+
+configure_file(input : 'namestore-drop.sql',
+ output : 'namestore-drop.sql',
+ configuration : cdata,
+ install: true,
+ install_dir: get_option('datadir')/'gnunet'/'sql')
+
if pq_dep.found()
shared_module('gnunet_plugin_namestore_postgres',
['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 @@
* @brief postgres-based namestore backend
* @author Christian Grothoff
*/
+#include "gnunet_db_lib.h"
#include "gnunet_namestore_plugin.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_pq_lib.h"
@@ -145,13 +146,12 @@ database_prepare (struct Plugin *plugin)
GNUNET_PQ_make_prepare ("edit_set",
"UPDATE namestore.ns098records"
" SET editor_hint=$3"
- " FROM ns098records AS old_ns098records"
+ " FROM namestore.ns098records AS old_ns098records"
" WHERE ns098records.zone_private_key=$1 AND ns098records.label=$2"
" RETURNING ns098records.seq,ns098records.record_count,ns098records.record_data,ns098records.label,old_ns098records.editor_hint "),
GNUNET_PQ_make_prepare ("clear_editor_hint",
"UPDATE namestore.ns098records"
" SET editor_hint=$4"
- " FROM namestore.ns098records"
" WHERE zone_private_key=$1 AND label=$2 AND editor_hint=$3"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
@@ -459,25 +459,21 @@ parse_result_call_iterator (void *cls,
* @param label name of the record in the zone
* @param iter function to call with the result
* @param iter_cls closure for @a iter
- * @param method the method to use "lookup_record" or "edit_set"
* @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
*/
static enum GNUNET_GenericReturnValue
-lookup_records (void *cls,
- const struct
- GNUNET_CRYPTO_PrivateKey *zone,
- const char *label,
- GNUNET_NAMESTORE_RecordIterator iter,
- void *iter_cls,
- const char *method,
- const char *editor_hint)
+namestore_postgres_lookup_records (void *cls,
+ const struct
+ GNUNET_CRYPTO_PrivateKey *zone,
+ const char *label,
+ GNUNET_NAMESTORE_RecordIterator iter,
+ void *iter_cls)
{
struct Plugin *plugin = cls;
GNUNET_assert (GNUNET_OK == database_prepare (plugin));
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (zone),
GNUNET_PQ_query_param_string (label),
- GNUNET_PQ_query_param_string (editor_hint),
GNUNET_PQ_query_param_end
};
struct ParserContext pc;
@@ -492,7 +488,7 @@ lookup_records (void *cls,
pc.iter_cls = iter_cls;
pc.zone_key = zone;
res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
- method,
+ "lookup_label",
params,
&parse_result_call_iterator,
&pc);
@@ -505,28 +501,6 @@ lookup_records (void *cls,
/**
- * Lookup records in the datastore for which we are the authority.
- *
- * @param cls closure (internal context for the plugin)
- * @param zone private key of the zone
- * @param label name of the record in the zone
- * @param iter function to call with the result
- * @param iter_cls closure for @a iter
- * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
- */
-static enum GNUNET_GenericReturnValue
-namestore_postgres_lookup_records (void *cls,
- const struct
- GNUNET_CRYPTO_PrivateKey *zone,
- const char *label,
- GNUNET_NAMESTORE_RecordIterator iter,
- void *iter_cls)
-{
- return lookup_records (cls, zone, label, iter, iter_cls, "lookup_label", "");
-}
-
-
-/**
*
* @param cls closure (internal context for the plugin)
* @param zone private key of the zone
@@ -564,7 +538,8 @@ namestore_postgres_clear_editor_hint (void *cls,
res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
"clear_editor_hint",
params);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res)
+ if ((GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res) &&
+ (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res))
return GNUNET_SYSERR;
}
return GNUNET_OK;
@@ -590,8 +565,35 @@ namestore_postgres_edit_records (void *cls,
GNUNET_NAMESTORE_RecordIterator iter,
void *iter_cls)
{
- return lookup_records (cls, zone, label, iter, iter_cls, "edit_set",
- (NULL == editor_hint) ? "" : editor_hint);
+ struct Plugin *plugin = cls;
+ GNUNET_assert (GNUNET_OK == database_prepare (plugin));
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (zone),
+ GNUNET_PQ_query_param_string (label),
+ GNUNET_PQ_query_param_string (editor_hint),
+ GNUNET_PQ_query_param_end
+ };
+ struct ParserContext pc;
+ enum GNUNET_DB_QueryStatus res;
+
+ if (NULL == zone)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ pc.iter = iter;
+ pc.iter_cls = iter_cls;
+ pc.zone_key = zone;
+ res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
+ "edit_set",
+ params,
+ &parse_result_call_iterator,
+ &pc);
+ if (res < 0)
+ return GNUNET_SYSERR;
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res)
+ return GNUNET_NO;
+ return GNUNET_OK;
}
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 @@
+perf_namestore_api_zone_iteration_postgres
+perf_namestore_api_zone_iteration_sqlite
+test_namestore_api_edit_records_sqlite
gnunet-service-namestore
gnunet-namestore-fcfsd
test_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,
input: 'test_namestore_api_sqlite.conf',
output: 'test_namestore_api_sqlite.conf')
+configure_file(copy: true,
+ input: 'test_namestore_api_postgres.conf',
+ output: 'test_namestore_api_postgres.conf')
+
namestoreapitestnames = [
'test_namestore_api_lookup_nick',
'test_namestore_api_monitoring',
@@ -109,7 +113,7 @@ foreach tn : namestoreapitestnames
libgnunetnamestore_dep],
include_directories: [incdir, configuration_inc],
install: false)
- test(tn + '_postgres', t, workdir: meson.current_build_dir(),
+ test(tn + '_postgres', t_pq, workdir: meson.current_build_dir(),
is_parallel: false,
suite: 'namestore')
endif