Skip to content

Commit

Permalink
perf(clustering) do granular hashes like #8519 does for old protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
javierguerragiraldez committed Apr 12, 2022
1 parent 93ba646 commit 8e3f67c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions kong/clustering/wrpc_control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function _M:export_deflated_reconfigure_payload()
end
end

local config_hash = self:calculate_config_hash(config_table)
local config_hash, hashes = self:calculate_config_hash(config_table)
config_version = config_version + 1

-- store serialized plugins map for troubleshooting purposes
Expand All @@ -162,7 +162,8 @@ function _M:export_deflated_reconfigure_payload()
self.config_call_rpc, self.config_call_args = assert(service:encode_args("ConfigService.SyncConfig", {
config = config_table,
version = config_version,
hash = config_hash,
config_hash = config_hash,
hashes = hashes,
}))

return config_table, nil
Expand Down
7 changes: 5 additions & 2 deletions kong/clustering/wrpc_data_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ local function get_config_service()
data.config.format_version = nil

peer.config_obj.next_config = data.config
peer.config_obj.next_hash = data.hash
peer.config_obj.next_hash = data.config_hash
peer.config_obj.next_hashes = data.hashes
peer.config_obj.next_config_version = tonumber(data.version)
if peer.config_semaphore:count() <= 0 then
-- the following line always executes immediately after the `if` check
Expand Down Expand Up @@ -196,11 +197,12 @@ function _M:communicate(premature)
end
local config_table = self.next_config
local config_hash = self.next_hash
local hashes = self.next_hashes
if config_table and self.next_config_version > last_config_version then
ngx_log(ngx_INFO, _log_prefix, "received config #", self.next_config_version, log_suffix)

local pok, res
pok, res, err = xpcall(self.update_config, debug.traceback, self, config_table, config_hash, true)
pok, res, err = xpcall(self.update_config, debug.traceback, self, config_table, config_hash, true, hashes)
if pok then
last_config_version = self.next_config_version
if not res then
Expand All @@ -214,6 +216,7 @@ function _M:communicate(premature)
if self.next_config == config_table then
self.next_config = nil
self.next_hash = nil
self.next_hashes = nil
end
end

Expand Down
12 changes: 11 additions & 1 deletion kong/include/kong/services/config/v1/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ message PluginVersion {
string version = 2;
}

message GranularHashes {
string config = 1;
string routes = 2;
string services = 3;
string plugins = 4;
string upstreams = 5;
string targets = 6;
}

message SyncConfigRequest {
// Config represents a configuration of Kong Gateway.
// This is same as the declarative configuration of Kong.
Expand All @@ -101,7 +110,8 @@ message SyncConfigRequest {
uint64 version = 2;

// raw binary hash of the config data.
string hash = 3;
string config_hash = 3;
GranularHashes hashes = 4;
}

message SyncConfigResponse {
Expand Down

0 comments on commit 8e3f67c

Please sign in to comment.