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

Add support for PostgreSQL as store engine #255

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

borismartinovic01
Copy link
Contributor

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: kv and locks tables. The kv table stores data regarding get, set, list and delete operations. The locks table 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_cron extension 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 the locks table. DELETE trigger created on the locks table 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

@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 63.68715% with 65 lines in your changes missing coverage. Please review.

Project coverage is 47.53%. Comparing base (6c56470) to head (413187a).
Report is 34 commits behind head on unstable.

Files with missing lines Patch % Lines
store/engine/postgresql/postgresql.go 63.68% 51 Missing and 14 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #255      +/-   ##
============================================
+ Coverage     43.38%   47.53%   +4.15%     
============================================
  Files            37       44       +7     
  Lines          2971     4085    +1114     
============================================
+ Hits           1289     1942     +653     
- Misses         1544     1933     +389     
- Partials        138      210      +72     
Flag Coverage Δ
unittests 47.53% <63.68%> (+4.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

store/engine/postgresql/postgresql.go Outdated Show resolved Hide resolved
store/engine/postgresql/postgresql_test.go Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

3 participants