-
Notifications
You must be signed in to change notification settings - Fork 520
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
[Chassis][LAG_ID] Address the same lagid been used in two different LCs issue #3303
base: master
Are you sure you want to change the base?
Changes from 3 commits
2c4f2f9
509c5d0
e9938d5
c64dbf1
4a0e6f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,28 +37,48 @@ if op == "add" then | |
end | ||
-- proposed lag id is different than that in database OR | ||
-- the portchannel does not exist in the database | ||
-- If proposed lagid is available, return the same proposed lag id | ||
if redis.call("sismember", "SYSTEM_LAG_ID_SET", tostring(plagid)) == 0 then | ||
redis.call("sadd", "SYSTEM_LAG_ID_SET", tostring(plagid)) | ||
redis.call("srem", "SYSTEM_LAG_ID_SET", tostring(dblagid)) | ||
-- If proposed lagid is not available, lpop the first availabe ID | ||
local index = redis.call("lpos", "SYSTEM_LAG_IDS_FREE_LIST", tostring(plagid)) | ||
if index == false then | ||
if redis.call("llen", "SYSTEM_LAG_IDS_FREE_LIST") <= 0 then | ||
return -1 | ||
end | ||
local lagid = redis.call("lpop", "SYSTEM_LAG_IDS_FREE_LIST") | ||
redis.call("hset", "SYSTEM_LAG_ID_TABLE", pcname, lagid) | ||
redis.call("sadd", "SYSTEM_LAG_ID_SET", lagid) | ||
if dblagid then | ||
redis.call("srem", "SYSTEM_LAG_ID_SET", tostring(dblagid)) | ||
if redis.call("lpos", "SYSTEM_LAG_IDS_FREE_LIST", tostring(dblagid)) == false then | ||
redis.call("rpush", "SYSTEM_LAG_IDS_FREE_LIST", tostring(dblagid)) | ||
end | ||
end | ||
return tonumber(lagid) | ||
else | ||
redis.call("lrem", "SYSTEM_LAG_IDS_FREE_LIST", 1, tostring(plagid)) | ||
redis.call("hset", "SYSTEM_LAG_ID_TABLE", pcname, tostring(plagid)) | ||
redis.call("sadd", "SYSTEM_LAG_ID_SET", tostring(plagid)) | ||
if dblagid then | ||
redis.call("srem", "SYSTEM_LAG_ID_SET", tostring(dblagid)) | ||
if redis.call("lpos", "SYSTEM_LAG_IDS_FREE_LIST", tostring(dblagid)) == false then | ||
redis.call("rpush", "SYSTEM_LAG_IDS_FREE_LIST", tostring(dblagid)) | ||
end | ||
end | ||
return plagid | ||
end | ||
end | ||
|
||
local lagid = lagid_start | ||
while lagid <= lagid_end do | ||
if redis.call("sismember", "SYSTEM_LAG_ID_SET", tostring(lagid)) == 0 then | ||
redis.call("sadd", "SYSTEM_LAG_ID_SET", tostring(lagid)) | ||
redis.call("srem", "SYSTEM_LAG_ID_SET", tostring(dblagid)) | ||
redis.call("hset", "SYSTEM_LAG_ID_TABLE", pcname, tostring(lagid)) | ||
return lagid | ||
else | ||
if redis.call("llen", "SYSTEM_LAG_IDS_FREE_LIST") <= 0 then | ||
return -1 | ||
end | ||
lagid = lagid + 1 | ||
local lagid = redis.call("lpop", "SYSTEM_LAG_IDS_FREE_LIST") | ||
redis.call("hset", "SYSTEM_LAG_ID_TABLE", pcname, lagid) | ||
redis.call("sadd", "SYSTEM_LAG_ID_SET", lagid) | ||
if dblagid then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use dblag here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is just for handling the out of sync cases. As normal operation, this should not happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should do
here too ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. In case of the old lagId (dblagid) still in the SYSTEM_LAG_ID_SET in a broken scenario, we just remove it. Anyway, this SYSTEM_LAG_ID_SET is just keeped for debugging purposes. We don't use it for any functionality. SYSTEM_LAG_ID_SET and SYSTM_LAG_IDS_FREE_LIST are mutual exclusive. |
||
if redis.call("lpos", "SYSTEM_LAG_IDS_FREE_LIST", tostring(dblagid)) == false then | ||
redis.call("rpush", "SYSTEM_LAG_IDS_FREE_LIST", tostring(dblagid)) | ||
end | ||
end | ||
return tonumber(lagid) | ||
end | ||
|
||
return -1 | ||
|
||
end | ||
|
||
if op == "del" then | ||
|
@@ -67,6 +87,9 @@ if op == "del" then | |
local lagid = redis.call("hget", "SYSTEM_LAG_ID_TABLE", pcname) | ||
redis.call("srem", "SYSTEM_LAG_ID_SET", lagid) | ||
redis.call("hdel", "SYSTEM_LAG_ID_TABLE", pcname) | ||
if redis.call("lpos", "SYSTEM_LAG_IDS_FREE_LIST", lagid) == false then | ||
redis.call("rpush", "SYSTEM_LAG_IDS_FREE_LIST", lagid) | ||
end | ||
return tonumber(lagid) | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code under "if dblagid then" is duplicated in both if and else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are the same in the if and else. Not able to simplify them in one because of "if" case returns "tonumber(lagid)" while the "else" case returns "plagid"