Skip to content

Commit 1ed09e0

Browse files
dzhangalibabalguohan
authored andcommitted
fully support bulk_remove in sairedis (sonic-net#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 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 [email protected]
1 parent 6cb1b31 commit 1ed09e0

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

lib/src/sai_redis_route.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ sai_status_t sai_bulk_create_route_entry(
134134
object_statuses);
135135
}
136136

137+
sai_status_t redis_dummy_remove_route_entry(
138+
_In_ const sai_route_entry_t *route_entry)
139+
{
140+
SWSS_LOG_ENTER();
141+
142+
/*
143+
* Since we are using validation for each route in bulk operations, we
144+
* can't execute actual REMOVE, we need to do dummy remove and then introduce
145+
* internal bulk_remove operation that will only touch redis db only once.
146+
* So we are returning success here.
147+
*/
148+
149+
return SAI_STATUS_SUCCESS;
150+
}
151+
137152
sai_status_t sai_bulk_remove_route_entry(
138153
_In_ uint32_t object_count,
139154
_In_ const sai_route_entry_t *route_entry,
@@ -144,6 +159,41 @@ sai_status_t sai_bulk_remove_route_entry(
144159

145160
SWSS_LOG_ENTER();
146161

162+
if (object_count < 1)
163+
{
164+
SWSS_LOG_ERROR("expected at least 1 object to create");
165+
166+
return SAI_STATUS_INVALID_PARAMETER;
167+
}
168+
169+
if (route_entry == NULL)
170+
{
171+
SWSS_LOG_ERROR("route_entry is NULL");
172+
173+
return SAI_STATUS_INVALID_PARAMETER;
174+
}
175+
176+
switch (mode)
177+
{
178+
case SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR:
179+
case SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR:
180+
// ok
181+
break;
182+
183+
default:
184+
185+
SWSS_LOG_ERROR("invalid bulk operation mode %d", mode);
186+
187+
return SAI_STATUS_INVALID_PARAMETER;
188+
}
189+
190+
if (object_statuses == NULL)
191+
{
192+
SWSS_LOG_ERROR("object_statuses is NULL");
193+
194+
return SAI_STATUS_INVALID_PARAMETER;
195+
}
196+
147197
std::vector<std::string> serialized_object_ids;
148198

149199
for (uint32_t idx = 0; idx < object_count; ++idx)
@@ -158,6 +208,31 @@ sai_status_t sai_bulk_remove_route_entry(
158208
sai_serialize_route_entry(route_entry[idx]));
159209
}
160210

211+
for (uint32_t idx = 0; idx < object_count; ++idx)
212+
{
213+
sai_status_t status =
214+
meta_sai_remove_route_entry(
215+
&route_entry[idx],
216+
&redis_dummy_remove_route_entry);
217+
218+
object_statuses[idx] = status;
219+
220+
if (status != SAI_STATUS_SUCCESS)
221+
{
222+
// TODO add attr id and value
223+
224+
SWSS_LOG_ERROR("failed on index %u: %s",
225+
idx,
226+
serialized_object_ids[idx].c_str());
227+
228+
if (mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR)
229+
{
230+
SWSS_LOG_NOTICE("stop on error since previous operation failed");
231+
break;
232+
}
233+
}
234+
}
235+
161236
return internal_redis_bulk_generic_remove(SAI_OBJECT_TYPE_ROUTE_ENTRY, serialized_object_ids, object_statuses);
162237
}
163238

syncd/syncd.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,10 @@ sai_status_t processEvent(
29172917
{
29182918
return processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_CREATE, kco);
29192919
}
2920+
else if (op == "bulkremove")
2921+
{
2922+
return processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_REMOVE, kco);
2923+
}
29202924
else if (op == "notify")
29212925
{
29222926
return notifySyncd(key);

0 commit comments

Comments
 (0)