aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-09-23 12:59:28 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-09-23 12:59:28 +0900
commite238c132f9e9d75437c465d8641b45427c622df5 (patch)
tree2ee821d0f52a8bada8b1d8cdc39a05dbe2c877dc /src/namestore
parent764871dcbec1f4bbd846d79b8bd34f5b56d435f2 (diff)
downloadgnunet-e238c132f9e9d75437c465d8641b45427c622df5.tar.gz
gnunet-e238c132f9e9d75437c465d8641b45427c622df5.zip
NAMESTORE: Add tx API for postgres
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am13
-rw-r--r--src/namestore/plugin_namestore_postgres.c65
2 files changed, 77 insertions, 1 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 2d2c8ac3c..32f2605ca 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -57,7 +57,8 @@ POSTGRES_TESTS = test_plugin_namestore_postgres \
57 test_namestore_api_zone_iteration_stop_postgres \ 57 test_namestore_api_zone_iteration_stop_postgres \
58 test_namestore_api_monitoring_existing_postgres \ 58 test_namestore_api_monitoring_existing_postgres \
59 test_namestore_api_zone_to_name_postgres \ 59 test_namestore_api_zone_to_name_postgres \
60 perf_namestore_api_zone_iteration_postgres 60 perf_namestore_api_zone_iteration_postgres \
61 test_namestore_api_tx_rollback_postgres
61endif 62endif
62 63
63if HAVE_SQLITE 64if HAVE_SQLITE
@@ -432,6 +433,16 @@ test_namestore_api_tx_rollback_sqlite_LDADD = \
432 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 433 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
433 $(top_builddir)/src/util/libgnunetutil.la 434 $(top_builddir)/src/util/libgnunetutil.la
434 435
436test_namestore_api_tx_rollback_postgres_SOURCES = \
437 test_namestore_api_tx_rollback.c
438test_namestore_api_tx_rollback_postgres_LDADD = \
439 $(top_builddir)/src/testing/libgnunettesting.la \
440 $(top_builddir)/src/identity/libgnunetidentity.la \
441 libgnunetnamestore.la \
442 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
443 $(top_builddir)/src/util/libgnunetutil.la
444
445
435 446
436test_namestore_api_zone_iteration_sqlite_SOURCES = \ 447test_namestore_api_zone_iteration_sqlite_SOURCES = \
437 test_namestore_api_zone_iteration.c 448 test_namestore_api_zone_iteration.c
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index 54a19794f..3b1b7ac21 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -553,6 +553,68 @@ namestore_postgres_zone_to_name (void *cls,
553 return GNUNET_OK; 553 return GNUNET_OK;
554} 554}
555 555
556/**
557 * Begin a transaction for a client.
558 *
559 * @param cls closure (internal context for the plugin)
560 * @param emsg error message set of return code is #GNUNET_SYSERR
561 * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started.
562 */
563static enum GNUNET_GenericReturnValue
564namestore_postgres_transaction_begin (void *cls,
565 char **emsg)
566{
567 struct Plugin *plugin = cls;
568 struct GNUNET_PQ_ExecuteStatement es[] = {
569 GNUNET_PQ_make_execute ("BEGIN;"),
570 GNUNET_PQ_EXECUTE_STATEMENT_END
571 };
572
573 return GNUNET_PQ_exec_statements (plugin->dbh, es);
574}
575
576/**
577 * Commit a transaction for a client.
578 * This releases the lock on the database.
579 *
580 * @param cls closure (internal context for the plugin)
581 * @param emsg error message set of return code is #GNUNET_SYSERR
582 * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started.
583 */
584static enum GNUNET_GenericReturnValue
585namestore_postgres_transaction_rollback (void *cls,
586 char **emsg)
587{
588 struct Plugin *plugin = cls;
589 struct GNUNET_PQ_ExecuteStatement es[] = {
590 GNUNET_PQ_make_execute ("ROLLBACK;"),
591 GNUNET_PQ_EXECUTE_STATEMENT_END
592 };
593
594 return GNUNET_PQ_exec_statements (plugin->dbh, es);
595}
596
597/**
598 * Roll back a transaction for a client.
599 * This releases the lock on the database.
600 *
601 * @param cls closure (internal context for the plugin)
602 * @param emsg error message set of return code is #GNUNET_SYSERR
603 * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started.
604 */
605static enum GNUNET_GenericReturnValue
606namestore_postgres_transaction_commit (void *cls,
607 char **emsg)
608{
609 struct Plugin *plugin = cls;
610 struct GNUNET_PQ_ExecuteStatement es[] = {
611 GNUNET_PQ_make_execute ("COMMIT;"),
612 GNUNET_PQ_EXECUTE_STATEMENT_END
613 };
614
615 return GNUNET_PQ_exec_statements (plugin->dbh, es);
616}
617
556 618
557/** 619/**
558 * Shutdown database connection and associate data 620 * Shutdown database connection and associate data
@@ -595,6 +657,9 @@ libgnunet_plugin_namestore_postgres_init (void *cls)
595 api->iterate_records = &namestore_postgres_iterate_records; 657 api->iterate_records = &namestore_postgres_iterate_records;
596 api->zone_to_name = &namestore_postgres_zone_to_name; 658 api->zone_to_name = &namestore_postgres_zone_to_name;
597 api->lookup_records = &namestore_postgres_lookup_records; 659 api->lookup_records = &namestore_postgres_lookup_records;
660 api->transaction_begin = &namestore_postgres_transaction_begin;
661 api->transaction_commit = &namestore_postgres_transaction_commit;
662 api->transaction_rollback = &namestore_postgres_transaction_rollback;
598 LOG (GNUNET_ERROR_TYPE_INFO, 663 LOG (GNUNET_ERROR_TYPE_INFO,
599 "Postgres namestore plugin running\n"); 664 "Postgres namestore plugin running\n");
600 return api; 665 return api;