WO2019228012A1 - 事务因果序的校正方法及装置、电子设备 - Google Patents
事务因果序的校正方法及装置、电子设备 Download PDFInfo
- Publication number
- WO2019228012A1 WO2019228012A1 PCT/CN2019/077435 CN2019077435W WO2019228012A1 WO 2019228012 A1 WO2019228012 A1 WO 2019228012A1 CN 2019077435 W CN2019077435 W CN 2019077435W WO 2019228012 A1 WO2019228012 A1 WO 2019228012A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- transaction
- timestamp
- correction
- time stamp
- database server
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/466—Transaction processing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/465—Distributed object oriented systems
Definitions
- One or more embodiments of the present specification relate to the technical field of terminals, and in particular, to a method and device for correcting causality of transactions, and an electronic device.
- the transaction time stamp of each executed transaction should be guaranteed to conform to the causal order defined by the client.
- the client first requests the database server A to execute the transaction T_1, and after the database server A returns a message that the transaction T_1 has been successfully executed, it then requests the database server B to execute the transaction T_2; then, the causal order is that the transaction T_2 occurs in the transaction After T_1. Therefore, the transaction time stamp of transaction T_1 should be smaller than the transaction time stamp of transaction T_2.
- one or more embodiments of the present specification provide a method and device for correcting causality of transactions, and an electronic device, which can ensure that the transaction time stamp of each transaction conforms to the causality sequence defined by the client.
- a method for correcting a causal order of transactions is provided, which is applied to a middleware device, which is used for transmitting client and database servers in a distributed database.
- Communication data includes:
- the correction time stamp is not less than a transaction time stamp of a historical transaction
- the historical transaction is a historical transaction requested by the client to each database server for execution
- a method for correcting causality of a transaction is proposed, and is applied to a client; the method includes:
- the correction time stamp is not less than a transaction time stamp of a historical transaction
- the historical transaction is a historical transaction requested by the client to each database server for execution
- a method for correcting causality of transactions is proposed, which is applied to a database server; the method includes:
- the correction timestamp is not less than the transaction timestamp of a historical transaction
- the historical transaction is a historical transaction that the client requests to each database server for execution
- a transaction timestamp corresponding to the execution request is generated according to the correction timestamp, so that the transaction timestamp is greater than the correction timestamp.
- a transaction causality correction device is proposed, which is applied to a middleware device, which is used to transmit client and database servers in a distributed database.
- Data for communication between devices includes:
- a detection unit that detects an execution request initiated by a client for a pending transaction of any database server in a distributed database
- a determining unit that determines a correction time stamp, the correction time stamp is not less than a transaction time stamp of a historical transaction, and the historical transaction is a historical transaction requested by the client to each database server for execution;
- the sending unit sends a correction time stamp to the any database server, so that the transaction time stamp of the any database server in response to the execution request is greater than the correction time stamp.
- a transaction causality correction device which is applied to a client; the device includes:
- a request unit which initiates an execution request for a transaction to be executed to any database server in the distributed database
- a determining unit that determines a correction time stamp, the correction time stamp is not less than a transaction time stamp of a historical transaction, and the historical transaction is a historical transaction requested by the client to each database server for execution;
- the sending unit sends a correction time stamp to the any database server, so that the transaction time stamp of the any database server in response to the execution request is greater than the correction time stamp.
- an apparatus for correcting causality of transactions which is applied to a database server; the apparatus includes:
- a receiving unit that receives a correction time stamp, the correction time stamp is not less than a transaction time stamp of a historical transaction, and the historical transaction is a historical transaction requested by a client to each database server for execution;
- a generating unit when receiving an execution request for a to-be-executed transaction initiated by the client, generating a transaction timestamp in response to the execution request according to the correction timestamp, so that the transaction timestamp is greater than the correction Timestamp.
- an electronic device including:
- Memory for storing processor-executable instructions
- the processor is configured to implement a method for correcting a causal order of transactions according to any one of the foregoing embodiments.
- FIG. 1 is a schematic structural diagram of a transaction causality correction system according to an exemplary embodiment.
- FIG. 2 is a flowchart of a method for correcting causality of a client-side transaction according to an exemplary embodiment.
- FIG. 3 is a flowchart of a method for correcting a causal order of transactions on a database server side according to an exemplary embodiment.
- FIG. 4 is an interaction diagram of a method for correcting causality of transactions provided by an exemplary embodiment.
- FIG. 5 is a schematic structural diagram of another transaction causality correction system according to an exemplary embodiment.
- FIG. 6 is a flowchart of a method for correcting a causal order of transactions on a middleware device side according to an exemplary embodiment.
- FIG. 7 is an interaction diagram of another method for correcting causality of transactions provided by an exemplary embodiment.
- FIG. 8 is a schematic structural diagram of an electronic device according to an exemplary embodiment.
- FIG. 9 is a block diagram of a transaction causality correction apparatus according to an exemplary embodiment.
- FIG. 10 is a schematic structural diagram of another electronic device according to an exemplary embodiment.
- FIG. 11 is a block diagram of another transaction causality correction apparatus according to an exemplary embodiment.
- FIG. 12 is a schematic structural diagram of another electronic device according to an exemplary embodiment.
- FIG. 13 is a block diagram of another transaction causality correction apparatus according to an exemplary embodiment.
- the steps of the corresponding method are not necessarily performed in the order shown and described in this specification.
- the method may include more or fewer steps than described in this specification.
- a single step described in this specification may be divided into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for other embodiments. description.
- FIG. 1 is a schematic structural diagram of a transaction causality correction system according to an exemplary embodiment.
- the system may include a client 10 and a distributed database 20.
- the distributed database 20 may include database servers 20A, 20B, and the like.
- the client maintains the correction timestamp (not less than the transaction timestamp of the historical transaction) and sends the correction timestamp to the database server that needs to request the execution of the transaction, so that the database server can generate transactions greater than the correction timestamp when executing the transaction. Timestamp to satisfy client-defined causal order (the transaction timestamp should be greater than the transaction timestamp of the historical transaction). The above process will be described in detail below.
- the database servers 20A, 20B, etc. may be physical servers including an independent host, or may be virtual servers carried by a host cluster. During the running process, database servers 20A, 20B, etc. can run server-side programs of an application to achieve the relevant business functions of the application, such as when the database servers 20A, 20B, etc., run programs that perform causal corrections of transactions. Can be configured as a server for implementing the causal correction of transactions. In the technical solution of one or more embodiments of the present specification, the database server 20A, 20B, etc. may cooperate with the client 10 to implement a solution for correcting the causal order of transactions.
- the user may use the following types of electronic devices as the client 10: tablet devices, notebook computers, personal digital assistants (PDAs, Personal Assistants, etc.), which are not limited in one or more embodiments of this specification.
- tablet devices notebook computers
- PDAs personal digital assistants
- Personal Assistants etc.
- the network (not shown in the figure) where the client 10 interacts with the database servers 20A, 20B, etc. may include multiple types of wired or wireless networks.
- the network may include a Public Switched Telephone Network (PSTN) and the Internet, which is not limited in one or more embodiments of the present specification.
- PSTN Public Switched Telephone Network
- FIG. 2 is a flowchart of a method for correcting causality of a client-side transaction according to an exemplary embodiment. As shown in FIG. 2, the method may include the following steps:
- Step 202 Initiate an execution request for a transaction to be executed to any database server in the distributed database.
- Step 204 Determine a correction time stamp.
- the time recorded by the clocks of the database servers in the distributed database may not be consistent. If each database server generates a transaction time stamp according to its own clock, it may cause the transaction time stamp of the transaction to not conform to the cause and effect defined by the client. sequence. For example, the client first requests the database server A to execute the transaction T_1. At this time, the clock of the database server A is 100; then the database server A returns a transaction time stamp of executing the transaction T_1 is 100. After determining that the database server A has finished executing the transaction T_1, the client requests the database server B to execute the transaction T_2 (causal order is that the transaction T_2 occurs after the transaction T_1).
- the database server B returns a transaction timestamp for executing transaction T_2 of 90, causing the transaction timestamp of transaction T_1 to be greater than the transaction timestamp of transaction T_2, that is, the order of executing transactions T_1 and T_2 does not conform to the causal order defined by the client . Then, if you need to read the transaction with a time stamp before 95, you can only read out the transaction T_2, and you cannot read out the transaction T_1. In fact, the transaction T_1 occurs before the transaction T_2, which belongs to the transaction time stamp. Before 95.
- the client can implement the correction scheme of transaction causality in this specification by maintaining a correction time stamp.
- the correction timestamp is not less than the transaction timestamp of the historical transaction (hereinafter simply referred to as the historical transaction timestamp), and the historical transaction is a historical transaction requested by the client to each database server for execution.
- the correction timestamp may be set to be equal to a transaction timestamp of a transaction that the client last requested from a database server (which may be any one of the database servers or another database server). (Hereinafter referred to as the most recent transaction timestamp); in another embodiment, the correction timestamp may be set to be greater than the most recent transaction timestamp.
- Step 206 Send a correction time stamp to the any database server, so that the transaction time stamp of the any database server in response to the execution request is greater than the correction time stamp.
- the database server may generate a response to the correction time stamp according to the correction time stamp.
- the requested transaction timestamp is executed, so that the generated transaction timestamp is later than the historical transaction timestamp in chronological order, satisfying the causal order defined by the client.
- any one of the database servers may first compare its own clock with the correction timestamp, and then determine a basis for generating a transaction timestamp in response to the execution request according to the comparison result.
- any database server may directly generate a transaction timestamp in response to the execution request according to the correction timestamp, so that the transaction timestamp is greater than the correction timestamp.
- FIG. 3 is a flowchart of a method for correcting causality of transactions on a database server side according to an exemplary embodiment. As shown in FIG. 3, the method may include the following steps:
- Step 302 Receive a correction time stamp.
- the correction timestamp is not less than the transaction timestamp of a historical transaction
- the historical transaction is a historical transaction requested by the client to each database server for execution.
- Step 304 When an execution request for a transaction to be executed initiated by the client is received, a transaction timestamp corresponding to the execution request is generated according to the correction timestamp, so that the transaction timestamp is greater than the correction. Timestamp.
- a transaction timestamp corresponding to the execution request is generated according to the correction timestamp, so that the transaction timestamp is greater than the correction timestamp. ; Otherwise, generate a transaction timestamp in response to the execution request according to its own clock.
- the own clock may be modified to be greater than the correction timestamp, so that the own clock is not slower than the clocks of other database servers.
- the detailed description can refer to the related content in the embodiment of FIG. 2 described above, which will not be repeated here.
- FIG. 4 is an interaction diagram of a method for correcting causality of transactions provided by an exemplary embodiment.
- the client requests database server A and database server B to modify data.
- the client requests database server B to modify data.
- the correction method may include the following steps:
- step 401 the client sends an execution request a to the database server A to modify the data a in the database server A.
- the client can communicate with each database server through the connection pool.
- step 402 the database server A modifies the data a.
- step 403 the database server A generates a transaction timestamp a.
- step 404 the database server A returns a modification result a and a transaction time stamp a to the client.
- step 405 the client determines a correction time stamp.
- the correction timestamp can be set equal to the most recent transaction timestamp.
- the most recent transaction timestamp is transaction timestamp a; therefore, the correction timestamp can be set equal to the transaction timestamp a.
- the correction timestamp may be set to 92.
- the correction timestamp can also be set to be greater than the most recent transaction timestamp; for example, following the above example, the correction timestamp can be set to 93, 94, 95, and so on.
- step 406 the client sends an execution request b and a correction time stamp to the database server B.
- the client after determining that the database server A has finished modifying the data a, the client sends an execution request b to the database server B to modify the data b in the database server B. Then, the causal order at this time is "Database server A modifies data a" before “Database server B modifies data b".
- Step 407 the database server B compares the correction time stamp with its own clock.
- step 408 when its own clock is not greater than the correction timestamp, the database server B modifies its own clock to be greater than the correction timestamp.
- step 409 the database server B modifies the data b.
- step 410 the database server B generates a transaction timestamp b.
- the database server B when its own clock is greater than the corrected timestamp, the database server B does not need to modify its own clock to be greater than the corrected timestamp, and directly generates a transaction timestamp b (transaction "modified data b" "Moment).
- the transaction timestamp b is greater than the transaction timestamp a, which satisfies the causal order of "the database server A modifies data a before the database server B modifies data b".
- the modification range can be flexibly set according to the actual situation, and this specification does not limit this. For example, you can also modify your own clock to 94, 95, 100, and so on. By modifying its own clock, it can make its own clock not slower than the clock of database server A. Then, when the above-mentioned causality requirement occurs again, the database server B can be prevented from frequently modifying its own clock.
- step 408 the operation of modifying its own clock to be greater than the correction timestamp may be omitted (that is, step 408 is omitted), and directly after comparing that its own clock is not greater than the correction timestamp, and after executing the transaction "modify data b" Generate a transaction timestamp b that is greater than the correction timestamp, thereby avoiding modification of its own clock.
- the database server B can also omit the comparison operation in step 407 (then step 408 does not need to be performed), and directly execute the transaction “modify data b” to generate a transaction time stamp b that is greater than the correction time stamp. This can prevent modification of its own clock. At the same time, by omitting the operation of comparing its own clock with the correction timestamp, the efficiency of generating a transaction timestamp can be improved.
- step 411 the database server B returns a modification result b and a transaction time stamp b to the client.
- Step 412 The client updates the correction time stamp according to the transaction time stamp b.
- the correction timestamp needs to be updated from the transaction timestamp a to the transaction timestamp b.
- the correction timestamp may be updated to 93.
- the correction time stamp may also be maintained by the middleware device, so as to implement a correction scheme of transaction causality.
- FIG. 5 is a schematic structural diagram of another transaction causality correction system provided by an exemplary embodiment.
- the system may include a client 30A-30C, a middleware device 40 and a distributed database 50 (including database servers 50A, 50B, etc.).
- the middleware device 40 is connected between the clients 30A-30C and the distributed database 50, and runs the middleware, so that it can be used to transfer the database servers (database servers 50A, 50B) in the client 30A-30C and the distributed database 50. Etc.) to communicate with each other.
- the clients 30A-30C and the distributed database 50 are similar to the client 10 and the distributed database 20 in FIG. 1 described above. For detailed descriptions, refer to the related content of the architecture shown in FIG.
- FIG. 6 is a method for correcting a causal order of a middleware device-side transaction according to an exemplary embodiment.
- the middleware device may run middleware for transmitting data communicated between the client and each database server in the distributed database; the method may include the following steps:
- Step 602 Detect an execution request initiated by a client for a pending transaction of any database server in a distributed database.
- Step 604 Determine a correction time stamp.
- the correction timestamp is not less than the transaction timestamp of a historical transaction
- the historical transaction is a historical transaction that the client requests to each database server for execution.
- the middleware device can maintain a correction time stamp corresponding to each client; wherein, a mapping relationship between a client identifier and a corresponding correction time stamp can be established. Then, when determining the correction timestamp, the middleware device may first determine the client identifier of the sender client of the execution request, and then (according to the mapping relationship) determine the correction timestamp corresponding to the client identifier.
- Step 606 Send a correction time stamp to the any database server, so that the transaction time stamp of the any database server in response to the execution request is greater than the correction time stamp.
- FIG. 7 is an interaction diagram of another method for correcting causality of transactions provided by an exemplary embodiment.
- the middleware device runs middleware for transmitting data communicated between each client and each database server in the distributed database.
- the client A requests the database server C and the database server D to modify data.
- the client A requests the database server D to modify the data.
- the correction method may include the following steps:
- Step 701 the client A sends an execution request c to the middleware device to modify the data c in the database server C;
- the client A can communicate with the middleware device through the connection pool.
- Step 702 The middleware device forwards the execution request c to the database server C.
- step 703 the database server C modifies the data c.
- step 704 the database server C generates a transaction timestamp c.
- step 705 the database server C returns a modification result c and a transaction time stamp c to the middleware device.
- Step 706 The middleware device determines a correction time stamp a.
- the correction time stamp a corresponding to the client A may be set equal to the latest transaction time stamp of the client A.
- the latest transaction timestamp of client A is transaction timestamp c; therefore, the correction timestamp a can be set equal to the transaction timestamp c.
- the correction timestamp a can also be set to be greater than the most recent transaction timestamp.
- the correction timestamp a may be set to 101, 104, 109, and so on.
- the middleware device can establish a mapping relationship between the client identifier and the corresponding correction time stamp to distinguish each correction time stamp. For example, if the client's IP address is used as the client identifier, the mapping relationship shown in Table 1 can be established:
- Corrected timestamp IP address Corrected timestamp a 1.1.1.1 Corrected timestamp b 1.1.1.2 Corrected timestamp c 1.1.1.3 ... ...
- client-related information can also be used as the client identification, and this specification does not limit this.
- Step 707 The middleware device forwards the modification result c to the client A.
- the middleware device can only forward the modification result c to the client A without forwarding the correction timestamp a, so that transparent processing of the client A can be achieved, and the client A cannot perceive the correction timestamp
- the maintenance process can be performed in accordance with the normal process of modifying data.
- Step 708 The client A sends an execution request d to the middleware device to modify the data d in the database server D.
- the client A after determining that the database server C has finished modifying the data c, the client A sends an execution request d to the database server D to modify the data d. Then, the causal order at this time is that "database server C modifies data c" occurs before “database server D modifies data d".
- Step 709 The middleware device forwards the execution request d and the correction time stamp a to the database server D.
- the middleware device determines the correction timestamp a corresponding to the client A, the client identifier of the client A (that is, the client A's IP address), and according to the mapping relationship in Table 1 above, a correction timestamp a corresponding to the client A is determined.
- step 710 the database server D compares the correction timestamp a with its own clock.
- step 711 when its own clock is not greater than the correction timestamp a, the database server D modifies its own clock to be greater than the correction timestamp a.
- step 712 the database server D modifies the data d.
- step 713 the database server D generates a transaction timestamp d.
- the database server D when its own clock is greater than the corrected timestamp a, the database server D does not need to modify its own clock to be greater than the corrected timestamp a, and directly generates a transaction timestamp d (transaction "modification” based on the time recorded by its own clock). Data d ").
- the correction timestamp a is equal to the transaction timestamp c
- the transaction timestamp c is the time when the transaction "modifies data c"
- the transaction timestamp d is not greater than the transaction timestamp c, that is, the database server C modifies the data c "does not occur before the" database server D modifies the data d ", and thus does not conform to the causal order.
- the transaction timestamp d is greater than the transaction timestamp c, which satisfies the causal order of "the database server C modifies data c before the database server D modifies data d".
- the modification range can be flexibly set according to the actual situation, and this specification does not limit this. For example, you can also modify your own clock to 102, 105, 111, and so on. By modifying its own clock, its own clock can be made no slower than that of the database server C. Then, when the above-mentioned causal requirement occurs again, the database server D can be prevented from frequently modifying its own clock.
- the database server D can also omit the comparison operation in step 710 (then step 711 does not need to be performed), and directly execute the transaction “modify data d” to generate a transaction time stamp d that is greater than the correction time stamp a. To avoid modifying your own clock. At the same time, by omitting the operation of comparing its own clock with the correction timestamp, the efficiency of generating a transaction timestamp can be improved.
- step 714 the database server D returns the modification result d and the transaction time stamp d to the middleware device.
- Step 715 The middleware device updates the correction time stamp a according to the transaction time stamp d.
- the correction timestamp a needs to be updated from the transaction timestamp c to the transaction timestamp d.
- the correction timestamp a may be updated to 101.
- step 716 the middleware device forwards the modification result d to the client A.
- the database server can perform the transaction based on the correction time stamp. Generate a transaction timestamp that is greater than the correction timestamp, that is, in a causal order defined by the client.
- FIG. 8 is a schematic structural diagram of an electronic device according to an exemplary embodiment. Please refer to FIG. 8.
- the device includes a processor 802, an internal bus 804, a network interface 806, a memory 808, and a non-volatile memory 810. Of course, it may also include hardware required by other services.
- the processor 802 reads the corresponding computer program from the non-volatile memory 810 into the memory 808 and then runs it to form a causal correction device for transactions on a logical level.
- one or more embodiments of this specification do not exclude other implementations, such as a logic device or a combination of software and hardware, etc., which means that the execution body of the following processing flow is not limited to each A logic unit can also be a hardware or logic device.
- a transaction causality correction device is applied to a middleware device, which is used to transmit data communicated between a client and each database server in a distributed database; the transaction
- the causal correction device may include:
- the detecting unit 91 detects an execution request initiated by a client for a pending transaction of any database server in a distributed database
- the determining unit 92 determines a correction time stamp, where the correction time stamp is not less than a transaction time stamp of a historical transaction, and the historical transaction is a historical transaction requested by the client to each database server for execution;
- the sending unit 93 sends a correction time stamp to the any database server, so that the transaction time stamp of the any database server in response to the execution request is greater than the correction time stamp.
- the middleware device is configured to transmit data communicated between multiple clients and database servers in a distributed database, and the middleware device maintains a correction time stamp corresponding to each client; the determination The unit 92 is specifically used for:
- a correction time stamp corresponding to the client identification is determined.
- the correction timestamp is a transaction timestamp of a transaction that the client last requested from a database server for execution.
- FIG. 10 is a schematic structural diagram of another electronic device according to an exemplary embodiment.
- the device includes a processor 1002, an internal bus 1004, a network interface 1006, a memory 1008, and a non-volatile memory 1010.
- the processor 1002 reads the corresponding computer program from the non-volatile memory 1010 into the memory 1008 and then runs it to form a transaction causality correction device on a logical level.
- one or more embodiments of this specification do not exclude other implementations, such as a logic device or a combination of software and hardware, etc., which means that the execution body of the following processing flow is not limited to each A logic unit can also be a hardware or logic device.
- the transaction causality correction device is applied to a client; it may include:
- the requesting unit 1101 sends an execution request for a transaction to be executed to any database server in the distributed database;
- the determining unit 1102 determines a correction time stamp, where the correction time stamp is not less than a transaction time stamp of a historical transaction, and the historical transaction is a historical transaction requested by the client to each database server for execution;
- the sending unit 1103 sends a correction time stamp to the any database server, so that the transaction time stamp of the any database server in response to the execution request is greater than the correction time stamp.
- FIG. 12 is a schematic structural diagram of another electronic device according to an exemplary embodiment. Please refer to FIG. 12.
- the device includes a processor 1202, an internal bus 1204, a network interface 1206, a memory 1208, and a non-volatile memory 1212. Of course, it may also include hardware required by other services.
- the processor 1202 reads the corresponding computer program from the non-volatile memory 1212 into the memory 1208 and then runs it to form a transaction causality correction device on a logical level.
- one or more embodiments of this specification do not exclude other implementations, such as a logic device or a combination of software and hardware, etc., which means that the execution body of the following processing flow is not limited to each A logic unit can also be a hardware or logic device.
- the transaction causality correction device is applied to a database server and may include:
- the receiving unit 1301 receives a correction time stamp, the correction time stamp is not less than a transaction time stamp of a historical transaction, and the historical transaction is a historical transaction requested by a client to each database server for execution;
- the generating unit 1302 generates a transaction timestamp in response to the execution request according to the correction timestamp when the execution request for the to-be-executed transaction initiated by the client is received, so that the transaction timestamp is greater than the transaction timestamp. Correct the timestamp.
- the generating unit 1302 is specifically configured to:
- a transaction time stamp is generated based on its own clock in response to the execution request.
- Optional also includes:
- the modifying unit 1303 modifies its own clock to be greater than the correction timestamp when its own clock is not greater than the correction timestamp.
- the system, device, module, or unit described in the foregoing embodiments may be specifically implemented by a computer chip or entity, or a product with a certain function.
- a typical implementation device is a computer, and the specific form of the computer may be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email sending and receiving device, and a game control Desk, tablet computer, wearable device, or a combination of any of these devices.
- a computer includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
- processors CPUs
- input / output interfaces output interfaces
- network interfaces network interfaces
- memory volatile and non-volatile memory
- Memory may include non-persistent memory, random access memory (RAM), and / or non-volatile memory in computer-readable media, such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
- RAM random access memory
- ROM read-only memory
- flash RAM flash memory
- Computer-readable media includes both permanent and non-permanent, removable and non-removable media.
- Information can be stored by any method or technology.
- Information may be computer-readable instructions, data structures, modules of a program, or other data.
- Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, read-only disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, Magnetic tape cartridges, magnetic disk storage, quantum memory, graphene-based storage media, or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices.
- computer-readable media does not include temporary computer-readable media, such as modulated data signals and carrier waves.
- first, second, third, etc. may be used to describe various information in one or more embodiments of the present specification, the information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other.
- first information may also be referred to as second information, and similarly, the second information may also be referred to as first information.
- word “if” as used herein can be interpreted as “at” or "when” or "in response to determination”.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Computer And Data Communications (AREA)
Abstract
一种事务因果序的校正方法及装置、电子设备,该方法可以包括:向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求(202);确定校正时间戳(204),所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳(206)。本方法可以保证数据库服务器生成的事务时间戳符合客户端定义的因果序。
Description
本说明书一个或多个实施例涉及终端技术领域,尤其涉及一种事务因果序的校正方法及装置、电子设备。
分布式数据库中的各个数据库服务器在执行客户端请求的事务时,执行的各个事务的事务时间戳应保证符合客户端定义的因果序。举例而言,客户端先向数据库服务器A请求执行事务T_1,并在数据库服务器A返回事务T_1执行成功的消息后,再向数据库服务器B请求执行事务T_2;那么,因果序为事务T_2发生于事务T_1之后。因此,事务T_1的事务时间戳应小于事务T_2的事务时间戳。
发明内容
有鉴于此,本说明书一个或多个实施例提供一种事务因果序的校正方法及装置、电子设备,可以保证各个事务的事务时间戳符合客户端定义的因果序。
为实现上述目的,本说明书一个或多个实施例提供技术方案如下:
根据本说明书一个或多个实施例的第一方面,提出了一种事务因果序的校正方法,应用于中间件设备,所述中间件设备用于传输客户端与分布式数据库中各数据库服务器之间进行通信的数据;所述方法包括:
检测客户端发起的针对分布式数据库中任一数据库服务器的待执行事务的执行请求;
确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;
向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
根据本说明书一个或多个实施例的第二方面,提出了一种事务因果序的校正方法,应用于客户端;所述方法包括:
向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求;
确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;
向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
根据本说明书一个或多个实施例的第三方面,提出了一种事务因果序的校正方法,应用于数据库服务器;所述方法包括:
接收校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为客户端向各数据库服务器请求执行的历史事务;
当接收到所述客户端发起的针对待执行事务的执行请求时,根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。
根据本说明书一个或多个实施例的第四方面,提出了一种事务因果序的校正装置,应用于中间件设备,所述中间件设备用于传输客户端与分布式数据库中各数据库服务器之间进行通信的数据;所述装置包括:
检测单元,检测客户端发起的针对分布式数据库中任一数据库服务器的待执行事务的执行请求;
确定单元,确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;
发送单元,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
根据本说明书一个或多个实施例的第五方面,提出了一种事务因果序的校正装置,应用于客户端;所述装置包括:
请求单元,向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求;
确定单元,确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;
发送单元,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
根据本说明书一个或多个实施例的第六方面,提出了一种事务因果序的校正装置,应用于数据库服务器;所述装置包括:
接收单元,接收校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为客户端向各数据库服务器请求执行的历史事务;
生成单元,当接收到所述客户端发起的针对待执行事务的执行请求时,根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。
根据本说明书一个或多个实施例的第七方面,提出了一种电子设备,包括:
处理器;
用于存储处理器可执行指令的存储器;
其中,所述处理器被配置为实现如上述任一实施例所述的事务因果序的校正方法。
图1是一示例性实施例提供的一种事务因果序的校正系统的架构示意图。
图2是一示例性实施例提供的一种客户端侧事务因果序的校正方法的流程图。
图3是一示例性实施例提供的一种数据库服务器侧事务因果序的校正方法的流程图。
图4是一示例性实施例提供的一种事务因果序的校正方法的交互图。
图5是一示例性实施例提供的另一种事务因果序的校正系统的架构示意图。
图6是一示例性实施例提供的一种中间件设备侧事务因果序的校正方法的流程图。
图7是一示例性实施例提供的另一种事务因果序的校正方法的交互图。
图8是一示例性实施例提供的一种电子设备的示意结构图。
图9是一示例性实施例提供的一种事务因果序的校正装置的框图。
图10是一示例性实施例提供的另一种电子设备的示意结构图。
图11是一示例性实施例提供的另一种事务因果序的校正装置的框图。
图12是一示例性实施例提供的另一种电子设备的示意结构图。
图13是一示例性实施例提供的另一种事务因果序的校正装置的框图。
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书一个或多个实施例相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。
需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。
图1是一示例性实施例提供的一种事务因果序的校正系统的架构示意图。如图1所示,该系统可以包括客户端10和分布式数据库20。其中,分布式数据库20可以包括数据库服务器20A、20B等。客户端通过维护校正时间戳(不小于历史事务的事务时间戳),并将校正时间戳发送至需请求执行事务的数据库服务器,使得该数据库服务器在执行事务时可生成大于该校正时间戳的事务时间戳,从而满足客户端定义的因果序(该事务时间戳应大于历史事务的事务时间戳)。下文将对上述过程进行详细说明。
数据库服务器20A、20B等可以为包含一独立主机的物理服务器,或者也可以为主机集群承载的虚拟服务器。在运行过程中,数据库服务器20A、20B等可以运行某一应用的服务器侧的程序,以实现该应用的相关业务功能,比如当该数据库服务器20A、20B等运行事务因果序的校正操作的程序时,可以被配置为用于实现事务因果序的校正功能的服务端。而在本说明书一个或多个实施例的技术方案中,可由数据库服务器20A、20B等通过与客户端10进行配合,以实现对事务因果序进行校正的方案。
用户可以使用诸如下述类型的电子设备作为客户端10:平板设备、笔记本电脑、掌上电脑(PDAs,Personal Digital Assistants)等,本说明书一个或多个实施例并不对此进行限制。
而对于客户端10与数据库服务器20A、20B等进行交互的网络(图中未示出),可以包括多种类型的有线或无线网络。在一实施例中,该网络可以包括公共交换电话网络(Public Switched Telephone Network,PSTN)和因特网,本说明书一个或多个实施例并 不对此进行限制。
下面分别针对客户端和数据库服务器中的不同角色,对本说明书的事务因果序的校正方案进行说明。
图2是一示例性实施例提供的一种客户端侧事务因果序的校正方法的流程图。如图2所示,该方法可以包括以下步骤:
步骤202,向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求。
步骤204,确定校正时间戳。
在本实施例中,分布式数据库中各数据库服务器的时钟记录的时间可能并不一致,若各数据库服务器按照自身的时钟生成事务时间戳,则可能导致事务的事务时间戳不符合客户端定义的因果序。例如,客户端先向数据库服务器A请求执行事务T_1,此时数据库服务器A的时钟为100;则数据库服务器A返回执行事务T_1的事务时间戳为100。客户端在确定数据库服务器A完成对事务T_1的执行后,再向数据库服务器B请求执行事务T_2(因果序为事务T_2发生于事务T_1之后),若此时数据库服务器B的时钟为90(小于100),则数据库服务器B返回执行事务T_2的事务时间戳为90,导致事务T_1的事务时间戳反而大于事务T_2的事务时间戳,即执行事务T_1和事务T_2的顺序不符合客户端定义的因果序。那么,如果后续需读取事务时间戳在95之前的事务,就只能读取出事务T_2,并不能够读取出事务T_1;而实际上事务T_1发生于事务T_2之前,属于事务时间戳在95之前的事务。
因此,客户端可通过维护校正时间戳来实现本说明书中事务因果序的校正方案。其中,所述校正时间戳不小于历史事务的事务时间戳(以下简称为历史事务时间戳),所述历史事务为所述客户端向各数据库服务器请求执行的历史事务。在一实施例中,可将所述校正时间戳设置为等于所述客户端最近一次向数据库服务器(可能是所述任一数据库服务器,也可能是其他数据库服务器)请求执行的事务的事务时间戳(以下简称为最近事务时间戳);在另一实施例中,可将所述校正时间戳设置为大于最近事务时间戳。
步骤206,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
在本实施例中,基于所述校正时间戳不小于历史事务时间戳的特点,所述任一数据库服务器在接收到所述校正时间戳后,可根据所述校正时间戳来生成响应于所述执行请求的事务时间戳,从而使得生成的事务时间戳在时间顺序上晚于历史事务时间戳,满足 客户端定义的因果序。在一实施例中,所述任一数据库服务器可先将自身的时钟与所述校正时间戳进行比较,再根据比较结果确定生成响应于所述执行请求的事务时间戳的依据。比如,若所述任一数据库服务器自身的时钟不大于所述校正时间戳,则根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳,否则,根据自身的时钟生成响应于所述执行请求的事务时间戳。其中,当自身的时钟不大于所述校正时间戳时,可进一步将自身的时钟修改为大于所述校正时间戳,从而使得自身的时钟不慢于其他数据库服务器的时钟。在另一实施例中,所述任一数据库服务器可直接根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。通过省略将自身的时钟与所述校正时间戳进行比较的操作,可提高生成事务时间戳的效率。
相应的,图3是一示例性实施例提供的一种数据库服务器侧事务因果序的校正方法的流程图。如图3所示,该方法可以包括以下步骤:
步骤302,接收校正时间戳。
在本实施例中,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为客户端向各数据库服务器请求执行的历史事务。其中,关于所述校正时间戳的详细描述,可参考上述图3实施例中的相关内容,在此不再赘述。
步骤304,当接收到所述客户端发起的针对待执行事务的执行请求时,根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。
在本实施例中,若自身的时钟不大于所述校正时间戳,则根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳;否则,根据自身的时钟生成响应于所述执行请求的事务时间戳。进一步的,当自身的时钟不大于所述校正时间戳时,可将自身的时钟修改为大于所述校正时间戳,从而使得自身的时钟不慢于其他数据库服务器的时钟。类似的,针对数据库服务器根据校正时间戳生成事务时间戳的操作,其详细说明可参考上述图2实施例中的相关内容,在此不再赘述。
为了便于理解,下面以客户端请求修改数据为例,对本说明书一个或多个实施例的技术方案进行详细说明。图4是一示例性实施例提供的一种事务因果序的校正方法的交互图。如图4所示,客户端先后向数据库服务器A、数据库服务器B请求修改数据;其中,在数据库服务器A修改数据成功后,客户端再向数据库服务器B请求修改数据。 该校正方法可以包括以下步骤:
步骤401,客户端向数据库服务器A发送执行请求a,以修改数据库服务器A中的数据a。
在本实施例中,客户端可通过连接池与各个数据库服务器进行通信。
步骤402,数据库服务器A修改数据a。
步骤403,数据库服务器A生成事务时间戳a。
步骤404,数据库服务器A向客户端返回修改结果a和事务时间戳a。
步骤405,客户端确定校正时间戳。
在本实施例中,可将校正时间戳设置为等于最近事务时间戳。而在当前阶段,最近事务时间戳为事务时间戳a;因此,可将校正时间戳设置为等于事务时间戳a。例如,假定事务时间戳a为92,那么可将校正时间戳设置为92。当然,也可将校正时间戳设置为大于最近事务时间戳;比如,承接于上述举例,可将校正时间戳设置为93、94、95等。
步骤406,客户端向数据库服务器B发送执行请求b和校正时间戳。
在本实施例中,客户端在确定出数据库服务器A已经完成对数据a进行修改后,向数据库服务器B发送执行请求b以修改数据库服务器B中的数据b。那么,此时的因果序为“数据库服务器A修改数据a”发生于“数据库服务器B修改数据b”之前。
步骤407,数据库服务器B比较校正时间戳与自身的时钟。
步骤408,当自身的时钟不大于校正时间戳时,数据库服务器B将自身的时钟修改为大于校正时间戳。
步骤409,数据库服务器B修改数据b。
步骤410,数据库服务器B生成事务时间戳b。
在本实施例中,当自身的时钟大于校正时间戳时,数据库服务器B无需将自身的时钟修改为大于校正时间戳,直接根据自身的时钟记录的时刻生成事务时间戳b(事务“修改数据b”的时刻)即可。当数据库服务器B自身的时钟不大于校正时间戳(此时校正时间戳等于事务时间戳a,而事务时间戳a为事务“修改数据a”的时刻)时,若继续采用自身时钟记录的时间来生成事务时间戳b,则将导致事务时间戳b不大于事务时间 戳a,即数据库服务器A修改数据a”并非发生于“数据库服务器B修改数据b”之前,从而不符合因果序。
因此,可先将自身的时钟修改为大于校正时间戳,再根据修改后的时钟来生成事务时间戳b以满足上述因果序。比如,承接于上述校正时间戳等于事务时间戳a的举例,假定自身的时钟为90,由于自身的时钟为90小于校正时间戳92,可将自身的时钟修改为93,再采用修改后的时钟记录的时刻生成事务时间戳b,即事务时间戳b为93。可见,事务时间戳b大于事务时间戳a,满足“数据库服务器A修改数据a发生于数据库服务器B修改数据b之前”的因果序。当然,修改的幅度可根据实际情况灵活设定,本说明书并不对此进行限制。例如,还可将自身的时钟修改为94、95、100等。通过对自身的时钟进行修改,可使得自身的时钟不慢于数据库服务器A的时钟。那么后续再出现上述因果序的要求时,可以避免数据库服务器B频繁修改自身的时钟。
需要说明的是,也可以省略将自身的时钟修改为大于校正时间戳的操作(即省略步骤408),直接在比较出自身的时钟不大于校正时间戳,以及执行事务“修改数据b”后,生成大于校正时间戳的事务时间戳b,从而可避免对自身的时钟进行修改。
在本实施例中,数据库服务器B还可省略步骤407的比较操作(那么步骤408也随之无需执行),直接在执行事务“修改数据b”后,生成大于校正时间戳的事务时间戳b,从而可避免对自身的时钟进行修改。同时,通过省略将自身的时钟与校正时间戳进行比较的操作,可提高生成事务时间戳的效率。
步骤411,数据库服务器B向客户端返回修改结果b和事务时间戳b。
步骤412,客户端根据事务时间戳b更新校正时间戳。
在本实施例中,在当前阶段,最近事务时间戳由事务时间戳a更换为事务时间戳b;因此,需要将校正时间戳由事务时间戳a更新为事务时间戳b。比如,承接于上述事务时间戳b为93的举例,可将校正时间戳更新为93。
在本申请的技术方案中,还可由中间件设备来维护校正时间戳,以实现事务因果序的校正方案。请参见图5,图5是一示例性实施例提供的另一种事务因果序的校正系统的架构示意图。如图5所示,该系统可以包括客户端30A-30C、中间件设备40和分布式数据库50(包括数据库服务器50A、50B等)。其中,中间件设备40连接于客户端30A-30C与分布式数据库50之间,运行有中间件,从而可用于传输客户端30A-30C与分布式数据库50中各数据库服务器(数据库服务器50A、50B等)之间进行通信的数 据。另外,客户端30A-30C和分布式数据库50与上述图1中的客户端10和分布式数据库20类似,其详细说明可参考上述图1所示架构的相关内容,在此不再赘述。
请参见图6,图6是一示例性实施例提供的一种中间件设备侧事务因果序的校正方法。如图6所示,所述中间件设备中可运行中间件,以用于传输客户端与分布式数据库中各数据库服务器之间进行通信的数据;该方法可以包括以下步骤:
步骤602,检测客户端发起的针对分布式数据库中任一数据库服务器的待执行事务的执行请求。
步骤604,确定校正时间戳。
在本实施例中,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务。其中,关于所述校正时间戳的详细描述,可参考上述图2实施例中的相关内容,在此不再赘述。
在本实施例中,基于由独立于客户端的中间件设备来维护校正时间戳,当存在多个客户端时,该多个客户端均可通过同一中间件设备与分布式数据库中的各个数据库服务器进行通信。因此,中间件设备可维护对应于各个客户端的校正时间戳;其中,可建立客户端标识与相应校正时间戳的映射关系。那么,中间件设备在确定校正时间戳时,可先确定所述执行请求的发送方客户端的客户端标识,再(根据所述映射关系)确定对应于所述客户端标识的校正时间戳。
步骤606,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
为了便于理解,下面以客户端请求修改数据为例,对本说明书一个或多个实施例的技术方案进行详细说明。如图7所示,图7是一示例性实施例提供的另一种事务因果序的校正方法的交互图。中间件设备中运行有中间件,用于传输各个客户端与分布式数据库中各数据库服务器之间进行通信的数据。客户端A先后向数据库服务器C、数据库服务器D请求修改数据;其中,在数据库服务器C修改数据成功后,客户端A再向数据库服务器D请求修改数据。该校正方法可以包括以下步骤:
步骤701,客户端A向中间件设备发送执行请求c,以修改数据库服务器C中的数据c;
在本实施例中,客户端A可通过连接池与中间件设备进行通信。
步骤702,中间件设备向数据库服务器C转发执行请求c。
步骤703,数据库服务器C修改数据c。
步骤704,数据库服务器C生成事务时间戳c。
步骤705,数据库服务器C向中间件设备返回修改结果c和事务时间戳c。
步骤706,中间件设备确定校正时间戳a。
在本实施例中,可将对应于客户端A的校正时间戳a设置为等于客户端A的最近事务时间戳。而在当前阶段,客户端A的最近事务时间戳为事务时间戳c;因此,可将校正时间戳a设置为等于事务时间戳c。例如,假定事务时间戳c为100,那么可将校正时间戳a设置为100。当然,也可将校正时间戳a设置为大于最近事务时间戳。比如,承接于上述举例,可将校正时间戳a设置为101、104、109等。由于中间件设备中维护有对应于各个客户端的校正时间戳,中间件设备可建立客户端标识与相应校正时间戳的映射关系,以区分出各个校正时间戳。举例而言,可将客户端的IP地址作为客户端标识,那么可建立如表1所示的映射关系:
校正时间戳 | IP地址 |
校正时间戳a | 1.1.1.1 |
校正时间戳b | 1.1.1.2 |
校正时间戳c | 1.1.1.3 |
…… | …… |
表1
当然,也可以采用其他与客户端相关的信息作为客户端标识,本说明书并不对此进行限制。
步骤707,中间件设备向客户端A转发修改结果c。
在本实施例中,中间件设备可以只向客户端A转发修改结果c,而无需转发校正时间戳a,从而可实现对客户端A的透明处理,使得客户端A感知不到校正时间戳的维护过程,按照正常的请求修改数据的流程执行即可。
步骤708,客户端A向中间件设备发送执行请求d,以修改数据库服务器D中的数据d。
在本实施例中,客户端A在确定出数据库服务器C已经完成对数据c进行修改后,向数据库服务器D发送执行请求d以修改数据d。那么,此时的因果序为“数据库服务器C修改数据c”发生于“数据库服务器D修改数据d”之前。
步骤709,中间件设备向数据库服务器D转发执行请求d和校正时间戳a。
在本实施例中,基于对上述表1中映射关系的建立,中间件设备在确定对应于客户端A的校正时间戳a时,可先确定客户端A的客户端标识(即客户端A的IP地址),再根据上述表1中的映射关系确定对应于客户端A的校正时间戳a。
步骤710,数据库服务器D比较校正时间戳a与自身的时钟。
步骤711,当自身的时钟不大于校正时间戳a时,数据库服务器D将自身的时钟修改为大于校正时间戳a。
步骤712,数据库服务器D修改数据d。
步骤713,数据库服务器D生成事务时间戳d。
在本实施例中,当自身的时钟大于校正时间戳a时,数据库服务器D无需将自身的时钟修改为大于校正时间戳a,直接根据自身的时钟记录的时刻生成事务时间戳d(事务“修改数据d”的时刻)即可。当数据库服务器D自身的时钟不大于校正时间戳(此时校正时间戳a等于事务时间戳c,而事务时间戳c为事务“修改数据c”的时刻)时,若继续采用自身时钟记录的时间来生成事务时间戳d,则将导致事务时间戳d不大于事务时间戳c,即数据库服务器C修改数据c”并非发生于“数据库服务器D修改数据d”之前,从而不符合因果序。
因此,可先将自身的时钟修改为大于校正时间戳,再根据修改后的时钟来生成事务时间戳d以满足上述因果序。比如,承接于上述校正时间戳a等于事务时间戳c的举例,假定自身的时钟为98,由于自身的时钟为98小于校正时间戳a的取值100,可将自身的时钟修改为101,再采用修改后的时钟记录的时刻生成事务时间戳d,即事务时间戳d为101。可见,事务时间戳d大于事务时间戳c,满足“数据库服务器C修改数据c发生于数据库服务器D修改数据d之前”的因果序。当然,修改的幅度可根据实际情况灵活设定,本说明书并不对此进行限制。例如,还可将自身的时钟修改为102、105、111等。通过对自身的时钟进行修改,可使得自身的时钟不慢于数据库服务器C的时钟。那么后续再出现上述因果序的要求时,可以避免数据库服务器D频繁修改自身的时钟。
需要说明的是,也可以省略将自身的时钟修改为大于校正时间戳a的操作(即省略步骤711),直接在比较出自身的时钟不大于校正时间戳a,以及执行事务“修改数据d”后,生成大于校正时间戳a的事务时间戳d,从而可避免对自身的时钟进行修 改。
在本实施例中,数据库服务器D还可省略步骤710的比较操作(那么步骤711也随之无需执行),直接在执行事务“修改数据d”后,生成大于校正时间戳a的事务时间戳d,从而可避免对自身的时钟进行修改。同时,通过省略将自身的时钟与校正时间戳进行比较的操作,可提高生成事务时间戳的效率。
步骤714,数据库服务器D向中间件设备返回修改结果d和事务时间戳d。
步骤715,中间件设备根据事务时间戳d更新校正时间戳a。
在本实施例中,在当前阶段,客户端A的最近事务时间戳由事务时间戳c更换为事务时间戳d;因此,需要将校正时间戳a由事务时间戳c更新为事务时间戳d。比如,承接于上述事务时间戳d为101的举例,可将校正时间戳a更新为101。
步骤716,中间件设备向客户端A转发修改结果d。
由以上技术方案可见,通过维护校正时间戳(不小于历史事务的事务时间戳),并将校正时间戳发送至需请求执行事务的数据库服务器,使得该数据库服务器在执行事务时可根据校正时间戳生成大于校正时间戳的事务时间戳,即符合客户端定义的因果序。
图8是一示例性实施例提供的一种电子设备的示意结构图。请参考图8,在硬件层面,该设备包括处理器802、内部总线804、网络接口806、内存808以及非易失性存储器810,当然还可能包括其他业务所需要的硬件。处理器802从非易失性存储器810中读取对应的计算机程序到内存808中然后运行,在逻辑层面上形成事务因果序的校正装置。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。
请参考图9,在软件实施方式中,事务因果序的校正装置应用于中间件设备,所述中间件设备用于传输客户端与分布式数据库中各数据库服务器之间进行通信的数据;该事务因果序的校正装置可以包括:
检测单元91,检测客户端发起的针对分布式数据库中任一数据库服务器的待执行事务的执行请求;
确定单元92,确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;
发送单元93,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
可选的,所述中间件设备用于传输多个客户端与分布式数据库中各数据库服务器之间进行通信的数据,所述中间件设备维护有对应于各个客户端的校正时间戳;所述确定单元92具体用于:
确定所述执行请求的发送方客户端的客户端标识;
确定对应于所述客户端标识的校正时间戳。
可选的,所述校正时间戳为所述客户端最近一次向数据库服务器请求执行的事务的事务时间戳。
图10是一示例性实施例提供的另一种电子设备的示意结构图。请参考图10,在硬件层面,该设备包括处理器1002、内部总线1004、网络接口1006、内存1008以及非易失性存储器1010,当然还可能包括其他业务所需要的硬件。处理器1002从非易失性存储器1010中读取对应的计算机程序到内存1008中然后运行,在逻辑层面上形成事务因果序的校正装置。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。
请参考图11,在软件实施方式中,该事务因果序的校正装置应用于客户端;可以包括:
请求单元1101,向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求;
确定单元1102,确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;
发送单元1103,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
图12是一示例性实施例提供的另一种电子设备的示意结构图。请参考图12,在硬件层面,该设备包括处理器1202、内部总线1204、网络接口1206、内存1208以及非易失性存储器1212,当然还可能包括其他业务所需要的硬件。处理器1202从非易失性存储器1212中读取对应的计算机程序到内存1208中然后运行,在逻辑层面上形成事务 因果序的校正装置。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。
请参考图13,在软件实施方式中,该事务因果序的校正装置应用于数据库服务器,可以包括:
接收单元1301,接收校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为客户端向各数据库服务器请求执行的历史事务;
生成单元1302,当接收到所述客户端发起的针对待执行事务的执行请求时,根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。
可选的,所述生成单元1302具体用于:
若自身的时钟不大于所述校正时间戳,则根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳;
否则,根据自身的时钟生成响应于所述执行请求的事务时间戳。
可选的,还包括:
修改单元1303,当自身的时钟不大于所述校正时间戳时,将自身的时钟修改为大于所述校正时间戳。
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。
在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方 法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。
应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的 任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。
Claims (17)
- 一种事务因果序的校正方法,应用于中间件设备,所述中间件设备用于传输客户端与分布式数据库中各数据库服务器之间进行通信的数据;所述方法包括:检测客户端发起的针对分布式数据库中任一数据库服务器的待执行事务的执行请求;确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
- 根据权利要求1所述的方法,所述中间件设备用于传输多个客户端与分布式数据库中各数据库服务器之间进行通信的数据,所述中间件设备维护有对应于各个客户端的校正时间戳;所述确定校正时间戳,包括:确定所述执行请求的发送方客户端的客户端标识;确定对应于所述客户端标识的校正时间戳。
- 根据权利要求1所述的方法,所述校正时间戳为所述客户端最近一次向数据库服务器请求执行的事务的事务时间戳。
- 一种事务因果序的校正方法,应用于客户端;所述方法包括:向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求;确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
- 一种事务因果序的校正方法,应用于数据库服务器;所述方法包括:接收校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为客户端向各数据库服务器请求执行的历史事务;当接收到所述客户端发起的针对待执行事务的执行请求时,根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。
- 根据权利要求5所述的方法,所述根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳,包括:若自身的时钟不大于所述校正时间戳,则根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳;否则,根据自身的时钟生成响应于所述执行请求的事务时间戳。
- 根据权利要求6所述的方法,还包括:当自身的时钟不大于所述校正时间戳时,将自身的时钟修改为大于所述校正时间戳。
- 一种事务因果序的校正装置,应用于中间件设备,所述中间件设备用于传输客户端与分布式数据库中各数据库服务器之间进行通信的数据;所述装置包括:检测单元,检测客户端发起的针对分布式数据库中任一数据库服务器的待执行事务的执行请求;确定单元,确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;发送单元,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
- 根据权利要求8所述的装置,所述中间件设备用于传输多个客户端与分布式数据库中各数据库服务器之间进行通信的数据,所述中间件设备维护有对应于各个客户端的校正时间戳;所述确定单元具体用于:确定所述执行请求的发送方客户端的客户端标识;确定对应于所述客户端标识的校正时间戳。
- 根据权利要求8所述的装置,所述校正时间戳为所述客户端最近一次向数据库服务器请求执行的事务的事务时间戳。
- 一种事务因果序的校正装置,应用于客户端;所述装置包括:请求单元,向分布式数据库中任一数据库服务器发起针对待执行事务的执行请求;确定单元,确定校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为所述客户端向各数据库服务器请求执行的历史事务;发送单元,向所述任一数据库服务器发送校正时间戳,以使得所述任一数据库服务器响应于所述执行请求的事务时间戳大于所述校正时间戳。
- 一种事务因果序的校正装置,应用于数据库服务器;所述装置包括:接收单元,接收校正时间戳,所述校正时间戳不小于历史事务的事务时间戳,所述历史事务为客户端向各数据库服务器请求执行的历史事务;生成单元,当接收到所述客户端发起的针对待执行事务的执行请求时,根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳。
- 根据权利要求12所述的装置,所述生成单元具体用于:若自身的时钟不大于所述校正时间戳,则根据所述校正时间戳生成响应于所述执行请求的事务时间戳,以使得所述事务时间戳大于所述校正时间戳;否则,根据自身的时钟生成响应于所述执行请求的事务时间戳。
- 根据权利要求13所述的装置,还包括:修改单元,当自身的时钟不大于所述校正时间戳时,将自身的时钟修改为大于所述校正时间戳。
- 一种电子设备,包括:处理器;用于存储处理器可执行指令的存储器;其中,所述处理器被配置为实现如权利要求1-3中任一项所述的方法。
- 一种电子设备,包括:处理器;用于存储处理器可执行指令的存储器;其中,所述处理器被配置为实现如权利要求4中所述的方法。
- 一种电子设备,包括:处理器;用于存储处理器可执行指令的存储器;其中,所述处理器被配置为实现如权利要求5-7中任一项所述的方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810550782.4A CN108829497A (zh) | 2018-05-31 | 2018-05-31 | 事务因果序的校正方法及装置、电子设备 |
CN201810550782.4 | 2018-05-31 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2019228012A1 true WO2019228012A1 (zh) | 2019-12-05 |
Family
ID=64147120
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2019/077435 WO2019228012A1 (zh) | 2018-05-31 | 2019-03-08 | 事务因果序的校正方法及装置、电子设备 |
Country Status (3)
Country | Link |
---|---|
CN (1) | CN108829497A (zh) |
TW (1) | TWI716822B (zh) |
WO (1) | WO2019228012A1 (zh) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108829497A (zh) * | 2018-05-31 | 2018-11-16 | 阿里巴巴集团控股有限公司 | 事务因果序的校正方法及装置、电子设备 |
CN109560985A (zh) * | 2018-11-19 | 2019-04-02 | 北京航空航天大学 | 一种因果语义测试方法 |
CN110018884B (zh) * | 2019-03-19 | 2023-06-06 | 创新先进技术有限公司 | 分布式事务处理方法、协调装置、数据库及电子设备 |
CN113946448B (zh) * | 2021-10-28 | 2024-05-28 | 苏州浪潮智能科技有限公司 | 一种服务器集群的时序管理方法、装置及电子设备 |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20060194573A1 (en) * | 2005-02-28 | 2006-08-31 | Fujitsu Limited & Citizen Watch Co., Ltd. | Method and apparatus for time calibration |
CN1960242A (zh) * | 2006-10-17 | 2007-05-09 | 中控科技集团有限公司 | 实现时钟同步的方法、装置、系统及分布式系统 |
CN104615478A (zh) * | 2014-12-31 | 2015-05-13 | 电子科技大学 | 一种用于分布式仿真的仿真推进顺序错误识别及修正方法 |
CN106330465A (zh) * | 2016-11-21 | 2017-01-11 | 航天信息股份有限公司 | 一种分布式时间戳的处理方法、服务器及系统 |
CN108829497A (zh) * | 2018-05-31 | 2018-11-16 | 阿里巴巴集团控股有限公司 | 事务因果序的校正方法及装置、电子设备 |
Family Cites Families (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
FR2702577B1 (fr) * | 1993-03-11 | 1995-04-28 | Gec Alsthom Transport Sa | Procédé pour contrôler l'exécution correcte d'un programme d'ordinateur multitâche. |
US6571270B1 (en) * | 1999-03-15 | 2003-05-27 | International Business Machines Corporation | Timeout detection facility |
US7856463B2 (en) * | 2006-03-21 | 2010-12-21 | Advantest Corporation | Probability density function separating apparatus, probability density function separating method, testing apparatus, bit error rate measuring apparatus, electronic device, and program |
JP2012018201A (ja) * | 2010-07-06 | 2012-01-26 | Hitachi Ltd | テキスト補正方法及び認識方法 |
CN104871453B (zh) * | 2012-12-27 | 2017-08-25 | 松下电器(美国)知识产权公司 | 影像显示方法和装置 |
CN106155780B (zh) * | 2015-04-02 | 2020-01-31 | 阿里巴巴集团控股有限公司 | 一种基于时间的节点选举方法及装置 |
CN106325978B (zh) * | 2015-06-19 | 2020-06-30 | 阿里巴巴集团控股有限公司 | 分布式事务的处理方法及装置 |
CN105183536B (zh) * | 2015-09-14 | 2018-11-13 | 中国人民解放军国防科学技术大学 | 基于gpu的乐观时间管理方法 |
-
2018
- 2018-05-31 CN CN201810550782.4A patent/CN108829497A/zh active Pending
-
2019
- 2019-02-25 TW TW108106322A patent/TWI716822B/zh active
- 2019-03-08 WO PCT/CN2019/077435 patent/WO2019228012A1/zh active Application Filing
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20060194573A1 (en) * | 2005-02-28 | 2006-08-31 | Fujitsu Limited & Citizen Watch Co., Ltd. | Method and apparatus for time calibration |
CN1960242A (zh) * | 2006-10-17 | 2007-05-09 | 中控科技集团有限公司 | 实现时钟同步的方法、装置、系统及分布式系统 |
CN104615478A (zh) * | 2014-12-31 | 2015-05-13 | 电子科技大学 | 一种用于分布式仿真的仿真推进顺序错误识别及修正方法 |
CN106330465A (zh) * | 2016-11-21 | 2017-01-11 | 航天信息股份有限公司 | 一种分布式时间戳的处理方法、服务器及系统 |
CN108829497A (zh) * | 2018-05-31 | 2018-11-16 | 阿里巴巴集团控股有限公司 | 事务因果序的校正方法及装置、电子设备 |
Also Published As
Publication number | Publication date |
---|---|
TWI716822B (zh) | 2021-01-21 |
TW202004592A (zh) | 2020-01-16 |
CN108829497A (zh) | 2018-11-16 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019228012A1 (zh) | 事务因果序的校正方法及装置、电子设备 | |
US11106655B2 (en) | Asset management system, method, apparatus, and electronic device | |
TWI689181B (zh) | 資料處理方法和系統 | |
US8892677B1 (en) | Manipulating objects in hosted storage | |
WO2020134615A1 (zh) | 跨链存证方法及访问方法、装置、电子设备 | |
WO2019237594A1 (zh) | 会话保持方法、装置、计算机设备及存储介质 | |
US11212371B2 (en) | Operation request allocation methods, apparatuses, and devices | |
US10193997B2 (en) | Encoded URI references in restful requests to facilitate proxy aggregation | |
US20210158352A1 (en) | Methods and systems for recording data based on plurality of blockchain networks | |
CN111143462A (zh) | 数据导出的方法、装置、计算机设备和存储介质 | |
US11500861B2 (en) | Methods and systems for recording data based on plurality of blockchain networks | |
US10938957B1 (en) | System and method for bridging gaps between traditional resource management solutions with cloud-based management solutions | |
US20210160054A1 (en) | Methods and systems for reading data based on plurality of blockchain networks | |
US9742676B2 (en) | Highly available servers | |
TWI697223B (zh) | 資料處理方法 | |
WO2017157111A1 (zh) | 防止内存数据丢失的的方法、装置和系统 | |
WO2016101759A1 (zh) | 一种数据路由方法、数据管理装置和分布式存储系统 | |
TW201727517A (zh) | 資料儲存與業務處理的方法及裝置 | |
US11275601B2 (en) | System and method for auto recovery of deleted virtual machines identified through comparison of virtual machine management application snapshots and having corresponding backups at a storage device | |
US7933962B1 (en) | Reducing reliance on a central data store while maintaining idempotency in a multi-client, multi-server environment | |
US11966373B2 (en) | System and method data quality validation for migrating servicing layer implementations | |
WO2023207087A1 (zh) | 用于区块链的最优链路选择方法及装置和电子设备 | |
WO2019242279A1 (zh) | 一种消息处理方法及装置 | |
US11086849B2 (en) | Methods and systems for reading data based on plurality of blockchain networks | |
CN113296968B (zh) | 地址列表更新方法、装置、介质及电子设备 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19810491 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 19810491 Country of ref document: EP Kind code of ref document: A1 |