Skip to content

Commit 9e888d4

Browse files
authoredNov 22, 2024··
Enable Multi DB (#20305)
Enable Multi DB
1 parent 36895fb commit 9e888d4

File tree

6 files changed

+211
-1
lines changed

6 files changed

+211
-1
lines changed
 

‎Makefile.work

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
# * SONIC_PTF_ENV_PY_VER: Python version for PTF image
6262
# * Default: mixed
6363
# * Values: mixed,py3
64+
# * ENABLE_MULTIDB: Enable multiple redis database instances.
65+
# * Default: unset
66+
# * Values: y
6467
###############################################################################
6568

6669
SHELL = /bin/bash
@@ -571,6 +574,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
571574
BUILD_PROCESS_TIMEOUT=$(BUILD_PROCESS_TIMEOUT) \
572575
LEGACY_SONIC_MGMT_DOCKER=$(LEGACY_SONIC_MGMT_DOCKER) \
573576
SONIC_PTF_ENV_PY_VER=$(SONIC_PTF_ENV_PY_VER) \
577+
ENABLE_MULTIDB=$(ENABLE_MULTIDB) \
574578
$(SONIC_OVERRIDE_BUILD_VARS)
575579

576580
.PHONY: sonic-slave-build sonic-slave-bash init reset

‎dockers/docker-database/Dockerfile.j2

+1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
4848
COPY ["files/sysctl-net.conf", "/etc/sysctl.d/"]
4949
COPY ["files/update_chassisdb_config", "/usr/local/bin/"]
5050
COPY ["flush_unused_database", "/usr/local/bin/"]
51+
COPY ["multi_database_config.json.j2", "/usr/share/sonic/templates/"]
5152

5253
ENTRYPOINT ["/usr/local/bin/docker-database-init.sh"]

‎dockers/docker-database/docker-database-init.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ mkdir -p /etc/supervisor/conf.d/
5050
if [ -f /etc/sonic/database_config$NAMESPACE_ID.json ]; then
5151
cp /etc/sonic/database_config$NAMESPACE_ID.json $REDIS_DIR/sonic-db/database_config.json
5252
else
53-
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
53+
if [ -f /etc/sonic/enable_multidb ]; then
54+
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
55+
else
56+
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
57+
fi
5458
fi
5559

5660
# on VoQ system, we only publish redis_chassis instance and CHASSIS_APP_DB when
@@ -125,6 +129,8 @@ do
125129
else
126130
echo -n > /var/lib/$inst/dump.rdb
127131
fi
132+
# the Redis process is operating under the 'redis' user in supervisord and make redis user own /var/lib/$inst inside db container.
133+
chown -R redis:redis /var/lib/$inst
128134
done
129135

130136
TZ=$(cat /etc/timezone)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
{% set include_remote_db = (REMOTE_DB_IP is defined and REMOTE_DB_PORT is defined) %}
2+
{
3+
"INSTANCES": {
4+
"redis":{
5+
"hostname" : "{{HOST_IP}}",
6+
"port" : {{REDIS_PORT}},
7+
"unix_socket_path" : "/var/run/redis{{DEV}}/redis.sock",
8+
"persistence_for_warm_boot" : "yes"
9+
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
10+
,"database_type": "{{DATABASE_TYPE}}"
11+
{% endif %}
12+
},
13+
"redis1": {
14+
"hostname" : "{{HOST_IP}}",
15+
"port" : 6378,
16+
"unix_socket_path" : "/var/run/redis{{DEV}}/redis1.sock",
17+
"persistence_for_warm_boot" : "yes"
18+
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
19+
,"database_type": "{{DATABASE_TYPE}}"
20+
{% endif %}
21+
},
22+
"redis2": {
23+
"hostname" : "{{HOST_IP}}",
24+
"port" : 6377,
25+
"unix_socket_path" : "/var/run/redis{{DEV}}/redis2.sock",
26+
"persistence_for_warm_boot" : "yes"
27+
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
28+
,"database_type": "{{DATABASE_TYPE}}"
29+
{% endif %}
30+
},
31+
"redis3": {
32+
"hostname" : "{{HOST_IP}}",
33+
"port" : 6376,
34+
"unix_socket_path" : "/var/run/redis{{DEV}}/redis3.sock",
35+
"persistence_for_warm_boot" : "yes"
36+
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
37+
,"database_type": "{{DATABASE_TYPE}}"
38+
{% endif %}
39+
},
40+
"redis4": {
41+
"hostname" : "{{HOST_IP}}",
42+
"port" : 6375,
43+
"unix_socket_path" : "/var/run/redis{{DEV}}/redis4.sock",
44+
"persistence_for_warm_boot" : "yes"
45+
{% if DATABASE_TYPE is defined and DATABASE_TYPE != "" %}
46+
,"database_type": "{{DATABASE_TYPE}}"
47+
{% endif %}
48+
},
49+
"redis_chassis":{
50+
"hostname" : "redis_chassis.server",
51+
"port": 6380,
52+
"unix_socket_path": "/var/run/redis-chassis/redis_chassis.sock",
53+
"persistence_for_warm_boot" : "yes"
54+
}
55+
{% if include_remote_db %}
56+
,"remote_redis":{
57+
"hostname" : "{{REMOTE_DB_IP}}",
58+
"port" : {{REMOTE_DB_PORT}},
59+
"unix_socket_path": "",
60+
"persistence_for_warm_boot" : "yes"
61+
}
62+
{% endif %},
63+
"redis_bmp":{
64+
"hostname" : "{{HOST_IP}}",
65+
"port" : {{BMP_DB_PORT}},
66+
"unix_socket_path" : "/var/run/redis{{DEV}}/redis_bmp.sock",
67+
"persistence_for_warm_boot" : "yes"
68+
}
69+
},
70+
"DATABASES" : {
71+
"APPL_DB": {
72+
"id": 0,
73+
"separator": ":",
74+
"instance": "redis1"
75+
},
76+
"ASIC_DB": {
77+
"id": 1,
78+
"separator": ":",
79+
"instance": "redis2"
80+
},
81+
"COUNTERS_DB": {
82+
"id": 2,
83+
"separator": ":",
84+
"instance": "redis3"
85+
},
86+
"LOGLEVEL_DB": {
87+
"id": 3,
88+
"separator": ":",
89+
"instance": "redis"
90+
},
91+
"CONFIG_DB": {
92+
"id": 4,
93+
"separator": "|",
94+
"instance": "redis"
95+
},
96+
"PFC_WD_DB": {
97+
"id": 5,
98+
"separator": ":",
99+
"instance": "redis3"
100+
},
101+
"FLEX_COUNTER_DB": {
102+
"id": 5,
103+
"separator": ":",
104+
"instance": "redis3"
105+
},
106+
"STATE_DB": {
107+
"id": 6,
108+
"separator": "|",
109+
"instance": "redis"
110+
},
111+
"SNMP_OVERLAY_DB": {
112+
"id": 7,
113+
"separator": "|",
114+
"instance": "redis"
115+
},
116+
"SYSMON_DB": {
117+
"id": 10,
118+
"separator": "|",
119+
"instance": "redis"
120+
},
121+
"BMC_DB": {
122+
"id": 12,
123+
"separator": ":",
124+
"instance": "redis4"
125+
},
126+
"RESTAPI_DB": {
127+
"id": 8,
128+
"separator": "|",
129+
"instance": "redis"
130+
},
131+
"GB_ASIC_DB": {
132+
"id": 9,
133+
"separator": ":",
134+
"instance": "redis"
135+
},
136+
"GB_COUNTERS_DB": {
137+
"id": 10,
138+
"separator": ":",
139+
"instance": "redis"
140+
},
141+
"GB_FLEX_COUNTER_DB": {
142+
"id": 11,
143+
"separator": ":",
144+
"instance": "redis"
145+
},
146+
"APPL_STATE_DB": {
147+
"id": 14,
148+
"separator": ":",
149+
"instance": "redis"
150+
},
151+
"CHASSIS_APP_DB" : {
152+
"id" : 12,
153+
"separator": "|",
154+
"instance" : "redis_chassis"
155+
},
156+
"CHASSIS_STATE_DB" : {
157+
"id" : 13,
158+
"separator": "|",
159+
"instance" : "redis_chassis"
160+
}
161+
{% if DATABASE_TYPE is defined and DATABASE_TYPE == "dpudb" %}
162+
,
163+
"DPU_APPL_DB" : {
164+
"id" : 15,
165+
"separator": ":",
166+
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %},
167+
"format": "proto"
168+
},
169+
"DPU_APPL_STATE_DB" : {
170+
"id" : 16,
171+
"separator": "|",
172+
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
173+
},
174+
"DPU_STATE_DB" : {
175+
"id" : 17,
176+
"separator": "|",
177+
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
178+
},
179+
"DPU_COUNTERS_DB" : {
180+
"id" : 18,
181+
"separator": ":",
182+
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
183+
}
184+
{% endif %},
185+
"BMP_STATE_DB" : {
186+
"id" : 20,
187+
"separator": "|",
188+
"instance" : "redis_bmp"
189+
}
190+
},
191+
"VERSION" : "1.0"
192+
}

‎files/build_templates/sonic_debian_extension.j2

+5
Original file line numberDiff line numberDiff line change
@@ -1156,3 +1156,8 @@ sudo rm -rf $FILESYSTEM_ROOT/tmp/mask_disabled_services.py
11561156

11571157

11581158
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install python3-dbus
1159+
1160+
## Enable MULTIDB
1161+
{% if ENABLE_MULTIDB == "y" %}
1162+
sudo touch $FILESYSTEM_ROOT_ETC_SONIC/enable_multidb
1163+
{% endif %}

‎slave.mk

+2
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ $(info "CROSS_BUILD_ENVIRON" : "$(CROSS_BUILD_ENVIRON)")
472472
$(info "LEGACY_SONIC_MGMT_DOCKER" : "$(LEGACY_SONIC_MGMT_DOCKER)")
473473
$(info "INCLUDE_EXTERNAL_PATCHES" : "$(INCLUDE_EXTERNAL_PATCHES)")
474474
$(info "PTF_ENV_PY_VER" : "$(PTF_ENV_PY_VER)")
475+
$(info "ENABLE_MULTIDB" : "$(ENABLE_MULTIDB)")
475476
$(info )
476477
else
477478
$(info SONiC Build System for $(CONFIGURED_PLATFORM):$(CONFIGURED_ARCH))
@@ -1491,6 +1492,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
14911492
export include_mux="$(INCLUDE_MUX)"
14921493
export include_bootchart="$(INCLUDE_BOOTCHART)"
14931494
export enable_bootchart="$(ENABLE_BOOTCHART)"
1495+
export enable_multidb="$(ENABLE_MULTIDB)"
14941496
$(foreach docker, $($*_DOCKERS),\
14951497
export docker_image="$(docker)"
14961498
export docker_image_name="$(basename $(docker))"

0 commit comments

Comments
 (0)
Please sign in to comment.