Skip to content

Commit

Permalink
In the _delete_intermediate_mark_group() function, also delete sequen…
Browse files Browse the repository at this point in the history
…ces data corresponding to mark to delete for tables and sequences that had been removed from their group. There is finaly no reason to keep this information.
  • Loading branch information
beaud76 committed Jan 2, 2018
1 parent e91d6ed commit 301821d
Show file tree
Hide file tree
Showing 21 changed files with 638 additions and 363 deletions.
51 changes: 51 additions & 0 deletions sql/emaj--2.2.1--next_version.sql
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,57 @@ $_delete_before_mark_group$
END;
$_delete_before_mark_group$;

CREATE OR REPLACE FUNCTION emaj._delete_intermediate_mark_group(v_groupName TEXT, v_markName TEXT, v_markId BIGINT, v_markTimeId BIGINT)
RETURNS VOID LANGUAGE plpgsql AS
$_delete_intermediate_mark_group$
-- This function effectively deletes an intermediate mark for a group.
-- It is called by the emaj_delete_mark_group() function.
-- It deletes rows corresponding to the mark to delete from emaj_mark and emaj_sequence
-- The statistical mark_log_rows_before_next column's content of the previous mark is also maintained
-- Input: group name, mark name, mark id and mark time stamp id of the mark to delete
DECLARE
v_previousMark TEXT;
v_nextMark TEXT;
v_previousMarkTimeId BIGINT;
v_nextMarkTimeId BIGINT;
BEGIN
-- delete the sequences related to the mark to delete
-- delete first data related to the application sequences (those attached to the group at the set mark time)
DELETE FROM emaj.emaj_sequence USING emaj.emaj_relation
WHERE sequ_time_id = v_markTimeId
AND rel_group = v_groupName AND rel_kind = 'S'
AND sequ_schema = rel_schema AND sequ_name = rel_tblseq;
-- delete then data related to the log sequences for tables (those attached to the group at the set mark time)
DELETE FROM emaj.emaj_sequence USING emaj.emaj_relation
WHERE sequ_time_id = v_markTimeId
AND rel_group = v_groupName AND rel_kind = 'r'
AND sequ_schema = rel_log_schema AND sequ_name = rel_log_sequence;
-- physically delete the mark from emaj_mark
DELETE FROM emaj.emaj_mark WHERE mark_group = v_groupName AND mark_name = v_markName;
-- adjust the mark_log_rows_before_next column of the previous mark
-- get the name of the mark immediately preceeding the mark to delete
SELECT mark_name, mark_time_id INTO v_previousMark, v_previousMarkTimeId FROM emaj.emaj_mark
WHERE mark_group = v_groupName AND mark_id < v_markId ORDER BY mark_id DESC LIMIT 1;
-- get the name of the first mark succeeding the mark to delete
SELECT mark_name, mark_time_id INTO v_nextMark, v_nextMarkTimeId FROM emaj.emaj_mark
WHERE mark_group = v_groupName AND mark_id > v_markId ORDER BY mark_id LIMIT 1;
IF NOT FOUND THEN
-- no next mark, so update the previous mark with NULL
UPDATE emaj.emaj_mark SET mark_log_rows_before_next = NULL
WHERE mark_group = v_groupName AND mark_name = v_previousMark;
ELSE
-- update the previous mark with the _sum_log_stat_group() call's result
UPDATE emaj.emaj_mark SET mark_log_rows_before_next = emaj._sum_log_stat_group(v_groupName, v_previousMarkTimeId, v_nextMarkTimeId)
WHERE mark_group = v_groupName AND mark_name = v_previousMark;
END IF;
-- reset the mark_logged_rlbk_target_mark column to null for other marks of the group
-- that may have the deleted mark as target mark from a previous logged rollback operation
UPDATE emaj.emaj_mark SET mark_logged_rlbk_target_mark = NULL
WHERE mark_group = v_groupName AND mark_logged_rlbk_target_mark = v_markName;
RETURN;
END;
$_delete_intermediate_mark_group$;

CREATE OR REPLACE FUNCTION emaj._rlbk_error(v_rlbkId INT, v_msg TEXT, v_cnxName TEXT)
RETURNS VOID LANGUAGE plpgsql AS
$_rlbk_error$
Expand Down
8 changes: 4 additions & 4 deletions sql/emaj--next_version.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3862,15 +3862,15 @@ $_delete_intermediate_mark_group$
v_nextMarkTimeId BIGINT;
BEGIN
-- delete the sequences related to the mark to delete
-- delete first data related to the application sequences currently belonging to the group
-- delete first data related to the application sequences (those attached to the group at the set mark time)
DELETE FROM emaj.emaj_sequence USING emaj.emaj_relation
WHERE sequ_time_id = v_markTimeId
AND upper_inf(rel_time_range) AND rel_group = v_groupName AND rel_kind = 'S'
AND rel_group = v_groupName AND rel_kind = 'S'
AND sequ_schema = rel_schema AND sequ_name = rel_tblseq;
-- delete then data related to the log sequences for tables currently belonging to the group
-- delete then data related to the log sequences for tables (those attached to the group at the set mark time)
DELETE FROM emaj.emaj_sequence USING emaj.emaj_relation
WHERE sequ_time_id = v_markTimeId
AND upper_inf(rel_time_range) AND rel_group = v_groupName AND rel_kind = 'r'
AND rel_group = v_groupName AND rel_kind = 'r'
AND sequ_schema = rel_log_schema AND sequ_name = rel_log_sequence;
-- physically delete the mark from emaj_mark
DELETE FROM emaj.emaj_mark WHERE mark_group = v_groupName AND mark_name = v_markName;
Expand Down
16 changes: 8 additions & 8 deletions test/10/expected/adm2.out
Original file line number Diff line number Diff line change
Expand Up @@ -1991,14 +1991,14 @@ select rlbk_id, rlbk_groups, rlbk_mark, rlbk_time_id, rlbk_is_logged, rlbk_is_al
22 | {myGroup1} | Conso_M2 | 3057 | t | | 1 | 5 | 2 | 3 | COMMITTED | 3447 | t | [ts] | {"Notice: 3 / 5 tables effectively processed.","Notice: 2 sequences processed."}
23 | {myGroup1} | Conso_M1 | 3059 | f | | 1 | 5 | 2 | 2 | COMMITTED | 3475 | t | [ts] | {"Notice: 2 / 5 tables effectively processed.","Notice: 2 sequences processed."}
24 | {myGroup4} | myGroup4_start | 3061 | f | | 1 | 5 | 0 | 0 | ABORTED | 3503 | t | [ts] | {"Notice: 0 / 5 tables effectively processed."}
6000 | {myGroup1} | Mk2b | 6059 | t | t | 1 | 5 | 1 | 0 | ABORTED | 6260 | t | [ts] | {"Notice: 0 / 5 tables effectively processed.","Notice: 1 sequences processed.","Warning: The sequence myschema1.\"myTbl3_col31_seq\" has been left unchanged (not in group anymore)"}
6001 | {myGroup1} | Mk2b | 6061 | f | t | 1 | 5 | 1 | 0 | ABORTED | 6274 | t | [ts] | {"Notice: 0 / 5 tables effectively processed.","Notice: 1 sequences processed."}
6004 | {myGroup1,myGroup2} | Mk3 | 6075 | f | f | 1 | 11 | 4 | 0 | COMMITTED | 6391 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6005 | {myGroup1,myGroup2} | Mk2 | 6076 | t | t | 1 | 11 | 4 | 1 | COMMITTED | 6403 | t | [ts] | {"Notice: 1 / 11 tables effectively processed.","Notice: 4 sequences processed.","Warning: Tables group change not rolled back: E-Maj priority for myschema1.mytbl1","Warning: Tables group change not rolled back: E-Maj log schema for myschema2.\"myTbl3\"","Warning: Tables group change not rolled back: E-Maj names prefix for myschema1.\"myTbl3\"","Warning: Tables group change not rolled back: log data tablespace for myschema1.mytbl2b","Warning: Tables group change not rolled back: log index tablespace for myschema2.mytbl6"}
6006 | {myGroup1,myGroup2} | Mk2 | 6078 | f | f | 1 | 11 | 4 | 1 | COMMITTED | 6427 | t | [ts] | {"Notice: 1 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6007 | {myGroup1,myGroup2} | Mk1 | 6079 | f | t | 1 | 11 | 4 | 0 | COMMITTED | 6452 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed.","Warning: Tables group change not rolled back: E-Maj priority for myschema1.mytbl1","Warning: Tables group change not rolled back: E-Maj log schema for myschema2.\"myTbl3\"","Warning: Tables group change not rolled back: E-Maj names prefix for myschema1.\"myTbl3\"","Warning: Tables group change not rolled back: log data tablespace for myschema1.mytbl2b","Warning: Tables group change not rolled back: log index tablespace for myschema2.mytbl6"}
6008 | {myGroup1,myGroup2} | Mk1 | 6080 | t | f | 1 | 11 | 4 | 0 | ABORTED | 6474 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6009 | {myGroup1,myGroup2} | Mk1 | 6082 | f | f | 1 | 11 | 4 | 0 | ABORTED | 6493 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6000 | {myGroup1} | Mk2b | 6060 | t | t | 1 | 5 | 1 | 0 | ABORTED | 6266 | t | [ts] | {"Notice: 0 / 5 tables effectively processed.","Notice: 1 sequences processed.","Warning: The sequence myschema1.\"myTbl3_col31_seq\" has been left unchanged (not in group anymore)"}
6001 | {myGroup1} | Mk2b | 6062 | f | t | 1 | 5 | 1 | 0 | ABORTED | 6280 | t | [ts] | {"Notice: 0 / 5 tables effectively processed.","Notice: 1 sequences processed."}
6004 | {myGroup1,myGroup2} | Mk3 | 6077 | f | f | 1 | 11 | 4 | 0 | COMMITTED | 6404 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6005 | {myGroup1,myGroup2} | Mk2 | 6078 | t | t | 1 | 11 | 4 | 1 | COMMITTED | 6416 | t | [ts] | {"Notice: 1 / 11 tables effectively processed.","Notice: 4 sequences processed.","Warning: Tables group change not rolled back: E-Maj priority for myschema1.mytbl1","Warning: Tables group change not rolled back: E-Maj log schema for myschema2.\"myTbl3\"","Warning: Tables group change not rolled back: E-Maj names prefix for myschema1.\"myTbl3\"","Warning: Tables group change not rolled back: log data tablespace for myschema1.mytbl2b","Warning: Tables group change not rolled back: log index tablespace for myschema2.mytbl6"}
6006 | {myGroup1,myGroup2} | Mk2 | 6080 | f | f | 1 | 11 | 4 | 1 | COMMITTED | 6440 | t | [ts] | {"Notice: 1 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6007 | {myGroup1,myGroup2} | Mk1 | 6081 | f | t | 1 | 11 | 4 | 0 | COMMITTED | 6465 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed.","Warning: Tables group change not rolled back: E-Maj priority for myschema1.mytbl1","Warning: Tables group change not rolled back: E-Maj log schema for myschema2.\"myTbl3\"","Warning: Tables group change not rolled back: E-Maj names prefix for myschema1.\"myTbl3\"","Warning: Tables group change not rolled back: log data tablespace for myschema1.mytbl2b","Warning: Tables group change not rolled back: log index tablespace for myschema2.mytbl6"}
6008 | {myGroup1,myGroup2} | Mk1 | 6082 | t | f | 1 | 11 | 4 | 0 | ABORTED | 6487 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed."}
6009 | {myGroup1,myGroup2} | Mk1 | 6084 | f | f | 1 | 11 | 4 | 0 | ABORTED | 6506 | t | [ts] | {"Notice: 0 / 11 tables effectively processed.","Notice: 4 sequences processed."}
10000 | {myGroup2} | M2 | 10009 | t | f | 1 | 6 | 2 | 3 | COMMITTED | 10057 | f | [ts] | {"Notice: 3 / 6 tables effectively processed.","Notice: 2 sequences processed."}
10001 | {myGroup2} | M3 | 10011 | t | f | 1 | 6 | 2 | 3 | COMMITTED | 10076 | f | [ts] | {"Notice: 3 / 6 tables effectively processed.","Notice: 2 sequences processed."}
10002 | {myGroup1} | M2 | 10013 | f | f | 1 | 5 | 2 | 2 | COMMITTED | 10095 | t | [ts] | {"Notice: 2 / 5 tables effectively processed.","Notice: 2 sequences processed."}
Expand Down

0 comments on commit 301821d

Please sign in to comment.