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

Concurrent appending of events cause constraint violation #183

Open
hamsterready opened this issue May 10, 2022 · 1 comment
Open

Concurrent appending of events cause constraint violation #183

hamsterready opened this issue May 10, 2022 · 1 comment

Comments

@hamsterready
Copy link

It looks like this part:

https://github.com/thehonesttech/zio-entity/blob/71dccddd986280c70ef265f9fbe01a1850b1a08e/core/src/main/scala/zio/entity/core/KeyedAlgebraCombinators.scala#L32-L45

cause issues when events are appended in a concurrent way.

Consider two threads/fibers: T1, T2
T1 and T2 read offset (say offset = 2)
after that offset is used to insert data into store (postgres):

eventJournal.append(key, offset, events)

T1 and T2 tries to insert with offset = 2 and one ends with exception like this:

ava.sql.BatchUpdateException: Batch entry 0 INSERT INTO ledger_event (key, seq_nr, event, tags) VALUES (?, 6, ?, ?) was aborted: ERROR: duplicate key value violates unique constraint "ledger_event_key_seq_nr_uindex"
  Detail: Key (key, seq_nr)=(\x7b2276616c7565223a7b2276616c7565223a2230636634626635362d396166362d343930612d386132372d303833333735623135383730227d7d, 2) already exists.  Call getNextException to see other errors in the batch.
@tobia80
Copy link
Owner

tobia80 commented Jun 7, 2022

Thanks for the issue! Can you please provide a concrete example? in an entity no parallel execution should happen calling append so the append is supposed to run in sequence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants