what's the role of slave_connection in neutron.conf

Asked by LeileiZhou

In neutron.conf, for section [database], there's two connection as below:
===================[database]================================
[database]
# This line MUST be changed to actually run the plugin.
# Example:
# connection = mysql://root:pass@127.0.0.1:3306/neutron
# Replace 127.0.0.1 above with the IP address of the database used by the
# main neutron server. (Leave it as is if the database runs on this host.)
# connection = sqlite://

# The SQLAlchemy connection string used to connect to the slave database
# slave_connection =
============================================================

What's the role of slave_connection ?

Question information

Language:
English Edit question
Status:
Solved
For:
neutron Edit question
Assignee:
No assignee Edit question
Solved by:
ZhiQiang Fan
Solved:
Last query:
Last reply:
Revision history for this message
ZhiQiang Fan (aji-zqfan) said :
#1

you can read this wiki to get a general knowledge: https://wiki.openstack.org/wiki/Slave_usage

the sql connection/slave_connection config opt is used by oslo sqlalchemy session module[0], not neutron directly, for now, I didn't find code in neutron using slave db feature. (If I'm wrong, please let me know, thanks)

some code may use slave db to reduce the master's load, for i.e. nova periodic task[1][2], they are read operations and can accept a little lag, but operator should ensure the lag is not too high.

[0] https://github.com/openstack/oslo-incubator/blob/master/openstack/common/db/sqlalchemy/session.py
[1] https://github.com/openstack/nova/blob/master/nova/db/api.py (#631, for i.e.)
[2] https://blueprints.launchpad.net/nova/+spec/periodic-tasks-to-db-slave

Revision history for this message
LeileiZhou (leileiz) said :
#2

I don't see any neutron function using slave. But in neutron, there's method for get_session in
https://github.com/openstack/neutron/blob/master/neutron/openstack/common/db/sqlalchemy/session.py

That's why I got confused here.

From your reference[0], other projects should get session from oslo get_session(), right? I looked at cinder,nova and neutron, all of them define and consume their own get_session function instead of oslo's. This is potential code refactor work here?

Thanks for explanation!

Revision history for this message
Best ZhiQiang Fan (aji-zqfan) said :
#3

oslo is a common code project (and it is a bit strict to sync upstream code from oslo to each project.), the link you provided in neutron is exactly oslo code. you can read https://wiki.openstack.org/wiki/Oslo for more detail.

some projects will define their own get_session, but just a simple wrapper to oslo's get_session, or maybe some special case cannot be met in specific low level driver so particular code should handle that. usually, openstack projects use oslo get_session directly, for i.e., nova, keystone, cinder, glance.

Neutron has written a simple helper function get_session, which just changes the default value of parameter sqlite_fk(which means SqliteForeignKeys) in oslo get_session, you can dig deeper to figure out why it does that, and I think this is another question.

-------------------details can be ignored---------------------
zqfan@openstack-dev:~/openstack/nova/nova$ grep -n 'def get_session' ./ -r
./openstack/common/db/sqlalchemy/session.py:412:def get_session(autocommit=True, expire_on_commit=False,
./tests/virt/xenapi/test_xenapi.py:128:def get_session():
./virt/hyperv/basevolumeutils.py:105: def get_session_id_from_mounted_disk(self, physical_drive_path):
./virt/baremetal/db/sqlalchemy/session.py:48:def get_session(autocommit=True, expire_on_commit=False):
./virt/xenapi/client/session.py:151: def get_session_id(self):

zqfan@openstack-dev:~/openstack/cinder/cinder$ grep -n 'def get_session' ./ -r
./openstack/common/db/sqlalchemy/session.py:370:def get_session(autocommit=True, expire_on_commit=False,
./volume/drivers/xenapi/lib.py:361: def get_session(self):

zqfan@openstack-dev:~/openstack/neutron/neutron$ grep -n 'def get_session' ./ -r./openstack/common/db/sqlalchemy/session.py:414:def get_session(autocommit=True, expire_on_commit=False,
./db/api.py:46:def get_session(autocommit=True, expire_on_commit=False):

Revision history for this message
LeileiZhou (leileiz) said :
#4

Thanks ZhiQiang Fan, that solved my question.

Revision history for this message
ZhiQiang Fan (aji-zqfan) said :
#5