aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange-0003.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/exchange-0003.sql')
-rw-r--r--src/exchangedb/exchange-0003.sql72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/exchangedb/exchange-0003.sql b/src/exchangedb/exchange-0003.sql
new file mode 100644
index 000000000..387746e54
--- /dev/null
+++ b/src/exchangedb/exchange-0003.sql
@@ -0,0 +1,72 @@
1--
2-- This file is part of TALER
3-- Copyright (C) 2021 Taler Systems SA
4--
5-- TALER is free software; you can redistribute it and/or modify it under the
6-- terms of the GNU General Public License as published by the Free Software
7-- Foundation; either version 3, or (at your option) any later version.
8--
9-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
10-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12--
13-- You should have received a copy of the GNU General Public License along with
14-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15--
16
17-- Everything in one big transaction
18BEGIN;
19
20-- Check patch versioning is in place.
21SELECT _v.register_patch('exchange-0003', NULL, NULL);
22
23
24CREATE TABLE IF NOT EXISTS aggregation_wip
25 (aggregation_wip_serial BIGSERIAL UNIQUE
26 ,wtid_raw BYTEA UNIQUE CHECK (LENGTH(wtid_raw)=32)
27 ,wire_target TEXT NOT NULL
28 ,exchange_account_section TEXT NOT NULL
29 ,execution_date INT8 NOT NULL
30 ,PRIMARY KEY (wire_target,execution_date));
31
32COMMENT ON TABLE aggregation_wip
33 IS 'Table tracking aggregations that are work in progress, allowing aggregation work to be divided up between multiple workers. Entries are created when a worker decides that a job is too big for a single worker/transaction and thus should be sharded. They are deleted once the work has concluded, that is a wire_out entry has been created from the final aggregation level.';
34COMMENT ON COLUMN aggregation_wip.wtid_raw
35 IS 'wire transfer identifier to be used';
36COMMENT ON COLUMN aggregation_wip.wire_target
37 IS 'identifies the credit account of the aggregated payment';
38COMMENT ON COLUMN aggregation_wip.execution_date
39 IS 'time when the payment was triggered (is due)';
40COMMENT ON COLUMN aggregation_wip.exchange_account_section
41 IS 'identifies the configuration section with the debit account of this payment';
42
43
44CREATE TABLE IF NOT EXISTS aggregation_tree
45 (aggregation_wip_uuid INT8 REFERENCES aggregation_wip (aggregation_wip_serial) ON DELETE CASCADE
46 ,amount_val INT8 NOT NULL DEFAULT 0
47 ,amount_frac INT4 NOT NULL DEFAULT 0
48 ,shard_offset INT8 NOT NULL
49 ,shard_end INT8 NOT NULL
50 ,shard_level INT4 NOT NULL
51 ,aggregated BOOLEAN NOT NULL DEFAULT false
52 ,summed BOOLEAN NOT NULL DEFAULT false
53 ,PRIMARY KEY (aggregation_wip_uuid,shard_offset,shard_level)
54 );
55COMMENT ON TABLE aggregation_tree
56 IS 'Entry in the B-tree for tracking aggregations that are work in progress. Entries are created when aggregation work is to be done on the level below. The exception is level 0, here each worker that performs a successful SELECT on its locked entry must create a speculative subsequent entry past the SELECTed range. Once the aggregation at for one entry is done, aggregated is set to true. Once an entry is itself aggregated into the level above, summed is set to true. Once the entire tree is summed, the aggregation_wip entry is deleted and the entire tree purged via the cascade.';
57COMMENT ON COLUMN aggregation_tree.amount_val
58 IS 'identifies the amount aggregated so far';
59COMMENT ON COLUMN aggregation_tree.shard_offset
60 IS 'starting offset of this aggregation entry (inclusive) in relation to the level below; at level 0, this refers to the offset in the deposits query';
61COMMENT ON COLUMN aggregation_tree.shard_end
62 IS 'end offset of this aggregation entry (exclusive)';
63COMMENT ON COLUMN aggregation_tree.shard_level
64 IS 'depth of the aggregation tree for this entry; work on a given level can only start if the level below has finished';
65COMMENT ON COLUMN aggregation_tree.aggregated
66 IS 'true once this transactions corresponding to this range have been added up into the amount_val (when false, amount_val is 0 and this column represents work that remains to be done)';
67COMMENT ON COLUMN aggregation_tree.summed
68 IS 'true once this entry has been aggregated into a higher-level entry';
69
70
71-- Complete transaction
72COMMIT;