Skip to content

Commit

Permalink
refactor(clustering/rpc): move is_valid_version() to strategies (#14135)
Browse files Browse the repository at this point in the history
code clean of #14078

KAG-5894
  • Loading branch information
chronolaw authored Jan 14, 2025
1 parent 9c48b27 commit 4d56a90
Show file tree
Hide file tree
Showing 2 changed files with 10 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
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

1 comment on commit 4d56a90

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:4d56a907f91f5bacc33492f2d8f64db2b33e9206
Artifacts available https://github.com/Kong/kong/actions/runs/12760349529

Please sign in to comment.