Skip to content

Commit b9a3586

Browse files
committed
Revert "Reload process to use DB-assigned updated_at timestamps (#4935)"
This reverts commit 5d45b2a.
1 parent c424b98 commit b9a3586

File tree

9 files changed

+16
-111
lines changed

9 files changed

+16
-111
lines changed

app/actions/app_update.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,12 @@ def update(app, message, lifecycle)
4444
)
4545

4646
# update process timestamp to trigger convergence if sending fails
47-
if updating_metric_tags?(message)
48-
app.processes.each do |process|
49-
process.skip_process_observer_on_update = true
50-
process.save
51-
end
52-
end
47+
app.processes.each(&:save) if updating_metric_tags?(message)
5348
end
5449

5550
if updating_metric_tags?(message)
5651
app.processes.each do |process|
57-
# Reload to get the DB-assigned updated_at, which ProcessesSync compares against
58-
# the LRP annotation to detect drift. Without this, the stale in-memory value
59-
# causes an unnecessary re-sync.
60-
@runners.runner_for_process(process.reload).update_metric_tags if process.state == ProcessModel::STARTED
52+
@runners.runner_for_process(process).update_metric_tags if process.state == ProcessModel::STARTED
6153
rescue Diego::Runner::CannotCommunicateWithDiegoError => e
6254
@logger.error("failed communicating with diego backend: #{e.message}")
6355
end

app/actions/process_restart.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ def restart(process:, config:, stop_in_runtime:, revision: nil)
99
process.lock!
1010
process.skip_process_observer_on_update = true
1111

12+
# A side-effect of submitting LRP requests before the transaction commits is that
13+
# the annotation timestamp stored on the LRP is slightly different than the process.updated_at
14+
# timestamp that is stored in the DB due to timestamp precision differences.
15+
# This difference causes the sync job to submit an extra update LRP request which updates
16+
# the LRP annotation at a later time. This should have no impact on the running LRP.
1217
if need_to_stop_in_runtime
1318
process.update(state: ProcessModel::STOPPED)
1419
runners(config).runner_for_process(process).stop

lib/cloud_controller/process_observer.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ def react_to_state_change(process)
3737

3838
process.update(revision: process.app.latest_revision) if process.revisions_enabled?
3939

40-
# Reload to get the DB-assigned updated_at, which ProcessesSync compares against
41-
# the LRP annotation to detect drift. Without this, the stale in-memory value
42-
# causes an unnecessary re-sync.
43-
@runners.runner_for_process(process.reload).start unless process.needs_staging?
40+
@runners.runner_for_process(process).start unless process.needs_staging?
4441
end
4542

4643
def react_to_instances_change(process)
47-
# Same as above: reload to get the DB-assigned updated_at before building the LRP annotation.
48-
@runners.runner_for_process(process.reload).scale if process.started? && process.active?
44+
@runners.runner_for_process(process).scale if process.started? && process.active?
4945
end
5046

5147
def with_diego_communication_handling

lib/cloud_controller/process_route_handler.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ def update_route_information(perform_validation: true, updated_ports: false)
2828
end
2929

3030
def notify_backend_of_route_update
31-
# Reload to get the DB-assigned updated_at, which ProcessesSync compares against
32-
# the LRP annotation to detect drift. Without this, the stale in-memory value
33-
# causes an unnecessary re-sync.
34-
@runners.runner_for_process(@process.reload).update_routes if @process && @process.staged? && @process.started?
31+
@runners.runner_for_process(@process).update_routes if @process && @process.staged? && @process.started?
3532
rescue Diego::Runner::CannotCommunicateWithDiegoError => e
3633
logger.error("failed communicating with diego backend: #{e.message}")
3734
end

spec/unit/actions/app_update_spec.rb

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,6 @@ module VCAP::CloudController
103103
expect(runner).to have_received(:update_metric_tags).twice
104104
end
105105

106-
it 'does not trigger ProcessObserver when saving processes', isolation: :truncation do
107-
expect(ProcessObserver).not_to receive(:updated)
108-
app_update.update(app_model, message, lifecycle)
109-
end
110-
111-
it 'passes a process with the correct updated_at timestamp to the runner', isolation: :truncation do
112-
received = {}
113-
allow(runners).to receive(:runner_for_process) do |p|
114-
received[p.guid] = p.updated_at
115-
runner
116-
end
117-
118-
app_update.update(app_model, message, lifecycle)
119-
120-
expect(runners).to have_received(:runner_for_process).twice
121-
expect(received[web_process.guid]).to eq(web_process.reload.updated_at)
122-
expect(received[worker_process.guid]).to eq(worker_process.reload.updated_at)
123-
end
124-
125106
context 'when there is a CannotCommunicateWithDiegoError' do
126107
before do
127108
allow(runner).to receive(:update_metric_tags).and_invoke(
@@ -149,12 +130,10 @@ module VCAP::CloudController
149130
let!(:worker_process) { instance_double(VCAP::CloudController::ProcessModel) }
150131

151132
before do
152-
allow(web_process).to receive(:skip_process_observer_on_update=)
153133
allow(web_process).to receive(:save)
154-
allow(web_process).to receive_messages(reload: web_process, state: ProcessModel::STARTED)
155-
allow(worker_process).to receive(:skip_process_observer_on_update=)
134+
allow(web_process).to receive(:state).and_return(ProcessModel::STARTED)
156135
allow(worker_process).to receive(:save)
157-
allow(worker_process).to receive_messages(reload: worker_process, state: ProcessModel::STARTED)
136+
allow(worker_process).to receive(:state).and_return(ProcessModel::STARTED)
158137
allow(app_model).to receive(:processes).and_return([web_process, worker_process])
159138
end
160139

@@ -201,12 +180,10 @@ module VCAP::CloudController
201180
let!(:worker_process) { instance_double(VCAP::CloudController::ProcessModel) }
202181

203182
before do
204-
allow(web_process).to receive(:skip_process_observer_on_update=)
205183
allow(web_process).to receive(:save)
206-
allow(web_process).to receive_messages(reload: web_process, state: ProcessModel::STARTED)
207-
allow(worker_process).to receive(:skip_process_observer_on_update=)
184+
allow(web_process).to receive(:state).and_return(ProcessModel::STARTED)
208185
allow(worker_process).to receive(:save)
209-
allow(worker_process).to receive_messages(reload: worker_process, state: ProcessModel::STARTED)
186+
allow(worker_process).to receive(:state).and_return(ProcessModel::STARTED)
210187
allow(app_model).to receive(:processes).and_return([web_process, worker_process])
211188
end
212189

spec/unit/actions/process_restart_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@ module VCAP::CloudController
3636
ProcessRestart.restart(process: process, config: config, stop_in_runtime: true)
3737
end
3838

39-
it 'passes a process with the correct updated_at timestamp to the runner', isolation: :truncation do
40-
received = nil
41-
allow(VCAP::CloudController::Diego::Runner).to receive(:new) do |p, _config|
42-
received = p.updated_at
43-
runner
44-
end
45-
46-
ProcessRestart.restart(process: process, config: config, stop_in_runtime: false)
47-
48-
expect(VCAP::CloudController::Diego::Runner).to have_received(:new).once
49-
expect(received).to eq(process.reload.updated_at)
50-
end
51-
5239
context 'when the process is STARTED' do
5340
it 'keeps process state as STARTED' do
5441
ProcessRestart.restart(process: process, config: config, stop_in_runtime: true)

spec/unit/lib/cloud_controller/process_observer_spec.rb

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module VCAP::CloudController
55
let(:stagers) { double(:stagers, stager_for_build: stager) }
66
let(:runners) { instance_double(Runners, runner_for_process: runner) }
77
let(:stager) { double(:stager) }
8-
let(:runner) { instance_double(Diego::Runner, stop: nil, start: nil, scale: nil) }
8+
let(:runner) { instance_double(Diego::Runner, stop: nil, start: nil) }
99
let(:process_active) { true }
1010
let(:diego) { false }
1111
let(:process) do
@@ -33,7 +33,6 @@ module VCAP::CloudController
3333

3434
before do
3535
ProcessObserver.configure(stagers, runners)
36-
allow(process).to receive(:reload).and_return(process)
3736
end
3837

3938
describe '.deleted' do
@@ -313,37 +312,6 @@ module VCAP::CloudController
313312
end
314313
end
315314
end
316-
317-
context 'updated_at annotation accuracy' do
318-
let(:received) { [] }
319-
320-
before do
321-
allow(runners).to receive(:runner_for_process) do |p|
322-
received << p.updated_at
323-
runner
324-
end
325-
end
326-
327-
context 'when the process instances have changed' do
328-
it 'passes a process with the correct updated_at timestamp to the runner', isolation: :truncation do
329-
process_model = ProcessModelFactory.make(state: 'STARTED')
330-
process_model.update(instances: process_model.instances + 1)
331-
332-
expect(runners).to have_received(:runner_for_process).once
333-
expect(received.last).to eq(process_model.reload.updated_at)
334-
end
335-
end
336-
337-
context 'when the process state has changed' do
338-
it 'passes a process with the correct updated_at timestamp to the runner', isolation: :truncation do
339-
process_model = ProcessModelFactory.make(state: 'STOPPED')
340-
process_model.update(state: ProcessModel::STARTED)
341-
342-
expect(runners).to have_received(:runner_for_process).once
343-
expect(received.last).to eq(process_model.reload.updated_at)
344-
end
345-
end
346-
end
347315
end
348316
end
349317
end

spec/unit/lib/cloud_controller/process_route_handler_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,5 @@ module VCAP::CloudController
196196
end
197197
end
198198
end
199-
200-
describe 'updated_at annotation accuracy' do
201-
let(:process) { ProcessModelFactory.make(state: 'STARTED') }
202-
203-
it 'passes a process with the correct updated_at timestamp to the runner', isolation: :truncation do
204-
received = nil
205-
allow(runners).to receive(:runner_for_process) do |p|
206-
received = p.updated_at
207-
runner
208-
end
209-
210-
handler.update_route_information
211-
212-
expect(runners).to have_received(:runner_for_process).once
213-
expect(received).to eq(process.reload.updated_at)
214-
end
215-
end
216199
end
217200
end

spec/unit/models/runtime/process_model_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ def act_as_cf_admin
14951495
end
14961496

14971497
describe 'saving' do
1498-
it 'calls ProcessObserver.updated', isolation: :truncation do
1498+
it 'calls AppObserver.updated', isolation: :truncation do
14991499
process = ProcessModelFactory.make
15001500
expect(ProcessObserver).to receive(:updated).with(process)
15011501
process.update(instances: process.instances + 1)

0 commit comments

Comments
 (0)