Get the App
SLTechnology News&Howtos  ›  Database  › 

Using Spring AOP section to solve the separation of database read and write

Shulou Source: shulou.com Published: 2022-06-01 12:45:41 09月29日 Update

Summary:

In order to reduce the pressure on the database, the database master-slave (master/slave) method is generally used, but this method will bring some trouble to the application, for example, how to write the data to the master library and read it from the slave library when reading the data. If the application misjudges and writes the data to the slave library, it will cause a fatal blow to the system.

There are many solutions to solve the separation of reading and writing, such as SQL parsing and dynamic setting of data sources. The main purpose of SQL parsing is to analyze which kind of sql statement is insert/select/update / delete, so as to choose the master and slave. On the other hand, the dynamic setting of the data source determines the master and slave by intercepting the method name, for example, the method in the form of save* (), insert* () uses the master library, begins with select (), and uses the slave library. Many companies use custom tags such as @ Master and @ Slave to select a master and slave, while others directly make a master-slave choice by calling code such as setxxMaster,setxxSlave.

For more information, please see my csdn blog:

Using Spring AOP section to solve the separation of database read and write

Tags: Data master and slave database application method method program application selection company dynamic data source aspect code blog pressure name common use beginning form Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Linux Redmi Xiaomi