From 2abe9bf6d7df83f480514dce06005a813503982c Mon Sep 17 00:00:00 2001 From: Marco Boss Date: Wed, 2 Mar 2022 10:50:51 +0100 Subject: include partitioning logic in dbinit --- src/exchange-tools/taler-exchange-dbinit.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/exchange-tools') diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c index a5e6a94af..f7c177edc 100644 --- a/src/exchange-tools/taler-exchange-dbinit.c +++ b/src/exchange-tools/taler-exchange-dbinit.c @@ -44,6 +44,11 @@ static int clear_shards; */ static int gc_db; +/** + * -P option: setup a partitioned database + */ +static uint32_t num_partitions; + /** * Main function that will be run. @@ -90,6 +95,24 @@ run (void *cls, global_ret = EXIT_NOPERMISSION; return; } + if (1 < + num_partitions) + { + if (GNUNET_OK != plugin->setup_partitions (plugin->cls, &num_partitions)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not setup partitions. Dropping default ones again\n"); + } + if (GNUNET_OK != plugin->drop_tables (plugin->cls)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not drop tables after failed partitioning, please delete the DB manually\n"); + } + TALER_EXCHANGEDB_plugin_unload (plugin); + plugin = NULL; + global_ret = EXIT_NOTINSTALLED; + return; + } if (gc_db || clear_shards) { if (GNUNET_OK != @@ -150,6 +173,11 @@ main (int argc, "shardunlock", "unlock all revolving shard locks (use after system crash or shard size change while services are not running)", &clear_shards), + GNUNET_GETOPT_option_uint ('P', + "partition", + "NUMBER", + "Setup a partitioned database where each table which can be partitioned holds NUMBER partitions on a single DB node (NOTE: this is different from sharding)", + &num_partitions), GNUNET_GETOPT_OPTION_END }; enum GNUNET_GenericReturnValue ret; -- cgit v1.2.3 From 41a9a73eb85c726a0e38f89cd2ca86de8040e17c Mon Sep 17 00:00:00 2001 From: Marco Boss Date: Wed, 2 Mar 2022 13:21:45 +0100 Subject: fix --- src/exchange-tools/taler-exchange-dbinit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/exchange-tools') diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c index f7c177edc..4afb5725c 100644 --- a/src/exchange-tools/taler-exchange-dbinit.c +++ b/src/exchange-tools/taler-exchange-dbinit.c @@ -102,11 +102,11 @@ run (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup partitions. Dropping default ones again\n"); - } - if (GNUNET_OK != plugin->drop_tables (plugin->cls)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not drop tables after failed partitioning, please delete the DB manually\n"); + if (GNUNET_OK != plugin->drop_tables (plugin->cls)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not drop tables after failed partitioning, please delete the DB manually\n"); + } } TALER_EXCHANGEDB_plugin_unload (plugin); plugin = NULL; -- cgit v1.2.3 From 548613c617cc6da29093e617964016e30c66a11f Mon Sep 17 00:00:00 2001 From: Marco Boss Date: Wed, 2 Mar 2022 13:30:44 +0100 Subject: fix --- src/exchange-tools/taler-exchange-dbinit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/exchange-tools') diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c index 4afb5725c..69b9d1a16 100644 --- a/src/exchange-tools/taler-exchange-dbinit.c +++ b/src/exchange-tools/taler-exchange-dbinit.c @@ -107,11 +107,11 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not drop tables after failed partitioning, please delete the DB manually\n"); } + TALER_EXCHANGEDB_plugin_unload (plugin); + plugin = NULL; + global_ret = EXIT_NOTINSTALLED; + return; } - TALER_EXCHANGEDB_plugin_unload (plugin); - plugin = NULL; - global_ret = EXIT_NOTINSTALLED; - return; } if (gc_db || clear_shards) { -- cgit v1.2.3 From 7f30609ff0773873df9274bf4a491dd00e623577 Mon Sep 17 00:00:00 2001 From: Marco Boss Date: Wed, 2 Mar 2022 17:22:43 +0100 Subject: use plain uint32_t --- src/exchange-tools/taler-exchange-dbinit.c | 2 +- src/exchangedb/plugin_exchangedb_postgres.c | 4 ++-- src/include/taler_exchangedb_plugin.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/exchange-tools') diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c index 69b9d1a16..9ec31afc1 100644 --- a/src/exchange-tools/taler-exchange-dbinit.c +++ b/src/exchange-tools/taler-exchange-dbinit.c @@ -98,7 +98,7 @@ run (void *cls, if (1 < num_partitions) { - if (GNUNET_OK != plugin->setup_partitions (plugin->cls, &num_partitions)) + if (GNUNET_OK != plugin->setup_partitions (plugin->cls, num_partitions)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup partitions. Dropping default ones again\n"); diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 517792b9d..b397728b4 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -207,13 +207,13 @@ postgres_create_tables (void *cls) */ static enum GNUNET_GenericReturnValue postgres_setup_partitions (void *cls, - const uint32_t *num) + const uint32_t num) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_Context *conn; enum GNUNET_GenericReturnValue ret; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint32 (num), + GNUNET_PQ_query_param_uint32 (&num), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_PreparedStatement ps[] = { diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index a3c2e2ca2..9841d45dc 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -2242,7 +2242,7 @@ struct TALER_EXCHANGEDB_Plugin */ enum GNUNET_GenericReturnValue (*setup_partitions)(void *cls, - const uint32_t *num); + const uint32_t num); /** * Start a transaction. -- cgit v1.2.3