Skip to content

Commit

Permalink
Merge pull request #2533 from cloudfoundry/pr_remove_tombstone_local_…
Browse files Browse the repository at this point in the history
…dns_records

When adding a new tombstone record, delete all the older ones
  • Loading branch information
jpalermo authored Jun 29, 2024
2 parents 4eb163b + 5113f0d commit 6410f73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class LocalDnsRecord < Sequel::Model(Bosh::Director::Config.db)
many_to_one :instance

def self.insert_tombstone
create(:ip => "#{SecureRandom.uuid}-tombstone")
tombstone_record = create(:ip => "#{SecureRandom.uuid}-tombstone")
where{id < tombstone_record.id}.where(Sequel.like(:ip, '%-tombstone')).delete
tombstone_record
end

def links=(value)
Expand Down
7 changes: 7 additions & 0 deletions src/bosh-director/spec/unit/models/local_dns_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ module Bosh::Director::Models

expect(Bosh::Director::Models::LocalDnsRecord.first.instance).to be_nil
end

it 'removes old tombstone records' do
previous_record = Bosh::Director::Models::LocalDnsRecord.insert_tombstone
new_record = Bosh::Director::Models::LocalDnsRecord.insert_tombstone
expect(Bosh::Director::Models::LocalDnsRecord.where(id: previous_record.id).first).to be_nil
expect(Bosh::Director::Models::LocalDnsRecord.where(id: new_record.id).first).not_to be_nil
end
end
end

0 comments on commit 6410f73

Please sign in to comment.