Add support for PostgreSQL as store engine#255
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #255 +/- ##
============================================
+ Coverage 43.38% 46.85% +3.47%
============================================
Files 37 45 +8
Lines 2971 4217 +1246
============================================
+ Hits 1289 1976 +687
- Misses 1544 2033 +489
- Partials 138 208 +70
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
Hey folks, I see that this PR hasn't been approved yet. If you have any feature requirements which need to be written from scratch (like the one I did for Consul) for either controller or kvrocks core, please send them to me, I'll implement whatever you need. |
|
@borismartinovic01 Thanks for your contributions! Will take a look in those two days. |
|
Thank you for your contribution! I didn't give a review since I'm not familiar with postgres. I'm fine if it looks good to other reviewers. And, some git conflicts need to be resolved now. |
35db676 to
0ca14a2
Compare
Description
This PR adds PostgreSQL as a store engine. The implementation is kept as similar as possible to other supported engines.
Two tables are created:
kvandlockstables. Thekvtable stores data regarding get, set, list and delete operations. Thelockstable is used for leader election. Design is based on publish/subscribe so there is no polling mechanism. This is achieved by utilizing the trigger and LISTEN/NOTIFY combination.In other engines, we would assign a session to the lock so it expires after a defined period, but here we don't have this functionality so we use the
pg_cronextension to define a job that will be executed every 6 seconds (session TTL for other engines) and deletes created lock entry. Job is scheduled by INSERT trigger created on thelockstable. DELETE trigger created on thelockstable removes this cronjob. If the cronjob is scheduled only once to run every 6 seconds, this time and TTL of lock entry will diverge. By creating and removing a cronjob at the same time when lock entry is created and removed we ensure TTL of 6 seconds is correct.Testing
Tested the implementation by running Postgres as Docker container locally and running UTs