From 110355201b4db92c12284e25db1b8289fb9c30b6 Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Sat, 3 Nov 2018 12:32:46 -0700 Subject: [PATCH] [swss]: Update swss.sh script to clean up specific db when start (#2223) This script shall not flush all the entries in the state database when it starts up, since there are entries maintained and written by other processes outside this docker. The issue we noticed was that the portchannel states are cleaned up after teamsyncd writes the entries into the database, which causes the IPs failed to be configured because intfmgrd considers the portchannels are not ready yet. Signed-off-by: Shu0T1an ChenG --- files/scripts/swss.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index f7fe1a5510cd..a026ad2f603d 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -62,6 +62,21 @@ function wait_for_database_service() done } +# This function cleans up the tables with specific prefixes from the database +# $1 the index of the database +# $2 the string of a list of table prefixes +function clean_up_tables() +{ + redis-cli -n $1 EVAL " + local tables = {$2} + for i = 1, table.getn(tables) do + local matches = redis.call('KEYS', tables[i]) + for j,name in ipairs(matches) do + redis.call('DEL', name) + end + end" 0 +} + start() { debug "Starting ${SERVICE} service..." @@ -78,7 +93,7 @@ start() { /usr/bin/docker exec database redis-cli -n 0 FLUSHDB /usr/bin/docker exec database redis-cli -n 2 FLUSHDB /usr/bin/docker exec database redis-cli -n 5 FLUSHDB - /usr/bin/docker exec database redis-cli -n 6 FLUSHDB + clean_up_tables 6 "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'WARM_RESTART_TABLE*'" fi # start service docker