CN113163027B - Data identifier generation method, device, equipment and storage medium - Google Patents
Data identifier generation method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN113163027B CN113163027B CN202110436088.1A CN202110436088A CN113163027B CN 113163027 B CN113163027 B CN 113163027B CN 202110436088 A CN202110436088 A CN 202110436088A CN 113163027 B CN113163027 B CN 113163027B
- Authority
- CN
- China
- Prior art keywords
- identifier
- service
- data
- identification
- interval
- 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
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/30—Managing network names, e.g. use of aliases or nicknames
- H04L61/3015—Name registration, generation or assignment
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2458—Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
- G06F16/2471—Distributed queries
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/30—Managing network names, e.g. use of aliases or nicknames
- H04L61/3005—Mechanisms for avoiding name conflicts
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- Theoretical Computer Science (AREA)
- Computational Linguistics (AREA)
- Software Systems (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Probability & Statistics with Applications (AREA)
- Mathematical Physics (AREA)
- Fuzzy Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the invention provides a method, a device, equipment and a storage medium for generating a data identifier, which are applied to an identifier service module, and are used for acquiring an initial identifier and an interval step length corresponding to an identifier generation request based on a service identifier when the identifier generation request sent by the service module is received; wherein the starting identifier is a non-negative number; acquiring an end identifier based on the initial identifier and the interval step length, and generating an initial identifier corresponding to the request by taking the end identifier as a next identifier of the service; the last mark is larger than the start mark; and sending the interval [ initial identification and tail identification ] to a service module as a data identification corresponding to the identification generation request so that the service module sequentially uses the nonnegative numbers in the interval to mark the service data one by one, and sending the identification generation request to an identification service module when the nonnegative numbers in the interval are used up and the data to be marked exist. The scheme can improve the query efficiency of the distributed service data and reduce high concurrency of the identifier generation request.
Description
Technical Field
The present invention relates to the field of distributed technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating a data identifier.
Background
For a service with a large amount of data, one table often cannot store the service data of the service. In this regard, distributed storage of traffic data may be performed: and taking the data belonging to the same service as complete service data, dividing the complete service data into a plurality of subdata, and performing distributed storage on each subdata to obtain distributed service data so as to realize the effect of database division and table division. Thus, it is necessary to generate data identifiers of distributed service data to avoid service confusion caused by data confusion.
In the related art, a UUID (a 128-bit value proposed by the international organization for standardization) may be generated based on data such as a current time, a counter (counter), and a hardware identifier (generally, a MAC address of a wireless network card). The UUID has the characteristic of being unique globally, so that the UUID can be used as data identification of distributed service data.
However, UUIDs are unordered, for example, "856f5555806443e98b7ed04c5a9d6a9a", and thus, irregular data identification is caused, which results in poor query efficiency of distributed service data.
Disclosure of Invention
Embodiments of the present invention provide a method, an apparatus, a device, and a storage medium for generating a data identifier, so as to generate a regular data identifier for distributed service data, so as to improve the query efficiency of the distributed service data. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a method for generating a data identifier, where the method is applied to an identifier service module, and the method includes:
when an identifier generation request sent by a service module is received, acquiring a service identifier of a service corresponding to the identifier generation request;
based on the service identifier, acquiring a starting identifier and an interval step length corresponding to the identifier generation request; wherein the starting identifier is a non-negative number, and the interval step length is a positive number;
acquiring an end identifier based on the initial identifier and the interval step length, and taking the end identifier as an initial identifier corresponding to a next identifier generation request of the service; the end identifier is larger than the start identifier;
and sending an interval [ the initial identifier and the tail identifier ] to the service module as a data identifier corresponding to the current identifier generation request of the service, so that the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and when the nonnegative numbers in the interval are used up and the data to be marked exists, sending an identifier generation request to the identifier service module.
Optionally, when the service identifier of the service corresponding to the identifier generation request is obtained, the method further includes:
updating the request times of the identifier generation request corresponding to the service identifier;
the interval step length is set by adopting the following steps:
acquiring the number of requests corresponding to each service identifier;
and searching the interval step length corresponding to the acquired request times from the corresponding relation between the pre-stored request times and the interval step length to be used as the interval step length corresponding to the service identifier.
Optionally, the obtaining a start identifier and an interval step length corresponding to the identifier generation request based on the service identifier includes:
searching an identification rule table corresponding to the service identification from a database;
reading a target field in the identification rule table to obtain an initial identification and an interval step length corresponding to the identification generation request; wherein, the target field is a field indicating a starting identifier and an interval step length;
the step of using the end identifier as a starting identifier corresponding to a next identifier generation request of the service includes:
and updating the initial identifier in the identifier rule table corresponding to the service identifier into the tail identifier.
Optionally, the service module stores the received data identifier in a first cache region; the occupancy rate of the first cache region is smaller than a preset threshold value;
the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and the method comprises the following steps:
the service module takes out nonnegative numbers in the interval from the first cache region and marks the data of the service one by one;
when the occupancy of the first cache region is equal to a preset threshold value, the service module stores the received data identifier in a second cache region; the occupation amount of the second cache region is 0;
and when the data identifiers in the first cache region are all taken out and the occupation amount of the second cache region is equal to a preset threshold value, the service module stores the received data identifiers in the first cache region.
Optionally, when receiving an identifier generation request sent by a service module, acquiring a service identifier of a service corresponding to the identifier generation request includes:
when a plurality of identification generation requests sent by a service module are received at the same time, locking one of the identification generation requests;
obtaining the locked identification to generate the service identification of the service corresponding to the request;
and when the generation of the data identifier corresponding to the locked identifier generation request is completed, unlocking the locked identifier generation request, and executing the locking processing on one of the identifier generation requests.
In a second aspect, an embodiment of the present invention provides an apparatus for generating a data identifier, where the apparatus is applied to an identifier service module, and the apparatus includes:
a service identifier obtaining unit, configured to obtain a service identifier of a service corresponding to an identifier generation request when receiving the identifier generation request sent by a service module;
a parameter obtaining unit, configured to obtain, based on the service identifier, a start identifier and an interval step length corresponding to the identifier generation request; wherein the starting identifier is a non-negative number, and the interval step length is a positive number;
an end identifier obtaining unit, configured to obtain an end identifier based on the start identifier and the interval step length, and use the end identifier as a start identifier corresponding to a next identifier generation request of the service; the end identifier is larger than the start identifier;
and the identification generation unit is used for sending an interval [ the initial identification and the tail identification ] to the service module as a data identification corresponding to the current identification generation request of the service, so that the service module sequentially uses nonnegative numbers in the interval to mark the data of the service one by one, and when the nonnegative numbers in the interval are used up and the data to be marked exist, the identification generation unit sends an identification generation request to the identification service module.
Optionally, the apparatus further comprises: a number update unit configured to:
updating the request times of the identifier generation request corresponding to the service identifier when the service identifier of the service corresponding to the identifier generation request is obtained;
the interval step length is set by adopting the following steps:
acquiring the number of requests corresponding to each service identifier;
and searching the interval step length corresponding to the acquired request times from the corresponding relation between the pre-stored request times and the interval step length to be used as the interval step length corresponding to the service identifier.
Optionally, the parameter obtaining unit is specifically configured to:
searching an identification rule table corresponding to the service identification from a database;
reading a target field in the identification rule table to obtain an initial identification and an interval step length corresponding to the identification generation request; wherein, the target field is a field indicating a starting identifier and an interval step length;
and updating the initial identifier in the identifier rule table corresponding to the service identifier into the tail identifier.
Optionally, the service module stores the received data identifier in a first cache region; the occupancy rate of the first cache region is smaller than a preset threshold value;
the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and the method comprises the following steps:
the business module takes out nonnegatives in the interval from the first cache region and marks the data of the business one by one;
when the occupation amount of the first cache region is equal to a preset threshold value, the service module stores the received data identifier in a second cache region; the occupation amount of the second cache region is 0;
and when the data identifiers in the first cache region are all taken out and the occupation amount of the second cache region is equal to a preset threshold value, the service module stores the received data identifiers in the first cache region.
Optionally, the parameter obtaining unit is specifically configured to:
when a plurality of identification generation requests sent by a service module are received at the same time, locking one of the identification generation requests;
obtaining the locked identification to generate the service identification of the service corresponding to the request;
and when the generation of the data identifier corresponding to the locked identifier generation request is completed, unlocking the locked identifier generation request, and executing the locking processing on one of the identifier generation requests.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor and the communication interface complete communication between the memory and the processor through the communication bus;
a memory for storing a computer program;
the processor is configured to implement the steps of the method for generating a data identifier according to the first aspect when executing the program stored in the memory.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method for generating a data identifier provided in the first aspect are implemented.
The embodiment of the invention has the following beneficial effects:
according to the scheme provided by the embodiment of the invention, the initial identifier is a non-negative number, and the interval step length is a positive number; acquiring an end identifier of the service based on the initial identifier and the interval step length, and generating an initial identifier corresponding to the request by taking the end identifier as a next identifier of the service; the last mark is larger than the start mark; sequentially taking nonnegative numbers in the interval [ initial identification and tail identification ] as data identifications corresponding to the current identification generation request of the service; and when the non-negative number in the interval is used up and the data to be marked exists, the business module sends an identification generation request to the identification service module. Therefore, the data identification of each service can be ensured to be increased in the global increment or trend increment of the service, and the data identification of the service is regulated and ordered, so that the query efficiency of the service data in a distributed mode can be improved when the data identification is used for service query. And moreover, non-negative numbers in the interval [ the initial identifier and the tail identifier ] are sequentially used as data identifiers corresponding to the identifier generation request of the service, so that batch generation of the data identifiers is realized, and compared with the generation of a single data identifier, the times of the identifier generation request can be reduced, and the performance reduction caused by high concurrency is reduced. Therefore, the scheme can generate regular data identifiers for the distributed service data so as to improve the query efficiency of the distributed service data, and can reduce the performance reduction caused by high concurrence of identifier generation requests.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the embodiments or the prior art descriptions will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other embodiments can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a method for generating a data identifier according to an embodiment of the present invention;
fig. 2 is a schematic view of an application scenario of a method for generating a data identifier according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a data identifier generation apparatus according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived from the embodiments given herein by one of ordinary skill in the art, are within the scope of the invention.
The database and table division is to divide the original database and table according to a certain rule, store the data blocks originally stored in one database into a plurality of databases, and store the data blocks originally stored in one table into a plurality of tables. Therefore, for services with a large amount of data, the data belonging to the same service is regarded as complete service data, the complete service data is divided into a plurality of subdata, and distributed storage is performed on each subdata to obtain distributed service data, so that the database and table splitting effect can be realized.
In order to generate regular data identifiers for distributed service data to improve query efficiency of the distributed service data, embodiments of the present invention provide a method for generating data identifiers. In a specific application, the data identifier generation method can be applied to an identifier service module to generate a data identifier for a service module. The identification service module and the service module may belong to the same database, or the identification service module may belong to an electronic device for generating a data identification, and the service module may belong to an electronic device for storing data. The database and the electronic device may be specifically a desktop computer, a portable computer, a mobile terminal, an internet television, a server, and the like.
The following describes a method for generating a data identifier according to an embodiment of the present invention.
As shown in fig. 1, a method for generating a data identifier according to an embodiment of the present invention may specifically include the following steps:
s101, when receiving an identifier generation request sent by a service module, acquiring a service identifier of a service corresponding to the identifier generation request.
In a specific application, the service identifier for acquiring the service corresponding to the identifier generation request may be various. Illustratively, when the identifier generation request carries a service identifier, the service identifier in the identifier generation request may be read to obtain the service identifier of the service corresponding to the identifier generation request. Or, for example, when the identifier generation request and the service identifier are sent separately, when the identifier generation request is received, the service identifier whose difference between the receiving time and the receiving time of the received identifier generation request is smaller than the delay threshold may be used as the service identifier of the service corresponding to the received identifier generation request.
And S102, acquiring a starting identifier and an interval step length corresponding to the identifier generation request based on the service identifier.
Wherein the start identifier is a non-negative number and the interval step is a positive number.
In a specific application, based on the service identifier, the manner of obtaining the start identifier and the interval step length corresponding to the identifier generation request may be various. For example, an identification rule table corresponding to the service identifier may be searched from the database, and the start identifier and the interval step length in the identification rule table may be read. Or directly reading the starting identifier and the interval step length corresponding to the service identifier locally stored in the electronic equipment to which the service module belongs.
For ease of understanding and reasonable layout, the first exemplary case is described in detail below in the form of an alternative embodiment.
And S103, acquiring an end identifier based on the initial identifier and the interval step length, and generating the initial identifier corresponding to the request by taking the end identifier as the next identifier of the service.
Wherein the end flag is larger than the start flag.
In a specific application, the manner of obtaining the end identifier may be various based on the start identifier and the interval step length. Illustratively, the sum between the start flag and the interval step size may be calculated as the end flag. Alternatively, the product between the enlightenment flag and the interval step is calculated as the end flag.
And S104, sending the interval [ the initial identifier and the tail identifier ] to a service module as a data identifier corresponding to the current identifier generation request of the service, so that the service module sequentially uses nonnegative numbers in the interval to label the data of the service one by one, and sending the identifier generation request to an identifier service module when the nonnegative numbers in the interval are used up and the data to be labeled exists.
In a specific application, when a non-negative number in the interval [ start identifier, end identifier ] is used as the data identifier of the marking data, the non-negative number can be increased or the trend can be increased. For example, when the interval is [0,1000], it is reasonable to use a non-negative number 0,1,2, … …,1000 as the data flag, or use a non-negative number 0,2,4,6, … …,1000 as the data flag. And, one non-negative number marks one data.
The scheme provided by the embodiment of the invention can ensure that the data identification of each service is increased in the global increment or trend increment of the service, and realizes the regularity and the orderliness of the data identification of the service, thereby improving the query efficiency of the distributed service data when the data identification is used for service query. And moreover, non-negative numbers in the interval [ the initial identifier and the tail identifier ] are sequentially used as data identifiers corresponding to the identifier generation request of the service, so that batch generation of the data identifiers is realized, and compared with the generation of a single data identifier, the times of the identifier generation request can be reduced, and the performance reduction caused by high concurrency is reduced. Therefore, the scheme can generate regular data identification aiming at the distributed service data so as to improve the query efficiency of the distributed service data and reduce the performance reduction caused by high concurrence of identification generation requests.
In an optional implementation manner, when the service identifier of the service corresponding to the identifier generation request is obtained, the method for generating the data identifier provided in the embodiment of the present invention may further include the following steps:
updating the request times of the identifier generation request corresponding to the service identifier;
correspondingly, the interval step length is set by adopting the following steps:
acquiring the number of requests corresponding to each service identifier;
and searching the interval step length corresponding to the acquired request times from the corresponding relation between the pre-stored request times and the interval step length to be used as the interval step length corresponding to the service identifier.
In specific applications, different interval step lengths can be set for different services through the optional embodiment. Illustratively, the larger the number of requests, the larger the interval step. The larger interval step length can ensure that the larger interval span obtained subsequently based on the interval step length and the initial identifier is, the more data identifiers are contained, thereby reducing the request times of the service and reducing the concurrency pressure. For example, when the number of requests is 10, the section step is 1000, and when the number of requests is 50, the section step is 5000.
In addition, the number of requests may be recorded within a predetermined time period from the current time. For example, the number of requests recorded within 30 minutes from the current time is used to improve the adaptation degree of the interval step length and the actual service request situation, and more accurately reduce the parallel pressure.
In an optional implementation manner, the obtaining of the start identifier and the interval step length corresponding to the identifier generation request based on the service identifier specifically includes the following steps:
searching an identification rule table corresponding to the service identification from a database;
reading a target field in the identification rule table to obtain an initial identification and an interval step length corresponding to the identification generation request; wherein, the target field is a field indicating the starting identifier and the interval step length;
correspondingly, the above step of using the end identifier as the start identifier corresponding to the next identifier generation request of the service may specifically include the following steps:
and updating the initial identifier in the identifier rule table corresponding to the service identifier into the tail identifier.
In a specific application, for any service, an identification rule table may be constructed in advance for the service, and a field indicating a start identifier and an interval step length is recorded in the identification rule table. At this time, the start flag in the flag rule table is an initial value. Thus, for any service, when the service requests data identification for the first time, the initial identification is the initial value in the identification rule table, and when the service requests data identification for the second time and the subsequent time, the initial identification is the identification obtained by utilizing the last end identification to update, so that the global regularity of the data identification of the same service is realized.
Moreover, with the optional embodiment, the initial identifier and the service name, that is, the service identifier, can be customized in the identifier rule table, which is beneficial to capacity expansion: the self-defined initial identifier can ensure that the generation of the data identifier is matched with the data volume of the service, and the capacity expansion aiming at the data volume is realized; the self-defined service name can ensure that the method for generating the data identifier provided by the embodiment of the invention is suitable for any service, and for different services, different service names are defined in the identifier rule table, so that the capacity expansion aiming at the service type is realized. For example, the scheme provided by the embodiment of the present invention is applicable to a member order service, an advertisement order service, a video storage service, a user registration service, and the like. And the access is simple, and the user-defined field is added in the identification rule table corresponding to the service. For example: when the service is a member order, the field indicating the service name is "biz: FANS-MEMBER ", field indicating start identifier is" maximum: 100001", field indicating interval step size is" step:1000".
For example, for an order service, when a user places an order, the service module that generates the order needs an identifier of the order. At this time, the service module may call an identifier service interface (ID-Server) interface, so that the identifier service interface sends an identifier generation request to the identifier generation module, and then the identifier generation module executes the identifier generation method provided in the embodiment of the present invention, and returns a data identifier for the order service to the service module through the identifier service interface. For example, the service name is biz _ order, the corresponding start identifier max _ id =0, and the interval step =1000, and the start identifier in the identifier rule table is updated to max _ id = max _ id + step, i.e., to max _ id1000. Thus, the data identifier obtained by the service module in the request is ID = [ max _ ID + 1, max \uid + step ], that is, the interval of [1,1000 ]. The service module may sequentially use the values 1-1000 as data identifiers to mark the data, for example, the data identifier of data D1 is 1, the data identifier of data D2 is 2, and so on. When the value in the interval [1,1000] is used up, the service module can call the identification service interface again to obtain the ID interval [1001,2000], and so on.
In addition, for convenience of maintenance and management, the identification rule table may further include fields: a service primary key field for indicating a service identity, a description field for explaining the use of the identification rule table, and an update time field for indicating the update time of the identification rule table. When the identifier generation request is received for the first time, the update time recorded in the identifier rule table may be the creation time of the identifier rule table. And because the initial identifier in the identifier rule table is updated when the identifier is generated, for the same service, when the identifier generation request is received for the second time and later, the updating time field recorded in the identifier rule table is the time for updating the identifier rule table last time.
In an optional implementation manner, the service module stores the received data identifier in a first cache region; the occupancy rate of the first cache region is smaller than a preset threshold value;
correspondingly, the service module sequentially uses the non-negative numbers in the interval to mark the service data one by one, and specifically includes the following steps:
the business module takes out nonnegative numbers in the interval from the first cache region and marks the data of the business one by one;
when the occupation amount of the first cache region is equal to a preset threshold value, the service module stores the received data identifier in a second cache region; the occupation amount of the second cache region is 0;
and when the data identifiers in the first cache region are all taken out and the occupation amount of the second cache region is equal to a preset threshold value, the service module stores the received data identifiers in the first cache region.
In this optional embodiment, the service module stores the received data identifier in a dual-cache region manner, and when the occupancy of one cache region exceeds a preset threshold, stores the received data using another cache region. And the data identifier is taken out from the cache region to mark the data of the service, so that the effect of reducing the occupation amount of the cache region to 0 can be realized. Therefore, the cyclic use of the two buffer areas is realized, and the high-availability effect is realized. Among them, high Availability (High Availability) means that High Availability is guaranteed by reducing downtime.
Illustratively, the first cache region is an A-buffer and the second cache region is a B-buffer. And the data identifier received for the first time, namely the interval is placed into the A-buffer, and at the moment, the occupation amount of the A-buffer is 0 or less than a preset threshold value. And when the occupancy rate of the A-buffer reaches a preset threshold value, for example, the occupancy rate reaches 30% of the available space, the received data identifier is placed into the B-buffer, and at the moment, the occupancy rate of the B-buffer is 0. And when the data identifiers in the A-buffer are all taken out, namely the occupied amount of the A-buffer is 0 and the occupied amount of the B-buffer reaches a preset threshold value, putting the received data identifiers into the A-buffer.
In addition, the first cache region and the second cache region may both be a memory of a device to which the service module belongs, for example, may be a memory of a database. Therefore, the data identification is stored in the internal memory, and can be supported for a period of time even if the database is down, so that the effect of high availability is realized.
In an optional implementation manner, the obtaining a service identifier of a service corresponding to an identifier generation request when receiving the identifier generation request sent by the service module specifically includes the following steps:
when a plurality of identification generation requests sent by a service module are received at the same time, locking one of the identification generation requests;
obtaining the locked identification to generate the service identification of the service corresponding to the request;
and when the generation of the data identifier corresponding to the locked identifier generation request is completed, unlocking the locked identifier generation request and executing locking processing on one of the identifier generation requests.
In a particular application, locking of the identifier generation request may be accomplished using a distributed lock. The optional embodiment of the present invention performs alternative locking on multiple concurrent identifier generation requests, so as to ensure that data identifiers are generated for one identifier generation request of the same service at the same time, avoid the problem of identifier generation confusion and repetition caused by simultaneous arrival of requests, and ensure regularity and uniqueness of global data identifiers of the same service.
For the convenience of understanding, the above alternative embodiments are integrated into one scheme in the form of exemplary description below. Illustratively, as shown in fig. 2. When receiving a service identifier 1, that is, an identifier generation request of service 1, the identifier generation module searches an identifier rule table of service 1 from the database. Specifically, the identification rule table includes: the service Id:1 indicates that the main key is 1, and represents that the identification rule table belongs to the service 1; the "biz: order" indicates that the business name is order, namely "order"; "max _ id:0" indicates that the starting flag is 0; step:1000 indicates that the interval step size is 1000; order mark generation indicates that the mark rule table is used for order mark generation; "update _ time:2020-08-24" indicates that the update time of the identification rule table is 2020-08-24. Service 1 is an order service, and the user places three orders: order service A, order service B and order service C. And respectively generating a data identifier for each order, wherein the data identifiers comprise a local cache data identifier [1,1000] of the order service A, a local cache data identifier [1001,2000] of the order service B, and a local cache data identifier [2001,3000] of the order service C. It can be seen that, in the scheme, for order service, the global data identification is ordered: from order service A to order service C, the data identification is incremented from [1,1000] to [1001,2000], and [2001,3000].
Corresponding to the above method embodiment, an embodiment of the present invention further provides a device for generating a data identifier.
As shown in fig. 3, an apparatus for generating a data identifier according to an embodiment of the present invention is applied to identify a service module, and the apparatus includes:
a service identifier obtaining unit 301, configured to obtain a service identifier of a service corresponding to an identifier generation request when receiving the identifier generation request sent by a service module;
a parameter obtaining unit 302, configured to obtain, based on the service identifier, a start identifier and an interval step length corresponding to the identifier generation request; wherein the starting identifier is a non-negative number, and the interval step length is a positive number;
an end identifier obtaining unit 303, configured to obtain an end identifier based on the start identifier and the interval step length, and use the end identifier as a start identifier corresponding to a next identifier generation request of the service; the end identifier is larger than the start identifier;
an identifier generating unit 304, configured to send an interval [ the start identifier, the end identifier ] to the service module as a data identifier corresponding to the identifier generating request of this time of the service, so that the service module sequentially uses the nonnegative numbers in the interval to tag the data of the service one by one, and when the nonnegative numbers in the interval are used up and there is data to be tagged, send an identifier generating request to the identifier service module.
The scheme provided by the embodiment of the invention can ensure that the data identification of each service is increased in the global increment or trend increment of the service, and realizes the regularity and the orderliness of the data identification of the service, thereby improving the query efficiency of the distributed service data when the data identification is used for service query. And moreover, non-negative numbers in the interval [ the initial identifier and the tail identifier ] are sequentially used as the data identifiers corresponding to the identifier generation request of the service, so that the batch generation of the data identifiers is realized, and compared with the generation of a single data identifier, the times of identifier generation requests can be reduced, and the performance reduction caused by high concurrency is reduced. Therefore, the scheme can generate regular data identification aiming at the distributed service data so as to improve the query efficiency of the distributed service data and reduce the performance reduction caused by high concurrence of identification generation requests.
Optionally, the apparatus further comprises: a number update unit configured to:
updating the request times of the identifier generation request corresponding to the service identifier when the service identifier of the service corresponding to the identifier generation request is obtained;
the interval step length is set by adopting the following steps:
acquiring the number of requests corresponding to each service identifier;
and searching the interval step length corresponding to the acquired request times from the corresponding relation between the pre-stored request times and the interval step length to be used as the interval step length corresponding to the service identifier.
Optionally, the parameter obtaining unit 302 is specifically configured to:
searching an identification rule table corresponding to the service identification from a database;
reading a target field in the identification rule table to obtain an initial identification and an interval step length corresponding to the identification generation request; wherein, the target field is a field indicating a starting identifier and an interval step length;
and updating the initial identifier in the identifier rule table corresponding to the service identifier into the tail identifier.
Optionally, the service module stores the received data identifier in a first cache region; the occupancy rate of the first cache region is smaller than a preset threshold value;
the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and the method comprises the following steps:
the business module takes out nonnegatives in the interval from the first cache region and marks the data of the business one by one;
when the occupation amount of the first cache region is equal to a preset threshold value, the service module stores the received data identifier in a second cache region; the occupation amount of the second cache region is 0;
and when the data identifiers in the first cache region are all taken out and the occupation amount of the second cache region is equal to a preset threshold value, the service module stores the received data identifiers in the first cache region.
Optionally, the parameter obtaining unit 302 is specifically configured to:
when a plurality of identification generation requests sent by a service module are received at the same time, locking one of the identification generation requests;
obtaining the locked identification to generate the service identification of the service corresponding to the request;
and when the generation of the data identifier corresponding to the locked identifier generation request is completed, unlocking the locked identifier generation request, and executing the locking processing on one of the identifier generation requests.
An embodiment of the present invention further provides an electronic device, as shown in fig. 4, including a processor 401, a communication interface 402, a memory 403, and a communication bus 404, where the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404,
a memory 403 for storing a computer program;
the processor 401, when executing the program stored in the memory 403, implements the following steps:
when an identifier generation request sent by a service module is received, acquiring a service identifier of a service corresponding to the identifier generation request;
based on the service identifier, acquiring a starting identifier and an interval step length corresponding to the identifier generation request; wherein the starting identifier is a non-negative number, and the interval step length is a positive number;
acquiring an end identifier based on the initial identifier and the interval step length, and using the end identifier as a next identifier of the service to generate an initial identifier corresponding to the request; the end identifier is larger than the start identifier;
and sending an interval [ the initial identifier and the tail identifier ] to the service module as a data identifier corresponding to the current identifier generation request of the service, so that the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and when the nonnegative numbers in the interval are used up and the data to be marked exists, sending an identifier generation request to the identifier service module.
In a specific application, the electronic device provided in this embodiment is an electronic device to which the identifier generating module belongs.
The scheme provided by the embodiment of the invention can ensure that the data identification of each service is increased in the global increment or trend increment of the service, and realizes the regularity and the orderliness of the data identification of the service, thereby improving the query efficiency of the distributed service data when the data identification is used for service query. And moreover, non-negative numbers in the interval [ the initial identifier and the tail identifier ] are sequentially used as data identifiers corresponding to the identifier generation request of the service, so that batch generation of the data identifiers is realized, and compared with the generation of a single data identifier, the times of the identifier generation request can be reduced, and the performance reduction caused by high concurrency is reduced. Therefore, the scheme can generate regular data identifiers for the distributed service data so as to improve the query efficiency of the distributed service data, and can reduce the performance reduction caused by high concurrence of identifier generation requests.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a non-negative Signal Processor (DSP), application Specific Integrated Circuit (ASIC), field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware component.
In another embodiment of the present invention, a computer-readable storage medium is further provided, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the computer program implements the steps of any one of the above-mentioned data identifier generation methods.
In a further embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the method for generating a data identity of any of the above embodiments.
In the above embodiments, all or part of the implementation may be realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wire (e.g., coaxial cable, fiber optic, non-negative subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), among others.
It should be noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on differences from other embodiments. In particular, for the apparatus and device embodiments, the description is relatively simple, as it is substantially similar to the method embodiments, and reference may be made to some of the description of the method embodiments for relevant points.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.
Claims (10)
1. A method for generating data identification is applied to an identification service module, and comprises the following steps:
when an identifier generation request sent by a service module is received, acquiring a service identifier of a service corresponding to the identifier generation request;
based on the service identifier, acquiring a starting identifier and an interval step length corresponding to the identifier generation request; wherein the starting identifier is a non-negative number, and the interval step length is a positive number;
acquiring an end identifier based on the initial identifier and the interval step length, and using the end identifier as a next identifier of the service to generate an initial identifier corresponding to the request; the end identifier is larger than the start identifier;
sending an interval [ the initial identifier and the tail identifier ] to the service module as a data identifier corresponding to the current identifier generation request of the service, so that the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and when the nonnegative numbers in the interval are used up and the data to be marked exists, sending an identifier generation request to the identifier service module;
when the service identifier of the service corresponding to the identifier generation request is obtained, the method further comprises the following steps:
updating the request times of the identifier generation request corresponding to the service identifier;
the interval step length is set by adopting the following steps:
acquiring the number of requests corresponding to each service identifier;
and searching the interval step length corresponding to the acquired request times from the corresponding relationship between the pre-stored request times and the interval step length to be used as the interval step length corresponding to the service identifier.
2. The method of claim 1, wherein the obtaining a start identifier and an interval step corresponding to the identifier generation request based on the service identifier comprises:
searching an identification rule table corresponding to the service identification from a database;
reading a target field in the identification rule table to obtain an initial identification and an interval step length corresponding to the identification generation request; wherein, the target field is a field indicating a starting identifier and an interval step length;
the step of using the end identifier as a starting identifier corresponding to a next identifier generation request of the service includes:
and updating the initial identifier in the identifier rule table corresponding to the service identifier into the tail identifier.
3. The method of claim 1, wherein the service module stores the received data identifier in a first cache area; the occupancy rate of the first cache region is less than a preset threshold value;
the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and the method comprises the following steps:
the service module takes out nonnegative numbers in the interval from the first cache region and marks the data of the service one by one;
when the occupancy of the first cache region is equal to a preset threshold value, the service module stores the received data identification in a second cache region; the occupation amount of the second cache region is 0;
and when the data identifiers in the first cache region are all taken out and the occupation amount of the second cache region is equal to a preset threshold value, the service module stores the received data identifiers in the first cache region.
4. The method of claim 1, wherein the obtaining a service identifier of a service corresponding to an identifier generation request when receiving the identifier generation request sent by a service module comprises:
when a plurality of identification generation requests sent by a service module are received at the same time, locking one of the identification generation requests;
obtaining the locked identification to generate the service identification of the service corresponding to the request;
and when the generation of the data identifier corresponding to the locked identifier generation request is completed, unlocking the locked identifier generation request, and executing the locking processing on one of the identifier generation requests.
5. An apparatus for generating data identifier, which is applied to identify a service module, the apparatus comprising:
a service identifier obtaining unit, configured to obtain a service identifier of a service corresponding to an identifier generation request when receiving the identifier generation request sent by a service module;
a parameter obtaining unit, configured to obtain, based on the service identifier, a start identifier and an interval step length corresponding to the identifier generation request; wherein the starting identifier is a non-negative number, and the interval step length is a positive number;
an end identifier obtaining unit, configured to obtain an end identifier based on the start identifier and the interval step length, and use the end identifier as a start identifier corresponding to a next identifier generation request of the service; the end identifier is larger than the start identifier;
an identifier generating unit, configured to send an interval [ the start identifier, the end identifier ] to the service module as a data identifier corresponding to the identifier generating request of the service this time, so that the service module sequentially uses non-negative numbers in the interval to tag the data of the service one by one, and when the non-negative numbers in the interval are used up and there is data to be tagged, send an identifier generating request to the identifier service module;
a number update unit configured to:
updating the request times of the identifier generation request corresponding to the service identifier when the service identifier of the service corresponding to the identifier generation request is obtained;
the interval step length is set by adopting the following steps:
acquiring the number of requests corresponding to each service identifier;
and searching the interval step length corresponding to the acquired request times from the corresponding relation between the pre-stored request times and the interval step length to be used as the interval step length corresponding to the service identifier.
6. The apparatus according to claim 5, wherein the parameter obtaining unit is specifically configured to:
searching an identification rule table corresponding to the service identification from a database;
reading a target field in the identification rule table to obtain an initial identification and an interval step length corresponding to the identification generation request; the target field is a field indicating a starting identifier and an interval step length;
and updating the initial identifier in the identifier rule table corresponding to the service identifier into the tail identifier.
7. The apparatus of claim 5, wherein the service module stores the received data identifier in a first cache region; the occupancy rate of the first cache region is less than a preset threshold value;
the service module sequentially uses the nonnegative numbers in the interval to mark the data of the service one by one, and the method comprises the following steps:
the service module takes out nonnegative numbers in the interval from the first cache region and marks the data of the service one by one;
when the occupancy of the first cache region is equal to a preset threshold value, the service module stores the received data identification in a second cache region; the occupation amount of the second cache region is 0;
and when the data identifications in the first cache region are all taken out and the occupation amount of the second cache region is equal to a preset threshold value, the service module stores the received data identifications in the first cache region.
8. The apparatus according to claim 5, wherein the parameter obtaining unit is specifically configured to:
when a plurality of identification generation requests sent by a service module are received at the same time, locking one of the identification generation requests;
obtaining the locked identification to generate the service identification of the service corresponding to the request;
and when the generation of the data identifier corresponding to the locked identifier generation request is completed, unlocking the locked identifier generation request, and executing the locking processing on one of the identifier generation requests.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing the communication between the processor and the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1 to 4 when executing a program stored in the memory.
10. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110436088.1A CN113163027B (en) | 2021-04-22 | 2021-04-22 | Data identifier generation method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110436088.1A CN113163027B (en) | 2021-04-22 | 2021-04-22 | Data identifier generation method, device, equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113163027A CN113163027A (en) | 2021-07-23 |
CN113163027B true CN113163027B (en) | 2022-10-25 |
Family
ID=76869708
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110436088.1A Active CN113163027B (en) | 2021-04-22 | 2021-04-22 | Data identifier generation method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113163027B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114697292B (en) * | 2022-02-18 | 2023-12-19 | 青岛海尔科技有限公司 | Identification information generation method and device, storage medium and electronic device |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110555078A (en) * | 2019-09-02 | 2019-12-10 | 上海摩库数据技术有限公司 | Distributed ID generation |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2011049553A1 (en) * | 2009-10-20 | 2011-04-28 | Hewlett-Packard Development Company, L.P. | Universally unique semantic identifiers |
US8958294B2 (en) * | 2012-08-09 | 2015-02-17 | Lenovo Enterprise Solutions (Singapore) Pte. Ltd. | Assigning identifiers to mobile devices according to their data service requirements |
CN111125569A (en) * | 2019-12-25 | 2020-05-08 | 北京同邦卓益科技有限公司 | Data identifier generation method and device, electronic equipment and medium |
CN112256930A (en) * | 2020-10-09 | 2021-01-22 | 北京沃东天骏信息技术有限公司 | Method, device and system for batch generation of identification codes for distributed services |
-
2021
- 2021-04-22 CN CN202110436088.1A patent/CN113163027B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110555078A (en) * | 2019-09-02 | 2019-12-10 | 上海摩库数据技术有限公司 | Distributed ID generation |
Also Published As
Publication number | Publication date |
---|---|
CN113163027A (en) | 2021-07-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108255958B (en) | Data query method, device and storage medium | |
US8544059B2 (en) | System and method for determining effective policy profiles in a client-server architecture | |
CN110457363B (en) | Query method, device and storage medium based on distributed database | |
WO2018201980A1 (en) | Insurance policy service task allocation method, apparatus, computer device and storage device | |
CN111722918A (en) | Service identification code generation method and device, storage medium and electronic equipment | |
CN113076303A (en) | Method and device for generating service identifier in distributed system | |
CN112579898A (en) | Enterprise information management method and device and server | |
CN111858586B (en) | Data processing method and device | |
CN109150962B (en) | Method for rapidly identifying HTTP request header through keywords | |
CN113163027B (en) | Data identifier generation method, device, equipment and storage medium | |
CN115757406A (en) | Data storage method and device, electronic equipment and storage medium | |
CN112860953A (en) | Data importing method, device, equipment and storage medium of graph database | |
CN116126864A (en) | Index construction method, data query method and related equipment | |
CN108399175B (en) | Data storage and query method and device | |
CN111708831A (en) | Global primary key generation method and device | |
EP3522040A1 (en) | Method and device for file storage | |
CN110727895B (en) | Sensitive word sending method and device, electronic equipment and storage medium | |
CN110427538B (en) | Data query method, data storage method, data query device, data storage device and electronic equipment | |
CN110955460A (en) | Service process starting method and device, electronic equipment and storage medium | |
JP6233846B2 (en) | Variable-length nonce generation | |
CN112148925B (en) | User identification association query method, device, equipment and readable storage medium | |
CN113312540A (en) | Information processing method, device, equipment, system and readable storage medium | |
CN108763498B (en) | User identity identification method and device, electronic equipment and readable storage medium | |
CN111355777A (en) | Management method and device of distributed file system and server | |
CN113032820A (en) | File storage method, access method, device, 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 |