Skip to content

Commit

Permalink
refactor(clustering/rpc): move is_valid_version() to strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Jan 14, 2025
1 parent 9c48b27 commit d9b3013
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
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
9 changes: 8 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,14 @@ 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 VERSION_FMT = VER_PREFIX .. "%028x"


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


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


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

0 comments on commit d9b3013

Please sign in to comment.