-
Notifications
You must be signed in to change notification settings - Fork 368
Fix broker stuck in SYNCHRONIZING on DB error during rollback #4995
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,14 @@ def display_name | |
| 'service_broker.catalog.synchronize' | ||
| end | ||
|
|
||
| def recover_from_failure | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this tested in a unit test? |
||
| ServiceBroker.where(guid: broker_guid, state: ServiceBrokerStateEnum::SYNCHRONIZING). | ||
| update(state: ServiceBrokerStateEnum::SYNCHRONIZATION_FAILED) | ||
| rescue StandardError => e | ||
| logger = Steno.logger('cc.background') | ||
| logger.error("Failed to recover broker state for #{broker_guid}: #{e.class}: #{e.message}") | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :broker_guid, :user_audit_info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,6 +201,55 @@ class BigException < StandardError | |
| execute_all_jobs(expected_successes: 0, expected_failures: 1) | ||
| end | ||
| end | ||
|
|
||
| context 'when the job implements recover_from_failure' do | ||
| let(:broker) do | ||
| VCAP::CloudController::ServiceBroker.create( | ||
| name: 'recovery-test-broker', | ||
| broker_url: 'http://example.org/broker-url', | ||
| auth_username: 'username', | ||
| auth_password: 'password', | ||
| state: VCAP::CloudController::ServiceBrokerStateEnum::SYNCHRONIZING | ||
| ) | ||
| end | ||
|
|
||
| let(:update_request) do | ||
| VCAP::CloudController::ServiceBrokerUpdateRequest.create( | ||
| name: 'new-name', | ||
| service_broker_id: broker.id | ||
| ) | ||
| end | ||
|
|
||
| let(:user_audit_info) { instance_double(VCAP::CloudController::UserAuditInfo, { user_guid: Sham.guid }) } | ||
| let(:update_job) { VCAP::CloudController::V3::UpdateBrokerJob.new(update_request.guid, broker.guid, 'AVAILABLE', user_audit_info:) } | ||
| let(:pollable_job) { PollableJobWrapper.new(update_job) } | ||
|
|
||
| before do | ||
| allow_any_instance_of(VCAP::CloudController::V3::UpdateBrokerJob::Perform).to receive(:perform).and_raise(StandardError.new('job failed')) | ||
| end | ||
|
|
||
| it 'calls recover_from_failure and reverts broker state to AVAILABLE' do | ||
| enqueued_job = VCAP::CloudController::Jobs::Enqueuer.new.enqueue(pollable_job) | ||
| VCAP::CloudController::PollableJobModel.make(delayed_job_guid: enqueued_job.guid, state: 'PROCESSING') | ||
|
|
||
| execute_all_jobs(expected_successes: 0, expected_failures: 1) | ||
|
|
||
| broker.reload | ||
| expect(broker.state).to eq('SYNCHRONIZATION_FAILED') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This basically repeats the test of
|
||
| end | ||
| end | ||
|
|
||
| context 'when the job does not implement recover_from_failure' do | ||
| it 'still marks the job as FAILED without error' do | ||
| enqueued_job = VCAP::CloudController::Jobs::Enqueuer.new.enqueue(pollable_job) | ||
| job_model = VCAP::CloudController::PollableJobModel.make(delayed_job_guid: enqueued_job.guid, state: 'PROCESSING') | ||
|
|
||
| execute_all_jobs(expected_successes: 0, expected_failures: 1) | ||
|
|
||
| job_model.reload | ||
| expect(job_model.state).to eq('FAILED') | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be simplified to
@handler.recover_from_failure(haven't tried it out)