From c04f6fc9c148ce854826bb2e71ae7b6904f8d075 Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Tue, 15 Oct 2024 15:47:12 +0800 Subject: [PATCH] fix(incremental): dont delete old entity from LMDB if we clear it already --- kong/clustering/services/sync/rpc.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 5998ff2762dd..04f5299bc208 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -219,7 +219,8 @@ local function do_sync() local t = txn.begin(512) - if ns_delta.wipe then + local wipe = ns_delta.wipe + if wipe then t:db_drop(false) end @@ -245,9 +246,12 @@ local function do_sync() local crud_event_type = "create" if old_entity then - local res, err = delete_entity_for_txn(t, delta_type, old_entity, nil) - if not res then - return nil, err + -- If we need to wipe lmdb, we don't need to not delete it from lmdb. + if not wipe then + local res, err = delete_entity_for_txn(t, delta_type, old_entity, nil) + if not res then + return nil, err + end end crud_event_type = "update" @@ -267,7 +271,8 @@ local function do_sync() return nil, err end - if old_entity then + -- If we need to wipe lmdb, we don't need to delete old entity. + if old_entity and not wipe then local res, err = delete_entity_for_txn(t, delta_type, old_entity, nil) if not res then return nil, err @@ -292,7 +297,7 @@ local function do_sync() return nil, err end - if ns_delta.wipe then + if wipe then kong.core_cache:purge() kong.cache:purge()