Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sairedis] Fail get/clear api on objects created in init view mode #930

Merged
merged 2 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ sai_status_t Syncd::processClearStatsEvent(
sai_object_meta_key_t metaKey;
sai_deserialize_object_meta_key(key, metaKey);

if (isInitViewMode() && m_createdInInitView.find(metaKey.objectkey.key.object_id) != m_createdInInitView.end())
{
SWSS_LOG_WARN("CLEAR STATS api can't be used on %s since it's created in INIT_VIEW mode", key.c_str());

sai_status_t status = SAI_STATUS_INVALID_OBJECT_ID;

m_selectableChannel->set(sai_serialize_status(status), {}, REDIS_ASIC_STATE_COMMAND_GETRESPONSE);

return status;
}

if (!m_translator->tryTranslateVidToRid(metaKey))
{
SWSS_LOG_WARN("VID to RID translation failure: %s", key.c_str());
Expand Down Expand Up @@ -675,7 +686,16 @@ sai_status_t Syncd::processGetStatsEvent(
sai_object_meta_key_t metaKey;
sai_deserialize_object_meta_key(key, metaKey);

// TODO get stats on created object in init view mode could fail
if (isInitViewMode() && m_createdInInitView.find(metaKey.objectkey.key.object_id) != m_createdInInitView.end())
{
SWSS_LOG_WARN("GET STATS api can't be used on %s since it's created in INIT_VIEW mode", key.c_str());

sai_status_t status = SAI_STATUS_INVALID_OBJECT_ID;

m_selectableChannel->set(sai_serialize_status(status), {}, REDIS_ASIC_STATE_COMMAND_GETRESPONSE);

return status;
}

m_translator->translateVidToRid(metaKey);

Expand Down Expand Up @@ -867,6 +887,16 @@ sai_status_t Syncd::processBulkQuadEventInInitViewMode(

syncUpdateRedisBulkQuadEvent(api, statuses, objectType, objectIds, strAttributes);

for (auto& str: objectIds)
{
sai_object_id_t objectVid;
sai_deserialize_object_id(str, objectVid);

// in init view mode insert every created object except switch

m_createdInInitView.insert(objectVid);
}

return SAI_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -1471,6 +1501,7 @@ sai_status_t Syncd::processBulkOidCreate(
if (statuses[idx] == SAI_STATUS_SUCCESS)
{
m_translator->insertRidAndVid(objectRids[idx], objectVids[idx]);

SWSS_LOG_INFO("saved VID %s to RID %s",
sai_serialize_object_id(objectVids[idx]).c_str(),
sai_serialize_object_id(objectRids[idx]).c_str());
Expand Down Expand Up @@ -1722,6 +1753,12 @@ sai_status_t Syncd::processQuadInInitViewModeCreate(
{
onSwitchCreateInInitViewMode(objectVid, attr_count, attr_list);
}
else
{
// in init view mode insert every created object except switch

m_createdInInitView.insert(objectVid);
}
}

sendApiResponse(SAI_COMMON_API_CREATE, SAI_STATUS_SUCCESS);
Expand Down Expand Up @@ -1837,6 +1874,19 @@ sai_status_t Syncd::processQuadInInitViewModeGet(
sai_object_id_t objectVid;
sai_deserialize_object_id(strObjectId, objectVid);

if (isInitViewMode() && m_createdInInitView.find(objectVid) != m_createdInInitView.end())
{
SWSS_LOG_WARN("GET api can't be used on %s (%s) since it's created in INIT_VIEW mode",
strObjectId.c_str(),
sai_serialize_object_type(objectType).c_str());

status = SAI_STATUS_INVALID_OBJECT_ID;

sendGetResponse(objectType, strObjectId, switchVid, status, attr_count, attr_list);

return status;
}

switchVid = VidManager::switchIdQuery(objectVid);

SWSS_LOG_DEBUG("generic get (init view) for object type %s:%s",
Expand Down Expand Up @@ -3211,6 +3261,8 @@ sai_status_t Syncd::processNotifySyncd(

clearTempView();

m_createdInInitView.clear();

// NOTE: Currently as WARN to be easier to spot, later should be NOTICE.

SWSS_LOG_WARN("syncd switched to INIT VIEW mode, all op will be saved to TEMP view");
Expand Down Expand Up @@ -3263,6 +3315,8 @@ sai_status_t Syncd::processNotifySyncd(
*/

m_translator->clearLocalCache();

m_createdInInitView.clear();
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions syncd/Syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,7 @@ namespace syncd
std::shared_ptr<BreakConfig> m_breakConfig;

TimerWatchdog m_timerWatchdog;

std::set<sai_object_id_t> m_createdInInitView;
};
}