CN111523002B - Main key distribution method, device, server and storage medium - Google Patents
Main key distribution method, device, server and storage medium Download PDFInfo
- Publication number
- CN111523002B CN111523002B CN202010326648.3A CN202010326648A CN111523002B CN 111523002 B CN111523002 B CN 111523002B CN 202010326648 A CN202010326648 A CN 202010326648A CN 111523002 B CN111523002 B CN 111523002B
- Authority
- CN
- China
- Prior art keywords
- main key
- key
- main
- primary key
- primary
- 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
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
When service data of a main key to be allocated exists, a first configuration file stored locally is read, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of a memory cache when main key allocation service is stopped; detecting whether unassigned primary keys are stored in the first configuration file; if the unassigned primary key is not stored in the first configuration file, detecting whether the unassigned primary key exists in the primary key sequence of the current memory cache; if the service data exists, determining a main key allocated to the service data from the main key sequence cached in the current memory; if the service data does not exist, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated for the service data from the main key sequence currently loaded into the memory. Based on the invention, the performance consumption of the distributed system can be reduced, and the utilization rate of the primary key can be improved.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a primary key allocation method, a primary key allocation device, a server, and a storage medium.
Background
Primary key assignment of traffic data in servers is a particularly important part of data management in distributed systems. The traditional primary key allocation method is to obtain a primary key by accessing primary key configuration information in a database when service data of the primary key to be allocated exists in a server. The traditional primary key allocation method can frequently operate primary key configuration information in a database, and the frequent primary key configuration information in the database can seriously consume the performance of the distributed system.
The existing primary key allocation method is that a server operation database reads a primary key sequence according to primary key configuration information in the database and loads the primary key sequence into a memory, and then when the server has service data to be allocated with primary keys, the primary keys are allocated for the service data according to the primary key sequence in the memory. According to the existing primary key distribution mode, primary key distribution of a plurality of business data in a server can be realized by operating the database once, frequent operation of the database is avoided, and further performance consumption of a distributed system is reduced. However, when the server is down accidentally, the currently stored primary key sequence in the memory of the server is deleted, and if the server is restarted, a section of primary key sequence is read again from the database, and when the server is down outside the server, the primary keys in the memory which are not allocated in the primary key sequence are wasted.
Disclosure of Invention
In view of this, embodiments of the present application provide a primary key allocation method, apparatus, server, and storage medium, so as to reduce performance consumption of a distributed system and improve utilization of primary keys.
The technical proposal is as follows:
the first aspect of the invention discloses a primary key allocation method, which comprises the following steps:
when business data to be allocated with the main key exists, reading a first configuration file stored locally, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of a memory cache when main key allocation service is stopped;
detecting whether unassigned primary keys are stored in the first configuration file;
if the first configuration file does not store the unassigned primary key, detecting whether the unassigned primary key exists in the primary key sequence of the memory cache currently;
if the main key sequence of the current memory cache has an unallocated main key, determining the main key allocated to the service data from the main key sequence of the current memory cache;
if the main key sequence of the memory cache does not exist unassigned main keys, reading the main key sequence from a database, loading the main key sequence to the memory, and determining the main key assigned to the service data from the main key sequence currently loaded to the memory.
Optionally, the method further comprises:
and if the unassigned primary key is stored in the first configuration file, determining the primary key assigned to the service data from the unassigned primary keys of the first configuration file.
Optionally, the reading the primary key sequence from the database is loaded into the memory, including:
reading a first primary key, a second primary key and a step length which are stored in the database and are related to the service data;
taking the sum of the first main key and the step length as a third main key;
comparing the second primary key with the third primary key;
if the third main key is not larger than the second main key, using the first main key as a starting main key of a main key sequence and the third main key as an ending main key of the main key sequence, updating the first main key in the database into the third main key, and loading the main key sequence into the memory;
and if the third main key is larger than the second main key, returning error information.
Optionally, the method further comprises:
when the main key allocation service is detected to stop, judging whether unallocated main keys exist in a main key sequence in the memory cache;
and if the main key sequence in the memory cache has the main key which is not allocated, storing the main key which is not allocated in the main key sequence in the memory cache into the first configuration file.
Optionally, when there is service data to be assigned with the primary key, the method includes: when the application process has service data to be allocated with the primary key, the method further comprises:
reading a second configuration file, wherein the second configuration file comprises current state information of the application process;
detecting whether the state information characterizes that the application process is in a stop running state;
the reading of the locally stored first configuration file includes: and if the state information indicates that the application program is not in the running stopping state, reading a first configuration file stored locally.
Optionally, the method further comprises:
when a database registration request is received, a first quantity, a second quantity and a total working time length of each server in at least one server are obtained, wherein the first quantity is the total quantity of the service quantity of the main key allocated in the server, and the second quantity is the total quantity of the service data of the main key to be allocated in the server;
calculating the matching degree of the server and the service registration request according to the first number, the second number and the total working time length of the server;
and distributing the database registration request to a target server with highest matching degree with the database registration request in the at least one server.
Optionally, the method further comprises:
reading a second configuration file, wherein the second configuration file comprises the current state information of the target server;
if the state information represents that the target server is in an operation state, acquiring basic information related to the target server, wherein the basic information is used for recording service data of a main key to be allocated to the target server currently;
and controlling the target server to carry out primary key allocation for the service data to be allocated currently.
The second aspect of the present invention discloses a primary key distribution device, comprising:
the first reading unit is used for reading a first configuration file stored locally when the service data of the main key to be allocated exist, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of the memory cache when the main key allocation service is stopped;
a first detection unit, configured to detect whether an unassigned primary key is stored in the first configuration file;
the second detection unit is used for detecting whether the unassigned primary key exists in the primary key sequence of the memory cache currently if the unassigned primary key is not stored in the first configuration file;
The first determining unit is used for determining the primary key allocated to the service data from the primary key sequence of the current memory cache if the primary key sequence of the current memory cache has the primary key which is not allocated;
and the second determining unit is used for reading the main key sequence from the database and loading the main key sequence to the memory if the main key sequence cached in the memory does not exist unassigned main keys currently, and determining the main key assigned to the service data from the main key sequence loaded to the memory currently.
The third aspect of the present invention discloses a server, comprising: at least one memory and at least one processor; the memory stores a program, and the processor calls the program stored in the memory, where the program is used to implement the primary key allocation method disclosed in any one of the first aspect of the present invention.
A fourth aspect of the present invention discloses a computer-readable storage medium having stored therein computer-executable instructions for performing the primary key allocation method as disclosed in any one of the above-described first aspects of the present invention.
The application provides a primary key distribution method, a device, a server and a storage medium, when service data of a distributed primary key exist, whether a primary key which is not distributed in a primary key sequence of a memory cache when primary key distribution service is stopped is stored in a first configuration file which is locally stored is detected, and if the primary key which is not distributed is not stored in the first configuration file, whether the primary key which is not distributed exists in the primary key sequence of the current memory cache is detected; if the main key sequence of the current memory cache stores the main key which is not allocated, determining the main key which is allocated to the service data from the main key sequence of the current memory cache; if the main key sequence of the current memory cache does not store the main key which is not allocated, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated for the service data from the main key sequence which is currently loaded into the memory. According to the primary key allocation method, the primary keys which are not allocated in the primary key sequence of the memory cache when the primary key allocation service is stopped are stored by presetting the first configuration file in the local, so that the waste of the primary keys can be effectively avoided. And under the condition that unallocated primary keys are not stored in the first configuration file stored locally and unallocated primary keys are not stored in the primary key sequence in the current memory cache, the primary key sequence is read from the database, so that frequent operation on the database is avoided, and further performance consumption of the distributed system is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart of a primary key allocation method according to an embodiment of the present invention;
FIG. 2 is a flowchart of a method for reading a primary key sequence from a database and loading the primary key sequence into a memory according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating another primary key allocation method according to an embodiment of the present invention;
fig. 4 is a flowchart of a method for distributing database registration requests according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a primary key distribution device according to an embodiment of the present invention;
fig. 6 is a block diagram of a server according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In this application, 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 one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As shown in fig. 1, the present invention provides a primary key allocation method, which is applicable to a server. The main key allocation method specifically comprises the following steps:
s101: when the business data of the main key to be allocated exist, a first configuration file stored locally is read, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of a memory cache when main key allocation service is stopped;
in this embodiment of the present application, for each server in the distributed system, a first configuration file is set in advance in the local area of the server, where the first configuration file set in the local area of the server is initially empty, and when the primary key allocation service of the server stops, the primary key that is not allocated in the primary key sequence that is currently cached in the memory of the server is stored in the first configuration file in the local area of the server. When the server has the service data of the main key to be allocated, the first configuration file stored locally is read so as to judge whether the first configuration file stores the main key which is not allocated or not, and then corresponding operation is executed according to the detection result.
S102: detecting whether unassigned primary keys are stored in the first configuration file; if the first configuration file does not store the unassigned primary key, executing step S103; if the first configuration file stores the unassigned primary key, step S106 is performed.
In the specific execution process of step S102, after the first configuration file is read, detecting whether an unassigned primary key is stored in the read first configuration file, and if the unassigned primary key is not stored in the first configuration file, detecting whether an unassigned primary key exists in a primary key sequence in a current memory cache of the server; if the first configuration file stores unassigned primary keys, determining the primary keys assigned to the service data directly from the first configuration file. If the first configuration file does not store the unassigned primary key, detecting whether the unassigned primary key exists in the primary key sequence of the current memory cache, and further executing corresponding operation according to the detection result.
S103: detecting whether unallocated primary keys exist in a primary key sequence of a current memory cache; if the main key sequence of the current memory cache has an unallocated main key; step S104 is executed; if there is no unassigned primary key in the primary key sequence in the current memory cache, step S105 is performed.
In the specific execution process of step S103, when the first configuration file does not store the unassigned primary key, detecting whether there is an unassigned primary key in the primary key sequence of the current memory cache of the server, and if there is an unassigned primary key in the primary key sequence of the current memory cache, determining the primary key as the primary key allocated for service data from the primary key sequence of the current memory cache; if the main key sequence of the current memory buffer does not have the main key which is not allocated, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key which is allocated for the service data from the main key sequence which is currently loaded into the memory.
S104: determining a primary key allocated to service data from a primary key sequence cached in a current memory;
in the specific execution of step S104, when it is detected that there is an unassigned primary key in the primary key sequence in the current memory cache, a primary key assigned to service data is determined from the primary key sequence in the current memory cache.
S105: reading a main key sequence from a database, loading the main key sequence into a memory, and determining a main key allocated for service data from the main key sequence currently loaded into the memory;
referring to fig. 2, a flow chart of a method for reading a primary key sequence from a database and loading the primary key sequence into a memory is shown, and the method specifically includes the following steps:
S201: reading a first main key, a second main key and a step length which are stored in a database and related to service data;
in the embodiment of the application, when detecting that the main key sequence cached in the current memory does not have the main key which is not allocated, the data table and the second main key which are stored in the database and are related to the service data are read. The data table comprises a first main key and a step length; the first primary key related to the service data is the maximum primary key value which is currently allocated to the server in the database, the second primary key is the maximum limit value of the primary key which can be allocated to the server and stored in the database, and the step length is the number of primary keys of the primary key sequence which need to be read from the database.
The data table related to the service data stored in the read database is as follows:
table name T | Maximum primary key value M currently assigned to server | Step S |
It should be noted that, in this embodiment of the present application, before the first primary key, the second primary key, and the step length related to the service data stored in the database are read, the primary key record in the database (the primary key record is used to record the primary key already allocated in the database) may be locked, so that when the primary key sequence is read from the database, the primary key already allocated may be avoided from being read.
S202: taking the sum of the first main key and the step length as a third main key;
in the process of specifically executing step S202, after the first primary key and the step length related to the service are read from the database, the first primary key and the step length are added, and then the result obtained by adding the first primary key and the step length is used as the third primary key.
For example, the first primary key read from the database to related to the business data is 1000, i.e. the number of primary keys of the primary keys currently allocated in the database is 1000; the step length read is 100, namely, a main key sequence formed by 100 main keys is required to be read from a database; the first primary key and the step size are added, i.e. 1000+100, to obtain 1100, and the result obtained by adding the first primary key and the step size is taken as the third primary key, i.e. the third primary key is equal to 1100.
S203: judging whether the third main key is larger than the second main key; if the third primary key is not greater than the second primary key, executing step S204; if the third primary key is larger than the second primary key, step S205 is performed.
In the specific execution of step S203, after taking the sum of the first primary key and the step size as the third primary key, comparing the second primary key with the third primary key, if the third primary key is not greater than the second primary key, it is indicated that the unassigned primary key in the database is still sufficient to be applied, and the primary key sequence can be read from the database; if the third primary key is larger than the second primary key, indicating that the unassigned primary key in the database is not sufficiently applied, i.e. the primary key sequence cannot be read from the database, outputting error information for prompting that the primary key sequence cannot be read from the database currently.
For example, when the third primary key is 1100, if the second primary key read from the database to be related to the service data is 10000, it is indicated that the third primary key is not larger than the second primary key, and further it is indicated that the primary key sequence can be read from the database; if the second primary key read from the database to the related service data is 1090, the third primary key is larger than the second primary key, further, the fact that the primary key sequence cannot be read from the database is further indicated, error information is output, and the fact that the primary key sequence cannot be read from the database at present is indicated.
S204: the first main key is used as a starting main key of the main key sequence, the third main key is used as an ending main key of the main key sequence, the first main key in the database is updated to be the third main key, and the main key sequence is loaded into the memory;
in the specific execution of step S204, when the third main key is not greater than the second main key, that is, when the main key sequence can be read from the database, the first main key is the start main key of the main key sequence, the third main key is the end main key of the main key sequence, the main key sequence is read from the database, and the read main key sequence is loaded into the memory.
In the embodiment of the application, after the primary key sequence is read from the database, the first primary key in the database is updated to the third primary key so as to record the situation of the primary key which is currently allocated in the database.
For example, when the first primary key read from the database to be related to the service data is 1000, that is, the number of primary keys of the primary keys currently allocated in the database is 1000; when the step size is 100, that is, when a primary key sequence consisting of 100 primary keys needs to be read from the database. If the third main key is smaller than the second main key, 1000 is used as the initial main key of the main key sequence, 1100 is used as the end main key of the main key sequence, the main key sequence (1000-1100) is read from the database, the read main key sequence is loaded into the memory, the first main key is updated to be the third main key, namely, the value 1000 of the first main key is updated to be the value 1100 of the third main key, and the value of the updated first main key is 1100.
After the first primary key is updated to the third primary key, the previously locked primary key record is unlocked.
S205: an error message is returned.
In the embodiment of the application, when detecting that there is no unassigned primary key in the primary key sequence in the current memory cache, the first primary key, the second primary key and the step length related to the service data stored in the database are read, and the sum of the first primary key and the step length is used as the third primary key, so that whether the primary key sequence can be read from the database can be judged by comparing the sizes of the third primary key and the second primary key. If the third main key is larger than the second main key, the main key sequence can not be read from the database, error information is returned, and the fact that the main key sequence can not be read from the database at present is indicated.
S106: determining a main key allocated to the service data from unassigned main keys of the first configuration file;
in the process of specifically executing step S106, when it is detected that the unassigned primary key is stored in the first configuration file, the primary key assigned to the service data is determined from the unassigned primary keys of the first configuration file.
In the embodiment of the application, when detecting that the unassigned primary key is stored in the first configuration file, determining the primary key assigned to the service data from the unassigned primary keys of the first configuration file. The method can greatly wait when different nodes access data to update the primary key simultaneously, and improves the distribution efficiency of the primary key.
S107: when the main key allocation service is detected to stop, judging whether unallocated main keys exist in a main key sequence in the memory cache; if there is an unassigned primary key in the primary key sequence in the memory cache, step S108 is performed.
In this embodiment of the present application, when the primary key allocation service is detected to stop, if the primary key sequence in the memory cache has a primary key that is not allocated, the primary key that is not allocated in the primary key sequence in the memory cache is stored in the first configuration file by detecting whether the primary key sequence in the memory cache has a primary key that is not allocated. When the service data to be allocated with the main key exists, the main key can be allocated for the service data directly through the main key which is stored in the first configuration file and is not allocated, so that the allocation efficiency of the main key can be improved, and the waste of the main key can be effectively avoided.
It should be noted that, when the server is turned off, or a request for stopping the primary key allocation service sent by the user is received, or the server is unexpected (for example, the server is unexpectedly down), the server may be regarded as stopping the primary key allocation service, at this time, it may be judged whether there is an unassigned primary key in the primary key sequence in the memory cache, if there is an unassigned primary key in the primary key sequence in the memory cache, the unassigned primary key in the primary key sequence in the memory cache is stored into the first configuration file, so as to avoid the waste of the primary key.
In addition, in the prior art, the current use condition of the primary key of the server is recorded by using a database, and each time a server needs to be added, a primary key configuration information for maintaining the server needs to be added in the database, so that a certain difficulty is caused to the expandability of the distributed system. Therefore, the invention presets the first configuration information related to the server aiming at each server in the distributed system, and further can record the current primary key use condition of the server by utilizing the first configuration file. The current main key use condition of the server is recorded by utilizing the first configuration file, so that the use condition of the current main key of the database storage server can be avoided.
S108: and storing the unassigned primary keys in the primary key sequence in the memory cache to a first configuration file.
When service data of allocated main keys exist, detecting whether a first configuration file stored locally stores main keys which are not allocated in a main key sequence of a memory cache when main key allocation service is stopped, if the first configuration file stores the main keys which are not allocated, directly determining the main keys allocated for the service data from the first configuration file; if the first configuration file does not store the unassigned primary key, detecting whether the unassigned primary key exists in the primary key sequence of the current memory cache; if the main key sequence of the current memory cache stores the main key which is not allocated, determining the main key which is allocated to the service data from the main key sequence of the current memory cache; if the main key sequence of the current memory cache does not store the main key which is not allocated, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated for the service data from the main key sequence which is currently loaded into the memory; when the fact that the main key sequence of the memory cache has the main key which is not distributed is detected, the main key sequence of the memory cache is stored in the first configuration file, and when the business data of the main key to be distributed exists, the main key is distributed for the business data directly through the main key which is stored in the first configuration file and is not distributed, so that the distribution efficiency of the main key can be improved, and the waste of the main key can be effectively avoided.
In addition, according to the primary key allocation method, the primary key sequence is read from the database only when the fact that the primary key which is not allocated is not stored in the first configuration file which is stored locally and the primary key sequence which is not allocated is not stored in the primary key sequence in the current memory cache is detected, so that frequent operation on the database is avoided, and further performance consumption of the distributed system is reduced.
Further, when there is service data of the primary key to be allocated, the method includes: when the application process has service data to be allocated with a primary key, as shown in fig. 3, another flow diagram of a primary key allocation method provided in an embodiment of the present invention is shown. The main key allocation method specifically comprises the following steps:
s301: reading a second configuration file, wherein the second configuration file comprises current state information of an application process;
in this embodiment of the present application, for each server in at least one server, a second configuration file corresponding to the server is preset, where the second configuration file includes current state information of an application process on the server. The current state information of the application process may be an running state or a running stop state.
In the specific execution process of step S301, when the application process on the server has the service data to be allocated with the primary key, the second configuration file is read, and then the corresponding operation is executed by detecting the current state information of the application process in the second configuration file.
S302: detecting whether the state information represents that the application process is not in a stop running state; if the state information indicates that the application process is not in the running stop state, step S303 is executed.
In the specific execution process of step S302, when the second configuration file is read, detecting whether the state information in the second configuration file indicates that the application process is not in a stop running state; and if the state information indicates that the application process is not in the running stopping state, namely, the application process is in the running state, reading the locally stored first configuration file. And if the state information indicates that the application process is in a stop running state, ending the primary key allocation service.
S303: reading a first configuration file stored locally, wherein the first configuration file comprises main keys which are not distributed in a main key sequence of a memory cache when main key distribution service is stopped;
s304: detecting whether unassigned primary keys are stored in the first configuration file; if the first configuration file does not store the unassigned primary key, executing step S305; if the first configuration file stores the unassigned primary key, step S308 is performed.
S305: detecting whether unallocated primary keys exist in a primary key sequence of a current memory cache; if the main key sequence of the current memory cache has an unallocated main key; step S306 is executed; if there is no unassigned primary key in the primary key sequence in the current memory cache, step S307 is performed.
S306: determining a primary key allocated to service data from a primary key sequence cached in a current memory;
s307: reading a main key sequence from a database, loading the main key sequence into a memory, and determining a main key allocated for service data from the main key sequence currently loaded into the memory;
s308: determining a main key allocated to the service data from unassigned main keys of the first configuration file;
s309: when the main key allocation service is detected to stop, judging whether unallocated main keys exist in a main key sequence in the memory cache; if there is an unassigned primary key in the primary key sequence in the memory cache, step S310 is performed.
S310: and storing the unassigned primary keys in the primary key sequence in the memory cache to a first configuration file.
In the process of specifically executing steps S303 to S310, the specific implementation principle and execution process of steps S303 to S310 are the same as those of steps S101 to S108 disclosed in fig. 1, and reference may be made to the corresponding parts disclosed in fig. 1, and the detailed description thereof will not be repeated.
In the embodiment of the application, when the application process has the service data to be allocated with the primary key, the second configuration file is read before the first configuration file is read; detecting whether the current state information of the application process included in the second configuration file represents that the application process is not in a stop state; reading a first configuration file under the condition that the state information indicates that the application process is not in a stop running state; if the state information indicates that the application process is in a stop running state, ending the primary key allocation service of the time, and avoiding unnecessary primary key application.
Further, on the basis of the above disclosed method for assigning the primary keys, as shown in fig. 4, the method specifically further includes the following steps:
s401: when a database registration request is received, acquiring a first number, a second number and a total working time length of each server in at least one server;
in the embodiment of the application, the distributed system comprises at least one server, and each server in the distributed system can be set as a task distribution server. And after the task distribution server receives the database registration request, acquiring the first number, the second number and the total working time length of each server except the task distribution server in at least one server. The first number is the total number of the service data of the assigned main key in the server, the second number is the total number of the service data of the main key to be assigned in the server, and the total working time is the working time of the server for processing the total number of the service data of the assigned main key.
It should be noted that each of the at least one server may serve as a task distribution server.
S402: calculating the matching degree of the server and the database registration request according to the first number, the second number and the total working time length of the server;
in the embodiment of the application, for each server in at least one server, after the first number, the second number and the total working duration of the server are acquired, the matching degree of the server and the database registration request is calculated according to the first number, the second number and the total working duration of the server,
in this embodiment of the present application, for each server in at least one server, according to the first number, the second number, and the total working duration of the servers, a manner of calculating the matching degree between the server and the registration request may be: first number/total working duration/second data amount. The specific formula is as follows:
match_rate=amt1/time/atm2
wherein match_rate is the matching degree of the server and the database registration request, amt1 is the first number, time is the total working time length, and atm2 is the second number.
As can be seen from the above formula, for each server of the at least one server, the greater the first number/total operating time length of that server, the greater the probability that server is assigned to a database registration request; the smaller the second number of servers, the greater the probability that the server is assigned to a database registration request.
S403: distributing the database registration request to a target server with highest matching degree with the database registration request in at least one server;
in the specific execution process of step S403, after the matching degree between each server in the at least one server and the database registration request is calculated, the calculated matching degree between each server and the database registration request is ordered from high to low, and the server with the highest matching degree with the database registration request in the at least one server is used as the target service, so that the database registration request is allocated to the target server.
In the embodiment of the application, when a database registration request is received, the first number, the second number and the total working time length of each server in at least one server are acquired, and for each server in at least one server, the matching degree of the server and the database registration request is calculated according to the first number, the second number and the total working time length of the server, and the database registration request is distributed to a target server with the highest matching degree with the database registration request in at least one server, so that the aim of balancing the load of the server performance is achieved.
S404: reading a second configuration file, wherein the second configuration file comprises the current state information of the target server;
in this embodiment of the present application, for each server in at least one server, a second configuration file corresponding to the server is preset, where the second configuration file includes current state information of the server. The current state information of the server may be an running state or a running stop state.
In the embodiment of the present application, after the database registration request is allocated to the target server, the second configuration file may be further read, so as to perform a corresponding operation by detecting the current state information of the target server in the second configuration file.
S405: detecting whether the state information represents that the target server is in an operating state; if the state information indicates that the target server is in an operation state, executing step S406;
in the specific execution process of step S405, after reading the second configuration file of the target server, detecting that the state information of the target server in the second configuration file is that the target server is in an operating state; and if the state information indicates that the target server is in an operation state, acquiring the service data of the current main key to be allocated with the target server, and further controlling the target server to allocate the main key for the service data of the current main key to be allocated.
S406: acquiring basic information related to a target server, wherein the basic information is used for recording service data of a main key to be allocated to the target server currently;
s407: and the control target server performs primary key allocation for the service data to be allocated currently.
In this embodiment of the present application, after the database registration request is allocated to the target server, the second configuration file may be further read, so that by detecting current state information of the target server in the second configuration file, if the current state information of the target server indicates that the target server is in an operating state, service data of a main key to be allocated currently with the target server is obtained, and the target server is controlled to allocate the main key for the service data to be allocated currently, so that the target server processes the service data of the main key to be allocated currently.
Referring to fig. 5, a schematic structural diagram of a primary key distribution device according to an embodiment of the present invention is shown, where the primary key distribution device includes:
a first reading unit 51, configured to read a first configuration file stored locally when there is service data to be allocated with a primary key, where the first configuration file includes a primary key that is not allocated in a primary key sequence of a memory cache when a primary key allocation service is stopped;
A first detecting unit 52, configured to detect whether an unassigned primary key is stored in the first configuration file;
a second detecting unit 53, configured to detect whether an unassigned primary key exists in the primary key sequence in the current memory cache if the unassigned primary key is not stored in the first configuration file;
the first determining unit 54 is configured to determine, from the primary key sequence of the current memory cache, a primary key allocated to service data if there is an unallocated primary key in the primary key sequence of the current memory cache;
and the second determining unit 55 is configured to read the primary key sequence from the database and load the primary key sequence into the memory if there is no unassigned primary key in the primary key sequence cached in the current memory, and determine the primary key allocated for the service data from the primary key sequence currently loaded into the memory.
The specific principle and execution process of each unit in the main key allocation device disclosed in the above embodiment of the present invention are the same as those of the main key allocation method disclosed in the above embodiment of the present invention, and may refer to corresponding parts in the main key allocation method disclosed in the above embodiment of the present invention, and will not be described in detail here.
The application provides a primary key distribution device, when service data of a distributed primary key exists, detecting whether a primary key which is not distributed in a primary key sequence of a memory cache when primary key distribution service is stopped is stored in a locally stored first configuration file, and if the primary key which is not distributed is not stored in the first configuration file, detecting whether the primary key which is not distributed exists in the primary key sequence of the current memory cache; if the main key sequence of the current memory cache stores the main key which is not allocated, determining the main key which is allocated to the service data from the main key sequence of the current memory cache; if the main key sequence of the current memory cache does not store the main key which is not allocated, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated for the service data from the main key sequence which is currently loaded into the memory. According to the primary key allocation method, the primary keys which are not allocated in the primary key sequence of the memory cache when the primary key allocation service is stopped are stored by presetting the first configuration file in the local, so that the waste of the primary keys can be effectively avoided. And detecting whether the unallocated primary key sequence is stored in the primary key sequence in the current memory cache or not by detecting the first locally stored configuration file and when the unallocated primary key is not stored in the first configuration file, and if the unallocated primary key sequence is not stored in the primary key sequence in the current memory cache, reading the primary key sequence in the database, thereby avoiding frequent operation on the database and further reducing performance consumption of the distributed system.
Further, the primary key allocation device provided in the embodiment of the present application further includes:
and the third determining unit is used for determining the main key allocated to the service data from the unassigned main keys of the first configuration file if the unassigned main keys are stored in the first configuration file.
In this embodiment of the present application, the reading primary key sequence from the database is loaded into the memory, and the second determining unit includes:
the second reading unit is used for reading a first main key, a second main key and a step length which are stored in the database and related to the service data;
a third main key determination unit configured to take the sum of the first main key and the step size as a third main key;
a comparison unit for comparing the second main key with the third main key;
a primary key sequence reading unit, configured to update the first primary key in the database to a third primary key and load the primary key sequence into the memory, where the first primary key is used as a start primary key of the primary key sequence and the third primary key is used as an end primary key of the primary key sequence if the third primary key is not greater than the second primary key;
and the return unit is used for returning error information if the third main key is larger than the second main key.
Further, the primary key allocation device provided in the embodiment of the present application further includes:
The judging unit is used for judging whether unassigned main keys exist in the main key sequence in the memory cache or not when the main key assignment service is detected to stop;
and the storage unit is used for storing the unassigned primary key in the primary key sequence in the memory cache to the first configuration file if the unassigned primary key exists in the primary key sequence in the memory cache.
Further, the primary key allocation device provided in the embodiment of the present application, when there is service data to be allocated with a primary key, includes: when the application process has service data to be allocated with the primary key, the device further comprises:
the third reading unit is used for reading a second configuration file, and the second configuration file comprises the current state information of the application process;
the third detection unit is used for detecting whether the state information represents that the application process is in a stop running state;
correspondingly, the first reading unit is also for: and if the state information indicates that the application program is not in the running stop state, reading the first configuration file stored locally.
Further, the primary key allocation device provided in the embodiment of the present application further includes:
the first acquisition unit is used for acquiring a first quantity, a second quantity and a total working time length of each server in at least one server when receiving a database registration request, wherein the first quantity is the total quantity of the service quantity of the assigned main key in the server, and the second quantity is the total quantity of the service data of the main key to be assigned in the server;
The computing unit is used for computing the matching degree of the server and the service registration request according to the first number, the second number and the total working duration of the server;
and the allocation unit is used for allocating the database registration request to the target server with the highest matching degree with the database registration request in the at least one server.
Further, the primary key allocation device provided in the embodiment of the present application further includes:
the fourth reading unit is used for reading a second configuration file, and the second configuration file comprises the current state information of the target server;
the second acquisition unit is used for acquiring basic information related to the target server if the state information represents that the target server is in an operation state, wherein the basic information is used for recording service data of a main key to be allocated to the target server currently;
and the control unit is used for controlling the target server to carry out primary key allocation for the service data to be allocated currently.
The following describes in detail a hardware structure of a server to which the primary key allocation method provided in the embodiment of the present application is applicable, taking an example in which the primary key allocation method is applied to the server.
The primary key allocation method provided by the embodiment of the invention can be applied to a server, wherein the server can be a service device for providing services for users on a network side, and the server can be a server cluster formed by a plurality of servers or a single server.
Optionally, fig. 6 is a block diagram showing a hardware structure of a server to which the primary key allocation method provided in the embodiment of the present application is applicable, and referring to fig. 6, the hardware structure of the server may include: a processor 61, a memory 62, a communication interface 63 and a communication bus 64;
in the embodiment of the present invention, the number of the processor 61, the memory 62, the communication interface 63 and the communication bus 64 may be at least one, and the processor 61, the memory 62 and the communication interface 63 complete communication with each other through the communication bus 64;
the memory 62 may comprise a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory) or the like, such as at least one disk memory;
wherein the memory stores a program, and the processor is operable to invoke the program stored in the memory, the program being operable to:
when the business data of the main key to be allocated exist, a first configuration file stored locally is read, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of a memory cache when main key allocation service is stopped;
Detecting whether unassigned primary keys are stored in the first configuration file;
if the unassigned primary key is not stored in the first configuration file, detecting whether the unassigned primary key exists in the primary key sequence of the current memory cache;
if the main key sequence of the current memory cache stores the main key which is not allocated, determining the main key which is allocated to the service data from the main key sequence of the current memory cache;
if the main key sequence of the current memory cache does not store the main key which is not allocated, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key which is allocated for the service data from the main key sequence which is currently loaded into the memory.
The function of the program may be referred to in the above description of a primary key allocation method provided in the embodiments of the present application, which is not described herein.
Further, the embodiment of the application also provides a computer storage medium, and the computer storage medium stores computer executable instructions for executing the main key allocation method.
For details of the computer executable instructions, reference is made to the above detailed description of a primary key allocation method provided in the embodiments of the present application, which is not repeated here.
The above description of the present invention provides a key allocation method, device, server and storage medium, and specific examples are applied to illustrate the principles and embodiments of the present invention, and the above description of the examples is only used to help understand the method and core idea of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.
It should be noted that, in the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described as different from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
It is further noted that 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. Moreover, 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, or is intended to include, elements inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A primary key assignment method, comprising:
when business data to be allocated with the main key exists, reading a first configuration file stored locally, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of a memory cache when main key allocation service is stopped;
detecting whether unassigned primary keys are stored in the first configuration file;
if the first configuration file does not store the unassigned primary key, detecting whether the unassigned primary key exists in the primary key sequence of the memory cache currently;
if the main key sequence of the current memory cache has an unallocated main key, determining the main key allocated to the service data from the main key sequence of the current memory cache;
If the main key sequence of the memory cache does not exist unassigned main keys, reading the main key sequence from a database, loading the main key sequence to the memory, and determining the main key assigned to the service data from the main key sequence currently loaded to the memory.
2. The method according to claim 1, wherein the method further comprises:
and if the unassigned primary key is stored in the first configuration file, determining the primary key assigned to the service data from the unassigned primary keys of the first configuration file.
3. The method of claim 1, wherein the reading the primary key sequence from the database is loaded into the memory, comprising:
reading a first primary key, a second primary key and a step length which are stored in the database and are related to the service data;
taking the sum of the first main key and the step length as a third main key;
comparing the second primary key with the third primary key;
if the third main key is not larger than the second main key, using the first main key as a starting main key of a main key sequence and the third main key as an ending main key of the main key sequence, updating the first main key in the database into the third main key, and loading the main key sequence into the memory;
And if the third main key is larger than the second main key, returning error information.
4. The method according to claim 1, wherein the method further comprises:
when the main key allocation service is detected to stop, judging whether unallocated main keys exist in a main key sequence in the memory cache;
and if the main key sequence in the memory cache has the main key which is not allocated, storing the main key which is not allocated in the main key sequence in the memory cache into the first configuration file.
5. The method of claim 1, wherein when there is traffic data to be assigned a primary key, comprising: when the application process has service data to be allocated with the primary key, the method further comprises:
reading a second configuration file, wherein the second configuration file comprises current state information of the application process;
detecting whether the state information characterizes that the application process is in a stop running state;
the reading of the locally stored first configuration file includes: and if the state information indicates that the application process is not in the running stopping state, reading a first configuration file stored locally.
6. The method of claim 5, wherein the method further comprises:
When a database registration request is received, a first quantity, a second quantity and a total working time length of each server in at least one server are obtained, wherein the first quantity is the total quantity of the service quantity of the main key allocated in the server, and the second quantity is the total quantity of the service data of the main key to be allocated in the server;
calculating the matching degree of the server and the service registration request according to the first number, the second number and the total working time length of the server;
and distributing the database registration request to a target server with highest matching degree with the database registration request in the at least one server.
7. The method of claim 5, wherein the method further comprises:
reading a second configuration file, wherein the second configuration file comprises current state information of a target server;
if the state information represents that the target server is in an operation state, acquiring basic information related to the target server, wherein the basic information is used for recording service data of a main key to be allocated to the target server currently;
and controlling the target server to carry out primary key allocation for the service data to be allocated currently.
8. A primary key distribution device, comprising:
the first reading unit is used for reading a first configuration file stored locally when the service data of the main key to be allocated exist, wherein the first configuration file comprises main keys which are not allocated in a main key sequence of the memory cache when the main key allocation service is stopped;
a first detection unit, configured to detect whether an unassigned primary key is stored in the first configuration file;
the second detection unit is used for detecting whether the unassigned primary key exists in the primary key sequence of the memory cache currently if the unassigned primary key is not stored in the first configuration file;
the first determining unit is used for determining the primary key allocated to the service data from the primary key sequence of the current memory cache if the primary key sequence of the current memory cache has the primary key which is not allocated;
and the second determining unit is used for reading the main key sequence from the database and loading the main key sequence to the memory if the main key sequence cached in the memory does not exist unassigned main keys currently, and determining the main key assigned to the service data from the main key sequence loaded to the memory currently.
9. A server, comprising: at least one memory and at least one processor; the memory stores a program, and the processor calls the program stored in the memory, the program being for implementing the primary key allocation method according to any one of claims 1 to 7.
10. A computer-readable storage medium having stored therein computer-executable instructions for performing the primary key assignment method as recited in any one of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010326648.3A CN111523002B (en) | 2020-04-23 | 2020-04-23 | Main key distribution method, device, server and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010326648.3A CN111523002B (en) | 2020-04-23 | 2020-04-23 | Main key distribution method, device, server and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111523002A CN111523002A (en) | 2020-08-11 |
CN111523002B true CN111523002B (en) | 2023-06-09 |
Family
ID=71902959
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010326648.3A Active CN111523002B (en) | 2020-04-23 | 2020-04-23 | Main key distribution method, device, server and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111523002B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113190554A (en) * | 2021-04-30 | 2021-07-30 | 平安养老保险股份有限公司 | Method for generating primary key and distributed system |
CN113313583A (en) * | 2021-06-25 | 2021-08-27 | 中国农业银行股份有限公司 | Integral clearing method and related device |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2017008657A1 (en) * | 2015-07-14 | 2017-01-19 | 阿里巴巴集团控股有限公司 | Method and system for acquiring data snapshot |
CN107977446A (en) * | 2017-12-11 | 2018-05-01 | 江苏润和软件股份有限公司 | A kind of memory grid data load method based on data partition |
CN108694218A (en) * | 2017-04-12 | 2018-10-23 | 大唐移动通信设备有限公司 | A kind of method and apparatus data write-in and read |
CN110162573A (en) * | 2019-05-05 | 2019-08-23 | 中国银行股份有限公司 | A kind of distribution sequence generating method, apparatus and system |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9953054B2 (en) * | 2013-04-22 | 2018-04-24 | Salesforce.Com, Inc. | Systems and methods for implementing and maintaining sampled tables in a database system |
-
2020
- 2020-04-23 CN CN202010326648.3A patent/CN111523002B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2017008657A1 (en) * | 2015-07-14 | 2017-01-19 | 阿里巴巴集团控股有限公司 | Method and system for acquiring data snapshot |
CN108694218A (en) * | 2017-04-12 | 2018-10-23 | 大唐移动通信设备有限公司 | A kind of method and apparatus data write-in and read |
CN107977446A (en) * | 2017-12-11 | 2018-05-01 | 江苏润和软件股份有限公司 | A kind of memory grid data load method based on data partition |
CN110162573A (en) * | 2019-05-05 | 2019-08-23 | 中国银行股份有限公司 | A kind of distribution sequence generating method, apparatus and system |
Non-Patent Citations (2)
Title |
---|
冯周 ; 左鹏飞 ; 刘进军 ; .大数据存储技术进展.科研信息化技术与应用.2015,(01),全文. * |
张东 ; 亓开元 ; 吴楠 ; 辛国茂 ; 刘正伟 ; 颜秉珩 ; 郭锋 ; .云海大数据一体机体系结构和关键技术.计算机研究与发展.2016,(02),全文. * |
Also Published As
Publication number | Publication date |
---|---|
CN111523002A (en) | 2020-08-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111523002B (en) | Main key distribution method, device, server and storage medium | |
CN110196860B (en) | Unique identifier allocation method and device, electronic equipment and storage medium | |
CN106230997B (en) | Resource scheduling method and device | |
CN107733957B (en) | Distributed service configuration system and version number distribution method | |
WO2009098547A1 (en) | Memory management | |
US11314689B2 (en) | Method, apparatus, and computer program product for indexing a file | |
US11681447B2 (en) | Method, device and computer program product of balance of storage space for file system | |
CN113691596B (en) | Gateway control method and device, electronic equipment and storage medium | |
CN110858162A (en) | Memory management method and device and server | |
CN110727517A (en) | Memory allocation method and device based on partition design | |
CN115617762A (en) | File storage method and equipment | |
US20090100436A1 (en) | Partitioning system including a generic partitioning manager for partitioning resources | |
CN101308467A (en) | Task processing method and device | |
CN117075815A (en) | Disk data buffer management method, device, equipment and storage medium | |
CN110825732A (en) | Data query method and device, computer equipment and readable storage medium | |
CN107632944B (en) | Method and device for reading data | |
JP2007317176A (en) | Terminal unit | |
KR101383793B1 (en) | Apparatus and method for memory allocating in system on chip | |
CN113742253A (en) | Storage medium management method, device, equipment and computer readable storage medium | |
CN111147556A (en) | Load balancing method, device, equipment and storage medium | |
JP5641300B2 (en) | Storage system and memory cache area control method for storage system | |
KR100758282B1 (en) | Apparatus for managing memory using bitmap memory and its method | |
CN113391757A (en) | Node expansion method and device and migration node | |
CN114697393B (en) | Data storage method, device, equipment and medium | |
CN114444440B (en) | Identifier generation method, device, storage medium and system |
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 |