Error while saving snapshot: (persistence_id, sequence_number) already exists

Hi, folks , I am getting the below error sometimes:
Detail: Key (persistence_id, sequence_number)=(MEMBERSHIP-d8ec1971-f095-43d2-a69f-39772463fd90, 43) already exists.

I am using postgres as database with classic actors

I found the below issues on github, but could not find a fix in those issues:
SnapShot Issue
Journal issue

I am not getting issue while saving into journal, it is only the snapshots which are not getting saved intermittently. Sometimes they get saved after throwing the above error , sometimes they are not saved. This can be problematic as some entries in the journal gets replayed, which is not desirable.
In this
Comment
Please, help me out.

Thanks.

After running slick in debug mode also I am not able to find the root cause of this issue.
Upsert operation is failing some times in the insert part in exists clause i guess.
Following is the query being executed by slick.

Executing prepared update: HikariProxyPreparedStatement@160991021 wrapping update "event"."snapshot" set "created"=?,"snapshot"=? where "persistence_id"=? and "sequence_number"=?; insert into "event"."snapshot" ("persistence_id","sequence_number","created","snapshot") select ?,?,?,? where not exists (select 1 from "event"."snapshot" where "persistence_id"=? and "sequence_number"=?)

There is already an exists check, then why is this query trying to insert as well.

Hi @tavisca-asingla,

Is that error triggered when saving the snapshot of when saving the event?
If that happens when saving a snapshot it looks like you are trying to save snapshots even when no event (aka, change in state) happened? how often do you save your snapshots?
If the error happens when inserting data on the journal this could indicate there’s a split brain on your cluster ro that you have multiple incarnations of the persistent actor in the cluster. If that was the case, then multiple instances read the database on a given version (eg. “Read Entity on version 42” from multiple incarnations) and then try to evolve that entity in different directions producing different instances of the event numbered 43. This branches the event history corrupting the journal.

Cheers,