-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feature: PostgreSQL support #1054
Conversation
See test case for detailed explanations. This was broken while implementing Postgres.
It seems the Luarocks install cached by Travis retains some data about the installed modules. Better to purge the tree before installing Kong, to avoid conflicts with module changes bearing the same version. (Sometimes modules are changed but Kong's version is not bumped until its release)
Since we need Cassandra and Postgres for integration tests.
💥 👏 👏 🎉 |
How can we transfer data from cassandra to postgresql? Is there a builtin tool or we need to create it? |
Sadly not, we do not provide a way to migrate from one to the other. Sorry! |
@codebien but migration could still be done by leveraging the API. |
👏 |
I know you've been working on this for awhile @thibaultcha. Really appreciate the effort! 👍 |
@thibaultcha i've been experimenting with Postgres and found an issue where the nodes disappear after one hour - i've traced it through to the TTL functionality. Firstly - on the heartbeat, the ttl is missing - so it never gets updated: --- a/kong/core/cluster.lua
+++ b/kong/core/cluster.lua
@@ -79,7 +79,7 @@ local function send_keepalive(premature)
ngx.log(ngx.ERR, tostring(err))
elseif #nodes == 1 then
local node = nodes[1]
- local _, err = singletons.dao.nodes:update(node, node)
+ local _, err = singletons.dao.nodes:update(node, node, {ttl = 3600})
if err then
ngx.log(ngx.ERR, tostring(err))
end The second issue is that the TTL is never updated - the stored procedure is called to perform the update, but the expiry never moves - this is because of a bug i think - here: https://github.com/Mashape/kong/blob/next/kong/dao/postgres_db.lua#L230 The base time for the new TTL is the created_at date of the node - but this will never change - so adding 1 hour to the created_at date will always result in the same time (as created_at is set once) It should be using the existing expiry_at as the base time for the new TTL. I haven't figured out how to patch that yet as my Lua skills are weak. |
Thanks for investigating this. @thefosk implemented the TTL part and will review this.
|
Good catch.
Let me look into this, your reasoning seems accurate. I will push the fixes and a couple more tests for the update bug. |
Okay, I have been looking at the code and the Updating an entity without specifying the TTL should not override any TTL previously set at insertion time, so I am looking into this now. |
Forget about my last comment - The issue you reported is correct, and the bug was introduced because Cassandra renews the TTL every time an update operation is being executed (even if the TTL is not being specified again), while with Postgres we need to manually renew it every time. So both your considerations are correct. |
Support for database abstraction with Cassandra (original) and PostgreSQL (new). Related: #331, #883.
This implements a new DAO, which can interface with both of those databases. At the same time, it tries to keep changes relatively backwards-compatible so changes to existing plugins (in this repo or custom ones) are relatively small.
For the new DAO, see:
kong/dao/factory.lua
kong/dao/dao.lua
kong/dao/postgres_db.lua
kong/dao/cassandra_db.lua
The underlying
*_db
implementations try to take advantages of each database's features. As such, the Postgres implementation relies on SQL's FOREIGN constraints and CASCADE deletion. As a trade-off between optimal SQL support and backwards-compatibility, Postgres' schema is as close as possible as Cassandra's.How to test it (if you want to try it out or just a glimpse of how to use it):
kong
feature/postgres
branch of Kong (you must have a source install for this)As usual, migrations should run from
kong start
, but as a reminder and just in case, here are some tips:Reset the database with (careful, you'll lose all data):
Run the migrations manually with:
If needed, list your migrations for debug purposes with:
If you test it, feel free to report any issues :)