diff --git a/Makefile.work b/Makefile.work index e6cddad289b9..2d52f16e1fd1 100644 --- a/Makefile.work +++ b/Makefile.work @@ -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 @@ -571,6 +574,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 diff --git a/dockers/docker-database/Dockerfile.j2 b/dockers/docker-database/Dockerfile.j2 index 6f39d0ac5f58..d9ba01360b30 100644 --- a/dockers/docker-database/Dockerfile.j2 +++ b/dockers/docker-database/Dockerfile.j2 @@ -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/"] ENTRYPOINT ["/usr/local/bin/docker-database-init.sh"] diff --git a/dockers/docker-database/docker-database-init.sh b/dockers/docker-database/docker-database-init.sh index c50add1a7698..076e06396447 100755 --- a/dockers/docker-database/docker-database-init.sh +++ b/dockers/docker-database/docker-database-init.sh @@ -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 fi # on VoQ system, we only publish redis_chassis instance and CHASSIS_APP_DB when @@ -125,6 +129,8 @@ do else echo -n > /var/lib/$inst/dump.rdb fi + # the Redis process is operating under the 'redis' user in supervisord and make redis user own /var/lib/$inst inside db container. + chown -R redis:redis /var/lib/$inst done TZ=$(cat /etc/timezone) diff --git a/dockers/docker-database/multi_database_config.json.j2 b/dockers/docker-database/multi_database_config.json.j2 new file mode 100644 index 000000000000..26ddb006b83d --- /dev/null +++ b/dockers/docker-database/multi_database_config.json.j2 @@ -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}}" + {% endif %} + }, + "redis1": { + "hostname" : "{{HOST_IP}}", + "port" : 6378, + "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" : 6377, + "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" : 6376, + "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" : 6375, + "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 %}, + "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" +} diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 891a9afdc06b..1d8a4c78fddc 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -1156,3 +1156,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 %} diff --git a/slave.mk b/slave.mk index 22b13a5ad452..17d46e056b3f 100644 --- a/slave.mk +++ b/slave.mk @@ -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)) @@ -1491,6 +1492,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))"