-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
multi-DB Part 1: create multiple Redis DB instances based on CONFIG at /etc/sonic/database_config.json #2182
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b4a8dfb
update creating multiple db insts
dzhangalibaba c6d47df
update design to allow user to configure database file
dzhangalibaba df4c216
keep database docker entrypoint
dzhangalibaba 91b56de
update supervisord to manage redis-server
dzhangalibaba d8353ed
update redis sock and pid for global access
dzhangalibaba 0cd414b
update non file case
dzhangalibaba 1621bdb
three config file, default one in imaage, running config and user def…
dzhangalibaba a8e69b0
diabled sample config file
dzhangalibaba 1f49cd3
update logic to create multiple DB instances
dzhangalibaba dd2a5ae
remnove unused codes
dzhangalibaba 8894164
update ping pong
dzhangalibaba c63bb64
fix ping redis timing issue
dzhangalibaba 744c21f
using one supervisord.conf and change docker entry point to docker-da…
dzhangalibaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
lguohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"INSTANCES": { | ||
"redis":{ | ||
"port": 6379, | ||
"socket": "/var/run/redis/redis.sock" | ||
} | ||
}, | ||
"DATABASES" : { | ||
"APPL_DB" : { | ||
"id" : 0, | ||
"instance" : "redis" | ||
}, | ||
"ASIC_DB" : { | ||
"id" : 1, | ||
"instance" : "redis" | ||
}, | ||
"COUNTERS_DB" : { | ||
"id" : 2, | ||
"instance" : "redis" | ||
}, | ||
"LOGLEVEL_DB" : { | ||
"id" : 3, | ||
"instance" : "redis" | ||
}, | ||
"CONFIG_DB" : { | ||
"id" : 4, | ||
"instance" : "redis" | ||
}, | ||
"PFC_WD_DB" : { | ||
"id" : 5, | ||
"instance" : "redis" | ||
}, | ||
"FLEX_COUNTER_DB" : { | ||
"id" : 5, | ||
"instance" : "redis" | ||
}, | ||
"STATE_DB" : { | ||
"id" : 6, | ||
"instance" : "redis" | ||
} | ||
}, | ||
"VERSION" : "1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
mkdir -p /var/run/redis/sonic-db | ||
if [ -f /etc/sonic/database_config.json ]; then | ||
cp /etc/sonic/database_config.json /var/run/redis/sonic-db | ||
else | ||
cp /etc/default/sonic-db/database_config.json /var/run/redis/sonic-db | ||
fi | ||
|
||
mkdir -p /etc/supervisor/conf.d/ | ||
# generate all redis server supervisord configuration file | ||
sonic-cfggen -j /var/run/redis/sonic-db/database_config.json -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf | ||
|
||
exec /usr/bin/supervisord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python | ||
import json | ||
import os | ||
import subprocess | ||
import time | ||
import syslog | ||
|
||
def ping_redis(cmd): | ||
output = '' | ||
while True: | ||
try: | ||
output = subprocess.check_output(cmd, shell=True) | ||
except subprocess.CalledProcessError as e: | ||
syslog.syslog(syslog.LOG_ERR, 'ping redis failed, cmd : {}'.format(cmd)) | ||
|
||
if 'PONG' in output: | ||
break | ||
syslog.syslog(syslog.LOG_ERR, 'ping response : {}'.format(output)) | ||
time.sleep(1) | ||
|
||
database_config_file = "/var/run/redis/sonic-db/database_config.json" | ||
|
||
data = {} | ||
while True: | ||
if os.path.isfile(database_config_file): | ||
with open(database_config_file, "r") as read_file: | ||
data = json.load(read_file) | ||
break | ||
time.sleep(1) | ||
syslog.syslog(syslog.LOG_ERR, 'config file {} does not exist right now'.format(database_config_file)) | ||
|
||
while True: | ||
if 'INSTANCES' in data: | ||
for inst in data["INSTANCES"]: | ||
port = data["INSTANCES"][inst]["port"] | ||
cmd = "redis-cli -p " + str(port) + " ping" | ||
ping_redis(cmd) | ||
break | ||
time.sleep(1) | ||
syslog.syslog(syslog.LOG_ERR, 'config file {} does not have INSTANCES'.format(database_config_file)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[supervisord] | ||
logfile_maxbytes=1MB | ||
logfile_backups=2 | ||
nodaemon=true | ||
|
||
[program:rsyslogd] | ||
command=/bin/bash -c "rm -f /var/run/rsyslogd.pid && /usr/sbin/rsyslogd -n" | ||
priority=1 | ||
autostart=true | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
|
||
{% if INSTANCES %} | ||
{% for redis_inst, redis_items in INSTANCES.iteritems() %} | ||
[program: {{ redis_inst }}] | ||
command=/bin/bash -c "{ [[ -s /var/lib/{{ redis_inst }}/dump.rdb ]] || rm -f /var/lib/{{ redis_inst }}/dump.rdb; } && mkdir -p /var/lib/{{ redis_inst }} && exec /usr/bin/redis-server /etc/redis/redis.conf --port {{ redis_items['port'] }} --unixsocket {{ redis_items['socket'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }}" | ||
priority=2 | ||
autostart=true | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
{% endfor %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We prefer keep supervisord as entrypoint. You may refer other docker containers for example with a start.sh. #Closed
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.
if the database_config file is static as you said, then we can use supervisord as Entrypoint, and we can generate supervisord.conf during compiling/building
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.
Keeping supervisord as entrypoint is a good practice. Even with database_config.json, it shall be possilble to generate redis-server.sh from redis-server.sh.j2 within db-docker-init.sh(dockers/docker-database/docker_init.sh), and let redis-server.sh handle the dynamic db instances case?