CN112256930A - Method, device and system for batch generation of identification codes for distributed services - Google Patents

Method, device and system for batch generation of identification codes for distributed services Download PDF

Info

Publication number
CN112256930A
CN112256930A CN202011073022.2A CN202011073022A CN112256930A CN 112256930 A CN112256930 A CN 112256930A CN 202011073022 A CN202011073022 A CN 202011073022A CN 112256930 A CN112256930 A CN 112256930A
Authority
CN
China
Prior art keywords
identification
identification code
distributed service
distributed
value
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
CN202011073022.2A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information 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 Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202011073022.2A priority Critical patent/CN112256930A/en
Publication of CN112256930A publication Critical patent/CN112256930A/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/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • G06F16/90348Query processing by searching ordered data, e.g. alpha-numerically ordered data
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

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

Abstract

The disclosure provides a method, a device and a system for generating identification codes in batch aiming at distributed services, and relates to the field of distributed services. The method comprises the following steps: receiving an identification code batch acquisition request sent by client equipment, inquiring whether the request exceeds a generation range of identification codes of distributed services corresponding to the identification from a storage system according to the identification of the distributed services in the identification code batch acquisition request and the number of the identification codes acquired by the request, and if not, generating a plurality of identification codes at one time according to a generation reference value of the identification codes returned by the storage system and the number of the identification codes acquired by the request and returning the identification codes to the client equipment, thereby improving the generation efficiency of a plurality of IDs.

Description

Method, device and system for batch generation of identification codes for distributed services
Technical Field
The present disclosure relates to the field of distributed services, and in particular, to a method, an apparatus, and a system for generating an identification code in batch for distributed services.
Background
In the related services of the computer, an identification code (ID) needs to be generated to identify data in the services. In some related art, database-augmented ID approaches are used to generate one ID at a time. If multiple IDs are needed, a single ID generation policy needs to be cycled multiple times to obtain multiple IDs.
Disclosure of Invention
The inventor finds that when a single ID generation strategy is circulated for multiple times to obtain multiple IDs, the generation efficiency of the multiple IDs is low.
According to the identification code batch acquisition request, whether the request exceeds the generation range of the identification code of the distributed service corresponding to the identification code is inquired from the storage system according to the identification of the distributed service in the identification code batch acquisition request and the quantity of the identification codes acquired by the request, if not, a plurality of identification codes are generated at one time according to the generation reference value of the identification code returned by the storage system and the quantity of the identification codes acquired by the request, and the generation efficiency of a plurality of IDs is improved. In addition, the distributed lock is used for carrying out update control on related data in the storage system, and the problem of data update conflict in a distributed service scene is solved. In addition, the cache system is matched with the database, related data are preferentially inquired and judged in the cache system, and the overall response efficiency of the storage system is improved.
Some embodiments of the present disclosure provide a method for generating an identification code in batch for a distributed service, including:
receiving an identification code batch acquisition request sent by client equipment, wherein the identification code batch acquisition request comprises identification of distributed services and the number of identification codes required to be acquired;
inquiring whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification or not from a storage system according to the identification of the distributed service and the number of the identification codes required to be acquired;
and under the condition that the query result shows that the generation range of the identification codes of the distributed services corresponding to the identifications is not exceeded, generating a plurality of identification codes according to the generation reference value of the identification codes returned by the storage system and the quantity of the identification codes required to be obtained, and returning the identification codes to the client equipment.
In some embodiments, the method further comprises:
acquiring a distributed lock under the condition that the query result shows that the query result exceeds the generation range of the identification code of the distributed service corresponding to the identification;
inquiring the maximum value and the step length of the identification code of the distributed service corresponding to the identification from a storage system according to the identification of the distributed service;
recalculating the maximum value of the identification code of the distributed service corresponding to the identification according to the maximum value and the step length of the identification code of the distributed service corresponding to the identification, and synchronizing the maximum value to a storage system;
releasing the distributed lock and then proceeding to the querying step and the identification code generating step of claim 1.
In some embodiments, querying a storage system whether the batch acquisition request for the identification code exceeds the generation range of the identification code identifying the corresponding distributed service includes:
and sending an inquiry request for judging whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification to a storage system, wherein the inquiry request carries the identification of the distributed service and the quantity of the identification code required to be acquired, so that the storage system judges whether the sum of the current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification code required to be acquired is greater than the maximum value of the identification code of the distributed service corresponding to the identification, if not, returning a generation reference value of the identification code, and if so, returning an indication value exceeding the generation range.
In some embodiments, the reference value for generating the identification code is the latest current value of the identification code of the distributed service corresponding to the identifier, which is determined according to the sum of the current value of the identification code of the distributed service corresponding to the identifier and the number of the identification codes requested to be obtained;
generating a plurality of identification codes, comprising:
adding 1 to the difference value between the latest current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification code acquired by the request to obtain a sum value, and using the sum value as a generation starting value of the identification code;
and circulating according to the number of the identification codes required to be acquired on the basis of the generation starting value of the identification codes, and increasing 1 by the numerical value of the identification code every time so as to generate one identification code.
In some embodiments, the storage system includes a caching system and a database;
the method further comprises the following steps:
after receiving an identification code batch acquisition request sent by client equipment, inquiring whether a distributed service identifier exists in a cache system;
and under the condition that the query result shows that the distributed service identification does not exist in the cache system, querying whether the distributed service identification exists in the database, receiving the query result whether the distributed service identification exists returned by the database and the maximum value of the identification code of the distributed service corresponding to the identification under the existence condition, acquiring the distributed lock, setting the current value of the identification code of the distributed service corresponding to the identification in the cache system to be 0, setting the maximum value of the identification code of the distributed service corresponding to the identification in the cache system to be the maximum value of the identification code of the distributed service corresponding to the identification returned by the database, and releasing the distributed lock.
In some embodiments, querying a storage system whether the batch acquisition request for the identification code exceeds the generation range of the identification code identifying the corresponding distributed service includes:
and under the condition that the query result shows that the distributed service identification exists in the cache system, or after the distributed lock is released, sending a query request to the cache system, wherein the query request is used for judging whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification, the query request carries the identification of the distributed service and the quantity of the identification codes acquired by the request, so that the cache system judges whether the sum of the current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification codes acquired by the request is greater than the maximum value of the identification code of the distributed service corresponding to the identification, if not, returning a generation reference value of the identification code, and if so, returning an indication value exceeding the generation range.
In some embodiments, the storage system includes a caching system and a database;
according to the distributed service identification, inquiring the maximum value and the step length of the identification code of the distributed service corresponding to the identification from a database; and synchronizing the maximum value of the identification code of the distributed service corresponding to the identification, which is obtained by recalculating the maximum value and the step length of the identification code of the distributed service corresponding to the identification, to a cache system and a database.
In some embodiments, recalculating the maximum value of the identification codes identifying the respective distributed services comprises:
and taking the sum of the maximum value and the step length of the identification code of the distributed service corresponding to the identification as the maximum value of the identification code of the distributed service corresponding to the identification, which is obtained by recalculation.
In some embodiments, the method further comprises: the client device respectively identifies the data in the distributed service by using the plurality of identification codes and migrates the identified data.
Some embodiments of the present disclosure provide an apparatus for generating an identification code in batch for distributed services, including:
a memory; and
a processor coupled to the memory, the processor configured to perform a method of generating an identification code for a distributed service batch based on instructions stored in the memory.
Some embodiments of the present disclosure provide a system for generating an identification code in batch for distributed services, including:
means for generating identification codes in batches for distributed services; and
and the storage system is configured to store the relevant data of the generation range of the identification codes of the distributed services and judge whether the batch acquisition request of the identification codes exceeds the generation range of the identification codes of the distributed services.
In some embodiments, a storage system comprises:
the cache system is configured to store the identification of the distributed service and the current value and the maximum value of the identification code of the distributed service, judge whether the sum of the current value of the identification code of the distributed service and the number of the identification codes acquired by the request is greater than the maximum value of the identification code of the distributed service, and respond to the corresponding query request; and
and the database is configured to store the distributed service identification and the maximum value and the step length of the identification code of the distributed service, and responds to the corresponding query request.
Some embodiments of the present disclosure propose a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of a method of bulk generation of identification codes for distributed services.
Drawings
The drawings that will be used in the description of the embodiments or the related art will be briefly described below. The present disclosure can be understood more clearly from the following detailed description, which proceeds with reference to the accompanying drawings.
It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without undue inventive faculty.
Fig. 1 is a schematic diagram of a system for batch generation of identification codes for distributed services in some embodiments of the present disclosure.
Fig. 2 illustrates a flow diagram of a method for batch generation of identification codes for distributed services according to some embodiments of the present disclosure.
Fig. 3 is a flowchart illustrating a method for batch generation of an identification code for distributed services according to further embodiments of the present disclosure.
Fig. 4 is a flowchart illustrating a method for batch generation of an identification code for distributed services according to further embodiments of the present disclosure.
Fig. 5 is a schematic structural diagram of an apparatus for batch generation of an identification code for distributed services according to some embodiments of the present disclosure.
Detailed Description
The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure.
Fig. 1 is a schematic diagram of a system for batch generation of identification codes for distributed services in some embodiments of the present disclosure.
As shown in fig. 1, a system 100 for batch generation of identification codes for distributed services includes: an apparatus 110 for batch generating identification codes for distributed services (referred to as a batch generating identification code apparatus 110 for short) and a storage system 120. The storage system 120 includes: one or more of a cache system 121 and a database 122. The cache system 121 is, for example, a Remote Dictionary service (Redis) cache system, but is not limited to the illustrated example. The database 122 is, for example, a mysql database, but is not limited to the illustrated example. The apparatus for generating identification codes in batches 110 provides a service of generating identification codes in batches for distributed services for each client device 130 based on data stored in the storage system 120. The client device 130 identifies data in the distributed service by using the plurality of identifiers, and performs processing such as migration on the identified data, for example, migrating the identified data to a storage device.
Fig. 2 illustrates a flow diagram of a method for batch generation of identification codes for distributed services according to some embodiments of the present disclosure.
As shown in fig. 2, the method of this embodiment includes:
in step S210, the apparatus for generating an identification code in batch 110 receives an identification code batch acquisition request sent by the client device, where the identification (biz _ tag) of the distributed service and the number (amount) of identification codes requested to be acquired are included.
Wherein the identity of the distributed service (biz _ tag) is used to identify the different distributed services. When the client device requests to acquire the identification code, the client device needs to indicate which distributed service identification code is requested to be acquired.
In step S220, the apparatus 110 for generating an identification code in batch queries, according to the identifier (biz _ tag) of the distributed service and the number (amount) of identification codes requested to be obtained, whether the request for acquiring the identification code in batch exceeds the generation range of the identification code of the distributed service corresponding to the identifier from the storage system 120.
The device 110 for generating identification codes in batches sends an inquiry request to the storage system 120, wherein the inquiry request indicates whether the request for acquiring identification codes in batches exceeds the generation range of the identification codes of the distributed services corresponding to the identification codes, and the inquiry request carries the identification (biz _ tag) of the distributed services and the number (amount) of the identification codes requested to be acquired; the storage system 120 determines whether the sum of the current value (current _ value) of the identification code identifying the corresponding distributed service and the number (amount) of the identification codes requested to be obtained is greater than the maximum value (max _ value) of the identification code identifying the corresponding distributed service, returns the generation reference value of the identification code if the sum is not greater than the maximum value (max _ value), i.e., if the sum is not greater than the generation range, i.e., if the sum is greater than the generation range, returns the indication value exceeding the generation range.
The reference value for generating the identification code is, for example: the latest current value of the identifier of the distributed service corresponding to the identifier, which is determined according to the sum of the current value of the identifier of the distributed service corresponding to the identifier and the number of the identifiers requested to be obtained, is represented as current _ value ═ current _ value + amount, where current _ value on the right side represents the latest current value (the generated reference value), and current _ value on the left side represents the original current value. The indication value outside the generation range is, for example, 0.
In step S230, when the query result indicates that the generation range of the identification code identifying the corresponding distributed service is not exceeded, the apparatus 110 for generating identification codes in batch generates a plurality of identification codes according to the generation reference value of the identification code returned by the storage system and the number (amount) of the identification codes requested to be obtained, and returns the generated identification codes to the client device.
In some embodiments, generating the plurality of identification codes comprises: adding a sum value (current _ value-amount +1) obtained by adding 1 to a difference value between the latest current value (current _ value) of the identification code for identifying the corresponding distributed service and the number (amount) of the identification codes acquired by the request, and taking the sum value as a generation starting value of the identification code; and circulating according to the number of the identification codes required to be acquired on the basis of the generation initial value of the identification codes, increasing 1 to the numerical value of the identification code in each circulation to generate one identification code, and circulating for multiple times to obtain multiple identification codes.
In step S240, in the case that the query result indicates that the generation range of the identification code identifying the corresponding distributed service is exceeded, the apparatus 110 for generating identification codes in batches acquires a distributed lock to obtain the right to update the related data in the storage system 120; inquiring the maximum value (max _ value) and the step length (step) of the identification code for identifying the corresponding distributed service from the storage system 120 according to the identification (biz _ tag) of the distributed service; according to the maximum value (max _ value) and the step length (step) of the identification code for identifying the corresponding distributed service, recalculating the maximum value (max _ value) of the identification code for identifying the corresponding distributed service, and synchronizing to the storage system 120; the distributed lock is released, the authority to update the related data in the storage system 120 is handed over, and then the step S220 and the subsequent steps are continuously executed.
Wherein, recalculating the maximum value of the identification code identifying the corresponding distributed service is represented as: max _ value + step, where current _ value on the right side represents the latest maximum value recalculated, and current _ value on the left side represents the original maximum value.
And inquiring whether the request exceeds the generation range of the identification codes of the distributed services corresponding to the identification from the storage system according to the identification of the distributed services in the batch acquisition request of the identification codes and the quantity of the identification codes acquired by the request, and if not, generating a plurality of identification codes at one time according to the generation reference value of the identification codes returned by the storage system and the quantity of the identification codes acquired by the request, thereby improving the generation efficiency of a plurality of IDs. And the distributed lock is used for carrying out update control on related data in the storage system, so that the problem of data update conflict in a distributed service scene is solved.
The method for generating the identification code for the distributed service batch is described in conjunction with fig. 3-4, respectively, according to different deployments of the storage system 120.
In case the storage system 120 comprises a cache system 121 and a database 122, the method of generating identification codes for distributed service batches is described in connection with fig. 3.
And a database 122 configured to store the identification biz _ tag of the distributed service and store the maximum value max _ value and step size of the identification code of the distributed service, and to respond to the corresponding query request.
An exemplary Mysql database table is designed as follows:
column name Type (B) Whether or not it is empty Description of the invention
biz_tag varchar(24) N Service identification, unique
max_value bigint(20) N Maximum value of identification code
step bigint(20) N Stride of cache system
desc varchar(500) Y Description of the invention
created datetime N Date of creation
modified datetime N Modifying the date
The cache system 121 is configured to store the identifier of the distributed service and the current value and the maximum value of the identifier of the distributed service, determine whether the sum of the current value of the identifier of the distributed service and the number of identifiers acquired by the request is greater than the maximum value of the identifier of the distributed service, and respond to a corresponding query request, and the like.
An exemplary Redis cache system (Redis for short) is designed as follows:
biz _ tag key
Value { "current _ value", "max _ value" }
Namely, a Redis cache system is constructed by taking the service identifier biz _ tag as a key and taking the current value current _ value and the maximum value max _ value of the identification code as values, and the maximum value max _ value of the cache system is consistent with the maximum value max _ value in the database.
Fig. 3 is a flowchart illustrating a method for batch generation of an identification code for distributed services according to further embodiments of the present disclosure.
As shown in fig. 3, the method of this embodiment includes: steps S31-S314.
Step S31: the client device 130 sends an identification code batch acquisition request, which includes the identification of the distributed service and the number of identification codes requested to be acquired; the apparatus 110 for generating the identification codes in batch queries whether the cache system 121 stores the relevant service identifier, that is, whether there is a biz _ tag in the key stored in the cache system 121, according to the service identifier (biz _ tag) transmitted by the client device 130 and the number (amount) of the identification codes acquired by the request.
Step S32: the caching system 121 returns the query result if it exists.
Step S33: the device 110 for generating the identification code in batch determines whether the cache system 121 has the service identifier biz _ tag transmitted by the client device according to the query result returned by the cache system 121, and if the service identifier biz _ tag does not exist, the step S34 is executed, and if the service identifier biz _ tag exists, the step S35 is executed.
Step S34: the apparatus 110 for generating identification codes in batches queries whether the database 122 stores the relevant service identifier according to the incoming service identifier (biz _ tag), and the database 122 returns a result, which includes: the result of the query is present or not, and, if present, the maximum value max _ value of the identification code of the distributed service corresponding to the identity biz _ tag (i.e., the maximum value of the identification code sequence).
Step S34.1: the device 110 for generating identification codes in batches determines whether the service identifier exists in the database 122 according to the query result returned by the database 122. If so, step S34.2 is entered, and if not, an error message is returned directly to the client device 130.
Step S34.2: the means 110 for batch generation of identification codes obtains the maximum value max _ value of the identification code sequence from the returned result.
Step S34.3: the apparatus 110 for generating identification codes in batches acquires distributed locks, and only when the distributed locks are acquired, the values associated with the identification code sequences can be initialized in the cache system 121.
Step S34.4: the apparatus 110 for batch generation of identification codes initializes the value of the identification code sequence in the cache system 121: current _ value is 0 and max _ value is max _ value (i.e., max _ value in the cache system 121 is initialized to max _ value returned by the database 122)
Step S34.5, after the device 110 for generating identification codes in batches releases the distributed lock, the process proceeds to step S35.
Step S35: the cache system 121 determines, according to the incoming biz _ tag, whether current _ value + amount is greater than max _ value (that is, determines whether the sum of the current value current _ value of the identification code of the distributed service corresponding to the service identifier biz _ tag and the number of identification codes amount requested to be obtained is greater than the maximum value max _ value of the identification code of the distributed service corresponding to the service identifier biz _ tag). If not, the process proceeds to step S36, and if so, the process proceeds to step S38.
Step S36: the cache system 121 sets a generation reference value of the identifier, which is, for example, the latest current value (current _ value on the left) of the identifier of the corresponding distributed service determined according to the sum of the current value (current _ value on the right) of the identifier of the corresponding distributed service and the number (amount) of identifiers requested to be acquired, and is denoted as current _ value ═ current _ value + amount.
Step S37: the caching system 121 returns the latest current value current _ value.
Step S38: the caching system 121 returns an indication value (e.g., 0) that is outside the generation range.
Step S39: the caching system 121 returns the result.
Step S310: the apparatus 110 for generating the identification codes in batches determines whether the result returned by the cache system 121 is greater than 0, if so, it indicates that the cache system 121 successfully returns the reference value for generating the identification codes, and then the process goes to step S311, and if not, it indicates that the number of the identification codes requested to be obtained exceeds the maximum value stored in the cache system 121, and then the process goes to step S312.
Step S311: the apparatus 110 for generating an identifier in batch uses a sum obtained by adding 1 to a difference value between the latest current value current _ value and the number amount of identifiers requested to be acquired, as a generation start value of the identifier, that is, a generation start value of current _ value-amount +1, according to the latest current value current _ value returned by the cache system 121.
Step S312: the device 110 for generating identification codes in batches acquires distributed locks, and only when the distributed locks are acquired, the data related to the identification code sequences in the database 122 and the cache system 121 can be changed.
Step S312.1: the device 110 for generating identification codes in batches queries the database 122 according to the biz _ tag, and obtains the max _ value and step returned by the database 122.
Step S312.2: the apparatus 110 for generating an identification code in batch is configured to recalculate the maximum value of the identification code identifying the corresponding distributed service according to the maximum value of the identification code identifying the corresponding distributed service and the step size to obtain the maximum value of the identification code identifying the corresponding distributed service, which is denoted as max _ value ═ max _ value + step, and synchronize the recalculated max _ value to the database 122.
Step S312.3: the apparatus for bulk generation of identification codes 110 synchronizes the recalculated max _ value to the cache system 121 so that the cache system 121 is consistent with the max _ value of the database 122.
Step S312.4: after the apparatus 110 for batch generation of the identification code releases the distributed lock, the process re-enters step S35.
Step S313: the apparatus 110 for generating identification codes in batches performs a cycle according to the number of identification codes requested to be obtained on the basis of the generation start value of the identification codes, that is, the cycle is performed by around, the value of the identification code is increased by 1 each time to generate one identification code, and a result set of a plurality of identification codes is obtained through multiple cycles.
Step S314: the means for bulk generation of identification codes 110 returns the result set to the client device 130.
And inquiring whether the request exceeds the generation range of the identification codes of the distributed services corresponding to the identification from the storage system according to the identification of the distributed services in the batch acquisition request of the identification codes and the quantity of the identification codes acquired by the request, and if not, generating a plurality of identification codes at one time according to the generation reference value of the identification codes returned by the storage system and the quantity of the identification codes acquired by the request, thereby improving the generation efficiency of a plurality of IDs. In addition, the distributed lock is used for carrying out update control on related data in the storage system, and the problem of data update conflict in a distributed service scene is solved. In addition, the cache system is matched with the database, related data are preferentially inquired and judged in the cache system, and the overall response efficiency of the storage system is improved.
In the case where the storage system 120 includes a database 122, a method of generating identification codes for distributed service batches is described in connection with fig. 4.
The storage system 120 is configured to store data related to the generation range of the identification code of the distributed service, and determine whether the batch acquisition request of the identification code exceeds the generation range of the identification code of the distributed service.
A database 122 configured to store the identification biz _ tag of the distributed service and store the current value current _ value of the identification code of the distributed service, the maximum value max _ value of the identification code, and the step size, and to respond to the corresponding query request.
An exemplary Mysql database table is designed as follows:
column name Type (B) Whether or not it is empty Description of the invention
biz_tag varchar(24) N Service identification, unique
current_value bigint(20) N Current value of identification code
max_value bigint(20) N Maximum value of identification code
step bigint(20) N Stride of cache system
desc varchar(500) Y Description of the invention
created datetime N Date of creation
modified datetime N Modifying the date
Fig. 4 is a flowchart illustrating a method for batch generation of an identification code for distributed services according to further embodiments of the present disclosure.
As shown in fig. 4, the method of this embodiment includes:
step S41: the client device sends an identifier batch obtaining request to the identifier batch generating apparatus 110, where the request includes an identifier of the distributed service and the number of identifiers to be obtained.
Step S42: the apparatus 110 for generating identification codes in batches queries whether the database 122 stores the relevant service identifier according to the service identifier (biz _ tag) transmitted by the client device 130 and the number (amount) of the identification codes acquired in the request.
Step S43: the database 122 returns the query results whether they exist.
Step S44: the device 110 for generating the identification code in batch judges whether the service identifier biz _ tag transmitted by the client device exists in the database 122 according to the query result returned by the database 122, if so, the step S45 is performed, and if not, the error information is directly returned to the client device 130.
Step S45: the database 122 determines whether current _ value + amount is greater than max _ value according to the incoming biz _ tag (i.e., determines whether the sum of the current value current _ value of the identification code of the distributed service corresponding to the service identifier biz _ tag and the number of identification codes amount requested to be obtained is greater than the maximum value max _ value of the identification code of the distributed service corresponding to the service identifier biz _ tag). If not, the process proceeds to step S46, and if so, the process proceeds to step S48.
Step S46: the database 122 sets a generation reference value of the identifier, which is, for example, the latest current value (current _ value on the left) of the identifier of the corresponding distributed service determined according to the sum of the current value (current _ value on the right) of the identifier of the corresponding distributed service and the number (amount) of identifiers requested to be acquired, and is represented as current _ value ═ current _ value + amount.
Step S47: database 122 returns the latest current value current _ value.
Step S48: the database 122 returns an indication value (e.g., 0) that is outside the generation range.
Step S49: the database 122 returns the results.
Step S410: the apparatus 110 for generating identification codes in batches determines whether the result returned by the database 122 is greater than 0, if so, it indicates that the database 122 successfully returns the reference value for generating identification codes, and then step S411 is performed, and if not, it indicates that the number of identification codes requested to be obtained exceeds the maximum value stored in the database 122, and then step S412 is performed.
Step S411: the apparatus 110 for batch generation of an identifier adds 1 to the difference between the latest current value current _ value and the number of identifiers requested to be obtained, and uses the sum as the generation start value of the identifier, that is, the generation start value is current _ value-identifier +1, according to the latest current value current _ value returned by the database 122.
Step S412: the means for generating an identification code in bulk 110 acquires a distributed lock and only if the distributed lock is reached can the data associated with the identification code sequence in the database 122 be modified.
Step S412.1: the device 110 for generating identification codes in batches queries the database 122 according to the biz _ tag, and obtains the max _ value and step returned by the database 122.
Step S412.2: the device 110 for generating the identification code in batch is configured to recalculate the maximum value of the identification code for identifying the corresponding distributed service according to the maximum value of the identification code for identifying the corresponding distributed service and the step size, and indicate the maximum value as max _ value ═ max _ value + step.
Step S412.3: the means 110 for bulk generation of the identification code synchronizes the recalculated max value to the database 122.
Step S412.4: after the apparatus 110 for batch generation of the identification code releases the distributed lock, the process re-enters step S45.
Step S413: the apparatus 110 for generating identification codes in batches performs a cycle according to the number of identification codes requested to be obtained on the basis of the generation start value of the identification codes, that is, the cycle is performed by around, the value of the identification code is increased by 1 each time to generate one identification code, and a result set of a plurality of identification codes is obtained through multiple cycles.
Step S414: the means for bulk generation of identification codes 110 returns the result set to the client device 130.
And inquiring whether the request exceeds the generation range of the identification codes of the distributed services corresponding to the identification from the storage system according to the identification of the distributed services in the batch acquisition request of the identification codes and the quantity of the identification codes acquired by the request, and if not, generating a plurality of identification codes at one time according to the generation reference value of the identification codes returned by the storage system and the quantity of the identification codes acquired by the request, thereby improving the generation efficiency of a plurality of IDs. In addition, the distributed lock is used for carrying out update control on related data in the storage system, and the problem of data update conflict in a distributed service scene is solved.
Fig. 5 is a schematic structural diagram of an apparatus for batch generation of an identification code for distributed services according to some embodiments of the present disclosure.
As shown in fig. 5, the apparatus 110 for batch-generating an identification code of this embodiment includes: a memory 510 and a processor 520 coupled to the memory 510, the processor 520 being configured to perform a method of generating an identification code for a distributed service batch in any of the embodiments described above based on instructions stored in the memory 510.
For example, receiving an identification code batch acquisition request sent by a client device, where the identification of the distributed service and the number of identification codes requested to be acquired are included; inquiring whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification or not from a storage system according to the identification of the distributed service and the number of the identification codes required to be acquired; under the condition that the query result shows that the generation range of the identification codes of the distributed services corresponding to the identifiers is not exceeded, generating a plurality of identification codes according to the generation reference value of the identification codes returned by the storage system and the quantity of the identification codes required to be obtained, and returning the identification codes to the client equipment; acquiring a distributed lock under the condition that the query result shows that the query result exceeds the generation range of the identification code of the distributed service corresponding to the identification; inquiring the maximum value and the step length of the identification code of the distributed service corresponding to the identification from a storage system according to the identification of the distributed service; recalculating the maximum value of the identification code of the distributed service corresponding to the identification according to the maximum value and the step length of the identification code of the distributed service corresponding to the identification, and synchronizing the maximum value to a storage system; the distributed lock is released and then the querying step and the identification code generating step are continued.
For another example, after receiving an identification code batch acquisition request sent by the client device, querying the cache system whether an identifier of the distributed service exists; under the condition that the query result shows that the distributed service identification does not exist in the cache system, querying whether the distributed service identification exists in the database, receiving the query result returned by the database and the maximum value of the identification code of the distributed service corresponding to the identification under the condition of existence, acquiring a distributed lock, setting the current value of the identification code of the distributed service corresponding to the identification in the cache system to be 0, setting the maximum value of the identification code of the distributed service corresponding to the identification in the cache system to be the maximum value of the identification code of the distributed service corresponding to the identification returned by the database, and releasing the distributed lock; and under the condition that the query result shows that the distributed service identification exists in the cache system, or after the distributed lock is released, sending a query request to the cache system, wherein the query request is used for judging whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification, the query request carries the identification of the distributed service and the quantity of the identification codes acquired by the request, so that the cache system judges whether the sum of the current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification codes acquired by the request is greater than the maximum value of the identification code of the distributed service corresponding to the identification, if not, returning a generation reference value of the identification code, and if so, returning an indication value exceeding the generation range.
Memory 510 may include, for example, system memory, fixed non-volatile storage media, and the like. The system memory stores, for example, an operating system, an application program, a Boot Loader (Boot Loader), and other programs.
The apparatus 110 for generating the identification code in batches may further include an input/output interface 530, a network interface 540, a storage interface 550, and the like. These interfaces 530, 540, 550 and the connections between the memory 510 and the processor 520 may be, for example, via a bus 560. The input/output interface 530 provides a connection interface for input/output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 540 provides a connection interface for various networking devices. The storage interface 550 provides a connection interface for external storage devices such as an SD card and a usb disk.
As will be appreciated by one skilled in the art, embodiments of the present disclosure may be provided as a method, system, or computer program product. Accordingly, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present disclosure may take the form of a computer program product embodied on one or more non-transitory computer-readable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer program code embodied therein.
The present disclosure is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the disclosure. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only exemplary of the present disclosure and is not intended to limit the present disclosure, so that any modification, equivalent replacement, or improvement made within the spirit and principle of the present disclosure should be included in the scope of the present disclosure.

Claims (13)

1. A method for generating identification codes in batch aiming at distributed services is characterized by comprising the following steps:
receiving an identification code batch acquisition request sent by client equipment, wherein the identification code batch acquisition request comprises identification of distributed services and the number of identification codes required to be acquired;
inquiring whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification or not from a storage system according to the identification of the distributed service and the number of the identification codes required to be acquired;
and under the condition that the query result shows that the generation range of the identification codes of the distributed services corresponding to the identifications is not exceeded, generating a plurality of identification codes according to the generation reference value of the identification codes returned by the storage system and the quantity of the identification codes required to be obtained, and returning the identification codes to the client equipment.
2. The method of claim 1, further comprising:
acquiring a distributed lock under the condition that the query result shows that the query result exceeds the generation range of the identification code of the distributed service corresponding to the identification;
inquiring the maximum value and the step length of the identification code of the distributed service corresponding to the identification from a storage system according to the identification of the distributed service;
recalculating the maximum value of the identification code of the distributed service corresponding to the identification according to the maximum value and the step length of the identification code of the distributed service corresponding to the identification, and synchronizing the maximum value to a storage system;
releasing the distributed lock and then proceeding to the querying step and the identification code generating step of claim 1.
3. The method of claim 1, wherein querying a storage system whether the batch acquisition request for the identification code exceeds the generation range of the identification code identifying the corresponding distributed service comprises:
and sending an inquiry request for judging whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification to a storage system, wherein the inquiry request carries the identification of the distributed service and the quantity of the identification code required to be acquired, so that the storage system judges whether the sum of the current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification code required to be acquired is greater than the maximum value of the identification code of the distributed service corresponding to the identification, if not, returning a generation reference value of the identification code, and if so, returning an indication value exceeding the generation range.
4. The method of claim 1,
the generation reference value of the identification code is the latest current value of the identification code of the distributed service corresponding to the identification, which is determined according to the sum of the current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification codes required to be obtained;
generating a plurality of identification codes, comprising:
adding 1 to the difference value between the latest current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification code acquired by the request to obtain a sum value, and using the sum value as a generation starting value of the identification code;
and circulating according to the number of the identification codes required to be acquired on the basis of the generation starting value of the identification codes, and increasing 1 by the numerical value of the identification code every time so as to generate one identification code.
5. The method of claim 1, wherein the storage system comprises a caching system and a database;
the method further comprises the following steps:
after receiving an identification code batch acquisition request sent by client equipment, inquiring whether a distributed service identifier exists in a cache system;
and under the condition that the query result shows that the distributed service identification does not exist in the cache system, querying whether the distributed service identification exists in the database, receiving the query result whether the distributed service identification exists returned by the database and the maximum value of the identification code of the distributed service corresponding to the identification under the existence condition, acquiring the distributed lock, setting the current value of the identification code of the distributed service corresponding to the identification in the cache system to be 0, setting the maximum value of the identification code of the distributed service corresponding to the identification in the cache system to be the maximum value of the identification code of the distributed service corresponding to the identification returned by the database, and releasing the distributed lock.
6. The method of claim 5, wherein querying a storage system whether the batch acquisition request for the identification code exceeds the generation range of the identification code identifying the corresponding distributed service comprises:
and under the condition that the query result shows that the distributed service identification exists in the cache system, or after the distributed lock is released, sending a query request to the cache system, wherein the query request is used for judging whether the identification code batch acquisition request exceeds the generation range of the identification code of the distributed service corresponding to the identification, the query request carries the identification of the distributed service and the quantity of the identification codes acquired by the request, so that the cache system judges whether the sum of the current value of the identification code of the distributed service corresponding to the identification and the quantity of the identification codes acquired by the request is greater than the maximum value of the identification code of the distributed service corresponding to the identification, if not, returning a generation reference value of the identification code, and if so, returning an indication value exceeding the generation range.
7. The method of claim 2, wherein the storage system comprises a caching system and a database;
according to the distributed service identification, inquiring the maximum value and the step length of the identification code of the distributed service corresponding to the identification from a database; and synchronizing the maximum value of the identification code of the distributed service corresponding to the identification, which is obtained by recalculating the maximum value and the step length of the identification code of the distributed service corresponding to the identification, to a cache system and a database.
8. The method of claim 2, wherein recalculating the maximum value of the identification codes identifying the corresponding distributed services comprises:
and taking the sum of the maximum value and the step length of the identification code of the distributed service corresponding to the identification as the maximum value of the identification code of the distributed service corresponding to the identification, which is obtained by recalculation.
9. The method of claim 1, further comprising:
the client device respectively identifies the data in the distributed service by using the plurality of identification codes and migrates the identified data.
10. An apparatus for batch generation of identification codes for distributed services, comprising:
a memory; and
a processor coupled to the memory, the processor configured to perform the method of generating an identification code for a distributed service batch of any of claims 1-8 based on instructions stored in the memory.
11. A system for batch generation of identification codes for distributed services, comprising:
the apparatus for bulk generation of identification codes for distributed services of claim 9; and
and the storage system is configured to store the relevant data of the generation range of the identification codes of the distributed services and judge whether the batch acquisition request of the identification codes exceeds the generation range of the identification codes of the distributed services.
12. The system of claim 11, wherein the storage system comprises:
the cache system is configured to store the identification of the distributed service and the current value and the maximum value of the identification code of the distributed service, judge whether the sum of the current value of the identification code of the distributed service and the number of the identification codes acquired by the request is greater than the maximum value of the identification code of the distributed service, and respond to the corresponding query request; and
and the database is configured to store the distributed service identification and the maximum value and the step length of the identification code of the distributed service, and responds to the corresponding query request.
13. A non-transitory computer readable storage medium, having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method for batch generation of identification codes for distributed services of any of claims 1 to 8.
CN202011073022.2A 2020-10-09 2020-10-09 Method, device and system for batch generation of identification codes for distributed services Pending CN112256930A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011073022.2A CN112256930A (en) 2020-10-09 2020-10-09 Method, device and system for batch generation of identification codes for distributed services

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011073022.2A CN112256930A (en) 2020-10-09 2020-10-09 Method, device and system for batch generation of identification codes for distributed services

Publications (1)

Publication Number Publication Date
CN112256930A true CN112256930A (en) 2021-01-22

Family

ID=74234981

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011073022.2A Pending CN112256930A (en) 2020-10-09 2020-10-09 Method, device and system for batch generation of identification codes for distributed services

Country Status (1)

Country Link
CN (1) CN112256930A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113163027A (en) * 2021-04-22 2021-07-23 北京奇艺世纪科技有限公司 Data identifier generation method, device, equipment and storage medium
CN113806407A (en) * 2021-09-27 2021-12-17 武汉众邦银行股份有限公司 Method, device and storage medium for obtaining order numbers in batch based on cache
CN115577732A (en) * 2022-12-09 2023-01-06 成都怡康科技有限公司 Method and device for generating unique identification code pictures in batches

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106506663A (en) * 2016-11-22 2017-03-15 北京科摩仕捷科技有限公司 A kind of number distributing method, server and system
CN107733957A (en) * 2016-08-12 2018-02-23 北京融聚世界网络科技有限公司 Distributed Services configure system and version number's distribution method
CN109104490A (en) * 2018-08-29 2018-12-28 北京达佳互联信息技术有限公司 Service identification management method, device, electronic equipment and storage medium
CN109525658A (en) * 2018-11-09 2019-03-26 广州虎牙科技有限公司 A kind of production method, server, equipment, storage medium and operation system
CN110555078A (en) * 2019-09-02 2019-12-10 上海摩库数据技术有限公司 Distributed ID generation
CN110677511A (en) * 2019-09-29 2020-01-10 北京三快在线科技有限公司 Identification generation method, device, equipment and storage medium in distributed system
CN110968589A (en) * 2019-12-18 2020-04-07 浙江明度智控科技有限公司 Self-adding ID management method and device in distributed system
CN111125569A (en) * 2019-12-25 2020-05-08 北京同邦卓益科技有限公司 Data identifier generation method and device, electronic equipment and medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107733957A (en) * 2016-08-12 2018-02-23 北京融聚世界网络科技有限公司 Distributed Services configure system and version number's distribution method
CN106506663A (en) * 2016-11-22 2017-03-15 北京科摩仕捷科技有限公司 A kind of number distributing method, server and system
CN109104490A (en) * 2018-08-29 2018-12-28 北京达佳互联信息技术有限公司 Service identification management method, device, electronic equipment and storage medium
CN109525658A (en) * 2018-11-09 2019-03-26 广州虎牙科技有限公司 A kind of production method, server, equipment, storage medium and operation system
CN110555078A (en) * 2019-09-02 2019-12-10 上海摩库数据技术有限公司 Distributed ID generation
CN110677511A (en) * 2019-09-29 2020-01-10 北京三快在线科技有限公司 Identification generation method, device, equipment and storage medium in distributed system
CN110968589A (en) * 2019-12-18 2020-04-07 浙江明度智控科技有限公司 Self-adding ID management method and device in distributed system
CN111125569A (en) * 2019-12-25 2020-05-08 北京同邦卓益科技有限公司 Data identifier generation method and device, electronic equipment and medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113163027A (en) * 2021-04-22 2021-07-23 北京奇艺世纪科技有限公司 Data identifier generation method, device, equipment and storage medium
CN113806407A (en) * 2021-09-27 2021-12-17 武汉众邦银行股份有限公司 Method, device and storage medium for obtaining order numbers in batch based on cache
CN115577732A (en) * 2022-12-09 2023-01-06 成都怡康科技有限公司 Method and device for generating unique identification code pictures in batches

Similar Documents

Publication Publication Date Title
CN112256930A (en) Method, device and system for batch generation of identification codes for distributed services
CN109345388B (en) Block chain intelligent contract verification method and device and storage medium
CN109034809B (en) Block chain generation method and device, block chain node and storage medium
CN109558162B (en) Application program issuing method and device, computer equipment and storage medium
CN112765262B (en) Data redistribution method, electronic equipment and storage medium
CN110427386B (en) Data processing method, device and computer storage medium
CN106815258B (en) Data storage method and coordination node
CN111290779A (en) Gray scale distribution method, device, storage medium and electronic equipment
CN110968478A (en) Log collection method, server and computer storage medium
CN107548039B (en) Short message retry processing method, device and system
CN110795171A (en) Service data processing method and device, computer equipment and storage medium
EP3370166B1 (en) Method and apparatus for model parameter fusion
CN111090519B (en) Task execution method and device, storage medium and electronic equipment
CN111143410A (en) Accommodation public security management method, device and system
CN113132356B (en) UDP message distribution method, device and storage medium
CN110619204A (en) Invitation code generation method and device, terminal equipment and storage medium
CN113111669A (en) Increment-based front-end multi-language internationalized translation method and device
CN109842482B (en) Information synchronization method, system and terminal equipment
CN106453592B (en) Asynchronous call processing method, device and distributed system
CN107315693B (en) Data storage method and device
CN112685064A (en) Device identification processing method and device, storage medium and electronic device
CN114742600B (en) Content analysis method based on industrial internet and computer storage medium
CN112711571A (en) File synchronization method and device
CN113672604A (en) User data synchronization method, device and system and electronic equipment
CN115033647B (en) Data synchronization method and device, 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