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

Installation of EDC 0.5.1 fails because of DB migration script error #792

Closed
DrDanielMetz opened this issue Sep 25, 2023 · 17 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@DrDanielMetz
Copy link

DrDanielMetz commented Sep 25, 2023

Describe the bug

If I try to setup an EDC 0.5.1 from scratch and not as a migration from an EDC 0.5.0, I am getting an error while the EDC controlplane boots up.

To Reproduce

  1. Deploy the EDC 0.5.1 from scratch with an empty / not existend database
  2. Check the logfile of the EDC controlplane

Expected behavior

The DB migration scripts can be executed successfully.

[2023-09-25 13:56:46] [INFO   ] Migrating schema "public" to version "0.0.3 - Add StatefulEntity Columns"
[2023-09-25 13:56:46] [SEVERE ] Migration of schema "public" to version "0.0.3 - Add StatefulEntity Columns" failed! Changes successfully rolled back.
SEVERE 2023-09-25T13:56:46.941900178 Error booting runtime: Migration V0_0_3__Add_StatefulEntity_Columns.sql failed ------------------------------------------------------- SQL State  : 42P01 Error Code : 0 Message    : ERROR: relation "edc_lease" does not exist 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       : 23 Statement  : ALTER TABLE edc_edr_cache ADD COLUMN lease_id VARCHAR CONSTRAINT edc_edr_cache_lease_lease_id_fk REFERENCES edc_lease ON DELETE SET NULL 
org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: Migration V0_0_3__Add_StatefulEntity_Columns.sql failed
-------------------------------------------------------
SQL State  : 42P01
Error Code : 0
Message    : ERROR: relation "edc_lease" does not exist
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       : 23
Statement  : ALTER TABLE edc_edr_cache ADD COLUMN lease_id VARCHAR CONSTRAINT edc_edr_cache_lease_lease_id_fk REFERENCES edc_lease ON DELETE SET NULL

	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:196)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:140)
	at org.eclipse.tractusx.edc.postgresql.migration.AbstractPostgresqlMigrationExtension.initialize(AbstractPostgresqlMigrationExtension.java:89)
	at org.eclipse.tractusx.edc.postgresql.migration.EdrPostgresqlMigrationExtension.initialize(EdrPostgresqlMigrationExtension.java:17)
	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:141)
	at org.eclipse.edc.boot.system.runtime.BaseRuntime.boot(BaseRuntime.java:202)
	at org.eclipse.edc.boot.system.runtime.BaseRuntime.boot(BaseRuntime.java:84)
	at org.eclipse.edc.boot.system.runtime.BaseRuntime.main(BaseRuntime.java:72)
Caused by: org.flywaydb.core.internal.sqlscript.FlywaySqlScriptException: Migration V0_0_3__Add_StatefulEntity_Columns.sql failed
-------------------------------------------------------
SQL State  : 42P01
Error Code : 0
Message    : ERROR: relation "edc_lease" does not exist
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       : 23
Statement  : ALTER TABLE edc_edr_cache ADD COLUMN lease_id VARCHAR CONSTRAINT edc_edr_cache_lease_lease_id_fk REFERENCES edc_lease ON DELETE SET NULL

	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.handleException(DefaultSqlScriptExecutor.java:267)
	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:222)
	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.execute(DefaultSqlScriptExecutor.java:126)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.executeOnce(SqlMigrationExecutor.java:68)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.lambda$execute$0(SqlMigrationExecutor.java:57)
	at org.flywaydb.core.internal.database.DefaultExecutionStrategy.execute(DefaultExecutionStrategy.java:27)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:56)
	at org.flywaydb.core.internal.command.DbMigrate.doMigrateGroup(DbMigrate.java:374)
	... 34 more
Caused by: org.postgresql.util.PSQLException: ERROR: relation "edc_lease" does not exist
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:415)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:335)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:321)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:297)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:292)
	at org.flywaydb.core.internal.jdbc.JdbcTemplate.executeStatement(JdbcTemplate.java:201)
	at org.flywaydb.core.internal.sqlscript.ParsedSqlStatement.execute(ParsedSqlStatement.java:95)
	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:210)
	... 40 more

Context Information

Bug seems to be introduced with #620

Possible Implementation

N/A

@DrDanielMetz DrDanielMetz added bug Something isn't working triage all new issues awaiting classification labels Sep 25, 2023
@wolf4ood
Copy link
Contributor

Hi @DrDanielMetz

how are you deploying the tractusx-edc with the helm charts?

@DrDanielMetz
Copy link
Author

Hi @wolf4ood,

simply with a helm install and a manifest file.

helm install edc --version 3.2.36-alpha gec-helm/cx-gec-edc -f manifests/int.yam

What I have to say is that we are running on OpenShift and we have our own helm charts.

How do you think the problem above is related to the helm charts?
Maybe you can give me a hint, what might be wrong.

@wolf4ood
Copy link
Contributor

@DrDanielMetz it shouldn't indeed but we do not experience this on our chart testing and deployment.
But it's definitely a bug in case the EDR migrations run before the other ones i guess, which is not happening in our testing.

We will work on a fix for this. As a workaround i think you can disable EDR one

https://github.com/eclipse-tractusx/tractusx-edc/tree/main/edc-extensions/postgresql-migration

@wolf4ood wolf4ood self-assigned this Sep 25, 2023
@DrDanielMetz
Copy link
Author

DrDanielMetz commented Sep 26, 2023

@wolf4ood I deactivated the EDR migration in EDC control plane.
However, in this case I am getting the below errors contiously:

org.eclipse.edc.spi.persistence.EdcPersistenceException: org.postgresql.util.PSQLException: ERROR: column "state" does not exist
  Position: 35
	at org.eclipse.edc.sql.SqlQueryExecutor.query(SqlQueryExecutor.java:104)
	at org.eclipse.tractusx.edc.edr.store.sql.SqlEndpointDataReferenceCache.lambda$nextNotLeased$9(SqlEndpointDataReferenceCache.java:213)
	at org.eclipse.edc.transaction.local.LocalTransactionContext.execute(LocalTransactionContext.java:74)
	at org.eclipse.tractusx.edc.edr.store.sql.SqlEndpointDataReferenceCache.nextNotLeased(SqlEndpointDataReferenceCache.java:204)
	at org.eclipse.tractusx.edc.edr.core.manager.EdrManagerImpl.lambda$processEdrInState$1(EdrManagerImpl.java:153)
	at org.eclipse.edc.statemachine.StateProcessorImpl.process(StateProcessorImpl.java:48)
	at java.base/java.util.stream.ReferencePipeline$5$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.LongPipeline.reduce(Unknown Source)
	at java.base/java.util.stream.LongPipeline.sum(Unknown Source)
	at org.eclipse.edc.statemachine.StateMachineManager.performLogic(StateMachineManager.java:110)
	at org.eclipse.edc.statemachine.StateMachineManager.lambda$loop$2(StateMachineManager.java:101)
	at io.micrometer.core.instrument.composite.CompositeTimer.record(CompositeTimer.java:141)
	at io.micrometer.core.instrument.Timer.lambda$wrap$0(Timer.java:196)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.postgresql.util.PSQLException: ERROR: column "state" does not exist
  Position: 35
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:415)
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
	at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:134)
	at org.eclipse.edc.sql.SqlQueryExecutor.query(SqlQueryExecutor.java:93)
	... 23 more

I guess that this is expected now.

After this, I tried to simply activating the EDR migration and tried to restart the pod. But then, I am getting the same error as stated above.

So, for the moment, I can run it with the continously printed / logged error that the edr-manager gets: column "state" does not exist.

@wolf4ood
Copy link
Contributor

Yeah if it's expected the error if the migration didn't run, but If you reactivate it should work though.

@DrDanielMetz
Copy link
Author

DrDanielMetz commented Sep 26, 2023

Expected the same as you. However, I am getting the same migration error.

The EDR database looks like this:

edr=# \dt List of relations Schema | Name | Type | Owner --------+---------------------------+-------+----------- public | edc_edr_cache | table | edrdbuser public | flyway_schema_history_edr | table | edrdbuser (2 rows)

And this are the executed flyway scripts:
edr=# select * from public.flyway_schema_history_edr; installed_rank | version | description | type | script | checksum | installed_by | installed_on | execution_time | success ----------------+---------+--------------------------+----------+--------------------------------------+-------------+--------------+----------------------------+----------------+--------- 1 | 0.0.0 | << Flyway Baseline >> | BASELINE | << Flyway Baseline >> | | edrdbuser | 2023-09-25 13:25:15.683781 | 0 | t 2 | 0.0.1 | Init Edr Database Schema | SQL | V0_0_1__Init_Edr_Database_Schema.sql | 48044077 | edrdbuser | 2023-09-25 13:25:15.784927 | 17 | t 3 | 0.0.2 | Add ProviderId Column | SQL | V0_0_2__Add_ProviderId_Column.sql | -1112623946 | edrdbuser | 2023-09-25 13:25:15.810639 | 2 | t (3 rows)

Where the edc_lease should be created?

@DrDanielMetz
Copy link
Author

I guess, the issue is that I am having it in a separate DB. Right?

@wolf4ood
Copy link
Contributor

oh so you did put the EDR table in a separated DB?

@DrDanielMetz
Copy link
Author

Yes, seems to be my fault.

I misinterpreted this one:

# see extension https://github.com/eclipse-tractusx/tractusx-edc/tree/main/edc-extensions/edr-cache-sql - name: "EDC_DATASOURCE_EDR_NAME" value: "edr" - name: "EDC_DATASOURCE_EDR_USER" value: {{ .Values.postgresql.auth.username | required ".Values.postgresql.auth.username is required" | quote }} - name: "EDC_DATASOURCE_EDR_PASSWORD" value: {{ .Values.postgresql.auth.password | required ".Values.postgresql.auth.password is required" | quote }} - name: "EDC_DATASOURCE_EDR_URL" value: {{ tpl .Values.postgresql.jdbcUrl . | quote }}

@wolf4ood
Copy link
Contributor

wolf4ood commented Sep 26, 2023

The bug still exists if you want to bind the edr table to another DB. but if you bind to the same it should work.

Let me know if this is the case
Thanks

@DrDanielMetz
Copy link
Author

It works.
Sorry for the inconvenience and many thanks for your support and help!

@wolf4ood
Copy link
Contributor

@DrDanielMetz np it's indeed a bug if you want to actually have the EDR table in another datasource :)

@florianrusch-zf
Copy link
Contributor

I also ran into problems in the past where I tried to create a separate database for each DB config section in the settings (asset, transfer, edr,...). Because why else would you keep specifying the same configs multiple times if everything has to/should be in the same DB.

@paullatzelsperger
Copy link
Contributor

pls upgrade to EDC 0.5.3

@ndr-brt ndr-brt removed the triage all new issues awaiting classification label Nov 21, 2023
@florianrusch-zf
Copy link
Contributor

I guess we can close this, or?

@DrDanielMetz
Copy link
Author

From my side yes.
Just @wolf4ood mentioned on Sep 26th 2023 that it is indeed a bug.
Is his comment / assessment on this still the same and valid?

@wolf4ood
Copy link
Contributor

wolf4ood commented Feb 5, 2024

I'd close this, it does not affect most of the use case, only when you configure the EDR on it's own datasource.

Also it will probably be affected by the dataplane signaling upcoming in EDC upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants