lagom / lagom

Reactive Microservices for the JVM
https://www.lagomframework.com
Apache License 2.0
2.63k stars 634 forks source link

readside and readside offset produce duplicate entry error #3321

Closed ASchmidt84 closed 2 years ago

ASchmidt84 commented 2 years ago

Are you looking for help?

Yes, need help 😄 3 Pods alive only using postgresql as database. The persistent read side processor should save a new created user to ensure no duplicates will created.

override def buildHandler(): ReadSideProcessor.ReadSideHandler[UserProfile.Event] = readSide
    .builder[UserProfile.Event](UserProfileDefaultTable.TableName+"_offset")
    .setGlobalPrepare(table.schema.createIfNotExists)
    .setEventHandler[UserProfile.UserCreated](r => saveEntry(r.entityId,r.event.login, r.event.uniqueAliasToken))
    .setEventHandler[UserProfile.UserDeleted](r => deleteEntry(r.entityId))
    .build()

Lagom Version 1.6.5

API Scala

Operating System Kubernetes

Expected Behavior

On creating an entity which before ensure in read side is no duplicate, the persistend event will produce a new entry in the readside processor table with no conflict. And their is no try again for this entity and event.

Actual Behavior

org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "processor_user_profile_default_table_uiq_email_address_key"

At resart a µs it initialize the system and wants to install the primary user. The other µs already done it. But all of them are restarts all the time, running in the error above and restarts again after a while.

octonato commented 2 years ago

When creating an issue, we add that message "Are you looking for help?" followed by the following paragraph.

This is an issue tracker, used to manage and track the development of Lagom. It is not a support system and so it is not a place to ask questions or get help. If you're not sure if you have found a bug, the best place to start is with either the discussion forum or Stack Overflow. If you have a feature request, the contributors channel is a better forum than an issue tracker to discuss it.

Please, ask questions in the forum instead.

I can give you a hint though: I think that your system is not forming a cluster. It looks like you have twice the same application running without know about it each and not forming a cluster.

Anyway, that's just a hint so you have a place to look at.

If you post on the forum, try to explain in more detail how are you deploying it. Share some configuration. Give enough context. That will allow other users to help you.