CN114168607A - Global serial number generation method, device, equipment, medium and product - Google Patents

Global serial number generation method, device, equipment, medium and product Download PDF

Info

Publication number
CN114168607A
CN114168607A CN202111520425.1A CN202111520425A CN114168607A CN 114168607 A CN114168607 A CN 114168607A CN 202111520425 A CN202111520425 A CN 202111520425A CN 114168607 A CN114168607 A CN 114168607A
Authority
CN
China
Prior art keywords
timestamp
time
task request
generating
module
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.)
Pending
Application number
CN202111520425.1A
Other languages
Chinese (zh)
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.)
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology Co Ltd
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology Co 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 Industrial and Commercial Bank of China Ltd ICBC, ICBC Technology Co Ltd filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202111520425.1A priority Critical patent/CN114168607A/en
Publication of CN114168607A publication Critical patent/CN114168607A/en
Pending legal-status Critical Current

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/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2315Optimistic concurrency control
    • G06F16/2322Optimistic concurrency control using timestamps
    • 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/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Fuzzy Systems (AREA)
  • Mathematical Physics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The disclosure provides a global sequence number generation method, which can be applied to the technical field of big data. The global sequence number generation method comprises the following steps: receiving a task request and recording the receiving time; acquiring a related sequence code based on the task request and the receiving time; generating a first timestamp through a locking process based on the reception time; and generating the global sequence number based on the correlation sequence code and the first timestamp. The present disclosure also provides a global serial number generation apparatus, device, storage medium, and program product.

Description

Global serial number generation method, device, equipment, medium and product
Technical Field
The present disclosure relates to the field of big data, particularly to the field of distributed data processing, and more particularly, to a method, apparatus, device, medium, and program product for generating a global serial number.
Background
The developers all use globally unique sequence codes in the development process, such as UUIDs, database self-increment sequences or snowflake algorithms in distributed scenes. And the self-increment sequence of the database has low performance and is difficult to expand, thereby easily causing technical bottleneck. For UUID, although simple and without network consumption, the query efficiency is low due to the sequence code disorder, and the trend cannot be increased. The snowflake algorithm can roughly meet the generation sequence and is simple and efficient, but is seriously dependent on the clock of the server, and if the clock is wrong, the global uniqueness cannot be guaranteed.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a method, apparatus, device, medium, and program product for global serial number generation that ensures global uniqueness while improving generation efficiency.
According to a first aspect of the present disclosure, there is provided a method of global sequence number generation, including: receiving a task request and recording the receiving time; acquiring a related sequence code based on the task request and the receiving time; generating a first timestamp through a locking process based on the reception time; and generating the global sequence number based on the correlation sequence code and the first timestamp.
According to an embodiment of the present disclosure, the obtaining a relevant sequence code based on the task request and the receiving time includes: acquiring a server identifier based on the task request, wherein the server identifier comprises an address identifier; generating a second timestamp based on the time of receipt, wherein a unit of a lowest bit of the second timestamp is greater than a unit of a highest bit of the first timestamp; generating a random code; and generating the correlation sequence code by sorting based on the server identification, the second timestamp, and the random code.
According to the embodiment of the present disclosure, the server identifier further includes a service group identifier, and the service group identifier is used to reflect a service group in which the server is located, where a plurality of service group identifiers are included for the same server.
According to an embodiment of the present disclosure, the generating a first timestamp through a locking process based on the reception time includes: acquiring a second task request, and recording a second moment; locking the second task request to ensure the uniqueness of the second task request at the moment when the tasks are sent concurrently; acquiring a first moment, wherein the first moment corresponds to a first task request, and the first task request comprises a last task request of the second task request; judging whether the second moment is greater than the first moment; and adopting the second time as the first time stamp when the second time is larger than the first time.
According to an embodiment of the present disclosure, the method further comprises: adding a fixed preset value to the value of the first moment to obtain a third moment under the condition that the second moment is not greater than the first moment; and adopting the third time as the first time stamp.
According to an embodiment of the present disclosure, the first timestamp includes millisecond information.
According to an embodiment of the present disclosure, the second timestamp comprises year, month, day, hour, minute, second level information.
A second aspect of the present disclosure provides an apparatus for global sequence number generation, comprising: the system comprises a task receiving module, a related sequence code generating module, a first time stamp generating module and a global sequence number generating module, wherein the task receiving module is used for receiving a task request and recording receiving time; the relevant sequence code generating module is used for acquiring a relevant sequence code based on the task request and the receiving time; the first timestamp generation module is configured to generate a first timestamp through locking processing based on the receiving time; and the global sequence number generation module is used for generating the global sequence number based on the correlation sequence code and the first time stamp.
According to an embodiment of the present disclosure, the correlation sequence code generating module includes: the system comprises a server identifier generation module, a second timestamp generation module, a random code generation module and a related sequence code sequencing module, wherein the server identifier generation module is used for acquiring a server identifier based on the task request, and the server identifier comprises an address identifier; the second timestamp generating module is configured to generate a second timestamp based on the receiving time, where a unit of a lowest bit of the second timestamp is greater than a unit of a highest bit of the first timestamp; the random code generating module is used for generating a random code; and the related sequence code ordering module is used for generating the related sequence code through ordering based on the server identification, the second time stamp and the random code.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of global sequence number generation described above.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the above-described method of global sequence number generation.
A fifth aspect of the present disclosure also provides a computer program product comprising a computer program which, when executed by a processor, implements the method of global sequence number generation described above.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be apparent from the following description of embodiments of the disclosure, which proceeds with reference to the accompanying drawings, in which:
fig. 1 schematically illustrates an application scenario diagram of a method, apparatus, device, medium, and program product for global serial number generation according to an embodiment of the present disclosure.
Fig. 2 schematically shows a flow chart of a method of global sequence number generation according to an embodiment of the present disclosure.
Fig. 3 schematically illustrates a flow chart of a method of correlating sequence code generation according to an embodiment of the disclosure.
Fig. 4A schematically illustrates a flow chart of a method of first timestamp generation according to an embodiment of the present disclosure.
Fig. 4B schematically illustrates a flow chart of another method of first timestamp generation according to an embodiment of the present disclosure.
Fig. 5A schematically shows a block diagram of a global sequence number generation apparatus according to an embodiment of the present disclosure.
Fig. 5B schematically shows a block diagram of another serial number generation apparatus according to an embodiment of the present disclosure.
FIG. 6 is a schematic diagram schematically illustrating the operation principle of volatile according to an embodiment of the present disclosure.
Fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a method of global sequence number according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
Before describing the technical solution of the present disclosure, technical terms in the field are explained as follows:
global sequence number: under the condition of realizing the database and the table, the database autonomous key cannot ensure the global uniqueness of the autonomous key, so the operation of generating a global serial number is required to ensure the full-field uniqueness.
volatile: the modifier of the Java language, which is related to the memory model, ensures that each instruction is not omitted due to compiler optimization and requires direct reading each time.
synchronized: the key words of Java language represent the meaning of the lock, and the locking code block can ensure that only one thread can access the locking code block when multiple threads are executed concurrently.
In the prior art, there are several solutions:
the first scheme is as follows: database incrementing is utilized such that the full database is unique. But at the same time, this approach causes increased database pressure in a single database-to-single table scenario.
Scheme II: UUID, a 16-system format string with length of 32 is generated, that is, data with length of 128 bit. But at the same time, the scheme is in an unordered state for the sequencing of the sequence codes, and the splicing time can be further used on the basis of the scheme, but the situation that the sequence number is too long can be generated.
The third scheme is as follows: the snowflake algorithm is ordered according to time increment, and ID collision cannot be generated in a distributed system. However, this sub-scheme relies on the server clock and requires expensive independent development and deployment.
And the scheme is as follows: and generating the ID by adopting Redis, and when the performance of generating the serial number by using the database is not enough, performing single-thread operation by adopting Redis to generate the globally unique ID. Specifically, this is achieved by atomic operations INCR and INCRBY of Redis. However, this solution requires the introduction of new components, which increases the complexity of the system.
The solutions in the prior art cannot be perfect, some solutions have low efficiency, performance bottlenecks easily exist, and some solutions depend on third-party components, thereby increasing the complexity of the system. Some generated unique sequences are unordered, and the query efficiency is low. And the time, business meaning and the like generated by the globally unique sequence cannot be intuitively seen basically. According to the invention, after different implementation modes are known and considered, a globally unique sequence can be efficiently generated by acquiring the server IP through a java memory model and a locking mechanism, and the requirement of globally increasing the sequence code generated by each server is met. The calling time and the calling time of the server can be immediately seen, and the condition can be met only if the IP of the server is unique in the same network segment in a multi-machine load deployment scene.
An embodiment of the present disclosure provides a method for generating a global sequence number, where the method includes: receiving a task request and recording the receiving time; acquiring a related sequence code based on the task request and the receiving time; generating a first timestamp through a locking process based on the reception time; and generating the global sequence number based on the correlation sequence code and the first timestamp. According to the embodiment of the disclosure, the global uniqueness of the current first timestamp in the locking stage is ensured through the first timestamp generated by the locking processing, and particularly when high concurrency threads are handled, the locking operation ensures that the first timestamp generated based on the task request is generated in order according to the queue, and the global sequence number generated by combining the related sequence code is globally unique. Meanwhile, the method is fast and simple to implement, and can be widely applied to different implementation scenes, particularly distributed scenes.
Fig. 1 schematically shows an application scenario diagram of a method of global sequence number generation according to an embodiment of the present disclosure.
As shown in fig. 1, the application scenario 100 according to this embodiment may include terminals 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (for example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and perform other processing on the received data such as the user request, and feed back a processing result (e.g., a webpage, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the method for generating the global sequence number provided by the embodiment of the present disclosure may be generally executed by the server 105. Accordingly, the apparatus for global sequence number generation provided by the embodiments of the present disclosure may be generally disposed in the server 105. The method for generating the global sequence number provided by the embodiment of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the apparatus for generating the global sequence number provided by the embodiment of the present disclosure may also be disposed in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation. The method for generating the global sequence number of the disclosed embodiment will be described in detail below with fig. 2 to 4B based on the scenario described in fig. 1.
Fig. 2 schematically shows a flow chart of a method of global sequence number generation according to an embodiment of the present disclosure.
As shown in fig. 2, a method of generating a global serial number of the embodiment includes operations S210 to S230, and the transaction processing method may be performed by a serial number generation server.
In operation S210, a task request is received, and a reception time is recorded.
According to embodiments of the present disclosure, a server of a distributed database may receive task requests including at least invocation requests, insertion requests, and the like. Wherein the call request exists in the form of a thread.
According to an embodiment of the present disclosure, the receiving time includes recording the time in units of time of year, month, day, hour, minute, second, millisecond, or the like.
In operation S220, a correlation sequence code is obtained based on the task request and the receiving time.
For example, the server receives the call request at 678 ms, 33 minutes 05 seconds at 11/10/18/2021. The time of day is recorded.
In operation S230, a first timestamp is generated through a locking process based on the reception time.
According to an embodiment of the present disclosure, the first timestamp includes millisecond information.
Of course, the first time stamp also includes units below the millisecond level, such as the microsecond level.
For example, the value of the millisecond value 678 is taken as the preselected value of the first timestamp, because before the value of the first timestamp is taken as the value of the millisecond value 678, the locking process needs to be performed to ensure the uniqueness of the current first timestamp. Therefore, the millisecond value 678 is only used as reference information, and the value of the first timestamp should be obtained after the lock-up process.
Specifically, for example, in a scenario of dealing with high concurrency, a call request of multiple threads needs to be distinguished, locked processing is performed in a Java environment by synchronized, and a code block to be accessed by a thread is locked, so that only one thread of the multiple threads can access the locked code block. And after the current thread is processed, the next thread is repeatedly locked, so that the current thread has uniqueness, and the generated first timestamp has certain uniqueness.
However, since the first timestamp includes only three bits, a value repetition occurs after processing the call request of the thread a plurality of times. The global sequence number is generated by combining with other related sequence codes to ensure the uniqueness of the global sequence number.
In operation S240, the global sequence number is generated based on the correlation sequence code and the first timestamp.
According to the embodiment of the present disclosure, the ordering of the relevant sequence code and the first timestamp in the global sequence number is not limited.
According to the embodiment of the disclosure, the global uniqueness of the current first timestamp in the locking stage is ensured through the first timestamp generated by the locking processing, and particularly when high concurrency threads are handled, the locking operation ensures that the first timestamp generated based on the task request is generated in order according to the queue, and the global sequence number generated by combining the related sequence code is globally unique. Meanwhile, the method is fast and simple to implement, and can be widely applied to different implementation environments, particularly scenes of distributed architectures.
Fig. 3 schematically illustrates a flow chart of a method of correlating sequence code generation according to an embodiment of the disclosure.
As shown in fig. 3, a method for generating a correlation serial code according to this embodiment includes operations S310 to S340.
In operation S310, a server identifier is obtained based on the task request, wherein the server identifier includes an address identifier.
According to an embodiment of the present disclosure, the address identification includes IP information of the server.
For example, in the case of being in the same network segment, the IP information may take only the last three bits, which may be 202. By doing so, redundant IP information is guaranteed to be eliminated, and the sequence is simplified.
According to the embodiment of the present disclosure, the server identifier further includes a service group identifier, and the service group identifier is used to reflect a service group in which the server is located, where a plurality of service group identifiers are included for the same server.
For example, if the deployment scenario is that the same server deploys multiple services, it can be distinguished by the profile flag. For example, a1 and a2 are used to distinguish different service groups in which the same server is located. The service identifier is used for distinguishing different services of the same server, so that the global sequence number is more reasonable.
In operation S320, a second timestamp is generated based on the reception time, wherein a unit of a lowest bit of the second timestamp is greater than a unit of a highest bit of the first timestamp.
For example, the second timestamp is 33 minutes 05 seconds at 11 hours at 18 months at 2021, and the lowest order unit of the second timestamp is seconds, which is greater than the highest order millisecond unit of the first timestamp.
In operation S330, a random code is generated.
According to an embodiment of the present disclosure, the random code includes: random letters, random numbers, etc.
According to an embodiment of the present disclosure, the random code further includes a number of bits.
For example, the random code employs a random letter with a digit number of 3, such as brb.
In operation S340, the related sequence code is generated by sorting based on the server identification, the second timestamp, and the random code.
According to the embodiment of the present disclosure, the server identifier, the second timestamp, and the random code in the related sequence code are not limited to be sorted.
For example, the global sequence number may be "202 brb211018Y113305T 678" and "202 brb211018Y 113305T" belong to the related sequence code. Wherein, "202" belongs to the address identifier, "brb" belongs to the random code, "211018Y 113305" belongs to the second timestamp, wherein, "Y" is used for dividing the number, which is convenient for the user to quickly identify, and similarly, "T" is also used for dividing the number. "678" belongs to the first timestamp.
For another example, the global sequence number may be "A1 brb211018Y113305T 678" or "A2 bts211018Y113305T 928", where "A1" belongs to the service group id, which indicates that the invocation request belongs to the first service group transmission of the server; "A2" belongs to the service group ID, indicating that the invocation request belongs to the second service group transmission of the server. So doing so will not be described in detail. It should be noted that the above-mentioned sorting is performed based on the principle of easy recognition and use for the user. Moreover, the global sequence number is the same as the global sequence number in different service groups of the same server, and further, in order to avoid the long bit number and redundancy of the global sequence number, the global sequence number is not constructed by adopting the address identifier.
It should be noted that, the above-mentioned S310 to S320 only indicate different acquisition manners adopted for different related sequence code components, and there is no logical context, and therefore, the execution order of the above-mentioned S310 to S320 is not particularly limited.
In the embodiment of the disclosure, the server identifier supports multi-server deployment; the second time stamp is used for viewing the generation date and the specific generation time; the random code can be used as a secondary guarantee to prevent repetition. Based on the above, the generated related sequence code can ensure that a massive and non-repetitive global sequence number is generated.
Fig. 4A schematically illustrates a flow chart of a method of first timestamp generation according to an embodiment of the present disclosure. FIG. 6 is a schematic diagram schematically illustrating the operation principle of volatile according to an embodiment of the present disclosure.
As shown in fig. 4A, a method of generating a first timestamp of this embodiment includes operations S410 to S450.
In operation S410, a second task request is obtained, and a second time is recorded.
According to the embodiment of the present disclosure, in the case of acquiring a call request for the first time or a request for acquiring a task for a long time. If the first task request and the first time do not exist, the second time (i.e. the current time) corresponding to the second task request is directly used as the first timestamp.
Specifically, a preset interval time is set, and if two requests exceed the preset interval time, the current time of receiving the task request is directly obtained, and the current time is used as a first timestamp.
In operation S420, the second task request is locked to ensure uniqueness of the second task request at the time when the task is concurrently executed.
In operation S430, a first time corresponding to a first task request is obtained, where the first task request includes a last task request of the second task request.
For example, the called code block is locked by synchronized and then compared with the first time of the last request by the current second time, which is based on the global variable modified by the vollatile.
The modifier volaile has the following characteristics: firstly, prohibiting instruction rearrangement; second, memory visibility is guaranteed. The invention mainly uses the characteristic of the modifier volatile for ensuring the visibility of the memory.
FIG. 6 is a schematic diagram schematically illustrating the operation principle of volatile according to an embodiment of the present disclosure.
As shown in FIG. 6, for the global variable i modified by the voltate, the modifier voltate can ensure that the value of the global variable i is immediately flushed back to the main memory after the thread A changes the value of the global variable i. Therefore, if at this point in time thread B is also calling the value of global variable i, this value is also invalidated for the value of global variable i called in working memory B. Thus, thread B is forced to read the new value of global variable i from the main memory into the working memory B again. Finally, at any one time, the value of the global variable i as seen by thread a and thread B is guaranteed to be the same value. Of course, the number of threads is merely illustrative and not limiting.
In operation S440, it is determined whether the second time is greater than the first time.
In operation S450, in case that the second time is greater than the first time, adopting the second time as the first timestamp.
According to the embodiment of the disclosure, uniqueness when the concurrent task request is received is ensured through locking, whether the current time is greater than the last time or not is judged based on the uniqueness, and if so, the current second time is taken as the first time stamp, so that rapid generation of the rapid first time stamp is ensured.
Fig. 4B schematically illustrates a flow chart of another method of first timestamp generation according to an embodiment of the present disclosure.
As shown in fig. 4B, the method for generating a first timestamp of this embodiment includes operations S460 to S470 in addition to the operations S410 to S450.
In operation S460, in the case that the second time is not greater than the first time, a fixed preset value is added to the value of the first time to obtain a third time.
In operation S470, the third time is adopted as the first timestamp.
According to an embodiment of the disclosure, the fixed preset value is determined based on a situation, in a general situation, the fixed preset data takes 1, and further, in a case that the second time is not greater than the first time, the first time is processed by adding 1 to obtain a third time.
For example, when the second time is 678 and the first time is 679, 1 is added to the first time to obtain a third time 680, and 680 is taken as the value of the first timestamp.
It should be noted that, in the embodiment of the present disclosure, the operations S460 to S470 and S450 are in any time sequence relationship, and only represent different operations performed in the case of two different determination results.
In the embodiment of the present disclosure, when the second time is not greater than the first time, a termination process such as an alarm is not performed. The method has the advantages that the operation of adding the fixed preset value is carried out on the basis of the original last receiving time, so that the method has a fault-tolerant mechanism, the time sequence is sequenced when the time sequence is disordered, the service generated by the global sequence number is not terminated, and the effective operation of the service is ensured.
Compared with the current mainstream global unique sequence generation scheme, the method and the device do not depend on a third-party component and do not need to generate additional network consumption. Secondly, when the multi-server deployment is carried out, the server can be uniquely determined. And the generation time and the generation sequence of the unique sequence code can be seen, and the unique sequence code has business meaning. In addition, through personal PC (personal computer) testing, the time consumed by calling 100 thousands of times is basically within the time range of 2.5S-3.2S, the high-concurrency and high-availability are realized, and the rapidly-developed Internet big data scene is met.
Based on the methods described in fig. 2 to fig. 4B, the present disclosure also provides a device for generating a global sequence number. The apparatus will be described in detail below with reference to fig. 5A to 5B.
Fig. 5A schematically shows a block diagram of a global sequence number generation apparatus according to an embodiment of the present disclosure.
As shown in fig. 5A, the global sequence number generating apparatus 500 of this embodiment includes a task receiving module 510, a correlation sequence code generating module 520, a first time stamp generating module 530, and a global sequence number generating module 540.
The task receiving module 510 is configured to receive a task request and record a receiving time. In an embodiment, the task receiving module 510 is configured to perform the operation S210 described above, which is not described herein again.
The relevant sequence code generating module 520 is configured to obtain a relevant sequence code based on the task request and the receiving time. In an embodiment, the correlation sequence code generating module 520 may be configured to perform the operation S220 described above, which is not described herein again.
The first timestamp generating module 530 is configured to generate a first timestamp through a locking process based on the receiving time. In an embodiment, the first timestamp generating module 530 may be configured to perform the operation S230 described above, which is not described herein again.
The global sequence number generating module 540 is configured to generate the global sequence number based on the correlation sequence code and the first timestamp. In an embodiment, the global sequence number generating module 540 may be configured to perform the operation S240 described above, which is not described herein again.
According to the embodiment of the disclosure, the global uniqueness of the current first timestamp in the locking stage is ensured through the first timestamp generated by the locking processing, and particularly when high concurrency threads are handled, the locking operation ensures that the first timestamp generated based on the task request is generated in order according to the queue, and the global sequence number generated by combining the related sequence code is globally unique. Meanwhile, the method is fast and simple to implement and can be widely applied to different distributed implementation environments.
Fig. 5B schematically shows a block diagram of another serial number generation apparatus according to an embodiment of the present disclosure.
As shown in fig. 5B, the correlation sequence code generating module 520 includes: a server identification generation module 521, a second timestamp generation module 522, a random code generation module 523 and a related sequence code sorting module 524,
wherein the content of the first and second substances,
the server identifier generating module 521 is configured to obtain a server identifier based on the task request, where the server identifier includes an address identifier;
the second timestamp generation module 522 is configured to generate a second timestamp based on the receiving time, where a unit of a lowest bit of the second timestamp is greater than a unit of a highest bit of the first timestamp;
the random code generating module 523 is configured to generate a random code; and
the related sequence code ordering module 524 is configured to generate the related sequence code by ordering based on the server identifier, the second timestamp, and the random code.
According to an embodiment of the present disclosure, any multiple modules of the task receiving module 510, the correlation sequence code generating module 520, the first time stamp generating module 530 and the global sequence number generating module 540 may be combined and implemented in one module, or any one of the modules may be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of the other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the task receiving module 510, the correlation sequence code generating module 520, the first time stamp generating module 530 and the global sequence number generating module 540 may be at least partially implemented as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented by hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or implemented by any one of three implementations of software, hardware and firmware, or by a suitable combination of any several of them. Alternatively, at least one of the task receiving module 510, the correlation sequence code generating module 520, the first time stamp generating module 530 and the global sequence number generating module 540 may be at least partially implemented as a computer program module, which when executed, may perform a corresponding function.
Fig. 7 schematically shows a block diagram of an electronic device adapted to implement a method of global sequence number generation according to an embodiment of the present disclosure.
As shown in fig. 7, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. The processor 701 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 701 may also include on-board memory for caching purposes. The processor 701 may comprise a single processing unit or a plurality of processing units for performing the different actions of the method flows according to embodiments of the present disclosure.
In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other by a bus 704. The processor 701 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 702 and/or the RAM 703. It is noted that the programs may also be stored in one or more memories other than the ROM 702 and RAM 703. The processor 701 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
Electronic device 700 may also include input/output (I/O) interface 705, which input/output (I/O) interface 705 is also connected to bus 704, according to an embodiment of the present disclosure. The electronic device 700 may also include one or more of the following components connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 707 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 702 and/or the RAM 703 and/or one or more memories other than the ROM 702 and the RAM 703 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method illustrated in the flow chart. When the computer program product runs in a computer system, the program code is used for causing the computer system to realize the global serial number generation method provided by the embodiment of the disclosure.
The computer program performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure when executed by the processor 701. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted in the form of a signal on a network medium, distributed, downloaded and installed via the communication section 709, and/or installed from the removable medium 711. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program, when executed by the processor 701, performs the above-described functions defined in the system of the embodiment of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.

Claims (12)

1. A method of global sequence number generation, the method comprising:
receiving a task request and recording the receiving time;
acquiring a related sequence code based on the task request and the receiving time;
generating a first timestamp through a locking process based on the reception time; and
generating the global sequence number based on the correlation sequence code and the first timestamp.
2. The method of claim 1, wherein obtaining the correlation sequence code based on the task request and the receiving time comprises:
acquiring a server identifier based on the task request, wherein the server identifier comprises an address identifier;
generating a second timestamp based on the time of receipt, wherein a unit of a lowest bit of the second timestamp is greater than a unit of a highest bit of the first timestamp;
generating a random code; and
generating the correlation sequence code by sorting based on the server identification, the second timestamp, and the random code.
3. The method of claim 2, wherein the server identifier further comprises a service group identifier, wherein the service group identifier is used to reflect a service group in which the server is located, and wherein the same server comprises a plurality of service group identifiers.
4. The method of claim 1, wherein generating the first timestamp through a lock process based on the reception time comprises:
acquiring a second task request, and recording a second moment;
locking the second task request to ensure the uniqueness of the second task request at the moment when the tasks are sent concurrently;
acquiring a first moment, wherein the first moment corresponds to a first task request, and the first task request comprises a last task request of the second task request;
judging whether the second moment is greater than the first moment; and
and adopting the second time as the first timestamp when the second time is greater than the first time.
5. The method of claim 4, further comprising:
adding a fixed preset value to the value of the first moment to obtain a third moment under the condition that the second moment is not greater than the first moment; and
and adopting the third time as the first time stamp.
6. The method of claim 1, wherein the first timestamp comprises millisecond information.
7. The method of claim 2, wherein the second timestamp comprises year, month, day, hour, minute, second level information.
8. An apparatus of global sequence number generation, the apparatus comprising: a task receiving module, a related sequence code generating module, a first time stamp generating module and a global sequence number generating module,
wherein the content of the first and second substances,
the task receiving module is used for receiving the task request and recording the receiving time;
the relevant sequence code generating module is used for acquiring a relevant sequence code based on the task request and the receiving time;
the first timestamp generation module is configured to generate a first timestamp through locking processing based on the receiving time; and
the global sequence number generation module is configured to generate the global sequence number based on the correlation sequence code and the first timestamp.
9. The apparatus of claim 8, wherein the correlation sequence code generating module comprises: a server identification generation module, a second time stamp generation module, a random code generation module and a related sequence code sorting module,
wherein the content of the first and second substances,
the server identifier generating module is used for acquiring a server identifier based on the task request, wherein the server identifier comprises an address identifier;
the second timestamp generating module is configured to generate a second timestamp based on the receiving time, where a unit of a lowest bit of the second timestamp is greater than a unit of a highest bit of the first timestamp;
the random code generating module is used for generating a random code; and
the related sequence code sorting module is configured to generate the related sequence code by sorting based on the server identifier, the second timestamp, and the random code.
10. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-7.
11. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method of any one of claims 1 to 7.
12. A computer program product comprising a computer program which, when executed by a processor, implements a method according to any one of claims 1 to 7.
CN202111520425.1A 2021-12-13 2021-12-13 Global serial number generation method, device, equipment, medium and product Pending CN114168607A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111520425.1A CN114168607A (en) 2021-12-13 2021-12-13 Global serial number generation method, device, equipment, medium and product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111520425.1A CN114168607A (en) 2021-12-13 2021-12-13 Global serial number generation method, device, equipment, medium and product

Publications (1)

Publication Number Publication Date
CN114168607A true CN114168607A (en) 2022-03-11

Family

ID=80486347

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111520425.1A Pending CN114168607A (en) 2021-12-13 2021-12-13 Global serial number generation method, device, equipment, medium and product

Country Status (1)

Country Link
CN (1) CN114168607A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116366609A (en) * 2023-06-02 2023-06-30 天津金城银行股份有限公司 Global unique identification generation method, system, computer and readable storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116366609A (en) * 2023-06-02 2023-06-30 天津金城银行股份有限公司 Global unique identification generation method, system, computer and readable storage medium
CN116366609B (en) * 2023-06-02 2023-09-01 天津金城银行股份有限公司 Global unique identification generation method, system, computer and readable storage medium

Similar Documents

Publication Publication Date Title
CN105787077B (en) Data synchronization method and device
US20070016893A1 (en) Tracking resource usage by applications
US10698962B2 (en) Analysis of data utilization
CN111913738A (en) Access request processing method, device, computing equipment and medium
CN110580305A (en) Method, apparatus, system, and medium for generating identifier
CN115357761A (en) Link tracking method and device, electronic equipment and storage medium
CN113505302A (en) Method, device and system for supporting dynamic acquisition of buried point data and electronic equipment
CN111625422B (en) Thread monitoring method, thread monitoring device, electronic equipment and computer readable storage medium
CN113238843A (en) Task execution method, device, equipment and storage medium
CN114153703A (en) Micro-service exception positioning method and device, electronic equipment and program product
CN114168607A (en) Global serial number generation method, device, equipment, medium and product
CN113132400A (en) Business processing method, device, computer system and storage medium
CN112948138A (en) Method and device for processing message
CN112818204B (en) Service processing method, device, equipment and storage medium
CN113111078B (en) Resource data processing method and device, computer equipment and storage medium
CN111124627A (en) Method, device, terminal and storage medium for determining application program caller
CN112506781B (en) Test monitoring method, device, electronic equipment, storage medium and program product
CN113918525A (en) Data exchange scheduling method, system, electronic device, medium, and program product
CN114780361A (en) Log generation method, device, computer system and readable storage medium
CN114201508A (en) Data processing method, data processing apparatus, electronic device, and storage medium
CN114461909A (en) Information processing method, information processing apparatus, electronic device, and storage medium
CN112597224A (en) Data export method, data export device, electronic equipment and medium
CN112988806A (en) Data processing method and device
CN115484149B (en) Network switching method, network switching device, electronic equipment and storage medium
CN113347250B (en) Data access method, data access device, electronic equipment and readable storage medium

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