Repository navigation
Closed
Labels
Milestone
Description
Bug Report
- Concourse version: 3.9.1
- Deployment type (BOSH/Docker/binary): binary
This appears to be a regression of #722. As a refresher, my Chef deployment of Concourse is also a torture test of initial migration safety, because it runs 'concourse web', and then pretty rapidly restarts that process. I'm seeing this in my 'integration tests' on fresh systems with a fresh db. On the Concourse side, I get
failed to migrate database: Dirty database version 1510262030. Fix and force version.
With verbose postgres logs, the problem seems like a straightforward repeat of #722- there are two separate transactions, one to update the schema_migrations table, one to apply the schema migrations, and if the second transaction is interrupted, the database is in an indeterminate state.
LOG: execute <unnamed>: SELECT pg_try_advisory_lock($1)
DETAIL: parameters: $1 = '6'
LOG: statement: SELECT version FROM migration_version
ERROR: relation "migration_version" does not exist at character 21
STATEMENT: SELECT version FROM migration_version
LOG: statement: SELECT CURRENT_DATABASE()
LOG: execute <unnamed>: SELECT COUNT(1) FROM information_schema.tables WHERE table_name = $1 AND table_schema = (SELECT current_schema()) LIMIT 1
DETAIL: parameters: $1 = 'schema_migrations'
LOG: statement: CREATE TABLE "schema_migrations" (version bigint not null primary key, dirty boolean not null)
LOG: execute <unnamed>: SELECT pg_try_advisory_lock($1)
DETAIL: parameters: $1 = '2019668375'
LOG: statement: SELECT version, dirty FROM "schema_migrations" LIMIT 1
LOG: statement: BEGIN
LOG: statement: TRUNCATE "schema_migrations"
LOG: execute <unnamed>: INSERT INTO "schema_migrations" (version, dirty) VALUES ($1, $2)
DETAIL: parameters: $1 = '1510262030', $2 = 't'
LOG: statement: COMMIT
LOG: statement: BEGIN;
CREATE TYPE build_status AS ENUM (
'pending',
'started',
'aborted',
... (omit the concourse schema)
ALTER TABLE ONLY workers
ADD CONSTRAINT workers_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE;
COMMIT;
LOG: could not receive data from client: Connection reset by peer
LOG: could not receive data from client: Connection reset by peer
LOG: execute <unnamed>: SELECT pg_try_advisory_lock($1)
DETAIL: parameters: $1 = '6'
LOG: statement: SELECT version FROM migration_version
ERROR: relation "migration_version" does not exist at character 21
STATEMENT: SELECT version FROM migration_version
LOG: statement: SELECT CURRENT_DATABASE()
LOG: execute <unnamed>: SELECT COUNT(1) FROM information_schema.tables WHERE table_name = $1 AND table_schema = (SELECT current_schema()) LIMIT 1
DETAIL: parameters: $1 = 'schema_migrations'
LOG: execute <unnamed>: SELECT pg_try_advisory_lock($1)
DETAIL: parameters: $1 = '2019668375'
LOG: statement: SELECT version, dirty FROM "schema_migrations" LIMIT 1
LOG: execute <unnamed>: SELECT pg_advisory_unlock($1)
DETAIL: parameters: $1 = '2019668375'
LOG: execute <unnamed>: SELECT pg_advisory_unlock($1)
DETAIL: parameters: $1 = '6'
LOG: could not receive data from client: Connection reset by peer
Reacted by Phillip Baker, Andrew Edgar and Rune Engseth
Activity
topherbullock commentedon Mar 22, 2018
@hfinucane This issue is related to the migration library we're using, and the inability to safely recover from a state where the migrations it is trying to run for us never succeeded. As you observed, there's 3 steps it uses to run each migration. Here's the flow it follows for running migrations:
schema_migrationsversionto<desired-version>anddirtytotrue<desired-version>schema_migrationsversionto<desired-version>anddirtytofalseupmigration to runOur initial thought was "Let's just change it to run 1-3 in a transaction", but there are reasons for not wanting every migration to run in a transaction. Since we don't really know whether step 2 (running the migration) or 3 (marking the migration table as clean) failed, the ATC isn't really able to determine what to do about the state being dirty.
One thing which may help you is the ability to upgrade the db to a desired version once, and exit.
concourse websupports a--migrate-db-to-versionflag which does just that. You could potentially use that in conjunction with--supported-db-versionlike so :concourse web --migrate-db-to-version $(concourse web --supported-db-version)If you run this once before the aggressive stopping and starting of the
concourse webservice (maybe in the db setup after the initial db is created?), then it will be more resilient to restarts going forward.nbrys commentedon May 7, 2018
We are currently having the same issue after trying an upgrade from 3.9.2 to 3.13.0. We get the following errors in the log: failed to migrate database: Dirty database version 1522178770. Fix and force version.
Any help to get our concourse installation working again is appreciated.
ywei2017 commentedon May 15, 2018
Any updates on the 3.9.2 to 3.13.0 upgrade? I just got into the exact same error, and am totally at a loss.
DRuggeri commentedon May 15, 2018
Same. It sounds like @vito is suggesting that this needs to be fixed in the schema somehow? The error
Fix and force versiondoesn't quite tell me, as an administrator, what needs to be done.DRuggeri commentedon May 15, 2018
FWIW, I was able to work past the issue by...
psqland concourse credentials to log into the DBUPDATE schema_migrations SET dirty=falseYMMV, but that's how I recovered from this half state.
bump etree tsa handlers mux clockwork goxmldsig genproto grpc
ddadlani commentedon Aug 20, 2018
We have moved to a new migration library (#2452) which should provide more information when migrations fail, so we are closing this issue.
If anyone runs into issues with migrations in the future (from Concourse v4.0.1 onward), please look at the
migrations_historytable for more information on what failed. Please also feel free to open a new issue to discuss the migration failure. Thanks!vito commentedon Aug 21, 2018
Accepting this! I opened a separate issue for extracting it to a separate library (repo) and some odds and ends: #2516