@@ -107,6 +107,106 @@ function clean_up_tables()
107
107
end" 0
108
108
}
109
109
110
+ # This function cleans up the chassis db table entries created ONLY by this asic
111
+ # This is used to do the clean up operation when the line card / asic reboots
112
+ # When the asic/lc is RE-booting, the chassis db server is supposed to be running
113
+ # in the supervisor. So the clean up is done when only the chassis db connectable.
114
+ # Otherwise no need to do the clean up since both the supervisor and line card may be
115
+ # rebooting (the whole chassis scenario)
116
+ # The clean up operation is required to delete only those entries created by
117
+ # the asic that is rebooted. Entries from the following tables are deleted in the order
118
+ # given below
119
+ # (1) SYSTEM_NEIGH
120
+ # (2) SYSTEM_INTERFACE
121
+ # (3) SYSTEM_LAG_MEMBER_TABLE
122
+ # (4) SYSTEM_LAG_TABLE
123
+ # (5) The corresponding LAG IDs of the entries from SYSTEM_LAG_TABLE
124
+ # SYSTEM_LAG_ID_TABLE and SYSTEM_LAG_ID_SET are adjusted appropriately
125
+ function clean_up_chassis_db_tables()
126
+ {
127
+ if [[ ! ($( $SONIC_DB_CLI CHASSIS_APP_DB PING | grep -c True) -gt 0) ]]; then
128
+ return
129
+ fi
130
+
131
+ lc=` $SONIC_DB_CLI CONFIG_DB hget ' DEVICE_METADATA|localhost' ' hostname' `
132
+ asic=` $SONIC_DB_CLI CONFIG_DB hget ' DEVICE_METADATA|localhost' ' asic_name' `
133
+ switch_type=` $SONIC_DB_CLI CONFIG_DB hget ' DEVICE_METADATA|localhost' ' switch_type' `
134
+
135
+ # Run clean up only in swss running for voq switches
136
+ if is_chassis_supervisor || [[ $switch_type != ' voq' ]]; then
137
+ return
138
+ fi
139
+
140
+ # First, delete SYSTEM_NEIGH entries
141
+ $SONIC_DB_CLI CHASSIS_APP_DB EVAL "
142
+ local host = string.gsub(ARGV[1], '%-', '%%-')
143
+ local dev = ARGV[2]
144
+ local ps = 'SYSTEM_NEIGH*|' .. host .. '|' .. dev
145
+ local keylist = redis.call('KEYS', 'SYSTEM_NEIGH*')
146
+ for j,key in ipairs(keylist) do
147
+ if string.match(key, ps) ~= nil then
148
+ redis.call('DEL', key)
149
+ end
150
+ end
151
+ return " 0 $lc $asic
152
+
153
+ # Wait for some time before deleting system interface so that the system interface's "object in use"
154
+ # is cleared in both orchangent and in syncd. Without this delay, the orchagent clears the refcount
155
+ # but the syncd (meta) still has no-zero refcount. Because of this, orchagent gets "object still in use"
156
+ # error and aborts.
157
+
158
+ sleep 30
159
+
160
+ # Next, delete SYSTEM_INTERFACE entries
161
+ $SONIC_DB_CLI CHASSIS_APP_DB EVAL "
162
+ local host = string.gsub(ARGV[1], '%-', '%%-')
163
+ local dev = ARGV[2]
164
+ local ps = 'SYSTEM_INTERFACE*|' .. host .. '|' .. dev
165
+ local keylist = redis.call('KEYS', 'SYSTEM_INTERFACE*')
166
+ for j,key in ipairs(keylist) do
167
+ if string.match(key, ps) ~= nil then
168
+ redis.call('DEL', key)
169
+ end
170
+ end
171
+ return " 0 $lc $asic
172
+
173
+ # Next, delete SYSTEM_LAG_MEMBER_TABLE entries
174
+ $SONIC_DB_CLI CHASSIS_APP_DB EVAL "
175
+ local host = string.gsub(ARGV[1], '%-', '%%-')
176
+ local dev = ARGV[2]
177
+ local ps = 'SYSTEM_LAG_MEMBER_TABLE*|' .. host .. '|' .. dev
178
+ local keylist = redis.call('KEYS', 'SYSTEM_LAG_MEMBER_TABLE*')
179
+ for j,key in ipairs(keylist) do
180
+ if string.match(key, ps) ~= nil then
181
+ redis.call('DEL', key)
182
+ end
183
+ end
184
+ return " 0 $lc $asic
185
+
186
+ # Wait for some time before deleting system lag so that the all the memebers of the
187
+ # system lag will be cleared.
188
+
189
+ sleep 15
190
+
191
+ # Finally, delete SYSTEM_LAG_TABLE entries and deallot LAG IDs
192
+ $SONIC_DB_CLI CHASSIS_APP_DB EVAL "
193
+ local host = string.gsub(ARGV[1], '%-', '%%-')
194
+ local dev = ARGV[2]
195
+ local ps = 'SYSTEM_LAG_TABLE*|' .. '(' .. host .. '|' .. dev ..'.*' .. ')'
196
+ local keylist = redis.call('KEYS', 'SYSTEM_LAG_TABLE*')
197
+ for j,key in ipairs(keylist) do
198
+ local lagname = string.match(key, ps)
199
+ if lagname ~= nil then
200
+ redis.call('DEL', key)
201
+ local lagid = redis.call('HGET', 'SYSTEM_LAG_ID_TABLE', lagname)
202
+ redis.call('SREM', 'SYSTEM_LAG_ID_SET', lagid)
203
+ redis.call('HDEL', 'SYSTEM_LAG_ID_TABLE', lagname)
204
+ end
205
+ end
206
+ return " 0 $lc $asic
207
+
208
+ }
209
+
110
210
start_peer_and_dependent_services () {
111
211
check_warm_boot
112
212
@@ -177,6 +277,7 @@ start() {
177
277
$SONIC_DB_CLI RESTAPI_DB FLUSHDB
178
278
clean_up_tables STATE_DB " 'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*', 'FG_ROUTE_TABLE*', 'BUFFER_POOL*', 'BUFFER_PROFILE*', 'MUX_CABLE_TABLE*', 'ADVERTISE_NETWORK_TABLE*', 'VXLAN_TUNNEL_TABLE*', 'MACSEC_PORT_TABLE*', 'MACSEC_INGRESS_SA_TABLE*', 'MACSEC_EGRESS_SA_TABLE*', 'MACSEC_INGRESS_SC_TABLE*', 'MACSEC_EGRESS_SC_TABLE*', 'VRF_OBJECT_TABLE*', 'VNET_MONITOR_TABLE*', 'BFD_SESSION_TABLE*', 'VNET_ROUTE_TUNNEL_TABLE*'"
179
279
$SONIC_DB_CLI APPL_STATE_DB FLUSHDB
280
+ clean_up_chassis_db_tables
180
281
rm -rf /tmp/cache
181
282
fi
182
283
0 commit comments