Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use external connection string for checking availablity #74

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions misc/misc_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def self.run_script_daemonized(resource_name, filename, task_name)
serv = LanternResource[name: resource_name].representative_server
serv.vm.sshable.cmd("common/bin/daemonizer 'sudo #{filename}' #{task_name}")

task_logs resource_name, "#{task_name}"
task_logs resource_name, task_name.to_s
end

def self.create_all_indexes_concurrently_script(resource_name, filename)
Expand All @@ -109,7 +109,7 @@ def self.create_all_indexes_concurrently_script(resource_name, filename)
if !indexes.empty?
queries = []
indexes.each {
queries.push(_1.gsub(/create\s+index/i, 'CREATE INDEX CONCURRENTLY')[1..-2])
queries.push(_1.gsub(/create\s+index/i, "CREATE INDEX CONCURRENTLY")[1..-2])
}

queries.map do |query|
Expand Down
10 changes: 5 additions & 5 deletions prog/lantern/lantern_server_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@ def destroy_domain
end

def available?
vm.sshable.invalidate_cache_entry

status = false
begin
lantern_server.run_query("SELECT 1")
return true
session = Sequel.connect(lantern_server.connection_string)
session["SELECT 1"].first
status = true
rescue
end

Expand All @@ -624,7 +624,7 @@ def available?
rescue
end

false
status
end

label def prewarm_indexes
Expand Down
38 changes: 15 additions & 23 deletions spec/prog/lantern/lantern_server_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,40 +748,32 @@
end
end

describe "#update_memory_limits" do
it "updates memory limits" do
expect(nx).to receive(:when_update_memory_limits_set?).and_yield
expect(lantern_server).to receive(:run_query)
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/update_memory_limits")
expect { nx.wait_db_available }.to hop("wait")
end
end

describe "#available" do
it "marks as available" do
expect(lantern_server).to receive(:run_query)
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server).to receive(:connection_string)
session = instance_double(Hash)
res = instance_double(Sequel::Dataset)
expect(res).to receive(:first)
expect(session).to receive(:[]).with("SELECT 1").and_return(res)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_return("logs")
expect(Sequel).to receive(:connect).and_return(session)
expect(nx.available?).to be(true)
end

it "does not mark as unavailable if redo in progress" do
expect(lantern_server).to receive(:run_query).and_raise "err"
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server).to receive(:connection_string)
session = instance_double(Hash)
expect(session).to receive(:[]).with("SELECT 1").and_raise "err"
expect(Sequel).to receive(:connect).and_return(session)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_return("redo in progress")
expect(nx.available?).to be(true)
end

it "marks unavailable if cmd fails" do
expect(lantern_server).to receive(:run_query).and_raise "err"
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_raise
expect(nx.available?).to be(false)
end

it "marks unavailable if cmd returns other logs" do
expect(lantern_server).to receive(:run_query).and_raise "err"
expect(lantern_server.vm.sshable).to receive(:invalidate_cache_entry)
expect(lantern_server).to receive(:connection_string)
session = instance_double(Hash)
expect(session).to receive(:[]).with("SELECT 1").and_raise "err"
expect(Sequel).to receive(:connect).and_return(session)
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo lantern/bin/logs --tail 5").and_return("logs")
expect(nx.available?).to be(false)
end
Expand Down