CN112948399B - Serial number generation method and device, computer equipment and storage medium - Google Patents

Serial number generation method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN112948399B
CN112948399B CN202110531636.9A CN202110531636A CN112948399B CN 112948399 B CN112948399 B CN 112948399B CN 202110531636 A CN202110531636 A CN 202110531636A CN 112948399 B CN112948399 B CN 112948399B
Authority
CN
China
Prior art keywords
serial number
database
identifier
cache
serial
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
CN202110531636.9A
Other languages
Chinese (zh)
Other versions
CN112948399A (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.)
Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch
Original Assignee
Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch
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 Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch filed Critical Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch
Priority to CN202110531636.9A priority Critical patent/CN112948399B/en
Publication of CN112948399A publication Critical patent/CN112948399A/en
Application granted granted Critical
Publication of CN112948399B publication Critical patent/CN112948399B/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
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • 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
    • 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/2455Query execution
    • G06F16/24552Database cache management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a serial number generation method, a serial number generation device, computer equipment and a storage medium. The method comprises the following steps: acquiring a serial number identifier to be generated; inquiring a corresponding serial number from a database according to the serial number identifier; and updating the serial number information in the cache according to the acquired serial number. The method can improve the reliability.

Description

Serial number generation method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of Java programming, and in particular, to a method and an apparatus for generating a serial number, a computer device, and a storage medium.
Background
With the development of distributed technology, micro service technology and cloud technology, the application scenes of the MySQL database are increasing day by day. However, the MySQL database does not realize the serial number function, and the serial number function realized only through the storage process cannot well meet the requirement of high concurrent flow. If the snowflake algorithm and the UUID are used, some functions with sequence requirements on numbers cannot be realized.
In addition, at present, only the pure java program is used for realizing the serial number, and the serial number is actually processed by a single program in an operation mode, so that the data reliability is very poor and the monitoring is difficult.
Disclosure of Invention
In view of the above, it is desirable to provide a serial number generation method, apparatus, computer device, and storage medium capable of improving reliability in response to the above technical problem.
A method of sequence number generation, the method comprising:
acquiring a serial number identifier to be generated;
inquiring a corresponding serial number from a database according to the serial number identifier;
and updating the serial number information in the cache according to the acquired serial number.
In one embodiment, the querying the corresponding serial number from the database according to the serial number identifier includes:
and inquiring a first number of serial numbers from a database according to the serial number identification, wherein the first number is configured through the database.
In one embodiment, after obtaining the serial number identifier to be generated, the method further includes:
judging whether serial number information corresponding to the serial number identifier to be generated exists in a cache or not;
if not, continuously inquiring a corresponding serial number from a database according to the serial number identifier;
if the serial number information exists, a serial number updating step length is obtained, and the serial number information in the cache is updated according to the serial number updating step length.
In one embodiment, after the updating the sequence number information in the cache according to the sequence number update step size, the method further includes:
judging whether the updated serial number information is larger than a maximum cache value, wherein the maximum cache value is generated according to the first quantity;
and when the updated serial number information is larger than the maximum cache value, continuing to query a corresponding serial number from a database according to the serial number identifier.
In one embodiment, the database supports multiple programs to operate on the serial numbers in the database simultaneously; the querying of the corresponding serial number from the database according to the serial number identifier includes:
and inquiring a corresponding serial number from a database according to the serial number identification in an optimistic lock and retry mode.
In one embodiment, after querying the corresponding serial number from the database according to the serial number identifier through an optimistic lock and a retry, the method further includes:
and when the retry times are more than or equal to a threshold value, modifying the optimistic lock into a pessimistic lock, and inquiring a corresponding serial number from a database according to the serial number identifier in a pessimistic lock mode.
An apparatus for serial number generation, the apparatus comprising:
the identification acquisition module is used for acquiring a serial number identification to be generated;
the query module is used for querying a corresponding serial number from a database according to the serial number identifier;
and the updating module is used for updating the serial number information in the cache according to the acquired serial number.
In one embodiment, the query module is further configured to query a database for a first number of serial numbers according to the serial number identification, where the first number is configured through the database.
A computer device comprising a memory storing a computer program and a processor implementing the steps of the method in any of the embodiments described above when the computer program is executed.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any of the above embodiments.
According to the serial number generation method, the serial number generation device, the computer equipment and the storage medium, the serial number is stored through the database, and when the program needs to use the serial number, the serial number is read from the database, so that the reliability of the serial number is guaranteed, the database can be monitored at any time due to the fact that the serial number exists in the database, the monitoring of the serial number is facilitated, and the reliability of the serial number is further improved.
Drawings
FIG. 1 is a diagram of an application environment of a method for generating a sequence number in one embodiment;
FIG. 2 is a flow diagram illustrating a method for sequence number generation in one embodiment;
FIG. 3 is a flow chart illustrating a method for generating sequence numbers in another embodiment;
FIG. 4 is a memory structure diagram of a cache ConcurrentHashMap in one embodiment;
FIG. 5 is a block diagram showing the structure of a serial number generation apparatus according to an embodiment;
FIG. 6 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The serial number generation method provided by the application can be applied to the application environment shown in fig. 1. The terminal 102 communicates with the database 104 through a network, wherein a JAVA program may be installed in the terminal 102, so that a serial number generation function is realized by matching the JAVA program with the database, that is, the terminal 102 acquires a serial number identifier to be generated, then queries a corresponding serial number from the database according to the serial number identifier, and updates serial number information in the cache according to the acquired serial number. Therefore, when the program needs to use the serial number, the serial number is read from the database, so that the reliability of the serial number is ensured, and the database can be monitored at any time due to the fact that the serial number exists in the database, so that the monitoring of the serial number is facilitated, and the reliability of the serial number is further improved. The terminal 102 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices, and the database 104 may be implemented by an independent database or a database cluster composed of a plurality of databases.
In an embodiment, as shown in fig. 2, a serial number generation method is provided, which is described by taking the application of the method to the terminal in fig. 1 as an example, and includes the following steps:
s202: and acquiring a serial number identifier to be generated.
Specifically, the serial number identifier may be used to label a serial number usage scenario, which may be only a name of the serial number usage scenario, and the serial number identifier serves as an index condition for searching the serial number.
S204: and inquiring the corresponding serial number from the database according to the serial number identification.
Specifically, the database may store serial numbers of a plurality of usage scenarios, and the serial number of each usage scenario may be stored in a different data table, or stored in the same data table, where configuration information of the serial number is set in the data table. The user can dynamically configure the serial number by processing the data table in the database. Therefore, the database table is used for unified management, real-time monitoring and real-time adjustment can be supported, and a user only needs to execute the database initialization script and introduce the Jar package to have the serial number function.
Wherein the configuration information of each sequence number may include a sequence number identifier, a buffer value, a sequence number current value, and a step size. Wherein, the serial number identification is used as an index condition; the cached value, i.e., the number of serial numbers that the Java program will reserve at a time, is not reserved again from the database until the Java program runs out of serial numbers. Generally, the value of the default configuration cache is 200, which can deal with most application scenarios, on one hand: performance can be guaranteed; on the other hand: the Java program stops causing the number of predetermined values to be lost is small. The current value of the sequence number, i.e. the field is updated each time the Java program predetermines a sequence number from the database. Here, the method of predetermining the sequence number is to update the current value of the database to "current value of the sequence number + configured buffer value", and use the original current value (before updating) as the initial value of the predetermined sequence number, and subtract 1 from the new current value (after updating) as the upper limit value of the predetermined sequence number. Step size, i.e. the length of the increase or decrease of the sequence number, for example: if the value is set to 2 and the initial value of the sequence number is 0, then the calculated sequence number is 2, 4, 6, 8, 10 … …
In the embodiment, the serial numbers are managed by the database in a unified manner, and can be adjusted and monitored at any time, that is, all serial number configurations of the current database can be inquired and visually displayed only by a select sql script; the adjustment can be realized through the update sql script, which is very simple and does not influence the running of the Java program. If only the pure Java program manages the serial number, it is very difficult to monitor and adjust, for example, to monitor information in the Java memory, there are 2 general approaches: the log is used for monitoring, the flexibility is poor, and the information printed by the program can be searched from the log file only in a passive mode. The operation of viewing jvm memory information is very cumbersome, jvm commands need to be well recognized, and the feedback information needs to be understood by a deep Java programming background. And if the java program is adjusted, the java program generally manages the configuration information through the configuration file, the adjustment of the configuration file needs to restart the program to be effective, and the restart can make the program suspend providing the service to the outside.
In addition, the serial number is stored through the database, so that a plurality of Java programs can be supported to operate simultaneously, and the database is highly available. On the contrary, the storage and calculation of the serial number are realized by completely losing the Java program, the stress is concentrated, the transverse expansion capability is not available, and the usability is low.
Finally, the serial number is stored in a database and is very reliable. On the contrary, storing the serial number information in the Java memory is very unsafe, and there are many situations that may cause data loss or errors, such as: the Java program stops unexpectedly.
S206: and updating the serial number information in the cache according to the acquired serial number.
Specifically, after acquiring the serial number from the database, the terminal may update the serial number according to the acquired serial number. Therefore, the serial number function is realized by combining the database with the Java program, the database is responsible for storing information, the Java program is responsible for logic calculation, and the Java program is easily transversely expanded relative to the database.
According to the serial number generation method, the serial number is stored through the database, and when the program needs to use the serial number, the serial number is read from the database, so that the reliability of the serial number is guaranteed, the database can be monitored at any time due to the fact that the serial number exists in the database, the monitoring of the serial number is facilitated, and the reliability of the serial number is further improved.
In one embodiment, querying the database for a corresponding serial number according to the serial number identifier includes: a first number of serial numbers are queried from a database based on the serial number identification, the first number being configured through the database.
Specifically, the first number is at least 2, and the first number may be configured by the database, that is, the cache value described above, so that each time the terminal acquires a batch of serial number values from the database and processes the serial number values in the memory, the number of times of interaction between the Java program and the database may be reduced, each time the Java program reserves a batch of values to process in the memory, and a batch of values may be reserved from the database again until the reserved values are used up. In addition, the calculation of the sequence number and the multithread safety control are all shared by the Java program to be completed, so that the database does not bear the calculation pressure. Finally, the buffered values can be configured according to the throughput of the system and can be adjusted as needed at any time. For example: the system will generate 500 transactions per second on average, and the buffered value is set to (500/application number). Namely, the database can acquire the system parameters of the terminal in real time, and then dynamically adjust the cache value according to the system parameters of the terminal, so as to ensure that the efficiency of the whole system is improved.
Specifically, the time for the terminal to obtain the serial number from the database includes two times: one is during initialization, namely the serial number is not acquired from the database, and the serial number is acquired from the database for the first time; the other is that the serial number has already been acquired from the database, but the currently acquired serial number has been used up, and the serial number needs to be acquired from the database again.
In one embodiment, after obtaining the serial number identifier to be generated, the method further includes: judging whether serial number information corresponding to the serial number identifier to be generated exists in the cache; if not, continuously inquiring the corresponding serial number from the database according to the serial number identifier; and if so, acquiring a serial number updating step size, and updating the serial number information in the cache according to the serial number updating step size.
In this embodiment, the serial number is obtained from the database for the first time when initialization is performed, that is, the serial number is not obtained from the database yet, after the Java program in the terminal obtains the serial number identifier, it is determined whether serial number information exists in the cache, if not, a corresponding serial number is queried from the database according to the serial number identifier, and if so, the serial number is directly updated according to the serial number update step size obtained from the database and the value of the current serial number.
In one embodiment, after updating the step size according to the sequence number and updating the sequence number information in the cache, the method further includes: judging whether the updated serial number information is larger than a maximum cache value, wherein the maximum cache value is generated according to the first quantity; and when the updated serial number information is larger than the maximum cache value, continuing to query the corresponding serial number from the database according to the serial number identifier.
In this embodiment, the serial number is already obtained from the database, but the currently obtained serial number is used up, and the serial number needs to be obtained from the database again, that is, a batch of serial numbers are obtained from the database each time, so that the batch of serial numbers are used, and each time the batch of serial numbers are used, whether the obtained serial numbers are used up is determined, and if yes, a new serial number is obtained from the database again.
In one embodiment, the database supports multiple programs to operate on the serial numbers in the database simultaneously; inquiring a corresponding serial number from a database according to the serial number identifier, wherein the method comprises the following steps: and inquiring a corresponding serial number from the database according to the serial number identification in an optimistic lock and retry mode.
In this embodiment, the serial number information is stored in the database, and can support simultaneous operation of multiple Java programs, which is highly available. In addition, in order to avoid the situation that a plurality of threads update the same piece of data at the same time and the data is confused, in this embodiment, data security is ensured by adding an optimistic lock and retrying.
The logical lock implemented using the Java program in this embodiment (optimistic lock + retry), i.e. the on-band condition when updating the database records, is: the method includes the steps of querying a database (select current _ value, step, cache from sequence number where name = 'seq _ default';) to obtain a result (current _ value =35, step =1, cache = 5), updating a database statement to (update sequence number set current _ value = 40 where name = 'seq _ default' and current _ value = 35), if other threads modify data, the current value is not 35, so that the current thread modification fails, and therefore it is ensured that the current thread is fed back by the failure of modification after the data is modified by other threads, the data is not updated in a covering manner due to concurrent operation, and the retry operation can be completed only by matching with a retry mechanism. The Java program locks the data of the database, and the database does not queue collision operations, so that the pressure of the database is reduced to a certain extent.
In one embodiment, after querying the corresponding serial number from the database according to the serial number identifier by an optimistic lock and retry, the method further includes: and when the retry number is greater than or equal to the threshold value, modifying the optimistic lock into a pessimistic lock, and inquiring a corresponding serial number from the database according to the serial number identifier in a pessimistic lock mode.
In particular, the situation that multiple threads operate on the same piece of data at the same time frequently occurs, and then excessive retries are caused, so that the performance advantage of the Java logical lock is lost. A set of coping mechanisms are designed for the above embodiments that may occur: the lock inflation mechanism, the Java program will monitor the number of retries, and when the number of retries reaches the configured threshold value within a short time (the default threshold value is 3), the lock will be upgraded to a pessimistic lock (for update statement of the database), and the database autonomously controls the lock.
In addition, if there is no special requirement for the sequence number (e.g., strictly disallowing the skip number), when the simultaneous operation of multiple threads on the same data frequently occurs, the cache value configured in the database should be adjusted to improve the performance of the program.
Specifically, referring to fig. 3, fig. 3 is a schematic diagram of a serial number generation method in another embodiment, where in this embodiment, the serial number generation method may include:
firstly, the terminal searches whether the corresponding serial number information exists in the Java cache according to the name of the serial number.
Specifically, the information of the sequence number is cached in the Java memory in a ConcurrentHashMap data structure. The ConcurrentHashMap is a key-value type structure which is convenient to retrieve and supports multi-thread operation. The key of the ConcurrentHashMap stores the name of the serial number, the value stores the Cache object, and the Cache object has 4 attributes: the sequence number CurrentValue is the current value of the sequence number in the Java program, and the Java program mainly performs accumulation calculation on the value to obtain the desired sequence value. This field uses the AtomicLong type of Java to meet the needs of multi-threaded data security. cache: the Java program caches the number of sequence number values. Corresponding to the cache value field in the database table. cacheMaxValue: and when the current value of the serial number obtained by accumulation of the Java program reaches the value, the number of cache values, namely the serial number values of the first number, needs to be preset again from the database and stored in the cache, and the upper limit of the cache value is reset to be equal to the maximum value in the serial number values preset from the database at this time. step stores step, which represents the accumulated value of accumulated calculation of current value of sequence number each time, and corresponds to step field in database table. Referring to fig. 4, fig. 4 is a diagram illustrating a storage structure of a cache ConcurrentHashMap in an embodiment.
Secondly, if the cache is not initialized, or the sequence value calculated by the Java program reaches the upper limit of the cache value, a batch of sequence number values need to be preset from the database and stored in the Java cache.
Specifically, the terminal queries the database sequence number table with the name of the sequence number to obtain the corresponding sequence number configuration, including the current value current _ value, the step size of the accumulation calculation, and the cache number. The terminal queries the current value of the sequence number in the database and updates (current _ value = step cache + current _ value). This operation needs to be done with locking to ensure the accuracy of the data. After the database update is completed, the Java cache ConcurrentHashMap needs to be updated. And the value of the ConcurrentHashMap is a cache object cache, and the cache current value serial number CurrentValue and the cache maximum value cacheMaxValue in the cache object are updated. Caching the current value serial number, CurrentValue, to be equal to the current _ value of the queried database; the cache maximum cacheMaxValue is equal to the updated current _ value-1.
Thirdly, the value of the sequence number is obtained from the Java cache.
Specifically, the first case: the cache is not yet initialized, at which time the Java program needs to reserve a batch of serial number values from the database and cache them in the ConcurrentHashMap in memory. In the second case: if the cache object cache of the serial number is found from the ConcurrentHashMap in the Java memory, calculating a current value serial number CurrentValue in the cache object cache = serial number CurrentValue + step, and then judging whether the calculated value is greater than an upper limit cacheMaxValue of the cache value. If not, returning the current value serial number CurrentValue of the serial number, which is the expected sequence value. If the number is larger than the preset value, the serial number of the Java cache is used up, the serial number needs to be obtained from the database again and cached in the Java memory, and then the steps are repeated.
The serial number generation method shares the calculation pressure of the database to the Java program in a mode of configuring serial number cache, and supports horizontal extension. The program has the characteristics of high efficiency, high performance and high availability, and can meet the requirement of high concurrent flow. Generation of ordered numbers is supported. The same numbering sequence can be used for a plurality of tables, and the requirement of separate banks and tables is met. The serial number information is stored in a database table, and the method is safe and reliable. Can monitor and adjust the serial number configuration at any time and flexibly cope with various conditions
It should be understood that although the steps in the flowcharts of fig. 2 and 3 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2 and 3 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed in turn or alternately with other steps or at least some of the other steps.
In one embodiment, as shown in fig. 5, there is provided a serial number generation apparatus including: an identity acquisition module 100, a query module 200, and an update module 300, wherein:
an identifier obtaining module 100, configured to obtain a serial number identifier to be generated;
the query module 200 is configured to query a corresponding serial number from the database according to the serial number identifier;
and an updating module 300, configured to update the serial number information in the cache according to the obtained serial number.
In one embodiment, the query module 200 is further configured to query the database for a first number of serial numbers based on the serial number identification, the first number being configured by the database.
In one embodiment, the serial number generating apparatus further includes:
the first judgment module is used for judging whether the cache has serial number information corresponding to the serial number identifier to be generated;
the query module 200 is further configured to continue querying a corresponding serial number from the database according to the serial number identifier if the serial number does not exist;
the update module 300 is further configured to, if the serial number information exists, obtain a serial number update step size, and update the serial number information in the cache according to the serial number update step size.
In one embodiment, the serial number generating apparatus further includes:
the second judging module is used for judging whether the updated serial number information is larger than the maximum cache value, and the maximum cache value is generated according to the first quantity;
the query module 200 is further configured to continue querying a corresponding serial number from the database according to the serial number identifier when the updated serial number information is greater than the maximum cache value.
In one embodiment, the database supports multiple programs to operate on the serial numbers in the database simultaneously; the query module 200 is further configured to query the corresponding serial number from the database according to the serial number identifier in an optimistic lock and retry manner.
In one embodiment, the serial number generating apparatus further includes:
and the modifying module is used for modifying the optimistic lock into a pessimistic lock when the retry number is greater than or equal to the threshold value, and inquiring the corresponding serial number from the database according to the serial number identifier in a pessimistic lock mode.
For the specific limitations of the serial number generation apparatus, reference may be made to the limitations of the serial number generation method above, and details are not repeated here. The modules in the serial number generation device can be wholly or partially realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 6. The computer device includes a processor, a memory, a communication interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless communication can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a method of serial number generation. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 6 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory having a computer program stored therein, the processor implementing the following steps when executing the computer program: acquiring a serial number identifier to be generated; inquiring a corresponding serial number from a database according to the serial number identifier; and updating the serial number information in the cache according to the acquired serial number.
In one embodiment, the querying of the database for a corresponding serial number based on the serial number identification performed by the processor when executing the computer program comprises: a first number of serial numbers are queried from a database based on the serial number identification, the first number being configured through the database.
In one embodiment, after obtaining the serial number identifier to be generated, the processor, which is implemented when executing the computer program, further includes: judging whether serial number information corresponding to the serial number identifier to be generated exists in the cache; if not, continuously inquiring the corresponding serial number from the database according to the serial number identifier; and if so, acquiring a serial number updating step size, and updating the serial number information in the cache according to the serial number updating step size.
In one embodiment, after the updating the sequence number information in the cache according to the sequence number update step size, which is implemented when the processor executes the computer program, the method further includes: judging whether the updated serial number information is larger than a maximum cache value, wherein the maximum cache value is generated according to the first quantity; and when the updated serial number information is larger than the maximum cache value, continuing to query the corresponding serial number from the database according to the serial number identifier.
In one embodiment, a database involved in the execution of the computer program by the processor supports multiple programs operating on serial numbers in the database simultaneously; the query of the corresponding serial number from the database according to the serial number identification when the processor executes the computer program comprises: and inquiring a corresponding serial number from the database according to the serial number identification in an optimistic lock and retry mode.
In one embodiment, the manner of optimistic locking and retrying implemented by the processor when executing the computer program further comprises, after querying the corresponding serial number from the database according to the serial number identifier: and when the retry number is greater than or equal to the threshold value, modifying the optimistic lock into a pessimistic lock, and inquiring a corresponding serial number from the database according to the serial number identifier in a pessimistic lock mode.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of: acquiring a serial number identifier to be generated; inquiring a corresponding serial number from a database according to the serial number identifier; and updating the serial number information in the cache according to the acquired serial number.
In one embodiment, a computer program implemented when executed by a processor to query a database for a corresponding serial number based on a serial number identification includes: a first number of serial numbers are queried from a database based on the serial number identification, the first number being configured through the database.
In one embodiment, after obtaining the serial number identifier to be generated, the computer program, when executed by the processor, further includes: judging whether serial number information corresponding to the serial number identifier to be generated exists in the cache; if not, continuously inquiring the corresponding serial number from the database according to the serial number identifier; and if so, acquiring a serial number updating step size, and updating the serial number information in the cache according to the serial number updating step size.
In one embodiment, the computer program, when executed by the processor, further performs, after updating the sequence number information in the cache according to the sequence number update stride, the method further comprising: judging whether the updated serial number information is larger than a maximum cache value, wherein the maximum cache value is generated according to the first quantity; and when the updated serial number information is larger than the maximum cache value, continuing to query the corresponding serial number from the database according to the serial number identifier.
In one embodiment, the computer program, when executed by the processor, references a database that supports multiple programs operating on serial numbers in the database at the same time; the computer program, when executed by a processor, implements querying a database for a corresponding serial number according to the serial number identifier, including: and inquiring a corresponding serial number from the database according to the serial number identification in an optimistic lock and retry mode.
In one embodiment, the method for querying the database for the corresponding serial number according to the serial number identifier by the optimistic lock and retry when the computer program is executed by the processor further includes: and when the retry number is greater than or equal to the threshold value, modifying the optimistic lock into a pessimistic lock, and inquiring a corresponding serial number from the database according to the serial number identifier in a pessimistic lock mode.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical storage, or the like. Volatile Memory can include Random Access Memory (RAM) or external cache Memory. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A method for generating a sequence number, the method being performed by at least one Java program, the method comprising:
acquiring a serial number identifier to be generated;
judging whether serial number information corresponding to the serial number identifier to be generated exists in a cache or not;
if the serial number information corresponding to the serial number identifier to be generated exists, acquiring serial number information in a cache, acquiring a serial number updating step length, and updating the serial number information in the cache according to the serial number updating step length;
if no serial number information corresponding to the serial number identifier to be generated exists, inquiring a corresponding serial number from a database according to the serial number identifier;
updating the serial number information in the cache according to the acquired serial number;
the querying of the corresponding serial number from the database according to the serial number identifier includes:
and inquiring a first number of serial numbers from a database according to the serial number identification, wherein the first number is configured through the database.
2. The method of claim 1, wherein after updating the sequence number information in the buffer according to the sequence number update step size, further comprising:
judging whether the updated serial number information is larger than a maximum cache value, wherein the maximum cache value is generated according to the first quantity;
and when the updated serial number information is larger than the maximum cache value, continuing to query a corresponding serial number from a database according to the serial number identifier.
3. The method of claim 1, wherein the database supports multiple programs operating on serial numbers in the database simultaneously; the querying of the corresponding serial number from the database according to the serial number identifier includes:
and inquiring a corresponding serial number from a database according to the serial number identification in an optimistic lock and retry mode.
4. The method of claim 3, wherein after querying the corresponding serial number from the database according to the serial number identifier by means of optimistic lock and retry, the method further comprises:
and when the retry times are more than or equal to a threshold value, modifying the optimistic lock into a pessimistic lock, and inquiring a corresponding serial number from a database according to the serial number identifier in a pessimistic lock mode.
5. An apparatus for generating a serial number, the apparatus comprising:
the identification acquisition module is used for acquiring a serial number identification to be generated;
the first judging module is used for judging whether serial number information corresponding to the serial number identifier to be generated exists in the cache;
the query module is used for querying a corresponding serial number from a database according to the serial number identifier if serial number information corresponding to the serial number identifier to be generated does not exist;
the updating module is used for acquiring a serial number updating step length if serial number information corresponding to the serial number identifier to be generated exists, and updating the serial number information in the cache according to the serial number updating step length; updating the serial number information in the cache according to the acquired serial number;
the query module is further configured to query a first number of serial numbers from a database according to the serial number identifier, where the first number is configured through the database.
6. The apparatus of claim 5, further comprising:
the second judging module is used for judging whether the updated serial number information is larger than a maximum cache value, and the maximum cache value is generated according to the first quantity;
and the query module is further used for continuing to query the corresponding serial number from the database according to the serial number identifier when the updated serial number information is larger than the maximum cache value.
7. The apparatus of claim 5, wherein the database supports multiple programs operating on serial numbers in the database simultaneously; and the query module is also used for querying a corresponding serial number from a database according to the serial number identifier in an optimistic lock and retry mode.
8. The apparatus of claim 7, further comprising:
and the modifying module is used for modifying the optimistic lock into a pessimistic lock when the retry number is greater than or equal to a threshold value, and inquiring a corresponding serial number from a database according to the serial number identifier in a pessimistic lock mode.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any of claims 1 to 4.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 4.
CN202110531636.9A 2021-05-17 2021-05-17 Serial number generation method and device, computer equipment and storage medium Active CN112948399B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110531636.9A CN112948399B (en) 2021-05-17 2021-05-17 Serial number generation method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110531636.9A CN112948399B (en) 2021-05-17 2021-05-17 Serial number generation method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112948399A CN112948399A (en) 2021-06-11
CN112948399B true CN112948399B (en) 2021-08-03

Family

ID=76233881

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110531636.9A Active CN112948399B (en) 2021-05-17 2021-05-17 Serial number generation method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112948399B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115103024B (en) * 2022-06-21 2024-03-15 联仁健康医疗大数据科技股份有限公司 Sequence number generation method and device, electronic equipment and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103020268A (en) * 2012-12-26 2013-04-03 大唐软件技术股份有限公司 Serial number applying method and system of relational database
CN107644071A (en) * 2017-09-18 2018-01-30 广州爱九游信息技术有限公司 Buffering updating method, device and data-storage system
CN109597853A (en) * 2018-10-22 2019-04-09 平安科技(深圳)有限公司 Business scenario element sequence generation method, device, medium and computer equipment
US10474678B1 (en) * 2015-06-03 2019-11-12 Subject Packet Solutions, Llc Computer-based system for facilitating the execution of law enforcement duties
CN110515956A (en) * 2019-09-02 2019-11-29 中国工商银行股份有限公司 Sequence number acquisition methods, device, system, electronic equipment and storage medium
CN111400330A (en) * 2020-03-13 2020-07-10 深圳前海微众银行股份有限公司 Task processing method, device, equipment and computer readable storage medium
CN111414379A (en) * 2020-03-20 2020-07-14 深圳前海微众银行股份有限公司 Serial number generation method, device, equipment and computer readable storage medium
CN111625543A (en) * 2020-05-27 2020-09-04 贵州易鲸捷信息技术有限公司 HBase table-based method for realizing global monotonically increasing sequence

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103020268A (en) * 2012-12-26 2013-04-03 大唐软件技术股份有限公司 Serial number applying method and system of relational database
US10474678B1 (en) * 2015-06-03 2019-11-12 Subject Packet Solutions, Llc Computer-based system for facilitating the execution of law enforcement duties
CN107644071A (en) * 2017-09-18 2018-01-30 广州爱九游信息技术有限公司 Buffering updating method, device and data-storage system
CN109597853A (en) * 2018-10-22 2019-04-09 平安科技(深圳)有限公司 Business scenario element sequence generation method, device, medium and computer equipment
CN110515956A (en) * 2019-09-02 2019-11-29 中国工商银行股份有限公司 Sequence number acquisition methods, device, system, electronic equipment and storage medium
CN111400330A (en) * 2020-03-13 2020-07-10 深圳前海微众银行股份有限公司 Task processing method, device, equipment and computer readable storage medium
CN111414379A (en) * 2020-03-20 2020-07-14 深圳前海微众银行股份有限公司 Serial number generation method, device, equipment and computer readable storage medium
CN111625543A (en) * 2020-05-27 2020-09-04 贵州易鲸捷信息技术有限公司 HBase table-based method for realizing global monotonically increasing sequence

Also Published As

Publication number Publication date
CN112948399A (en) 2021-06-11

Similar Documents

Publication Publication Date Title
US9990132B2 (en) Off-heap direct-memory data stores, methods of creating and/or managing off-heap direct-memory data stores, and/or systems including off-heap direct-memory data store
EP3047381B1 (en) Dynamic sizing of memory caches
CN111078147B (en) Processing method, device and equipment for cache data and storage medium
CN109491928B (en) Cache control method, device, terminal and storage medium
US10860377B2 (en) Technologies for identifying thread memory allocation
US20160004455A1 (en) Method of controlling splitting of data, and system
US11663143B2 (en) Multi-state midtier dynamic cache replacement
CN110704463A (en) Local caching method and device for common data, computer equipment and storage medium
US11018860B2 (en) Highly available and reliable secret distribution infrastructure
JP6134390B2 (en) Dynamic firmware update
CN113220669B (en) Service data processing method and device and electronic equipment
CN112948399B (en) Serial number generation method and device, computer equipment and storage medium
CN111400578A (en) Goods data query method and device, computer equipment and storage medium
US11057488B2 (en) Multi-state midtier cache
US8341368B2 (en) Automatic reallocation of structured external storage structures
CN114911717A (en) Data caching method and device, electronic equipment and storage medium
US11146629B2 (en) Process transfer between servers
CN113986391A (en) Request processing method, device, medium and computing equipment
CN112783866A (en) Data reading method and device, computer equipment and storage medium
CN109388645B (en) Instruction execution method, instruction execution device, and storage medium
US11960721B2 (en) Dynamic storage in key value solid state drive
CN113742381A (en) Cache acquisition method, apparatus and computer readable medium
Kuhn et al. Memory Structures
CN113867975A (en) Quick response method and device for command line and computer equipment
CN116719551A (en) Hot deployment method, cloud service system, electronic equipment and 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
GR01 Patent grant
GR01 Patent grant