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

[MultiDB] add mutidb warmboot support - restoring database #5773

Merged
merged 7 commits into from
Dec 10, 2020
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
1 change: 1 addition & 0 deletions dockers/docker-database/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["files/sysctl-net.conf", "/etc/sysctl.d/"]
COPY ["critical_processes", "/etc/supervisor"]
COPY ["files/update_chassisdb_config", "/usr/local/bin/"]
COPY ["flush_unused_database", "/usr/local/bin/"]

ENTRYPOINT ["/usr/local/bin/docker-database-init.sh"]
16 changes: 16 additions & 0 deletions dockers/docker-database/docker-database-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,20 @@ else
fi
rm $db_cfg_file_tmp

# copy dump.rdb file to each instance for restoration
DUMPFILE=/var/lib/redis/dump.rdb
redis_inst_list=`/usr/bin/python -c "import swsssdk; print(' '.join(swsssdk.SonicDBConfig.get_instancelist().keys()))"`
for inst in $redis_inst_list
do
mkdir -p /var/lib/$inst
if [[ -f $DUMPFILE ]]; then
# copy warmboot rdb file into each new instance location
if [[ "$DUMPFILE" != "/var/lib/$inst/dump.rdb" ]]; then
cp $DUMPFILE /var/lib/$inst/dump.rdb
fi
else
echo -n > /var/lib/$inst/dump.rdb
fi
done

exec /usr/local/bin/supervisord
28 changes: 28 additions & 0 deletions dockers/docker-database/flush_unused_database
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python
import swsssdk
import redis
import subprocess
import time

while(True):
output = subprocess.Popen(['sonic-db-cli', 'PING'], stdout=subprocess.PIPE).communicate()[0]
if 'PONG' in output:
break
time.sleep(1)
dzhangalibaba marked this conversation as resolved.
Show resolved Hide resolved

instlists = swsssdk.SonicDBConfig.get_instancelist()
for instname, v in instlists.items():
insthost = v['hostname']
instsocket = v['unix_socket_path']

dblists = swsssdk.SonicDBConfig.get_dblist()
for dbname in dblists:
dbid = swsssdk.SonicDBConfig.get_dbid(dbname)
dbinst = swsssdk.SonicDBConfig.get_instancename(dbname)

# this DB is on current instance, skip flush
if dbinst == instname:
continue

r = redis.Redis(host=insthost, unix_socket_path=instsocket, db=dbid)
r.flushdb()
8 changes: 8 additions & 0 deletions dockers/docker-database/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ stdout_logfile=syslog
stderr_logfile=syslog
{% endfor %}
{% endif %}

[program:flushdb]
dzhangalibaba marked this conversation as resolved.
Show resolved Hide resolved
command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database"
priority=3
autostart=true
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog