関数特性
言語: PLPGSQL
戻り値: integer
sl_confirm、 sl_event から古いデータを掃除。(オリジンノード、レシーバノード)毎の最新の sl_confirm 行を別として全てを削除し、最後の SYNC までの全てのクラスタ全般の全てのノードにより確認された全ての事象を削除します。declare v_max_row record; v_min_row record; v_max_sync int8; begin -- ---- -- 最初に、オリジンノードとレシーバノードの組み合せ毎の最も古く確認されたものを除いて全てを削除 -- ---- delete from sl_confirm where con_origin not in (select no_id from sl_node); delete from sl_confirm where con_received not in (select no_id from sl_node); -- ---- -- 次にオリジンノードとレシーバノードの組み合せ毎の最も古く確認されたものを除いて全てを削除 -- 10 分以内にあった確認を無視。私たちは、サーバのクラッシュが -- 他のセッションから可視である事による、もしかして失われた -- トランザクションへの現在確認されていない疑いを抱いています。 -- ---- for v_max_row in select con_origin, con_received, max(con_seqno) as con_seqno from sl_confirm where con_timestamp < (CURRENT_TIMESTAMP - '10 min'::interval) group by con_origin, con_received loop delete from sl_confirm where con_origin = v_max_row.con_origin and con_received = v_max_row.con_received and con_seqno < v_max_row.con_seqno; end loop; -- ---- -- 最後の SYNC までの全てのクラスタ全般の -- 全てのノードにより確認された全ての事象を削除 -- ---- for v_min_row in select con_origin, min(con_seqno) as con_seqno from sl_confirm group by con_origin loop select coalesce(max(ev_seqno), 0) into v_max_sync from sl_event where ev_origin = v_min_row.con_origin and ev_seqno <= v_min_row.con_seqno and ev_type = 'SYNC'; if v_max_sync > 0 then delete from sl_event where ev_origin = v_min_row.con_origin and ev_seqno < v_max_sync; end if; end loop; return 0; end;