linagora / james-project

Mirror of Apache James Project
Apache License 2.0
72 stars 62 forks source link

[PGSQL] Implement PostgresEventStore #5029

Closed quantranhong1999 closed 8 months ago

quantranhong1999 commented 10 months ago

Why

We need an EventStore backed by Postgres (some parts of James rely on event sourcing).

How

DoD

Pass contract tests.

chibenwa commented 10 months ago

TL;DR: More complex than it seems, I would love to see a POC...


This is a tricky one, as we need transactionnality when inserting several events: they either all succeed or all fails. Partial application is not supported. I would love to see in this ticket...

... Is this feature actually used? Is there some features that relies on storing several events or is this just some convoluted complexity we can get rid of? ... We could implement this with a transaction for sure. But do we have a way to match desired consistency without resorting to such extremities? Eg: Apparently PG supports inserting several rows at once natively: https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-insert-multiple-rows/

INSERT INTO 
    links (url, name)
VALUES
    ('https://www.google.com','Google'),
    ('https://www.yahoo.com','Yahoo'),
    ('https://www.bing.com','Bing');
quantranhong1999 commented 10 months ago

TL;DR: More complex than it seems, I would love to see a POC...

The inserting of several rows at once query is atomic: all or nothing. We can rely on that IMO.

https://github.com/linagora/james-project/assets/55171818/197f8de2-f185-4d5f-9cd7-760c977b6776

BTW, generally, I think every SQL query is atomic too, as each is an implicit transaction anyway.

chibenwa commented 10 months ago

Looks great to me!

Thanks for testing!

And PG is suuuuuch an awwwwwwwwesome database!

hungphan227 commented 10 months ago

batch could be another option

chibenwa commented 10 months ago

batch could be another option

And restricts our options for connection management

hungphan227 commented 9 months ago

draft https://github.com/apache/james-project/pull/1970