Skip to content

Commit

Permalink
Enable Multi DB (#20305)
Browse files Browse the repository at this point in the history
Enable Multi DB
  • Loading branch information
Pan-XT authored Nov 22, 2024
1 parent 36895fb commit 9e888d4
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 1 deletion.
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 @@ -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
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/"]

ENTRYPOINT ["/usr/local/bin/docker-database-init.sh"]
8 changes: 7 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
fi

# on VoQ system, we only publish redis_chassis instance and CHASSIS_APP_DB when
Expand Down Expand Up @@ -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)
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}}"
{% 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"
}
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 @@ -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 %}
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 @@ -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))"
Expand Down

0 comments on commit 9e888d4

Please sign in to comment.