From 1ed09e059b396356eddf6f943ecb435fa8011893 Mon Sep 17 00:00:00 2001 From: Dong Zhang <41927498+dzhangalibaba@users.noreply.github.com> Date: Fri, 20 Sep 2019 01:58:18 +0800 Subject: [PATCH] fully support bulk_remove in sairedis (#516) - add redis_dummy_remove_route_entry() for meta_sai_remove_route_entry() calls, which is the same logic as create/set - add NULL pointer check and add meta_sai_remove_route_entry() calls which will remove meta data after remove entries. The logic is the same as create/set - syncd add bulkremove option for processEvent() to select processBulkEvent() - together with this , there should be a consumer_table_pops.lua script changes to handle bulkremove in sonic_swss_common Azure/sonic-swss-common#306 - after these changes , when we call bulk_create and bulk_remove, the meta data is cleared and we can bulk_create again, otherwise it raise error entry already exists. Signed-off-by: Dong Zhang d.zhang@alibaba-inc.com --- lib/src/sai_redis_route.cpp | 75 +++++++++++++++++++++++++++++++++++++ syncd/syncd.cpp | 4 ++ 2 files changed, 79 insertions(+) diff --git a/lib/src/sai_redis_route.cpp b/lib/src/sai_redis_route.cpp index 982116e0dab6..4121742fc5a0 100644 --- a/lib/src/sai_redis_route.cpp +++ b/lib/src/sai_redis_route.cpp @@ -134,6 +134,21 @@ sai_status_t sai_bulk_create_route_entry( object_statuses); } +sai_status_t redis_dummy_remove_route_entry( + _In_ const sai_route_entry_t *route_entry) +{ + SWSS_LOG_ENTER(); + + /* + * Since we are using validation for each route in bulk operations, we + * can't execute actual REMOVE, we need to do dummy remove and then introduce + * internal bulk_remove operation that will only touch redis db only once. + * So we are returning success here. + */ + + return SAI_STATUS_SUCCESS; +} + sai_status_t sai_bulk_remove_route_entry( _In_ uint32_t object_count, _In_ const sai_route_entry_t *route_entry, @@ -144,6 +159,41 @@ sai_status_t sai_bulk_remove_route_entry( SWSS_LOG_ENTER(); + if (object_count < 1) + { + SWSS_LOG_ERROR("expected at least 1 object to create"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (route_entry == NULL) + { + SWSS_LOG_ERROR("route_entry is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + switch (mode) + { + case SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR: + case SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR: + // ok + break; + + default: + + SWSS_LOG_ERROR("invalid bulk operation mode %d", mode); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (object_statuses == NULL) + { + SWSS_LOG_ERROR("object_statuses is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + std::vector serialized_object_ids; for (uint32_t idx = 0; idx < object_count; ++idx) @@ -158,6 +208,31 @@ sai_status_t sai_bulk_remove_route_entry( sai_serialize_route_entry(route_entry[idx])); } + for (uint32_t idx = 0; idx < object_count; ++idx) + { + sai_status_t status = + meta_sai_remove_route_entry( + &route_entry[idx], + &redis_dummy_remove_route_entry); + + object_statuses[idx] = status; + + if (status != SAI_STATUS_SUCCESS) + { + // TODO add attr id and value + + SWSS_LOG_ERROR("failed on index %u: %s", + idx, + serialized_object_ids[idx].c_str()); + + if (mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR) + { + SWSS_LOG_NOTICE("stop on error since previous operation failed"); + break; + } + } + } + return internal_redis_bulk_generic_remove(SAI_OBJECT_TYPE_ROUTE_ENTRY, serialized_object_ids, object_statuses); } diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index db5fcf0fbfa1..9038a7220941 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -2917,6 +2917,10 @@ sai_status_t processEvent( { return processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_CREATE, kco); } + else if (op == "bulkremove") + { + return processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_REMOVE, kco); + } else if (op == "notify") { return notifySyncd(key);