diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 5998ff2762dd..3d3ec5360890 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 @@ -242,15 +243,14 @@ local function do_sync() return nil, err end - local crud_event_type = "create" + local crud_event_type = old_entity and "update" or "create" - if old_entity then + -- If we will wipe lmdb, we don't need to delete it from lmdb. + 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 end - - crud_event_type = "update" end local res, err = insert_entity_for_txn(t, delta_type, delta_row, nil) @@ -267,7 +267,8 @@ local function do_sync() return nil, err end - if old_entity then + -- If we will wipe lmdb, we don't need to delete it from lmdb. + 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 +293,7 @@ local function do_sync() return nil, err end - if ns_delta.wipe then + if wipe then kong.core_cache:purge() kong.cache:purge()