Skip to content

Commit

Permalink
Change the internal way to register log sequence states. Previously t…
Browse files Browse the repository at this point in the history
…he state of application sequences and emaj log sequences at each mark were recorded into the unique emaj_sequence table. But 1) both sequence types are never accessed together, 2) the only usefull log sequences attributes are the last value and the is_called flag and 3) there is a need to also record some application table properties at mark time for future use. So this patch moves the data related to log sequences towards a new emaj_table table. This new technical table stores for each application table and each mark the last value of the related log sequence, as well as the approximate number of pages and tuples of the table taken from pg_class. The application sequences states remain in the emaj_sequence table.
  • Loading branch information
beaud76 committed Jul 17, 2020
1 parent eeb181b commit e6622e9
Show file tree
Hide file tree
Showing 78 changed files with 11,879 additions and 9,158 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ E-Maj - Change log
handle these TRUNCATE statements.
* A new emaj_purge_histories() function is callable by external scheduler
tool to purge various emaj history tables, based on a retention delay.
* Change the internal way to register log sequence states. This has no
impact for users.
* Minor coding changes.

###Bug fixes:###
Expand Down
1,091 changes: 1,079 additions & 12 deletions sql/emaj--3.3.0--devel.sql

Large diffs are not rendered by default.

253 changes: 134 additions & 119 deletions sql/emaj--devel.sql

Large diffs are not rendered by default.

253 changes: 134 additions & 119 deletions sql/emaj-devel.sql

Large diffs are not rendered by default.

916 changes: 482 additions & 434 deletions test/10/expected/adm1.out

Large diffs are not rendered by default.

541 changes: 278 additions & 263 deletions test/10/expected/adm2.out

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/10/expected/adm3.out
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,10 @@ select * from emaj.emaj_verify_all();
-- a removal while the group is LOGGING fails
select emaj.emaj_remove_table('phil''s schema3','mytbl4');
ERROR: relation "emaj_phil's schema3.mytbl4_log_seq" does not exist
LINE 1: ...alue ELSE rel.last_value - increment_by END FROM "emaj_phil...
LINE 1: ...lled THEN last_value ELSE last_value - 1 END FROM "emaj_phil...
^
QUERY: SELECT CASE WHEN rel.is_called THEN rel.last_value ELSE rel.last_value - increment_by END FROM "emaj_phil's schema3".mytbl4_log_seq rel, pg_sequences WHERE schemaname = 'emaj_phil''s schema3' AND sequencename = 'mytbl4_log_seq'
CONTEXT: PL/pgSQL function emaj._log_stat_tbl(emaj.emaj_relation,bigint,bigint) line 23 at EXECUTE
QUERY: SELECT CASE WHEN is_called THEN last_value ELSE last_value - 1 END FROM "emaj_phil's schema3".mytbl4_log_seq
CONTEXT: PL/pgSQL function emaj._log_stat_tbl(emaj.emaj_relation,bigint,bigint) line 20 at EXECUTE
SQL statement "WITH stat_group1 AS ( -- for each group, time id of the last active mark
SELECT mark_group, max(mark_time_id) AS last_mark_time_id
FROM emaj.emaj_mark
Expand Down
78 changes: 41 additions & 37 deletions test/10/expected/alter_logging.out
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,12 @@ begin;
myGroup2 | Just after ADD_TBL | 6098 | f | f | | |
(1 row)

select * from emaj.emaj_sequence where sequ_name = 'mytbl7_log_seq' order by sequ_time_id;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_start_val | sequ_increment | sequ_max_val | sequ_min_val | sequ_cache_val | sequ_is_cycled | sequ_is_called
----------------+----------------+--------------+---------------+----------------+----------------+---------------------+--------------+----------------+----------------+----------------
emaj_myschema2 | mytbl7_log_seq | 6096 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | f
emaj_myschema2 | mytbl7_log_seq | 6098 | 2 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | t
select tbl_schema, tbl_name, tbl_time_id, tbl_log_seq_last_val from emaj.emaj_table
where tbl_name = 'mytbl7' order by tbl_time_id;
tbl_schema | tbl_name | tbl_time_id | tbl_log_seq_last_val
------------+----------+-------------+----------------------
myschema2 | mytbl7 | 6096 | 0
myschema2 | mytbl7 | 6098 | 2
(2 rows)

rollback;
Expand All @@ -894,10 +895,11 @@ begin;
1
(1 row)

select * from emaj.emaj_sequence where sequ_name = 'mytbl7_log_seq' order by sequ_time_id limit 1;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_start_val | sequ_increment | sequ_max_val | sequ_min_val | sequ_cache_val | sequ_is_cycled | sequ_is_called
----------------+----------------+--------------+---------------+----------------+----------------+---------------------+--------------+----------------+----------------+----------------
emaj_myschema2 | mytbl7_log_seq | 6096 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | f
select tbl_schema, tbl_name, tbl_time_id, tbl_log_seq_last_val from emaj.emaj_table
where tbl_name = 'mytbl7' order by tbl_time_id limit 1;
tbl_schema | tbl_name | tbl_time_id | tbl_log_seq_last_val
------------+----------+-------------+----------------------
myschema2 | mytbl7 | 6096 | 0
(1 row)

rollback;
Expand All @@ -919,10 +921,11 @@ begin;
Warning | The table myschema2.mytbl7 has only been rolled back to its latest group attachment (<timestamp>)
(3 rows)

select * from emaj.emaj_sequence where sequ_schema = 'emaj_myschema2' and sequ_name = 'mytbl7_log_seq' order by sequ_time_id;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_start_val | sequ_increment | sequ_max_val | sequ_min_val | sequ_cache_val | sequ_is_cycled | sequ_is_called
----------------+----------------+--------------+---------------+----------------+----------------+---------------------+--------------+----------------+----------------+----------------
emaj_myschema2 | mytbl7_log_seq | 6096 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | f
select tbl_schema, tbl_name, tbl_time_id, tbl_log_seq_last_val from emaj.emaj_table
where tbl_schema = 'myschema2' and tbl_name = 'mytbl7' order by tbl_time_id;
tbl_schema | tbl_name | tbl_time_id | tbl_log_seq_last_val
------------+----------+-------------+----------------------
myschema2 | mytbl7 | 6096 | 0
(1 row)

select * from emaj.emaj_seq_hole where sqhl_schema = 'myschema2' and sqhl_table = 'mytbl7';
Expand Down Expand Up @@ -1006,11 +1009,12 @@ select * from emaj.emaj_consolidate_rollback_group('myGroup2', 'Logged_Rlbk_End'
3
(1 row)

select * from emaj.emaj_sequence where sequ_schema = 'emaj_myschema2' and sequ_name = 'mytbl7_log_seq' order by sequ_time_id;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_start_val | sequ_increment | sequ_max_val | sequ_min_val | sequ_cache_val | sequ_is_cycled | sequ_is_called
----------------+----------------+--------------+---------------+----------------+----------------+---------------------+--------------+----------------+----------------+----------------
emaj_myschema2 | mytbl7_log_seq | 6096 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | f
emaj_myschema2 | mytbl7_log_seq | 6102 | 7 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | t
select tbl_schema, tbl_name, tbl_time_id, tbl_log_seq_last_val from emaj.emaj_table
where tbl_schema = 'myschema2' and tbl_name = 'mytbl7' order by tbl_time_id;
tbl_schema | tbl_name | tbl_time_id | tbl_log_seq_last_val
------------+----------+-------------+----------------------
myschema2 | mytbl7 | 6096 | 0
myschema2 | mytbl7 | 6102 | 7
(2 rows)

-- perform some other updates
Expand Down Expand Up @@ -1349,12 +1353,12 @@ begin;
myschema1 | mytbl2b | [6052,6109) | myGroup1 | r | emaj_myschema1 | mytbl2b_log_1 | 0
(2 rows)

select * from emaj.emaj_sequence where
sequ_name in ('mytbl2b_log_seq', 'myTbl3_log_seq') order by sequ_time_id desc, sequ_name limit 2;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_start_val | sequ_increment | sequ_max_val | sequ_min_val | sequ_cache_val | sequ_is_cycled | sequ_is_called
----------------+-----------------+--------------+---------------+----------------+----------------+---------------------+--------------+----------------+----------------+----------------
emaj_myschema1 | myTbl3_log_seq | 6109 | 3 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | t
emaj_myschema1 | mytbl2b_log_seq | 6109 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | f | f
select tbl_schema, tbl_name, tbl_time_id, tbl_log_seq_last_val from emaj.emaj_table
where tbl_name in ('mytbl2b', 'myTbl3') order by tbl_time_id desc, tbl_name limit 2;
tbl_schema | tbl_name | tbl_time_id | tbl_log_seq_last_val
------------+----------+-------------+----------------------
myschema1 | myTbl3 | 6109 | 3
myschema1 | mytbl2b | 6109 | 0
(2 rows)

select * from emaj.emaj_mark where mark_group = 'myGroup1' and mark_name = '2 tables removed from myGroup1';
Expand Down Expand Up @@ -2111,19 +2115,6 @@ select rel_schema, rel_tblseq, rel_time_range, rel_group, rel_kind, rel_log_sche
myschema2 | mytbl2 | [6151,) | myGroup2 | r | emaj_myschema2 | mytbl2_log |
(16 rows)

select sequ_schema, sequ_name, sequ_time_id, sequ_last_val, sequ_is_called from emaj.emaj_sequence
where sequ_schema = 'emaj_myschema2' and sequ_name = 'mytbl1_log_seq' order by sequ_name, sequ_time_id;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_is_called
----------------+----------------+--------------+---------------+----------------
emaj_myschema2 | mytbl1_log_seq | 6144 | 1 | f
emaj_myschema2 | mytbl1_log_seq | 6145 | 1 | t
emaj_myschema2 | mytbl1_log_seq | 6147 | 2 | f
emaj_myschema2 | mytbl1_log_seq | 6148 | 2 | f
emaj_myschema2 | mytbl1_log_seq | 6149 | 2 | t
emaj_myschema2 | mytbl1_log_seq | 6151 | 3 | f
emaj_myschema2 | mytbl1_log_seq | 6152 | 3 | f
(7 rows)

select sequ_schema, sequ_name, sequ_time_id, sequ_last_val, sequ_is_called from emaj.emaj_sequence
where sequ_schema = 'myschema2' and sequ_name like 'myseq%' order by sequ_name, sequ_time_id;
sequ_schema | sequ_name | sequ_time_id | sequ_last_val | sequ_is_called
Expand All @@ -2141,6 +2132,19 @@ select sequ_schema, sequ_name, sequ_time_id, sequ_last_val, sequ_is_called from
myschema2 | myseq2 | 6152 | 3 | f
(11 rows)

select tbl_schema, tbl_name, tbl_time_id, tbl_log_seq_last_val from emaj.emaj_table
where tbl_schema = 'myschema2' and tbl_name = 'mytbl1' order by tbl_time_id;
tbl_schema | tbl_name | tbl_time_id | tbl_log_seq_last_val
------------+----------+-------------+----------------------
myschema2 | mytbl1 | 6144 | 0
myschema2 | mytbl1 | 6145 | 1
myschema2 | mytbl1 | 6147 | 1
myschema2 | mytbl1 | 6148 | 1
myschema2 | mytbl1 | 6149 | 2
myschema2 | mytbl1 | 6151 | 2
myschema2 | mytbl1 | 6152 | 2
(7 rows)

-----------------------------
-- change group ownership for some tables and sequences without updating emaj_group_def
-----------------------------
Expand Down
7 changes: 4 additions & 3 deletions test/10/expected/check.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ select count(*) from pg_proc, pg_namespace
where pg_namespace.oid=pronamespace and nspname = 'emaj' and (proname like E'emaj\\_%' or proname like E'\\_%');
count
-------
177
178
(1 row)

select count(*) from pg_proc, pg_namespace
Expand Down Expand Up @@ -139,8 +139,9 @@ select funcname, calls from pg_stat_user_functions
_gen_sql_groups | 28
_gen_sql_seq | 41
_gen_sql_tbl | 55
_get_current_sequence_state | 2852
_get_current_sequence_state | 752
_get_default_tablespace | 20
_get_log_sequence_last_value | 2100
_get_previous_mark_group | 37
_import_groups_conf | 10
_import_groups_conf_exec | 10
Expand Down Expand Up @@ -261,7 +262,7 @@ select funcname, calls from pg_stat_user_functions
emaj_unprotect_group | 8
emaj_unprotect_mark_group | 6
emaj_verify_all | 48
(173 rows)
(174 rows)

-- count the total number of user-callable function calls (those who failed are not counted)
select sum(calls) from pg_stat_user_functions where funcname like E'emaj\\_%';
Expand Down
26 changes: 25 additions & 1 deletion test/10/expected/install.out
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ select relname from pg_catalog.pg_class,
emaj_schema
emaj_seq_hole
emaj_sequence
emaj_table
emaj_time_stamp
emaj_time_stamp_time_id_seq
(21 rows)
(22 rows)

-- check the emaj_param content
SELECT param_value_text FROM emaj.emaj_param WHERE param_key = 'emaj_version';
Expand Down Expand Up @@ -663,6 +664,28 @@ Foreign-key constraints:
sequ_time_id | bigint | sequ_time_id
primary key, btree, for table "emaj.emaj_sequence"

Table "emaj.emaj_table"
Column | Type | Collation | Nullable | Default
----------------------+------------------+-----------+----------+---------
tbl_schema | text | | not null |
tbl_name | text | | not null |
tbl_time_id | bigint | | not null |
tbl_pages | integer | | |
tbl_tuples | double precision | | |
tbl_log_seq_last_val | bigint | | not null |
Indexes:
"emaj_table_pkey" PRIMARY KEY, btree (tbl_schema, tbl_name, tbl_time_id)
Foreign-key constraints:
"emaj_table_tbl_time_id_fkey" FOREIGN KEY (tbl_time_id) REFERENCES emaj.emaj_time_stamp(time_id)

Index "emaj.emaj_table_pkey"
Column | Type | Definition
-------------+--------+-------------
tbl_schema | text | tbl_schema
tbl_name | text | tbl_name
tbl_time_id | bigint | tbl_time_id
primary key, btree, for table "emaj.emaj_table"

Table "emaj.emaj_time_stamp"
Column | Type | Collation | Nullable | Default
----------------------+--------------------------+-----------+----------+-------------------------------------------------------
Expand All @@ -685,6 +708,7 @@ Referenced by:
TABLE "emaj.emaj_seq_hole" CONSTRAINT "emaj_seq_hole_sqhl_begin_time_id_fkey" FOREIGN KEY (sqhl_begin_time_id) REFERENCES emaj.emaj_time_stamp(time_id)
TABLE "emaj.emaj_seq_hole" CONSTRAINT "emaj_seq_hole_sqhl_end_time_id_fkey" FOREIGN KEY (sqhl_end_time_id) REFERENCES emaj.emaj_time_stamp(time_id)
TABLE "emaj.emaj_sequence" CONSTRAINT "emaj_sequence_sequ_time_id_fkey" FOREIGN KEY (sequ_time_id) REFERENCES emaj.emaj_time_stamp(time_id)
TABLE "emaj.emaj_table" CONSTRAINT "emaj_table_tbl_time_id_fkey" FOREIGN KEY (tbl_time_id) REFERENCES emaj.emaj_time_stamp(time_id)

Index "emaj.emaj_time_stamp_pkey"
Column | Type | Definition
Expand Down
3 changes: 2 additions & 1 deletion test/10/expected/install_upgrade.out
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ select relname from pg_catalog.pg_class,
emaj_schema
emaj_seq_hole
emaj_sequence
emaj_table
emaj_time_stamp
emaj_time_stamp_time_id_seq
(21 rows)
(22 rows)

-- check the emaj_param content
SELECT param_value_text FROM emaj.emaj_param WHERE param_key = 'emaj_version';
Expand Down

0 comments on commit e6622e9

Please sign in to comment.