Database read-write separation method based on JAVA section and dynamic data source

Through the database read and write separation method based on JAVA section and dynamic data source, the data source is automatically selected for read and write operations, which solves the time-consuming and labor-intensive problem of manually configuring data source routing rules in traditional methods, and improves development efficiency and system performance.

CN119903087APending Publication Date: 2025-04-29重庆富民银行股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411984213.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

Traditional database read and write separation methods require manual configuration of data source routing rules, which is time-consuming and labor-intensive and error-prone. Especially when the system scale is expanded and the business logic is complex, configuration management becomes extremely difficult.

Method used

The database read and write separation method based on JAVA section and dynamic data source is adopted. By receiving user's business request data, identifying packets and DAOs, tag associations, finding mapping configuration tables, and automatically selecting data sources for read and write operations.

Benefits of technology

It realizes automatic selection of data sources according to business operation types, reduces the need for developers to manually distinguish data sources, improves development efficiency, effectively shares database pressure, and improves system performance and fault tolerance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119903087A_ABST
    Figure CN119903087A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database processing, in particular to a database read-write separation method based on a JAVA section and a dynamic data source, which comprises the following steps: receiving service request data initiated by a user; according to the received service request data, identifying a packet corresponding to the service request data, and calling the corresponding DAO in each packet to form a corresponding DAO set; according to each DAO in the formed DAO set, identifying a label corresponding to each DAO, and associating each DAO with the identified label; calling a corresponding mapping configuration table from a database, and searching a data source corresponding to the tag associated with each DAO in the mapping configuration table according to the tag associated with each DAO and the called mapping configuration table; and selecting a corresponding data source according to the searched data source corresponding to each DAO, and executing a read or write operation on the corresponding data source.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database processing, and in particular to a database read-write separation method based on JAVA aspect and dynamic data source. Background Art

[0002] In modern application systems, as the business scale expands and the number of users grows, a single database instance often cannot withstand the pressure of high concurrent access. In order to improve the performance, availability and scalability of the system, database read-write separation has become a common optimization method. Traditional database read-write separation generally uses hard coding, middleware or direct application splitting.

[0003] However, the traditional method of implementing database read-write separation has many problems, which limits its effectiveness and flexibility in practical applications. Specifically, the following problems are encountered:

[0004] Traditional read-write separation technology often requires manual configuration of data source routing rules. This manual configuration is not only time-consuming and labor-intensive, but also prone to errors. Configuration management becomes extremely difficult, especially when the system scale is expanded and the business logic is complex.

[0005] Some implementation methods require explicit specification of the use of data sources in business code, which increases the coupling of the code.

[0006] Based on this, there is an urgent need for a database read-write separation method based on JAVA aspects and dynamic data sources, which can automatically select the corresponding data source according to the business operation type, thereby eliminating the need for wireless developers to manually distinguish data sources, greatly improving development efficiency. Summary of the invention

[0007] One of the purposes of the present invention is to provide a database read-write separation method based on JAVA aspects and dynamic data sources, which can automatically select the corresponding data source according to the business operation type, thereby eliminating the need for wireless developers to manually distinguish data sources, greatly improving development efficiency.

[0008] In order to achieve the above object, a database read-write separation method based on JAVA aspect and dynamic data source is provided, which includes the following steps:

[0009] S1. Receive service request data initiated by the user;

[0010] S2. According to the received service request data, identify the package corresponding to the service request data, and retrieve the corresponding DAO in each package to form a corresponding DAO set;

[0011] S3. According to each DAO in the formed DAO set, the label corresponding to each DAO is identified, and each DAO is associated with the identified label;

[0012] S4. Retrieve the corresponding mapping configuration table from the database, and find out the data source corresponding to the tag associated with each DAO in the mapping configuration table according to the tag associated with each DAO and the retrieved mapping configuration table;

[0013] S5. According to the data sources corresponding to the found DAOs, select the corresponding data source, and perform a read or write operation on the corresponding data source.

[0014] Technical principles and effects of this solution: In this solution, first, business request data from the user is received as the basis for subsequent processing, then the package corresponding to the business request data is identified based on the received business request data, and the DAO corresponding to each package is called up, and then the label of each DAO in the formed DAO set is identified, and each DAO is associated with the identified label.

[0015] Then, the mapping configuration table is retrieved from the database, and the data source corresponding to the tag associated with each DAO is found in the mapping configuration table according to the tag associated with each DAO and the retrieved mapping configuration table. Finally, according to the data source corresponding to each DAO found, the corresponding data source is selected, and the read or write operation is performed on the corresponding data source.

[0016] In this solution, the business request data is used to retrieve different packages to identify and retrieve the data sources corresponding to the DAOs of different packages, thereby realizing read-write separation. Different data sources perform different operations, namely read operations or write operations, which effectively shares the pressure on the database and improves the overall performance of the system. Write operations point to different data sources, reducing the risk of misoperation and enhancing data security. Even if a data source has a problem, other data sources can continue to provide services, improving the fault tolerance and stability of the system. That is, it is possible to automatically select the corresponding data source according to the business operation type, thereby eliminating the need for wireless developers to manually distinguish data sources, greatly improving development efficiency.

[0017] Furthermore, it also includes S6, when the corresponding data source executes the read or write operation, detecting the execution status of the corresponding read or write operation, and when it is detected that the corresponding read or write operation fails, immediately triggering an alarm and sending an alarm message to the server.

[0018] Beneficial effects: By monitoring the execution of read and write operations in real time, any anomalies can be discovered in a timely manner, reducing the scope of potential problems. Once an operation fails, an alarm is immediately triggered and relevant personnel are notified, so that the problem can be quickly handled, improving the reliability and stability of the system. Rapid response and handling of abnormal situations reduces system downtime caused by database problems and improves user satisfaction.

[0019] Further, the S4 includes:

[0020] S40, retrieve the corresponding mapping configuration table from the database;

[0021] S41. Determine the data source corresponding to each tag according to the tags associated with each DAO and the retrieved mapping configuration table. If a tag corresponds to multiple data sources, select the data source that best matches the tag based on the preset data source selection strategy.

[0022] Beneficial effects: In this solution, the introduction of multi-level selection strategies and preset data source selection strategies not only solves the problems existing in the existing technology, but also significantly improves the performance, reliability and maintainability of the system.

[0023] Furthermore, the preset data source selection strategy is:

[0024] S410: when a tag corresponds to multiple data sources, retrieve the basic information of the data source corresponding to each data source, and calculate the business matching degree between the corresponding data source and the business request data based on the business request data;

[0025] S420, arranging the data sources in descending order according to the business matching degrees corresponding to the data sources to form a business matching degree arrangement table;

[0026] S430, selecting the data source corresponding to the maximum business matching degree according to the business matching degree arrangement table;

[0027] S440. According to the selected data source with the greatest business matching degree, the status of the selected data source is checked. If the corresponding data source is online, the selected data source is the data source that best matches the label. Otherwise, the data source with the greatest remaining business matching degree is selected and S440 is executed again.

[0028] Beneficial effects: In this solution, the business matching degree calculation ensures that the data source selected each time is the most suitable for the current business needs, reducing unnecessary network delays and resource waste. Reasonable allocation of read and write traffic to different data sources improves the system's concurrent processing capabilities and response speed. Through status checking and recursive selection mechanisms, it ensures that even if some data sources are unavailable, the system can automatically switch to other available data sources, improving the system's fault tolerance and stability. Support for dynamic expansion and hot updates enables the system to flexibly respond to changes in data sources, reducing downtime and operation and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 The present invention is a flowchart of a database read-write separation method based on JAVA aspects and dynamic data sources in the first embodiment of the present invention. DETAILED DESCRIPTION

[0030] The following is further described in detail through specific implementation methods:

[0031] Embodiment 1

[0032] The database read-write separation method based on JAVA aspects and dynamic data sources is basically as follows Figure 1 As shown, the following steps are included:

[0033] S1. Receive business request data initiated by a user. In this embodiment, the user request is received through a Web service, an API interface or other forms, and is encapsulated into a processable object.

[0034] S2. According to the received service request data, identify the package corresponding to the service request data, and retrieve the corresponding DAO in each package to form a corresponding DAO set;

[0035] S3. According to each DAO in the formed DAO set, the tag corresponding to each DAO is identified, and each DAO is associated with the identified tag; in this embodiment, the corresponding DAO is identified through AOP processing, so as to obtain the corresponding mapping configuration table. AOP is seamlessly integrated into the existing system without large-scale modification of business code.

[0036] S4. Retrieve the corresponding mapping configuration table from the database, and find out the data source corresponding to the label associated with each DAO in the mapping configuration table according to the label associated with each DAO and the retrieved mapping configuration table; of course, in this embodiment, the mapping configuration table stored in the database is the correspondence between the label associated with each DAO and each data source, and new mapping relationships can be added by means, or they can be generated automatically.

[0037] The S4 includes:

[0038] S40, retrieve the corresponding mapping configuration table from the database;

[0039] S41. Determine the data source corresponding to each tag according to the tags associated with each DAO and the retrieved mapping configuration table. If a tag corresponds to multiple data sources, select the data source that best matches the tag based on the preset data source selection strategy.

[0040] The preset data source selection strategy is:

[0041] S410: when a tag corresponds to multiple data sources, retrieve the basic information of the data source corresponding to each data source, and calculate the business matching degree between the corresponding data source and the business request data based on the business request data;

[0042] S420, arranging the data sources in descending order according to the business matching degrees corresponding to the data sources to form a business matching degree arrangement table;

[0043] S430, selecting the data source corresponding to the maximum business matching degree according to the business matching degree arrangement table;

[0044] S440, according to the selected data source with the greatest business matching degree, check the status of the selected data source, if the corresponding data source is online, then the selected data source is the data source that best matches the label, otherwise, select the data source with the greatest remaining business matching degree, and re-execute S440. For example, the corresponding data sources corresponding to the corresponding label K1 are D1, D2, and D3, where the business matching degrees between each data source and the business request data of this time are A, B, and C, respectively, where A>C>B, so the data source D1 that is first selected at this time, according to the selected data source with the greatest business matching degree, check the status of the selected data source, if the data source D1 is online, then the selected data source D1 is the data source that best matches the label; otherwise, select the data source D3 with the greatest remaining business matching degree, and then re-check the status of the data source D3.

[0045] S5. According to the data sources corresponding to the found DAOs, select the corresponding data source, and perform a read or write operation on the corresponding data source.

[0046] S6. When the corresponding data source performs a read or write operation, the execution status of the corresponding read or write operation is detected. When it is detected that the corresponding read or write operation fails, an alarm is immediately triggered and an alarm message is sent to the server.

[0047] The above is only an embodiment of the present invention. The common sense such as the known specific structure and characteristics in the scheme is described too much here. The ordinary technicians in the relevant field know all the common technical knowledge in the technical field of the invention before the application date or priority date, can know all the existing technologies in the field, and have the ability to apply the conventional experimental means before that date. The ordinary technicians in the relevant field can improve and implement this scheme in combination with their own abilities under the enlightenment given by this application. Some typical known structures or known methods should not become obstacles for ordinary technicians in the relevant field to implement this application. It should be pointed out that for those skilled in the art, without departing from the structure of the present invention, several deformations and improvements can be made, which should also be regarded as the protection scope of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent. The protection scope required by this application shall be based on the content of its claims, and the specific implementation methods and other records in the specification can be used to interpret the content of the claims.

Claims

1. A database read-write separation method based on JAVA aspects and dynamic data sources, characterized by: The following steps are involved: S1. Receive service request data initiated by the user; S2. According to the received service request data, identify the package corresponding to the service request data, and retrieve the corresponding DAO in each package to form a corresponding DAO set; S3. According to each DAO in the formed DAO set, the label corresponding to each DAO is identified, and each DAO is associated with the identified label; S4. Retrieve the corresponding mapping configuration table from the database, and find out the data source corresponding to the tag associated with each DAO in the mapping configuration table according to the tag associated with each DAO and the retrieved mapping configuration table; S5. According to the data sources corresponding to the found DAOs, select the corresponding data source, and perform a read or write operation on the corresponding data source.

2. The database read-write separation method based on JAVA aspects and dynamic data sources according to claim 1 is characterized in that: The method further includes S6: when the corresponding data source performs a read or write operation, detecting the execution status of the corresponding read or write operation, and when detecting that the corresponding read or write operation fails, immediately triggering an alarm and sending an alarm message to the server.

3. The database read-write separation method based on JAVA aspect and dynamic data source according to claim 2 is characterized in that: The S4 includes: S40, retrieve the corresponding mapping configuration table from the database; S41. Determine the data source corresponding to each tag according to the tags associated with each DAO and the retrieved mapping configuration table. If a tag corresponds to multiple data sources, select the data source that best matches the tag based on the preset data source selection strategy.

4. The database read-write separation method based on JAVA aspect and dynamic data source according to claim 3 is characterized in that: The preset data source selection strategy is: S410: when a tag corresponds to multiple data sources, retrieve the basic information of the data source corresponding to each data source, and calculate the business matching degree between the corresponding data source and the business request data based on the business request data; S420, arranging the data sources in descending order according to the business matching degrees corresponding to the data sources to form a business matching degree arrangement table; S430, selecting the data source corresponding to the maximum business matching degree according to the business matching degree arrangement table; S440. According to the selected data source with the greatest business matching degree, the status of the selected data source is checked. If the corresponding data source is online, the selected data source is the data source that best matches the label. Otherwise, the data source with the greatest remaining business matching degree is selected and S440 is executed again.