Host Data Double-Writing Method and Device
By intercepting and parsing online transaction requests and transaction submission transaction instructions, data update service call packets for the host data service platform are generated, which solves the problems of high development costs and business logic intrusion in the host database dual write process, and realizes efficient and accurate data dual write operations.
Patent Information
- Application Number
- CN202111403038.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-11-24
AI Technical Summary
The existing technology requires adding new calling code in the process of double writing of host databases, resulting in high development costs and intrusion of platform business logic code, affecting the continuity of business functions and rapid retelling capabilities.
By intercepting when online transaction requests and transactions submit transaction instructions, analyzing database update operation requests, generating update record query requests, and synchronizingly generating data update service call messages of the host data service platform, the data double-write operation of the host database is performed independently of the business processing logic.
It improves the efficiency and accuracy of dual writing of host data, reduces development costs, and does not affect business logic, and supports rapid shutdown of the host.
Smart Images

Figure CN114153856B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data backup and can also be used in the financial field. Specifically, it relates to a method and device for dual-writing host data. Background Art
[0002] In the construction process of the lower host platform, to ensure the continuity of business functions and support rapid host rollback in case of platform failures, in the prior art, the dual-writing of the host database is usually achieved by calling the host data update interface corresponding to each function or the MDSP (Mainframe Data Service Platform) data update service in the platform service. This leads to the need to add new call codes, high development costs, and the need for each business function to separately call the dual-writing process, which invades the platform business logic code. Summary of the Invention
[0003] Aiming at the problems in the prior art, the present application provides a method and device for dual-writing host data, which can effectively improve the efficiency and accuracy of dual-writing host data.
[0004] To solve at least one of the above problems, the present application provides the following technical solutions:
[0005] In a first aspect, the present application provides a method for dual-writing host data, including:
[0006] When an online transaction request is detected, intercept the database update operation request in the online transaction request and parse the intercepted database update operation request;
[0007] Generate an update record query request according to the parsed update operation conditions and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request;
[0008] When an online transaction commit transaction instruction is detected, intercept the online transaction commit transaction instruction, generate a data update service call message for the host data service platform according to the update record information, and execute the host database update operation according to the data update service call message.
[0009] Further, the generating an update record query request according to the parsed update operation conditions and update table name, and obtaining the update record information before and after the execution of the database update operation request according to the update record query request includes:
[0010] Determine whether the update table corresponding to the database update operation request is a technical table that does not require dual-writing. If so, perform an update operation on the main storage system according to the database update operation request;
[0011] Otherwise, generate an update record query request according to the parsed update operation conditions and update table name, and obtain the field values corresponding to the update table and the field values corresponding to the update table after the execution of the database update operation request according to the update record query request;
[0012] Determine the update record information according to the update table name, the update type corresponding to the update record query request, and the field values before and after the execution of the database update operation request.
[0013] Further, the intercepting the database update operation request in the online transaction request when monitoring the online transaction request includes:
[0014] When the online transaction request is first monitored within a set time period, put the business transaction identifier into the context of the double-write task thread and clear the update record information in the update table.
[0015] Further, the generating a data update service call message for the host data service platform according to the update record information and performing a host database update operation according to the data update service call message includes:
[0016] Judge whether there is a business transaction identifier in the context of the double-write task thread corresponding to the data update service call message. If not, return a double-write failure signal;
[0017] Otherwise, traverse and obtain the update record information in the update table, and generate a data update service call message for the host data service platform according to the update table name, update type, the field values before and after the execution of the database update operation request in the update record information, and the set message data format, so that the host data service platform performs an update operation on the slave storage system according to the data update service call message.
[0018] Further, the intercepting the database update operation request in the online transaction request when monitoring the online transaction request includes:
[0019] When monitoring the online transaction request, intercept the database update operation request in the online transaction request through the interceptor configured in the persistence layer framework configuration file, where the database update operation request is a request for performing a data update operation on the update table of the main storage system.
[0020] Further, the parsing of the intercepted database update operation request includes:
[0021] The database update operation request is parsed by a preset connection pool component, and parameter placeholders in the corresponding database operation statement are replaced with preset bound parameters to obtain a database operation statement after parameter replacement, where the database operation statement includes an update operation condition and an update table name.
[0022] In a second aspect, the present application provides a host data dual-writing device, including:
[0023] A transaction request interception module, configured to intercept the database update operation request in the online transaction request when monitoring the online transaction request, and parse the intercepted database update operation request;
[0024] An update information recording module, configured to generate an update record query request according to the parsed update operation condition and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request;
[0025] A data synchronization operation module, configured to intercept the online transaction commit transaction instruction when monitoring the online transaction commit transaction instruction, generate a data update service call message for the host data service platform according to the update record information, and perform a host database update operation according to the data update service call message.
[0026] Further, the update information recording module includes:
[0027] A main storage operation unit, configured to determine whether the update table corresponding to the database update operation request is a technical table that does not require dual writing. If so, perform an update operation on the main storage system according to the database update operation request;
[0028] An update record query unit, configured to, when determining that the update table corresponding to the database update operation request is not a technical table that does not require dual writing, generate an update record query request according to the parsed update operation condition and update table name, and obtain the field values corresponding to the update table and the field values corresponding to the update table after the execution of the database update operation request according to the update record query request;
[0029] An update record information determination unit, configured to determine the update record information according to the update table name, the update type corresponding to the update record query request, and the field values before and after the execution of the database update operation request.
[0030] Further, the transaction request interception module includes:
[0031] A business transaction identification unit, which is used to put the business transaction identification into the context of the double-writing task thread when an online transaction request is first detected within a set time period, and clear the update record information in the update table.
[0032] Further, the data synchronization operation module includes:
[0033] A business transaction identification judgment unit, which is used to judge whether there is a business transaction identification in the context of the double-writing task thread corresponding to the data update service call message. If not, it returns a double-writing failure signal;
[0034] A slave storage operation unit, which is used to traverse and obtain the update record information in the update table when it is determined that there is a business transaction identification in the context of the double-writing task thread corresponding to the data update service call message, and generate a data update service call message for the host data service platform according to the update table name, update type, field values before and after the database update operation request, and the set message data format in the update record information, so that the host data service platform performs an update operation on the slave storage system according to the data update service call message.
[0035] In a third aspect, the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps of the host data double-writing method described above.
[0036] In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the steps of the host data double-writing method described above.
[0037] As can be seen from the above technical solutions, the present application provides a host data double-writing method and device. By intercepting the online transaction request and the online transaction submission transaction instruction in a timely manner, synchronously generating a data update service call message for the host data service platform, and accurately performing the double-writing operation of the host database master-slave storage system independently of the business processing logic, the efficiency and accuracy of host data double-writing can be effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0039] Figure 1 It is one of the flow diagrams of the host data double-writing method in the embodiments of the present application;
[0040] Figure 2 It is the second flowchart of the host data dual-writing method in the embodiments of the present application;
[0041] Figure 3 It is the third flowchart of the host data dual-writing method in the embodiments of the present application;
[0042] Figure 4 It is the first structural diagram of the host data dual-writing device in the embodiments of the present application;
[0043] Figure 5 It is the second structural diagram of the host data dual-writing device in the embodiments of the present application;
[0044] Figure 6 It is the third structural diagram of the host data dual-writing device in the embodiments of the present application;
[0045] Figure 7 It is the fourth structural diagram of the host data dual-writing device in the embodiments of the present application;
[0046] Figure 8 It is the structural diagram of the electronic device in the embodiments of the present application. Detailed implementation manners
[0047] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0048] Considering that to ensure the continuity of business functions and support quick host rollback in case of platform failures, in the prior art, the dual-writing of the host database is usually performed by calling the host data update interface corresponding to each function or the MDSP (Mainframe Data Service Platform) data update service in the platform service, which results in the need to add new call codes, high development costs, and the need for each business function to separately call the dual-writing process, which invades the platform business logic code. The present application provides a host data dual-writing method and device. By intercepting the online transaction request and the online transaction submission transaction instruction in a timely manner, synchronously generating the data update service call message of the host data service platform, and accurately performing the dual-writing operation of the master-slave storage system of the host database independently of the business processing logic, the dual-writing efficiency and accuracy of the host data can be effectively improved.
[0049] To effectively improve the efficiency and accuracy of dual writing of host data, this application provides an embodiment of a method for dual writing host data. Refer to Figure 1 The method for dual writing host data specifically includes the following content:
[0050] Step S101: When an online transaction request is detected, intercept the database update operation request in the online transaction request, and parse the intercepted database update operation request.
[0051] Optionally, this application can define the entry of entities such as online services or batch processing as the pointcut of Spring (a JavaWeb development framework). When an online transaction occurs (i.e., an online transaction request is detected) or batch processing starts, the aspect will be triggered. Optionally, this application can put the business transaction identifier into the context of the dual writing thread within the aspect to sequentially identify that the dual writing thread enters business transaction processing, and at the same time clear the record information in the set update table.
[0052] Optionally, in the above step S101, this application can configure an interceptor in the Mybatis (a Java-based persistence layer framework) configuration file of the project to intercept the database update operation request or the online transaction submission transaction instruction. After intercepting the online transaction request sent by the client, this application can obtain or identify the database update operation request from it. The database update operation request refers to a request for performing data update operations such as addition, deletion, and modification on the update table (i.e., the target data table) of the main storage system.
[0053] Optionally, in the above step S101, the parsing of the intercepted database update operation request can be to replace the parameter placeholder in the database update operation request (i.e., the SQL request) with a preset bound parameter to obtain the finally executed SQL.
[0054] Specifically, this application can parse the SQL statement through the SQL parsing tool of druid (a JDBC connection pool component).
[0055] Step S102: Generate an update record query request according to the parsed update operation conditions and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request.
[0056] Optionally, after parsing the database update operation request, the update operation conditions (such as the where condition) and the updated table name (i.e., the table name of the target data table) can be obtained, and an update record query request can be generated accordingly. That is, before and after the update is executed, query using "table name + where condition" to obtain the table record values before and after the update, that is, the update record information, and cache it in the double-write thread context.
[0057] Step S103: When the online transaction submission transaction instruction is detected, intercept the online transaction submission transaction instruction, generate a data update service call message for the host data service platform according to the update record information, and execute the host database update operation according to the data update service call message.
[0058] Optionally, when the online transaction initiates a submission transaction instruction, the interceptor of the present application can intercept the online transaction submission transaction instruction, read the cached update record information mentioned above, and assemble it into a message for calling the data update service of the MDSP (host data service platform) to be used to call the MDSP service to implement the data update of the host database from the storage system.
[0059] As can be seen from the above description, the host data double-write method provided by the embodiments of the present application can intercept the online transaction request and the online transaction submission transaction instruction in a timely manner, synchronously generate a data update service call message for the host data service platform, and accurately execute the data double-write operation of the host database master-slave storage system independently of the business processing logic, thereby effectively improving the efficiency and accuracy of the host data double-write.
[0060] In order to accurately obtain the update record information of the primary storage system before and after the update, in an embodiment of the host data double-write method of the present application, see Figure 2 , the above step S102 may further specifically include the following content:
[0061] Step S201: Determine whether the updated table corresponding to the database update operation request is a technical table that does not require double-writing. If so, perform an update operation on the primary storage system according to the database update operation request.
[0062] Step S202: Otherwise, generate an update record query request according to the parsed update operation conditions and the updated table name, and obtain the field values corresponding to the updated table and the field values corresponding to the updated table after the execution of the database update operation request according to the update record query request.
[0063] Step S203: Determine the update record information according to the updated table name, the update type corresponding to the update record query request, and the field values before and after the execution of the database update operation request.
[0064] Optionally, after parsing the database update operation request, the update operation conditions (such as the where condition) and the updated table name (i.e., the table name of the target data table) can be obtained, and an update record query request can be generated accordingly. That is, before and after the update is executed, the query is performed using "table name + where condition" to obtain the table record values before and after the update, that is, the update record information, and it is cached in the double-write thread context.
[0065] For example, first parse the SQL statement through the SQL parsing tool of Druid.
[0066] If it is determined to be an update statement after parsing, obtain the where condition for the update and the updated table name, and then perform a query using the table name + where condition before and after the update is executed to obtain the table record values before and after the update.
[0067] If it is determined to be an insert statement after parsing, parse each column name and the corresponding column value through the SQL parsing tool of Druid, and then store them in a HashMap.
[0068] If it is determined to be a delete statement after parsing, obtain the where condition for the deletion and the deleted table name, and then perform a query using the table name + where condition before the update is executed to obtain the content of the deleted record.
[0069] Then, convert the records before and after the update into a JSON format string, and save the table name of the updated table record, the update type (insert, update, delete), and the field values before and after the update in the transaction thread context in the format shown in Table 1 below:
[0070] Table 1 Format of the update record information table
[0071] Table Name 1 Operation Type 1 Value Before Operation 1 Value After Operation 1 Table Name 2 Operation Type 2 Value Before Operation 2 Value After Operation 2 Table Name 3 Operation Type 3 Value Before Operation 3 Value After Operation 3
[0072] During the actual execution process, it is stored as shown in Table 2 below:
[0073] Table 2 Example of the update record information table
[0074]
[0075] In order to accurately perform the data double-write operation for the online transaction request triggered by the business, in an embodiment of the host data double-write method of the present application, the above step S101 may further specifically include the following content:
[0076] When the online transaction request is first detected within the set time period, put the business transaction identifier into the double-write task thread context and clear the update record information in the updated table.
[0077] Optionally, when the online transaction request is first detected within a set time period in this application, the business transaction identifier is placed into the double-write task thread context, and the update record information in the update table is cleared. Thus, when intercepting the transaction submission action subsequently, it is determined whether there is a business transaction identifier in the double-write thread context. If not, it indicates that it is triggered by non-business processing, and a double-write failure signal is directly returned.
[0078] In order to accurately double-write data to the slave storage system, in an embodiment of the host data double-write method of this application, refer to Figure 3 , the above step S103 may further specifically include the following content:
[0079] Step S301: Determine whether there is a business transaction identifier in the double-write task thread context corresponding to the data update service call message. If not, return a double-write failure signal.
[0080] Step S302: Otherwise, traverse to obtain the update record information in the update table, and generate a data update service call message for the host data service platform according to the update table name, update type, field values before and after the database update operation request, and the set message data format in the update record information, so that the host data service platform performs an update operation on the slave storage system according to the data update service call message.
[0081] Optionally, when it is determined that the double-write thread context contains a business transaction identifier and the update record information is not empty, traverse the update record information and assemble a data message for calling the MDSP service according to the update table name, update type, field values before and after the database update operation request, and the set message data format in the update record information.
[0082] Optionally, after receiving the message sent from the platform, MDSP can convert the JOSN message data into a table processing object. When it comes to Chinese ASCII codes, to avoid garbled characters when inserting data, the field type of the ASCII code in the host table can be modified to char for bit format, and this field type is defined as byte[] in the sqlj program.
[0083] Then, MDSP calls each table processor to perform data update processing. Each table processor defines methods for addition, deletion, and modification. Among them, the deletion operation is updated according to the unique index of the table, and the modification operation is a full-table update according to the unique index of the table.
[0084] Meanwhile, if an update exception occurs, an error is returned to let the platform side synchronously roll back to ensure data consistency at both ends.
[0085] In order to effectively improve the efficiency and accuracy of dual writing of host data, this application provides an embodiment of a host data dual writing device for implementing all or part of the content of the host data dual writing method. Refer to Figure 4 , the host data dual writing device specifically includes the following content:
[0086] A transaction request interception module 10, configured to intercept a database update operation request in the online transaction request when detecting an online transaction request, and parse the intercepted database update operation request.
[0087] An update information recording module 20, configured to generate an update record query request according to the parsed update operation conditions and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request.
[0088] A data synchronization operation module 30, configured to intercept the online transaction commit transaction instruction when detecting an online transaction commit transaction instruction, generate a data update service call message for the host data service platform according to the update record information, and execute the host database update operation according to the data update service call message.
[0089] As can be seen from the above description, the host data dual writing device provided by the embodiment of this application can effectively improve the efficiency and accuracy of host data dual writing by timely intercepting the online transaction request and the online transaction commit transaction instruction, synchronously generating a data update service call message for the host data service platform, and accurately executing the data dual writing operation of the host database master-slave storage system independently of the business processing logic.
[0090] In order to accurately obtain the update record information of the main storage system before and after the update, in an embodiment of the host data dual writing device of this application, refer to Figure 5 , the update information recording module 20 includes:
[0091] A main storage operation unit 21, configured to determine whether the update table corresponding to the database update operation request is a technical table that does not require dual writing. If so, perform an update operation on the main storage system according to the database update operation request.
[0092] An update record query unit 22, configured to, when determining that the update table corresponding to the database update operation request is not a technical table that does not require dual writing, generate an update record query request according to the parsed update operation conditions and update table name, and obtain the field values corresponding to the update table and the field values corresponding to the update table after the execution of the database update operation request according to the update record query request.
[0093] An update record information determination unit 23, configured to determine update record information according to the update table name, the update type corresponding to the update record query request, and the field values before and after the database update operation request.
[0094] In order to accurately perform data dual-writing operations for online transaction requests triggered by services, in an embodiment of the host data dual-writing device of the present application, refer to Figure 6 , the transaction request interception module 10 includes:
[0095] A service transaction identification unit 11, configured to, when an online transaction request is first detected within a set time period, put the service transaction identification into the dual-writing task thread context and clear the update record information in the update table.
[0096] In order to accurately dual-write data to the slave storage system, in an embodiment of the host data dual-writing device of the present application, refer to Figure 7 , the data synchronization operation module 30 includes:
[0097] A service transaction identification judgment unit 31, configured to judge whether there is a service transaction identification in the dual-writing task thread context corresponding to the data update service call message. If not, return a dual-writing failure signal.
[0098] A slave storage operation unit 32, configured to, when it is determined that there is a service transaction identification in the dual-writing task thread context corresponding to the data update service call message, traverse and obtain the update record information in the update table, and generate a data update service call message for the host data service platform according to the update table name, update type, the field values before and after the database update operation request, and the set message data format in the update record information, so that the host data service platform performs an update operation on the slave storage system according to the data update service call message.
[0099] To further illustrate the present solution, the present application also provides a specific application example of implementing the host data dual-writing method using the above host data dual-writing device, which specifically includes the following content:
[0100] 1. Initialize the dual-writing thread context
[0101] (1) Define the entry of the online service or batch processing entity as the pointcut of Spring. When an online transaction occurs or batch processing starts, the aspect will be triggered.
[0102] (2) Define the above aspect. Inside the aspect, put the service transaction flag into the thread context to mark that the thread enters service transaction processing, and at the same time clear the content of the dual-writing table records.
[0103] 2. Intercept the update SQL
[0104] (1) The interceptors configured in the Mybatis configuration file of the project intercept the update and transaction submission processing.
[0105] (2) Intercept the update SQL, replace the parameter placeholder in the SQL with the bound parameter, and obtain the finally executed SQL.
[0106] (3) Judge that if the table name currently being operated on is a technical table that does not require double writing, skip the subsequent parsing process and return directly.
[0107] (4) Parse the update statement, parse the SQL statement through the SQL parsing tool of Druid, judge that if it is an update SQL, obtain the update where condition and the updated table name, and then query using the table name + where condition before and after the update to obtain the table record values before and after the update.
[0108] (5) Parse the insert statement, parse each column name and the corresponding column value through the SQL parsing tool of Druid, and then store them in a HashMap.
[0109] (6) Parse the delete statement, parse the SQL statement through the SQL parsing tool of Druid, judge that if it is a delete SQL, obtain the delete where condition and the deleted table name, and then query using the table name + where condition before the update to obtain the content of the deleted record.
[0110] (7) Convert the records before and after the update into a JSON format string.
[0111] (8) Save the table name of the updated table record, the update type (insert, update, delete), and the field values before and after the update in the transaction thread context in the set format.
[0112] 3. Intercept the transaction submission action and call the MDSP service for double writing.
[0113] (1) Intercept the transaction submission action, judge whether there is a double writing flag in the thread context. If not, it means it is triggered by non-business processing and return directly.
[0114] (2) Judge whether the update content list in the thread context is empty. If not, traverse the update records and assemble the data message for calling the MDSP service.
[0115] 4. MDSP service double writing processing
[0116] (1) Receive the message sent from the platform, convert the JOSN message data into a table processing object, and the definition format of the table processing object is as follows:
[0117] TableData{
[0118] private List <tablerecord>before;
[0119] private List <tablerecord>after;
[0120] }
[0121] (2) When it comes to Chinese ASCII codes, to avoid garbled characters when inserting data, modify the field type of the fields involving ASCII codes in the host table to char for bit format, and define this field type as byte[] in the sqlj program.
[0122] (3) Call each table processor to perform data update processing. Each table processor defines methods for addition, deletion, and modification. Among them, the deletion operation is updated according to the unique index of the table, and the modification operation performs a full-table update according to the unique index of the table.
[0123] (4) If an exception occurs during the update, return an error message to let the platform side synchronously roll back to ensure data consistency between the two ends.
[0124] As can be seen from the above content, the present application can at least further achieve the following technical effects:
[0125] 1. Using the Spring aspect and MyBatis interceptor methods, it is transparent to developers of new platform functions, reducing the difficulty of implementing dual writing of the host.
[0126] 2. Decoupled from specific business rules, applicable to all host scenarios below, the platform processing can be componentized, and the MDSP program implementation can be tooled, achieving the effect of writing once and directly reusing by each application.
[0127] From the hardware level, in order to effectively improve the efficiency and accuracy of dual writing of host data, the present application provides an embodiment of an electronic device for implementing all or part of the content in the method for dual writing of host data. The electronic device specifically includes the following content:
[0128] A processor, a memory, a communication interface, and a bus; wherein, the processor, the memory, and the communication interface complete mutual communication through the bus; the communication interface is used to implement information transmission between the host data dual writing device and related devices such as the core business system, the user terminal, and the related database. The logical controller can be a desktop computer, a tablet computer, a mobile terminal, etc., and this embodiment is not limited thereto. In this embodiment, the logical controller can be implemented with reference to the embodiments of the method for dual writing of host data and the embodiments of the host data dual writing device in the embodiments, and the content is incorporated herein, and the repeated parts will not be elaborated.
[0129] It can be understood that the user terminal may include a smart phone, a tablet electronic device, a network set-top box, a portable computer, a desktop computer, a personal digital assistant (PDA), a vehicle-mounted device, a smart wearable device, etc. Among them, the smart wearable device may include smart glasses, smart watches, smart bracelets, etc.
[0130] In practical applications, part of the host data dual-writing method may be executed on the side of the electronic device as described above, or all operations may be completed in the client device. Specifically, it can be selected according to the processing capacity of the client device and the limitations of the user usage scenario, etc. This application does not make any limitations in this regard. If all operations are completed in the client device, the client device may further include a processor.
[0131] The above-mentioned client device may have a communication module (i.e., a communication unit), and may be communicatively connected to a remote server to achieve data transmission with the server. The server may include a server on the task scheduling center side, and in other implementation scenarios, it may also include a server of an intermediate platform, such as a server of a third-party server platform communicatively linked to the task scheduling center server. The server may include a single computer device, or may include a server cluster composed of multiple servers, or a server structure of a distributed device.
[0132] Figure 8 It is a schematic block diagram of the system composition of the electronic device 9600 according to an embodiment of the present application. As Figure 8 shown, the electronic device 9600 may include a central processing unit 9100 and a memory 9140; the memory 9140 is coupled to the central processing unit 9100. It should be noted that this Figure 8 is exemplary; other types of structures may also be used to supplement or replace this structure to implement telecommunication functions or other functions.
[0133] In one embodiment, the function of the host data dual-writing method may be integrated into the central processing unit 9100. Among them, the central processing unit 9100 may be configured to perform the following controls:
[0134] Step S101: Intercept the database update operation request in the online transaction request when monitoring the online transaction request, and parse the intercepted database update operation request.
[0135] Step S102: Generate an update record query request according to the parsed update operation conditions and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request.
[0136] Step S103: When a transaction instruction for an online transaction submission is detected, intercept the transaction instruction for the online transaction submission, generate a data update service call message for the host data service platform according to the updated record information, and perform a host database update operation according to the data update service call message.
[0137] As can be seen from the above description, the electronic device provided by the embodiment of the present application can effectively improve the data dual-writing efficiency and accuracy of the host database by timely intercepting the online transaction request and the transaction instruction for the online transaction submission, synchronously generating a data update service call message for the host data service platform, and accurately performing the data dual-writing operation of the master-slave storage system of the host database independently of the service processing logic.
[0138] In another embodiment, the host data dual-writing device can be separately configured from the central processing unit 9100. For example, the host data dual-writing device can be configured as a chip connected to the central processing unit 9100, and the function of the host data dual-writing method can be implemented through the control of the central processing unit.
[0139] As Figure 8 shown, the electronic device 9600 may further include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It should be noted that the electronic device 9600 does not necessarily have to include Figure 8 all the components shown in Figure 8 ; in addition, the electronic device 9600 may further include
[0140] As Figure 8 shown, the central processing unit 9100 is sometimes also referred to as a controller or an operation control, and may include a microprocessor or other processor devices and / or logic devices. The central processing unit 9100 receives inputs and controls the operations of the various components of the electronic device 9600.
[0141] Among them, the memory 9140 may be, for example, one or more of a buffer, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory, or other suitable devices. The above information related to failures can be stored, and in addition, programs for executing relevant information can also be stored. And the central processing unit 9100 can execute the program stored in the memory 9140 to implement information storage or processing, etc.
[0142] The input unit 9120 provides inputs to the central processing unit 9100. The input unit 9120 is, for example, a key or a touch input device. The power supply 9170 is used to supply power to the electronic device 9600. The display 9160 is used for displaying display objects such as images and texts. The display may be, for example, an LCD display, but is not limited thereto.
[0143] The memory 9140 can be a solid-state memory, for example, a read-only memory (ROM), a random access memory (RAM), a SIM card, etc. It can also be a memory that stores information even when power is off, can be selectively erased and has more data. Examples of such a memory are sometimes referred to as EPROMs, etc. The memory 9140 can also be some other type of device. The memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 can include an application / function storage unit 9142, which is used to store application programs and function programs or the processes for operating the electronic device 9600 by the central processing unit 9100.
[0144] The memory 9140 can also include a data storage unit 9143, which is used to store data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 9144 of the memory 9140 can include various drivers of the electronic device for communication functions and / or for performing other functions of the electronic device (such as a messaging application, an address book application, etc.).
[0145] The communication module 9110 is a transmitter / receiver 9110 that transmits and receives signals via the antenna 9111. The communication module (transmitter / receiver) 9110 is coupled to the central processing unit 9100 to provide input signals and receive output signals, which can be the same as in the case of a conventional mobile communication terminal.
[0146] Based on different communication technologies, multiple communication modules 9110 can be provided in the same electronic device, such as a cellular network module, a Bluetooth module, and / or a wireless local area network module, etc. The communication module (transmitter / receiver) 9110 is also coupled to the speaker 9131 and the microphone 9132 via the audio processor 9130 to provide an audio output via the speaker 9131 and receive an audio input from the microphone 9132, thereby implementing normal telecommunication functions. The audio processor 9130 can include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor 9130 is also coupled to the central processing unit 9100, so that recording can be performed on the local machine through the microphone 9132 and the sound stored on the local machine can be played through the speaker 9131.
[0147] Embodiments of the present application also provide a computer-readable storage medium capable of implementing all steps of the host data dual-writing method in which the execution entity in the above embodiments is a server or a client. A computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, all steps of the host data dual-writing method in which the execution entity in the above embodiments is a server or a client are implemented. For example, when the processor executes the computer program, the following steps are implemented:
[0148] Step S101: When an online transaction request is monitored, intercept the database update operation request in the online transaction request, and parse the intercepted database update operation request.
[0149] Step S102: Generate an update record query request according to the parsed update operation conditions and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request.
[0150] Step S103: When an online transaction commit transaction instruction is monitored, intercept the online transaction commit transaction instruction, generate a data update service call message for the host data service platform according to the update record information, and execute the host database update operation according to the data update service call message.
[0151] As can be seen from the above description, the computer-readable storage medium provided by the embodiments of the present application can effectively improve the efficiency and accuracy of host data dual-writing by timely intercepting online transaction requests and online transaction commit transaction instructions, synchronously generating data update service call messages for the host data service platform, and accurately executing the data dual-writing operation of the host database master-slave storage system independently of the business processing logic.
[0152] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, an apparatus, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0153] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatus (devices), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, such that the instructions executed by the processor of the computer or other programmable data processing device generate a means for implementing the functions specified in one or more flows and / or blocks in the flowchart. Figure 1 in one or more flows and / or blocks Figure 1 or in one or more blocks.
[0154] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including an instruction means that implements the functions specified in one or more flows and / or blocks in the flowchart. Figure 1 in one or more flows and / or blocks Figure 1 or in one or more blocks.
[0155] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more flows and / or blocks in the flowchart. Figure 1 in one or more flows and / or blocks Figure 1 or in one or more blocks.
[0156] Specific embodiments of the present invention are used to elaborate on the principles and implementation manners of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation on the present invention.< / tablerecord> < / tablerecord>
Claims
1. A method for double writing host data, characterized in that The method includes: When an online transaction request is detected, intercept the database update operation request in the online transaction request, and parse the intercepted database update operation request; Generate an update record query request according to the parsed update operation conditions and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request; When an online transaction commit transaction instruction is detected, intercept the online transaction commit transaction instruction, generate a data update service call message for the host data service platform according to the update record information, and perform a host database update operation according to the data update service call message; Determine whether there is a business transaction identifier in the double-write task thread context corresponding to the data update service call message, if not, return a double-write failure signal; Otherwise, traverse and obtain the update record information in the update table, and generate a data update service call message for the host data service platform according to the update table name, update type, field values before and after the execution of the database update operation request, and the set message data format, so that the host data service platform performs an update operation on the slave storage system according to the data update service call message.
2. The host data double-writing method according to claim 1, wherein The generating an update record query request according to the parsed update operation conditions and update table name, and obtaining the update record information before and after the execution of the database update operation request according to the update record query request includes: Determine whether the update table corresponding to the database update operation request is a technical table that does not require double writing. If so, perform an update operation on the primary storage system according to the database update operation request; Otherwise, generate an update record query request according to the parsed update operation conditions and update table name, and obtain the field values corresponding to the update table and the field values corresponding to the update table after the execution of the database update operation request according to the update record query request; Determine the update record information according to the update table name, the update type corresponding to the update record query request, and the field values before and after the execution of the database update operation request.
3. The method for dual-writing host data according to claim 1, wherein The intercepting the database update operation request in the online transaction request when an online transaction request is detected includes: When an online transaction request is first detected within a set time period, put the business transaction identifier into the double-write task thread context and clear the update record information in the update table.
4. The method for double writing host data according to claim 1, wherein The intercepting the database update operation request in the online transaction request when an online transaction request is detected includes: When an online transaction request is detected, intercept the database update operation request in the online transaction request through an interceptor configured in the persistence layer framework configuration file, where the database update operation request is a request for performing a data update operation on the update table of the primary storage system.
5. The method for dual writing of host data according to claim 1, characterized in that The parsing the intercepted database update operation request includes: The database update operation request is parsed by a preset connection pool component, and parameter placeholders in the corresponding database operation statement are replaced with preset bound parameters to obtain a database operation statement after parameter replacement, where the database operation statement includes an update operation condition and an update table name.
6. A host data double-writing device, characterized in that, It includes: A transaction request interception module, configured to intercept the database update operation request in the online transaction request when an online transaction request is detected, and parse the intercepted database update operation request; An update information recording module, configured to generate an update record query request according to the parsed update operation condition and update table name, and obtain the update record information before and after the execution of the database update operation request according to the update record query request; A data synchronization operation module, configured to intercept the online transaction commit transaction instruction when an online transaction commit transaction instruction is detected, generate a data update service call message for the host data service platform according to the update record information, and perform a host database update operation according to the data update service call message; determine whether there is a business transaction identifier in the context of the dual-write task thread corresponding to the data update service call message, and if not, return a dual-write failure signal; Otherwise, traverse to obtain the update record information in the update table, and generate a data update service call message for the host data service platform according to the update table name, update type, field values before and after the execution of the database update operation request, and the set message data format in the update record information, so that the host data service platform performs an update operation on the slave storage system according to the data update service call message.
7. The host data double-writing device according to claim 6, characterized in that The update information recording module includes: A main storage operation unit, configured to determine whether the update table corresponding to the database update operation request is a technical table that does not require dual writing. If so, update the main storage system according to the database update operation request; An update record query unit, configured to generate an update record query request according to the parsed update operation condition and update table name when it is determined that the update table corresponding to the database update operation request is not a technical table that does not require dual writing, and obtain the field values corresponding to the update table and the field values corresponding to the update table after the execution of the database update operation request according to the update record query request; An update record information determination unit, configured to determine the update record information according to the update table name, the update type corresponding to the update record query request, and the field values before and after the execution of the database update operation request.
8. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, the steps of the host data dual-write method according to any one of claims 1 to 5 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the host data dual-write method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Data collection method, device, equipment and readable storage medium
CN111625552A
Database synchronization method, system and device, electronic equipment and medium
CN113094434A