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

refactor(clustering/rpc): move is_valid_version() to strategies #14135

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ local MAX_RETRY = 5

local assert = assert
local ipairs = ipairs
local sub = string.sub
local ngx_null = ngx.null
local ngx_log = ngx.log
local ngx_ERR = ngx.ERR
Expand Down Expand Up @@ -60,17 +59,6 @@ local function get_current_version()
end


local is_valid_version
do
local VER_PREFIX = "v02_"

-- version string must start with 'v02_'
is_valid_version = function(v)
return sub(v, 1, 4) == VER_PREFIX
end
end


function _M:init_cp(manager)
local purge_delay = manager.conf.cluster_data_plane_purge_delay

Expand Down Expand Up @@ -118,7 +106,7 @@ function _M:init_cp(manager)
end

-- string comparison effectively does the same as number comparison
if not is_valid_version(default_namespace_version) or
if not self.strategy:is_valid_version(default_namespace_version) or
default_namespace_version ~= latest_version then
return full_sync_result()
end
Expand Down
10 changes: 9 additions & 1 deletion kong/clustering/services/sync/strategies/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ local _M = {}
local _MT = { __index = _M }


local sub = string.sub
local fmt = string.format
local ngx_null = ngx.null


-- version string should look like: "v02_0000"
local VERSION_FMT = "v02_%028x"
local VER_PREFIX = "v02_"
local VER_PREFIX_LEN = #VER_PREFIX
local VERSION_FMT = VER_PREFIX .. "%028x"


function _M.new(db)
Expand Down Expand Up @@ -56,6 +59,11 @@ function _M:get_latest_version()
end


function _M:is_valid_version(str)
return sub(str, 1, VER_PREFIX_LEN) == VER_PREFIX
end


function _M:begin_txn()
return self.connector:query("BEGIN;")
end
Expand Down
Loading