Skip to content

Duplicate resource type volumes created over time #2168

Closed

Description

@vito

Our test deployment always seems to run out of disk space eventually. I hopped on the VM and found this:

web/0b5af54a-50b5-4e9f-a888-7f0a1bbbe6b1:~$ fly -t tf vs -d | awk '{print $2, $3, $4}' | sort | uniq -c | sort -n | grep '^ *[0-9]\{2,\}'
    189 58b964cb-6ce5-4dfb-9f69-b1e122fbdea8 resource-type name:time,version:210cd426fc36d50bcd005c8ca56cfdc4af87e7d5
    362 58b964cb-6ce5-4dfb-9f69-b1e122fbdea8 resource-type name:docker-image,version:afd962224535c88f533e8afad0e99bcd26403261

So, for the same worker (first guid), we have 362 volumes for the same version of the docker-image resource type.

Here are two database entries for identical volumes:

atc=# select * from volumes where handle = 'fe1cc117-ca16-44aa-464b-f471558526c4';
-[ RECORD 1 ]----------------+-------------------------------------
id                           | 52271
handle                       | fe1cc117-ca16-44aa-464b-f471558526c4
resource_version             | 
resource_hash                | 
worker_name                  | 58b964cb-6ce5-4dfb-9f69-b1e122fbdea8
original_volume_handle       | 
output_name                  | 
path                         | 
host_path_version            | 
replicated_from              | 
container_id                 | 
team_id                      | 
state                        | created
parent_id                    | 
parent_state                 | 
worker_base_resource_type_id | 89
worker_resource_cache_id     | 
worker_task_cache_id         | 
worker_resource_certs_id     | 

atc=# select * from volumes where handle = 'fef50fda-68a7-4381-7427-b004cf7a8b2a';
-[ RECORD 1 ]----------------+-------------------------------------
id                           | 58883
handle                       | fef50fda-68a7-4381-7427-b004cf7a8b2a
resource_version             | 
resource_hash                | 
worker_name                  | 58b964cb-6ce5-4dfb-9f69-b1e122fbdea8
original_volume_handle       | 
output_name                  | 
path                         | 
host_path_version            | 
replicated_from              | 
container_id                 | 
team_id                      | 
state                        | created
parent_id                    | 
parent_state                 | 
worker_base_resource_type_id | 89
worker_resource_cache_id     | 
worker_task_cache_id         | 
worker_resource_certs_id     | 

atc=# 

These volumes are pretty global, and aren't even team-scoped, so it doesn't make sense to have more than one.

We should at least make this impossible by adding a UNIQUE constraint. Once we've done that, maybe we can figure out why so many are being created.

  • Concourse version: v3.11.0, likely earlier versions too
  • Deployment type (BOSH/Docker/binary): BOSH
  • Infrastructure/IaaS: GCP
  • Did this used to work? unclear

Activity

  1. kmacoskey commented on May 10, 2018

    @kmacoskey

    I can see the same issue on Concourse v3.9.2 and v3.12.0 for git, s3, and docker-image resource types. With larger deployments this amounts to many 1ks of volumes.

  2. xtremerui commented on May 11, 2018

    @xtremerui
    Contributor

    @vito Added partial unique constraint to concoursre_test

    CREATE UNIQUE INDEX worker_name_worker_base_resource_type_id ON volumes (worker_name, worker_base_resource_type_id) WHERE (team_id is null);
    

    Observed massive failure on job bosh-wats and bosh-watsjs while it tried to clean up test teams, it failed by violating above constraint. DB log:

    2018-05-11 20:40:58.611 GMT: CONTEXT:  SQL statement "UPDATE ONLY "public"."volumes" SET "team_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "team_id""
    2018-05-11 20:40:58.611 GMT: STATEMENT:  DELETE FROM teams WHERE name = $1
    2018-05-11 20:42:07.980 GMT: ERROR:  duplicate key value violates unique constraint "worker_name_worker_base_resource_type_id"
    2018-05-11 20:42:07.980 GMT: DETAIL:  Key (worker_name, worker_base_resource_type_id)=(92dbfceb-9907-44a3-a2b6-fd3e39dac108, 5) already exists.
    

    Check volumes table team_id column, noticed that the its volumes_team_id_fkey is set to Set Null when On delete. This explains why there were duplicate resource type volumes that is not scoped to any team. Since concourse-test is the only deployment that keep getting UI tests(and we don't delete the deployment afterwards), its disk keeps growing until explode.

    I believe this issue would be noticed by users who runs create/delete team frequently.

  3. xtremerui commented on May 14, 2018

    @xtremerui
    Contributor

    Couple solutions here:

    1. When deleting a team, it also deletes rows in volumes table where it belongs to that team and worker_base_resource_type_id is not null.
    2. Or it set worker_base_resource_type_id to null so it could be picked on option 4 below.
    3. Add addition condition when trying to find orphaned volume so it could consider the above duplicated volume as destroying. The current logic:
    	query, args, err := psql.Select(volumeColumns...).
    		From("volumes v").
    		LeftJoin("workers w ON v.worker_name = w.name").
    		LeftJoin("containers c ON v.container_id = c.id").
    		LeftJoin("volumes pv ON v.parent_id = pv.id").
    		LeftJoin("worker_resource_caches wrc ON wrc.id = v.worker_resource_cache_id").
    		Where(sq.Eq{
    			"v.worker_resource_cache_id":     nil,
    			"v.worker_base_resource_type_id": nil,
    			"v.container_id":                 nil,
    			"v.worker_task_cache_id":         nil,
    			"v.worker_resource_certs_id":     nil,
    		}).
    		Where(sq.Or{
    			sq.Eq{"v.state": string(VolumeStateCreated)},
    			sq.Eq{"v.state": string(VolumeStateDestroying)},
    		}).
    		Where(sq.Or{
    			sq.Eq{"w.state": string(WorkerStateRunning)},
    			sq.Eq{"w.state": string(WorkerStateLanding)},
    			sq.Eq{"w.state": string(WorkerStateRetiring)},
    		}).
    		ToSql()
    
  4. added a commit that references this issue on May 16, 2018
  5. jmelchio commented on May 16, 2018

    @jmelchio
    Contributor

    We ended up going with option 4 and updated the VolumeRepository query that finds the orphaned volumes to include the case where the team_id is nil and worker_base_resource_type_id is not nil.

  6. mikemimik commented on May 18, 2018

    @mikemimik

    What version of concourse will this target and land in?

  7. xtremerui commented on May 22, 2018

    @xtremerui
    Contributor

    @mikemimik should be in the next release

  8. added this to the v3.14.0 milestone on Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions