Database double-writing method, device, equipment, medium and product
By receiving application requests to control the operation of the first database and the second database, the problem of inaccuracy in dual database writing under the background of full-stack localization is solved, and the accuracy and consistency of dual database writing are achieved.
Patent Information
- Application Number
- CN202311235480.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-22
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2043-09-22
AI Technical Summary
Under the current technology and the background of full-stack localization, the write operation results of database A and database B are different or the accurate dual-write function of databases cannot be achieved.
By receiving requests from the application to the first database, the system controls the first database to perform operations. Upon the application's termination instruction, the system controls the second database to perform corresponding operations based on the request type. This includes distinguishing between non-transactional dual-write and transactional dual-write types. The system utilizes the Mybatis technology stack and asynchronous task management to manage transaction links, ensuring the accuracy of dual-write operations on the database.
The dual-write functionality of the database is accurate, ensuring data consistency and integrity under different hardware and operating system environments.
Smart Images

Figure CN117194575B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of data storage, and particularly relates to a database double-writing method, device, equipment, medium and product. BACKGROUND
[0002] In the prior art, after an application program writes a database A successfully, a database synchronization tool is used to change related data to a database B. However, due to the difference in hardware and operating systems involved in the technology background of full-stack domestication, and the database synchronization tool is not verified in the above technical background, so that the results of executing write operations of the database A and the database B are different, or the function of database double-writing cannot be realized, that is, the functional accuracy of database double-writing cannot be guaranteed. SUMMARY
[0003] The application embodiment provides a database double-writing method and device, equipment, medium and product, which guarantees the functional accuracy of database double-writing.
[0004] In a first aspect, the application embodiment provides a database double-writing method, which comprises:
[0005] receiving a request sent by an application program for a first database, the request comprising a request execution type;
[0006] in response to the request, controlling the first database to execute a first operation corresponding to the request;
[0007] in response to an end instruction of the first database executing the first operation, controlling a second database to execute the first operation corresponding to the request based on the request execution type, the first database and the second database being relational databases.
[0008] In an optional implementation of the first aspect, the response to the end instruction of the first database executing the first operation, the control of the second database to execute the first operation corresponding to the request based on the request execution type comprises:
[0009] in response to the end instruction of the first database executing the first operation, in the case where the request execution type is a first execution type, obtaining an execution parameter of the first database executing the first operation;
[0010] sending the execution parameter to the second database based on a first link, so as to be used for the second database to execute the first operation based on the execution parameter, the first link being a link for accessing the second database created in response to a start input of the application program.
[0011] In an optional implementation of the first aspect, in response to the end instruction of the first database executing the first operation, the second database is controlled to execute the first operation corresponding to the request based on the request execution type, including:
[0012] In response to the end instruction of the first database executing the first operation, in a case where the request execution type is the second execution type, a transaction identifier corresponding to the request and an execution parameter of the first database executing the first operation are obtained;
[0013] In a case where the second link corresponding to the transaction identifier does not exist in the cache, the second link corresponding to the transaction identifier is initialized, and the execution parameter of the first database executing the first operation is sent to the second database based on the second link, so as to be used by the second database to execute the first operation based on the execution parameter.
[0014] In an optional implementation of the first aspect, the method further includes:
[0015] In a case where the second link corresponding to the transaction identifier exists in the cache, the execution result of the second operation is obtained from the cache;
[0016] Based on the second link, the execution parameter used to execute the first operation and the execution result of the second operation are sent to the second database, so as to be used by the second database to execute the operation corresponding to the request based on the execution parameter of the first operation after determining that the second operation is executed completely;
[0017] The second operation is a previous operation of the first operation in a transaction corresponding to the transaction ID, and the transaction includes a plurality of operations and an operation sequence of the plurality of operations.
[0018] In an optional implementation of the first aspect, the method further includes:
[0019] The execution result of the first operation is stored to the cache.
[0020] In an optional implementation of the first aspect, the method further includes:
[0021] In response to the end instruction of the first database executing the transaction corresponding to the transaction identifier, in a case where the execution result of the last operation in the transaction executed by the second database is obtained, the cache is cleaned up.
[0022] In the second aspect, an embodiment of the present application provides a database double-writing device, which includes:
[0023] The receiving module is configured to receive a request sent by an application program to the first database, and the request includes a request execution type;
[0024] The control module is configured to control the first database to execute a first operation corresponding to the request in response to the request;
[0025] The control module is configured to, in response to an end instruction of the first database performing the first operation, control the second database to perform the first operation corresponding to the request based on a request execution type, the first database and the second database being relational databases.
[0026] In a third aspect, an electronic device is provided, including: a memory configured to store computer program instructions; and a processor configured to read and run the computer program instructions stored in the memory to execute the database double-write method provided in any of the optional implementation manners of the first aspect.
[0027] In a fourth aspect, a computer storage medium is provided, and the computer storage medium stores computer program instructions. When the computer program instructions are executed by a processor, the database double-write method provided in any of the optional implementation manners of the first aspect is implemented.
[0028] In a fifth aspect, a computer program product is provided. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the database double-write method provided in any of the optional implementation manners of the first aspect.
[0029] In the embodiments of the present application, the request sent by the application program to the first database can be received, and then the first operation corresponding to the request can be controlled to be performed by the first database in response to the request. Since the request can include a request execution type, the first operation corresponding to the request can be controlled to be performed by the second database in response to an end instruction of the first database performing the first operation based on the request execution type. In this way, the database double-write is realized by receiving the request sent by the application program layer, and the functional accuracy of the database double-write is ensured. BRIEF DESCRIPTION OF DRAWINGS
[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments of the present application will be briefly introduced. Those skilled in the art can obtain other drawings according to these drawings without creating any creative labor.
[0031] Figure 1 is a flowchart of a database double-write method provided by the embodiments of the present application;
[0032] Figure 2 is a structural schematic diagram of a database double-write device provided by the embodiments of the present application;
[0033] Figure 3 is a structural schematic diagram of an electronic device provided by the embodiments of the present application. DETAILED DESCRIPTION
[0034] The features and exemplary embodiments of various aspects of the present application will be described below in detail, in order to make the purposes, technical solutions and advantages of the present application more clear and apparent, the present application will be further described in detail below in combination with the drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, but not to limit the present application. The present application can be implemented without some of these specific details for those skilled in the art. The following description of the embodiments is only to provide a better understanding of the present application by showing examples of the present application. In addition, it should be noted that the acquisition, storage, use, processing and other data in the technical solutions of the present application comply with the relevant provisions of national laws and regulations.
[0035] It should be noted that, in this paper, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the elements defined by the statement "include" do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0036] The term "and / or" in this paper is only a description of the association relationship between the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone.
[0037] In order to solve the problem that the correctness of the function of database double writing cannot be guaranteed in the prior art, the embodiments of the present application provide a database double writing method, device, equipment, medium and product, which can receive a request sent by an application program to a first database, and then can control the first database to execute a first operation corresponding to the request in response to the request. And since the request can include a request execution type, the second database can execute the first operation corresponding to the request based on the request execution type in response to the end instruction of the first database executing the first operation. In this way, the database double writing is realized by receiving the request sent by the application program layer, and the functional accuracy of the database double writing is guaranteed.
[0038] In addition, it should be noted that the database double-writing method provided in the embodiments of the present application can be executed by a database double-writing device or a control module in the database double-writing device for executing the database double-writing method. In the embodiments of the present application, the database double-writing method is executed by the database double-writing device, and the data method provided in the embodiments of the present application is taken as an example.
[0039] The database double-writing method provided in the embodiments of the present application will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0040] The embodiments of the present application provide a flowchart of a database double-writing method. As shown in the figure, the execution subject of the database double-writing method can be a database double-writing device, and the method can specifically include the following steps: Figure 1
[0041] S110, receiving a request sent by an application program for a first database.
[0042] The application program can be any one of a plurality of application programs running in the system, which is not limited here. In addition, the above-mentioned request can include a request execution type, which can be a non-transaction double-writing type and a transaction double-writing type. In addition, it should be noted that the request can be a structured query language (SQL) request.
[0043] It should be noted that the above-mentioned application program can be a Java application program obtained by using a Spring+Mybatis technology stack, and accordingly, the data double-writing method provided in the embodiments of the present application is designed by using Spring+Mybatis. That is, the application program using the Spring+Mybatis technology stack can implement database double-writing by using the database double-writing method provided in the embodiments of the present application.
[0044] S120, in response to the request, controlling the first database to execute a first operation corresponding to the request.
[0045] Specifically, after receiving the request sent by the application program for the first database, the database double-writing device can control the first database to execute a first operation corresponding to the request in response to the request. The first operation can be a write operation, which is not described in detail here.
[0046] S130, in response to an end instruction of the first database executing the first operation, controlling the second database to execute the first operation corresponding to the request based on the request execution type.
[0047] In some embodiments, the first database and the second database are relational databases.
[0048] Specifically, the database double-writing apparatus can respond to an end instruction of the first database performing the first operation, i.e., the database can control the second database to perform the first operation corresponding to the request based on the request execution type included in the request after the first database finishes performing the first operation.
[0049] It should be noted that the database double-writing method provided by the embodiments of the present application distinguishes the request execution type when performing double writing on the first database and the second database, i.e., the request execution type includes a non-transaction double-writing type and a transaction double-writing type. Specifically, the non-transaction double-writing type refers to an automatically committed SQL statement, and when writing to the second database, transaction control is not needed; the transaction double-writing type refers to a SQL statement that is not automatically committed, and when writing to the second database, the transaction link of the second database needs to be cached according to the transaction ID of the first database to manage and control the transaction of the second database. It should be noted that whether the transaction is started can be confirmed according to the isAutoCommit attribute of the connection: when the transaction is started, isAutoCommit is false, and when the transaction is not started, isAutoCommit is true. For the above two types of double writing, different thread pools can be configured as needed to meet the database double-writing needs of different types of application programs.
[0050] In one example, the database double-writing apparatus can receive a write request of an application program to the first database, and intercept the write request through the Interceptor of Mybatis to control the first database to perform a write operation corresponding to the write request, and after the first database finishes performing the write operation, judge the request execution type of the write request. Specifically, when the request execution type of the write request is automatic submission (Connection.isAutoCommit=true), i.e., the request execution type of the write request is a non-transaction double-writing type, a non-transaction double-writing module is called to control the second database to perform a write operation corresponding to the write request. In addition, when the first database execution type is non-automatic submission (Connection.isAutoCommit=false), i.e., the request execution type of the write request is a transaction double-writing type, a transaction double-writing module is called to control the second database to perform a write operation corresponding to the write request.
[0051] In addition, it should be noted that the database double-writing method provided by the embodiments of the present application can further include the following steps:
[0052] In response to an end instruction of the first database performing the first operation, the execution result of the first database performing the first operation is fed back to the application program.
[0053] In this embodiment, after the first database performs the first operation, the application needs to be fed back the execution result of the first database performing the first operation.
[0054] It should be further noted that the second database can establish a data source alone, build a set of Mybatis SqlSessionFactory which is the same as the Mybatis configuration of the first database but has different data sources, thereby reusing the Myabtis configuration of the first database, without separately configuring the second database, and realizing zero-intrusion database double writing.
[0055] In the embodiments of the present application, the request sent by the application to the first database can be received, and then the first database can be controlled to perform the first operation corresponding to the request in response to the request. Since the request can include a request execution type, the second database can be controlled to perform the first operation corresponding to the request based on the request execution type in response to the end instruction of the first database performing the first operation. In this way, the database double writing is realized by receiving the request sent by the application layer, and the functional accuracy of the database double writing is ensured.
[0056] In order to more accurately describe the database double writing method provided by the embodiments of the present application, in one embodiment, the S130 mentioned above can include the following steps:
[0057] In response to the end instruction of the first database performing the first operation, the execution parameter of the first database performing the first operation is obtained in the case where the request execution type is the first execution type.
[0058] The execution parameter is sent to the second database based on the first link, so that the second database performs the first operation based on the execution parameter.
[0059] The first execution type mentioned above can be understood as a non-transaction double writing type. In addition, the execution parameter mentioned above can be a related parameter when the first database performs the first operation, such as SQL identification, SQL name, and SQL template, etc., which is not limited here.
[0060] In some embodiments, the first link mentioned above is a link for accessing the second database created in response to the start input of the application.
[0061] Specifically, the database double writing device can obtain the execution parameter of the first database performing the first operation in the case where the request execution type of the request is the first execution type in response to the end execution of the first database performing the first operation, and then the execution parameter can be sent to the second database through the first link, so that the second database can perform the first operation based on the execution parameter.
[0062] In one example, after receiving the write request, if the request execution type of the write request is the first execution type, i.e., the non-transactional double-write type, the non-transactional double-write module can be called to control the first database to execute the write operation corresponding to the write request, and after the first database completes the execution of the write operation, the execution parameters of the write operation executed by the first database are obtained, and the execution parameters are packaged into an asynchronous task, and the asynchronous task is sent to the second database through the obtained Mybatis Session, so that the second database executes the write operation based on the execution parameters.
[0063] In this embodiment, since the request execution type of the request is the first execution type, the database double-write device can control the second database to execute the first operation after the first database completes the execution of the first operation. In this way, the database double-write function is realized.
[0064] To more comprehensively describe the database double-write method provided by the embodiments of the present application, in another embodiment, the S130 mentioned above can specifically include the following steps:
[0065] In response to the end instruction of the execution of the first operation by the first database, if the request execution type is the second execution type, the transaction identifier corresponding to the request and the execution parameters of the execution of the first operation by the first database are obtained;
[0066] If the second link corresponding to the transaction identifier does not exist in the cache, the second link corresponding to the transaction identifier is initialized, and the execution parameters of the execution of the first operation by the first database are sent to the second database based on the second link, so that the second database executes the first operation based on the execution parameters.
[0067] Specifically, the database double-write device can obtain the transaction identifier corresponding to the request in response to the end instruction of the execution of the first operation by the first database, if the request execution type included in the request is the second execution type. Then, the transaction identifier can be queried in the cache. If the second link corresponding to the transaction identifier cannot be queried in the cache, i.e., the request received by the database double-write device is the first request executed in the transaction corresponding to the transaction identifier, based on this, the database double-write device can initialize the second link corresponding to the transaction identifier, and send the execution parameters of the execution of the first operation by the first database to the second database based on the second link, so that the second database executes the first operation based on the execution parameters.
[0068] It should be noted that the cache mentioned above can be a transaction double-write module for saving the transaction ID of each transaction, the Futrue object of the last execution of the transaction, and the link for accessing the second database. The transaction double-write module determines whether the transaction is started (first execution) through the link stored in the above cache. When the link corresponding to the transaction ID does not exist in the cache, it is considered that the transaction is executed for the first time, and the link corresponding to the transaction ID needs to be obtained, the transaction needs to be opened and managed. It should be noted that the transaction double-write module is implemented through the TransactionalEventListener mechanism of Spring, which is actually an event publishing mechanism. When Spring monitors the transaction end event, the event is published, and the database subscribed to the event can immediately receive the event and perform the corresponding operation.
[0069] In this embodiment, since the request execution type of the request is the second execution type, the database double-write device can obtain the transaction identifier corresponding to the request and the execution parameter of the first operation executed by the first database after the first operation executed by the first database is completed, and in the case that the second link corresponding to the transaction identifier does not exist in the cache, the second link corresponding to the transaction identifier is initialized, and the execution parameter of the first operation is sent to the second database based on the second link, so that the second database executes the first operation based on the execution parameter. In this way, the database double-write function is realized.
[0070] Based on this, in one embodiment, the database double-write method mentioned above can further include the following steps:
[0071] In the case that the second link corresponding to the transaction identifier exists in the cache, the execution result of the second operation is obtained from the cache;
[0072] Based on the second link, the execution parameter for executing the first operation and the execution result of the second operation are sent to the second database, so that the second database executes the operation corresponding to the request based on the execution parameter of the first operation after determining that the second operation is executed.
[0073] In some embodiments, the second operation mentioned above is the previous operation of the first operation in the transaction corresponding to the transaction ID, and the transaction includes a plurality of operations and an operation sequence of the plurality of operations.
[0074] Specifically, in the case that the second link corresponding to the transaction identifier exists in the cache, the database double-write device can obtain the execution result of the second operation from the cache, and can send the execution parameter for executing the first operation and the execution result of the second operation to the second database based on the second link, so that the second database can execute the operation corresponding to the first operation based on the execution parameter of the first operation after determining that the second operation is executed.
[0075] In one example, if the second link corresponding to the transaction identifier can be acquired in the cache, it indicates that the first operation corresponding to the request is not the first operation in the multiple operations included in the transaction. Based on this, the database double-write device needs to wrap the execution parameter of the first operation and the execution result of the second operation (i.e., the Future object of the second operation) into an asynchronous task, and then send it to the asynchronous thread pool for execution. The asynchronous thread pool directly returns the task Future object (i.e., the Future object of the first operation) this time. In addition, the asynchronous thread pool waits for the second database to complete the execution of the second operation of this transaction by calling the Future.get() method, and then executes the first operation. To ensure the execution order of the first operation in the second database.
[0076] In this embodiment, since the request execution type of the request is the second execution type, the database double-write device can acquire the execution result of the second operation from the cache in the case that the second link corresponding to the transaction identifier exists in the cache. And based on the second link, the execution parameter of the first operation and the execution result of the second operation are sent to the second database, so that the second database executes the operation corresponding to the request based on the execution parameter of the first operation after determining that the second operation is executed. In this way, not only the database double-write function is realized, but also the execution order of multiple operations in the transaction is ensured.
[0077] Based on this, in one embodiment, the above-mentioned database double-write method can include the following steps:
[0078] The execution result of the first operation is stored in the cache.
[0079] In this embodiment, the database double-write device can store the execution result of the first operation executed by the second database in the cache, so that subsequent operations included in the same transaction can continue to implement the database double-write function.
[0080] In order to more accurately describe the database double-write method provided by the embodiments of the present application, in one embodiment, the above-mentioned database double-write method can include the following steps:
[0081] In response to the end instruction of the transaction corresponding to the transaction identifier executed by the first database, the cache is cleaned up in the case that the execution result of the last operation in the transaction executed by the second database is acquired.
[0082] Specifically, the database double-writing apparatus can clean up the cache when the first database completes all operations included in the transaction and the execution result of the last operation in the transaction executed by the second database is obtained, in response to an end instruction of the transaction identified by the first database executing the transaction.
[0083] In one example, the database double-writing apparatus can obtain the second link and the Future object of the last operation in the operation sequence of the plurality of operations in the transaction corresponding to the transaction ID according to the transaction ID provided in the Spring transaction end event after monitoring the Spring transaction end event, and can call the Future.get() method to wait for the end of the execution of the last operation in the second database, and clean up the cache in response to the commit / rollback operation of the second database.
[0084] In this embodiment, the database double-writing apparatus can clean up the cache when the first database completes all operations included in the transaction and the execution result of the last operation in the transaction executed by the second database is obtained. In this way, the second database can make consistent operations according to the transaction state when the first database commits or rolls back. Also, it is ensured that the nested transaction execution is not chaotic and the commit sequence is consistent during the execution of a request or task.
[0085] Based on the same inventive concept, the embodiments of the present application also provide a database double-writing apparatus. Specifically, the database double-writing apparatus comprises Figure 2 The database double-writing apparatus provided by the embodiments of the present application is described in detail.
[0086] Figure 2 FIG. 1 is a structural schematic diagram of a database double-writing apparatus provided by an embodiment of the present application.
[0087] As shown in Figure 2 FIG. 2, the database double-writing apparatus 200 can comprise a receiving module 210 and a control module 220.
[0088] The receiving module 210 is configured to receive a request sent by an application program to a first database, the request comprising a request execution type.
[0089] The control module 220 is configured to control the first database to execute a first operation corresponding to the request in response to the request.
[0090] The control module 220 is configured to control a second database to execute the first operation corresponding to the request based on the request execution type in response to an end instruction of the first database executing the first operation, the first database and the second database being relational databases.
[0091] In one embodiment, the control module is specifically configured to:
[0092] in response to an end instruction of the first database executing the first operation, in a case where the request execution type is the first execution type, obtaining an execution parameter of the first database executing the first operation;
[0093] sending the execution parameter to the second database based on the first link, so that the second database executes the first operation based on the execution parameter, the first link being a link created for accessing the second database in response to a start input of the application program.
[0094] In one embodiment, the control module is specifically configured to:
[0095] in response to an end instruction of the first database executing the first operation, in a case where the request execution type is the second execution type, obtaining a transaction identifier corresponding to the request and an execution parameter of the first database executing the first operation;
[0096] in a case where the second link corresponding to the transaction identifier does not exist in the cache, initializing the second link corresponding to the transaction identifier, and sending the execution parameter of the first database executing the first operation to the second database based on the second link, so that the second database executes the first operation based on the execution parameter.
[0097] In one embodiment, the database double-writing device can include an obtaining module and a sending module.
[0098] The obtaining module is configured to, in a case where the second link corresponding to the transaction identifier exists in the cache, obtain an execution result of the second operation from the cache;
[0099] The sending module is configured to, based on the second link, send the execution parameter for executing the first operation and the execution result of the second operation to the second database, so that the second database executes the operation corresponding to the request based on the execution parameter of the first operation after determining that the second operation is executed.
[0100] The second operation is a previous operation of the first operation in a transaction corresponding to the transaction ID, and the transaction includes a plurality of operations and an operation sequence of the plurality of operations.
[0101] In one embodiment, the database double-writing device can include a storage module.
[0102] The storage module is configured to store the execution result of the first operation to the cache.
[0103] In one embodiment, the database double-writing device can include a cleaning module.
[0104] The cleaning module is configured to, in response to the first database executing the end instruction of the transaction, clean the cache in a case where the execution result of the last operation in the transaction executed by the second database is obtained.
[0105] In the embodiments of the present application, the request sent by the application program to the first database can be received, and then the first database can be controlled to execute the first operation corresponding to the request in response to the request. Since the request can include a request execution type, the second database can be controlled to execute the first operation corresponding to the request based on the request execution type in response to the end instruction of the first database executing the first operation. In this way, the database double writing is realized by receiving the request sent by the application program layer, and the functional accuracy of the database double writing is ensured.
[0106] The modules in the database double writing apparatus provided by the embodiments of the present application can implement the method steps of any one of the embodiments shown in the above Figure 1 and achieve the corresponding technical effects. For brevity, they will not be described here.
[0107] Figure 3 A hardware structure schematic diagram of an electronic device provided by the embodiments of the present application is shown.
[0108] The electronic device can include a processor 301 and a memory 302 having computer program instructions stored therein.
[0109] Specifically, the processor 301 can include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0110] The memory 302 can include a mass storage for data or instructions. By way of example and not limitation, the memory 302 can include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. Where appropriate, the memory 302 can include removable or non-removable (or fixed) media. Where appropriate, the memory 302 can be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, the memory 302 is a non-volatile solid-state memory.
[0111] The memory can include read-only memory (ROM), random access memory (RAM), magnetic disk storage mediums devices, optical storage mediums devices, flash memory devices, electrical, optical, or other physical / tangible memory storage devices. Thus, in general, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software that, when executed (by one or more processors), is operable to perform the operations described with reference to the methods according to an aspect of the present disclosure.
[0112] The processor 301 implements the database double-writing method in any of the above-described embodiments by reading and executing computer program instructions stored in the memory 302.
[0113] In one example, the electronic device can further include a communication interface 303 and a bus 310. As shown, the processor 301, the memory 302, and the communication interface 303 are connected by the bus 310 and complete communication with each other. Figure 3
[0114] The communication interface 303 is mainly used to realize the communication between the modules, devices, units and / or equipment in the embodiments of the present application.
[0115] The bus 310 includes hardware, software or both to couple components of the online data traffic billing device to each other in a known manner. By way of example, and not limitation, the bus can include an accelerated graphics port (AGP) or other graphics bus, an enhanced industry standard architecture (EISA) bus, a front-side bus (FSB), a HyperTransport (HT) interconnect, an industry standard architecture (ISA) bus, an infiniband interconnect, a low pin count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standards association local (VLB) bus, or another suitable bus or a combination of two or more of these. Where appropriate, the bus 310 can include one or more buses. Although the present application describes and illustrates a particular bus, the present application contemplates any suitable bus or interconnect.
[0116] In addition, in combination with the database double-writing method in the above-described embodiments, the present application can provide a computer storage medium to implement. The computer storage medium has computer program instructions stored thereon; the computer program instructions are executed by a processor to implement the database double-writing method provided by the present application.
[0117] The embodiment of the present application further provides a computer program product. Instructions in the computer program product are executed by a processor of an electronic device, so that the electronic device executes the database double-writing method provided by the embodiment of the present application.
[0118] It should be noted that the present application is not limited to the specific configurations and processes described above and shown in the drawings. For the sake of brevity, detailed descriptions of well-known methods are omitted. In the above embodiments, several specific steps are described and shown as examples. However, the method processes of the present application are not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order of the steps, after understanding the spirit of the present application.
[0119] The functional blocks shown in the above structural block diagrams can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a functional card, etc. When implemented in software, the elements of the present application are program or code segments used to perform the required tasks. The program or code segments can be stored in a machine-readable medium or transmitted through a data signal carried in a carrier wave over a transmission medium or communication link. The "machine-readable medium" can include any medium capable of storing or transmitting information. Examples of the machine-readable medium include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segments can be downloaded via a computer network such as the Internet, an intranet, etc.
[0120] It should be further noted that the exemplary embodiments mentioned in the present application describe some methods or systems based on a series of steps or devices. However, the present application is not limited to the order of the above steps, that is, the steps can be executed in the order mentioned in the embodiments, or in an order different from the embodiments, or several steps can be executed simultaneously.
[0121] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0122] The above is merely specific implementation of the present application, and those skilled in the art can clearly understand the specific working process of the system, module and unit described above for the convenience and brevity of description, which can refer to the corresponding process in the foregoing method embodiments, and will not be described herein. It should be understood that the protection scope of the present application is not limited to this, and any person skilled in the art can easily think of various equivalent modifications or replacements within the technical range disclosed in the present application, and these modifications or replacements should be covered within the protection scope of the present application.
Claims
1. A database double write method, characterized by, The method comprises: receiving a request sent by an application program to a first database, the request comprising a request execution type; in response to the request, controlling the first database to perform a first operation corresponding to the request; in response to an end instruction of the first database performing the first operation, controlling a second database to perform the first operation corresponding to the request based on the request execution type, the first database and the second database being relational databases; wherein, in response to the end instruction of the first database performing the first operation, controlling the second database to perform the first operation corresponding to the request based on the request execution type comprises: in response to the end instruction of the first database performing the first operation, if the request execution type is a second execution type, obtaining a transaction identifier corresponding to the request and execution parameters of the first database performing the first operation; if there is no second link corresponding to the transaction identifier in the cache, initializing a second link corresponding to the transaction identifier, and sending the execution parameters of the first database performing the first operation to the second database based on the second link, so that the second database performs the first operation based on the execution parameters.
2. The method of claim 1, wherein, The response to the end instruction of the first database performing the first operation, controlling the second database to perform the first operation corresponding to the request based on the request execution type comprises: in response to the end instruction of the first database performing the first operation, if the request execution type is a first execution type, obtaining execution parameters of the first database performing the first operation; sending the execution parameters to the second database based on a first link, so that the second database performs the first operation based on the execution parameters, the first link being a link created for accessing the second database in response to a start input of the application program.
3. The method of claim 1, wherein, The method further comprises: if there is a second link corresponding to the transaction identifier in the cache, obtaining the execution result of the second operation from the cache; based on the second link, sending the execution parameters for executing the first operation and the execution result of the second operation to the second database, so that the second database performs the operation corresponding to the request based on the execution parameters of the first operation after determining that the second operation is completed; wherein, the second operation is a previous operation of the first operation in a transaction corresponding to the transaction ID, and the transaction comprises a plurality of operations and an operation sequence of the plurality of operations.
4. The method according to claim 1 or 3, characterized in that, The method further comprises: storing the execution result of the first operation to the cache.
5. The method of claim 1, wherein, The method further comprises: in response to the end instruction of the first database performing the transaction corresponding to the transaction identifier, if the execution result of the last operation of the second database performing the transaction is obtained, cleaning up the cache.
6. A database double writing apparatus, characterized by comprising: The apparatus comprises: a receiving module configured to receive a request sent by an application program to a first database, the request comprising a request execution type; The control module is configured to control the first database to perform a first operation corresponding to the request in response to the request. The control module is configured to control a second database to perform the first operation corresponding to the request based on the request execution type in response to an end instruction of the first database performing the first operation, the first database and the second database being relational databases. The control module is specifically configured to: In response to the end instruction of the first database performing the first operation, if the request execution type is a second execution type, obtain a transaction identifier corresponding to the request and execution parameters of the first database performing the first operation; If a second link corresponding to the transaction identifier does not exist in the cache, initialize the second link corresponding to the transaction identifier, and send the execution parameters of the first database performing the first operation to the second database based on the second link, so that the second database performs the first operation based on the execution parameters.
7. An electronic device, comprising: The device comprises a processor and a memory storing computer program instructions; The processor reads and executes the computer program instructions to implement the database double-writing method of any one of claims 1-5.
8. A computer storage medium, characterized in that The computer storage medium stores computer program instructions executed by the processor to implement the database double-writing method of any one of claims 1-5.
9. A computer program product, characterised in that, The instructions in the computer program product are executed by the processor of the electronic device to enable the electronic device to perform the database double-writing method of any one of claims 1-5.
Citation Information
Patent Citations
Transaction processing method, server and storage medium
CN107391539A
Master-slave database read-write method and system, storage device and server
CN108038157A