IBMStockTrader / portfolio

Microservice implemented with MicroProfile that persists stock portfolios to JDBC (such as DB2)
Apache License 2.0
7 stars 60 forks source link

Concurrent Delete #52

Closed rtclauss closed 1 year ago

rtclauss commented 2 years ago

Was seeing the following error in portfolio

WTRN0074E: Exception caught from before_completion synchronization operation: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.10.v20211216-fe64cd39c3): org.eclipse.persistence.exceptions.DatabaseException\nInternal Exception: org.postgresql.util.PSQLException: ERROR: could not serialize access due to concurrent delete\nError Code: 0\nCall: DELETE FROM STOCK WHERE ((SYMBOL = ?) AND (owner = ?))\n\tbind => [2 parameters bound]\nQuery: DeleteObjectQuery({\"symbol\": \"AMZN\", \"shares\": 5, \"commission\": 9.99, \"price\": 140.8, \"total\": 704.0, \"date\": \"2022-08-05\"})\n\tat org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl$1.handleException(EntityManagerSetupImpl.java:788)\n\tat

Googling led to this answer https://stackoverflow.com/questions/38466095/in-a-was-liberty-connection-pool-can-i-validate-connections-on-borrow

So the connection pool should be:

<connectionManager id="dbConnections" maxPoolSize="50" purgePolicy="ValidateAllConnections" validationTimeout="10m"/>

I've been running this for 2 months now without seeing any more concurrent delete errors in portfolio.

jwalcorn commented 1 year ago

Fixed under https://github.com/IBMStockTrader/portfolio/commit/4067e0ceddb0fd04d4d9a67a7539df91ea8a5c69