eclipse-tractusx / tutorial-resources

Apache License 2.0
10 stars 22 forks source link

Flyway problem after kubernetes restart #353

Closed oliverbusch closed 1 week ago

oliverbusch commented 3 weeks ago

Current Behavior

After restarting Kubernetes, the alice-tractusx-connector-controlplane cannot be started due to a flyway error.

2024-06-13 13:55:41] [INFO   ] Current version of schema "public": 0.0.2
[2024-06-13 13:55:41] [INFO   ] Migrating schema "public" to version "0.0.3 - Add StatefulEntity Columns"
[2024-06-13 13:55:41] [SEVERE ] Migration of schema "public" to version "0.0.3 - Add StatefulEntity Columns" failed! Changes successfully rolled back.
SEVERE 2024-06-13T13:55:41.344506517 Error booting runtime: Migration V0_0_3__Add_StatefulEntity_Columns.sql failed ------------------------------------------------------- SQL State  : 42701 Error Code : 0 Message    : ERROR: column "expiration_timestamp" of relation "edc_edr_cache" already exists Location   : org/eclipse/tractusx/edc/postgresql/migration/edr/V0_0_3__Add_StatefulEntity_Columns.sql (/app/file:/app/edc-controlplane.jar!/org/eclipse/tractusx/edc/postgresql/migration/edr/V0_0_3__Add_StatefulEntity_Columns.sql) Line       : 18 Statement  : -- --  Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) -- --  This program and the accompanying materials are made available under the --  terms of the Apache License, Version 2.0 which is available at --  https://www.apache.org/licenses/LICENSE-2.0 -- --  SPDX-License-Identifier: Apache-2.0 -- --  Contributors: --       Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation --  -- Statements are designed for and tested with Postgres only!   -- add column ALTER TABLE edc_edr_cache ADD COLUMN expiration_timestamp BIGINT
org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: Migration V0_0_3__Add_StatefulEntity_Columns.sql failed
-------------------------------------------------------
SQL State  : 42701
Error Code : 0
Message    : ERROR: column "expiration_timestamp" of relation "edc_edr_cache" already exists
Location   : org/eclipse/tractusx/edc/postgresql/migration/edr/V0_0_3__Add_StatefulEntity_Columns.sql (/app/file:/app/edc-controlplane.jar!/org/eclipse/tractusx/edc/postgresql/migration/edr/V0_0_3__Add_StatefulEntity_Columns.sql)
Line       : 18
Statement  : --
--  Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
--
--  This program and the accompanying materials are made available under the
--  terms of the Apache License, Version 2.0 which is available at
--  https://www.apache.org/licenses/LICENSE-2.0
--
--  SPDX-License-Identifier: Apache-2.0
--
--  Contributors:
--       Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
--

-- Statements are designed for and tested with Postgres only!

-- add column
ALTER TABLE edc_edr_cache ADD COLUMN expiration_timestamp BIGINT

        at org.flywaydb.core.internal.command.DbMigrate.doMigrateGroup(DbMigrate.java:382)
        at org.flywaydb.core.internal.command.DbMigrate.lambda$applyMigrations$1(DbMigrate.java:272)
        at org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:55)
        at org.flywaydb.core.internal.command.DbMigrate.applyMigrations(DbMigrate.java:271)
        at org.flywaydb.core.internal.command.DbMigrate.migrateGroup(DbMigrate.java:244)
        at org.flywaydb.core.internal.command.DbMigrate.lambda$migrateAll$0(DbMigrate.java:139)
        at org.flywaydb.core.internal.database.postgresql.PostgreSQLAdvisoryLockTemplate.execute(PostgreSQLAdvisoryLockTemplate.java:73)
        at org.flywaydb.core.internal.database.postgresql.PostgreSQLAdvisoryLockTemplate.lambda$execute$0(PostgreSQLAdvisoryLockTemplate.java:56)
        at org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:55)
        at org.flywaydb.core.internal.database.postgresql.PostgreSQLAdvisoryLockTemplate.execute(PostgreSQLAdvisoryLockTemplate.java:56)
        at org.flywaydb.core.internal.database.postgresql.PostgreSQLConnection.lock(PostgreSQLConnection.java:96)
        at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.lock(JdbcTableSchemaHistory.java:144)
        at org.flywaydb.core.internal.command.DbMigrate.migrateAll(DbMigrate.java:139)
        at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:97)
        at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:188)
        at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:213)
        at org.flywaydb.core.Flyway.migrate(Flyway.java:140)
        at org.eclipse.tractusx.edc.postgresql.migration.FlywayManager.migrate(FlywayManager.java:48)
        at org.eclipse.tractusx.edc.postgresql.migration.AbstractPostgresqlMigrationExtension.initialize(AbstractPostgresqlMigrationExtension.java:81)
        at org.eclipse.tractusx.edc.postgresql.migration.EdrPostgresqlMigrationExtension.initialize(EdrPostgresqlMigrationExtension.java:22)
        at org.eclipse.edc.boot.system.injection.lifecycle.InitializePhase.initialize(InitializePhase.java:37)
        at org.eclipse.edc.boot.system.injection.lifecycle.ExtensionLifecycleManager.initialize(ExtensionLifecycleManager.java:61)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
        at org.eclipse.edc.boot.system.ExtensionLoader.bootServiceExtensions(ExtensionLoader.java:67)
        at org.eclipse.edc.boot.system.runtime.BaseRuntime.bootExtensions(BaseRuntime.java:139)
        at org.eclipse.edc.boot.system.runtime.BaseRuntime.boot(BaseRuntime.java:200)
        at org.eclipse.edc.boot.system.runtime.BaseRuntime.boot(BaseRuntime.java:83)
        at org.eclipse.edc.boot.system.runtime.BaseRuntime.main(BaseRuntime.java:71)
Caused by: org.flywaydb.core.internal.sqlscript.FlywaySqlScriptException: Migration V0_0_3__Add_StatefulEntity_Columns.sql failed

Expected Behavior

After restarting Kubernetes, all containers should start without any problems.

Steps To Reproduce

Restart the kubernetes cluster Main Branch (pull date 05.06.24)

hemantxpatel commented 2 weeks ago

Hi @oliverbusch, Kubernetes cluster created by kind should not be restarted. If you somehow restart the cluster, it may not work as expected, and you need to re-create the cluster. Please see below references: kubernetes-sigs/kind#148 https://discuss.kubernetes.io/t/restart-a-kind-cluster/5413/4

oliverbusch commented 2 weeks ago

Hello @hemantxpatel, I use minikube for the kubernetes cluster. And from my point of view the error is not related to the restart. The error mesaage Message : ERROR: column "expiration_timestamp" of relation "edc_edr_cache" already exists The message indicates an error in the flyway setup.

hemantxpatel commented 2 weeks ago

Hi @oliverbusch , this issue is best suited for tractusx-edc. We don't configure anything related to flyway. DB Migration scripts are part of EDC internally and we don't have any control / configurations on it. I found a similar old issue related to EDR eclipse-tractusx/tractusx-edc#792

oliverbusch commented 1 week ago

Ok, I will monitor https://github.com/eclipse-tractusx/tractusx-edc/issues/792.