Skip to content

Commit

Permalink
remove ddl_log table after switchover is done
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Nov 14, 2024
1 parent 3bdcdd6 commit e486877
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def create_ddl_log
INSERT INTO ddl_log (object_tag, ddl_command, timestamp)
VALUES (tg_tag, current_query(), current_timestamp);
END;
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql
SECURITY DEFINER;
DROP EVENT TRIGGER IF EXISTS log_ddl_trigger;
CREATE EVENT TRIGGER log_ddl_trigger
Expand Down Expand Up @@ -170,6 +171,15 @@ def listen_ddl_log
representative_server.run_query_all(commands)
end

def drop_ddl_log
commands = <<SQL
DROP EVENT TRIGGER IF EXISTS log_ddl_trigger;
DROP TABLE IF EXISTS ddl_log;
DROP FUNCTION IF EXISTS execute_ddl_command();
SQL
representative_server.run_query_all(commands)
end

def create_publication(name)
representative_server.run_query_all("CREATE PUBLICATION #{name} FOR ALL TABLES")
end
Expand Down
3 changes: 3 additions & 0 deletions prog/lantern/lantern_resource_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def before_run
lantern_resource.update(parent_id: nil)
lantern_resource.timeline.update(parent_id: nil)

# remove ddl_log
lantern_resource.drop_ddl_log

hop_wait
end

Expand Down
2 changes: 1 addition & 1 deletion rhizome/lantern/bin/run_pg_upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data["services"]["postgresql"]["deploy"].delete("restart_policy")
File.open($compose_file, "w") { |f| YAML.dump(data, f) }

puts "Starting pg_upgrade..."
puts r "sudo docker compose -f #{$compose_file} up"
r "sudo docker compose -f #{$compose_file} run --rm postgresql"
puts "pg_upgrade successfull."

puts "Starting new cluster..."
Expand Down
9 changes: 9 additions & 0 deletions spec/model/lantern/lantern_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@
end
end

describe "#drop_ddl_log" do
it "drops ddl log table and triggers" do
representative_server = instance_double(LanternServer)
expect(lantern_resource).to receive(:representative_server).and_return(representative_server).at_least(:once)
expect(representative_server).to receive(:run_query_all).with(a_string_matching(/DROP .* ddl_log/m))
expect { lantern_resource.drop_ddl_log }.not_to raise_error
end
end

describe "#rollback_switchover" do
it "performs a rollback switchover successfully" do
current_representative_server = instance_double(LanternServer, domain: "example.com", vm: instance_double(GcpVm, sshable: instance_double(Sshable, host: "127.0.0.1")))
Expand Down
1 change: 1 addition & 0 deletions spec/prog/lantern/lantern_resource_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@

expect(lantern_resource).to receive(:update).with(parent_id: nil)
expect(lantern_resource).to receive(:timeline).and_return(timeline)
expect(lantern_resource).to receive(:drop_ddl_log)
expect(timeline).to receive(:update).with(parent_id: nil)

expect { nx.finish_take_over }.to hop("wait")
Expand Down

0 comments on commit e486877

Please sign in to comment.