commit 561f1ede9664df957f7849ad2d71063aaf1c1b08
parent df6585633847490f7f362a23e2f6c99f7944fac1
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date: Wed, 3 Apr 2024 17:04:28 +0200
removed db table partitioning
Diffstat:
5 files changed, 53 insertions(+), 264 deletions(-)
diff --git a/src/donau-tools/donau-dbinit.c b/src/donau-tools/donau-dbinit.c
@@ -36,16 +36,6 @@ static int global_ret;
static int reset_db;
/**
- * -P option: setup a partitioned database
- */
-static uint32_t num_partitions;
-
-/**
- * -f option: force partitions to be created when there is only one
- */
-static int force_create_partitions;
-
-/**
* Main function that will be run.
*
* @param cls closure
@@ -85,9 +75,7 @@ run (void *cls,
}
if (GNUNET_OK !=
- plugin->create_tables (plugin->cls,
- force_create_partitions || num_partitions > 0,
- num_partitions))
+ plugin->create_tables (plugin->cls))
{
fprintf (stderr,
"Failed to initialize database.\n");
@@ -119,15 +107,6 @@ main (int argc,
"reset",
"reset database (DANGEROUS: all existing data is lost!)",
&reset_db),
- 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",
- &num_partitions),
- GNUNET_GETOPT_option_flag ('f',
- "force",
- "Force partitions to be created if there is only one partition",
- &force_create_partitions),
GNUNET_GETOPT_OPTION_END
};
enum GNUNET_GenericReturnValue ret;
diff --git a/src/donaudb/donau-0001.sql b/src/donaudb/donau-0001.sql
@@ -32,122 +32,24 @@ CREATE TABLE donau_tables
,name TEXT NOT NULL
,version TEXT NOT NULL
,action TEXT NOT NULL
- ,partitioned BOOL NOT NULL
- ,by_range BOOL NOT NULL
,finished BOOL NOT NULL DEFAULT(FALSE));
COMMENT ON TABLE donau_tables
IS 'Tables of the donau and their status';
COMMENT ON COLUMN donau_tables.name
- IS 'Base name of the table (without partition/shard)';
+ IS 'Base name of the table';
COMMENT ON COLUMN donau_tables.version
IS 'Version of the DB in which the given action happened';
COMMENT ON COLUMN donau_tables.action
- IS 'Action to take on the table (e.g. create, constrain, or foreign). Create is done for the master table and each partition; constrain is only for partitions or for master if there are no partitions; master only on master (takes no argument); foreign only on master if there are no partitions.';
-COMMENT ON COLUMN donau_tables.partitioned
- IS 'TRUE if the table is partitioned';
-COMMENT ON COLUMN donau_tables.by_range
- IS 'TRUE if the table is partitioned by range';
+ IS 'Action to take on the table (e.g. create, constrain, or foreign).';
COMMENT ON COLUMN donau_tables.finished
IS 'TRUE if the respective migration has been run';
-CREATE FUNCTION create_partitioned_table(
- IN table_definition TEXT -- SQL template for table creation
- ,IN table_name TEXT -- base name of the table
- ,IN main_table_partition_str TEXT -- declaration for how to partition the table
- ,IN partition_suffix TEXT DEFAULT NULL -- NULL: no partitioning, 0: yes partitioning, no sharding, >0: sharding
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- IF (partition_suffix IS NULL)
- THEN
- -- no partitioning, disable option
- main_table_partition_str = '';
- ELSE
- IF (partition_suffix::int > 0)
- THEN
- -- sharding, add shard name
- table_name=table_name || '_' || partition_suffix;
- END IF;
- END IF;
- EXECUTE FORMAT(
- table_definition,
- table_name,
- main_table_partition_str
- );
-END $$;
-
-COMMENT ON FUNCTION create_partitioned_table
- IS 'Generic function to create a table that is partitioned or sharded.';
-
-
-CREATE FUNCTION comment_partitioned_table(
- IN table_comment TEXT
- ,IN table_name TEXT
- ,IN partition_suffix TEXT DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- IF ( (partition_suffix IS NOT NULL) AND
- (partition_suffix::int > 0) )
- THEN
- -- sharding, add shard name
- table_name=table_name || '_' || partition_suffix;
- END IF;
- EXECUTE FORMAT(
- 'COMMENT ON TABLE %s IS %s'
- ,table_name
- ,quote_literal(table_comment)
- );
-END $$;
-
-COMMENT ON FUNCTION comment_partitioned_table
- IS 'Generic function to create a comment on table that is partitioned.';
-
-
-CREATE FUNCTION comment_partitioned_column(
- IN table_comment TEXT
- ,IN column_name TEXT
- ,IN table_name TEXT
- ,IN partition_suffix TEXT DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- IF ( (partition_suffix IS NOT NULL) AND
- (partition_suffix::int > 0) )
- THEN
- -- sharding, add shard name
- table_name=table_name || '_' || partition_suffix;
- END IF;
- EXECUTE FORMAT(
- 'COMMENT ON COLUMN %s.%s IS %s'
- ,table_name
- ,column_name
- ,quote_literal(table_comment)
- );
-END $$;
-
-COMMENT ON FUNCTION comment_partitioned_column
- IS 'Generic function to create a comment on column of a table that is partitioned.';
-
-
---------------------------------------------------------------------------
-- Main DB setup loop
---------------------------------------------------------------------------
-CREATE FUNCTION do_create_tables(
- num_partitions INTEGER
--- NULL: no partitions, add foreign constraints
--- 0: no partitions, no foreign constraints
--- 1: only 1 default partition
--- > 1: normal partitions
-)
+CREATE FUNCTION do_create_tables()
RETURNS VOID
LANGUAGE plpgsql
AS $$
@@ -156,8 +58,6 @@ DECLARE
SELECT table_serial_id
,name
,action
- ,partitioned
- ,by_range
FROM donau.donau_tables
WHERE NOT finished
ORDER BY table_serial_id ASC;
@@ -165,113 +65,30 @@ BEGIN
FOR rec IN tc
LOOP
CASE rec.action
- -- "create" actions apply to master and partitions
WHEN 'create'
THEN
- IF (rec.partitioned AND
- (num_partitions IS NOT NULL))
- THEN
- -- Create master table with partitioning.
- EXECUTE FORMAT(
- 'SELECT donau.%s_table_%s (%s)'::text
- ,rec.action
- ,rec.name
- ,quote_literal('0')
- );
- IF (rec.by_range OR
- (num_partitions = 0))
- THEN
- -- Create default partition.
- IF (rec.by_range)
- THEN
- -- Range partition
- EXECUTE FORMAT(
- 'CREATE TABLE donau.%s_default'
- ' PARTITION OF %s'
- ' DEFAULT'
- ,rec.name
- ,rec.name
- );
- ELSE
- -- Hash partition
- EXECUTE FORMAT(
- 'CREATE TABLE donau.%s_default'
- ' PARTITION OF %s'
- ' FOR VALUES WITH (MODULUS 1, REMAINDER 0)'
- ,rec.name
- ,rec.name
- );
- END IF;
- ELSE
- FOR i IN 1..num_partitions LOOP
- -- Create num_partitions
- EXECUTE FORMAT(
- 'CREATE TABLE donau.%I'
- ' PARTITION OF %I'
- ' FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
- ,rec.name || '_' || i
- ,rec.name
- ,num_partitions
- ,i-1
- );
- END LOOP;
- END IF;
- ELSE
- -- Only create master table. No partitions.
- EXECUTE FORMAT(
- 'SELECT donau.%s_table_%s ()'::text
- ,rec.action
- ,rec.name
- );
- END IF;
- -- Constrain action apply to master OR each partition
+ EXECUTE FORMAT(
+ 'SELECT donau.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
WHEN 'constrain'
THEN
- ASSERT rec.partitioned, 'constrain action only applies to partitioned tables';
- IF (num_partitions IS NULL)
- THEN
- -- Constrain master table
- EXECUTE FORMAT(
- 'SELECT donau.%s_table_%s (NULL)'::text
- ,rec.action
- ,rec.name
- );
- ELSE
- IF ( (num_partitions = 0) OR
- (rec.by_range) )
- THEN
- -- Constrain default table
- EXECUTE FORMAT(
- 'SELECT donau.%s_table_%s (%s)'::text
- ,rec.action
- ,rec.name
- ,quote_literal('default')
- );
- ELSE
- -- Constrain each partition
- FOR i IN 1..num_partitions LOOP
- EXECUTE FORMAT(
- 'SELECT donau.%s_table_%s (%s)'::text
- ,rec.action
- ,rec.name
- ,quote_literal(i)
- );
- END LOOP;
- END IF;
- END IF;
- -- Foreign actions only apply if partitioning is off
+ -- Constrain master table
+ EXECUTE FORMAT(
+ 'SELECT donau.%s_table_%s (NULL)'::text
+ ,rec.action
+ ,rec.name
+ );
WHEN 'foreign'
THEN
- IF (num_partitions IS NULL)
- THEN
- -- Add foreign constraints
- EXECUTE FORMAT(
- 'SELECT donau.%s_table_%s (%s)'::text
- ,rec.action
- ,rec.name
- ,NULL
- );
- END IF;
+ -- Add foreign constraints
+ EXECUTE FORMAT(
+ 'SELECT donau.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,NULL
+ );
WHEN 'master'
THEN
EXECUTE FORMAT(
diff --git a/src/donaudb/pg_create_tables.c b/src/donaudb/pg_create_tables.c
@@ -27,24 +27,21 @@
enum GNUNET_GenericReturnValue
-DH_PG_create_tables (void *cls,
- bool support_partitions,
- uint32_t num_partitions)
+DH_PG_create_tables (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret = GNUNET_OK;
+
struct GNUNET_PQ_QueryParam params[] = {
- support_partitions
- ? GNUNET_PQ_query_param_uint32 (&num_partitions)
- : GNUNET_PQ_query_param_null (),
GNUNET_PQ_query_param_end
};
+
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("create_tables",
"SELECT"
" donau.do_create_tables"
- " ($1);"),
+ " ();"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
struct GNUNET_PQ_ExecuteStatement es[] = {
diff --git a/src/donaudb/pg_create_tables.h b/src/donaudb/pg_create_tables.h
@@ -36,9 +36,7 @@
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
-DH_PG_create_tables (void *cls,
- bool support_partitions,
- uint32_t num_partitions);
+DH_PG_create_tables (void *cls);
#endif
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
@@ -216,7 +216,7 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*drop_tables)(void *cls);
+ (*drop_tables)(void *cls);
/**
* Create the necessary tables if they are not present
@@ -229,9 +229,7 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*create_tables)(void *cls,
- bool support_partitions,
- uint32_t num_partitions);
+ (*create_tables)(void *cls);
/**
@@ -243,8 +241,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start)(void *cls,
- const char *name);
+ (*start)(void *cls,
+ const char *name);
/**
@@ -256,8 +254,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start_read_committed)(void *cls,
- const char *name);
+ (*start_read_committed)(void *cls,
+ const char *name);
/**
* Start a READ ONLY serializable transaction.
@@ -268,8 +266,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start_read_only)(void *cls,
- const char *name);
+ (*start_read_only)(void *cls,
+ const char *name);
/**
@@ -279,7 +277,7 @@ struct DONAUDB_Plugin
* @return transaction status
*/
enum GNUNET_DB_QueryStatus
- (*commit)(void *cls);
+ (*commit)(void *cls);
/**
@@ -293,7 +291,7 @@ struct DONAUDB_Plugin
* #GNUNET_SYSERR on hard errors
*/
enum GNUNET_GenericReturnValue
- (*preflight)(void *cls);
+ (*preflight)(void *cls);
/**
@@ -314,7 +312,7 @@ struct DONAUDB_Plugin
* #GNUNET_SYSERR on DB errors
*/
enum GNUNET_GenericReturnValue
- (*gc)(void *cls);
+ (*gc)(void *cls);
/**
@@ -369,7 +367,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*lookup_charity)(
+ (*lookup_charity)(
void *cls,
uint64_t charity_id,
struct DONAUDB_CharityMetaData *meta);
@@ -384,7 +382,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*do_charity_delete)(
+ (*do_charity_delete)(
void *cls,
uint64_t charity_id);
@@ -397,7 +395,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_charities)(
+ (*get_charities)(
void *cls,
DONAUDB_GetCharitiesCallback cb,
void *cb_cls);
@@ -411,7 +409,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*insert_charity)(
+ (*insert_charity)(
void *cls,
const struct DONAU_CharityPublicKeyP *charity_pub,
const char *charity_name,
@@ -430,7 +428,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_donation_units)(
+ (*iterate_donation_units)(
void *cls,
DONAUDB_IterateDonationUnitsCallback cb,
void *cb_cls);
@@ -444,7 +442,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_history)(
+ (*get_history)(
void *cls,
DONAUDB_GetHistoryCallback cb,
void *cb_cls);
@@ -458,7 +456,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*lookup_history_entry)(
+ (*lookup_history_entry)(
void *cls,
const unsigned long long charity_id,
const struct TALER_Amount *final_amount,
@@ -472,7 +470,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*insert_donation_unit)(
+ (*insert_donation_unit)(
void *cls,
const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
@@ -489,7 +487,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_history_entry)(
+ (*insert_history_entry)(
void *cls,
const uint64_t charity_id,
const struct TALER_Amount *final_amount,
@@ -508,7 +506,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_issued_receipt)(
+ (*insert_issued_receipt)(
void *cls,
const size_t num_blinded_sig,
const struct DONAU_BlindedDonationUnitSignature *signatures,
@@ -529,7 +527,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_submitted_receipt)(
+ (*insert_submitted_receipt)(
void *cls,
const struct DONAU_HashDonorTaxId *h_tax_number,
const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
@@ -546,7 +544,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_issued_receipts)(
+ (*lookup_issued_receipts)(
void *cls,
struct DONAU_DonationReceiptHashP h_receitps,
struct DONAUDB_IssuedReceiptsMetaData *meta);
@@ -560,7 +558,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_signing_key)(
+ (*insert_signing_key)(
void *cls,
const struct DONAU_DonauPublicKeyP *donau_pub,
struct DONAUDB_SignkeyMetaData *meta);
@@ -574,7 +572,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_signing_key)(
+ (*lookup_signing_key)(
void *cls,
const struct DONAU_DonauPublicKeyP *donau_pub,
struct DONAUDB_SignkeyMetaData *meta);
@@ -588,7 +586,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_active_signing_keys)(
+ (*iterate_active_signing_keys)(
void *cls,
DONAUDB_IterateActiveSigningKeysCallback cb,
void *cb_cls);