diff --git a/kong/clustering/services/sync/hooks.lua b/kong/clustering/services/sync/hooks.lua index 931e6599001..01bc6c1d9d1 100644 --- a/kong/clustering/services/sync/hooks.lua +++ b/kong/clustering/services/sync/hooks.lua @@ -3,12 +3,12 @@ local _MT = { __index = _M, } local hooks = require("kong.hooks") -local constants = require("kong.constants") +--local constants = require("kong.constants") -local CLUSTERING_PING_INTERVAL = constants.CLUSTERING_PING_INTERVAL +--local CLUSTERING_PING_INTERVAL = constants.CLUSTERING_PING_INTERVAL local ngx_log = ngx.log -local ngx_DEBUG = ngx.DEBUG +--local ngx_DEBUG = ngx.DEBUG local ngx_ERR = ngx.ERR diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 504894109bf..67f062e6f65 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -2,8 +2,8 @@ local _M = {} local _MT = { __index = _M, } -local semaphore = require("ngx.semaphore") -local lmdb = require("resty.lmdb") +--local semaphore = require("ngx.semaphore") +--local lmdb = require("resty.lmdb") local txn = require("resty.lmdb.transaction") local declarative = require("kong.db.declarative") local constants = require("kong.constants") @@ -201,9 +201,13 @@ function _M:sync_once(delay) -- upsert the entity -- does the entity already exists? local old_entity, err = kong.db[delta.type]:select(delta.row) + if err then + return nil, err + end + local crud_event_type = "create" - if entity then + if old_entity then local res, err = delete_entity_for_txn(t, delta.type, old_entity, nil) if not res then return nil, err @@ -223,6 +227,10 @@ function _M:sync_once(delay) else -- delete the entity local old_entity, err = kong.db[delta.type]:select({ id = delta.id, }) -- TODO: composite key + if err then + return nil, err + end + if old_entity then local res, err = delete_entity_for_txn(t, delta.type, old_entity, nil) if not res then diff --git a/kong/db/declarative/import.lua b/kong/db/declarative/import.lua index c6e353d3055..430c6f13559 100644 --- a/kong/db/declarative/import.lua +++ b/kong/db/declarative/import.lua @@ -15,10 +15,10 @@ local sha256_hex = require("kong.tools.sha256").sha256_hex local pk_string = declarative_config.pk_string local assert = assert -local sort = table.sort +--local sort = table.sort local type = type local pairs = pairs -local next = next +--local next = next local insert = table.insert local string_format = string.format local null = ngx.null @@ -306,7 +306,7 @@ local function insert_entity_for_txn(t, entity_name, item, options) end if fdata.unique_across_ws then - ws_id = default_workspace_id + ws_id = kong.default_workspace end local key = unique_field_key(entity_name, ws_id, fname, value) @@ -364,7 +364,7 @@ local function delete_entity_for_txn(t, entity_name, item, options) end if fdata.unique_across_ws then - ws_id = default_workspace_id + ws_id = kong.default_workspace end local key = unique_field_key(entity_name, ws_id, fname, value) diff --git a/kong/db/strategies/off/init.lua b/kong/db/strategies/off/init.lua index 1f34d6725d9..54a5f68d2af 100644 --- a/kong/db/strategies/off/init.lua +++ b/kong/db/strategies/off/init.lua @@ -1,34 +1,35 @@ local declarative_config = require("kong.db.schema.others.declarative_config") -local workspaces = require("kong.workspaces") +--local workspaces = require("kong.workspaces") local lmdb = require("resty.lmdb") local lmdb_prefix = require("resty.lmdb.prefix") -local lmdb_transaction = require("resty.lmdb.transaction") +--local lmdb_transaction = require("resty.lmdb.transaction") local marshaller = require("kong.db.declarative.marshaller") -local yield = require("kong.tools.yield").yield +--local yield = require("kong.tools.yield").yield local declarative = require("kong.db.declarative") local kong = kong local string_format = string.format local type = type local next = next -local sort = table.sort -local pairs = pairs -local match = string.match +--local sort = table.sort +--local pairs = pairs +--local match = string.match local assert = assert -local tostring = tostring -local tonumber = tonumber -local encode_base64 = ngx.encode_base64 -local decode_base64 = ngx.decode_base64 +--local tostring = tostring +--local tonumber = tonumber +--local encode_base64 = ngx.encode_base64 +--local decode_base64 = ngx.decode_base64 local null = ngx.null local unmarshall = marshaller.unmarshall -local marshall = marshaller.marshall +--local marshall = marshaller.marshall local lmdb_get = lmdb.get -local get_workspace_id = workspaces.get_workspace_id +--local get_workspace_id = workspaces.get_workspace_id local pk_string = declarative_config.pk_string local unique_field_key = declarative.unique_field_key local item_key = declarative.item_key local item_key_prefix = declarative.item_key_prefix local workspace_id = declarative.workspace_id +local foreign_field_key_prefix = declarative.foreign_field_key_prefix local PROCESS_AUTO_FIELDS_OPTS = { @@ -110,7 +111,7 @@ local function page_for_prefix(self, prefix, size, offset, options, follow) offset = offset or prefix - local list = {} + --local list = {} local ret = {} local ret_idx = 0 @@ -201,6 +202,7 @@ local function select_by_field(self, field, value, options) end +--[[ local function remove_nulls(tbl) for k,v in pairs(tbl) do if v == null then @@ -212,6 +214,7 @@ local function remove_nulls(tbl) end return tbl end +--]] do