We're updating the issue view to help you get more done. 

Rewrite DatabaseMetaDataReaderImpl.getFields Using Standard JDBC

Description

See the OD issue here

https://sdog.jira.com/browse/JSTDEV-2760

Basically if the Tomcat preparedStatementCache is used then AO can blow up on the second ao.migrate() after a destructive ALTER

The SD team is falling into this trap. Anyone how migrates multiple columns (in a standard migrate / copy / migrate) pattern will blow up with this.

It also seems to depend on what DB connection you get from the pool.

We need to "clean" out the connection / statement or change the way we do the meta data reading.

I noticed one thing about the code where is "re-uses" the metadata generating connection to get its statement. Maybe thats the problem?

Either way we need clean connections during migration on Postgres

The error from Postgres is

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Caused by: java.lang.RuntimeException: Could not read fields for table AO_54307E_VIEWPORT at net.java.ao.schema.helper.DatabaseMetaDataReaderImpl.getFields(DatabaseMetaDataReaderImpl.java:151) at net.java.ao.schema.ddl.SchemaReader.readFields(SchemaReader.java:125) at net.java.ao.schema.ddl.SchemaReader.readTable(SchemaReader.java:108) at net.java.ao.schema.ddl.SchemaReader.access$000(SchemaReader.java:46) at net.java.ao.schema.ddl.SchemaReader$1.apply(SchemaReader.java:96) at net.java.ao.schema.ddl.SchemaReader$1.apply(SchemaReader.java:93) at com.google.common.collect.Iterators$8.next(Iterators.java:782) at com.google.common.collect.Lists.newArrayList(Lists.java:139) at com.google.common.collect.Lists.newArrayList(Lists.java:119) at net.java.ao.schema.ddl.SchemaReader.readSchema(SchemaReader.java:92) at net.java.ao.schema.ddl.SchemaReader.readSchema(SchemaReader.java:80) at net.java.ao.schema.ddl.SchemaReader.readSchema(SchemaReader.java:71) at net.java.ao.schema.SchemaGenerator.generateImpl(SchemaGenerator.java:109) at net.java.ao.schema.SchemaGenerator.migrate(SchemaGenerator.java:83) at net.java.ao.EntityManager.migrate(EntityManager.java:133) at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.migrate(EntityManagedActiveObjects.java:43) at com.atlassian.pocketknife.ao.util.ActiveObjectsKit.migrate(ActiveObjectsKit.java:79) at com.atlassian.servicedesk.ao.upgrade.task002.AoUpgradeTask002_STAGE2.doUpgrade(AoUpgradeTask002_STAGE2.java:39) at com.atlassian.pocketknife.ao.spi.AbstractActiveObjectsUpgradeTask.upgrade(AbstractActiveObjectsUpgradeTask.java:68) Caused by: org.postgresql.util.PSQLException: ERROR: cached plan must not change result type at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2077) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1810) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:498) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96) at net.java.ao.schema.helper.DatabaseMetaDataReaderImpl.getResultSetMetaData(DatabaseMetaDataReaderImpl.java:301) at net.java.ao.schema.helper.DatabaseMetaDataReaderImpl.getFields(DatabaseMetaDataReaderImpl.java:88)

Notice the ao.migrate() call is trying to read the metadata having made a ALTERing DDL call and because the underlying database strcuture has change it blows up.

Setting the poolPreparedStatements="false" fixes the problem.

Environment

None

Testing Notes

None

Status

Assignee

Unassigned

Reporter

Brad Baker

Labels

Add-on Type

None

Team

None

CC

None

Risk factor

None

QA Kickoff Status

None

QA Demo Status

None

Story Points

0.5

Components

Priority

Major