Skip to content
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

Issue 4092: Mark "FAILED" droplets/packages as expired #4093

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/cloud_controller/bits_expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(config=Config.config)

def expire_droplets!(app)
expirable_candidates = DropletModel.
where(state: DropletModel::STAGED_STATE, app_guid: app.guid).
where(state: [DropletModel::STAGED_STATE, DropletModel::FAILED_STATE], app_guid: app.guid).
exclude(guid: app.droplet_guid)

return if expirable_candidates.count < droplets_storage_count
Expand All @@ -28,7 +28,7 @@ def expire_packages!(app)
current_package_guid = app.droplet.try(:package_guid)

expirable_candidates = PackageModel.
where(state: PackageModel::READY_STATE, app_guid: app.guid).
where(state: [PackageModel::READY_STATE, PackageModel::FAILED_STATE], app_guid: app.guid).
exclude(guid: current_package_guid)

return if expirable_candidates.count < packages_storage_count
Expand All @@ -37,7 +37,7 @@ def expire_packages!(app)

packages_to_expire.each do |package|
package.update(state: PackageModel::EXPIRED_STATE)
enqueue_package_delete_job(package.guid)
enqueue_package_delete_job(package.guid) if package.package_hash
end
end

Expand Down
24 changes: 21 additions & 3 deletions spec/unit/lib/cloud_controller/bits_expiration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ module VCAP::CloudController
expect(BitsExpiration.new(changed_config).packages_storage_count).to eq(10)
end

context 'with an app with few droplets / packages' do
context 'with an app with few droplets / packages and one failed droplet / package' do
it 'does not mark any as expired' do
3.times { DropletModel.make(state: DropletModel::STAGED_STATE, app_guid: app.guid) }
3.times { PackageModel.make(state: PackageModel::READY_STATE, app_guid: app.guid) }
DropletModel.make(state: DropletModel::FAILED_STATE, app_guid: app.guid)
PackageModel.make(state: PackageModel::FAILED_STATE, app_guid: app.guid)
BitsExpiration.new.expire_droplets!(app)
BitsExpiration.new.expire_packages!(app)
expect(DropletModel.where(state: DropletModel::EXPIRED_STATE).count).to eq(0)
Expand Down Expand Up @@ -77,10 +79,19 @@ module VCAP::CloudController
)
app.update(droplet: @current)

10.times do |i|
2.times do |i|
DropletModel.make(
app_guid: app.guid,
created_at: t + i,
droplet_hash: nil,
state: DropletModel::FAILED_STATE
)
end

10.times do |i|
DropletModel.make(
app_guid: app.guid,
created_at: t + i + 2,
droplet_hash: 'current_droplet_hash'
)
end
Expand Down Expand Up @@ -133,11 +144,18 @@ module VCAP::CloudController
)
app.update(droplet: @current)

2.times do |i|
PackageModel.make(package_hash: nil,
state: PackageModel::FAILED_STATE,
app_guid: app.guid,
created_at: t + i)
end

10.times do |i|
PackageModel.make(package_hash: 'real hash!',
state: PackageModel::READY_STATE,
app_guid: app.guid,
created_at: t + i)
created_at: t + i + 2)
end
end

Expand Down