Skip to content

Commit

Permalink
fix(clustering/sync): delta.version may be null
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 25, 2024
1 parent 1ae5171 commit 198060b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 5 additions & 3 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function _M:init_cp(manager)
end

-- is the node empty? If so, just do a full sync to bring it up to date faster
if default_namespace_version == 0 or latest_version == ngx_null or
if default_namespace_version == 0 or
latest_version - default_namespace_version > FULL_SYNC_THRESHOLD
then
-- we need to full sync because holes are found
Expand Down Expand Up @@ -295,8 +295,10 @@ local function do_sync()
crud_events_n = crud_events_n + 1
crud_events[crud_events_n] = ev

-- XXX TODO: could delta.version be nil or ngx.null
if type(delta.version) == "number" and delta.version ~= version then
-- delta.version should not be nil or ngx.null
assert(type(delta.version) == "number")

if delta.version ~= version then
version = delta.version
end
end -- for _, delta
Expand Down
8 changes: 7 additions & 1 deletion kong/clustering/services/sync/strategies/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local buffer = require("string.buffer")

local string_format = string.format
local cjson_encode = cjson.encode
local ngx_null = ngx.null
local ngx_log = ngx.log
local ngx_ERR = ngx.ERR
local ngx_DEBUG = ngx.DEBUG
Expand Down Expand Up @@ -99,7 +100,12 @@ function _M:get_latest_version()
return nil, err
end

return res[1] and res[1].max_version
local ver = res[1] and res[1].max_version
if ver == ngx_null then
return 0
end

return ver
end


Expand Down
4 changes: 4 additions & 0 deletions kong/db/declarative/export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ local function export_from_db_impl(emitter, skip_ws, skip_disabled_entities, exp
return nil, err
end

-- it will be ngx.null when the table clustering_sync_version is empty
sync_version = assert(ok[1].max)
if sync_version == null then
sync_version = 0
end
end

emitter:emit_toplevel({
Expand Down

0 comments on commit 198060b

Please sign in to comment.