-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retry in sync_dns_scheduler if migration not finished
We have to ensure that the migration has finshed succesfully in the sync_dns_scheduler, before we can load the db Models. Otherwise the sync-dns job gets into an inconsistent state since the db is still being migrated or DB being upgraded. [#164325756](https://www.pivotaltracker.com/story/show/164325756) Co-authored-by: Sebastian Heid <[email protected]> Co-authored-by: Vladimir Videlov <[email protected]> Co-authored-by: Denis Langer <[email protected]>
- Loading branch information
1 parent
78fee5f
commit 1f9ca8b
Showing
8 changed files
with
165 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
require 'db_migrator' | ||
|
||
module Bosh::Director | ||
describe 'DBMigrator' do | ||
subject(:migrator) { DBMigrator.new('db', 'test', {}, 0.01) } | ||
|
||
describe '#finished?' do | ||
it 'returns true if migration is already current' do | ||
allow(migrator).to receive(:current?).once.and_return(true) | ||
expect(migrator.finished?).to be(true) | ||
end | ||
|
||
it 'return true if migration is current after retrying' do | ||
allow(migrator).to receive(:current?).twice.and_return(false, true) | ||
expect(migrator.finished?).to be(true) | ||
end | ||
|
||
it 'returns false if migrations are never current' do | ||
allow(migrator).to receive(:current?).exactly(DBMigrator::MAX_MIGRATION_ATTEMPTS).times.and_return(false) | ||
expect(migrator.finished?).to be(false) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'spec_helper' | ||
require 'db_migrator' | ||
require_relative '../../lib/bosh/director/sync_dns_scheduler' | ||
|
||
Models = Bosh::Director::Models | ||
module Kernel | ||
alias original_require require | ||
def require(path) | ||
Bosh::Director.const_set(:Models, Models) if path == 'bosh/director' && !defined?(Bosh::Director::Models) | ||
original_require(path) | ||
end | ||
end | ||
|
||
module Bosh::Director | ||
describe 'sync_dns_scheduler' do | ||
subject(:sync_dns_scheduler) { SyncDnsScheduler.new(config, 0.01) } | ||
let(:config_hash) do | ||
SpecHelper.spec_get_director_config | ||
end | ||
|
||
let(:config) { Config.load_hash(config_hash) } | ||
let(:dns_version_converger) { double(DnsVersionConverger) } | ||
|
||
before do | ||
Bosh::Director.send(:remove_const, :Models) | ||
end | ||
|
||
after do | ||
require 'bosh/director' | ||
end | ||
|
||
describe 'migrations' do | ||
let(:migrator) { instance_double(DBMigrator, current?: true) } | ||
before do | ||
allow(config).to receive(:db).and_return(double(:config_db)) | ||
allow(DBMigrator).to receive(:new).with(config.db, :director).and_return(migrator) | ||
end | ||
|
||
it 'starts up immediately if migrations have finished' do | ||
allow(migrator).to receive(:finished?).and_return(true) | ||
expect(sync_dns_scheduler).to receive(:ensure_migrations) | ||
expect { sync_dns_scheduler.prep }.not_to raise_error | ||
end | ||
|
||
it 'raises error if migrations never finish' do | ||
logger = double(Logging::Logger) | ||
allow(config).to receive(:sync_dns_scheduler_logger).and_return(logger.tap { |l| allow(l).to receive(:error) }) | ||
allow(migrator).to receive(:finished?).and_return(false) | ||
|
||
expect(logger).to receive(:error).with( | ||
/Migrations not current during sync dns scheduler start after #{DBMigrator::MAX_MIGRATION_ATTEMPTS} attempts./, | ||
) | ||
expect do | ||
sync_dns_scheduler.prep | ||
end .to raise_error( | ||
/Migrations not current during sync dns scheduler start after #{DBMigrator::MAX_MIGRATION_ATTEMPTS} retries/, | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters