CN110162573B - Distributed sequence generation method, device and system - Google Patents

Distributed sequence generation method, device and system Download PDF

Info

Publication number
CN110162573B
CN110162573B CN201910367543.XA CN201910367543A CN110162573B CN 110162573 B CN110162573 B CN 110162573B CN 201910367543 A CN201910367543 A CN 201910367543A CN 110162573 B CN110162573 B CN 110162573B
Authority
CN
China
Prior art keywords
sequence
value
sequence value
distributed
server
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910367543.XA
Other languages
Chinese (zh)
Other versions
CN110162573A (en
Inventor
苗海柱
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bank of China Ltd
Original Assignee
Bank of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN201910367543.XA priority Critical patent/CN110162573B/en
Publication of CN110162573A publication Critical patent/CN110162573A/en
Application granted granted Critical
Publication of CN110162573B publication Critical patent/CN110162573B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the specification discloses a distributed sequence generation method, a distributed sequence generation device and a distributed sequence generation system. The method comprises receiving a request for a target server to obtain a sequence; acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period; incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period; and splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server. By using the embodiment of the specification, the efficiency of generating the sequence can be improved while the global unique sequence can be generated according to the actual scene.

Description

Distributed sequence generation method, device and system
Technical Field
The embodiment scheme of the specification belongs to the technical field of distributed systems, and particularly relates to a distributed sequence generation method, device and system.
Background
With the rapid development of the internet, a large-scale and distributed application system gradually becomes the standard configuration of a software system. In a distributed system, a plurality of servers provide services to the outside, and in many scenarios, a unique sequence ID in the system global needs to be allocated to the servers to distinguish the services provided by which server is the same service request, for example, a business order system generates a globally unique order number, a technical database partitioning system generates a globally unique database table primary key, and the like.
Currently, there are multiple ways to generate globally unique sequence IDs for servers in distributed systems: one is to use the unified server's own sequence ID generation mechanism to generate unique sequence IDs, for example, oracle database, redis database, zookeeper, etc. can all implement similar functions. However, this method needs to ensure the uniqueness of the generated sequence through the server characteristics, and using a single-point server in a high concurrency scenario becomes a single-point bottleneck. For example, with a sequence generation mechanism of the oracle database, since the oracle database is a single point itself and the number of receivable connections is limited, the oracle database becomes a system performance bottleneck when the concurrency reaches a certain degree. The second is a snowflake algorithm for generating a globally unique sequence ID under a distributed system based on local services. Although the mode is completely based on the local server to generate the unique sequence from the line, the problem of single-point bottleneck does not exist, the sequence generated by the snowflake algorithm is the maximum 19-bit length sequence, the sequence length cannot be defined by the user, and when the service scene has strict requirements on the sequence length, the method is not suitable. For example, a certain service application scenario requires a fixed-length sequence with a length of 12 bits, the snowflake algorithm cannot meet the requirement.
Therefore, there is a need in the art for a solution that can ensure that the generated sequence is globally unique and can adapt to different distributed scenarios.
Disclosure of Invention
An embodiment of the present disclosure aims to provide a method, an apparatus, and a system for generating a distributed sequence, which can generate a globally unique sequence ID in a distributed system according to a usage scenario of the distributed sequence, so as to effectively improve efficiency of generating the sequence while ensuring extremely high processing performance.
In one aspect, the present application provides a distributed sequence generation method, including:
receiving a request of a target server for acquiring a sequence;
acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period;
incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period;
and splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server.
In another embodiment of the method provided in this specification, the obtaining a first sequence value, and obtaining a current-use sequence value according to the first sequence value and a sequence offset, the first sequence value being a sequence value read by a sequence manager from a storage server, includes:
judging whether a persistent sequence value exists in the storage server or not;
upon determining that a persisted sequence value exists in the storage server, then reading the last persisted sequence value from the storage server as the first sequence value.
In another embodiment of the method provided in this specification, the method further includes:
and when the persistent sequence value is determined not to exist in the storage server, reading a preset value from the storage server as the first sequence value.
In another embodiment of the method provided in this specification, after the incrementing based on the current sequence of use value and obtaining a second sequence of values, the method further includes:
judging whether the second sequence value is larger than a preset sequence value or not;
when the sequence value is determined to be larger than the preset sequence value, resetting the second sequence value to obtain a reset second sequence value, wherein the sequence manager performs persistent storage on the reset second sequence value every other sequence storage period;
correspondingly, the reset second sequence value is spliced with the machine identification to generate a global unique sequence of the target server.
In another embodiment of the method provided in this specification, the storage server includes at least the functionality of persisting data.
In another aspect, an embodiment of the present specification further provides a distributed sequence generation apparatus, where the apparatus includes:
the receiving module is used for receiving a request of a target server for acquiring the sequence;
a first obtaining module, configured to obtain a first sequence value, and obtain a current usage sequence value according to the first sequence value and a sequence offset, where the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in one sequence storage period;
a second obtaining module, configured to increment based on the current usage sequence value to obtain a second sequence value, where the sequence manager persistently stores the second sequence value every other sequence storage period;
and the sequence generation module is used for splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server.
In another embodiment of the apparatus provided in this specification, the first obtaining module includes:
a first judging unit, configured to judge whether a persistent sequence value exists in the storage server;
a first reading unit, configured to, when it is determined that a persisted sequence value exists in the storage server, read, from the storage server, a last persisted sequence value as the first sequence value.
In another embodiment of the apparatus provided in this specification, the apparatus further includes:
and the second reading unit is used for reading a preset value from the storage server as the first sequence value when the storage server is determined not to have the persistent sequence value.
In another embodiment of the apparatus provided in this specification, the incrementing based on the current sequence of use value, after obtaining a second sequence of values, further comprises:
a second judging unit, configured to judge whether the second sequence value is greater than a preset sequence value;
a third obtaining unit, configured to reset the second sequence value when it is determined that the sequence value is greater than a preset sequence value, and obtain a reset second sequence value, where the sequence manager performs persistent storage on the reset second sequence value every other sequence storage period;
correspondingly, the reset second sequence value is spliced with the machine identification to generate a global unique sequence of the target server.
In another aspect, an embodiment of the present specification provides a distributed sequence generation apparatus, including a processor and a memory for storing processor-executable instructions, where the instructions, when executed by the processor, implement steps including:
receiving a request of a target server for acquiring a sequence;
acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period;
incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period;
and splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server.
In another aspect, the present specification provides a distributed sequence generation system, which includes at least one processor and a memory storing computer-executable instructions, where the processor executes the instructions to implement the steps of the method according to any one of the foregoing embodiments.
In the distributed sequence generation method, device and system provided in the embodiments of the present specification, on one hand, a sequence manager is introduced into a sequence generation service, and is used to intermittently persist a currently used sequence, and when the service is started, the persisted sequence data is read and an offset is added as a currently used sequence value, so that the problem that the sequence is lost after the service is restarted by using a memory storage sequence can be effectively solved, and the sequence generated before and after the service is started is guaranteed to be globally unique, thereby improving the efficiency of generating the sequence. On the other hand, as the sequence is completely generated by adopting the local service during the service operation period, the problem that the single-point server becomes the performance bottleneck can be effectively avoided, thereby ensuring extremely high processing performance. On the other hand, the sequence accumulation is carried out based on the currently used sequence synchronous increment mode, and no element is added into the sequence except the machine identifier, so that the length of the sequence can be completely customized according to the actual needs of a service scene, and the generated sequence can adapt to different distributed scenes. Therefore, by using the embodiments of the present specification, a globally unique sequence ID can be generated in a distributed system according to a usage scenario of a distributed sequence, thereby effectively improving the efficiency of generating a sequence while ensuring extremely high processing performance.
Drawings
In order to more clearly illustrate the embodiments of the present specification or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only some embodiments described in the present specification, and for those skilled in the art, other drawings can be obtained according to the drawings without any creative effort.
FIG. 1 is a schematic diagram of one scenario embodiment of a distributed sequence generation method provided herein;
FIG. 2 is a flow diagram of one embodiment of a distributed sequence generation method provided herein;
FIG. 3 is a flow diagram illustrating one embodiment of a distributed sequence generation method provided herein;
FIG. 4 is a flow diagram of a sequence manager at service startup in one embodiment of a distributed sequence generation method provided herein;
FIG. 5 is a flow diagram of a sequence manager during service run time in one embodiment of a distributed sequence generation method provided herein;
FIG. 6 is a block diagram of an embodiment of a distributed sequence generator provided in the present specification;
fig. 7 is a block diagram of a hardware structure of an embodiment of a distributed sequence generation server provided in the present specification.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present specification, the technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments in the present specification, and not all of the embodiments. All other embodiments that can be obtained by a person skilled in the art on the basis of one or more embodiments of the present description without inventive step shall fall within the scope of protection of the embodiments of the present description.
Currently, there are multiple ways to generate globally unique sequence IDs for servers in distributed systems: firstly, a unique sequence ID is generated by using a sequence ID generation mechanism of a unified server, but the method needs to ensure the uniqueness of a generated sequence through the characteristics of the server, and using a single-point server in a high-concurrency scene becomes a single-point bottleneck. And secondly, a snowflake algorithm for generating a global unique sequence ID under a distributed system based on local services is used, although the mode is that a unique sequence is generated from a line based on a local server completely, the problem of single-point bottleneck does not exist, but the sequence generated by the snowflake algorithm is a sequence with the maximum 19-bit length, the sequence length cannot be defined by self, and the snowflake algorithm is not suitable for use when a service scene has strict requirements on the sequence length.
Accordingly, embodiments of the present specification provide a distributed sequence generation method, and on one hand, a sequence manager is introduced into a sequence generation service, and is configured to intermittently persist a currently used sequence, and read persisted sequence data and add an offset as a currently used sequence value when a service is started, so that a problem that a sequence is lost after the service is restarted by using a memory storage sequence can be effectively solved, and it is ensured that sequences generated before and after the service is started are globally unique, thereby improving efficiency of generating the sequence. On the other hand, the sequence is generated by adopting the local service in the service operation period, so that the problem that the single-point server becomes a performance bottleneck can be effectively avoided, and extremely high processing performance is ensured. On the other hand, the sequence accumulation is carried out by using a sequence synchronous increment mode, and no element except the machine identifier is added into the sequence, so the length of the sequence can be completely customized according to the actual needs of a service scene, and the generated sequence can adapt to different distributed scenes. Therefore, by using the embodiments of the present specification, a globally unique sequence ID can be generated in a distributed system according to a usage scenario of a distributed sequence, thereby effectively improving the efficiency of generating a sequence while ensuring extremely high processing performance.
From the development perspective, in the embodiment provided in this specification, a developer needs to perform sequence structure setting according to an actual service scenario, select an appropriate storage server for persisting a current sequence value, and select an appropriate sequence manager for managing a sequence generation service.
The embodiments provided herein may be applied to a scenario in which a server is assigned a unique ID within a system in a distributed system, which may include a plurality of servers. As shown in fig. 1, fig. 1 is a schematic diagram of a scenario embodiment of a distributed sequence generation method provided in this specification. Specifically, in the distributed system sequence generation service, a sequence manager is introduced for reading a persistent sequence value from a storage server for use in the sequence generation service when the service is started; in addition, the sequence manager can also be used for intermittently persisting the currently used sequence value to the storage server, so that the problem that the sequence is lost after the service is restarted by using a memory storage sequence can be effectively avoided, the sequence generated before and after the service is started is ensured to be globally unique, and the sequence generation efficiency is improved.
The following describes an embodiment of the present disclosure with a specific application scenario as an example. Specifically, fig. 2 is a schematic flowchart of an embodiment of a distributed sequence generation method provided in this specification. Although the present specification provides the method steps or apparatus structures as shown in the following examples or figures, more or less steps or modules may be included in the method or apparatus structures based on conventional or non-inventive efforts. In the case of steps or structures which do not logically have the necessary cause and effect relationship, the execution order of the steps or the block structure of the apparatus is not limited to the execution order or the block structure shown in the embodiments or the drawings of the present specification. When the described method or module structure is applied to a device, a server or an end product in practice, the method or module structure according to the embodiment or the figures may be executed sequentially or in parallel (for example, in a parallel processor or multi-thread processing environment, or even in an implementation environment including distributed processing and server clustering).
Of course, the following description of the embodiments does not limit other extensible solutions based on the present description.
A specific embodiment is shown in fig. 2, where fig. 2 is a schematic flow chart of an embodiment of a distributed sequence generation method provided in this specification, and the method may include:
s0: a request for a target server to obtain a sequence is received.
The sequence, which may also be referred to as a sequence ID, is composed of a sequence value and a machine identification concatenation. The sequence value is a fixed-length value (which can be unified into long type), and is synchronously accumulated by 1 each time the sequence is generated, namely the sequence value is a series of self-increment values. The machine identifier, i.e., a working machine ID, which may also be referred to as a machine ID, is a unique identifier of the machine, and may be set in various ways, such as using an environment variable, a database storage, and the like. Since a plurality of servers run simultaneously in the distributed system environment, in order to make the sequence generated by each server inconsistent, the machine ID is added, that is, the machine ID is used for distinguishing different servers in the distributed system, so as to ensure the uniqueness of the sequence generated by different servers. In addition, the machine ID is initialized already at server startup, i.e., it is determined which server is when the sequence is generated. For example, two servers, numbered 1 and 2, respectively, then at server 1 boot up, a machine ID needs to be loaded. In general, the length of the sequence may be set according to actual situations, so that the length of the sequence value may be determined by using the length of the sequence and the length of the machine ID, and then the sequence value may be supplemented in a preset manner. The preset mode may be a mode of right-aligning and left-complementing 0, or other modes, which is not limited in this specification. If the length of the sequence is 12 and the length of the device ID is 3, the length of the sequence value can be determined to be 12-3 to 9, and if the sequence value is 1, the sequence value 1 is padded to a length of 9 bits, i.e., 000000001, by right-aligning and left-padding 0. In one embodiment of the present description, the target server sends a request for acquiring a sequence to the distributed system when the target server needs to acquire a unique sequence.
S2: acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read from a storage server by a sequence manager, and the sequence offset is a maximum sequence number generated in one sequence storage period.
In one embodiment of the present description, after the target server sends a request for obtaining a sequence to the distributed system, the distributed system reads a sequence value from the storage server through the sequence manager, that is, obtains a first sequence value, and then adds a sequence offset to the read sequence value as a current sequence of the managed sequence generation service.
Wherein the storage server is an encapsulation of the storage server operations, which may be a server for persistently recording the current sequence value. Further, the storage server may be a type selected according to actual needs, for example, the storage server may be a database such as mysql, oracle, or the like, a registration server such as zookeeper, or a redis cache server, or a file system, and the like, and the storage server may be all persistent data, which is not limited in this specification. In some embodiments, the storage server may include functionality to persist data. In other embodiments, the storage server may include other functions besides the function of persisting data, such as an operation function of reading data.
The sequence manager is a persistent store operation on the currently used sequence values. When the service is started, the sequence manager can read the sequence value recorded at the last time from the storage server, and adds the sequence offset as a sequence to generate a current sequence of the service, namely a current used sequence value; at service runtime, the sequence manager can persist the current usage sequence value to the storage server every specified sequence storage period.
The sequence offset is the maximum number of sequences that can be generated within one sequence storage period. For example, if the sequence storage period is 60 seconds, the maximum TPS supported by a single service (1 second processable transaction request) is 1000 (more than 1000 unprocessed), the sequence offset should be equal to or greater than 60 × 1000, 60000. Specifically, for example, if the currently used sequence value is 55, the sequence manager performs persistence, that is, it records the last used sequence value as 55, and the persistence of the next time is after 60 seconds, if a sequence needs to be generated during this period, that is, the sequence value may become 56, 57, 58, etc., when 60 seconds have not been reached, the service is restarted, the persistence data read after the restart is 55, obviously, because 56, 57, 58, etc. have been used, 55 cannot be used as the initial sequence value after the restart, so an offset is added on the basis of 55, and this offset is the maximum number of sequences that may occur in 60 seconds. When the sequence storage period is set, the sequence manager performs a current sequence value persistence operation every other time of the time limit, for example, the sequence manager sets the current sequence value to be 1 minute, and then persists the current sequence value every other 1 minute.
In addition, in one or more embodiments of the present disclosure, the sequence offset may also be greater than a maximum number of sequences that may be generated in a sequence storage period, that is, greater than a maximum number of sequences that may be consumed in one period, so that it is ensured that a sequence to be used after the service is started is not repeated with a sequence that is consumed.
In one embodiment of the present specification, the obtaining a first sequence value, and obtaining a current-use sequence value according to the first sequence value and a sequence offset, where the first sequence value is a sequence value read by a sequence manager from a storage server, includes: and judging whether the persistent sequence value exists in the storage server, and reading the last persistent sequence value from the storage server as the first sequence value when the persistent sequence value exists in the storage server. Specifically, when the sequence manager reads the sequence value from the storage server, the sequence manager first determines whether a persistent sequence value exists in the storage server, and if so, reads the last persistent sequence value from the storage server as a first sequence value, and then adds a sequence offset to the sequence value as a current usage sequence value of the managed sequence generation service.
In another embodiment of the present specification, the obtaining a first sequence value, and obtaining a current-use sequence value according to the first sequence value and a sequence offset, the first sequence value being a sequence value read by a sequence manager from a storage server, includes: and judging whether the storage server has a persistent sequence value, and reading a preset value from the storage server as the first sequence value when determining that the storage server does not have the persistent sequence value. Specifically, when the sequence manager reads the sequence value from the storage server, the sequence manager first determines whether a persistent sequence value exists in the storage server, and if not, reads a default value from the storage server as a first sequence value, and then adds a sequence offset to the sequence value as a current usage sequence value of the managed sequence generation service. The default value may be 0 or 1, or may be other values, which are not limited in this specification.
In another embodiment of the present specification, the obtaining a first sequence value, and obtaining a current-use sequence value according to the first sequence value and a sequence offset, the first sequence value being a sequence value read by a sequence manager from a storage server, includes: judging whether a persistent sequence value exists in the storage server, and reading the last persistent sequence value from the storage server as the first sequence value when the persistent sequence value exists in the storage server; and when the persistent sequence value is determined not to exist in the storage server, reading a preset value from the storage server as the first sequence value.
In the above embodiment, by introducing the sequence manager into the sequence generating service, on one hand, it can be well ensured that the sequences generated before and after the service is started are globally unique, that is, the generated sequences are not unique due to the loss of memory data. On the other hand, since the sequence manager only periodically and asynchronously reads the currently used sequence for the sequence generation service, there is hardly any influence on the performance of generating the sequence, that is, extremely high processing performance can be ensured. On the other hand, as the sequence generated during the service operation period is completely based on the operation of the memory, namely the local service is completely adopted to generate the sequence, the problem of performance bottleneck caused by a single-point server can be effectively avoided.
It should be noted that the embodiments of the present disclosure may be applied to service start and may also be applied to a service operation process.
S4: incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persists the second sequence value every other sequence storage period.
In one embodiment of the present description, after the sequence manager reads the sequence value from the storage server and then adds a sequence offset to the read sequence value as the current sequence of the managed sequence generation service, it is necessary to increment the sequence value required in the generation sequence for the target server, i.e., the second sequence value, on the basis of the current sequence. Wherein, the increment is adding 1 on the basis of the current sequence.
In an embodiment of the present description, at service runtime, the sequence manager may persist a current usage sequence value to the storage server every specified sequence storage period. Specifically, the sequence manager may store the current sequence value to the storage server periodically, that is, once every specified period, and only record the last stored record, and the history data is not saved. In this way, since the sequence manager asynchronously stores the managed sequence values during the running period, not only is there no intrusion influence on the performance of the sequence generation, but also even after the service is restarted, the sequence values are still increased based on the sequence values before the restart, and the global uniqueness of the sequence after the service is restarted can be effectively ensured. Wherein, the specified time period involved in the persistence of the currently used sequence value to the storage server by the sequence manager every other specified time period is the sequence storage period.
It should be noted that the asynchronism involved in the above embodiments is also embodied in that the sequence generation service is functionally independent during the program runtime, in addition to being embodied in the periodic persistence sequence. For example, when the sequence generation service generates 9 sequences 1 to 9, when the sequence manager reads the sequence, 5 is read, the sequence generation is not affected during the reading process, and the sequence may become 6 as soon as the reading is finished, i.e. the reading and the generation are independent.
In an embodiment of the present specification, after obtaining the second sequence value by incrementing based on the current usage sequence value, the method further includes: and judging whether the second sequence value is greater than a preset sequence value, resetting the second sequence value when the second sequence value is determined to be greater than the preset sequence value, and obtaining the reset second sequence value, wherein the sequence manager performs persistent storage on the reset second sequence value every other sequence storage period, and correspondingly splices the reset second sequence value with a machine identifier to generate a global unique sequence of the target server. Specifically, the sequence value is increased progressively on the basis of the current use sequence value, after a second sequence value is obtained, whether the sequence value is accumulated to a preset maximum sequence value is further judged, and when the maximum sequence value is accumulated, the sequence value is rolled back to the minimum value to start cycle use. It should be noted that, the accumulation of the sequence value to the preset maximum sequence value requires rolling back to the minimum value to start the loop, which is to ensure that the sequence generated in the service time limit is unique through data cleaning, and the maximum sequence value and the minimum value may be set according to an actual scene, which is not limited herein.
In another embodiment of the present specification, after determining whether the second sequence value is greater than the preset sequence value, when it is determined that the second sequence value is not greater than the preset sequence value, the second sequence value is converted into a sequence value with a fixed length according to a preset manner, and then the sequence value with the fixed length is spliced with the machine identifier to generate the global unique sequence of the target server, where the preset manner may be a right-alignment left-zero-filling manner, or another manner. Specifically, for example, the current usage sequence value is 55, the preset maximum sequence value is 100, 1 is added on the basis of the current usage sequence value 55 to obtain a second sequence value 56, and 56<100, the second sequence value 56 is converted into a fixed length by right-aligning and left-zero-filling, and then is spliced with the machine identifier to generate a globally unique sequence for the target server, where the fixed length can be determined according to the length of the actually required sequence and the length of the machine identifier, and if the length of the sequence is 12 bits and the length of the machine identifier is 3 bits, the fixed length of the sequence value can be determined to be 12-3-9 bits.
In another embodiment of the present specification, after determining whether the second sequence value is greater than a preset sequence value, if it is determined that the second sequence value is greater than the preset sequence value, resetting the second sequence value to obtain a reset second sequence value; and when the second sequence value is determined to be not greater than the preset sequence value, converting the second sequence value into a sequence value with a fixed length according to a preset mode. And the sequence manager performs persistent storage on the reset second sequence value/second sequence value every other sequence storage period, correspondingly converts the reset second sequence value/second sequence value into a sequence value with a fixed length according to a preset mode, and splices the sequence value with a machine identifier to generate a global unique sequence for the target server.
S6: and splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server.
Since the sequence is composed of a sequence value and a machine identifier, in some embodiments, after the sequence value is obtained, the sequence value and the machine identifier may be concatenated to generate a globally unique sequence for the target server. Where, generally, in some embodiments, the machine ID needs to be placed in front of the splice.
Since in a distributed system environment multiple servers are running simultaneously, machine identification is added in order to make the sequences generated by each server inconsistent. The machine identification is the unique identification of the machine.
In the embodiment, the sequence accumulation is performed only based on the currently used mode of sequence synchronization plus 1, and no element is added into the sequence except for the machine identifier, so that the length of the sequence can be completely customized according to the actual needs of a service scene, and the limitation that the snowflake algorithm needs 19-bit length can be avoided.
In the embodiment of the present specification, when the globally unique sequence is generated by splicing the sequence value and the machine identifier, the sequence value with a fixed length may be generated in a preset manner, and then the sequence value may be spliced with the machine identifier. The preset mode may be a mode of right-aligning and left-complementing 0, or other modes, which is not limited in this specification. Since the length of the sequence can be set according to the actual scene, and the machine ID is known, the length thereof can be determined, so that the length of the sequence value can be determined according to the length of the sequence and the length of the machine ID. Specifically, for example, assuming that the length of the sequence is 12, the machine ID is 123 (whose length can be determined to be 3), and the sequence value is 1, the length of the sequence value is 12-3-9, the sequence value is converted into 000000001 of length 9 by right-aligning and left-complementing 0, and since the machine ID is put in front in the normal splicing process, the final result obtained after splicing the machine ID (123) and the converted sequence value (000000001) is 123000000001, that is, the globally unique sequence of the target server. In the embodiment of the present invention, the sequence generation service uses a synchronization lock to process, that is, when a plurality of threads request, it is necessary to ensure that as long as 1 thread works, other threads wait.
In the distributed sequence generation method provided in the embodiments of this specification, on one hand, a sequence manager is introduced into a sequence generation service, persistent sequence data is read when the service is started, an offset is added as a currently used sequence value, then, in a process of using the sequence in a service operation period, accumulation is performed on the basis of the currently used sequence value to generate a final sequence for a target server, and meanwhile, the sequence manager is used to periodically store the current sequence value in the sequence generation service to a storage server, so that a problem that a memory storage sequence is lost after the service is restarted can be effectively solved, and it is ensured that a sequence generated before and after the service is started is globally unique, thereby improving efficiency of generating the sequence. On the other hand, in the service operation period, the sequence is generated by adopting the local service, so that the problem that the single-point server becomes a performance bottleneck can be effectively avoided, and extremely high processing performance is ensured. On the other hand, the sequence accumulation is carried out based on the currently used sequence synchronous increment mode, and no element is added into the sequence except the machine identifier, so that the length of the sequence can be completely customized according to the actual needs of a service scene, and the generated sequence can adapt to different distributed scenes. Therefore, by using the embodiments of the present specification, a globally unique sequence ID can be generated in a distributed system according to a usage scenario of a distributed sequence, thereby effectively improving the efficiency of generating a sequence while ensuring extremely high processing performance.
In order to further verify the practicability and feasibility of the method, the present specification also provides a specific example of applying the above scheme, as shown in fig. 3, fig. 3 is a schematic flow diagram of a specific embodiment of the distributed sequence generation method provided in the present specification. The method comprises the following concrete steps:
(1) a request to generate a sequence is received.
(2) And adding 1 to the current sequence value to be used as a new current sequence value.
When the service is started, the sequence manager reads the sequence value from the storage server, then adds a sequence offset value to the sequence generation service on the basis of the read sequence value, namely, the sequence value is used as the current sequence value, and adds 1 to the sequence on the basis of the subsequent sequence generation service to be used as a new current sequence value. And when the sequence value exists in the storage server, reading the sequence value recorded at the last time, and when the sequence value does not exist, defaulting to 0. Specifically, as shown in fig. 4, fig. 4 is a schematic flowchart of a sequence manager at the time of service startup in an embodiment of the distributed sequence generation method provided in this specification.
(3) And judging whether the new current sequence value is larger than a preset maximum value or not.
If the new current sequence value is larger than the preset maximum value, executing the step (4); and (5) if the new current sequence value is not larger than the preset maximum value, executing the step. The preset maximum value is a value preset according to an actual scene.
(4) Roll back the new current sequence value to 0 (or 1) and perform steps (5) -7.
(5) And generating the new current sequence value into a sequence value with a specified length according to a right alignment left complement 0 mode.
(6) And generating a global unique sequence by using a splicing mode of machine identification and a sequence value with a fixed length.
And (5) splicing the machine identification with the sequence value with the specified length generated in the step (5) to generate a global unique sequence.
(7) And returning the spliced sequence.
It should be noted that, in the above embodiment, during the service operation, the sequence manager persists the current sequence value to the storage server every specified sequence storage period. Specifically, the service operation period sequence manager comprises the following working steps: firstly, acquiring a current sequence value of a managed sequence generation service; secondly, the acquired current sequence value is persisted to a storage server; and thirdly, designating a sequence storage period at intervals and continuing to execute the step one. Fig. 5 is a schematic flowchart of a sequence manager during service operation in a specific embodiment of a distributed sequence generation method provided in this specification, as shown in fig. 5.
The result shows that by using the scheme provided by the application, the unique sequence ID of the whole office can be generated in the distributed system according to the use scene of the distributed sequence, so that the efficiency of generating the sequence can be effectively improved while the extremely high processing performance is ensured.
In the present specification, each embodiment of the method is described in a progressive manner, and the same and similar parts in each embodiment may be joined together, and each embodiment focuses on the differences from the other embodiments. Relevant points can be obtained by referring to part of the description of the embodiment of the method.
Based on the above-described distributed sequence generation method, one or more embodiments of the present specification further provide a distributed sequence generation apparatus. The apparatus may include systems (including distributed systems), software (applications), modules, components, servers, clients, etc. that use the methods described in the embodiments of the present specification in conjunction with any necessary apparatus to implement the hardware. Based on the same innovative conception, embodiments of the present specification provide an apparatus as described in the following embodiments. Since the implementation scheme of the apparatus for solving the problem is similar to that of the method, the specific implementation of the apparatus in the embodiment of the present specification may refer to the implementation of the foregoing method, and repeated details are not repeated. As used hereinafter, the term "unit" or "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Specifically, fig. 6 is a schematic block structure diagram of an embodiment of a distributed sequence generation apparatus provided in this specification, and as shown in fig. 6, the distributed sequence generation apparatus provided in this specification may include: a receiving module 120, a first obtaining module 122, a second obtaining module 124, and a sequence generating module 126.
A receiving module 120, configured to receive a request of a target server to obtain a sequence;
a first obtaining module 122, configured to obtain a first sequence value, and obtain a current-use sequence value according to the first sequence value and a sequence offset, where the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in one sequence storage period;
a second obtaining module 124, configured to increment based on the current usage sequence value to obtain a second sequence value, wherein the sequence manager persists the second sequence value every other sequence storage period;
the sequence generation module 126 may be configured to concatenate the second sequence value with the machine identifier to generate the globally unique sequence of the target server.
In another embodiment of the apparatus, the first obtaining module 122 may include:
a first judging unit, configured to judge whether a persistent sequence value exists in the storage server;
the first reading unit may be configured to, when it is determined that the persisted sequence value exists in the storage server, read the last persisted sequence value from the storage server as the first sequence value.
In another embodiment of the apparatus, the first obtaining module 122 may further include:
the second reading unit may be configured to read a preset value from the storage server as the first sequence value when it is determined that the persistent sequence value does not exist in the storage server.
In another embodiment of the apparatus, the incrementing based on the current sequence of usage value to obtain a second sequence of values may further comprise:
a second determining unit, configured to determine whether the second sequence value is greater than a preset sequence value;
a third obtaining unit, configured to reset the second sequence value when it is determined that the sequence value is greater than a preset sequence value, and obtain a reset second sequence value, where the sequence manager performs persistent storage on the reset second sequence value every other sequence storage period;
correspondingly, the reset second sequence value is spliced with the machine identification to generate a global unique sequence of the target server.
In the distributed sequence generation apparatus provided in the embodiments of the present specification, on one hand, a sequence manager is introduced into a sequence generation service, and is configured to intermittently persist a currently used sequence, and read persisted sequence data and add an offset as a currently used sequence value when the service is started, so that a problem that a sequence is lost after the service is restarted by using a memory storage sequence can be effectively solved, and it is ensured that the sequence generated before and after the service is started is globally unique, thereby improving the efficiency of generating the sequence. On the other hand, as the sequence is completely generated by adopting the local service during the service operation period, the problem that the single-point server becomes the performance bottleneck can be effectively avoided, thereby ensuring extremely high processing performance. On the other hand, the sequence accumulation is carried out based on the currently used sequence synchronous increment mode, and no element is added into the sequence except the machine identifier, so that the length of the sequence can be completely customized according to the actual needs of a service scene, and the generated sequence can adapt to different distributed scenes. Therefore, by using the embodiments of the present specification, a globally unique sequence ID can be generated in a distributed system according to a usage scenario of a distributed sequence, thereby effectively improving the efficiency of generating a sequence while ensuring extremely high processing performance.
It should be noted that the above-mentioned description of the apparatus according to the method embodiment may also include other embodiments, and specific implementation manners may refer to the description of the related method embodiment, which is not described herein again.
An embodiment of the present specification further provides a distributed sequence generation apparatus, including a processor and a memory for storing processor-executable instructions, where the instructions, when executed by the processor, implement steps including:
receiving a request of a target server for acquiring a sequence;
acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period;
incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period;
and splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server.
It should be noted that the above description of the apparatus according to the method embodiment may also include other embodiments. The specific implementation manner may refer to the description of the related method embodiment, and is not described in detail herein.
Embodiments of the present specification further provide a distributed sequence generation system, including at least one processor and a memory storing computer-executable instructions, where the processor executes the instructions to implement the steps of the method in any one or more of the above embodiments, for example, the steps include: receiving a request of a target server for acquiring a sequence; acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period; incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period; and splicing the second sequence value with a machine identifier to generate a global unique sequence of the target server. The system may be a single server, or may include a server cluster, a system (including a distributed system), software (applications), an actual operating device, a logic gate device, a quantum computer, etc. using one or more of the methods or one or more of the example devices of the present specification, in combination with a terminal device implementing hardware as necessary.
The method embodiments provided by the embodiments of the present specification can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking an example of the distributed sequence generation system running on a server, fig. 7 is a block diagram of a hardware structure of an embodiment of a distributed sequence generation server provided in this specification, where the server may be a distributed sequence generation apparatus or a distributed sequence generation system in the above embodiment. As shown in fig. 7, the server 10 may include one or more (only one shown) processors 100 (the processors 100 may include, but are not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 200 for storing data, and a transmission module 300 for communication functions. It will be understood by those skilled in the art that the structure shown in fig. 7 is only an illustration and is not intended to limit the structure of the electronic device. For example, the server 10 may also include more or fewer components than shown in FIG. 7, and may also include other processing hardware, such as a database or multi-level cache, a GPU, or have a different configuration than shown in FIG. 7, for example.
The memory 200 may be used to store software programs and modules of application software, such as program instructions/modules corresponding to the distributed sequence generation method in the embodiment of the present specification, and the processor 100 executes various functional applications and data processing by executing the software programs and modules stored in the memory 200. Memory 200 may include high speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, memory 200 may further include memory located remotely from processor 100, which may be connected to a computer terminal through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission module 300 is used for receiving or transmitting data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal. In one example, the transmission module 300 includes a Network adapter (NIC) that can be connected to other Network devices through a base station so as to communicate with the internet. In one example, the transmission module 300 may be a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The method or apparatus provided by the present specification and described in the foregoing embodiments may implement service logic through a computer program and record the service logic on a storage medium, where the storage medium may be read and executed by a computer, so as to implement the effect of the solution described in the embodiments of the present specification.
The storage medium may include a physical device for storing information, and typically, the information is digitized and then stored using an electrical, magnetic, or optical media. The storage medium may include: devices that store information using electrical energy, such as various types of memory, e.g., RAM, ROM, etc.; devices that store information using magnetic energy, such as hard disks, floppy disks, tapes, core memories, bubble memories, and usb disks; devices that store information optically, such as CDs or DVDs. Of course, there are other ways of storing media that can be read, such as quantum memory, graphene memory, and so forth.
The distributed sequence generation method or apparatus provided in the embodiments of the present specification may be implemented in a computer by a processor executing corresponding program instructions, for example, implemented in a PC end using a c + + language of a windows operating system, implemented in a linux system, or implemented in an intelligent terminal using android, iOS system programming languages, implemented in processing logic based on a quantum computer, or the like.
It should be noted that descriptions of the apparatus, the computer storage medium, and the system described above according to the related method embodiments may also include other embodiments, and specific implementations may refer to descriptions of corresponding method embodiments, which are not described in detail herein.
The embodiments in the present application are described in a progressive manner, and the same and similar parts among the embodiments can be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the hardware + program class embodiment, since it is substantially similar to the method embodiment, the description is simple, and the relevant points can be referred to the partial description of the method embodiment.
The embodiments of this specification are not limited to what must be in compliance with industry communication standards, standard computer data processing and data storage rules, or the description of one or more embodiments of this specification. Certain industry standards, or implementations modified slightly from those described using custom modes or examples, may also achieve the same, equivalent, or similar, or other, contemplated implementations of the above-described examples. The embodiments using the modified or transformed data acquisition, storage, judgment, processing and the like can still fall within the scope of the alternative embodiments of the embodiments in this specification.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Hardware Description Language), traffic, pl (core universal Programming Language), HDCal (jhdware Description Language), lang, Lola, HDL, laspam, hardward Description Language (vhr Description Language), vhal (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., 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 which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular telephone, 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 a combination of any of these devices.
Although one or more embodiments of the present description provide method operational steps as described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive approaches. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. When an actual apparatus or end product executes, it may execute sequentially or in parallel (e.g., parallel processors or multi-threaded environments, or even distributed data processing environments) according to the method shown in the embodiment or the figures. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, the presence of additional identical or equivalent elements in a process, method, article, or apparatus that comprises the recited elements is not excluded. The terms first, second, etc. are used to denote names, but not any particular order.
For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, when implementing one or more of the present description, the functions of each module may be implemented in one or more software and/or hardware, or a module implementing the same function may be implemented by a combination of multiple sub-modules or sub-units, etc. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, 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 a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
As will be appreciated by one skilled in the art, one or more embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment. In the description of the specification, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the specification. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
The above description is merely exemplary of one or more embodiments of the present disclosure and is not intended to limit the scope of one or more embodiments of the present disclosure. Various modifications and alterations to one or more embodiments described herein will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims.

Claims (11)

1. A distributed sequence generation method, comprising:
receiving a request of a target server for acquiring a sequence;
acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period;
incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period;
and converting the second sequence value into a sequence value with a fixed length according to a preset mode, and splicing the sequence value with the fixed length and the machine identifier to generate a global unique sequence of the target server.
2. The distributed sequence generation method of claim 1, wherein said obtaining a first sequence value, obtaining a current-use sequence value based on the first sequence value and a sequence offset, the first sequence value being a sequence value read by a sequence manager from a storage server, comprises:
judging whether a persistent sequence value exists in the storage server or not;
upon determining that a persisted sequence value exists in the storage server, then reading the last persisted sequence value from the storage server as the first sequence value.
3. The distributed sequence generation method of claim 2, further comprising:
and when the persistent sequence value is determined not to exist in the storage server, reading a preset value from the storage server as the first sequence value.
4. The distributed sequence generation method of claim 1, wherein said incrementing based on said current usage sequence value, after obtaining a second sequence value, further comprises:
judging whether the second sequence value is larger than a preset sequence value or not;
when the sequence value is determined to be larger than the preset sequence value, resetting the second sequence value to obtain a reset second sequence value, wherein the sequence manager performs persistent storage on the reset second sequence value every other sequence storage period;
correspondingly, the reset second sequence value is spliced with the machine identification to generate a global unique sequence of the target server.
5. A distributed sequence generation method as claimed in claim 1, wherein said storage server includes at least the function of persisting data.
6. A distributed sequence generation apparatus, comprising:
the receiving module is used for receiving a request of a target server for acquiring the sequence;
a first obtaining module, configured to obtain a first sequence value, and obtain a current usage sequence value according to the first sequence value and a sequence offset, where the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in one sequence storage period;
a second obtaining module, configured to increment based on the current usage sequence value to obtain a second sequence value, where the sequence manager persistently stores the second sequence value every other sequence storage period;
and the sequence generation module is used for converting the second sequence value into a sequence value with a fixed length according to a preset mode, splicing the sequence value with the fixed length with a machine identifier and generating a global unique sequence of the target server.
7. The distributed sequence generation apparatus of claim 6, wherein the first obtaining module comprises:
a first judging unit, configured to judge whether a persistent sequence value exists in the storage server;
a first reading unit, configured to, when it is determined that a persisted sequence value exists in the storage server, read, from the storage server, a last persisted sequence value as the first sequence value.
8. The distributed sequence generation apparatus of claim 7, further comprising:
and the second reading unit is used for reading a preset value from the storage server as the first sequence value when the storage server is determined not to have the persistent sequence value.
9. The distributed sequence generation apparatus of claim 6, wherein said incrementing based on said current usage sequence value, after obtaining a second sequence value, further comprises:
a second judging unit, configured to judge whether the second sequence value is greater than a preset sequence value;
a third obtaining unit, configured to reset the second sequence value when it is determined that the sequence value is greater than a preset sequence value, and obtain a reset second sequence value, where the sequence manager performs persistent storage on the reset second sequence value every other sequence storage period;
correspondingly, the reset second sequence value is spliced with the machine identification to generate a global unique sequence of the target server.
10. A distributed sequence generation apparatus comprising a processor and a memory for storing processor-executable instructions, which when executed by the processor implement steps comprising:
receiving a request of a target server for acquiring a sequence;
acquiring a first sequence value, and acquiring a current use sequence value according to the first sequence value and a sequence offset, wherein the first sequence value is a sequence value read by a sequence manager from a storage server, and the sequence offset is a maximum sequence number generated in a sequence storage period;
incrementing on the basis of the current usage sequence value to obtain a second sequence value, wherein the sequence manager persistently stores the second sequence value every other sequence storage period;
and converting the second sequence value into a sequence value with a fixed length according to a preset mode, and splicing the sequence value with the fixed length and the machine identifier to generate a global unique sequence of the target server.
11. A distributed sequence generation system comprising at least one processor and a memory storing computer-executable instructions which, when executed by the processor, implement the steps of the method of any one of claims 1 to 5.
CN201910367543.XA 2019-05-05 2019-05-05 Distributed sequence generation method, device and system Active CN110162573B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910367543.XA CN110162573B (en) 2019-05-05 2019-05-05 Distributed sequence generation method, device and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910367543.XA CN110162573B (en) 2019-05-05 2019-05-05 Distributed sequence generation method, device and system

Publications (2)

Publication Number Publication Date
CN110162573A CN110162573A (en) 2019-08-23
CN110162573B true CN110162573B (en) 2021-04-30

Family

ID=67633418

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910367543.XA Active CN110162573B (en) 2019-05-05 2019-05-05 Distributed sequence generation method, device and system

Country Status (1)

Country Link
CN (1) CN110162573B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111523002B (en) * 2020-04-23 2023-06-09 中国农业银行股份有限公司 Main key distribution method, device, server and storage medium
CN113934792B (en) * 2020-06-29 2023-03-24 金篆信科有限责任公司 Processing method and device of distributed database, network equipment and storage medium
CN112402983A (en) * 2020-08-03 2021-02-26 上海幻电信息科技有限公司 Game result verification method and system
CN113297327A (en) * 2021-05-24 2021-08-24 建信金融科技有限责任公司 System and method for generating distributed ID

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20030030514A (en) * 2001-10-11 2003-04-18 한국전자통신연구원 A method for optimizing the post-processing of sub-sequence matching in time-series databases
CN101174857A (en) * 2006-09-30 2008-05-07 华为技术有限公司 Sequence distribution method, sequence processing method and device in communication system
CN106549990A (en) * 2015-09-18 2017-03-29 阿里巴巴集团控股有限公司 A kind of processing method and system of distributed data
CN106570097A (en) * 2016-10-31 2017-04-19 华为技术有限公司 Sequence generating method and device
CN106899654A (en) * 2016-08-10 2017-06-27 阿里巴巴集团控股有限公司 A kind of sequence value generation method, apparatus and system
CN106940712A (en) * 2017-03-01 2017-07-11 星环信息科技(上海)有限公司 Sequence generating method and equipment
CN107038191A (en) * 2016-11-15 2017-08-11 阿里巴巴集团控股有限公司 A kind of data processing method of database sequence, device and server
CN108959386A (en) * 2018-05-31 2018-12-07 深圳壹账通智能科技有限公司 Distributed globally unique ID generation method, device, equipment and storage medium
CN109241447A (en) * 2018-10-29 2019-01-18 金蝶软件(中国)有限公司 A kind of method, terminal and the server of inquiring document data

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101963944B (en) * 2010-09-30 2015-04-15 用友软件股份有限公司 Object storage method and system
CN106407050B (en) * 2016-10-20 2020-11-10 科华恒盛股份有限公司 Data storage method

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20030030514A (en) * 2001-10-11 2003-04-18 한국전자통신연구원 A method for optimizing the post-processing of sub-sequence matching in time-series databases
CN101174857A (en) * 2006-09-30 2008-05-07 华为技术有限公司 Sequence distribution method, sequence processing method and device in communication system
CN106549990A (en) * 2015-09-18 2017-03-29 阿里巴巴集团控股有限公司 A kind of processing method and system of distributed data
CN106899654A (en) * 2016-08-10 2017-06-27 阿里巴巴集团控股有限公司 A kind of sequence value generation method, apparatus and system
CN106570097A (en) * 2016-10-31 2017-04-19 华为技术有限公司 Sequence generating method and device
CN107038191A (en) * 2016-11-15 2017-08-11 阿里巴巴集团控股有限公司 A kind of data processing method of database sequence, device and server
CN106940712A (en) * 2017-03-01 2017-07-11 星环信息科技(上海)有限公司 Sequence generating method and equipment
CN108959386A (en) * 2018-05-31 2018-12-07 深圳壹账通智能科技有限公司 Distributed globally unique ID generation method, device, equipment and storage medium
CN109241447A (en) * 2018-10-29 2019-01-18 金蝶软件(中国)有限公司 A kind of method, terminal and the server of inquiring document data

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于Hadoop架构和多级索引技术的医学影像存储检索系统研究;刘家志;《中国优秀硕士学位论文全文数据库 信息科技辑》;20160315;I138-5385 *

Also Published As

Publication number Publication date
CN110162573A (en) 2019-08-23

Similar Documents

Publication Publication Date Title
CN110162573B (en) Distributed sequence generation method, device and system
CN107450981B (en) Block chain consensus method and equipment
CN107450979B (en) Block chain consensus method and device
CN107391527B (en) Data processing method and device based on block chain
CN109634561B (en) Online visual programming method and device
CN108959341B (en) Data synchronization method, device and equipment
CN111767143A (en) Transaction data processing method, device, equipment and system
CN107066519B (en) Task detection method and device
CN110245279B (en) Dependency tree generation method, device, equipment and storage medium
CN110989939A (en) Data cache processing method, device and equipment and cache component
CN109947643B (en) A/B test-based experimental scheme configuration method, device and equipment
CN109033127B (en) Synchronous data verification method, device and equipment
CN109597678B (en) Task processing method and device
CN116305298B (en) Method and device for managing computing power resources, storage medium and electronic equipment
CN110633096B (en) Node control method and device, version control method and device and distributed system
CN111402058B (en) Data processing method, device, equipment and medium
CN113254163B (en) Processing method and device of block chain data
CN111190655A (en) Processing method, device, equipment and system for application cache data
CN114297734A (en) Data identifier generation method, device, equipment and medium
CN111142975B (en) State machine persistence method and state machine persistence system
CN111311267B (en) Multi-account risk prevention and control method, system and equipment
CN108769152B (en) Service refresh policy registration method, service refresh request method, device and equipment
CN107291439B (en) Target incremental data construction method and device
CN107402749B (en) Method and device for realizing picture loading library
CN107645541B (en) Data storage method and device and server

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant