From a435bbb0863fbe20a4204ba27ba62ac358b8e7d1 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 20 May 2024 08:07:51 +0000 Subject: [PATCH 01/12] Add new redis database instance for BMP_STATE_DB. --- dockers/docker-database/database_config.json.j2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dockers/docker-database/database_config.json.j2 b/dockers/docker-database/database_config.json.j2 index b5c231a93f41..a8c8db3e2564 100644 --- a/dockers/docker-database/database_config.json.j2 +++ b/dockers/docker-database/database_config.json.j2 @@ -130,6 +130,12 @@ "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %} } {% endif %} + , + "BMP_STATE_DB" : { + "id" : 19, + "separator": "|", + "instance" : "redis" + } }, "VERSION" : "1.0" } From f7a26c87393322143d088ceaffbd4d17ae6a0cea Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 20 May 2024 08:07:51 +0000 Subject: [PATCH 02/12] Add new redis database instance for BMP_STATE_DB. --- dockers/docker-database/database_config.json.j2 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dockers/docker-database/database_config.json.j2 b/dockers/docker-database/database_config.json.j2 index b5c231a93f41..1398cd2be3a0 100644 --- a/dockers/docker-database/database_config.json.j2 +++ b/dockers/docker-database/database_config.json.j2 @@ -24,6 +24,12 @@ "persistence_for_warm_boot" : "yes" } {% endif %} + ,"redis_bmp":{ + "hostname" : "redis_bmp.server", + "port": 6399, + "unix_socket_path": "/var/run/redis-chassis/redis_bmp.sock", + "persistence_for_warm_boot" : "yes" + } }, "DATABASES" : { "APPL_DB" : { @@ -130,6 +136,12 @@ "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %} } {% endif %} + , + "BMP_STATE_DB" : { + "id" : 19, + "separator": "|", + "instance" : "redis" + } }, "VERSION" : "1.0" } From fbd913b54a3df34957b7b9de81aadd04328a1c16 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 9 Sep 2024 07:54:35 +0000 Subject: [PATCH 03/12] Update code --- dockers/docker-database/database_config.json.j2 | 9 ++++----- rules/docker-restapi.mk | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dockers/docker-database/database_config.json.j2 b/dockers/docker-database/database_config.json.j2 index 399ad30c77f8..f37b64ee9665 100644 --- a/dockers/docker-database/database_config.json.j2 +++ b/dockers/docker-database/database_config.json.j2 @@ -23,11 +23,11 @@ "unix_socket_path": "", "persistence_for_warm_boot" : "yes" } -{% endif %} - ,"redis_bmp":{ +{% endif %}, + "redis_bmp":{ "hostname" : "{{HOST_IP}}", "port" : {{BMP_DB_PORT}}, - "unix_socket_path" : "/var/run/redis/redis_bmp.sock", + "unix_socket_path" : "/var/run/redis{{DEV}}/redis_bmp.sock", "persistence_for_warm_boot" : "yes" } }, @@ -135,8 +135,7 @@ "separator": ":", "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %} } -{% endif %} - , +{% endif %}, "BMP_STATE_DB" : { "id" : 20, "separator": "|", diff --git a/rules/docker-restapi.mk b/rules/docker-restapi.mk index 5cc515a5991b..0fb8e19d5c92 100644 --- a/rules/docker-restapi.mk +++ b/rules/docker-restapi.mk @@ -29,7 +29,6 @@ endif $(DOCKER_RESTAPI)_CONTAINER_NAME = restapi $(DOCKER_RESTAPI)_RUN_OPT += -t $(DOCKER_RESTAPI)_RUN_OPT += -v /var/run/redis/redis.sock:/var/run/redis/redis.sock -$(DOCKER_RESTAPI)_RUN_OPT += -v /var/run/redis/redis_bmp.sock:/var/run/redis/redis_bmp.sock $(DOCKER_RESTAPI)_RUN_OPT += -v /etc/sonic/credentials:/etc/sonic/credentials:ro $(DOCKER_RESTAPI)_RUN_OPT += -p=8081:8081/tcp From fdf1908b622c9c4642e272d0470fb662f3de0b04 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Fri, 27 Sep 2024 14:22:25 +0000 Subject: [PATCH 04/12] Fix supervisord.conf issue --- dockers/docker-database/supervisord.conf.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index 232b8ffcbfa7..226b58998b12 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -48,6 +48,7 @@ autostart=true autorestart=false stdout_logfile=syslog stderr_logfile=syslog + {%- endif -%} {% endfor %} {% endif %} From 345efba1866b5742b0731117e12daad9fa852f52 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Fri, 27 Sep 2024 14:22:25 +0000 Subject: [PATCH 05/12] Fix supervisord.conf issue --- dockers/docker-database/supervisord.conf.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index 232b8ffcbfa7..f2fdffd2677d 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -48,7 +48,8 @@ autostart=true autorestart=false stdout_logfile=syslog stderr_logfile=syslog -{%- endif -%} + +{% endif %} {% endfor %} {% endif %} From 26b1ae9aa602804416ffa0dabb3c7588cb5a4b49 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Mon, 30 Sep 2024 16:59:01 +0000 Subject: [PATCH 06/12] Fix supervisord.conf.j2 issue --- dockers/docker-database/supervisord.conf.j2 | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index 0800e1ddff31..3c27415fcb0c 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -28,8 +28,18 @@ stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true +[program:flushdb] +command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database" +priority=2 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running + {% if INSTANCES %} -{% for redis_inst, redis_items in INSTANCES.items() %} +{% for index, (redis_inst, redis_items) in enumerate(INSTANCES.items()) %} {%- if redis_inst != 'remote_redis' %} [program:{{ redis_inst }}] {% if redis_items['hostname'] != '127.0.0.1' %} @@ -42,23 +52,13 @@ dependent_startup=true {%- set ADDITIONAL_OPTS = '' %} {%- endif -%} 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 --bind {{ LOOPBACK_IP }} {{ redis_items['hostname'] }} --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }} {{ ADDITIONAL_OPTS }}" -priority=2 +priority={{ index + 3 }} user=redis autostart=true autorestart=false stdout_logfile=syslog stderr_logfile=syslog -{% endif -%} +{% endif %} {% endfor %} {% endif %} - -[program:flushdb] -command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database" -priority=3 -autostart=false -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for=rsyslogd:running From 0f6b846b05eac20499ac7228e0d63680a479a97f Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Tue, 8 Oct 2024 08:29:13 +0000 Subject: [PATCH 07/12] Fix priority issue --- dockers/docker-database/supervisord.conf.j2 | 30 +++++++++------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index 3c27415fcb0c..0835e5c8d14e 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -28,31 +28,15 @@ stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -[program:flushdb] -command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database" -priority=2 -autostart=false -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for=rsyslogd:running - {% if INSTANCES %} -{% for index, (redis_inst, redis_items) in enumerate(INSTANCES.items()) %} +{% for redis_inst, redis_items in INSTANCES.items() %} {%- if redis_inst != 'remote_redis' %} [program:{{ redis_inst }}] {% if redis_items['hostname'] != '127.0.0.1' %} -{%- set ADDITIONAL_OPTS = '--protected-mode no' %} -{%- if redis_inst != 'redis_chassis' %} -{%- set LOOPBACK_IP = '127.0.0.1' -%} -{%- endif -%} -{%- else -%} -{%- set LOOPBACK_IP = '' -%} + @@ -42,22 +52,13 @@ dependent_startup=true {%- set ADDITIONAL_OPTS = '' %} {%- endif -%} 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 --bind {{ LOOPBACK_IP }} {{ redis_items['hostname'] }} --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }} {{ ADDITIONAL_OPTS }}" -priority={{ index + 3 }} user=redis autostart=true autorestart=false @@ -62,3 +46,13 @@ stderr_logfile=syslog {% endif %} {% endfor %} {% endif %} + +[program:flushdb] +command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database" +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running \ No newline at end of file From cfdd2117388eec41cf92a0b71f36e4a527780879 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Tue, 8 Oct 2024 08:29:13 +0000 Subject: [PATCH 08/12] Fix priority issue --- dockers/docker-database/supervisord.conf.j2 | 23 ++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index 3c27415fcb0c..d7363e2e19d1 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -28,18 +28,8 @@ stdout_logfile=syslog stderr_logfile=syslog dependent_startup=true -[program:flushdb] -command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database" -priority=2 -autostart=false -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for=rsyslogd:running - {% if INSTANCES %} -{% for index, (redis_inst, redis_items) in enumerate(INSTANCES.items()) %} +{% for redis_inst, redis_items in INSTANCES.items() %} {%- if redis_inst != 'remote_redis' %} [program:{{ redis_inst }}] {% if redis_items['hostname'] != '127.0.0.1' %} @@ -52,7 +42,6 @@ dependent_startup_wait_for=rsyslogd:running {%- set ADDITIONAL_OPTS = '' %} {%- endif -%} 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 --bind {{ LOOPBACK_IP }} {{ redis_items['hostname'] }} --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }} {{ ADDITIONAL_OPTS }}" -priority={{ index + 3 }} user=redis autostart=true autorestart=false @@ -62,3 +51,13 @@ stderr_logfile=syslog {% endif %} {% endfor %} {% endif %} + +[program:flushdb] +command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database" +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running \ No newline at end of file From 827bbf732fd3eafa91fc9ddd770cc667f16a74af Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Wed, 9 Oct 2024 08:27:30 +0000 Subject: [PATCH 09/12] Fix permission issue --- dockers/docker-database/docker-database-init.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dockers/docker-database/docker-database-init.sh b/dockers/docker-database/docker-database-init.sh index 7bcb2143df7d..c50add1a7698 100755 --- a/dockers/docker-database/docker-database-init.sh +++ b/dockers/docker-database/docker-database-init.sh @@ -132,5 +132,7 @@ rm -rf /etc/localtime ln -sf /usr/share/zoneinfo/$TZ /etc/localtime chown -R redis:redis $REDIS_DIR +REDIS_BMP_DIR="/var/lib/redis_bmp" +chown -R redis:redis $REDIS_BMP_DIR exec /usr/local/bin/supervisord From fac649322a39d3d94676923bbf4c9f4872a454f7 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Wed, 9 Oct 2024 13:54:06 +0000 Subject: [PATCH 10/12] Address comment --- platform/vs/docker-sonic-vs/database_config.json | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/platform/vs/docker-sonic-vs/database_config.json b/platform/vs/docker-sonic-vs/database_config.json index da7c27dca892..04cb3d3aaaec 100644 --- a/platform/vs/docker-sonic-vs/database_config.json +++ b/platform/vs/docker-sonic-vs/database_config.json @@ -11,11 +11,6 @@ "port": 6380, "unix_socket_path": "/var/run/redis/redis_chassis.sock" } - ,"redis_bmp":{ - "hostname" : "127.0.0.1", - "port" : 6400, - "unix_socket_path" : "/var/run/redis/redis_bmp.sock" - } }, "DATABASES" : { "APPL_DB" : { @@ -82,11 +77,6 @@ "id" : 14, "separator": ":", "instance" : "redis" - }, - "BMP_STATE_DB" : { - "id" : 20, - "separator": "|", - "instance" : "redis_bmp" } }, "VERSION" : "1.0" From 35fc7622eafc3e3d6d0b4edbadacb8d461227f68 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Tue, 15 Oct 2024 08:17:14 +0000 Subject: [PATCH 11/12] Address comments --- dockers/docker-database/supervisord.conf.j2 | 1 + files/build_templates/docker_image_ctl.j2 | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index aaf1fabff2a2..f2fdffd2677d 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -42,6 +42,7 @@ dependent_startup=true {%- set ADDITIONAL_OPTS = '' %} {%- endif -%} 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 --bind {{ LOOPBACK_IP }} {{ redis_items['hostname'] }} --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }} {{ ADDITIONAL_OPTS }}" +priority=2 user=redis autostart=true autorestart=false diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index b38f8d30fe2a..f1757f69ba42 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -90,7 +90,6 @@ function preStartAction() if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast" || "$BOOT_TYPE" == "fast") && -f $WARM_DIR/dump.rdb ]]; then # Load redis content from /host/warmboot/dump.rdb docker cp $WARM_DIR/dump.rdb database$DEV:/var/lib/redis/dump.rdb - docker cp $WARM_DIR/dump.rdb database$DEV:/var/lib/redis_bmp/dump.rdb else # Create an emtpy file and overwrite any RDB if already there echo -n > /tmp/dump.rdb From 45ca700edf8709dfdec32a58fb7c246c770ff9f4 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Fri, 18 Oct 2024 23:52:21 +0000 Subject: [PATCH 12/12] Use separate PR for fixing multiple instance issue --- dockers/docker-database/supervisord.conf.j2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dockers/docker-database/supervisord.conf.j2 b/dockers/docker-database/supervisord.conf.j2 index f2fdffd2677d..232b8ffcbfa7 100644 --- a/dockers/docker-database/supervisord.conf.j2 +++ b/dockers/docker-database/supervisord.conf.j2 @@ -48,8 +48,7 @@ autostart=true autorestart=false stdout_logfile=syslog stderr_logfile=syslog - -{% endif %} +{%- endif -%} {% endfor %} {% endif %}