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

Enable Multi DB #20305

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aaefb71
Updated supervisord.conf.j2 to support multidb
Pan-XT Aug 30, 2024
c5c3e59
Merge branch 'multidb' of https://github.com/Pan-XT/sonic-buildimage …
Pan-XT Aug 30, 2024
289f8e6
chown redis
Pan-XT Aug 31, 2024
f51867e
update multi db json.j2
Pan-XT Sep 1, 2024
42fc418
[sonic-swss] update submodule for sonic-swss
Pan-XT Sep 1, 2024
67a9804
Updated docker-database-init.sh to support multidb
Pan-XT Sep 1, 2024
4c6527e
update multi_database_config.json.j2
Pan-XT Sep 1, 2024
46939a0
update docker-database-init.sh
Pan-XT Sep 1, 2024
5b3c458
update multi_database_config.json
Pan-XT Sep 5, 2024
2bc006a
update critical_processes.j2
Pan-XT Sep 5, 2024
614bb83
update docker-database-init.sh
Pan-XT Sep 5, 2024
e42bfc3
update docker-database-init.sh
Pan-XT Sep 6, 2024
f51eedb
update docker-database-init.sh
Pan-XT Sep 11, 2024
2b121de
update docker-database-init.sh
Pan-XT Sep 19, 2024
397c6fa
Enable Multi DB
Pan-XT Sep 23, 2024
81fdc48
Revert changes to src/sonic-swss
Pan-XT Sep 24, 2024
a220f2c
enable multi db for cisco-8101-p4-32x100-vs
Pan-XT Sep 26, 2024
e53cc25
Set ENABLE_MULTIDB=y when building SONiC image and enable Multidb dep…
Pan-XT Oct 9, 2024
87aab3e
update sonic_debian_extension.j2
Pan-XT Oct 10, 2024
b158823
Merge branch 'sonic-net:master' into multidb
Pan-XT Oct 11, 2024
8c942d6
remove "bind": "240.1.1.2 127.0.0.1"
Pan-XT Oct 23, 2024
bffe653
Merge branch 'multidb' of https://github.com/Pan-XT/sonic-buildimage …
Pan-XT Oct 23, 2024
96b9d14
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Oct 23, 2024
025031b
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Oct 23, 2024
c4cf9c3
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 1, 2024
5981cb4
update docker-database-init.sh
Pan-XT Nov 1, 2024
67c4798
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 1, 2024
1743065
chmod -f 0760 $sock_file
Pan-XT Nov 1, 2024
ca52619
update docker-database-init.sh
Pan-XT Nov 1, 2024
43869e1
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 1, 2024
43bcec0
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 4, 2024
8c5405e
update docker-database-init.sh
Pan-XT Nov 4, 2024
2185014
update docker-databse-init.sh
Pan-XT Nov 4, 2024
b854771
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 4, 2024
5c98f54
chmod -f 0760 $sock_file
Pan-XT Nov 4, 2024
26d834c
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 6, 2024
2f7eda0
going down for new redis instances
Pan-XT Nov 6, 2024
3b30645
revert changes to supervisord.conf.j2
Pan-XT Nov 6, 2024
f402859
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 7, 2024
55808b5
add comments on chown -R redis:redis /var/lib/$inst
Pan-XT Nov 7, 2024
90ace92
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 7, 2024
de605aa
Merge branch 'master' of https://github.com/sonic-net/sonic-buildimag…
Pan-XT Nov 8, 2024
f947e14
change {%- endfor %} to {% endfor %} in critical_processes.j2
Pan-XT Nov 8, 2024
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
4 changes: 4 additions & 0 deletions Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
# * SONIC_PTF_ENV_PY_VER: Python version for PTF image
# * Default: mixed
# * Values: mixed,py3
# * ENABLE_MULTIDB: Enable multiple redis database instances.
# * Default: unset
# * Values: y
###############################################################################

SHELL = /bin/bash
Expand Down Expand Up @@ -570,6 +573,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
BUILD_PROCESS_TIMEOUT=$(BUILD_PROCESS_TIMEOUT) \
LEGACY_SONIC_MGMT_DOCKER=$(LEGACY_SONIC_MGMT_DOCKER) \
SONIC_PTF_ENV_PY_VER=$(SONIC_PTF_ENV_PY_VER) \
ENABLE_MULTIDB=$(ENABLE_MULTIDB) \
$(SONIC_OVERRIDE_BUILD_VARS)

.PHONY: sonic-slave-build sonic-slave-bash init reset
Expand Down
1 change: 1 addition & 0 deletions dockers/docker-database/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["files/sysctl-net.conf", "/etc/sysctl.d/"]
COPY ["files/update_chassisdb_config", "/usr/local/bin/"]
COPY ["flush_unused_database", "/usr/local/bin/"]
COPY ["multi_database_config.json.j2", "/usr/share/sonic/templates/"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pan-XT Could you upload a write-up for this multi-DB including the current issues and usage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed


ENTRYPOINT ["/usr/local/bin/docker-database-init.sh"]
1 change: 1 addition & 0 deletions dockers/docker-database/critical_processes.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% if INSTANCES %}
{% for redis_inst, redis_items in INSTANCES.items() %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this unnecessary change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no blank line here, all program:{{ redis_inst }} of critical_processes will be concentrated on one line, which will cause subsequent regular expression matching to fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does changing {%- endfor %} to {% endfor %} work? That will make the intention a bit clearer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing {%- endfor %} to {% endfor %} works. I apply this change instead of adding blank line.

program:{{ redis_inst }}
{%- endfor %}
{%- endif %}
12 changes: 11 additions & 1 deletion dockers/docker-database/docker-database-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ mkdir -p /etc/supervisor/conf.d/
if [ -f /etc/sonic/database_config$NAMESPACE_ID.json ]; then
cp /etc/sonic/database_config$NAMESPACE_ID.json $REDIS_DIR/sonic-db/database_config.json
else
HOST_IP=$host_ip REDIS_PORT=$redis_port DATABASE_TYPE=$DATABASE_TYPE BMP_DB_PORT=$BMP_DB_PORT j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
if [ -f /etc/sonic/enable_multidb ]; then
HOST_IP=$host_ip REDIS_PORT=$redis_port DATABASE_TYPE=$DATABASE_TYPE BMP_DB_PORT=$BMP_DB_PORT j2 /usr/share/sonic/templates/multi_database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
else
HOST_IP=$host_ip REDIS_PORT=$redis_port DATABASE_TYPE=$DATABASE_TYPE BMP_DB_PORT=$BMP_DB_PORT j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pan-XT any sonic-mgmt tests for multi DB?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fi

# on VoQ system, we only publish redis_chassis instance and CHASSIS_APP_DB when
Expand Down Expand Up @@ -125,6 +129,12 @@ do
else
echo -n > /var/lib/$inst/dump.rdb
fi

chown -R redis:redis /var/lib/$inst
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments to this file, help other understand.
Also, this seems not related with enable multi-DB, can this move to another PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the necessary permissions for enable_multidb, see /etc/supervisor/conf.d/supervisord.conf.j2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Pan-XT , can you add your comments to this file? that will help other understand the propose of this code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,I add commnets “the Redis process is operating under the 'redis' user in supervisord and make redis user own /var/lib/$inst inside db container.”

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed

sock_file="$REDIS_DIR/$inst.sock"
if [[ -f $sock_file ]]; then
chgrp -f redis $sock_file && chmod -f 0760 $sock_file
fi
done

TZ=$(cat /etc/timezone)
Expand Down
192 changes: 192 additions & 0 deletions dockers/docker-database/multi_database_config.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{% set include_remote_db = (REMOTE_DB_IP is defined and REMOTE_DB_PORT is defined) %}
{
"INSTANCES": {
"redis":{
"hostname" : "{{HOST_IP}}",
"port" : {{REDIS_PORT}},
"unix_socket_path" : "/var/run/redis{{DEV}}/redis.sock",
"persistence_for_warm_boot" : "yes"
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
,"database_type": "{{DATABASE_TYPE}}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find code in sonic-swss-common to parse and handle 'database_type', is there a PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I search that PR, not find any code read "database_type"
This attribute is an optional attribute, and this file need be parsed by SonicDBConfig::parseDatabaseConfig
https://github.com/sonic-net/sonic-swss-common/blob/master/common/dbconnector.cpp

Otherwise, sonic-swss-common lib can't handle multi-DB, so please make sure sonic-swss-common also change to handle it.

Copy link
Author

@Pan-XT Pan-XT Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liuh-80

This field was added via
9f08f88
by @Pterosaur

It is current SONiC behavior
https://github.com/sonic-net/sonic-buildimage/blob/master/dockers/docker-database/database_config.json.j2#L10

Can you help to check with him to see what the need for this field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed, I will offline sync with Ze

{% endif %}
},
"redis1": {
"hostname" : "{{HOST_IP}}",
"port" : 6380,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The port selection conflicts with both the chassis DB and Smart Switch DB service and must be changed. Port 6380 is used by the chassis Redis server, while ports 6381-6388 are assigned to the DPU databases.

Copy link
Collaborator

@eddieruan-alibaba eddieruan-alibaba Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oleksandrivantsiv where does chassis DB's port get defined?

This multi-db approach is enabled only on the platform which needs performance and controlled via a compile flag. ENABLE_MULTIDB=y The detail information could be found at https://lists.sonicfoundation.dev/g/sonic-wg-routing/wiki/37961

During the discussion in routing WG, we feel there is NO use case to enable it for chassis based platform for the following reasons.

  1. The scale for chassis based approach is limited. MSFT uses it as T1, and Alibaba uses it as gateway. The benefit is less.
  2. Even chassis case wants to use it later. It may only wants to enable it for main switch asic, not enable all 5 for each DPU. That means we need to create a new j2 for that case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with Guahan on this one. 6380 will be kept for Chassis DB. It is not easy to change chassis's port number.

We use 6379, 6378, 6377, ... a.k.a going down for new redis instances.

@Pan-XT can you update your diff?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update redis1,reids2,redis3,redis4 port number to 6378,6377,6376,6375

"unix_socket_path" : "/var/run/redis{{DEV}}/redis1.sock",
"persistence_for_warm_boot" : "yes"
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
,"database_type": "{{DATABASE_TYPE}}"
{% endif %}
},
"redis2": {
"hostname" : "{{HOST_IP}}",
"port" : 6381,
"unix_socket_path" : "/var/run/redis{{DEV}}/redis2.sock",
"persistence_for_warm_boot" : "yes"
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
,"database_type": "{{DATABASE_TYPE}}"
{% endif %}
},
"redis3": {
"hostname" : "{{HOST_IP}}",
"port" : 6382,
"unix_socket_path" : "/var/run/redis{{DEV}}/redis3.sock",
"persistence_for_warm_boot" : "yes"
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
,"database_type": "{{DATABASE_TYPE}}"
{% endif %}
},
"redis4": {
"hostname" : "{{HOST_IP}}",
"port" : 6383,
"unix_socket_path" : "/var/run/redis{{DEV}}/redis4.sock",
"persistence_for_warm_boot" : "yes"
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
,"database_type": "{{DATABASE_TYPE}}"
{% endif %}
},
"redis_chassis":{
"hostname" : "redis_chassis.server",
"port": 6380,
"unix_socket_path": "/var/run/redis-chassis/redis_chassis.sock",
"persistence_for_warm_boot" : "yes"
}
{% if include_remote_db %}
,"remote_redis":{
"hostname" : "{{REMOTE_DB_IP}}",
"port" : {{REMOTE_DB_PORT}},
"unix_socket_path": "",
"persistence_for_warm_boot" : "yes"
}
{% endif %},
"redis_bmp":{
"hostname" : "{{HOST_IP}}",
"port" : {{BMP_DB_PORT}},
"unix_socket_path" : "/var/run/redis{{DEV}}/redis_bmp.sock",
"persistence_for_warm_boot" : "yes"
}
},
"DATABASES" : {
"APPL_DB": {
"id": 0,
"separator": ":",
"instance": "redis1"
},
"ASIC_DB": {
"id": 1,
"separator": ":",
"instance": "redis2"
},
"COUNTERS_DB": {
"id": 2,
"separator": ":",
"instance": "redis3"
},
"LOGLEVEL_DB": {
"id": 3,
"separator": ":",
"instance": "redis"
},
"CONFIG_DB": {
"id": 4,
"separator": "|",
"instance": "redis"
},
"PFC_WD_DB": {
"id": 5,
"separator": ":",
"instance": "redis3"
},
"FLEX_COUNTER_DB": {
"id": 5,
"separator": ":",
"instance": "redis3"
},
"STATE_DB": {
"id": 6,
"separator": "|",
"instance": "redis"
},
"SNMP_OVERLAY_DB": {
"id": 7,
"separator": "|",
"instance": "redis"
},
"SYSMON_DB": {
"id": 10,
"separator": "|",
"instance": "redis"
},
"BMC_DB": {
"id": 12,
"separator": ":",
"instance": "redis4"
},
"RESTAPI_DB": {
"id": 8,
"separator": "|",
"instance": "redis"
},
"GB_ASIC_DB": {
"id": 9,
"separator": ":",
"instance": "redis"
},
"GB_COUNTERS_DB": {
"id": 10,
"separator": ":",
"instance": "redis"
},
"GB_FLEX_COUNTER_DB": {
"id": 11,
"separator": ":",
"instance": "redis"
},
"APPL_STATE_DB": {
"id": 14,
"separator": ":",
"instance": "redis"
},
"CHASSIS_APP_DB" : {
"id" : 12,
"separator": "|",
"instance" : "redis_chassis"
},
"CHASSIS_STATE_DB" : {
"id" : 13,
"separator": "|",
"instance" : "redis_chassis"
}
{% if DATABASE_TYPE is defined and DATABASE_TYPE == "dpudb" %}
,
"DPU_APPL_DB" : {
"id" : 15,
"separator": ":",
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest define a variable for all these dupe template

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the multi_database_config.json.j2 is consistent with the database_config.json.j2, except for the added content related to redis1,redis2,redis3,redis4. Defining a variable for all these dupe templates will be implemented in future modifications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed

"format": "proto"
},
"DPU_APPL_STATE_DB" : {
"id" : 16,
"separator": "|",
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
},
"DPU_STATE_DB" : {
"id" : 17,
"separator": "|",
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
},
"DPU_COUNTERS_DB" : {
"id" : 18,
"separator": ":",
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
}
{% endif %},
"BMP_STATE_DB" : {
"id" : 20,
"separator": "|",
"instance" : "redis_bmp"
}
},
"VERSION" : "1.0"
}
3 changes: 3 additions & 0 deletions dockers/docker-database/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependent_startup=true
{% if INSTANCES %}
{% for redis_inst, redis_items in INSTANCES.items() %}
{%- if redis_inst != 'remote_redis' %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest remove unnecessary change in this file

Copy link
Author

@Pan-XT Pan-XT Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is the same as #20545 , so I remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed


[program:{{ redis_inst }}]
{% if redis_items['hostname'] != '127.0.0.1' %}
{%- set ADDITIONAL_OPTS = '--protected-mode no' %}
Expand All @@ -53,6 +55,7 @@ stderr_logfile=syslog
{% endfor %}
{% endif %}


[program:flushdb]
command=/bin/bash -c "sleep 300 && /usr/local/bin/flush_unused_database"
priority=3
Expand Down
5 changes: 5 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -1153,3 +1153,8 @@ sudo rm -rf $FILESYSTEM_ROOT/tmp/mask_disabled_services.py


sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install python3-dbus

## Enable MULTIDB
{% if ENABLE_MULTIDB == "y" %}
sudo touch $FILESYSTEM_ROOT_ETC_SONIC/enable_multidb
{% endif %}
2 changes: 2 additions & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ $(info "CROSS_BUILD_ENVIRON" : "$(CROSS_BUILD_ENVIRON)")
$(info "LEGACY_SONIC_MGMT_DOCKER" : "$(LEGACY_SONIC_MGMT_DOCKER)")
$(info "INCLUDE_EXTERNAL_PATCHES" : "$(INCLUDE_EXTERNAL_PATCHES)")
$(info "PTF_ENV_PY_VER" : "$(PTF_ENV_PY_VER)")
$(info "ENABLE_MULTIDB" : "$(ENABLE_MULTIDB)")
$(info )
else
$(info SONiC Build System for $(CONFIGURED_PLATFORM):$(CONFIGURED_ARCH))
Expand Down Expand Up @@ -1492,6 +1493,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
export include_mux="$(INCLUDE_MUX)"
export include_bootchart="$(INCLUDE_BOOTCHART)"
export enable_bootchart="$(ENABLE_BOOTCHART)"
export enable_multidb="$(ENABLE_MULTIDB)"
$(foreach docker, $($*_DOCKERS),\
export docker_image="$(docker)"
export docker_image_name="$(basename $(docker))"
Expand Down
Loading