Skip to content

Commit

Permalink
Merge pull request #19254 from yrudman/do-not-calculate-backlog-when-…
Browse files Browse the repository at this point in the history
…subscription-not-active

[HAMMER]Do not calculate backlog when subscription not active
  • Loading branch information
simaishi committed Sep 5, 2019
2 parents 103f880 + 52b42a0 commit 879889a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/models/pglogical_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ def validate(new_connection_params = {})
end

def backlog
connection.xlog_location_diff(remote_node_lsn, remote_replication_lsn)
rescue PG::Error => e
_log.error(e.message)
nil
if status != "replicating"
_log.error("Is `#{dbname}` running on host `#{host}` and accepting TCP/IP connections on port #{port} ?")
return nil
end
begin
connection.xlog_location_diff(remote_node_lsn, remote_replication_lsn)
rescue PG::Error => e
_log.error(e.message)
nil
end
end

# translate the output from the pglogical stored proc to our object columns
Expand Down
7 changes: 7 additions & 0 deletions spec/models/pglogical_subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,5 +496,12 @@

expect(described_class.first.backlog).to be nil
end

it 'does not attempt to calculate backlog and returns nil unless subscription status is "replicating"' do
allow(described_class).to receive(:status).and_return("down")

expect(remote_connection).not_to receive(:xlog_location)
expect(described_class.first.backlog).to be nil
end
end
end

0 comments on commit 879889a

Please sign in to comment.