Method and apparatus for providing clock service for distributed databases

By autonomously determining and persisting log identifier pre-allocated intervals on the distributed database master node, the problem of high cost or unreliability clock services in existing technologies is solved, realizing low-cost and highly available clock services and avoiding clock rollback and system risks.

CN115543015BActive Publication Date: 2026-02-06BEIJING OCEANBASE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211266641.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-17
Publication Date
2026-02-06
Estimated Expiration
2042-10-17

AI Technical Summary

Technical Problem

Existing clock service methods for distributed databases are costly or rely on unreliable external services, increasing system risk.

Method used

By utilizing the pre-allocated interval of the persistent log identifier on the master node of the distributed database, the current pre-allocated interval of the log identifier can be determined and persisted autonomously, providing a clock service and avoiding reliance on external ETCD services.

Benefits of technology

It implements a relatively reliable and low-cost clock service, avoids clock rollback, reduces system risks, and improves the availability of the distributed database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115543015B_ABST
    Figure CN115543015B_ABST
Patent Text Reader

Abstract

Embodiments of the present specification provide a method and device for providing clock service for a distributed database. In the method for providing clock service for a distributed database, a right boundary of a previous log identification pre-allocated interval is obtained; a left boundary of a current log identification pre-allocated interval is determined as being greater than or equal to the right boundary of the previous log identification pre-allocated interval; a right boundary of the current log identification pre-allocated interval and a next log identification pre-allocated interval are determined according to the left boundary of the current log identification pre-allocated interval and a pre-allocated interval length; the right boundary of the current log identification pre-allocated interval is persisted to a log of the distributed database; and clock service is provided according to the next log identification pre-allocated interval.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present specification generally relate to the field of computer technology, and more particularly to a method and apparatus for providing clock service for distributed database. BACKGROUND

[0002] With the rapid development of Internet technology and big data technology, distributed database (DDB) has achieved more and more extensive application. The distributed database is composed of multiple nodes, and each node needs to communicate with each other by exchanging messages. Since the database instance on each node of the distributed database has a relatively independent clock or log, the clock on each node cannot reflect the global sequence, and there may be network delay, clock skew, etc. on each node, so the clock service is needed to provide a globally consistent time sequence mark, such as assigning a timestamp for all transactions of the entire distributed cluster. One of the existing technologies, such as distributed database Spanner, directly interfaces the international standard time by equipping the cluster with GPS time calibration and atomic clock hardware, that is, the industry is called "absolute time" (True Time) method. One of the existing technologies, such as distributed database TiDB, uses a global central control node PD (Placement Driver) integrated with ETCD (a distributed consistent key-value storage system) to implement TSO (Timestamp Oracle, through central unified time service). However, in the above method, the cost of the former is high, and the distributed storage system of the latter depends on the external ETCD service, and since we cannot guarantee the availability of the external service, the risk of the entire system is increased. SUMMARY

[0003] In view of the above, the present specification provides a method and apparatus for providing clock service for distributed database. By using the method and apparatus, a more reliable and lower cost clock service can be provided for the distributed database.

[0004] According to an aspect of embodiments of the present specification, there is provided a method for providing a clock service for a distributed database, the method being applied to a master node of the distributed database, the method comprising: obtaining a right boundary of a previous log-identified pre-allocated interval that has been persisted; determining a left boundary of a current log-identified pre-allocated interval to be greater than or equal to the right boundary of the previous log-identified pre-allocated interval; determining a right boundary of the current log-identified pre-allocated interval and a next log-identified pre-allocated interval according to the left boundary of the current log-identified pre-allocated interval and a pre-allocated interval length; persisting the right boundary of the current log-identified pre-allocated interval to a log of the distributed database; and providing a clock service according to the next log-identified pre-allocated interval.

[0005] According to yet another aspect of embodiments of the present specification, there is provided a method for providing a clock service for a distributed database, the method being applied to a master node of the distributed database, the method comprising: obtaining a right boundary of a previous log-identified pre-allocated interval that has been persisted; determining whether there exists a persisted current remaining allocable interval in a log of the distributed database that matches the right boundary of the previous log-identified pre-allocated interval; in response to the existence, determining a left boundary of a current log-identified pre-allocated interval to be greater than or equal to a left boundary of the matched persisted current remaining allocable interval; determining a right boundary of the current log-identified pre-allocated interval to be greater than or equal to the right boundary of the previous log-identified pre-allocated interval; persisting the right boundary of the current log-identified pre-allocated interval to the log of the distributed database; determining a next log-identified pre-allocated interval according to the left boundary of the current log-identified pre-allocated interval and the right boundary of the persisted current log-identified pre-allocated interval; and providing a clock service according to the next log-identified pre-allocated interval.

[0006] According to another aspect of embodiments of the present specification, there is provided an apparatus for providing a clock service for a distributed database, wherein the apparatus is disposed at a master node of the distributed database, the apparatus comprising: a first previous boundary obtaining unit configured to obtain a right boundary of a previous log-identified pre-allocated interval that has been persisted; a first current boundary determining unit configured to determine a left boundary of a current log-identified pre-allocated interval to be greater than or equal to the right boundary of the previous log-identified pre-allocated interval; determine a right boundary of the current log-identified pre-allocated interval and a next log-identified pre-allocated interval according to the left boundary of the current log-identified pre-allocated interval and a pre-allocated interval length; a first persisting unit configured to persist the right boundary of the current log-identified pre-allocated interval to a log of the distributed database; and a first clock service providing unit configured to provide a clock service according to the next log-identified pre-allocated interval.

[0007] According to a further aspect of embodiments of the present specification, there is provided an apparatus for providing clock service for a distributed database, wherein the apparatus is arranged at a master node of the distributed database, and the apparatus comprises: a second previous boundary obtaining unit configured to obtain a right boundary of a previous log-identified pre-allocated interval which has been persisted; a second current boundary determining unit configured to determine whether there is a persisted current remaining allocable interval in a log of the distributed database which matches the right boundary of the previous log-identified pre-allocated interval; in response to there being, determining a left boundary which is greater than or equal to a left boundary of the matched persisted current remaining allocable interval as a left boundary of a current log-identified pre-allocated interval; determining a right boundary which is greater than or equal to the right boundary of the previous log-identified pre-allocated interval as a right boundary of the current log-identified pre-allocated interval; a second persisting unit configured to persist the right boundary of the current log-identified pre-allocated interval to the log of the distributed database; and a second clock service providing unit configured to determine a current log-identified pre-allocated interval according to the left boundary of the current log-identified pre-allocated interval and the persisted right boundary of the current log-identified pre-allocated interval; and provide clock service according to the current log-identified pre-allocated interval.

[0008] According to a further aspect of embodiments of the present specification, there is provided a distributed database, comprising: a master node configured to perform the method for providing clock service for a distributed database as described above; and a slave node configured to synchronize a log of the distributed database.

[0009] According to a further aspect of embodiments of the present specification, there is provided an apparatus for providing clock service for a distributed database, comprising: at least one processor, and a memory coupled to the at least one processor, the memory storing instructions which, when executed by the at least one processor, cause the at least one processor to perform the method for providing clock service for a distributed database as described above.

[0010] According to a further aspect of embodiments of the present specification, there is provided a computer-readable storage medium storing a computer program, the computer program being executed by a processor to implement the method for providing clock service for a distributed database as described above.

[0011] According to a further aspect of embodiments of the present specification, there is provided a computer program product comprising a computer program, the computer program being executed by a processor to implement the method for providing clock service for a distributed database as described above. BRIEF DESCRIPTION OF DRAWINGS

[0012] A further understanding of the nature and advantages of the disclosure can be realized by reference to the following drawings. In the drawings, like reference numerals can refer to like components or features.

[0013] Figure 1 An exemplary architecture of a method and apparatus for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0014] Figure 2 A flowchart of one example of a method for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0015] Figure 3 A flowchart of one example of a process of providing clock service according to an embodiment of the present specification is shown.

[0016] Figure 4 A flowchart of yet another example of a method for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0017] Figure 5 A schematic diagram of one example of an application scenario of a method for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0018] Figure 6 A block diagram of one example of an apparatus for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0019] Figure 7 A block diagram of yet another example of an apparatus for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0020] Figure 8 A block diagram of one example of an apparatus for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0021] Figure 9 A block diagram of one example of an apparatus for providing clock service for a distributed database according to an embodiment of the present specification is shown. DETAILED DESCRIPTION

[0022] The subject matter described herein will now be discussed with reference to example implementations. It should be understood that the implementations discussed are merely provided for illustration and the understanding of the subject matter described herein and are not limiting on the scope of the protection, applicability, or examples set forth in the claims. Alterations to the function and arrangement of elements can be made without departing from the scope of the examples embodied in this specification. Various examples can omit, substitute, or add various procedures or components as appropriate. Also, the description described some examples with reference to particular examples. However, a person of ordinary skill in the art will appreciate that features described relative to some examples can be combined with features described relative to other examples, even if not explicitly stated in a given combination.

[0023] As used herein, the term "includes" and its variants are meant to be interpreted broadly. The term "based on" means "based, at least in part, on." The terms "one embodiment" and "an embodiment" mean "at least one embodiment." The term "another embodiment" means "at least one additional embodiment." The terms "a first," "a second," etc. do not require, unless otherwise specified, that the first and second be different. The following detailed description is presented in terms of examples. It should be understood, however, that these examples are not limiting examples of the scope of the disclosure. In the description below, numerous specific details are set forth to provide a thorough understanding of various examples. However, one skilled in the relevant art will recognize that the functionality explained, but not specifically described, can be accomplished by specific

[0024] In this specification, the term "clock service" can refer to a technology that provides a globally consistent time order of markers for a distributed database, such as assigning timestamps to all transactions of the entire distributed cluster, assigning log sequence numbers to the WAL (Write Ahead Log) of the entire distributed cluster, etc.

[0025] In this specification, the term "log replay" can refer to a technology that guarantees data consistency, which generally refers to a process of "cleaning up" data involved in transactions when a master node of a distributed database fails (e.g., performing a rollback operation on modifications to data involved in transactions that have not been committed when a failure occurs).

[0026] In this specification, the term "atomicity" operation can refer to one or a series of operations that are not interrupted by a thread scheduling mechanism. An atomic operation, once started, runs until the end without switching to another thread (context switch) in between, and thus does not need to be additionally synchronized.

[0027] A method and apparatus for providing a clock service for a distributed database according to an example embodiment of the present specification will now be described in detail with reference to the accompanying drawings.

[0028] Figure 1An exemplary architecture 100 of a method and apparatus for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0029] Figure 1 A schematic diagram showing one example of a distributed database 100 is shown. As shown, Figure 1 The distributed database system 100 includes a plurality of database nodes 110, 120, 130. The database nodes 110, 120, 130 are distributed database nodes, each of which can include a log management engine and a log storage space. It is to be noted that, Figure 1 The example shown is merely exemplary, and each database node can also include a data query engine and a data storage engine for performing data query tasks, etc. In other embodiments, the distributed database 100 can include more or fewer database nodes.

[0030] In such a distributed database, data can be stored in the storage engines of the respective database nodes in a distributed manner. For example, the data can be split into a plurality of data partitions (also referred to as data chunks), and the split data partitions are stored in different storage engines. Each storage engine can store one or more data partitions. The CPU resources and IO resources required for data access involved on each database node occur locally and are performed by the data query engine on that database node.

[0031] A database node (e.g., one of the database nodes 110, 120, 130) in the distributed database 100 as a master node can perform the method for providing clock service for a distributed database described above to achieve a more reliable and lower-cost clock service for the entire distributed database 100. For example, the database node 130 determines the current log identification pre-allocated interval by the persisted log stored in its log storage space (such as a disk), and provides clock service (such as allocating a log sequence number) according to the determined current log identification pre-allocated interval. The database nodes (e.g., the database nodes 110, 120) in the distributed database 100 as slave nodes can synchronize the primary and secondary versions of the log through the respective log management engines, so as to on the one hand ensure data consistency, and on the other hand effectively avoid the occurrence of the "clock rollback" phenomenon after the master node is switched.

[0032] It should be understood that Figure 1 All network entities shown in the above are exemplary, and any other network entity can be involved in the architecture 100 according to specific application requirements.

[0033] Figure 2 A flowchart showing one example of a method 200 for providing clock service for a distributed database according to an embodiment of the present specification is shown.

[0034] As shown in FIG. 2, at 210, a right boundary of a previous log identification pre-allocated interval is obtained. Figure 2

[0035] In the embodiment, the right boundary of the previous log identification pre-allocated interval can be obtained in various ways. The log identification pre-allocated interval can refer to an interval of values of an identification used to distinguish logs. In an example, the log can be a pre-written log of a distributed database. For example, the previous log identification pre-allocated interval can be [T x , Tlimited). T x , Tlimited can be used to represent a timestamp. Tlimited is the right boundary of the previous log identification pre-allocated interval. It can be understood that the previous log identification pre-allocated interval can also be (T x , Tlimited], but it needs to be consistent in the entire scheme to avoid repeated allocation at the endpoint. The relevant log identification pre-allocated interval described below is the same, and will not be repeated.

[0036] As an example, when the execution subject of persisting the right boundary of the previous log identification pre-allocated interval is consistent with the execution subject of the method for providing a clock service for the distributed database (for example, both are the database node 110 as shown in FIG. 1), the right boundary of the previous log identification pre-allocated interval can be directly obtained from the memory. Figure 1

[0037] In some optional implementations of the embodiment, the right boundary of the previous log identification pre-allocated interval can include the right boundary of the log identification pre-allocated interval persisted by a former master node of the distributed database. The former master node generally refers to the last master node of the current master node.

[0038] In these implementations, the right boundary of the log identification pre-allocated interval persisted by the former master node of the distributed database can be obtained through log replay. In an example, the execution subject of the method for providing a clock service for the distributed database can be the database node 120 as shown in FIG. 2. The former master node that persists the right boundary of the previous log identification pre-allocated interval can be the database node 110 as shown in FIG. 1. Based on the log master-slave version synchronization mechanism of the distributed database, the database node 120 can obtain the right boundary of the previous log identification pre-allocated interval that has been persisted through log replay. Figure 1 Figure 1

[0039] ​​​​In one example, the log can also be played back in multi-thread and concurrently. For example, a log distribution thread reads a batch of logs from the local log storage space each time, and after splitting, the separate log playback tasks are assigned to different log playback threads for processing, thereby improving the log playback efficiency.

[0040] At 220, the right boundary of the log identification pre-allocation interval greater than or equal to the previous log identification pre-allocation interval is determined as the left boundary of the current log identification pre-allocation interval.

[0041] In the embodiment, the right boundary of the log identification pre-allocation interval greater than or equal to the previous log identification pre-allocation interval can be determined as the left boundary of the current log identification pre-allocation interval. In one example, the right boundary of the previous log identification pre-allocation interval can be Tlimited. Thus, the left boundary of the current log identification pre-allocation interval can be Tlimited+Δt. Wherein, the above Δt can be a value greater than or equal to 0, used to represent the offset.

[0042] At 230, according to the left boundary of the current log identification pre-allocation interval and the pre-allocation interval length, the right boundary of the current log identification pre-allocation interval and the current log identification pre-allocation interval are determined.

[0043] In the embodiment, as an example, referring to the previous example, the pre-allocation interval length can be Trange. Thus, the right boundary of the current log identification pre-allocation interval can be determined as Tlimited+Trange. The interval between the left boundary of the current log identification pre-allocation interval and the determined right boundary of the current log identification pre-allocation interval can be regarded as a to-be-determined interval. Then, the current log identification pre-allocation interval can be determined as a subset of the to-be-determined interval. In one example, the left boundary of the current log identification pre-allocation interval can be T1, for example. The determined right boundary of the current log identification pre-allocation interval can be T2, for example. The current log identification pre-allocation interval can be determined as [T1, T2). Alternatively, the current log identification pre-allocation interval can also be determined as [T1+t, T2-t). Wherein, t≤(T2-T1) / 2. The above t can be a safety margin, used to prevent overlap between the allocated log identifications.

[0044] At 240, the right boundary of the current log identification pre-allocation interval is persisted to the log of the distributed database.

[0045] In the embodiment, the right boundary of the current log identification pre-allocated interval determined in the above step is persisted to the log of the distributed database. In one example, the master node persists the right boundary of the current log identification pre-allocated interval determined in the above step to the local log storage space. Based on the log master-slave version synchronization mechanism of the distributed database, the slave node of the distributed database can obtain the log recording the persisted right boundary of the current log identification pre-allocated interval.

[0046] At 250, the clock service is provided according to the current log identification pre-allocated interval.

[0047] In the embodiment, the clock service can be provided according to the current log identification pre-allocated interval in various manners. In one example, the log identification can be a timestamp. Thus, the timestamp can be allocated according to the current log identification pre-allocated interval used to represent the timestamp interval.

[0048] Optionally, further referring to Figure 3 , Figure 3 A flow chart showing one example of the providing process 300 of the clock service according to the embodiment of the present specification is shown.

[0049] As Figure 3 shown, at 310, in response to receiving the clock service request, the log identification corresponding to the clock service request is determined from the current log identification pre-allocated interval in an auto-increment manner.

[0050] In the embodiment, when the clock service request is received, the log identification corresponding to the clock service request can be determined from the determined current log identification pre-allocated interval in an auto-increment manner (e.g. an atomic auto-increment manner). In one example, the clock service request can include a timestamp acquisition request. In one example, the clock service request can include a log sequence number acquisition request. Optionally, the log identification (e.g. timestamp or log sequence number) corresponding to the clock service request can be determined from the determined current log identification pre-allocated interval in an incremental order through an atomic operation.

[0051] In some optional implementations of the embodiment, the above clock service request can be multiple requests, i.e. multiple log identifications are applied in batches through one network request. Thus, the network overhead can be reduced and the response efficiency can be improved.

[0052] At 320, the log identification corresponding to the clock service request is provided as a response to the sender of the clock service request.

[0053] In the embodiment, the determined log identification corresponding to the clock service request can be provided as a response to the sender of the clock service request.

[0054] Based on this, the scheme can provide clock service in a manner of responding to clock service request, and make the allocated log identifier sequentially advance in a self-increment manner, so as to realize global monotonic increment of log identifier allocation and avoid occurrence of "clock rollback" phenomenon.

[0055] Optionally, the log identifier can include a log sequence number. In an example, the log sequence number can be allocated in a monotonic increment manner from the determined log identifier pre-allocation interval of this time.

[0056] Based on this, the scheme can realize allocation of log sequence number in a distributed database through the clock service, so as to guarantee global consistency of the database system.

[0057] Optionally, step 260 of persisting the determined current remaining allocable interval of the log identifier pre-allocation interval of this time to the log of the distributed database in response to receiving the abdication instruction indicating the conversion from the master node to the slave node can also be performed.

[0058] In an example, the clock service can be provided on the basis of persisting the right boundary of the current log identifier pre-allocation interval to the log of the distributed database. The process of providing the clock service can be equivalent to the actual allocation process of the log identifier in the determined log identifier pre-allocation interval of this time. In the actual allocation process of the log identifier, the current remaining allocable interval of the log identifier pre-allocation interval of this time can be determined.

[0059] In an example, when the abdication instruction indicating the conversion from the master node to the slave node is received, the current remaining allocable interval of the log identifier pre-allocation interval of this time can be determined in advance, and then the determined current remaining allocable interval of the log identifier pre-allocation interval of this time can be persisted to the log of the distributed database. For example, the current remaining allocable interval of the log identifier pre-allocation interval of this time can be determined when the abdication instruction indicating the conversion from the master node to the slave node is received.

[0060] Based on this, the scheme can retain the current remaining allocable interval in the process of switching the master and slave nodes due to non-fault (for example, active switching of the master), so as to provide data and technical basis for the next master node to obtain the persisted current remaining allocable interval to expand the range of the log identifier pre-allocation interval of this time after taking office, thereby helping to reduce the interval waste caused by active frequent switching of the master and slave nodes.

[0061] In some optional implementation manners of the embodiment, the method for providing clock service for the distributed database can further include the following steps:

[0062] S1, determining a current remaining allocable interval of a log identifier pre-allocation interval of this time.

[0063] In one example, the current remaining allocable interval can be determined periodically (e.g., every preset time interval). In one example, the current remaining allocable interval can be determined every time of allocation or every N (N is a positive integer) times of allocation. Wherein, the current remaining allocable interval can be the left boundary and the right boundary of the interval in which the allocable log identifier is located, can be the number of the allocable log identifier, or can be the ratio of the number of the allocable log identifier to the total number of the log identifiers corresponding to the current log identifier pre-allocation interval, which is not limited here.

[0064] S2, determining whether the current remaining allocable interval meets the pre-allocation space expansion condition.

[0065] In the embodiment, the pre-allocation space expansion condition can match the form of the current remaining allocable interval. The pre-allocation space expansion condition can be set according to the actual application scenario. In one example, the pre-allocation space expansion condition can be that the ratio of the current remaining allocable interval to the current log identifier pre-allocation interval is less than 1 / 3. In one example, the pre-allocation space expansion condition can be that the number of the log identifiers indicated by the current remaining allocable interval is less than a preset allocable number threshold.

[0066] When the above S2 is yes, the following steps S21-S22 are continued to be executed:

[0067] In S21, the right boundary of the new log identifier pre-allocation interval is determined according to the right boundary of the current log identifier pre-allocation interval which has been persisted.

[0068] In the embodiment, the determined right boundary of the new log identifier pre-allocation interval is not less than the above-mentioned right boundary of the current log identifier pre-allocation interval which has been persisted. In one example, the right boundary of the current log identifier pre-allocation interval can be Tlimited+Trange. Tlimited+2×Trange can be determined as the right boundary of the new log identifier pre-allocation interval. In one example, Tlimited+2×Trange+Δt can be determined as the right boundary of the new log identifier pre-allocation interval. In one example, Trange can be the pre-allocation interval length. Δt can be a preset safety margin value, for example, 1 ms. Thus, the lengths of the various log identifier pre-allocation intervals can be consistent.

[0069] S22, persisting the right boundary of the new log identifier pre-allocation interval to the log of the distributed database.

[0070] In the embodiment, the above-mentioned Figure 2In a similar manner as in embodiment 240, the right boundary of the new log identifier pre-allocated interval determined in step S21 is persisted to the log of the distributed database.

[0071] Optionally, when the determination in step S2 is negative, the clock service can be continued to be provided according to the current log identifier pre-allocated interval. During this period, the steps S1 and S2 can be continued to be executed, and the steps S21-S22 can be executed when the determination in step S2 is positive.

[0072] Based on this, the present scheme can detect the current remaining allocatable interval during the actual allocation of the log identifier of the current log identifier pre-allocated interval, and trigger the determination and persistence of the new log identifier pre-allocated interval in advance, thereby ensuring the steady progress of the clock service.

[0073] Reference is made below to Figure 4 , Figure 4 A flow chart illustrating yet another example of a method 400 for providing a clock service for a distributed database according to an embodiment of the present specification is shown.

[0074] As shown in Figure 4 , at 410, the right boundary of the previous log identifier pre-allocated interval that has been persisted is obtained.

[0075] In some optional implementations of the present embodiment, the right boundary of the previous log identifier pre-allocated interval can include the right boundary of the log identifier pre-allocated interval that has been persisted by a previous primary node of the distributed database. The previous primary node is generally used to refer to the last primary node of the current primary node. In these implementations, the right boundary of the log identifier pre-allocated interval that has been persisted by the previous primary node of the distributed database can be obtained through log replay.

[0076] It should be noted that the above process can refer to the related description of the optional implementation of step 210 of the aforementioned Figure 2 embodiments, which will not be described herein again.

[0077] At 420, it is determined whether there exists a persisted current remaining allocatable interval in the log of the distributed database that matches the right boundary of the previous log identifier pre-allocated interval.

[0078] In this embodiment, the former master node can also persist the current remaining allocable interval that matches the right boundary of the persisted log-identifier pre-allocable interval. Thus, the log of the distributed database can also be used to save the current remaining allocable interval that matches the log-identifier pre-allocable interval. In one example, the former master node can generally refer to the last master node of the current master node. The right boundary of the previous log-identifier pre-allocable interval can be the right boundary of the log-identifier pre-allocable interval persisted by the former master node. The persisted current remaining allocable interval that matches the right boundary of the previous log-identifier pre-allocable interval can be the current remaining allocable interval persisted by the former master node when allocating the previous log-identifier pre-allocable interval. In one example, the log can be a write-ahead log of the distributed database.

[0079] It should be noted that the persistence of the current remaining allocable interval by the former master node can generally occur in the process of switching the master and slave nodes without failure (e.g., active master switching).

[0080] It should also be noted that the log-identifier pre-allocable interval can be regarded as a pre-applied continuous interval for allocating log identifiers. There is a certain time between the completion of the persistence and the actual allocation of the log-identifier pre-allocable interval. During this period of time, the current remaining allocable interval corresponding to different time points can be determined.

[0081] At 430, in response to the existence, the left boundary of the current log-identifier pre-allocable interval is determined to be greater than or equal to the left boundary of the matched persisted current remaining allocable interval.

[0082] In this embodiment, when the step 420 determines yes, the left boundary of the current log-identifier pre-allocable interval can be determined to be greater than or equal to the left boundary of the matched persisted current remaining allocable interval.

[0083] At 440, the right boundary of the current log-identifier pre-allocable interval is determined to be greater than or equal to the right boundary of the previous log-identifier pre-allocable interval.

[0084] In this embodiment, as an example, the right boundary of the previous log-identifier pre-allocable interval can be Tlimited. Thus, the right boundary of the current log-identifier pre-allocable interval can be Tlimited+Δt. Wherein, the Δt can be a value greater than or equal to 0, used to represent the offset. Alternatively, the Δt can also be the pre-allocable interval length as described in the step 230 of the previous embodiment.

[0085] At 450, the right boundary of the current log-identifier pre-allocable interval is persisted to the log of the distributed database.

[0086] At 460, the current log identifier pre-allocation interval is determined according to the left boundary of the current log identifier pre-allocation interval and the right boundary of the current log identifier pre-allocation interval which has been persisted.

[0087] In the embodiment, the candidate log identifier pre-allocation interval can be determined according to the left boundary of the current log identifier pre-allocation interval and the right boundary of the current log identifier pre-allocation interval which has been persisted. In an example, the current log identifier pre-allocation interval can be determined as a subset of the candidate log identifier pre-allocation interval.

[0088] In an example, the left boundary of the current log identifier pre-allocation interval can be T0, for example. The right boundary of the current log identifier pre-allocation interval which has been persisted can be T2, for example. The current log identifier pre-allocation interval can be determined as [T0, T2). Alternatively, the current log identifier pre-allocation interval can also be determined as [T0+t', T2-t'). Wherein, t'≤(T2-T0) / 2. The t' can be used as a safety margin to prevent overlap between the allocated log identifiers.

[0089] Alternatively, when the step 420 determines no, the current log identifier pre-allocation interval can be determined in the manner described in the step 230. Figure 2 The current log identifier pre-allocation interval can be determined in the manner described in the step 230 of the embodiment.

[0090] Based on this, the scheme can expand the range of the current log identifier pre-allocation interval of the newly appointed primary node according to the current remaining allocable interval persisted by the previous primary node saved in the log, thereby effectively reducing the interval waste caused by frequent active switching of primary and secondary nodes. Moreover, by persisting the right boundary of the current log identifier pre-allocation interval by each newly appointed primary node, the problem of "clock rollback" that can occur in the next primary node due to the reservation of the current remaining allocable interval persisted by the previous primary node without re-persisting is avoided.

[0091] At 470, the clock service is provided according to the current log identifier pre-allocation interval.

[0092] It should be noted that the specific operations of the steps 410, 450, and 470 can refer to the corresponding descriptions of the steps 210, 240, and 250 of the foregoing Figure 2 embodiment, which will not be described here again.

[0093] In some optional implementations of the embodiment, the process of providing the clock service can include:

[0094] In response to receiving the clock service request, the log identifier corresponding to the clock service request is determined from the current log identifier pre-allocation interval in an auto-increment manner; and

[0095] The log identifier corresponding to the clock service request is provided as a response to the sender of the clock service request.

[0096] It should be noted that the above process can refer to the foregoing Figure 3 The description of steps 310 and 320 in the described embodiments is not repeated here.

[0097] Optionally, the log identifier includes a log sequence number. In an example, the log sequence number can be assigned in a monotonically increasing manner from the determined log identifier pre-allocated interval.

[0098] In some optional implementations of the present embodiment, in response to receiving the abdication instruction indicating that the primary node is converted into a follower node, the current remaining allocatable interval of the determined log identifier pre-allocated interval is persisted to the log of the distributed database.

[0099] It should be noted that the above process can refer to the foregoing Figure 2 The description of step 260 in the described embodiments is not repeated here.

[0100] Continuing to refer to Figure 5 , Figure 5 FIG. 5 shows a schematic diagram of one example of an application scenario of a method 500 for providing a clock service for a distributed database according to an embodiment of the present specification.

[0101] As Figure 5As shown, at time t1, the node A as the primary node can obtain the right boundary of the previous log sequence number pre-allocated interval which has been persisted (e.g. "100" persisted by node A). During time period t1-t2, the node A as the primary node can determine the left boundary of the current log identity pre-allocated interval as "100". According to the left boundary "100" and the pre-allocated interval length (e.g. 100), the node A as the primary node can determine the right boundary of the current log sequence number pre-allocated interval (e.g. "200") and the current log identity pre-allocated interval (e.g. [100, 200)). Then, the determined right boundary of the current log sequence number pre-allocated interval (e.g. "200") can be persisted to the log of the distributed database. During time period t2-t3, the node A as the primary node can allocate log sequence numbers in the above log sequence number pre-allocated interval (e.g. [100, 200)). At time t3, the node A can stop serving (i.e. demote as the primary node) due to various reasons. During time period t3-t4, the distributed database where the node A is located can re-elect a primary node. At time t4, the node B takes office as the new primary node. At this time, the node B as the primary node can obtain the right boundary of the previous log sequence number pre-allocated interval which has been persisted (e.g. "200" persisted by node A). During time period t4-t5, according to the right boundary of the previous log sequence number pre-allocated interval, the node B as the primary node can determine the right boundary of the current log sequence number pre-allocated interval (e.g. "300") and persist it by referring to the above manner of the previous primary node A. Thus, the node B as the primary node can determine the current log sequence number pre-allocated interval (e.g. [200, 300)). During time period t5-t6, the node B as the primary node can allocate log sequence numbers in the above log sequence number pre-allocated interval (e.g. [200, 300)).

[0102] Optionally, at time t3, node A may stop service due to actively switching master status. Before relinquishing the master status, node A can persist the current remaining allocatable interval (e.g., [150, 200)). In this example, node B, as the master node, can determine that there exists a persisted current remaining allocatable interval (e.g., [150, 200)) in the distributed database log that matches the right boundary of the previously pre-allocated log identifier interval (e.g., [100, 200)). Thus, node B, as the master node, can determine the left boundary (e.g., "150") of the matching persisted current remaining allocatable interval as the left boundary of the current pre-allocated log identifier interval; and determine the right boundary (e.g., "200") of the previously pre-allocated log identifier interval as the right boundary (e.g., "300") of the current pre-allocated log identifier interval. Afterwards, node B, as the master node, can persist the right boundary (e.g., "300") of the current pre-allocated log identifier interval to the distributed database log. Furthermore, node B, as the master node, can determine the pre-allocated range of the log sequence number for this time (e.g., [150, 300)).

[0103] Optionally, during the time period t5 to t6, node B, acting as the master node, can determine the current remaining allocatable interval of the current log sequence number pre-allocation interval. When the determined current remaining allocatable interval meets the pre-allocation space expansion condition, node B, acting as the master node, can determine the right boundary (e.g., "400") of the new log identifier pre-allocation interval based on the already persisted right boundary (e.g., "300") and persist it.

[0104] use Figures 1-5 The method disclosed in the paper for providing clock services for distributed databases can leverage the existing log system and master-slave version synchronization mechanism of distributed databases. By persisting the right boundary of the pre-allocated log identifier interval in a timely manner and ensuring that the left boundary of the current pre-allocated log identifier interval is always greater than the allocated log identifier, a low-cost and highly available clock service for distributed databases can be achieved.

[0105] Figure 6 A block diagram illustrating an example of a clock service apparatus 600 for a distributed database according to an embodiment of this specification is shown. This apparatus embodiment can be used with... Figures 1-5 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.

[0106] like Figure 6As shown, the apparatus 600 for providing clock service for a distributed database can include a first previous boundary obtaining unit 610, a first current boundary determining unit 620, a first persisting unit 630, and a first clock service providing unit 640.

[0107] The first previous boundary obtaining unit 610 is configured to obtain a right boundary of a previous log-identified pre-allocated interval that has been persisted. The operation of the first previous boundary obtaining unit 610 can refer to the operation of 210 described above. Figure 2

[0108] In one example, the right boundary of the previous log-identified pre-allocated interval can include a right boundary of a log-identified pre-allocated interval that has been persisted by a previous primary node of the distributed database. The first previous boundary obtaining unit 610 can be further configured to obtain the right boundary of the log-identified pre-allocated interval that has been persisted by the previous primary node of the distributed database through log replay. The operation of the first previous boundary obtaining unit 610 can refer to the related description of the optional implementation of step 210 in the embodiments described above. Figure 2

[0109] The first current boundary determining unit 620 is configured to determine a left boundary of a current log-identified pre-allocated interval as being greater than or equal to a right boundary of a previous log-identified pre-allocated interval; and determine a right boundary of the current log-identified pre-allocated interval and a next log-identified pre-allocated interval according to the left boundary of the current log-identified pre-allocated interval and a pre-allocated interval length. The operation of the first current boundary determining unit 620 can refer to the operation of 220 and 230 described above. Figure 2

[0110] In one example, the first current boundary determining unit 620 can be further configured to determine the left boundary of the current log-identified pre-allocated interval as being the right boundary of the previous log-identified pre-allocated interval; and determine the right boundary of the current log-identified pre-allocated interval according to the left boundary and the pre-allocated interval length. The operation of the first current boundary determining unit 620 can refer to the determination process of the right boundary of the current log-identified pre-allocated interval described above. Figure 3

[0111] The first persisting unit 630 is configured to persist the right boundary of the current log-identified pre-allocated interval to a log of the distributed database. The operation of the first persisting unit 630 can refer to the operation of 240 described above. Figure 2

[0112] ​​​​​In one example, the first persistence unit 630 is further configured to, in response to receiving a demission instruction indicating a transition from a primary node to a secondary node, persist the determined current log identification and the current remaining allocable interval of the allocation interval to a log of the distributed database. The above operation of the first persistence unit 630 can refer to the operation of 260 described above. Figure 2 The operation of 260 described above.

[0113] The first clock service providing unit 640 is configured to provide a clock service according to the current log identification pre-allocated interval. The operation of the first clock service providing unit 640 can refer to the operation of 250 described above. Figure 2 The operation of 250 described above.

[0114] In one example, the first clock service providing unit 640 can be further configured to, in response to receiving a clock service request, determine a log identification corresponding to the clock service request from the current log identification pre-allocated interval in a self-increment manner; and provide the log identification corresponding to the clock service request as a response to a sender of the clock service request. The operation of the first clock service providing unit 640 can refer to the provision process of the clock service described above. Figure 3 The operation of 250 described above.

[0115] In one example, the above log identification can include a log sequence number. The first clock service providing unit 640 can be further configured to allocate log sequence numbers in a monotonically increasing manner from the current log identification pre-allocated interval. The operation of the first clock service providing unit 640 can refer to the description of the optional implementation of the embodiment above. Figure 3 The operation of 250 described above.

[0116] Figure 7 A block diagram illustrating yet another example of an apparatus 700 for providing a clock service for a distributed database according to an embodiment of the present specification is shown. The apparatus can be specifically applied to various electronic devices.

[0117] As Figure 7 shown, the apparatus 700 for providing a clock service for a distributed database can include a second previous boundary obtaining unit 710, a second current boundary determining unit 720, a second persistence unit 730, and a second clock service providing unit 740.

[0118] The second current boundary determination unit 720 is configured to determine whether there is a persisted current remaining allocatable interval in the log of the distributed database that matches the right boundary of the previous log-identified pre-allocatable interval; in response to the existence, determine a left boundary of the current log-identified pre-allocatable interval that is greater than or equal to the left boundary of the matched persisted current remaining allocatable interval; and determine a right boundary of the current log-identified pre-allocatable interval that is greater than or equal to the right boundary of the previous log-identified pre-allocatable interval. The above operations of the second current boundary determination unit 720 can refer to the operations of 420-440 described above. Figure 4 The operations of 420-440 described above.

[0119] The second clock service providing unit 740 is further configured to determine a current log-identified pre-allocatable interval according to the left boundary of the current log-identified pre-allocatable interval and the right boundary of the persisted current log-identified pre-allocatable interval; and provide a clock service according to the current log-identified pre-allocatable interval. The above operations of the second clock service providing unit 740 can refer to the operations of 460 described above. Figure 4 The operations of 460 described above.

[0120] It should be noted that the second previous boundary obtaining unit 710 and the second persistence unit 730 can refer to the corresponding descriptions of the first previous boundary obtaining unit 610 and the first persistence unit 630 in the foregoing Figure 6 embodiments, and details are not described herein.

[0121] The above describes the embodiments of the method and device for providing a clock service for a distributed database according to the embodiments of the present specification. Figures 1 to 7 The above describes the embodiments of the method and device for providing a clock service for a distributed database according to the embodiments of the present specification.

[0122] The device for providing a clock service for a distributed database according to the embodiments of the present specification can be implemented in hardware, or in software, or in a combination of hardware and software. For example, in software, as a logical device, it is formed by reading the corresponding computer program instructions in the memory to the memory of the processor of the device in which it is located. In the embodiments of the present specification, the device for providing a clock service for a distributed database can be implemented by an electronic device.

[0123] The distributed database according to the embodiments of the present specification can refer to the distributed database shown in Figure 1 The database nodes 110, 120, and 130 can have different node roles, respectively. When the node role is a master node, the operations of the foregoing Figures 2-5A method for providing clock service for a distributed database is described. When a node role is a slave node, a log of the distributed database can be synchronized. In one example, a local log can be updated to a log consistent with a log of a master node based on a master replica synchronization mechanism of the distributed database.

[0124] Figure 8 A schematic diagram of an apparatus 800 for providing clock service for a distributed database is shown.

[0125] As Figure 8 shown, the apparatus 800 for providing clock service for a distributed database can include at least one processor 810, a memory (e.g., a non-volatile memory) 820, a storage 830, and a communication interface 840, and the at least one processor 810, the memory 820, the storage 830, and the communication interface 840 are connected together via a bus 850. The at least one processor 810 executes at least one computer-readable instruction (i.e., the above-mentioned elements implemented in software) stored or encoded in the memory.

[0126] In one embodiment, computer-executable instructions stored in the memory, which when executed, cause the at least one processor 810 to: obtain a right boundary of a pre-allocated interval of a previous log identification; determine a left boundary of a pre-allocated interval of a current log identification to be greater than or equal to the right boundary of the pre-allocated interval of the previous log identification; determine a right boundary of the pre-allocated interval of the current log identification and a pre-allocated interval of a current log identification according to the left boundary of the pre-allocated interval of the current log identification and a pre-allocated interval length; persist the right boundary of the pre-allocated interval of the current log identification to a log of the distributed database; and provide clock service according to the pre-allocated interval of the current log identification.

[0127] Figure 9 A schematic diagram of an apparatus 900 for providing clock service for a distributed database is shown.

[0128] As Figure 9 shown, the apparatus 900 for providing clock service for a distributed database can include at least one processor 910, a memory (e.g., a non-volatile memory) 920, a storage 930, and a communication interface 940, and the at least one processor 910, the memory 920, the storage 930, and the communication interface 940 are connected together via a bus 950. The at least one processor 910 executes at least one computer-readable instruction (i.e., the above-mentioned elements implemented in software) stored or encoded in the memory.

[0129] In one embodiment, computer executable instructions are stored in the memory that, when executed, cause the at least one processor 910 to: obtain a right boundary of a previous log-identified pre-allocated interval; determine whether there exists a persisted current remaining allocable interval in the log of the distributed database that matches the right boundary of the previous log-identified pre-allocated interval; in response to the existence, determine a left boundary of the current log-identified pre-allocated interval to be greater than or equal to a left boundary of the matched persisted current remaining allocable interval; determine a right boundary of the current log-identified pre-allocated interval to be greater than or equal to the right boundary of the previous log-identified pre-allocated interval; persist the right boundary of the current log-identified pre-allocated interval to the log of the distributed database; determine a current log-identified pre-allocated interval according to the left boundary of the current log-identified pre-allocated interval and the persisted right boundary of the current log-identified pre-allocated interval; and provide a clock service according to the current log-identified pre-allocated interval.

[0130] It should be understood that the computer executable instructions stored in the memory, when executed, cause the at least one processor 810 or the at least one processor 910 to perform various operations and functions described above in conjunction with various embodiments of the present specification. Figures 1-5

[0131] According to one embodiment, a program product, such as a computer readable medium, is provided. The computer readable medium can have instructions (i.e., the above-mentioned elements implemented in software) that, when executed by a computer, cause the computer to perform various operations and functions described above in conjunction with various embodiments of the present specification. Figures 1-5

[0132] In particular, a system or apparatus equipped with a readable storage medium on which software program codes implementing the functions of any of the above-mentioned embodiments are stored, and a computer or processor of the system or apparatus are provided to read out and execute the instructions stored in the readable storage medium.

[0133] In this case, the program codes read from the readable medium can implement the functions of any of the above-mentioned embodiments by themselves, and thus the machine readable codes and the readable storage medium storing the machine readable codes constitute a part of the present invention.

[0134] ​​Computer program code for carrying out operations of the present specification can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB, NET, and Python, conventional procedural programming languages, such as the "C" programming language, Visual Basic 2003, Perl, COBOL 2002, PHP, and ABAP, dynamic programming languages, such as Python, Ruby, and Groovy, or other programming languages. The program code can execute entirely on the user's computer, or it can be executed as a separate software package, in part on the user's computer, and in part on a remote computer, or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic program code can be downloaded from a server or from the cloud, or it can be downloaded from another computer or device. In some embodiments, the electronic program code can be downloaded over the air, for example, over a wireless network.

[0135] Embodiments of the readable storage medium include floppy diskettes, hard disks, optical disks such as CD-ROMs, CD-RWs, DVDs, DVD-ROMs, DVD-RWs, DVD-RWs, magnetic tapes, flash memories, and ROMs. The program code can also be downloaded from a server or from the cloud over a network, for example, the Internet.

[0136] The above-described embodiments of the present specification are described in connection with certain specific embodiments. Other embodiments fall within the scope of the claims. In some cases, the actions or steps recited in the claims can be performed in a different order and still achieve desirable results. Additionally, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.

[0137] Not all steps and units in the above-described flowcharts and system block diagrams are required, and some steps or units can be omitted according to actual needs. The execution order of the steps is not fixed and can be determined as needed. The device structures described in the above embodiments can be physical structures or logical structures, i.e., some units can be implemented by the same physical entity, or some units can be implemented by multiple physical entities, or some units can be implemented by some components in multiple independent devices.

[0138] The term "exemplary" is used throughout this specification to mean "serving as an example, instance, or illustration." Nothing herein is intended to be construed as implying that any embodiment described herein is "preferred" or "superior" to, or has preference over any other embodiment described herein. The detailed description includes specific details for the purpose of providing a thorough understanding of the described techniques. However, it will be apparent to those skilled in the art that these techniques can be practiced without these specific details. In some instances, well-known structures and devices are shown in block diagram form in order to avoid obscuring the concepts of the described embodiments.

[0139] The above describes optional implementation manners of the embodiments of the present specification in detail in combination with the drawings, but the embodiments of the present specification are not limited to the specific details in the above implementation manners, and various simple modifications can be made to the technical solutions of the embodiments of the present specification within the technical concept scope of the embodiments of the present specification, and all of these simple modifications belong to the protection scope of the embodiments of the present specification.

[0140] The above description of the present specification is provided to enable any person skilled in the art to implement or use the present specification. Various modifications to the present specification are apparent to those skilled in the art, and the general principles defined herein can also be applied to other variations without departing from the protection scope of the present specification. Therefore, the present specification is not limited to the examples and designs described herein, but is consistent with the broadest scope of the principles and novel features disclosed herein.

Claims

1. A method for providing clock services for a distributed database, wherein, The method is applied to the master node of the distributed database, and the method includes: Get the right boundary of the previously persisted log identifier pre-allocated range; The right boundary of the previous log identifier pre-allocation interval, which is greater than or equal to the previous one, is determined as the left boundary of the current log identifier pre-allocation interval. Based on the left boundary of the current log identifier pre-allocation interval and the length of the pre-allocation interval, determine the right boundary of the current log identifier pre-allocation interval and the current log identifier pre-allocation interval. Persist the right boundary of the current log identifier pre-allocated interval to the log of the distributed database; and Clock services are provided based on the pre-allocated interval of the current log identifier.

2. The method as described in claim 1, wherein, The right boundary of the previous log identifier pre-allocation interval includes the right boundary of the log identifier pre-allocation interval persisted by the previous master node of the distributed database. The step of obtaining the right boundary of the previously persisted log identifier pre-allocated interval includes: The right boundary of the pre-allocated interval of the log identifier persisted by the previous master node of the distributed database is obtained by log replay.

3. The method of claim 1, further comprising: In response to receiving a shunt instruction instructing the master node to become a slave node, the currently remaining allocatable interval of the pre-allocated log identifier is persisted to the log of the distributed database.

4. The method of claim 1, wherein, The provision of clock services based on the pre-allocated interval according to the current log identifier includes: In response to receiving a clock service request, a log identifier corresponding to the clock service request is determined from the pre-allocated log identifier range for the current request using an auto-incrementing method; and The log identifier corresponding to the clock service request is provided as a response to the sender of the clock service request.

5. The method as described in any one of claims 1 to 4, wherein, The log identifier includes the log sequence number. The provision of clock services based on the pre-allocated interval according to the current log identifier includes: Log sequence numbers are allocated from the pre-allocated range of log identifiers in a monotonically increasing manner.

6. A method for providing clock services for a distributed database, wherein, The method is applied to the master node of the distributed database, and the method includes: Get the right boundary of the previously persisted log identifier pre-allocated range; Determine whether there exists a persisted remaining allocable interval in the log of the distributed database that matches the right boundary of the previously identified pre-allocated interval. In response to existence, the left boundary of the current remaining allocatable interval that is greater than or equal to the matching persistent interval is determined as the left boundary of the current log identifier pre-allocated interval; The right boundary of the previous log identifier pre-allocation interval is determined as the right boundary of the current log identifier pre-allocation interval. Persist the right boundary of the current log identifier pre-allocated interval to the log of the distributed database; The current log identifier pre-allocation interval is determined based on the left boundary of the current log identifier pre-allocation interval and the right boundary of the persisted current log identifier pre-allocation interval; and Clock services are provided based on the pre-allocated interval of the current log identifier.

7. The method of claim 6, wherein, The right boundary of the previous log identifier pre-allocation interval includes the right boundary of the log identifier pre-allocation interval persisted by the previous master node of the distributed database. The step of obtaining the right boundary of the previously persisted log identifier pre-allocated interval includes: The right boundary of the pre-allocated interval of the log identifier persisted by the previous master node of the distributed database is obtained by log replay.

8. The method of claim 6, further comprising: In response to receiving a shunt instruction instructing the master node to become a slave node, the currently remaining allocatable interval of the pre-allocated log identifier is persisted to the log of the distributed database.

9. The method of claim 6, wherein, The provision of clock services based on the pre-allocated interval according to the current log identifier includes: In response to receiving a clock service request, a log identifier corresponding to the clock service request is determined from the pre-allocated log identifier range for the current request using an auto-incrementing method; and The log identifier corresponding to the clock service request is provided as a response to the sender of the clock service request.

10. The method as described in any one of claims 6 to 9, wherein, The log identifier includes the log sequence number. The provision of clock services based on the pre-allocated interval according to the current log identifier includes: Log sequence numbers are allocated from the pre-allocated range of log identifiers in a monotonically increasing manner.

11. An apparatus for providing clock services for a distributed database, wherein, The device is located on the master node of the distributed database, and the device includes: The first previous boundary acquisition unit is configured to acquire the right boundary of the previously persisted log identifier pre-allocated interval; The first current boundary determination unit is configured to determine the right boundary of the previous log identifier pre-allocation interval as the left boundary of the current log identifier pre-allocation interval; and to determine the right boundary of the current log identifier pre-allocation interval and the current log identifier pre-allocation interval based on the left boundary of the current log identifier pre-allocation interval and the length of the pre-allocation interval. The first persistence unit is configured to persist the right boundary of the current log identifier pre-allocated interval to the log of the distributed database; and The first clock service providing unit is configured to provide clock services by pre-allocating an interval based on the current log identifier.

12. The apparatus of claim 11, wherein, The right boundary of the previous log identifier pre-allocation interval includes the right boundary of the log identifier pre-allocation interval persisted by the previous master node of the distributed database, and the first previous boundary acquisition unit is further configured as follows: The right boundary of the pre-allocated interval of the log identifier persisted by the previous master node of the distributed database is obtained by log replay.

13. The apparatus of claim 11, wherein, The first persistence unit is further configured as follows: In response to receiving a detach instruction indicating a switch from master to slave, the currently remaining allocatable interval of the pre-allocated log identifier is persisted to the log of the distributed database.

14. The apparatus of claim 11, wherein, The first clock service providing unit is further configured as follows: In response to receiving a clock service request, a log identifier corresponding to the clock service request is determined from the pre-allocated range of log identifiers for the current time using an auto-incrementing method; as well as The log identifier corresponding to the clock service request is provided as a response to the sender of the clock service request.

15. The apparatus as claimed in any one of claims 11 to 14, wherein, The log identifier includes the log sequence number. The first clock service providing unit is further configured as follows: Log sequence numbers are allocated from the pre-allocated range of log identifiers in a monotonically increasing manner.

16. An apparatus for providing clock services for a distributed database, wherein, The device is located on the master node of the distributed database, and the device includes: The second previous boundary acquisition unit is configured to acquire the right boundary of the previously persisted log identifier pre-allocated interval; The second current boundary determination unit is configured to determine whether there exists a persistent currently available allocable interval in the log of the distributed database that matches the right boundary of the previous log identifier pre-allocated interval; in response to the existence, the left boundary of the persistent currently available allocable interval that matches the previous log identifier pre-allocated interval is determined as the left boundary of the current log identifier pre-allocated interval; and the right boundary of the log identifier pre-allocated interval that matches the previous log identifier pre-allocated interval is determined as the right boundary of the current log identifier pre-allocated interval. The second persistence unit is configured to persist the right boundary of the current log identifier pre-allocated interval to the log of the distributed database; and The second clock service providing unit is configured to determine the current log identifier pre-allocation interval based on the left boundary of the current log identifier pre-allocation interval and the right boundary of the current log identifier pre-allocation interval that has been persisted; and to provide clock service based on the current log identifier pre-allocation interval.

17. The apparatus of claim 16, wherein, The right boundary of the previous log identifier pre-allocation interval includes the right boundary of the log identifier pre-allocation interval persisted by the previous master node of the distributed database, and the second previous boundary acquisition unit is further configured as follows: The right boundary of the pre-allocated interval of the log identifier persisted by the previous master node of the distributed database is obtained by log replay.

18. The apparatus of claim 16, wherein, The second persistence unit is further configured as follows: In response to receiving a detach instruction indicating a switch from master to slave, the currently remaining allocatable interval of the pre-allocated log identifier is persisted to the log of the distributed database.

19. The apparatus of claim 16, wherein, The second clock service providing unit is further configured as follows: In response to receiving a clock service request, a log identifier corresponding to the clock service request is determined from the pre-allocated range of log identifiers for the current time using an auto-incrementing method; as well as The log identifier corresponding to the clock service request is provided as a response to the sender of the clock service request.

20. The apparatus according to any one of claims 16 to 19, wherein, The log identifier includes the log sequence number. The second clock service providing unit is further configured as follows: Log sequence numbers are allocated from the pre-allocated range of log identifiers in a monotonically increasing manner.

21. A distributed database, comprising: The master node is configured to perform the method as described in any one of claims 1 to 5 or to implement the method as described in any one of claims 6 to 10; The slave node is configured to synchronize the logs of the distributed database.

22. An apparatus for providing clock services for a distributed database, comprising: At least one processor, a memory coupled to the at least one processor, and a computer program stored on the memory, wherein the at least one processor executes the computer program to implement the method as claimed in any one of claims 1 to 5 or to implement the method as claimed in any one of claims 6 to 10.

23. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method as claimed in any one of claims 1 to 5 or the method as claimed in any one of claims 6 to 10.

24. A computer program product comprising a computer program that is executed by a processor to implement the method as claimed in any one of claims 1 to 5 or to implement the method as claimed in any one of claims 6 to 10.

Citation Information

Patent Citations

  • Data storage method and data storage device

    CN114201551A

  • Transaction commit protocol with recoverable commit identifier

    US20180232412A1