add partitions to new p2p tables

This commit is contained in:
Christian Grothoff 2022-03-26 09:00:19 +01:00
parent 238761c87d
commit 783e2ae424
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 498 additions and 201 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,3 +26,7 @@ IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
# After how long do we forget about reserves? Should be above
# the legal expiration timeframe of withdrawn coins.
LEGAL_RESERVE_EXPIRATION_TIME = 7 years
# What is the desired delay between a transaction being ready and the
# aggregator triggering on it?
AGGREGATOR_SHIFT = 1 s

View File

@ -229,6 +229,28 @@ BEGIN
);
PERFORM add_constraints_to_deposits_partition(num_partitions::varchar);
-- TODO: dynamically (!) creating/deleting deposits partitions:
-- create new partitions 'as needed', drop old ones once the aggregator has made
-- them empty; as 'new' deposits will always have deadlines in the future, this
-- would basically guarantee no conflict between aggregator and exchange service!
-- SEE also: https://www.cybertec-postgresql.com/en/automatic-partition-creation-in-postgresql/
-- (article is slightly wrong, as this works:)
--CREATE TABLE tab (
-- id bigint GENERATED ALWAYS AS IDENTITY,
-- ts timestamp NOT NULL,
-- data text
-- PARTITION BY LIST ((ts::date));
-- CREATE TABLE tab_def PARTITION OF tab DEFAULT;
-- BEGIN
-- CREATE TABLE tab_part2 (LIKE tab);
-- insert into tab_part2 (id,ts, data) values (5,'2022-03-21', 'foo');
-- alter table tab attach partition tab_part2 for values in ('2022-03-21');
-- commit;
-- Naturally, to ensure this is actually 100% conflict-free, we'd
-- need to create tables at the granularity of the wire/refund deadlines;
-- that is right now configurable via AGGREGATOR_SHIFT option.
PERFORM create_table_partition(
'refunds'
,modulus
@ -287,4 +309,4 @@ BEGIN
END
$$;
COMMIT;
COMMIT;

View File

@ -115,6 +115,12 @@ struct PostgresClosure
*/
struct GNUNET_TIME_Relative legal_reserve_expiration_time;
/**
* What delay should we introduce before ready transactions
* are actually aggregated?
*/
struct GNUNET_TIME_Relative aggregator_shift;
/**
* Which currency should we assume all amounts to be in?
*/
@ -5993,7 +5999,8 @@ postgres_get_ready_deposit (void *cls,
};
enum GNUNET_DB_QueryStatus qs;
now = GNUNET_TIME_absolute_get ();
now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
pg->aggregator_shift);
GNUNET_assert (start_shard_row < end_shard_row);
GNUNET_assert (end_shard_row <= INT32_MAX);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@ -6154,7 +6161,7 @@ postgres_iterate_matching_deposits (
uint32_t limit)
{
struct PostgresClosure *pg = cls;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Absolute now = {0};
uint64_t shard = compute_shard (merchant_pub);
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (merchant_pub),
@ -6173,6 +6180,8 @@ postgres_iterate_matching_deposits (
};
enum GNUNET_DB_QueryStatus qs;
now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
pg->aggregator_shift);
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
"deposits_iterate_matching",
params,
@ -13012,6 +13021,17 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
GNUNET_free (pg);
return NULL;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
"exchangedb",
"AGGREGATOR_SHIFT",
&pg->aggregator_shift))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
"exchangedb",
"AGGREGATOR_SHIFT");
}
if (GNUNET_OK !=
TALER_config_get_currency (cfg,
&pg->currency))

View File

@ -28,3 +28,6 @@ IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
# After how long do we forget about reserves? Should be above
# the legal expiration timeframe of withdrawn coins.
LEGAL_RESERVE_EXPIRATION_TIME = 7 years
# Shift to apply before aggregating.
AGGREGATOR_SHIFT = 1s