Method, apparatus, and device for generating a monotonically increasing sequence
By generating global mapping tables in a distributed system and using distributed locks to generate monotonic incremental sequences in a distributed system, the unavailability problem caused by relying on third-party arbitration services is solved, and stable monotonic incremental sequence generation and service migration in disaster recovery scenarios are achieved.
Patent Information
- Application Number
- CN202210696481.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-20
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2042-06-20
AI Technical Summary
The existing monotonic incremental sequence generation method relies on third-party arbitration services, which makes the sequence generated when the arbitration service fails and is difficult to maintain.
Generate global mapping tables in a distributed system and push them regularly to slave nodes through distributed locks to ensure that the information flow of the same user is divided into the same data bucket, generating a monotonic incremental sequence, and avoiding dependence on third-party services.
It realizes stable monotonic increasing sequence generation in disaster recovery scenarios, reduces dependence on third-party services, and improves system stability and resource utilization.
Smart Images

Figure CN115033414B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of Internet technologies, and in particular, to a method, apparatus, and device for generating a monotonically increasing sequence. Background Art
[0002] With the development of the Internet, the Synchronize service is widely used in the synchronization between multimedia such as music and video and text content, and also, the content download and update between the client and the server depend on this service. The Synchronize service relies on a monotonically increasing sequence number to mark a unique and ordered message, so as to achieve incremental and ordered data push for the information flow and avoid conflicts. In the existing methods for generating a monotonically increasing sequence, generally, a third-party arbitration service is relied on. If the third-party arbitration service fails, the generated sequence may become unavailable and difficult to maintain.
[0003] Based on this, a more stable scheme for generating a monotonically increasing sequence is needed. Summary of the Invention
[0004] Embodiments of this specification provide a method, apparatus, device, and storage medium for generating a monotonically increasing sequence to solve the following technical problem: a more stable scheme for generating a monotonically increasing sequence is needed.
[0005] To solve the above technical problem, one or more embodiments of this specification are implemented as follows:
[0006] In a first aspect, an embodiment of this specification provides a method for generating a monotonically increasing sequence, which is applied to a master node in a distributed system including multiple nodes. The method includes: generating a global mapping table, and periodically pushing the global mapping table to slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes in the system and data buckets; according to the global mapping relationship, obtaining the data bucket corresponding to itself by using a distributed lock, where the information flow of the same user is pre-divided into the same data bucket; generating a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
[0007] In a second aspect, an embodiment of this specification provides another method for generating a monotonically increasing sequence, which is applied to a slave node in a distributed system including multiple nodes. The method includes: obtaining the global mapping table periodically pushed by the master node, where the global mapping table is used to store the global mapping relationship between all nodes in the system and data buckets; according to the global mapping relationship, obtaining the data bucket corresponding to itself by using a distributed lock, where the information flow of the same user is pre-divided into the same data bucket; generating a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
[0008] In a third aspect, corresponding to the first aspect, an embodiment of the present specification provides a monotonically increasing sequence generation device, which is applied to a master node in a distributed system including multiple nodes. The device includes: a generation module, which generates a global mapping table and periodically pushes the global mapping table to slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; a first data bucket acquisition module, which acquires the data bucket corresponding to itself by using a distributed lock according to the global mapping relationship, where the information flow of the same user is pre-divided into the same data bucket; a first sequence module, which generates a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
[0009] In a fourth aspect, corresponding to the second aspect, an embodiment of the present specification provides another monotonically increasing sequence generation device, which is applied to a slave node in a distributed system including multiple nodes. The device includes: a global mapping table acquisition module, which acquires the global mapping table periodically pushed by the master node, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; a second data bucket acquisition module, which acquires the data bucket corresponding to itself by using a distributed lock according to the global mapping relationship, where the information flow of the same user is pre-divided into the same data bucket; a second sequence module, which generates a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
[0010] In a fifth aspect, an embodiment of the present specification provides an electronic device, including:
[0011] at least one processor; and,
[0012] a memory communicatively connected to the at least one processor; where,
[0013] the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described in the first aspect or the second aspect.
[0014] In a sixth aspect, an embodiment of the present specification provides a non-volatile computer storage medium storing computer-executable instructions. When a computer reads the computer-executable instructions in the storage medium, the instructions cause one or more processors to execute the method as described in the first aspect or the second aspect.
[0015] The above at least one technical solution adopted by one or more embodiments of this specification can achieve the following beneficial effects: By generating a global mapping table in the master node and regularly pushing the global mapping table to the slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; in both the master node and the slave nodes, the corresponding data bucket can be obtained by using a distributed lock according to the global mapping relationship, and the information flow of the same user is pre-divided into the same data bucket; and in both the master node and the slave nodes, a monotonically increasing sequence can be generated for the information flow in the corresponding data bucket. Thus, except for the service migration process in the disaster recovery scenario being weakly dependent on the distributed storage, the main process of the sequence generation service does not depend on any other third-party service, and a stable monotonically increasing sequence can be generated. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in this specification. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0017] Figure 1 It is a schematic flowchart of a method for generating a monotonically increasing sequence provided by an embodiment of this specification;
[0018] Figure 2 It is a schematic architecture diagram of a distributed system provided by an embodiment of this specification;
[0019] Figure 3 It is a schematic flowchart of another method for generating a monotonically increasing sequence provided by an embodiment of this specification;
[0020] Figure 4 It is a schematic diagram of service migration occurring in the master node provided by an embodiment of this specification;
[0021] Figure 5 It is a schematic structural diagram of a device for generating a monotonically increasing sequence provided by an embodiment of this specification;
[0022] Figure 6 It is a schematic structural diagram of another device for generating a monotonically increasing sequence provided by an embodiment of this specification;
[0023] Figure 7 It is a schematic structural diagram of an electronic device provided by an embodiment of this specification. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] The embodiments of this specification provide a method, apparatus, device, and storage medium for generating a monotonically increasing sequence.
[0025] To enable those skilled in the art to better understand the technical solutions in this specification, the following will clearly and completely describe the technical solutions in the embodiments of this specification with reference to the accompanying drawings in the embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments of this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application.
[0026] In the first aspect, as Figure 1 shown, Figure 1 is a schematic flowchart of a method for generating a monotonically increasing sequence provided by the embodiments of this specification, which is applied to the master node in a distributed system including multiple nodes. Figure 1 The process in it may include the following steps:
[0027] S101, generate a global mapping table and periodically push the global mapping table to the slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system.
[0028] As Figure 2 shown, Figure 2 is a schematic architecture diagram of a distributed system provided by the embodiments of this specification. In this distributed system, there are a master node and slave nodes. Among them, the master node and slave nodes can be elected from the cluster based on a distributed consensus algorithm (such as VSR, Paxos, Raft, and Zab, etc.). Generally, there is one master node and multiple slave nodes.
[0029] A heartbeat mechanism can be adopted between the master node and the slave nodes to determine whether they are active or have failed, etc. When the master node fails, the slave nodes can re-elect a new master node to maintain the relevant functions of the master node.
[0030] In the embodiments of this specification, the distributed system provides a monotonically increasing sequence service for the obtained traffic. Specifically, as Figure 2 shown, there are multiple clients respectively obtaining information streams from the database. In order to accurately push these information streams to the clients of each user in an orderly manner, that is, it is necessary for the distributed system to provide a monotonically increasing sequence for the information streams.
[0031] To this end, it is first necessary to bucket the traffic to be served, and regard a data bucket as a whole, and a single node (including the master node or the slave node) provides exclusive service for this data bucket: for example, if data bucket A is occupied by node 1, then all information flows in data bucket A will be serially served by node 1; at the same time, when node 1 is serially serving data bucket A, other nodes cannot process data bucket A.
[0032] Also based on this, the master node can communicate with the database and generate a global mapping table, which is used to store the global mapping relationship between all nodes and data buckets in the system, that is, the routing relationship between data buckets and nodes.
[0033] Maintaining the global mapping table is a dynamic process. Any operation such as a node going offline, crashing, or coming online may cause changes in the global mapping relationship. For example, assume that the routing for data buckets is distributed based on the remainder of the number of nodes. Then, when there are 3 nodes, data bucket 5 will be distributed to node 2, and when there are 4 nodes, data bucket 5 will be distributed to node 1. That is, the global mapping relationship can be dynamically maintained based on the number of nodes in the distributed system.
[0034] In this case, each node (including the master node and the slave node) will also maintain a temporary local mapping relationship locally. The local mapping table is used to store the local mapping relationship between its own node and the data bucket. The local mapping table can be updated based on the global mapping table. In other words, the local mapping table has a certain lag with respect to the global mapping table.
[0035] S103, according to the global mapping relationship, use a distributed lock to obtain the data bucket corresponding to itself, where the information flows of the same user are pre-divided into the same data bucket.
[0036] In the embodiments of this specification, the distributed system provides a monotonically increasing sequence service for the obtained traffic. Specifically, as Figure 2 shown, there are multiple clients respectively obtaining information flows from the database. In order to accurately push these information flows to the clients of each user in an orderly manner, that is, it is necessary for the distributed system to provide a monotonically increasing sequence for the information flows.
[0037] To this end, it is first necessary to bucket the traffic to be served, and regard a data bucket as a whole, and a single node (including the master node or the slave node) provides exclusive service for this data bucket: that is, if data bucket A is occupied by node 1, then all information flows in data bucket A will be serially served by node 1; at the same time, when node 1 is serially serving data bucket A, other nodes cannot process data bucket A.
[0038] In other words, in the embodiments of this specification, the data buckets satisfy the following characteristics: a single data bucket is only held by a single-node machine; during machine offline, downtime, and multi-data center disaster recovery, the data buckets on some nodes will be transferred to other nodes, and during the transfer process, each data bucket needs to be transferred as a whole.
[0039] Since the sequences generated for each data bucket are independent of each other, in order to keep the information flow of the same user monotonically increasing in terms of sequence, it is necessary to allocate the information flow of the same user to the same data bucket so that the information flow of the same user can be processed by a master node or a slave node.
[0040] Specifically, the following method can be used to bucket the information flow: for any information flow, obtain the user identifier included in the information flow; determine the hash value of the user identifier, and determine the data bucket corresponding to the information flow according to the hash value. Since the hash value of the user identifier is unique, it can be ensured that the information flow of the same user is always divided into the same data bucket.
[0041] In the distributed system, in theory, actually each node can seize and exclusively occupy any of the foregoing data buckets. However, in order to achieve consistency among nodes, each node will exclusively seize each data bucket according to the obtained global mapping relationship, and use the method of distributed locks during the seizure process, so as to ensure that any data bucket can only be held by a single node when being contended by multiple nodes.
[0042] For example, if the global mapping table stores the mapping relationship between the master node and data bucket 1, then the master node can initiate a seizure of data bucket 1 and initiate a consensus to other nodes. Since other nodes can query this mapping relationship from the global mapping table, the consensus initiated by the master node can pass in the system. After the consensus passes, lock processing is performed on data bucket 1 to prevent other nodes from seizing it again.
[0043] If other nodes initiate a seizure of data bucket 1 first, then since other nodes cannot query the mapping relationship between other nodes and data bucket 1 from the global mapping table, the consensus cannot pass, and the master node can still seize data bucket 1.
[0044] S105, generate a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
[0045] In practical applications, although the master node needs to maintain the global mapping table, it still needs to provide the service of generating a monotonically increasing sequence for the information flow.
[0046] Specifically, a data bucket can contain multiple information flows, and the information flows contain user identifiers and timestamps. The master node only needs to generate a monotonically increasing sequence corresponding to the information flows according to the order of the timestamps.
[0047] For example, in data bucket 1, there are information flows arranged in sequence based on timestamps T1 to T5: (ID1, T1), (ID2, T2), (ID1, T3), (ID3, T4), (ID2, T5). Then, a corresponding monotonically increasing sequence can be generated based on the order of T1 to T5: (ID1, T1, No1), (ID2, T2, No2), (ID1, T3, No3), (ID3, T4, No4), (ID2, T5, No5). Thus, for user ID1, its information flows will be processed in sequence based on No1 and No3. For user ID2, its corresponding information flows will be processed in sequence based on No2 and No5, thereby realizing that the main process of the sequence generation service in the master node does not depend on any other third-party services and achieving stable generation of a monotonically increasing sequence.
[0048] In one embodiment, for the master node, it also needs to detect the status of the slave nodes in the distributed system and update the global mapping table according to the status of the slave nodes.
[0049] For example, establish connections with each slave node based on a heartbeat mechanism. When a slave node stops sending heartbeat feedback, remove the slave node from the global mapping table, reallocate the data bucket corresponding to the slave node to other nodes, and update the global mapping table.
[0050] In addition, the master node can also actively add other new slave nodes outside to the distributed system and update the routing allocation status of the data buckets based on the number of newly added slave nodes, thereby updating the global mapping table.
[0051] In addition, it should be noted that for the master node, it can also maintain a local mapping table locally (for example, in local memory or cache) to store the local mapping relationship between the master node and the data buckets. If there is a conflict between the local mapping table and the global mapping table, service migration can also be initiated on the master node to transfer the corresponding data buckets to other nodes for generating a monotonically increasing sequence.
[0052] The foregoing first aspect has described the basic functions of the master node in the embodiments of this specification. In the second aspect, the embodiments of this specification also provide another method for generating a monotonically increasing sequence, which is applied to the slave nodes in a distributed system including multiple nodes, as Figure 3 shown Figure 3The flowchart of another method for generating a monotonically increasing sequence provided by the embodiments of this specification, the method comprising:
[0053] S301, obtain the global mapping table regularly pushed by the master node, wherein the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system. The generation method and function of the global mapping table have been described in the foregoing first aspect and will not be elaborated herein.
[0054] S303, according to the global mapping relationship, use a distributed lock to obtain the data bucket corresponding to itself, wherein the information flow of the same user is pre-divided into the same data bucket.
[0055] S305, generate a monotonically increasing sequence for the information flow in the data bucket corresponding to itself
[0056] For the implementation manners of parts in steps S301 and S305, reference may be made to the obtaining manner and sequence generation manner adopted in the master node of the first aspect. The two are only different in the implementation subject, and the rest of the implementation manners are the same.
[0057] By generating a global mapping table in the master node and regularly pushing the global mapping table to the slave nodes, wherein the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; according to the global mapping relationship, a distributed lock can be used to obtain the data bucket corresponding to itself in both the master node and the slave nodes, wherein the information flow of the same user is pre-divided into the same data bucket; and, a monotonically increasing sequence can be generated for the information flow in the data bucket corresponding to itself in both the master node and the slave nodes. Thus, in addition to the service migration process in the disaster recovery scenario being weakly dependent on distributed storage, the main process of the sequence generation service does not depend on any other third-party services, realizing stable generation of a monotonically increasing sequence.
[0058] In one implementation manner, if there is a change in the cluster members (usually occurring in the slave nodes), including adding nodes, deleting nodes, removing faulty nodes, etc., it means a change in the global mapping table of data buckets and nodes in the entire system, and it also means that some data buckets need to be transferred from one node (also called the previous node or the old node) to another node (also called the new node) for sequence generation service. This process of data bucket transfer can generally be referred to as service migration.
[0059] In the embodiments of this specification, for the service migration that occurs in the slave nodes, the following specific method can be adopted: compare the global mapping table with the local mapping table maintained locally to determine the data buckets with differences, where the local mapping table is used to store the local mapping relationship between its own node and the data buckets; determine the previous node corresponding to the data buckets with differences; initiate a service migration request to the previous node so that the previous node releases the distributed lock of the data buckets with differences; receive the notification information indicating the success of the request returned by the previous node, and generate a monotonically increasing sequence for the information flow in the data buckets with differences.
[0060] Since the service migration is completed in units of data buckets, each node can check whether new data buckets (i.e., data buckets with differences) need to be processed by comparing the differences between the latest global mapping table and the local mapping table maintained in the current memory. If so, a service migration request will be initiated to the previous node where the data buckets with differences are located.
[0061] It should be noted that in this process, each node only needs to compare and determine the data buckets with differences in its own node. For example, after the global mapping table is updated, data bucket 1 originally processed by node 4 is forwarded to node 1, data bucket 2 originally processed by node 4 is forwarded to node 2, and data bucket 5 originally processed by node 5 is forwarded to node 1. Then, for node 1, the data buckets with differences in its own node obtained by comparison are data bucket 1 and data bucket 5.
[0062] Furthermore, node 1 can respectively initiate a service migration request for data bucket 1 to node 4 and a service migration request for data bucket 5 to node 5.
[0063] After receiving the service migration request, each previous node can suspend the processing of these data buckets and release the corresponding distributed lock, and reply with the notification information indicating the success of the request after the release is successful. Continuing with the previous example, node 4 can suspend the processing of data bucket 1 and release the distributed lock for data bucket 1 so that node 1 can perform exclusive processing of the distributed lock for data bucket 1.
[0064] When the new node receives the notification information indicating the success of the request from the old node, it immediately attempts to acquire the distributed lock corresponding to these data bucket lists. After successful acquisition, it begins to generate a monotonically increasing sequence. Thus, a mechanism based on negotiation is implemented to achieve second-level smooth migration of services within the cluster. In the aforementioned disaster recovery scenario, all service nodes are mutual primary and standby, which improves resource utilization compared to the primary and standby disaster recovery mode.
[0065] In one implementation, when the old node returns the notification information indicating the success of the request, it can also return the theoretically maximum sequence value generated in the previous node at the same time. The theoretically maximum sequence value is positively correlated with the communication interval between the old node and the new node. Correspondingly, when the new node receives the theoretically maximum sequence value, when processing the information flow in the data bucket with differences, it needs to generate a monotonically increasing sequence not lower than the theoretically maximum sequence value. If the generated sequence is greater than the above-mentioned theoretically maximum sequence value, it starts to provide services normally; otherwise, the service is blocked until the newly generated sequence is greater than the above-mentioned theoretically maximum sequence value.
[0066] For example, for a data bucket 10, it has been processed halfway by node 4 and needs to be transferred to node 1 for processing. For node 4, it determines a safe sequence interval (assumed to be 200) based on the communication interval between node 4 and node 1, and for the sequence value (assumed to be 100) that node 4 has given to data bucket 10 currently, the theoretically maximum sequence value = safe sequence interval + currently given sequence value (which is 300).
[0067] For node 1, when it processes data bucket 10 again, if the given sequence value is lower than 300, it pauses the information service for the users in data bucket 10 by blocking the service until the sequence value is higher than 300. In this way, it can be ensured that a monotonically increasing sequence can still be maintained during the transfer between the old node and the new node, so as to ensure accurate service for users.
[0068] In one implementation, for the new node, if it does not receive the notification information indicating the success of the request returned by the previous node within the specified duration, it can be considered that it is caused by current node failure, network disconnection, etc. In this case, it may not be possible to use the above-mentioned negotiation-based mechanism to complete service transfer.
[0069] At this time, the service transfer can be realized based on the mechanism of the distributed lock lease period. Specifically, for the master node and the slave node, when they obtain the data bucket using the distributed lock, they can both determine the duration of the distributed lock. If the time to obtain the data bucket exceeds the duration, the distributed lock is released. If a node fails to process a data bucket within the duration and needs to continue processing the data bucket, it needs to initiate a lease application to extend the duration by one more period. This can avoid the long-term exclusive occupation caused by reasons such as network failures of nodes, resulting in the inability to resume normal services.
[0070] Under this mechanism, for a node, if it initiates a service transfer request to other nodes and does not receive a response, and if it does not receive the notification information indicating the success of the request returned by the previous node within the specified duration (the specified duration is usually greater than the duration of the aforementioned distributed lock), it can be defaulted that the other node has failed, and the distributed lock of the data bucket has been released due to timeout. At this time, the node can use the distributed lock to obtain the data bucket with differences, and perform sequential services after successful acquisition. In this way, an additional mechanism can be provided to ensure data consistency among nodes to achieve service migration when the negotiation mechanism fails to work properly.
[0071] In addition, for each slave node, if the master node fails or goes offline actively, then each slave node can re-elect a new master node based on the distributed consensus algorithm within the system, and perform service migration based on the global mapping table given by the new master node. As Figure 4 shown, Figure 4 is a schematic diagram of service migration of the master node provided by the embodiments of this specification.
[0072] In this schematic diagram, node 5 (node5) fails or needs to go offline actively as the original master node. When other slave nodes cannot detect its heartbeat, they re-elect node 4 as the master node based on the distributed consensus algorithm and establish a heartbeat connection, and perform service migration of the data buckets that need to be processed in the original node 5 to other nodes for processing based on the master node 4.
[0073] Based on the same idea, one or more embodiments of this specification also provide a corresponding device and equipment for the above method.
[0074] In the third aspect, corresponding to the first aspect, as Figure 5 shown, Figure 5 is a schematic structural diagram of a monotonically increasing sequence generation device provided by the embodiments of this specification, which is applied to the master node in a distributed system including multiple nodes. The device includes:
[0075] A generation module 501 that generates a global mapping table and periodically pushes the global mapping table to slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system;
[0076] A first data bucket acquisition module 503 that acquires its corresponding data bucket using a distributed lock according to the global mapping relationship, where the information flow of the same user is pre-divided into the same data bucket;
[0077] A first sequence module 505 that generates a monotonically increasing sequence for the information flow in its corresponding data bucket.
[0078] Optionally, the first sequence module 505 determines the timestamps of the information flows included in the data bucket, and generates a monotonically increasing sequence corresponding to the information flows according to the chronological order of the timestamps.
[0079] Optionally, the apparatus further includes a detection module 507 that detects the status of the slave nodes in the distributed system and updates the global mapping table according to the status of the slave nodes.
[0080] Optionally, the apparatus further includes a data bucket partitioning module 509 that, for any information flow, obtains the user identifiers included in the information flow, determines the hash values of the user identifiers, and determines the data bucket corresponding to the information flow according to the hash values.
[0081] In a fourth aspect, corresponding to the second aspect, as Figure 6 shown, Figure 6 is a schematic structural diagram of another monotonically increasing sequence generation apparatus provided by an embodiment of this specification, which is applied to a slave node in a distributed system including multiple nodes. The apparatus includes:
[0082] A global mapping table acquisition module 601 acquires the global mapping table regularly pushed by the master node, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system.
[0083] A second data bucket acquisition module 603 acquires its corresponding data bucket by using a distributed lock according to the global mapping relationship, where the information flows of the same user are pre-partitioned into the same data bucket.
[0084] A second sequence module 605 generates a monotonically increasing sequence for the information flows in its corresponding data bucket.
[0085] Optionally, the second sequence module 605 determines the timestamps of the information flows included in the data bucket, and generates a monotonically increasing sequence corresponding to the information flows according to the chronological order of the timestamps.
[0086] Optionally, the apparatus further includes a service migration module 607: compares the global mapping table with the local mapping table maintained locally to determine the data buckets with differences, where the local mapping table is used to store the local mapping relationship between its own node and data buckets; determines the previous node corresponding to the data buckets with differences; sends a service migration request to the previous node so that the previous node releases the distributed lock of the data buckets with differences; and receives the notification information indicating the success of the request returned by the previous node, and generates a monotonically increasing sequence for the information flows in the data buckets with differences.
[0087] Optionally, if the service migration module 607 does not receive the notification information indicating successful request returned by the previous node within a specified duration, it acquires the data buckets with differences by using a distributed lock.
[0088] Optionally, the service migration module 607 receives the notification information indicating successful request and the theoretical maximum sequence value returned by the previous node; correspondingly, the second sequence module 605 generates a monotonically increasing sequence not lower than the theoretical maximum sequence value for the information flow in the data buckets with differences.
[0089] Optionally, the apparatus further includes a lock lease module 609 that determines the duration of the distributed lock; after the time for acquiring the data bucket exceeds the duration, the distributed lock is released.
[0090] In a fifth aspect, as Figure 7 shown, Figure 7 is a schematic structural diagram of an electronic device provided by an embodiment of this specification. The device includes:
[0091] At least one processor; and,
[0092] A memory communicatively connected to the at least one processor; wherein,
[0093] The memory stores instructions executable by the at least one processor. When the instructions are executed by the at least one processor, the at least one processor is enabled to execute the method according to the first aspect or the second aspect.
[0094] In a sixth aspect, based on the same concept, an embodiment of this specification further provides a non-volatile computer storage medium corresponding to the above method, storing computer-executable instructions. When a computer reads the computer-executable instructions in the storage medium, the instructions cause one or more processors to execute the method according to the first aspect or the second aspect.
[0095] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software improvements (improvements to method flows). However, with the development of technology, many method flow improvements today can be regarded as direct improvements to hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement to a method flow cannot be implemented using a hardware entity module. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logical function is determined by the user programming the device. Designers can program themselves to "integrate" a digital system onto a single PLD, without having to ask a chip manufacturer to design and fabricate a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly implemented using "logic compiler" software, which is similar to the software compilers used in program development and writing. The original code before compilation also has to be written in a specific programming language, which is called a Hardware Description Language (HDL), and there is not just one type of HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also be aware that by simply performing a little logical programming on the method flow using the above-mentioned several hardware description languages and programming it into an integrated circuit, it is easy to obtain the hardware circuit that implements the logical method flow.
[0096] The controller can be implemented in any suitable manner. For example, the controller can take the form of, for example, a microprocessor or a processor and a computer-readable medium that stores computer-readable program code (such as software or firmware) executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of the controller include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program code, it is entirely possible to logically program the method steps to enable the controller to be implemented in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. to achieve the same function. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be regarded as the structures within the hardware component. Or even, the devices for implementing various functions can be regarded as either software modules for implementing the method or structures within the hardware component.
[0097] The systems, devices, modules, or units illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0098] For the convenience of description, when describing the above devices, they are described separately as various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0099] Those skilled in the art should understand that the embodiments of this specification can be provided as a method, a system, or a computer program product. Therefore, the embodiments of this specification can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of this specification can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) that contain computer-usable program code.
[0100] This specification is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the specification. It should be understood that each flow and / or block in the flowchart and / or block diagram, and combinations of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions executed by the processor of the computer or other programmable data processing device generate means for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0101] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable memory produce a manufacture including instruction means for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0102] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are performed on the computer or other programmable device to produce a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0103] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0104] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
[0105] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0106] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0107] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0108] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and non-volatile computer storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0109] The above description has been made of specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the acts or steps recited in the claims may be performed in a different order than in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require the particular order shown or sequential order to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0110] The foregoing is only one or more embodiments of this specification and is not intended to limit this specification. For those skilled in the art, various changes and modifications can be made to one or more embodiments of this specification. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of this specification shall be included within the scope of the claims of this specification.
Claims
1. A method for generating a monotonically increasing sequence, which is applied to a master node in a distributed system including multiple nodes. The method includes: generating a global mapping table and periodically pushing the global mapping table to slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; acquiring the data bucket corresponding to itself according to the global mapping relationship by using a distributed lock, where the information flow of the same user is pre-divided into the same data bucket; generating a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
2. The method according to claim 1, wherein Generating a monotonically increasing sequence for the information flow in the data bucket corresponding to itself includes: determining the timestamps of the information flows included in the data bucket; generating a monotonically increasing sequence corresponding to the information flows according to the chronological order of the timestamps.
3. The method according to claim 1, further includes: detecting the status of slave nodes in the distributed system and updating the global mapping table according to the status of the slave nodes.
4. The method according to claim 1, wherein, The information flow of the same user is pre-divided into the same data bucket in the following way: for any information flow, acquiring the user identifier included in the information flow; determining the hash value of the user identifier and determining the data bucket corresponding to the information flow according to the hash value.
5. A method for generating a monotonically increasing sequence, which is applied to a slave node in a distributed system including multiple nodes. The method includes: acquiring the global mapping table periodically pushed by the master node, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; acquiring the data bucket corresponding to itself according to the global mapping relationship by using a distributed lock, where the information flow of the same user is pre-divided into the same data bucket; generating a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
6. The method according to claim 5, wherein, Generating a monotonically increasing sequence for the information flow in the data bucket corresponding to itself includes: determining the timestamps of the information flows included in the data bucket; generating a monotonically increasing sequence corresponding to the information flows according to the chronological order of the timestamps.
7. The method according to claim 5, wherein, The method further includes: comparing the global mapping table with the local mapping table maintained locally to determine the data buckets with differences, where the local mapping table is used to store the local mapping relationship between its own node and data buckets; determining the previous node corresponding to the data bucket with differences; initiating a service migration request to the previous node so that the previous node releases the distributed lock of the data bucket with differences; receiving the notification information indicating the success of the request returned by the previous node and generating a monotonically increasing sequence for the information flow in the data bucket with differences.
8. The method according to claim 7, further includes: if the notification information indicating the success of the request returned by the previous node is not received within a specified duration, acquiring the data bucket with differences by using a distributed lock.
9. The method according to claim 7, wherein, Receiving the notification information indicating the success of the request returned by the previous node further includes: receiving the notification information indicating the success of the request returned by the previous node and the theoretical maximum sequence value; Correspondingly, generating a monotonically increasing sequence for the information flow in the data bucket with differences includes: generating a monotonically increasing sequence not lower than the theoretical maximum sequence value for the information flow in the data bucket with differences.
10. The method according to claim 5, the method further includes: Determining the duration of the distributed lock; Releasing the distributed lock after the time for obtaining the data bucket exceeds the duration.
11. A monotonically increasing sequence generation device, applied to the master node in a distributed system including multiple nodes, the device includes: A generation module, which generates a global mapping table and periodically pushes the global mapping table to the slave nodes, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; A first data bucket acquisition module, which acquires the data bucket corresponding to itself by using a distributed lock according to the global mapping relationship, where the information flow of the same user is pre-divided into the same data bucket; A first sequence module, which generates a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
12. A monotonically increasing sequence generation device, applied to the slave node in a distributed system including multiple nodes, the device includes: A global mapping table acquisition module, which acquires the global mapping table periodically pushed by the master node, where the global mapping table is used to store the global mapping relationship between all nodes and data buckets in the system; A second data bucket acquisition module, which acquires the data bucket corresponding to itself by using a distributed lock according to the global mapping relationship, where the information flow of the same user is pre-divided into the same data bucket; A second sequence module, which generates a monotonically increasing sequence for the information flow in the data bucket corresponding to itself.
13. An electronic device, including: At least one processor; And, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
A method and apparatus for allocate service identifiers
CN109388502A
Sorting method and device applied to database and related equipment
CN110704424A