extend sharding logic that shard nodes can be initialied and dropped

This commit is contained in:
Marco Boss 2022-04-02 18:43:49 +02:00
parent caabee9e94
commit ae75ff2cb4
No known key found for this signature in database
GPG Key ID: 89A3EC33C625C3DF
11 changed files with 576 additions and 264 deletions

View File

@ -59,6 +59,11 @@ static uint32_t num_foreign_servers;
*/
static uint32_t shard_idx;
/**
* -R option: do full shard DB reset
*/
static uint32_t reset_shard_db;
/**
* Main function that will be run.
*
@ -94,10 +99,25 @@ run (void *cls,
"Could not drop tables as requested. Either database was not yet initialized, or permission denied. Consult the logs. Will still try to create new tables.\n");
}
}
if (1 <
if (0 <
reset_shard_db)
{
if (GNUNET_OK != plugin->drop_shard_tables (plugin->cls, reset_shard_db))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not drop shard tables as requested. Either database was not yet initialized or permission denied. Consult the logs.\n");
global_ret = EXIT_FAILURE;
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
"Dropped shard database, please call taler-exchange-dbinit -S <N> to initialize a new shard database\n");
return;
}
if (0 <
shard_idx)
{
if (GNUNET_OK != plugin->create_shard_tables (plugin->cls, shard_idx))
if (GNUNET_OK != plugin->create_shard_tables (plugin->cls,
shard_idx))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not create shard database\n");
@ -226,13 +246,18 @@ main (int argc,
GNUNET_GETOPT_option_uint ('F',
"foreign",
"NUMBER",
"Setup a sharded database whit N foreign servers (shards) / tables",
"Setup a sharded database whit N foreign servers (shards) / tables, must be called as DB superuser",
&num_foreign_servers),
GNUNET_GETOPT_option_uint ('S',
"shard",
"INDEX",
"Setup a shard server, creates tables with INDEX as suffix",
&shard_idx),
GNUNET_GETOPT_option_uint ('R',
"reset-shard",
"OLD_SHARD_IDX",
"reset a shard database, does not reinitialize i.e. call taler-exchange-dbinit -S afterwards (DANGEROUS: all existsing data is lost!)",
&reset_shard_db),
GNUNET_GETOPT_OPTION_END
};
enum GNUNET_GenericReturnValue ret;

View File

@ -8,3 +8,5 @@ bench-db-postgres
exchange-0001.sql
shard-0000.sql
shard-0001.sql
drop0001.sql
shard-drop0001.sql

View File

@ -21,27 +21,38 @@ sql_DATA = \
exchange-0001.sql \
shard-0000.sql \
shard-0001.sql \
shard-drop0001.sql \
drop0001.sql
BUILT_SOURCES = \
shard-0000.sql \
shard-0001.sql \
exchange-0001.sql
exchange-0001.sql \
drop0001.sql \
shard-drop0001.sql
CLEANFILES = \
shard-0000.sql \
shard-0001.sql \
exchange-0001.sql
exchange-0001.sql \
drop0001.sql \
shard-drop0001.sql
exchange-0001.sql: common-0001.sql exchange-0001-part.sql
cat common-0001.sql exchange-0001-part.sql >$@
shard-0001.sql: common-0001.sql
cp common-0001.sql $@
shard-0001.sql: common-0001.sql shard-0001-part.sql
cat common-0001.sql shard-0001-part.sql >$@
shard-0000.sql: exchange-0000.sql
cp exchange-0000.sql $@
drop0001.sql: drop-common.sql drop0001-exchange-part.sql
cat drop-common.sql drop0001-exchange-part.sql >$@
shard-drop0001.sql: drop-common.sql drop0001-shard-part.sql
cat drop-common.sql drop0001-shard-part.sql >$@
EXTRA_DIST = \
exchangedb.conf \
exchangedb-postgres.conf \

View File

@ -17,9 +17,6 @@
-- Everything in one big transaction
BEGIN;
-- Check patch versioning is in place.
SELECT _v.register_patch('exchange-0001', NULL, NULL);
-------------------- Tables ----------------------------
CREATE OR REPLACE FUNCTION create_partitioned_table(
@ -833,7 +830,7 @@ DECLARE
table_name VARCHAR DEFAULT 'aggregation_transient';
BEGIN
EXECUTE FORMAT (
PERFORM create_partitioned_table(
'CREATE TABLE IF NOT EXISTS %I '
'(amount_val INT8 NOT NULL'
',amount_frac INT4 NOT NULL'
@ -1141,7 +1138,7 @@ $$;
------------------------- Partitions ------------------------------
CREATE OR REPLACE FUNCTION create_table_partition(
CREATE OR REPLACE FUNCTION create_hash_partition(
source_table_name VARCHAR
,modulus INTEGER
,partition_num INTEGER
@ -1166,6 +1163,18 @@ BEGIN
END
$$;
CREATE OR REPLACE FUNCTION create_range_partition(
source_table_name VARCHAR
,partition_num INTEGER
)
RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
RAISE NOTICE 'TODO';
END
$$;
CREATE OR REPLACE FUNCTION detach_default_partitions()
RETURNS VOID
LANGUAGE plpgsql
@ -1303,75 +1312,75 @@ BEGIN
LOOP
PERFORM create_table_partition(
PERFORM create_hash_partition(
'wire_targets'
,modulus
,num_partitions
);
PERFORM add_constraints_to_wire_targets_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'reserves'
,modulus
,num_partitions
);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'reserves_in'
,modulus
,num_partitions
);
PERFORM add_constraints_to_reserves_in_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'reserves_close'
,modulus
,num_partitions
);
PERFORM add_constraints_to_reserves_close_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'reserves_out'
,modulus
,num_partitions
);
PERFORM add_constraints_to_reserves_out_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'reserves_out_by_reserve'
,modulus
,num_partitions
);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'known_coins'
,modulus
,num_partitions
);
PERFORM add_constraints_to_known_coins_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'refresh_commitments'
,modulus
,num_partitions
);
PERFORM add_constraints_to_refresh_commitments_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'refresh_revealed_coins'
,modulus
,num_partitions
);
PERFORM add_constraints_to_refresh_revealed_coins_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'refresh_transfer_keys'
,modulus
,num_partitions
);
PERFORM add_constraints_to_refresh_transfer_keys_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'deposits'
,modulus
,num_partitions
@ -1400,72 +1409,72 @@ BEGIN
-- that is right now configurable via AGGREGATOR_SHIFT option.
-- FIXME: range partitioning
-- PERFORM create_table_partition(
-- PERFORM create_range_partition(
-- 'deposits_by_ready'
-- ,modulus
-- ,num_partitions
-- );
--
-- PERFORM create_table_partition(
-- PERFORM create_range_partition(
-- 'deposits_for_matching'
-- ,modulus
-- ,num_partitions
-- );
PERFORM create_table_partition(
PERFORM create_hash_partition(
'refunds'
,modulus
,num_partitions
);
PERFORM add_constraints_to_refunds_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'wire_out'
,modulus
,num_partitions
);
PERFORM add_constraints_to_wire_out_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'aggregation_transient'
,modulus
,num_partitions
);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'aggregation_tracking'
,modulus
,num_partitions
);
PERFORM add_constraints_to_aggregation_tracking_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'recoup'
,modulus
,num_partitions
);
PERFORM add_constraints_to_recoup_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'recoup_by_reserve'
,modulus
,num_partitions
);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'recoup_refresh'
,modulus
,num_partitions
);
PERFORM add_constraints_to_recoup_refresh_partition(num_partitions::varchar);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'prewire'
,modulus
,num_partitions
);
PERFORM create_table_partition(
PERFORM create_hash_partition(
'cs_nonce_locks'
,modulus
,num_partitions
@ -1484,79 +1493,7 @@ $$;
--------------------- Sharding ---------------------------
---------------------- Shards ----------------------------
CREATE OR REPLACE FUNCTION setup_shard(
shard_suffix VARCHAR
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM create_table_wire_targets(shard_suffix);
PERFORM add_constraints_to_wire_targets_partition(shard_suffix);
PERFORM create_table_reserves(shard_suffix);
PERFORM create_table_reserves_in(shard_suffix);
PERFORM add_constraints_to_reserves_in_partition(shard_suffix);
PERFORM create_table_reserves_close(shard_suffix);
PERFORM create_table_reserves_out(shard_suffix);
PERFORM create_table_reserves_out_by_reserve(shard_suffix);
PERFORM create_table_known_coins(shard_suffix);
PERFORM add_constraints_to_known_coins_partition(shard_suffix);
PERFORM create_table_refresh_commitments(shard_suffix);
PERFORM add_constraints_to_refresh_commitments_partition(shard_suffix);
PERFORM create_table_refresh_revealed_coins(shard_suffix);
PERFORM add_constraints_to_refresh_revealed_coins_partition(shard_suffix);
PERFORM create_table_refresh_transfer_keys(shard_suffix);
PERFORM add_constraints_to_refresh_transfer_keys_partition(shard_suffix);
PERFORM create_table_deposits(shard_suffix);
PERFORM add_constraints_to_deposits_partition(shard_suffix);
PERFORM create_table_deposits_by_ready(shard_suffix);
PERFORM create_table_deposits_for_matching(shard_suffix);
PERFORM create_table_refunds(shard_suffix);
PERFORM add_constraints_to_refunds_partition(shard_suffix);
PERFORM create_table_wire_out(shard_suffix);
PERFORM add_constraints_to_wire_out_partition(shard_suffix);
PERFORM create_table_aggregation_transient(shard_suffix);
PERFORM create_table_aggregation_tracking(shard_suffix);
PERFORM add_constraints_to_aggregation_tracking_partition(shard_suffix);
PERFORM create_table_recoup(shard_suffix);
PERFORM add_constraints_to_recoup_partition(shard_suffix);
PERFORM create_table_recoup_by_reserve(shard_suffix);
PERFORM create_table_recoup_refresh(shard_suffix);
PERFORM add_constraints_to_recoup_refresh_partition(shard_suffix);
PERFORM create_table_prewire(shard_suffix);
PERFORM create_table_cs_nonce_locks(shard_suffix);
PERFORM add_constraints_to_cs_nonce_locks_partition(shard_suffix);
END
$$;
------------------------------ Master ----------------------------------
CREATE OR REPLACE FUNCTION create_foreign_table(
CREATE OR REPLACE FUNCTION create_foreign_hash_partition(
source_table_name VARCHAR
,modulus INTEGER
,shard_suffix VARCHAR
@ -1591,6 +1528,18 @@ BEGIN
END
$$;
CREATE OR REPLACE FUNCTION create_foreign_range_partition(
source_table_name VARCHAR
,partition_num INTEGER
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
BEGIN
RAISE NOTICE 'TODO';
END
$$;
CREATE OR REPLACE FUNCTION prepare_sharding()
RETURNS VOID
LANGUAGE plpgsql
@ -1683,7 +1632,7 @@ $$;
CREATE OR REPLACE FUNCTION create_shard_server(
shard_suffix VARCHAR
shard_idx VARCHAR
,total_num_shards INTEGER
,current_shard_num INTEGER
,remote_host VARCHAR
@ -1728,147 +1677,154 @@ BEGIN
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'wire_targets'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'reserves'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'reserves_in'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'reserves_out'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'reserves_close'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'known_coins'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'refresh_commitments'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'refresh_revealed_coins'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'refresh_transfer_keys'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'deposits'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
-- PERFORM create_foreign_table(
-- 'deposits_by_ready'
-- ,total_num_shards
-- ,shard_suffix
-- ,current_shard_num
-- ,local_user
-- );
-- PERFORM create_foreign_table(
-- 'deposits_for_matching'
-- ,total_num_shards
-- ,shard_suffix
-- ,current_shard_num
-- ,local_user
-- );
PERFORM create_foreign_table(
'refunds'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'wire_out'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'aggregation_tracking'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'recoup'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
'recoup_by_reserve'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'reserves_out_by_reserve'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'reserves_close'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'known_coins'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'refresh_commitments'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'refresh_revealed_coins'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'refresh_transfer_keys'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'deposits'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
-- PERFORM create_foreign_range_partition(
-- 'deposits_by_ready'
-- ,total_num_shards
-- ,shard_suffix
-- ,current_shard_num
-- ,local_user
-- );
-- PERFORM create_foreign_range_partition(
-- 'deposits_for_matching'
-- ,total_num_shards
-- ,shard_suffix
-- ,current_shard_num
-- ,local_user
-- );
PERFORM create_foreign_hash_partition(
'refunds'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'wire_out'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'aggregation_transient'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'aggregation_tracking'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'recoup'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'recoup_by_reserve'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_hash_partition(
'recoup_refresh'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'prewire'
,total_num_shards
,shard_suffix
,current_shard_num
,local_user
);
PERFORM create_foreign_table(
PERFORM create_foreign_hash_partition(
'cs_nonce_locks'
,total_num_shards
,shard_suffix

View File

@ -0,0 +1,76 @@
--
-- This file is part of TALER
-- Copyright (C) 2014--2021 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
-- Everything in one big transaction
BEGIN;
-- This script DROPs all of the common functions we create.
--
-- Unlike the other SQL files, it SHOULD be updated to reflect the
-- latest requirements for dropping tables.
DROP FUNCTION IF EXISTS create_table_prewire;
DROP FUNCTION IF EXISTS create_table_recoup;
DROP FUNCTION IF EXISTS add_constraints_to_recoup_partition;
DROP FUNCTION IF EXISTS create_table_recoup_by_reserve;
DROP FUNCTION IF EXISTS create_table_recoup_refresh;
DROP FUNCTION IF EXISTS add_constraints_to_recoup_refresh_partition;
DROP FUNCTION IF EXISTS create_table_aggregation_transient;
DROP FUNCTION IF EXISTS create_table_aggregation_tracking;
DROP FUNCTION IF EXISTS add_constraints_to_aggregation_tracking_partition;
DROP FUNCTION IF EXISTS create_table_wire_out;
DROP FUNCTION IF EXISTS add_constraints_to_wire_out_partition;
DROP FUNCTION IF EXISTS create_table_wire_targets;
DROP FUNCTION IF EXISTS add_constraints_to_wire_targets_partition;
DROP FUNCTION IF EXISTS create_table_deposits;
DROP FUNCTION IF EXISTS create_table_deposits_by_ready;
DROP FUNCTION IF EXISTS create_table_deposits_for_matching;
DROP FUNCTION IF EXISTS add_constraints_to_deposits_partition;
DROP FUNCTION IF EXISTS create_table_refunds;
DROP FUNCTION IF EXISTS add_constraints_to_refunds_partition;
DROP FUNCTION IF EXISTS create_table_refresh_commitments;
DROP FUNCTION IF EXISTS add_constraints_to_refresh_commitments_partition;
DROP FUNCTION IF EXISTS create_table_refresh_revealed_coins;
DROP FUNCTION IF EXISTS add_constraints_to_refresh_revealed_coins_partition;
DROP FUNCTION IF EXISTS create_table_refresh_transfer_keys;
DROP FUNCTION IF EXISTS add_constraints_to_refresh_transfer_keys_partition;
DROP FUNCTION IF EXISTS create_table_known_coins;
DROP FUNCTION IF EXISTS add_constraints_to_known_coins_partition;
DROP FUNCTION IF EXISTS create_table_reserves_close;
DROP FUNCTION IF EXISTS add_constraints_to_reserves_close_partition;
DROP FUNCTION IF EXISTS create_table_reserves_out;
DROP FUNCTION IF EXISTS create_table_reserves_out_by_reserve;
DROP FUNCTION IF EXISTS add_constraints_to_reserves_out_partition;
DROP FUNCTION IF EXISTS create_table_reserves_in;
DROP FUNCTION IF EXISTS add_constraints_to_reserves_in_partition;
DROP FUNCTION IF EXISTS create_table_reserves;
DROP FUNCTION IF EXISTS create_table_cs_nonce_locks;
DROP FUNCTION IF EXISTS add_constraints_to_cs_nonce_locks_partition;
DROP FUNCTION IF EXISTS create_partitioned_table;
DROP FUNCTION IF EXISTS create_hash_partition;
DROP FUNCTION IF EXISTS create_range_partition;
DROP FUNCTION IF EXISTS create_partitions;
DROP FUNCTION IF EXISTS detach_default_partitions;
DROP FUNCTION IF EXISTS drop_default_partitions;
DROP FUNCTION IF EXISTS prepare_sharding;
DROP FUNCTION IF EXISTS create_foreign_hash_partition;
DROP FUNCTION IF EXISTS create_foreign_range_partition;
DROP FUNCTION IF EXISTS create_foreign_servers;
DROP FUNCTION IF EXISTS create_shard_server;
COMMIT;

View File

@ -14,19 +14,13 @@
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
-- Everything in one big transaction
BEGIN;
-- This script DROPs all of the tables we create.
--
-- Unlike the other SQL files, it SHOULD be updated to reflect the
-- latest requirements for dropping tables.
-- Unregister patch (exchange-0001.sql)
SELECT _v.unregister_patch('exchange-0001');
-- Drops for exchange-0001.sql
-- Drops for exchange-0001-part.sql
DROP TRIGGER IF EXISTS reserves_out_on_insert ON reserves_out;
DROP TRIGGER IF EXISTS reserves_out_on_delete ON reserves_out;
DROP TRIGGER IF EXISTS deposits_on_insert ON deposits;
@ -43,70 +37,32 @@ DROP TABLE IF EXISTS wire_accounts CASCADE;
DROP TABLE IF EXISTS signkey_revocations CASCADE;
DROP TABLE IF EXISTS work_shards CASCADE;
DROP TABLE IF EXISTS prewire CASCADE;
DROP FUNCTION IF EXISTS create_table_prewire;
DROP TABLE IF EXISTS recoup CASCADE;
DROP FUNCTION IF EXISTS create_table_recoup;
DROP FUNCTION IF EXISTS add_constraints_to_recoup_partition;
DROP TABLE IF EXISTS recoup_refresh CASCADE;
DROP FUNCTION IF EXISTS create_table_recoup_refresh;
DROP FUNCTION IF EXISTS add_constraints_to_recoup_refresh_partition;
DROP TABLE IF EXISTS aggregation_transient CASCADE;
DROP FUNCTION IF EXISTS create_table_aggregation_transient;
DROP TABLE IF EXISTS aggregation_tracking CASCADE;
DROP FUNCTION IF EXISTS create_table_aggregation_tracking;
DROP FUNCTION IF EXISTS add_constraints_to_aggregation_tracking_partition;
DROP TABLE IF EXISTS wire_out CASCADE;
DROP FUNCTION IF EXISTS create_table_wire_out;
DROP FUNCTION IF EXISTS add_constraints_to_wire_out_partition;
DROP TABLE IF EXISTS wire_targets CASCADE;
DROP FUNCTION IF EXISTS create_table_wire_targets;
DROP FUNCTION IF EXISTS add_constraints_to_wire_targets_partition;
DROP TABLE IF EXISTS wire_fee CASCADE;
DROP TABLE IF EXISTS deposits CASCADE;
DROP FUNCTION IF EXISTS create_table_deposits;
DROP TABLE IF EXISTS deposits_by_ready CASCADE;
DROP FUNCTION IF EXISTS create_table_deposits_by_ready;
DROP TABLE IF EXISTS deposits_for_matching CASCADE;
DROP FUNCTION IF EXISTS create_table_deposits_for_matching;
DROP FUNCTION IF EXISTS add_constraints_to_deposits_partition;
DROP TABLE IF EXISTS extension_details CASCADE;
DROP TABLE IF EXISTS refunds CASCADE;
DROP FUNCTION IF EXISTS create_table_refunds;
DROP FUNCTION IF EXISTS add_constraints_to_refunds_partition;
DROP TABLE IF EXISTS refresh_commitments CASCADE;
DROP FUNCTION IF EXISTS create_table_refresh_commitments;
DROP FUNCTION IF EXISTS add_constraints_to_refresh_commitments_partition;
DROP TABLE IF EXISTS refresh_revealed_coins CASCADE;
DROP FUNCTION IF EXISTS create_table_refresh_revealed_coins;
DROP FUNCTION IF EXISTS add_constraints_to_refresh_revealed_coins_partition;
DROP TABLE IF EXISTS refresh_transfer_keys CASCADE;
DROP FUNCTION IF EXISTS create_table_refresh_transfer_keys;
DROP FUNCTION IF EXISTS add_constraints_to_refresh_transfer_keys_partition;
DROP TABLE IF EXISTS known_coins CASCADE;
DROP FUNCTION IF EXISTS create_table_known_coins;
DROP FUNCTION IF EXISTS add_constraints_to_known_coins_partition;
DROP TABLE IF EXISTS reserves_close CASCADE;
DROP FUNCTION IF EXISTS create_table_reserves_close;
DROP FUNCTION IF EXISTS add_constraints_to_reserves_close_partition;
DROP TABLE IF EXISTS reserves_out CASCADE;
DROP FUNCTION IF EXISTS create_table_reserves_out;
DROP TABLE IF EXISTS reserves_out_by_reserve CASCADE;
DROP FUNCTION IF EXISTS create_table_reserves_out_by_reserve;
DROP FUNCTION IF EXISTS add_constraints_to_reserves_out_partition;
DROP TABLE IF EXISTS reserves_in CASCADE;
DROP FUNCTION IF EXISTS create_table_reserves_in;
DROP FUNCTION IF EXISTS add_constraints_to_reserves_in_partition;
DROP TABLE IF EXISTS reserves CASCADE;
DROP FUNCTION IF EXISTS create_table_reserves;
DROP TABLE IF EXISTS denomination_revocations CASCADE;
DROP TABLE IF EXISTS denominations CASCADE;
DROP TABLE IF EXISTS cs_nonce_locks CASCADE;
DROP FUNCTION IF EXISTS create_table_cs_nonce_locks;
DROP FUNCTION IF EXISTS add_constraints_to_cs_nonce_locks_partition;
DROP TABLE IF EXISTS global_fee CASCADE;
DROP TABLE IF EXISTS recoup_by_reserve CASCADE;
DROP TABLE IF EXISTS aggregation_transient CASCADE;
DROP TABLE IF EXISTS partners CASCADE;
@ -144,17 +100,6 @@ DROP FUNCTION IF EXISTS exchange_do_account_merge;
DROP FUNCTION IF EXISTS exchange_do_history_request;
DROP FUNCTION IF EXISTS exchange_do_close_request;
DROP FUNCTION IF EXISTS create_table_partition;
DROP FUNCTION IF EXISTS create_partitions;
DROP FUNCTION IF EXISTS detach_default_partitions;
DROP FUNCTION IF EXISTS drop_default_partitions;
DROP FUNCTION IF EXISTS prepare_sharding;
DROP FUNCTION IF EXISTS create_foreign_table;
DROP FUNCTION IF EXISTS create_foreign_servers;
DROP FUNCTION IF EXISTS create_shard_server;
-- And we're out of here...
COMMIT;

View File

@ -0,0 +1,27 @@
--
-- This file is part of TALER
-- Copyright (C) 2014--2021 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
BEGIN;
-- Unregister patch (shard-0001.sql)
SELECT _v.unregister_patch('shard-0001');
-- Drops for shard-0001-part.sql
DROP FUNCTION IF EXISTS drop_shard;
DROP FUNCTION IF EXISTS setup_shard;
COMMIT;

View File

@ -17,6 +17,9 @@
-- Everything in one big transaction
BEGIN;
-- Check patch versioning is in place.
SELECT _v.register_patch('exchange-0001', NULL, NULL);
-- ------------------------------ denominations ----------------------------------------
CREATE TABLE IF NOT EXISTS denominations

View File

@ -174,6 +174,63 @@ postgres_drop_tables (void *cls)
}
/**
* Drop all Taler shard tables. This should only be used by testcases.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param old_idx the index which was used when the shard database was initialized
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static enum GNUNET_GenericReturnValue
postgres_drop_shard_tables (void *cls,
uint32_t old_idx)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret = GNUNET_OK;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&old_idx),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("drop_shard_tables",
"SELECT"
" drop_shard"
" ($1);",
1),
GNUNET_PQ_PREPARED_STATEMENT_END
};
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
NULL,
NULL,
ps);
if (NULL == conn)
return GNUNET_SYSERR;
if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
"drop_shard_tables",
params))
ret = GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
"shard-drop",
NULL,
NULL);
if (NULL == conn)
return GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
if (NULL != pg->conn)
{
GNUNET_PQ_disconnect (pg->conn);
pg->conn = NULL;
pg->init = false;
}
return ret;
}
/**
* Create the necessary tables if they are not present
*
@ -13140,6 +13197,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin);
plugin->cls = pg;
plugin->drop_tables = &postgres_drop_tables;
plugin->drop_shard_tables = &postgres_drop_shard_tables;
plugin->create_tables = &postgres_create_tables;
plugin->create_shard_tables = &postgres_create_shard_tables;
plugin->setup_partitions = &postgres_setup_partitions;

View File

@ -0,0 +1,199 @@
--
-- This file is part of TALER
-- Copyright (C) 2014--2022 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
-- Everything in one big transaction
BEGIN;
-- Check patch versioning is in place.
SELECT _v.register_patch('shard-0001', NULL, NULL);
CREATE OR REPLACE FUNCTION setup_shard(
shard_idx INTEGER
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
shard_suffix VARCHAR;
BEGIN
shard_suffix = shard_idx::varchar;
PERFORM create_table_wire_targets(shard_suffix);
PERFORM add_constraints_to_wire_targets_partition(shard_suffix);
PERFORM create_table_reserves(shard_suffix);
PERFORM create_table_reserves_in(shard_suffix);
PERFORM add_constraints_to_reserves_in_partition(shard_suffix);
PERFORM create_table_reserves_close(shard_suffix);
PERFORM create_table_reserves_out(shard_suffix);
PERFORM create_table_reserves_out_by_reserve(shard_suffix);
PERFORM create_table_known_coins(shard_suffix);
PERFORM add_constraints_to_known_coins_partition(shard_suffix);
PERFORM create_table_refresh_commitments(shard_suffix);
PERFORM add_constraints_to_refresh_commitments_partition(shard_suffix);
PERFORM create_table_refresh_revealed_coins(shard_suffix);
PERFORM add_constraints_to_refresh_revealed_coins_partition(shard_suffix);
PERFORM create_table_refresh_transfer_keys(shard_suffix);
PERFORM add_constraints_to_refresh_transfer_keys_partition(shard_suffix);
PERFORM create_table_deposits(shard_suffix);
PERFORM add_constraints_to_deposits_partition(shard_suffix);
PERFORM create_table_deposits_by_ready(shard_suffix);
PERFORM create_table_deposits_for_matching(shard_suffix);
PERFORM create_table_refunds(shard_suffix);
PERFORM add_constraints_to_refunds_partition(shard_suffix);
PERFORM create_table_wire_out(shard_suffix);
PERFORM add_constraints_to_wire_out_partition(shard_suffix);
PERFORM create_table_aggregation_transient(shard_suffix);
PERFORM create_table_aggregation_tracking(shard_suffix);
PERFORM add_constraints_to_aggregation_tracking_partition(shard_suffix);
PERFORM create_table_recoup(shard_suffix);
PERFORM add_constraints_to_recoup_partition(shard_suffix);
PERFORM create_table_recoup_by_reserve(shard_suffix);
PERFORM create_table_recoup_refresh(shard_suffix);
PERFORM add_constraints_to_recoup_refresh_partition(shard_suffix);
PERFORM create_table_prewire(shard_suffix);
PERFORM create_table_cs_nonce_locks(shard_suffix);
PERFORM add_constraints_to_cs_nonce_locks_partition(shard_suffix);
END
$$;
CREATE OR REPLACE FUNCTION drop_shard(
shard_idx INTEGER
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
shard_suffix VARCHAR;
BEGIN
shard_suffix = shard_idx::varchar;
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'wire_targets_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'reserves_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'reserves_in_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'reserves_out_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'reserves_close_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'known_coins_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'refresh_commitments_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'refresh_revealed_coins_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'refresh_transfer_keys_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'deposits_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'deposits_by_ready_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'deposits_for_matching_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'refunds_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'wire_out_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'aggregation_transient_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'aggregation_tracking_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'recoup_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'recoup_by_reserve_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'reserves_out_by_reserve_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'recoup_refresh_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'prewire_' || shard_suffix
);
EXECUTE FORMAT(
'DROP TABLE IF EXISTS %I CASCADE'
,'cs_nonce_locks_' || shard_suffix
);
END
$$;
COMMIT;

View File

@ -2244,6 +2244,16 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_GenericReturnValue
(*drop_tables)(void *cls);
/**
* Drop the Taler tables on a shard. This should only be used in testcases.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param old_idx the index which was used then the database was initialized.
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
(*drop_shard_tables)(void *cls,
uint32_t old_idx);
/**
* Create the necessary tables if they are not present