-
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
feat(clustering) retiring Serf - new cache invalidation mechanism #2561
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cb3e7c7
feat(cluster) new cluster events module
thibaultcha 61dc944
feat(mlcache) new [temporary] kong.mlcache module
thibaultcha d3379fd
feat(cache) new kong.cache module to replace database_cache.lua
thibaultcha 4c703e0
tests(*) disable tests relying on old cluster arch
thibaultcha 8b2f36c
refactor(core) use new invalidations framework
thibaultcha eefc6d9
feat(admin) update /cache/ endpoint to use newer caching module
thibaultcha d0b3c44
refactor(plugins) use new invalidations framework
thibaultcha da4d8c6
refactor(*) retire Serf - for good
thibaultcha c7f9da5
chore(migrations) remove 'nodes' table
thibaultcha a9f45bd
feat(conf) new properties for datastore cache
thibaultcha 79bea8b
tests(*) reorganize test suites
thibaultcha e5cce15
feat(conf) warn log when dangerous cache setting detected
thibaultcha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,34 @@ | ||
local responses = require "kong.tools.responses" | ||
local cache = require "kong.tools.database_cache" | ||
local singletons = require "kong.singletons" | ||
|
||
-- Create a table of functions per cache type | ||
local caches | ||
do | ||
local cache_names = {} | ||
caches = setmetatable({ | ||
lua = function(action, ...) | ||
if action == "get" then | ||
return cache.get(...) | ||
elseif action == "delete" then | ||
return cache.delete(...) | ||
elseif action == "delete_all" then | ||
return cache.delete_all(...) | ||
end | ||
end, | ||
shm = function(action, ...) | ||
if action == "get" then | ||
return cache.sh_get(...) | ||
elseif action == "delete" then | ||
return cache.sh_delete(...) | ||
elseif action == "delete_all" then | ||
return cache.sh_delete_all(...) | ||
return { | ||
["/cache/:key"] = { | ||
GET = function(self, _, helpers) | ||
-- probe the cache to see if a key has been requested before | ||
|
||
local ttl, err, value = singletons.cache:probe(self.params.key) | ||
if err then | ||
return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(err) | ||
end | ||
end, | ||
}, { | ||
__index = function(self, key) | ||
return responses.send_HTTP_BAD_REQUEST("invalid cache type; '" .. | ||
tostring(key) .. "', valid caches are: " .. cache_names) | ||
end, | ||
}) | ||
|
||
-- build string with valid cache names (for error mesage above) | ||
for name in pairs(caches) do cache_names[#cache_names+1] = "'" .. name .. "'" end | ||
table.sort(cache_names) -- make order deterministic, for test purposes | ||
cache_names = table.concat(cache_names, ", ") | ||
end | ||
if ttl then | ||
return helpers.responses.send_HTTP_OK(value) | ||
end | ||
|
||
return { | ||
["/cache/"] = { | ||
before = function(self) | ||
self.params.cache = self.params.cache or "lua" | ||
return helpers.responses.send_HTTP_NOT_FOUND() | ||
end, | ||
|
||
DELETE = function(self, dao_factory) | ||
caches[self.params.cache]("delete_all") | ||
return responses.send_HTTP_NO_CONTENT() | ||
end | ||
}, | ||
DELETE = function(self, _, helpers) | ||
singletons.cache:invalidate_local(self.params.key) | ||
|
||
["/cache/:key"] = { | ||
before = function(self) | ||
self.params.cache = self.params.cache or "lua" | ||
return helpers.responses.send_HTTP_NO_CONTENT() | ||
end, | ||
}, | ||
|
||
GET = function(self, dao_factory) | ||
if self.params.key then | ||
local cached_item = caches[self.params.cache]("get", self.params.key) | ||
if cached_item ~= nil then | ||
return responses.send_HTTP_OK(cached_item) | ||
end | ||
end | ||
["/cache"] = { | ||
DELETE = function(self, _, helpers) | ||
singletons.cache:purge() | ||
|
||
return responses.send_HTTP_NOT_FOUND() | ||
return helpers.responses.send_HTTP_NO_CONTENT() | ||
end, | ||
|
||
DELETE = function(self, dao_factory) | ||
if self.params.key then | ||
caches[self.params.cache]("delete", self.params.key) | ||
return responses.send_HTTP_NO_CONTENT() | ||
end | ||
|
||
return responses.send_HTTP_NOT_FOUND() | ||
end | ||
} | ||
}, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand what this setting does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the description to clarify the meaning