CN111523002A - Main key distribution method, device, server and storage medium - Google Patents

Main key distribution method, device, server and storage medium Download PDF

Info

Publication number
CN111523002A
CN111523002A CN202010326648.3A CN202010326648A CN111523002A CN 111523002 A CN111523002 A CN 111523002A CN 202010326648 A CN202010326648 A CN 202010326648A CN 111523002 A CN111523002 A CN 111523002A
Authority
CN
China
Prior art keywords
primary key
configuration file
primary
sequence
server
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.)
Granted
Application number
CN202010326648.3A
Other languages
Chinese (zh)
Other versions
CN111523002B (en
Inventor
郭峰
崔攸
周志境
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Agricultural Bank of China
Original Assignee
Agricultural Bank of China
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Agricultural Bank of China filed Critical Agricultural Bank of China
Priority to CN202010326648.3A priority Critical patent/CN111523002B/en
Publication of CN111523002A publication Critical patent/CN111523002A/en
Application granted granted Critical
Publication of CN111523002B publication Critical patent/CN111523002B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • YGENERAL 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
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE 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/00Energy 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

According to the method, the device, the server and the storage medium for distributing the primary keys, when business data of the primary keys to be distributed exist, a first configuration file stored locally is read, wherein the first configuration file comprises the primary keys which are not distributed in a primary key sequence cached in a memory when the primary key distribution service is stopped; detecting whether the first configuration file stores the unassigned primary key or not; if the first configuration file does not store the primary key which is not allocated, detecting whether the primary key which is not allocated exists in the primary key sequence cached in the current memory; if yes, determining a primary key distributed for the service data from the primary key sequence cached in the current memory; and if the main key sequence does not exist, reading the main key sequence from the database and loading the main key sequence into the memory, and determining the main key distributed 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 main key can be improved.

Description

Main key distribution method, device, server and storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method, an apparatus, a server, and a storage medium for assigning a primary key.
Background
The primary key allocation of service data in a server is an especially important part of data management of a distributed system. In a conventional primary key allocation method, when there is service data of a primary key to be allocated in a server, the primary key is acquired by accessing primary key configuration information in a database. The traditional primary key allocation method can frequently operate the primary key configuration information in the database, and the performance of the distributed system can be seriously consumed by frequently operating the primary key configuration information in the database.
The existing primary key allocation method is that a server operates a database to read a segment of primary key sequence according to primary key configuration information in the database and loads the segment of primary key sequence into a memory, and then when the server has service data of primary keys to be allocated, the primary keys are allocated to the service data according to the primary key sequence in the memory. Although the existing primary key distribution mode can realize primary key distribution of a plurality of service data in the server 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 crashed unexpectedly, the main key sequence currently stored in the memory of the server is deleted, if the server is restarted, a section of main key sequence is read from the database again, and then when the server is crashed out, the main keys which are not distributed in the main key sequence in the memory are wasted.
Disclosure of Invention
In view of this, embodiments of the present application provide a method, an apparatus, a server, and a storage medium for assigning a primary key, so as to achieve the purposes of reducing performance consumption of a distributed system and improving utilization rate of the primary key.
The technical scheme is as follows:
the invention discloses a primary key distribution method in a first aspect, which comprises the following steps:
when business data of a primary key to be allocated exist, reading a first configuration file stored locally, wherein the first configuration file comprises the primary key which is not allocated in a primary key sequence cached in a memory when the primary key allocation service is stopped;
detecting whether the first configuration file stores an unassigned primary key or not;
if the first configuration file does not store the primary key which is not allocated, detecting whether the primary key which is not allocated exists in the primary key sequence of the current memory cache;
if an unallocated primary key exists in the primary key sequence of the current memory cache, determining the primary key allocated to the service data from the primary key sequence of the current memory cache;
and if the main key sequence cached in the memory does not have an unallocated main key, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated to the service data from the main key sequence currently loaded into the memory.
Optionally, the method further includes:
and if the unassigned primary key is stored in the first configuration file, determining the primary key allocated to the service data from the unassigned primary key of the first configuration file.
Optionally, the reading the primary key sequence from the database and loading the primary key sequence into the memory includes:
reading a first main key, a second main key and a step length which are stored in the database and are related to the service data;
taking the sum of the first primary key and the step size as a third primary key;
comparing the second primary key and the third primary key;
if the third primary key is not larger than the second primary key, taking the first primary key as a starting primary key of a primary key sequence and taking the third primary key as an ending primary key of the primary key sequence, updating the first primary key in the database into the third primary key, and loading the primary key sequence into the memory;
and if the third primary key is larger than the second primary key, returning error information.
Optionally, the method further includes:
when the primary key distribution service is detected to stop, judging whether an unallocated primary key exists in a primary key sequence in the memory cache;
and if the primary key sequence in the memory cache has an unallocated primary key, storing the unallocated primary key in the primary key sequence in the memory cache to 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 business data to be allocated with the primary key, the method further comprises the following steps:
reading a second configuration file, wherein the second configuration file comprises the current state information of the application process;
detecting whether the state information represents that the application process is in a stop operation state or not;
the reading the locally stored first configuration file includes: and if the state information represents that the application program is not in the operation stop state, reading a first configuration file stored locally.
Optionally, the method further includes:
when a database registration request is received, acquiring a first quantity, a second quantity and a total working time of each server in at least one server, wherein the first quantity is the total quantity of the service quantities of the primary keys which are distributed in the servers, and the second quantity is the total quantity of the service data of the primary keys to be distributed in the servers;
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 of the server;
and distributing the database registration request to a target server which is matched with the database registration request to the highest degree in the at least one server.
Optionally, the method further includes:
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 operating state, acquiring basic information related to the target server, wherein the basic information is used for recording service data of a current primary key to be allocated to the target server;
and controlling the target server to perform primary key distribution on the current service data to be distributed.
A second aspect of the present invention discloses a primary key assigning apparatus, comprising:
the device comprises a first reading unit, a second reading unit and a third reading unit, wherein the first reading unit is used for reading a first configuration file stored locally when business data of a primary key to be allocated exist, and the first configuration file comprises the primary key which is not allocated in a primary key sequence cached in a memory when the primary key allocation service is stopped;
the first detection unit is used for detecting whether the first configuration file stores unassigned primary keys or not;
the second detection unit is used for detecting whether an unallocated primary key exists in a primary key sequence of the current memory cache if the unallocated primary key does not exist in the first configuration file;
a first determining unit, configured to determine, if an unassigned primary key exists in the primary key sequence of the current memory cache, a primary key allocated to the service data from the primary key sequence of the current memory cache;
and the second determining unit is used for reading the primary key sequence from the database and loading the primary key sequence into the memory if the unallocated primary key does not exist in the primary key sequence of the current memory cache, and determining the primary key allocated to the service data from the primary key sequence currently loaded into the memory.
A 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, wherein the program is used for realizing the primary key allocation method disclosed in any one of the first aspect of the invention.
A fourth aspect of the present invention discloses a computer-readable storage medium having stored thereon computer-executable instructions for performing the primary key assignment method as disclosed in any one of the first aspects of the present invention above.
The application provides a primary key allocation method, a primary key allocation device, a server and a storage medium, when business data of allocated primary keys exist, whether an unallocated primary key in a primary key sequence of a memory cache when a primary key allocation service is stopped is stored in a first configuration file stored locally is detected, and if the unallocated primary key is not stored in the first configuration file, whether the unallocated primary key 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 for the service data from the main key sequence of the current memory cache; and if the unallocated primary key is not stored in the primary key sequence cached in the current memory, reading the primary key sequence from the database, loading the primary key sequence into the memory, and determining the primary key allocated to the service data from the primary key sequence currently loaded into the memory. The primary key allocation method stores the primary keys which are not allocated in the primary key sequence of the memory cache when the primary key allocation service is stopped by presetting the first configuration file in the local area, and can effectively avoid the waste of the primary keys. And under the condition that the first configuration file stored locally does not store the unallocated primary key and the primary key sequence in the current memory cache does not store the unallocated primary key, the primary key sequence is read from the database, so that frequent operation on the database is avoided, and the 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 used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a schematic flowchart of a method for assigning a primary key according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating 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 schematic flowchart of another primary key allocation method according to an embodiment of the present invention;
fig. 4 is a schematic flowchart of a database registration request allocation method 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 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 by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present 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 an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
As shown in fig. 1, the present invention provides a primary key assignment method, which is applicable to a server. The method for allocating the main key specifically comprises the following steps:
s101: when business data of a primary key to be allocated exist, reading a first configuration file stored locally, wherein the first configuration file comprises the primary key which is not allocated in a primary key sequence cached in a memory when the primary key allocation service is stopped;
in the embodiment of the application, for each server in the distributed system, a first configuration file is set locally in the server in advance, the first configuration file set locally in the server is initially empty, and when the primary key allocation service of the server is stopped, the first configuration file is used for storing the primary key which is not allocated in the primary key sequence cached in the server memory to the first configuration file locally in the server. When the server has the service data of the primary key to be allocated, reading a first configuration file stored locally so as to judge whether the first configuration file stores the primary key which is not allocated, and further executing corresponding operation according to the detection result.
S102: detecting whether the first configuration file stores the unassigned primary key or not; 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, go to step S106.
In the specific execution process of step S102, after reading the first configuration file, 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 cached in a current memory of the server; and if the first configuration file stores the primary key which is not allocated, directly determining the primary key which is allocated to the service data from the first configuration file. If the first configuration file does not store the unallocated primary keys, detecting whether the unallocated primary keys exist in the primary key sequence of the current memory cache, and further executing corresponding operation according to a detection result.
S103: detecting whether an unallocated primary key exists in a primary key sequence of a current memory cache; if the primary key sequence of the current memory cache has an unallocated primary key; executing step S104; if the primary key sequence in the current memory cache does not have an unassigned primary key, go to step S105.
In the process of specifically executing step S103, when an unassigned primary key is not stored in the first configuration file, detecting whether an unassigned primary key exists in a primary key sequence of a current memory cache of the server, and if an unassigned primary key exists in a primary key sequence of a current memory cache, determining a 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 cache does not have an unallocated main key, reading the main key sequence from the database and loading the main key sequence into the memory, and determining the main key sequence from the main key sequence currently loaded into the memory as the main key of business data allocation.
S104: determining a primary key distributed for the service data from a primary key sequence cached in a current memory;
in the process of specifically executing step S104, when it is detected that an unassigned primary key exists in the primary key sequence of the current memory cache, the primary key assigned to the service data is determined from the primary key sequence of 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 distributed for service data from the main key sequence currently loaded into the memory;
referring to fig. 2, a schematic flow chart 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 is shown, where 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 are related to service data;
in the embodiment of the application, when it is detected that an unassigned primary key does not exist in a primary key sequence of a current memory cache, a data table related to service data and stored in a database is read, and the second primary key is read. Wherein the data table comprises a first primary 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 is stored in the database and can be allocated to the server, and the step length is the number of the primary keys of the primary key sequence which need to be read from the database.
It should be noted that 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 allocated to server Step length S
It should be noted that, in the embodiment of the present application, before reading the first primary key, the second primary key, and the step length related to the business data stored in the database, the primary key record in the database (the primary key record is used to record the primary key that has been allocated in the database) may be locked, and it may be avoided that the primary key that has been allocated is read when the primary key sequence is read from the database.
S202: taking the sum of the first primary key and the step length as a third primary key;
in the specific process of 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 a result obtained by adding the first primary key and the step length is used as a third primary key.
For example, the number of the first primary keys read from the database and related to the business data is 1000, that is, the number of the primary keys currently allocated in the database is 1000; the step length of reading is 100, namely a primary key sequence consisting of 100 primary keys needs to be read from a database; the addition of the first primary key and the step size, i.e. 1000+100, results in 1100, and the addition of the first primary key and the step size results in the third primary key, i.e. the third primary key equals 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, go to step S205.
In the process of specifically executing step S203, after the sum of the first primary key and the step length is used as a third primary key, comparing the second primary key with the third primary key, and if the third primary key is not greater than the second primary key, it indicates that the unassigned primary key in the database is still sufficient to be applied, that is, the primary key sequence can be read from the database; if the third primary key is larger than the second primary key, it is indicated that the unassigned primary key in the database is not sufficiently applied, that is, the primary key sequence cannot be read from the database, and error information is output to prompt that the primary key sequence cannot be read from the database at present.
For example, when the third primary key is 1100, if the second primary key read from the database and related to the business data is 10000, it indicates that the third primary key is not greater than the second primary key, and further indicates that the primary key sequence can be read from the database; if 1090 is read from the database, the second primary key related to the service data is indicated, the third primary key is larger than the second primary key, the fact that the primary key sequence cannot be read from the database is further indicated, error information is output, and it is prompted that the primary key sequence cannot be read from the database at present.
S204: taking the first primary key as a starting primary key of a primary key sequence and taking the third primary key as an ending primary key of the primary key sequence, updating the first primary key in the database into the third primary key, and loading the primary key sequence into a memory;
in the process of specifically executing step S204, when the third primary key is not greater than the second primary key, that is, when the primary key sequence can be read from the database, the first primary key is used as the starting primary key of the primary key sequence, the third primary key is used as the ending primary key of the primary key sequence, the primary key sequence is read from the database, and the read primary 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 that the condition of the currently allocated primary key in the database is recorded.
For example, when the first primary key related to the business data is read from the database and is 1000, that is, the number of the primary keys currently allocated in the database is 1000; when a step size of 100 is read, i.e. a sequence of primary keys consisting of 100 primary keys needs to be read from the database. If the third primary key is smaller than the second primary key, taking 1000 as the initial primary key of the primary key sequence, taking 1100 as the ending primary key of the primary key sequence, reading the primary key sequence (1000-plus 1100) from the database, loading the read primary key sequence into the memory and updating the first primary key to the third primary key, namely updating the numerical value 1000 of the first primary key to the numerical value 1100 of the third primary key, and the updated numerical value of the first primary key is 1100.
After the first primary key is updated to the third primary key, the lock is released from the record of the previously locked primary key.
S205: and returning error information.
In the embodiment of the application, when it is detected that an unallocated primary key does not exist in a primary key sequence cached in a current memory, a first primary key, a second primary key and a step length which are stored in a database and are related to service data are read, the sum of the first primary key and the step length is used as a third primary key, and then 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 cannot be read from the database, and an error message is returned to prompt that the main key sequence cannot be read from the database at present.
S106: determining a primary key distributed for the service data from the unassigned primary 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 key of the first configuration file.
In the embodiment of the application, when it is detected that the unassigned primary key is stored in the first configuration file, the primary key allocated for the service data is determined from the unassigned primary key of the first configuration file. The method can greatly wait when different nodes simultaneously access the data updating main key, and improve the distribution efficiency of the main key.
S107: when the primary key distribution service is detected to stop, judging whether an unallocated primary key exists in a primary key sequence in a memory cache; if there is an unallocated primary key in the primary key sequence in the memory cache, go to step S108.
In the embodiment of the application, when the primary key allocation service is detected to stop, whether an unallocated primary key exists in a primary key sequence in the memory cache is detected, and if the unallocated primary key exists in the primary key sequence in the memory cache, the unallocated primary key in the primary key sequence in the memory cache is stored in the first configuration file. When the business data of the primary key to be distributed exists, the primary key can be directly distributed to the business data through the primary key which is stored in the first configuration file and is not distributed, so that the distribution efficiency of the primary key can be improved, and the waste of the primary 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 an accident occurs (for example, the server goes down unexpectedly), it may be considered that the primary key allocation service of the server is stopped, at this time, it may be determined whether there is an unassigned primary key in the primary key sequence in the memory cache, and 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 in the first configuration file, thereby avoiding the waste of the primary keys.
In addition, in the prior art, the database is used to record the current use condition of the primary key of the server, and a piece of primary key configuration information for maintaining the server needs to be added in the database every time a server is added, which may cause certain difficulty in the expandability of the distributed system. Therefore, the invention presets the first configuration information related to each server in the distributed system, and further can record the current primary key use condition of the server by using the first configuration file. The use condition of the current primary key of the server is recorded by using the first configuration file, so that the use condition of the current primary key of the server stored by using a database can be avoided.
S108: and storing the primary key which is not allocated in the primary key sequence in the memory cache to a first configuration file.
The method for distributing the primary keys comprises the steps that when business data of the distributed primary keys exist, whether the first configuration file stored locally stores the primary keys which are not distributed in a primary key sequence cached when the primary key distribution service is stopped is detected, and if the first configuration file stores the primary keys which are not distributed, the primary keys distributed to the business data are directly determined from the first configuration file; if the first configuration file does not store the primary key which is not allocated, detecting whether the primary key which is not allocated exists in the primary key sequence cached in the current memory; 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 for the service data from the main key sequence of the current memory cache; if the main key sequence cached in the current memory does not store the unallocated main key, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated to the service data from the main key sequence currently loaded into the memory; when detecting that the primary key sequence of the memory cache has the primary key which is not allocated, storing the primary key sequence of the memory cache which is not allocated into the first configuration file, and when the service data of the primary key to be allocated exists, directly allocating the primary key for the service data through the primary key which is stored in the first configuration file and is not allocated, so that the allocation efficiency of the primary key can be improved, and the waste of the primary key can be effectively avoided.
In addition, the primary key allocation method reads the primary key sequence from the database under the condition that the first configuration file stored locally is detected not to store the unassigned primary key and the primary key sequence in the current memory cache is detected not to store the unassigned primary key, so that frequent operation on the database is avoided, and the performance consumption of the distributed system is reduced.
Further, when there is service data to be allocated with the primary key, the method includes: when there is service data to be assigned with a primary key in an application process, as shown in fig. 3, a flowchart of another primary key assignment method provided in an embodiment of the present invention is shown. The method for allocating the main key specifically comprises the following steps:
s301: reading a second configuration file, wherein the second configuration file comprises the current state information of the application process;
in the embodiment of the application, for each server in at least one server, a second configuration file corresponding to the server is preset, and the second configuration file comprises current state information of an application process on the server. The current state information of the application process can be in an operating state or in a stop operating state.
In the specific process of executing step S301, when the application process on the server has service data to be assigned 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 operation state or not; if the state information indicates that the application process is not in the stop operation state, step S303 is executed.
In the specific process of executing step S302, when the second configuration file is read, detecting whether state information in the second configuration file represents that the application process is not in a stop operation state; and if the state information indicates that the application process is not in the running stop state, namely the application process is in the running state, reading a first configuration file stored locally. And if the state information represents that the application process is in a stop running state, ending the current primary key distribution service.
S303: reading a first configuration file stored locally, wherein the first configuration file comprises primary keys which are not allocated in a primary key sequence cached in a memory when primary key allocation service is stopped;
s304: detecting whether the first configuration file stores the unassigned primary key or not; if the first configuration file does not store the unassigned primary key, go to step S305; if the first configuration file stores the unassigned primary key, go to step S308.
S305: detecting whether an unallocated primary key exists in a primary key sequence of a current memory cache; if the primary key sequence of the current memory cache has an unallocated primary key; executing step S306; if the primary key sequence in the current memory cache does not have an unassigned primary key, go to step S307.
S306: determining a primary key distributed for the 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 distributed for service data from the main key sequence currently loaded into the memory;
s308: determining a primary key distributed for the service data from the unassigned primary keys of the first configuration file;
s309: when the primary key distribution service is detected to stop, judging whether an unallocated primary key exists in a primary key sequence in a memory cache; if there is an unallocated primary key in the primary key sequence in the memory cache, step S310 is executed.
S310: and storing the primary key which is not allocated in the primary key sequence in the memory cache to a first configuration file.
In the process of specifically executing step S303 to step S310, the specific implementation principle and the execution process of step S303 to step S310 are the same as those of step S101 to step S108 disclosed in fig. 1, and reference may be made to the corresponding parts disclosed in fig. 1, which are not described herein again.
In the embodiment of the application, when the application process has the service data of the primary key to be distributed, 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 or not; under the condition that the state information represents that the application process is not in the stop operation state, reading a first configuration file; if the state information represents that the application process is in the stop operation state, the primary key distribution service of this time is ended, and unnecessary primary key application can be avoided.
Further, on the basis of each of the above-disclosed primary key assignment methods, as shown in fig. 4, the method specifically includes the following steps:
s401: when a database registration request is received, acquiring a first quantity, a second quantity and total working time 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 when the task distribution server receives the database registration request, acquiring the first quantity, the second quantity and the total working time of each server except the task distribution server in at least one server. The first quantity is the total quantity of the service data of the primary key which is distributed in the server, the second quantity is the total quantity of the service data of the primary key which is to be distributed in the server, and the total working time is the working time of the server for processing the total quantity of the service data of the primary key which is distributed.
It should be noted that each server of the at least one server may be a task distribution server.
S402: calculating the matching degree of the server and the database registration request according to the first quantity, the second quantity and the total working time of the servers;
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 obtained, the matching degree between 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 the at least one server, according to the first number, the second number, and the total operating time of the servers, the manner of calculating the matching degree between the server and the registration request may be: first quantity/total working duration/second data quantity. The following formula is shown in detail:
match_rate=amt1/time/atm2
the match _ rate is the matching degree of the server and the database registration request, the amt1 is a first quantity, the time is the total working duration, and the atm2 is a second quantity.
As can be seen from the above formula, for each server in at least one server, the greater the first number/total operating time 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 the highest matching degree with the database registration request in at least one server;
in the specific process of executing 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 degrees between the servers and the database registration request are sorted from high to low, the server with the highest matching degree with the database registration request in the at least one server is used as the target service, and the database registration request is distributed to the target server.
In the embodiment of the application, when a database registration request is received, a first number, a second number and a total working time of each server in at least one server are obtained, for each server in at least one server, according to the first number, the second number and the total working time of the server, the matching degree of the server and the database registration request is calculated, the database registration request is distributed to a target server which is the highest in matching degree with the database registration request in at least one server, and therefore the purpose of load balancing of server performance is achieved.
S404: reading a second configuration file, wherein the second configuration file comprises current state information of a target server;
in the embodiment of the application, for each server in at least one server, a second configuration file corresponding to the server is preset, and the second configuration file comprises current state information of the server. The current state information of the server can be in an operating state or in a stop operating state.
In the embodiment of the present application, after the database registration request is assigned 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 represents that the target server is in the running state, executing step S406;
in the process of specifically executing 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 the running state; and if the state information represents that the target server is in the running state, acquiring the service data of the current primary key to be allocated with the target server, and further controlling the target server to perform primary key allocation on the service data of the current primary 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 current primary key to be distributed to the target server;
s407: and the control target server performs primary key distribution on the current service data to be distributed.
In this embodiment of the 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 current primary key to be allocated to the target server is obtained, and the target server is controlled to perform primary key allocation on the current service data to be allocated, so that the target server finishes processing the current service data of the primary key to be allocated.
Referring to fig. 5, a schematic structural diagram of a primary key distribution device provided in 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 of a primary key to be allocated, where the first configuration file includes an unassigned primary key in a primary key sequence cached in a memory 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 of the current memory cache if the unassigned primary key is not stored in the first configuration file;
a first determining unit 54, configured to determine, if an unassigned primary key exists in the primary key sequence of the current memory cache, a primary key allocated to service data from the primary key sequence of the current memory cache;
a second determining unit 55, configured to, if an unassigned primary key does not exist in the primary key sequence of the current memory cache, read the primary key sequence from the database and load the primary key sequence into the memory, and determine, from the primary key sequence currently loaded into the memory, the primary key allocated to the service data.
The specific principle and the execution process of each unit in the primary key allocation apparatus disclosed in the above embodiment of the present invention are the same as those of the primary key allocation method disclosed in the above embodiment of the present invention, and reference may be made to corresponding parts in the primary key allocation method disclosed in the above embodiment of the present invention, and details are not described here again.
The application provides a primary key distribution device, when business data of a distributed primary key exists, whether an unallocated primary key in a primary key sequence of a memory cache when a primary key distribution service is stopped is stored in a first configuration file stored locally or not is detected, and if the unallocated primary key is not stored in the first configuration file, whether an unallocated primary key exists in the primary key sequence of the current memory cache or not 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 for the service data from the main key sequence of the current memory cache; and if the unallocated primary key is not stored in the primary key sequence cached in the current memory, reading the primary key sequence from the database, loading the primary key sequence into the memory, and determining the primary key allocated to the service data from the primary key sequence currently loaded into the memory. The primary key allocation method stores the primary keys which are not allocated in the primary key sequence of the memory cache when the primary key allocation service is stopped by presetting the first configuration file in the local area, and can effectively avoid the waste of the primary keys. And by detecting the first configuration file stored locally and detecting whether the unallocated primary key sequence is stored in the primary key sequence in the current memory cache when the unallocated primary key is not stored in the first configuration file, if the unallocated primary key sequence is 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 the performance consumption of the distributed system is reduced.
Further, the primary key distribution device provided in the embodiment of the present application further includes:
and the third determining unit is used for determining the primary key distributed to the service data from the unassigned primary keys of the first configuration file if the unassigned primary keys are stored in the first configuration file.
In this embodiment of the present application, the second determining unit reads the primary key sequence from the database and loads the primary key sequence into the memory, and includes:
the second reading unit is used for reading the first main key, the second main key and the step length which are stored in the database and are related to the service data;
a third primary key determination unit configured to take a sum of the first primary key and the step size as a third primary key;
a comparison unit for comparing the second primary key and the third primary key;
a primary key sequence reading unit, configured to, if the third primary key is not greater than the second primary key, take the first primary key as a starting primary key of the primary key sequence and take the third primary key as an ending primary key of the primary key sequence, update the first primary key in the database to the third primary key, and load the primary key sequence into the memory;
and the returning unit is used for returning error information if the third main key is larger than the second main key.
Further, the primary key distribution device provided in the embodiment of the present application further includes:
the judging unit is used for judging whether an unallocated primary key exists in a primary key sequence in a memory cache when the primary key allocation service is detected to stop;
and the storage unit is used for storing the unallocated primary keys in the primary key sequence in the memory cache to a first configuration file if the unallocated primary keys exist in the primary key sequence in the memory cache.
Further, the primary key assigning apparatus provided in this embodiment of the present application, when there is service data to be assigned with a primary key, includes: when the application process has business 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 operation state or not;
correspondingly, the first reading unit is further configured to: and if the state information indicates that the application program is not in the running stop state, reading a first configuration file stored locally.
Further, the primary key distribution device provided in the embodiment of the present application further includes:
the system comprises a first acquisition unit, a second acquisition unit and a first processing unit, wherein the first acquisition unit is used for acquiring a first quantity, a second quantity and a total working time of each server in at least one server when a database registration request is received, the first quantity is the total quantity of the business quantities of the primary keys which are distributed in the servers, and the second quantity is the total quantity of the business data of the primary keys to be distributed in the servers;
the computing unit is used for computing the matching degree of the server and the service registration request according to the first quantity, the second quantity and the total working duration of the server;
and the distribution unit is used for distributing the database registration request to a target server with the highest matching degree with the database registration request in at least one server.
Further, the primary key distribution 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 obtaining unit is used for obtaining basic information related to the target server if the state information represents that the target server is in the running state, wherein the basic information is used for recording service data of a current main key to be distributed to the target server;
and the control unit is used for controlling the target server to carry out primary key distribution on the current service data to be distributed.
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 applied, by taking the application of the primary key allocation method to the server as an example.
The method for allocating the primary key provided by the embodiment of the application can be applied to a server, wherein the server can be a service device which provides service for a user on a network side, can be a server cluster formed by a plurality of servers, and can also be a single server.
Optionally, fig. 6 is a block diagram illustrating a hardware structure of a server to which the primary key allocation method provided in the embodiment of the present application is applied, 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 mutual communication through the communication bus 64;
the processor 61 may be a central processing unit CPU, or an application specific integrated circuit asic, or one or more integrated circuits configured to implement embodiments of the present invention, or the like;
the memory 62 may include a high-speed RAM memory, and may further include a non-volatile memory (non-volatile memory) or the like, such as at least one disk memory;
wherein the memory stores a program, the processor may invoke the program stored in the memory, and the program is operable to:
when business data of a primary key to be allocated exist, reading a first configuration file stored locally, wherein the first configuration file comprises the primary key which is not allocated in a primary key sequence cached in a memory when the primary key allocation service is stopped;
detecting whether the first configuration file stores the unassigned primary key or not;
if the first configuration file does not store the primary key which is not allocated, detecting whether the primary key which is not allocated exists in the primary key sequence cached in the current memory;
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 for the service data from the main key sequence of the current memory cache;
and if the unallocated primary key is not stored in the primary key sequence cached in the current memory, reading the primary key sequence from the database, loading the primary key sequence into the memory, and determining the primary key allocated to the service data from the primary key sequence currently loaded into the memory.
For the functions of the program, reference may be made to the above detailed description of a method for assigning a primary key provided in the embodiments of the present application, which is not described herein again.
Further, an embodiment of the present application also provides a computer storage medium, where computer-executable instructions are stored in the computer storage medium, and the computer-executable instructions are used to execute the primary key allocation method.
For specific contents of the computer executable instructions, reference may be made to the above detailed description of a method for assigning a primary key provided in the embodiments of the present application, which is not described herein again.
The method, the device, the server and the storage medium for assigning the primary key provided by the present invention are described in detail above, and a specific example is applied in the present disclosure to explain the principle and the implementation of the present invention, and the description of the above embodiment is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
It is further noted that, herein, relational terms such as first and second, and the like may be 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 or 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 an … …" does not exclude the presence of other identical 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 of a primary key to be allocated exist, reading a first configuration file stored locally, wherein the first configuration file comprises the primary key which is not allocated in a primary key sequence cached in a memory when the primary key allocation service is stopped;
detecting whether the first configuration file stores an unassigned primary key or not;
if the first configuration file does not store the primary key which is not allocated, detecting whether the primary key which is not allocated exists in the primary key sequence of the current memory cache;
if an unallocated primary key exists in the primary key sequence of the current memory cache, determining the primary key allocated to the service data from the primary key sequence of the current memory cache;
and if the main key sequence cached in the memory does not have an unallocated main key, reading the main key sequence from the database, loading the main key sequence into the memory, and determining the main key allocated to the service data from the main key sequence currently loaded into the memory.
2. The method of claim 1, further comprising:
and if the unassigned primary key is stored in the first configuration file, determining the primary key allocated to the service data from the unassigned primary key of the first configuration file.
3. The method of claim 1, wherein reading the primary key sequence from the database is loaded into the memory, comprising:
reading a first main key, a second main key and a step length which are stored in the database and are related to the service data;
taking the sum of the first primary key and the step size as a third primary key;
comparing the second primary key and the third primary key;
if the third primary key is not larger than the second primary key, taking the first primary key as a starting primary key of a primary key sequence and taking the third primary key as an ending primary key of the primary key sequence, updating the first primary key in the database into the third primary key, and loading the primary key sequence into the memory;
and if the third primary key is larger than the second primary key, returning error information.
4. The method of claim 1, further comprising:
when the primary key distribution service is detected to stop, judging whether an unallocated primary key exists in a primary key sequence in the memory cache;
and if the primary key sequence in the memory cache has an unallocated primary key, storing the unallocated primary key in the primary key sequence in the memory cache to the first configuration file.
5. The method of claim 1, wherein when there is service data to be assigned a primary key, the method comprises: when the application process has business data to be allocated with the primary key, the method further comprises the following steps:
reading a second configuration file, wherein the second configuration file comprises the current state information of the application process;
detecting whether the state information represents that the application process is in a stop operation state or not;
the reading the locally stored first configuration file includes: and if the state information represents that the application program is not in the operation stop state, reading a first configuration file stored locally.
6. The method of claim 5, further comprising:
when a database registration request is received, acquiring a first quantity, a second quantity and a total working time of each server in at least one server, wherein the first quantity is the total quantity of the service quantities of the primary keys which are distributed in the servers, and the second quantity is the total quantity of the service data of the primary keys to be distributed in the servers;
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 of the server;
and distributing the database registration request to a target server which is matched with the database registration request to the highest degree in the at least one server.
7. The method of claim 5, further comprising:
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 operating state, acquiring basic information related to the target server, wherein the basic information is used for recording service data of a current primary key to be allocated to the target server;
and controlling the target server to perform primary key distribution on the current service data to be distributed.
8. A primary key assignment device, comprising:
the device comprises a first reading unit, a second reading unit and a third reading unit, wherein the first reading unit is used for reading a first configuration file stored locally when business data of a primary key to be allocated exist, and the first configuration file comprises the primary key which is not allocated in a primary key sequence cached in a memory when the primary key allocation service is stopped;
the first detection unit is used for detecting whether the first configuration file stores unassigned primary keys or not;
the second detection unit is used for detecting whether an unallocated primary key exists in a primary key sequence of the current memory cache if the unallocated primary key does not exist in the first configuration file;
a first determining unit, configured to determine, if an unassigned primary key exists in the primary key sequence of the current memory cache, a primary key allocated to the service data from the primary key sequence of the current memory cache;
and the second determining unit is used for reading the primary key sequence from the database and loading the primary key sequence into the memory if the unallocated primary key does not exist in the primary key sequence of the current memory cache, and determining the primary key allocated to the service data from the primary key sequence currently loaded into the memory.
9. A server, comprising: at least one memory and at least one processor; the memory stores a program that the processor calls, the program being used to implement the primary key allocation method according to any one of claims 1 to 7.
10. A computer-readable storage medium having stored thereon computer-executable instructions for performing the primary key assignment method of any one of claims 1-7.
CN202010326648.3A 2020-04-23 2020-04-23 Main key distribution method, device, server and storage medium Active CN111523002B (en)

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 true CN111523002A (en) 2020-08-11
CN111523002B 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)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113190554A (en) * 2021-04-30 2021-07-30 平安养老保险股份有限公司 Method for generating primary key and distributed system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140317087A1 (en) * 2013-04-22 2014-10-23 Salesforce.Com, Inc. Systems and methods for implementing and maintaining sampled tables in a database system
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

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140317087A1 (en) * 2013-04-22 2014-10-23 Salesforce.Com, Inc. Systems and methods for implementing and maintaining sampled tables in a database system
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)

* Cited by examiner, † Cited by third party
Title
冯周;左鹏飞;刘进军;: "大数据存储技术进展" *
张东;亓开元;吴楠;辛国茂;刘正伟;颜秉珩;郭锋;: "云海大数据一体机体系结构和关键技术" *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113190554A (en) * 2021-04-30 2021-07-30 平安养老保险股份有限公司 Method for generating primary key and distributed system

Also Published As

Publication number Publication date
CN111523002B (en) 2023-06-09

Similar Documents

Publication Publication Date Title
CN106230997B (en) Resource scheduling method and device
JP2013109756A (en) Method for tracking memory usages of data processing system
CN110858162B (en) Memory management method and device and server
JPH10254756A (en) Use of three-state reference for managing referred object
US11797453B2 (en) In-memory distributed cache
US20050166028A1 (en) Method and apparatus for adaptive garbage collection
US20100030994A1 (en) Methods, systems, and computer readable media for memory allocation and deallocation
US20190220443A1 (en) Method, apparatus, and computer program product for indexing a file
CN108829342B (en) Log storage method, system and storage device
CN110516465B (en) Resource address management method, device, equipment and computer readable storage medium
CN111722918A (en) Service identification code generation method and device, storage medium and electronic equipment
CN112615792B (en) Interface current limiting method and device
CN115617762A (en) File storage method and equipment
CN111523002B (en) Main key distribution method, device, server and storage medium
CN111385370A (en) ID allocation method, device, storage medium and ID allocation system
CN111291062A (en) Data synchronous writing method and device, computer equipment and storage medium
CN116880746A (en) Data processing method, device, electronic equipment and computer readable storage medium
CN110825732A (en) Data query method and device, computer equipment and readable storage medium
CN115858668A (en) Distributed transaction processing method, device, electronic device and storage medium
CN115907949A (en) Bank transaction data processing method and device
CN116069810A (en) Data query method and device and terminal equipment
CN113391757B (en) Node expansion method and device and migration node
CN111143288A (en) Data storage method, system and related device
CN113742253A (en) Storage medium management method, device, equipment and computer readable storage medium
KR101383793B1 (en) Apparatus and method for memory allocating in system on chip

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