Skip to content

Commit

Permalink
fully support bulk_remove in sairedis (#516)
Browse files Browse the repository at this point in the history
- 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
sonic-net/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
  • Loading branch information
dzhangalibaba authored and lguohan committed Sep 19, 2019
1 parent 6cb1b31 commit 1ed09e0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
75 changes: 75 additions & 0 deletions lib/src/sai_redis_route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<std::string> serialized_object_ids;

for (uint32_t idx = 0; idx < object_count; ++idx)
Expand All @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1ed09e0

Please sign in to comment.