A management and control method and gateway applying read-write separation
By parsing the application identification information and request parameters of external requests in the gateway, and creating preferred read-write separation rules, the problem of not being able to dynamically switch master and slave nodes in the existing technology is solved. This enables flexible read-write separation configuration, avoids database synchronization delay errors, and adapts to the diverse needs of microservice architecture.
Patent Information
- Application Number
- CN202411030231.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2044-07-30
AI Technical Summary
Existing technologies cannot dynamically switch between master and slave nodes, leading to database synchronization delays and errors. Furthermore, in a microservice architecture, they cannot differentiate read/write separation requirements based on external requests.
By receiving external requests in the gateway, parsing application identification information, creating preferred read/write separation rules based on request parameters, and sending them to the application for dynamic request processing, the read/write separation SDK package is integrated to achieve flexible configuration.
It enables dynamic configuration of read/write separation based on different business scenarios, avoiding database synchronization delays and errors, and meeting the read/write needs of different applications.
Smart Images

Figure CN119202039B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the technical field of data read-write separation, and particularly relates to a management and control method and a gateway for read-write separation. BACKGROUND
[0002] At present, in order to support high concurrency and high throughput scenes, read-write separation is used at the database level to improve the overall efficiency of the database. The so-called read-write separation is that write operations enter a master database, and read operations enter a slave database. In order to realize the read-write separation, applications generally use the form of annotation tags to rigidly limit the code, for example, the code in some DAO layer forces the SQL query class statement to point to the slave database, and the write statement points to the master database.
[0003] However, this method has some disadvantages: first, the master-slave node switching cannot be dynamically and freely controlled, for example, when some business scenarios require high performance and the master-slave synchronization has a certain delay, the direct query of the slave database will fail, at this time, the master database needs to be pointed to, and the old scheme cannot dynamically switch; second, in the micro-service architecture, there are multiple micro-service application instances and multiple micro-services may call each other, if the read-write separation mode is written in the code, the different requests from the outside cannot be distinguished. For example, for the request from the A application, because it requires higher performance, all nodes uniformly use the master database, and for the request from the B application, it does not require high performance and can support the slave database, and the old method cannot well support the link requirements of the micro-service. SUMMARY
[0004] The technical problem to be solved by the application is to provide a management and control method and a gateway for read-write separation of applications, which can flexibly switch the master-slave objects of the read-write separation of the applications and guarantee that there is no error problem caused by database synchronization delay.
[0005] To solve the above technical problems, the technical scheme adopted by the application is as follows:
[0006] A management and control method for read-write separation of applications is used to manage and control the read-write separation of all applications attached to the gateway, and comprises the following steps:
[0007] S1, receiving an external request, and analyzing key information contained in the external request, wherein the key information comprises application identification information;
[0008] S2, creating a preferred read-write separation rule corresponding to each application identification information contained in the key information in combination with the request parameters of the external request, and sending the key information to the application corresponding to each application identification information;
[0009] S3, receiving and according to the rule acquisition request issued by the application after acquiring the key information, sending the preferred read-write separation rule to the corresponding application, so that the application processes the external request according to the received preferred read-write separation rule when the external request arrives.
[0010] In order to solve the above technical problems, another technical scheme is adopted in the present application:
[0011] A management and control gateway applying read-write separation comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the following steps when executing the computer program:
[0012] S1, receiving an external request, and parsing key information contained in the external request, wherein the key information comprises application identification information;
[0013] S2, creating a preferred read-write separation rule corresponding to each application identification information contained in the key information in combination with the request parameter of the external request, and sending the key information to the application corresponding to each application identification information;
[0014] S3, receiving and according to the rule acquisition request issued by the application after acquiring the key information, sending the preferred read-write separation rule to the corresponding application, so that the application processes the external request according to the received preferred read-write separation rule when the external request arrives.
[0015] The present application has the beneficial effects that: a management and control method and gateway applying read-write separation are provided, after receiving an external request, a corresponding preferred read-write separation rule can be created according to the request parameter of the external request and the application identification information pointed to by the external request, and then the application dynamically acquires the preferred read-write separation rule corresponding to itself, and when the external request arrives, the application processes the external request according to the preferred read-write separation rule, in this way, the read-write separation operation that should be made by different applications is dynamically configured according to each external request, avoiding that the application only processes the request according to the default read-write separation rule carried by itself, and guaranteeing that the error problem of database synchronization delay does not occur, and meeting the needs of different business scenarios. BRIEF DESCRIPTION OF DRAWINGS
[0016] Figure 1 A step schematic diagram of a management and control method applying read-write separation of the present application;
[0017] Figure 2 A system block diagram of a management and control gateway applying read-write separation of the present application.
[0018] LABEL EXPLANATION:
[0019] 1. A management and control gateway applying read-write separation; 2. a memory; 3. a processor. DETAILED DESCRIPTION
[0020] To illustrate the technical content of the present application, the purposes and effects achieved are described below in conjunction with the embodiments and the accompanying drawings.
[0021] Please refer to Figure 1 A management and control method applying read-write separation, for managing and controlling the read-write separation of all applications attached to the gateway, comprising the following steps:
[0022] S1. Receiving an external request, and parsing the key information contained in the external request, wherein the key information comprises application identification information;
[0023] S2. Creating preferred read-write separation rules corresponding to each of the application identification information contained in the key information in combination with the request parameters of the external request, and sending the key information to the applications corresponding to each of the application identification information.
[0024] S3. Receiving and sending the preferred read-write separation rules to the corresponding applications according to the rule acquisition requests sent by the applications after acquiring the key information, so that the applications process the external requests according to the received preferred read-write separation rules when the external requests arrive.
[0025] From the above description, the beneficial effects of the present application are as follows: after receiving an external request, the corresponding preferred read-write separation rules can be created according to the request parameters of the external request and the application identification information pointed to by the external request, and then the preferred read-write separation rules corresponding to the applications are dynamically acquired by the applications, and when the external requests arrive, the applications process the external requests according to the preferred read-write separation rules. In this way, the read-write separation operations that should be performed by different applications are dynamically configured according to each external request, avoiding the situation that the applications only process the requests according to the default read-write separation rules carried by themselves, thus ensuring that there will be no error problem of database synchronization delay, and meeting the needs of different business scenarios.
[0026] Further, it further comprises:
[0027] S0. Creating a read-write separation SDK package and a preset read-write separation rule as a loading object of the read-write separation SDK package, and configuring the read-write separation SDK package to all of the applications.
[0028] The step S3 further comprises:
[0029] If the preferred read-write separation rules sent to the corresponding applications are none or have no requirements, the application is controlled to process the external requests according to the preset read-write separation rules.
[0030] From the above description, by integrating the read-write separation SDK package to each application, the read-write separation rules of the application local can be freely configured, that is, the preset read-write separation rules are adopted, and in subsequent processing of external requests, if there is no special requirement for read-write operation of a certain application, the application can be processed according to the preset read-write separation rules, so as to reduce the processing burden of creating the optimal read-write separation rules. At the same time, the customization of the read-write separation rules of the application local cache is also realized. In some scenarios where it is determined that new read-write rules are not needed for a long time, the application can directly perform read-write separation by itself, reducing the processing pressure of the management gateway.
[0031] Further, it also includes:
[0032] S4, when the preset read-write separation rules are updated, the application is notified to reload the new preset read-write separation rules.
[0033] From the above description, under the premise of establishing the preset read-write separation rules, the real-time updating function is introduced to strengthen the centralized management of the local read-write separation function of different applications, so that the read-write separation function of the application is more flexible and has stronger adaptability.
[0034] Further, the combination of the request parameters of the external request and the creation of the optimal read-write separation rules corresponding to each application identification information contained in the key information includes:
[0035] The interface object is obtained from the request parameter, and the optimal read-write separation rules corresponding to each application identification information are created according to the important level to which the interface object belongs.
[0036] From the above description, in the setting of the optimal read-write separation rules, the read-write separation actions of the corresponding application can be controlled according to the important level to which the interface object belongs. The more important the interface is, the more it needs to ensure that there is no error problem of database synchronization delay.
[0037] Further, the sending of the key information to each application corresponding to the application identification information specifically includes:
[0038] The key information contained in the request header of the external request is sent to all the applications in the request header transparent transmission mode.
[0039] From the above description, the request header transparent transmission mode ensures that the key information can be efficiently and stably transmitted to each application.
[0040] Please refer to a kind of application read-write separation management and control gateway, including memory, processor and computer program stored in memory and can be run on processor, the processor executes the computer program when the following steps are realized:
[0041] S1, receive external request, parse the key information contained in the external request, the key information includes application identification information;
[0042] S2, in combination with the request parameter of the external request, create preferred read-write separation rule corresponding to each application identification information contained in the key information, send the key information to each application corresponding to the application identification information;
[0043] S3, receive and according to the rule acquisition request issued by the application after obtaining the key information, send the preferred read-write separation rule to the corresponding application, so that the application handles the external request according to the received preferred read-write separation rule when the external request arrives.
[0044] From the above description, the beneficial effects of the present application are that: after receiving the external request, the corresponding preferred read-write separation rule can be created according to the request parameter of the external request and the application identification information pointed by the external request, and then the preferred read-write separation rule corresponding to the application is dynamically obtained by the application, and when the external request arrives, the application handles the external request according to the preferred read-write separation rule. In this way, the read-write separation operation that each application should make is dynamically configured according to each external request, avoiding that the application only handles the request according to the default read-write separation rule carried by itself, ensuring that there is no error problem of database synchronization delay, and meeting the needs of different business scenarios.
[0045] Further, it also includes:
[0046] S0, create read-write separation SDK package and preset read-write separation rule as the loading object of the read-write separation SDK package, and configure the read-write separation SDK package to all the applications;
[0047] The step S3 further includes:
[0048] If the preferred read-write separation rule sent to the corresponding application is none or no requirement, control the application to handle the external request according to the preset read-write separation rule.
[0049] From the above description, by integrating the read-write separation SDK package to each application, the read-write separation rules of the application local can be freely configured, that is, the preset read-write separation rules are adopted, and in subsequent processing of external requests, if there is no special requirement for read-write operation of the application, the application can be processed according to the preset read-write separation rules, so that the processing burden of creating the optimal read-write separation rules can be reduced; meanwhile, the customization of the read-write separation rules of the application local cache is realized, and in some scenarios where it is determined that the new read-write rules are not needed for a long time, the application can directly perform read-write separation by itself, thereby reducing the processing pressure of the management gateway.
[0050] Further, it further comprises:
[0051] S4, when the preset read-write separation rules are updated, the application is notified to reload the new preset read-write separation rules.
[0052] From the above description, under the premise of establishing the preset read-write separation rules, the real-time updating function is introduced, the centralized management of the local read-write separation function of different applications is strengthened, the read-write separation function of the application is more flexible and more adaptable.
[0053] Further, the combination of the request parameters of the external request and the creation of the optimal read-write separation rules corresponding to each application identification information contained in the key information comprises:
[0054] The interface object is obtained from the request parameters, and the optimal read-write separation rules corresponding to each application identification information are created according to the important level to which the interface object belongs.
[0055] From the above description, in the setting of the optimal read-write separation rules, the read-write separation actions of the corresponding application can be controlled according to the important level to which the interface object belongs, that is, the more important the interface is, the more need to ensure that there is no error problem of database synchronization delay.
[0056] Further, the sending of the key information to each application corresponding to the application identification information specifically comprises:
[0057] The key information contained in the request header of the external request is sent to all the applications in the request header transparent transmission mode.
[0058] From the above description, the request header transparent transmission mode ensures that the key information can be efficiently and stably transmitted to each application.
[0059] Please refer to Figure 1 An embodiment of the application is:
[0060] A kind of application read-write separation management and control method is used to read-write separation management and control all applications attached to gateway, comprising the following steps:
[0061] S0, create read-write separation SDK package and the preset read-write separation rule as the loading object of read-write separation SDK package, configure read-write separation SDK package to all applications;
[0062] In the embodiment, an independent read-write separation SDK package is provided, which includes the main functions: providing an existing commonly used read-write separation annotation class, and aspect function.The management and control gateway or system on microservice architecture will create a preset read-write separation rule;Each application needs to integrate this read-write separation SDK package, and when the application starts successfully, the SDK package will automatically load the preset read-write separation rule from the rule management system to the local cache.Each application in microservice integrates the SDK package, and needs to add read-write separation annotation tags in the key places of itself, indicating that the SQL statements in these places can perform read-write separation operation.In addition, for the places that have added annotation tags, the information of these already configured and registered places can be collected and displayed in the background, including application name, class name, method name, etc., which can be configured in the background.
[0063] S1, receive external request, parse the key information contained in external request, and the key information includes application identification information;
[0064] In the embodiment, the key information generally includes application id, and the application id can be used as application identification information.
[0065] S2, create the preferred read-write separation rule corresponding to each application identification information contained in key information in combination with the request parameter of external request, and send the key information to the application corresponding to each application identification information;
[0066] In the embodiment, when the client request reaches the microservice gateway, the outermost request header needs to be sent to all applications in the manner of request header transmission, and the key information is contained in the request header.
[0067] In the embodiment, the interface object is acquired from the request parameter, and the preferred read-write separation rule corresponding to each application identification information is created according to the importance level to which the interface object belongs. For example, the route of a certain external request has three nodes A, B and C; because the interface pointed by the external request is a key interface, it needs to be guaranteed, so all the subsequent route nodes of the request are set to pass through the master database. The corresponding preferred read-write separation rule at least includes: interface unique identifier, A-master database, B-master database, C-master database; and another interface is a secondary key interface or a non-important interface, that is, part of the function can be degraded or ignored, so a certain error is allowed, and the corresponding preferred read-write separation rule at least includes: interface unique identifier, A-master database, B-master database, C-slave database; and the like.
[0068] S3, receiving and acquiring the rule acquisition request issued by the application after acquiring the key information, and sending the preferred read-write separation rule to the corresponding application, so that the application processes the external request according to the received preferred read-write separation rule when the external request arrives, and if the preferred read-write separation rule sent to the corresponding application is none or no requirement, the application processes the external request according to the preset read-write separation rule.
[0069] In the case where the preferred read-write separation rule is not required, it is assumed that there are four applications A, B, C and D, and the read-write control of the interface in each application is controlled by the application itself, so the application is controlled by the preset read-write separation rule.
[0070] S4, when the preset read-write separation rule is updated, the application is notified to reload the new preset read-write separation rule.
[0071] Please refer to Figure 2 Embodiment two of the application is:
[0072] A kind of application read-write separation management and control gateway 1, including memory 2, processor 3 and the computer program stored on memory 2 and can be run on processor 3, when the processor 3 executes the computer program, the management and control method of one kind of application read-write separation of embodiment one is realized.
[0073] In summary, the application provides a kind of application read-write separation management method and gateway, after receiving external request, can create corresponding preferred read-write separation rule according to the request parameter of external request and the application identification information pointed to by external request, and then the preferred read-write separation rule corresponding to itself is acquired dynamically by application, after external request arrives, application handles external request according to preferred read-write separation rule, in this way, different read-write separation operations that should be made by each external request dynamically configured different application, avoid application only according to the default read-write separation rule carried by itself to handle request, guarantee that there will be no database synchronization delay error problem, at the same time, integrate read-write separation SDK tool package on each application, utilize read-write separation SDK tool package in the local cache of each application to preset read-write separation rule, so as to be called under certain conditions, meet the demand of different business scenarios.
[0074] The above is only an embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent transformation, direct or indirect application in related technical fields using the content of the present application specification and drawings are also included in the patent protection scope of the present application.
Claims
1. A method for managing and controlling application read-write separation, characterized in that, A gateway is used to control read-write separation of all applications attached thereto, comprising the following steps: S1, receiving an external request, analyzing key information contained in the external request, the key information comprising application identification information; S2, creating preferred read-write separation rules corresponding to each of the application identification information contained in the key information in combination with request parameters of the external request, sending the key information to each of the applications corresponding to the application identification information; S3, receiving and sending the preferred read-write separation rules to the corresponding applications according to rule acquisition requests sent by the applications after acquiring the key information, so that the applications process the external request according to the received preferred read-write separation rules when the external request arrives; Further comprising: S0, creating a read-write separation SDK package and preset read-write separation rules as a loading object of the read-write separation SDK package, and configuring the read-write separation SDK package to all the applications; The step S3 further comprises: If the preferred read-write separation rules sent to the corresponding applications are none or have no requirements, the applications are controlled to process the external request according to the preset read-write separation rules; The step S2 further comprises: According to an important level to which an interface object belongs, the preferred read-write separation rules corresponding to each of the application identification information are created.
2. The method according to claim 1, wherein, Further comprising: S4, when the preset read-write separation rules are updated, the applications are notified to reload new preset read-write separation rules.
3. The method according to claim 1, wherein, The step S2 further comprises: The key information contained in the request header of the external request is sent to all the applications in a request header transparent transmission manner.
4. A management and control gateway applying read-write separation, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that, When the processor executes the computer program, the following steps are implemented: S1, receiving an external request, analyzing key information contained in the external request, the key information comprising application identification information; S2, creating preferred read-write separation rules corresponding to each of the application identification information contained in the key information in combination with request parameters of the external request, sending the key information to each of the applications corresponding to the application identification information; S3, receiving and sending the preferred read-write separation rules to the corresponding applications according to rule acquisition requests sent by the applications after acquiring the key information, so that the applications process the external request according to the received preferred read-write separation rules when the external request arrives; Further comprising: S0, creating a read-write separation SDK package and preset read-write separation rules as a loading object of the read-write separation SDK package, and configuring the read-write separation SDK package to all the applications; The step S3 further comprises: If the preferred read-write separation rules sent to the corresponding applications are none or have no requirements, the applications are controlled to process the external request according to the preset read-write separation rules; The request parameter combined with the external request creates a preferred read-write separation rule corresponding to each of the application identification information contained in the key information. An interface object is obtained from the request parameter, and a preferred read-write separation rule corresponding to each of the application identification information is created according to the importance level to which the interface object belongs.
5. The application of the pipe control gateway of claim 4, wherein, Further comprising: S4, when the preset read-write separation rule is updated, the application is notified to reload the new preset read-write separation rule.
6. The application of the pipe control gateway of claim 4, wherein, The key information is sent to the application corresponding to each of the application identification information. The key information contained in the request header of the external request is sent to all the applications in the request header transmission mode.
Citation Information
Patent Citations
Data read-write method and system
CN111339131A
System and method for dynamic read-write separation of database
CN117251500A