Logical timestamp acquisition and distribution method applied to distributed database
By introducing a timestamp proxy and cache module on each server node of a distributed database, the problem of excessive load on the global timestamp manager under high concurrency is solved, timestamps can be quickly obtained, and transaction processing efficiency is improved.
Patent Information
- Application Number
- CN202510947328.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2045-07-10
AI Technical Summary
In distributed databases, the global timestamp manager is overloaded in high-concurrency scenarios, resulting in excessive consumption of CPU and network resources, long timestamp application times, and slow transaction execution.
A timestamp proxy module and a cache module are deployed on each server node. Timestamps are requested from the global timestamp manager at fixed time intervals, and the requested and assigned timestamps are cached in the cache module. The transaction module performs comparisons and sleeps to obtain the latest timestamps when processing transactions.
This reduces the pressure on the global timestamp manager, reduces resource competition, avoids computing bottlenecks, improves transaction processing speed, and saves locking and unlocking operations on shared linked lists.
Smart Images

Figure CN120448140B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and further belongs to the field of distributed database global consistency technology, and more specifically relates to a method for obtaining and allocating logical timestamps applied to distributed databases. Background Art
[0002] Database transactions must meet consistency requirements. In a stand-alone database, each transaction is assigned a timestamp through a monotonically increasing time series to achieve transaction consistency.
[0003] For example, a database contains concurrent transactions T1 and T2, and client C accesses the transaction results. If transaction T1 commits first and is assigned timestamp 100, and client C accesses database data at timestamp 110, and transaction T2 commits and is assigned timestamp 120, the data seen by client C is the result of transaction T1, and the result of transaction T2 is invisible to client C.
[0004] In a distributed database, a similar monotonically increasing time series is also required to meet the consistency requirements of transactions. However, in a distributed database, transaction modules run on different server nodes, so the module that maintains the monotonically increasing data series is called a global timestamp manager.
[0005] All transactions apply for timestamps from the global timestamp manager to meet the consistency requirements of transactions. Because the transaction module and the global timestamp manager module run on different server nodes, the timestamp allocation action needs to be completed through network communication (RPC call).
[0006] In a high-concurrency scenario, thousands of transactions may be running simultaneously on each server node, and each cluster may have dozens to hundreds of server nodes. If each transaction applies for a timestamp from the global timestamp manager, it will put a lot of pressure on the global timestamp manager.
[0007] Each transaction needs to wait for a response from the global timestamp manager when applying for a timestamp. When the concurrency pressure is high, this waiting time will be very long, affecting the speed of transaction execution. Summary of the Invention
[0008] The purpose of the present invention is to solve the problems of excessive load on the global timestamp manager of a distributed database under high concurrency, excessive consumption of CPU and network resources, and long time to apply for timestamps, and to provide a method for obtaining and allocating logical timestamps applied to a distributed database.
[0009] The present invention is achieved through the following technical solutions:
[0010] A method for obtaining and allocating logical timestamps applied to a distributed database, the method comprising:
[0011] The timestamp proxy module of each server node sends a timestamp application request to the global timestamp manager of the distributed database system at fixed time intervals and receives the timestamp allocated by the global timestamp manager in response; the timestamp proxy module caches the time Treq of the requested timestamp and the allocated timestamp Timestamp in the timestamp cache module of the server node where the timestamp proxy module is located;
[0012] When processing a transaction, the transaction module of each server node compares the time Tstart of the transaction application timestamp with the time Treq of the request timestamp currently cached by the timestamp cache module in the server node where the transaction is located. If Treq is greater than or equal to Tstart, the timestamp Timestamp currently cached by the timestamp cache module is used as the timestamp required for the transaction; if Treq is less than Tstart, the transaction module processing the transaction is actively put to sleep for a set time so that the Treq updated by the timestamp cache module after the sleep period is greater than or equal to Tstart, and the latest timestamp Timestamp in the timestamp cache module is used as the timestamp required for the transaction.
[0013] In the above technical solution, the workflow of the timestamp agent module and the global timestamp manager includes the following steps:
[0014] Step S1.1: The timestamp agent module sends a timestamp request message to the global timestamp manager and records the time Treq of the timestamp request;
[0015] Step S1.2: Upon receiving the request message, the global timestamp manager increments the monotonically increasing sequence it maintains by 1;
[0016] Step S1.3: The global timestamp manager responds to the request message and sends the allocated timestamp Timestamp to the timestamp agent module;
[0017] Step S1.4: The timestamp proxy module receives the assigned timestamp Timestamp, and then stores the recorded request timestamp time Treq and the assigned timestamp Timestamp into the timestamp cache module.
[0018] In the above technical solution, the timestamp cache module has two storage units, the first storage unit is used to store the time of requesting the timestamp, and the second storage unit is used to store the allocated timestamp.
[0019] In the above technical solution, the timestamp data cached by the timestamp cache module is updated periodically at fixed time intervals, so that the timestamp cache module of each server node stores the latest requested timestamp time Treq and the allocated timestamp Timestamp in real time.
[0020] In the above technical solution, a global timestamp manager is set in the distributed database system. The global timestamp manager is responsible for processing received timestamp application requests. The global timestamp manager maintains a monotonically increasing timestamp sequence, and each timestamp application request increases the value of the sequence by 1.
[0021] In the above technical solution, a timestamp proxy module and a timestamp cache module are respectively deployed on each server node in the distributed database system.
[0022] In the above technical solution, the sleep time is set to Tstart - Treq.
[0023] Another aspect of the present invention provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned method.
[0024] Another aspect of the present invention provides a computer-readable storage medium storing computer-executable instructions, which are used to implement the above method when executed.
[0025] Another aspect of the present invention provides a computer program product, which includes computer executable instructions. When the instructions are executed, they are used to implement the above method.
[0026] The advantages and beneficial effects of the present invention are:
[0027] The present invention introduces a timestamp proxy module and a timestamp cache module into each server node. The timestamp proxy module sends timestamp request requests to the global timestamp manager of the distributed database system at fixed time intervals and receives the timestamps allocated by the global timestamp manager in response. The timestamp proxy module caches the time Treq of the requested timestamp and the allocated timestamp Timestamp in the timestamp cache module and updates them, so that the timestamp cache module of each server node stores the latest time Treq of the requested timestamp and the allocated timestamp Timestamp in real time. When processing transactions, the transaction module reuses the timestamps cached in the timestamp cache module obtained by the timestamp proxy module, thereby reducing the pressure on the global timestamp manager, reducing resource competition, and avoiding computing bottlenecks in large concurrency scenarios.
[0028] The transaction module actively enters a sleep state during idle time while waiting to obtain timestamps to reduce CPU consumption. In addition, by precisely controlling the transaction module's active sleep time, the transaction module is guaranteed to obtain timestamps as quickly as possible.
[0029] In addition, the method of the present invention does not require a shared linked list data structure, thus saving frequent locking and unlocking operations caused by concurrent access to the shared linked list. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 This is an application scenario diagram of the method for obtaining and allocating logical timestamps applied to a distributed database according to the present invention.
[0031] Figure 2 This is an architectural flow chart of the method for obtaining and allocating logical timestamps applied to a distributed database according to the present invention.
[0032] Figure 3 A schematic diagram of storing the time Treq for requesting a timestamp and the assigned timestamp Timestamp in the timestamp cache module.
[0033] Figure 4 Schematic diagram of updating cache data for the timestamp cache module.
[0034] Figure 5 This is the workflow diagram of the timestamp agent module.
[0035] Figure 6 Flowchart of applying for a submission timestamp for a transaction in the present invention.
[0036] For ordinary technicians in this field, other relevant drawings can be obtained based on the above drawings without any creative work. DETAILED DESCRIPTION
[0037] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concept of the present invention.
[0038] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the presence of the features, steps, operations and / or components, but do not exclude the presence or addition of one or more other features, steps, operations or components.
[0039] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0040] In the technical solution of the present invention, the user information involved (including but not limited to user personal information, user image information, user device information, such as location information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, invention and application of the relevant data comply with relevant laws, regulations and standards, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0041] In scenarios where personal information is used for automated decision-making, the methods, devices, and systems provided by embodiments of the present invention provide users with corresponding operational portals, allowing them to choose to agree or reject the automated decision-making results; if the user chooses to reject, the expert decision-making process will be entered. The term "automated decision-making" herein refers to the activity of automatically analyzing and evaluating an individual's behavioral habits, interests, or economic, health, or credit status through computer programs and making decisions. The term "expert decision-making" herein refers to the activity of decision-making by individuals who specialize in a particular field, possess specialized experience, knowledge, and skills, and have reached a certain level of professional expertise.
[0042] In a distributed database system, database transactions must meet consistency requirements. In high-concurrency scenarios, each server node may be running thousands of transactions simultaneously, and each cluster may have dozens to hundreds of server nodes. If every transaction requests a timestamp from the global timestamp manager, this will place a significant strain on the manager. Each transaction must wait for a response from the global timestamp manager during the timestamp request process. When the concurrency pressure is high, this wait time can be very long, thus slowing down transaction execution.
[0043] In view of this, an embodiment of the present invention provides a method for obtaining and allocating logical timestamps for a distributed database. The method comprises: a timestamp proxy module of each server node sends a timestamp application request to a global timestamp manager of the distributed database system at fixed time intervals and receives a timestamp allocated in response by the global timestamp manager; the timestamp proxy module caches the time Treq of the requested timestamp and the allocated timestamp Timestamp in a timestamp cache module of the server node where the timestamp proxy module is located; when processing a transaction, a transaction module of each server node compares the time Tstart of the transaction application timestamp with the time Treq of the requested timestamp currently cached by the timestamp cache module in the server node where the transaction is located; if Treq is greater than or equal to Tstart, the allocated timestamp Timestamp currently cached by the timestamp cache module is used as the timestamp required for the transaction; if Treq is less than Tstart, the transaction module processing the transaction is actively dormant for a set time so that after the dormant period, the updated Treq of the timestamp cache module is greater than or equal to Tstart, and the latest timestamp Timestamp in the timestamp cache module is used as the timestamp required for the transaction.
[0044] It should be noted that the logical timestamp acquisition and allocation method applied to distributed databases of the present invention can be used in the field of computer technology, in database task processing scenarios, and can also be used in any field other than the field of computer technology, such as the field of artificial intelligence technology.
[0045] Figure 1 The application scenario diagram of the method for obtaining and allocating logical timestamps applied to a distributed database according to an embodiment of the present invention is schematically shown.
[0046] like Figure 1 As shown, the application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a cluster server 105. The network 104 is used as a medium for providing a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the cluster server 105. The network 104 may include various connection types, such as wired or wireless communication links or optical fiber cables.
[0047] A user may use a first terminal device 101, a second terminal device 102, or a third terminal device 103 to interact with a cluster server 105 via a network 104 to receive or send messages, etc. Various communication client applications may be installed on the first terminal device 101, the second terminal device 102, or the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (for example only).
[0048] The first terminal device 101 , the second terminal device 102 , and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0049] Cluster server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using first terminal device 101, second terminal device 102, and third terminal device 103 (for example only). A distributed database is deployed on cluster server 105. Cluster server 105 includes multiple server nodes that can analyze and process received user requests and other data, and feed back processing results (e.g., web pages, information, or data obtained or generated based on user requests) to the terminal devices.
[0050] It should be noted that the method for obtaining and allocating logical timestamps applied to a distributed database provided in the embodiment of the present invention is executed by the cluster server 105 .
[0051] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0052] It should be noted that the sequence numbers of the operations in the following method are only used to indicate the operation for the purpose of description, and should not be regarded as indicating the order in which the operations should be performed. Unless explicitly stated, the method does not need to be performed in the order shown.
[0053] The following will be based on Figure 1 The scene described by Figures 2 to 6 A method for obtaining and allocating logical timestamps applied to a distributed database according to an embodiment of the present invention is described in detail.
[0054] Figure 2 The following schematically shows an architectural flow chart of a method for obtaining and allocating logical timestamps applied to a distributed database according to an embodiment of the present invention. Figure 2 As shown, the method includes:
[0055] A global timestamp manager is set up in the distributed database system (that is, there is only one global timestamp manager in the entire distributed database system). This global timestamp manager can be deployed on any server node in the distributed database system. The global timestamp manager is responsible for processing received timestamp request requests and maintains a monotonically increasing timestamp sequence. Each timestamp request increments the sequence value by 1.
[0056] Each server node has multiple transaction modules, which are used to process transactions. In high-concurrency scenarios, each server node may be running thousands of transactions simultaneously. When processing each transaction, all transaction modules on each server node need to obtain timestamps assigned by the global timestamp manager to meet transaction consistency requirements.
[0057] Specifically, the transaction module needs to apply for a timestamp as a snapshot when reading data to determine the visibility of the data; the transaction module needs to apply for a timestamp to mark the order in which transactions are submitted when submitting transactions.
[0058] For example, Example 1 is as follows:
[0059] 1) The initial value of data D in the distributed database is 0;
[0060] 2) Transaction T1 modifies the value of data D to 100 and applies for timestamp t1 when it is submitted;
[0061] 3) Transaction T2 obtains snapshot timestamp t2 when reading data D.
[0062] 4) Transaction T3 modifies the value of data D to 200, and the application submission timestamp is t3;
[0063] 5) Because t3>t2>t1, the value of data D read by transaction T2 is 100.
[0064] In a typical distributed database transaction, the frequency of data reading operations is greater than the frequency of transaction submission, that is, the frequency of applying for snapshot timestamps is greater than the frequency of applying for transaction submission timestamps.
[0065] A timestamp proxy module and a timestamp cache module are deployed on each server node in the distributed database system.
[0066] Step S1: The timestamp proxy module of each server node sends a timestamp request to the global timestamp manager of the distributed database system at a fixed time interval Tinterval and receives the timestamp allocated by the global timestamp manager in response; the timestamp proxy module caches the time Treq of the requested timestamp and the allocated timestamp Timestamp in the timestamp cache module of the server node where the timestamp proxy module is located. The workflow of the timestamp proxy module is shown in the attached Figure 5 .
[0067] Furthermore, step S1 is divided into four steps:
[0068] Step S1.1: The timestamp agent module sends a timestamp request message to the global timestamp manager and records the time Treq of the timestamp request;
[0069] Step S1.2: Upon receiving the request message, the global timestamp manager increments the monotonically increasing sequence it maintains by 1;
[0070] Step S1.3: The global timestamp manager responds to the request message and sends the allocated timestamp Timestamp to the timestamp agent module;
[0071] Step S1.4: The timestamp proxy module receives the assigned timestamp Timestamp, and then stores the recorded request timestamp time Treq and the assigned timestamp Timestamp into the timestamp cache module. Thus, the timestamp cache module stores both the request timestamp time Treq and the assigned timestamp Timestamp. Figure 3 .
[0072] Furthermore, the timestamp cache module has two storage units, the first storage unit is used to store the time of requesting the timestamp, and the second storage unit is used to store the allocated timestamp.
[0073] Furthermore, since the timestamp proxy module requests timestamps from the global timestamp management module at a fixed time interval Tinterval, the time from initiating the request to receiving the response for each request is fixed, so the timestamp data cached by the timestamp cache module will be updated at a time interval Tinterval (i.e., whenever the timestamp proxy module requests a new timestamp, it will record the time New Treq of the new request timestamp. When the timestamp proxy module obtains the new timestamp New Timestamp assigned by the global timestamp manager, it will update the New Treq and New Timestamp to the timestamp cache module, as shown in the following example). Figure 4As shown), the timestamp cache module of each server node saves the latest request timestamp time Treq and the assigned timestamp Timestamp in real time.
[0074] Furthermore, when Tinterval is configured smaller, the timestamp cache module updates the timestamps cached faster, and the transaction module obtains the required timestamps more quickly. However, the more requests the global timestamp manager receives per unit time, the greater the pressure. When Tinterval is configured larger, the timestamp cache module updates the timestamps cached, and the transaction module may lag behind the ideal time by Tinterval.
[0075] Step S2: When processing a transaction, the transaction module of each server node compares the time Tstart of the transaction application timestamp with the time Treq of the request timestamp currently cached by the timestamp cache module in the server node where the transaction is located. If Treq is greater than or equal to Tstart, the timestamp Timestamp currently cached by the timestamp cache module is used as the timestamp required for the transaction; if Treq is less than Tstart, the transaction module processing the transaction is actively put into sleep for a set time (the timestamp cache module will update data during the sleep period), so that the Treq updated by the timestamp cache module after the sleep period is greater than or equal to Tstart, and the latest timestamp Timestamp in the timestamp cache module is used as the timestamp required for the transaction.
[0076] For further information, see the attached Figure 6 Taking the T1 transaction in Example 1 (modifying the value of data D) as an example, the process of applying for a transaction commit timestamp is described:
[0077] 1) Transaction T1 modifies the value of data D;
[0078] 2) Transaction T1 starts to commit, and the commit start time Tstart is recorded;
[0079] 3) When transaction T1 applies for a commit timestamp, the timestamp cache module in the server node where the transaction is located compares the values of Treq and Tstart. If Treq ≥ Tstart, it means that the timestamp currently cached by the timestamp cache module was applied after the transaction started to commit, and therefore the timestamp is valid. In this case, the current timestamp is used directly as the commit timestamp for transaction T1.
[0080] 4) If Treq < Tstart, it indicates that this timestamp was applied before the transaction started to be committed. This timestamp cannot be used by transaction T1 and needs to wait for a new timestamp. Therefore, the transaction module handling this transaction is made to actively sleep for Tstart - Treq time. After the sleep time expires (the timestamp cache module will update the data during the sleep period), check again whether the updated Treq is greater than or equal to Tstart. If Treq ≥ Tstart (in this case, there is a high probability that Treq ≥ Tstart), the latest timestamp Timestamp is valid, and the latest timestamp Timestamp is used as the timestamp for transaction T1 to commit. In special cases (such as when there is network fluctuation), it may happen that after the sleep time expires, Treq is still less than Tstart. At this time, continue to sleep for Tstart - Treq time and then check until Treq ≥ Tstart, and then use the latest timestamp Timestamp as the timestamp for transaction T1 to commit.
[0081] Furthermore, taking the T2 transaction (i.e., reading data D) in Example 1 above as an example, the process of a transaction applying for a snapshot timestamp is described as follows:
[0082] 1) Transaction T2 starts to read data D and records the time Tstart when the SQL starts to read.
[0083] 2) When transaction T2 applies for a snapshot timestamp, compare the sizes of Treq and Tstart currently cached in the timestamp cache module of the server node where this transaction is located. If Treq ≥ Tstart, it indicates that the timestamp Timestamp currently cached in this timestamp cache module was applied after the transaction started to be committed. Therefore, this timestamp Timestamp is valid, and the current timestamp Timestamp is directly used as the snapshot timestamp for transaction T2.
[0084] 3) If Treq < Tstart, it indicates that this timestamp was applied before the transaction started to be committed. This timestamp cannot be used by transaction T2 and needs to wait for a new timestamp. Therefore, the transaction module handling this transaction is made to actively sleep for Tstart - Treq time. After the sleep time expires (the timestamp cache module will update the data during the sleep period), check again whether the updated Treq is greater than or equal to Tstart. If Treq ≥ Tstart (in this case, there is a high probability that Treq ≥ Tstart), then the latest timestamp Timestamp is valid, and the latest timestamp Timestamp is used as the snapshot timestamp required by transaction T2 to determine the visibility of the data. In special cases (such as when there is network fluctuation), it may happen that after the sleep time expires, Treq is still less than Tstart. At this time, continue to sleep for Tstart - Treq time and then check until Treq ≥ Tstart. After that, use the latest timestamp Timestamp as the snapshot timestamp of transaction T2.
[0085] The present invention also provides a computer-readable storage medium, which carries one or more programs. When the above one or more programs are executed, the method according to the embodiments of the present invention is implemented.
[0086] According to the embodiments of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include but is not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present invention, the computer-readable storage medium may be any tangible medium that contains or stores a program, and this program can be used by or combined with an instruction execution system, device, or component.
[0087] Embodiments of the present invention further include a computer program product, which includes a computer program. The computer program contains program codes for executing the method provided by the embodiments of the present invention. When the computer program product runs on an electronic device, the program codes are used to cause the electronic device to implement the method for obtaining and allocating logical timestamps applied to a distributed database provided by the embodiments of the present invention.
[0088] In one embodiment, the computer program may be stored on a tangible storage medium, such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may be transmitted and distributed in the form of a signal over a network medium, downloaded and installed via a communication component, and / or installed from a removable medium. The program code contained in the computer program may be transmitted using any suitable network medium, including but not limited to wireless, wired, or any suitable combination thereof.
[0089] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages. Specifically, these computer programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect via the Internet).
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of the systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram may represent a module, program segment, or portion of code, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the boxes may occur in an order different from that marked in the accompanying drawings. For example, two boxes shown in succession may actually be executed substantially in parallel, or they may sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, as well as the combination of boxes in the block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or may be implemented using a combination of dedicated hardware and computer instructions. It will be understood by those skilled in the art that the features described in the various embodiments of the present invention may be combined and / or coupled in various ways, even if such combinations or couplings are not explicitly described in the present invention. In particular, the features described in the various embodiments of the present invention may be combined and / or coupled in various ways without departing from the spirit and teachings of the present invention. All such combinations and / or combinations fall within the scope of the present invention.
[0091] The above describes embodiments of the present invention. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present invention. Although each embodiment has been described separately above, this does not mean that the measures in each embodiment cannot be advantageously used in combination. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.
Claims
1. A method for obtaining and allocating logical timestamps in a distributed database, characterized in that: The method includes: The timestamp proxy module of each server node sends a timestamp application request to the global timestamp manager of the distributed database system at fixed time intervals and receives the timestamp allocated by the global timestamp manager in response; the timestamp proxy module caches the time Treq of the requested timestamp and the allocated timestamp Timestamp in the timestamp cache module of the server node where the timestamp proxy module is located; When processing a transaction, the transaction module of each server node compares the time Tstart of the transaction application timestamp with the time Treq of the request timestamp currently cached by the timestamp cache module in the server node where the transaction is located. If Treq is greater than or equal to Tstart, the timestamp Timestamp currently cached by the timestamp cache module is used as the timestamp required for the transaction; if Treq is less than Tstart, the transaction module processing the transaction is actively put to sleep for a set time so that the Treq updated by the timestamp cache module after the sleep period is greater than or equal to Tstart, and the latest timestamp Timestamp in the timestamp cache module is used as the timestamp required for the transaction.
2. The method for obtaining and allocating logical timestamps in a distributed database according to claim 1, wherein: The workflow of the timestamp agent module and the global timestamp manager includes the following steps: Step S1.1: The timestamp agent module sends a timestamp request message to the global timestamp manager and records the time Treq of the timestamp request; Step S1.2: Upon receiving the request message, the global timestamp manager increments the monotonically increasing sequence it maintains by 1; Step S1.3: The global timestamp manager responds to the request message and sends the allocated timestamp Timestamp to the timestamp agent module; Step S1.4: The timestamp proxy module receives the assigned timestamp Timestamp, and then stores the recorded request timestamp time Treq and the assigned timestamp Timestamp into the timestamp cache module.
3. The method for obtaining and allocating logical timestamps in a distributed database according to claim 1, wherein: The timestamp cache module has two storage units, the first storage unit is used to store the time of requesting the timestamp, and the second storage unit is used to store the allocated timestamp.
4. The method for obtaining and allocating logical timestamps in a distributed database according to claim 1, wherein: The timestamp data cached by the timestamp cache module is updated periodically at fixed time intervals, so that the timestamp cache module of each server node saves the latest requested timestamp time Treq and the assigned timestamp Timestamp in real time.
5. The method for obtaining and allocating logical timestamps in a distributed database according to claim 1, wherein: A global timestamp manager is set up in the distributed database system. The global timestamp manager is responsible for processing the received timestamp application requests. The global timestamp manager maintains a monotonically increasing timestamp sequence. Each timestamp application request increases the value of the sequence by 1.
6. The method for obtaining and allocating logical timestamps in a distributed database according to claim 1, wherein: A timestamp proxy module and a timestamp cache module are deployed on each server node in the distributed database system.
7. The method for obtaining and allocating logical timestamps in a distributed database according to claim 1, wherein: The sleep time is set to Tstart - Treq.
8. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method for obtaining and allocating logical timestamps applied to a distributed database as described in claim 1.
9. A computer-readable storage medium, characterized in that: Computer executable instructions are stored, and when the instructions are executed, they are used to implement the method for obtaining and allocating logical timestamps applied to a distributed database as claimed in claim 1.
10. A computer program product, characterized in that: The computer program product includes computer executable instructions, which are used to implement the method for obtaining and allocating logical timestamps applied to a distributed database as claimed in claim 1 when executed.
Citation Information
Patent Citations
Information acquisition method and device, electronic equipment and storage medium
CN113312370A
Transaction submission sequence number snapshot acquisition method and device, equipment and storage medium
CN115858104A