CN109739930A - Date storage method, device based on distributed cache system, computer equipment - Google Patents
Date storage method, device based on distributed cache system, computer equipment Download PDFInfo
- Publication number
- CN109739930A CN109739930A CN201811558902.1A CN201811558902A CN109739930A CN 109739930 A CN109739930 A CN 109739930A CN 201811558902 A CN201811558902 A CN 201811558902A CN 109739930 A CN109739930 A CN 109739930A
- Authority
- CN
- China
- Prior art keywords
- hash value
- cache server
- storing data
- cache
- hash
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
This application involves distributed technical field, in particular to a kind of date storage method based on distributed cache system, device, computer equipment.The described method includes: one hash function of configuration, obtains the key of more cache servers;The hash value of more cache servers is calculated using hash function;Obtain the key of storing data;According to the key of storing data, the hash value of storing data is calculated using hash function;According to the hash value of more cache servers, the hash value of storing data in the distribution in closed loop space, a hash value of the hash value of storing data in the hash value of more cache servers is judged by storage rule clockwise, obtains target cache server;By storing data storage to target cache server.Even if newly-increased cache server, does not need to do whole data cached move yet and turn, it is intended to it solves in existing distributed cache system, because of the mode of hash modulus, in newly-increased cache server, the problem of needing to do whole data cached migration.
Description
Technical field
This application involves distributed technical field, in particular to a kind of data storage side based on distributed cache system
Method, device, computer equipment.
Background technique
Key and value are evenly distributed in cache cluster by distributed cache system at present, and most conventional mode is
Use the mode of hash modulus.For example suitable N can be used in cluster, then the request of data that key value is K simply should very much
It is routed in the corresponding machine of hash (K) mod N, although this method is simple, in the web system of some high speed developments
Bigger defect is had, because with the growth of system access pressure, caching system is had to by increasing cache node
Mode improves the response speed and data-carrying capacity of cluster.Increase node machine to mean in the way of hash modulus,
Newly-increased node machine at the moment, a large amount of caching is since it is desired that rebuilding and can not hit, or even need to do whole data cached
Migration, moment bring high system load to database, even result in DB server delay machine.
Apply for content
In view of the shortcomings of the prior art, the application propose a kind of date storage method based on distributed cache system, device,
Computer equipment, it is intended to solve in existing distributed cache system, because of the mode of hash modulus, in newly-increased cache server
When, the problem of needing to do whole data cached migration.
The technical solution that the application proposes is:
A kind of date storage method based on distributed cache system, which comprises
A hash function is configured, wherein calculating the hash value of key by the hash function, the hash value is arrived 0
223In -1 closed loop space;
Obtain the key of more cache servers;
According to the key of the more cache servers, the more cache servers are calculated using the hash function
Hash value;
Obtain the key of storing data;
According to the key of the storing data, the hash value of the storing data is calculated using the hash function;
Divided according to the hash value of the more cache servers, the hash value of the storing data the closed loop space
Cloth judges the hash value of the storing data in the hash value of the more cache servers by storage rule clockwise
One hash value obtains target cache server;
By storing data storage to the target cache server.
Further, existed described according to hash value, the hash value of the storing data of the more cache servers
The distribution in the closed loop space judges that the hash value of the storing data takes close to the more cachings by storage rule clockwise
After the step of hash value being engaged in the hash value of device, acquisition target cache server, stored by the storing data
Before the step of to the target cache server, comprising:
It detects in distributed cache system with the presence or absence of newly-increased cache server;The newly-increased caching clothes if it exists
Business device, then obtain the key of the newly-increased cache server;
According to the key of the newly-increased cache server, the newly-increased buffer service is calculated using the hash function
The hash value of device;
According to the hash value of the newly-increased cache server, the hash value of the target cache server, the storage
The hash value of data is judged the hash value of the storing data by the storage rule clockwise in the distribution in the closed loop space
A hash value in the hash value, the hash value of the target cache server of the newly-increased cache server, is obtained
Obtain fresh target cache server.
Further, existed described according to hash value, the hash value of the storing data of the more cache servers
The distribution in the closed loop space judges that the hash value of the storing data takes close to the more cachings by storage rule clockwise
After the step of hash value being engaged in the hash value of device, acquisition target cache server, stored by the storing data
Before the step of to the target cache server, comprising:
Detect the target cache server whether delay machine;
It is empty in the closed loop according to the hash value of the more cache servers if the target cache server delay machine
Between distribution, and according to the storage rule clockwise, identify the next slow of the hash value of the target cache server
The hash value of server is deposited, fresh target cache server is obtained.
Further, described by storing data storage to the target cache server the step of in, comprising:
By storing data storage to the fresh target cache server.
Further, described by storing data storage to the target cache server the step of after, comprising:
Detection whether there is deleted cache server in the more cache servers;
The deleted cache server if it exists is then closed according to the hash value of the more cache servers described
The distribution of annular space, and according to the storage rule clockwise, identify the hash value of the deleted cache server
The hash value of next cache server obtains the first cache server;
The corresponding data of the deleted cache server are obtained from database, obtain data to be stored;
By data to be stored storage to first cache server.
Further, the key of the cache server is the IP of cache server or the title of cache server.
Further, the key of the storing data is the field name of data.
The application also provides a kind of data storage device based on distributed cache system, and described device includes:
Configuration module, for configuring a hash function, wherein calculating the hash value of key, institute by the hash function
Hash value is stated 0 to 223In -1 closed loop space;
First obtains module, for obtaining the key of more cache servers;
First computing module, for the key according to the more cache servers, using described in hash function calculating
The hash value of more cache servers;
Second obtains module, for obtaining the key of storing data;
Second computing module calculates the storage number using the hash function for the key according to the storing data
According to hash value;
Judgment module, for according to the hash values of the more cache servers, the hash value of the storing data in institute
The distribution for stating closed loop space judges the hash value of the storing data close to the more buffer services by storage rule clockwise
A hash value in the hash value of device obtains target cache server;
Memory module, for storing the storing data to the target cache server.
The application also provides a kind of computer equipment, including memory and processor, and the memory is stored with computer
The step of program, the processor realizes method described in any of the above embodiments when executing the computer program.
The application also provides a kind of computer readable storage medium, is stored thereon with computer program, the computer journey
The step of method described in any of the above embodiments is realized when sequence is executed by processor.
According to above-mentioned technical solution, the application is the utility model has the advantages that calculate the hash value of key, hash value by hash function
0 to 223In -1 closed loop space, according to the key of more cache servers, more cache servers are calculated using hash function
Hash value the hash value of storing data is calculated using hash function, by storage rule clockwise according to the key of storing data
Judge cache server of the hash value of storing data in closed loop space in more cache servers, obtains target cache
Server stores storing data to target cache server, for this purpose, even if newly-increased cache server, does not need to do entirety yet
Data cached move turns, it is intended to solve in existing distributed cache system, because of the mode of hash modulus, in newly-increased buffer service
When device, the problem of needing to do whole data cached migration.
Detailed description of the invention
Fig. 1 is the flow chart using the date storage method provided by the embodiments of the present application based on distributed cache system;
Fig. 2 is the functional module using the data storage device provided by the embodiments of the present application based on distributed cache system
Figure;
Fig. 3 is the structural schematic block diagram using computer equipment provided by the embodiments of the present application.
Specific embodiment
It is with reference to the accompanying drawings and embodiments, right in order to which the objects, technical solutions and advantages of the application are more clearly understood
The application is further elaborated.It should be appreciated that specific embodiment described herein is only used to explain the application, and
It is not used in restriction the application.
As shown in Figure 1, the embodiment of the present application proposes a kind of date storage method based on distributed cache system, the side
Method the following steps are included:
Step S101, a hash function is configured, wherein the hash value of key is calculated by the hash function, it is described
Hash value is 0 to 223In -1 closed loop space.
It configures a hash function to input key in hash function, exports corresponding hash value.Hash function calculates
The hash value of key, and hash value is 0 to 223In -1 closed loop space, that is to say, that calculated, obtained by hash function
Hash value is all 0 to 223In -1 closed loop space.Closed loop space refers to numerical value since 0 to 223- 1, then 223- 1 lower one
A numerical value is 0 closed loop recycled.
In the present embodiment, the realization of the hash algorithms such as MD4, MD5, SHA-1, SHA256 can be used in hash function.
Hash function is the function of the hash algorithm of MD4, MD5, SHA-1 or SHA256.
Step S102, the key of more cache servers is obtained.
From distributed cache system, the key of more cache servers, in the present embodiment, cache server are obtained
Key is the IP of cache server or the title of cache server.For this purpose, the IP or title of more cache servers are obtained,
To get the key of more cache servers.The key of cache server is to pass through hash letter for inputting in hash function
Number calculates the hash value of cache server.
Step S103, according to the key of the more cache servers, the more cachings are calculated using the hash function
The hash value of server.
After the key for getting more cache servers, start to calculate the hash value of cache server, utilize
Hash function calculates, and by the key input hash function of each cache server, calculates the hash value of each cache server, according to
Calculated result obtains the hash value of more cache servers.
Step S104, the key of storing data is obtained.
After the hash value for obtaining more cache servers, the key of storing data is obtained.In the present embodiment, it stores
The key of data is the field name of data.For this purpose, the field name of data is obtained, to get the key of storing data.It deposits
The key for storing up data is that the hash value of storing data is calculated by hash function for inputting in hash function.
In the present embodiment, in step S104, comprising:
Detection is currently with the presence or absence of the storing data for waiting storage;
The storing data if it exists then obtains the key of the storing data.
In distributed cache system, detection currently whether there is the storing data for waiting storage, if it exists storing data,
Then obtain the key of storing data.Storing data if it does not exist, then the storage number that detection is currently stored with the presence or absence of waiting again
According to.
Step S105, according to the key of the storing data, the hash of the storing data is calculated using the hash function
Value.
After getting the key of storing data, starts to calculate the hash value of storing data, utilize hash function
It calculates, by the key input hash function of storing data, the hash value for calculating storing data is stored according to calculated result
The hash value of data.
Step S106, it is closed according to the hash value of the more cache servers, the hash value of the storing data described
The distribution of annular space judges the hash value of the storing data close to the more cache servers by storage rule clockwise
A hash value in hash value obtains target cache server.
After the hash value, the hash value of storing data of more cache servers of acquisition, according to more cache servers
Hash value, the hash value of storing data in the distribution in closed loop space, and judge storing data by storage rule clockwise
A hash value of the hash value in the hash value of more cache servers, then according to pair of hash value and cache server
It should be related to, obtain target cache server.Storage rule clockwise be in closed loop space, in the direction of the clock, storing data
Close first cache server of hash value hash value, the corresponding caching clothes of the hash value of first cache server
Business device is the target cache server of storing data.
Step S107, the storing data is stored to the target cache server.
After obtaining target cache server, by storing data storage to target cache server.
In the present embodiment, after step s 106, before step S107, comprising:
It detects in distributed cache system with the presence or absence of newly-increased cache server;
The newly-increased cache server if it exists then obtains the key of the newly-increased cache server;
According to the key of the newly-increased cache server, the newly-increased buffer service is calculated using the hash function
The hash value of device;
According to the hash value of the newly-increased cache server, the hash value of the target cache server, the storage
The hash value of data is judged the hash value of the storing data by the storage rule clockwise in the distribution in the closed loop space
A hash value in the hash value, the hash value of the target cache server of the newly-increased cache server, is obtained
Obtain fresh target cache server.
It after obtaining target cache server, is detected, is detected in distributed caching in distributed cache system
Newly-increased caching is obtained if detecting the presence of newly-increased cache server with the presence or absence of newly-increased cache server in system
The key of server obtains the IP or title of newly-increased cache server in the present embodiment, to get newly-increased delay
Deposit the key of server.After the key for getting newly-increased cache server, start the hash to newly-increased cache server
Value is calculated, and is calculated using hash function, by the key input hash function of newly-increased cache server, is calculated newly-increased
The hash value of cache server obtains the hash value of newly-increased cache server according to calculated result.Obtaining newly-increased caching
After the hash value of server, according to the hash value of newly-increased cache server, the hash value of storing data in closed loop space
Distribution, and press storage rule clockwise and judge the hash value of the close newly-increased cache server of the hash value of storing data, mesh
A hash value in the hash value of cache server is marked, then according to the corresponding relationship of hash value and cache server, is obtained
Fresh target cache server.
Described according to the hash value of the newly-increased cache server, the hash value of the target cache server, institute
Distribution of the hash value in the closed loop space for stating storing data, judges the storing data by the storage rule clockwise
A hash of the hash value in the hash value of the newly-increased cache server, the hash value of the target cache server
In the step of value, acquisition fresh target cache server, comprising:
According to the hash value of the newly-increased cache server, the hash value of the target cache server, the storage
The hash value of data is judged the hash value of the storing data by the storage rule clockwise in the distribution in the closed loop space
A hash value in the hash value, the hash value of the target cache server of the newly-increased cache server;
If the hash value of the storing data close to the hash value of the newly-increased cache server, determines that fresh target is slow
Depositing server is newly-increased cache server;
If the hash value of the storing data close to the hash value of the target cache server, determines that fresh target caches
Server is target cache server.
According to storage rule clockwise, by hash value, the hash value of target cache server of newly-increased cache server
It is compared with the hash value of storing data, if the hash value of the close newly-increased cache server of the hash value of storing data,
Fresh target cache server is newly-increased cache server;If the hash value of storing data is close to the hash of target cache server
Value, then fresh target cache server is target cache server.
Accordingly, in step s 107, comprising:
By storing data storage to the fresh target cache server.
After obtaining fresh target cache server, by storing data storage to fresh target cache server.
In the present embodiment, after step s 106, before step S107, comprising:
Detect the target cache server whether delay machine;
It is empty in the closed loop according to the hash value of the more cache servers if the target cache server delay machine
Between distribution, and according to the storage rule clockwise, identify the next slow of the hash value of the target cache server
The hash value of server is deposited, fresh target cache server is obtained.
It after obtaining target cache server, is detected in distributed cache system, detects target cache service
Device whether delay machine, if target cache server is delay machine, according to the hash value of more cache servers closed loop space point
Cloth, and according to storage rule clockwise, identify the hash of next cache server of the hash value of target cache server
Value, obtains the hash value of next cache server, after the hash value for obtaining next cache server, according to next
The corresponding cache server of hash value of cache server obtains fresh target cache server.
Accordingly, in step s 107, comprising:
By storing data storage to the fresh target cache server.
After obtaining fresh target cache server, by storing data storage to fresh target cache server.
In the present embodiment, after step S107, comprising:
Detection whether there is deleted cache server in the more cache servers;
The deleted cache server if it exists is then closed according to the hash value of the more cache servers described
The distribution of annular space, and according to the storage rule clockwise, identify the hash value of the deleted cache server
The hash value of next cache server obtains the first cache server;
The corresponding data of the deleted cache server are obtained from database, obtain data to be stored;
By data to be stored storage to first cache server.
After by storing data storage to target cache server, detection is in more cache servers with the presence or absence of
The cache server of deletion is needed if there is deleted cache server by the data on deleted cache server
It is migrated, for this purpose, deleted cache server if it exists, then according to the hash value of more cache servers in closed loop space
Distribution, and according to storage rule clockwise, identify next buffer service of the hash value of deleted cache server
The hash value of device obtains the hash value of next cache server, after the hash value for obtaining next cache server, root
According to the corresponding cache server of hash value of next cache server, the first cache server is obtained.It is obtained from database
The corresponding data of deleted cache server, obtain data to be stored, by data to be stored storage to the first cache server,
Complete the Data Migration on deleted cache server.
In conclusion calculating the hash value of key by hash function, hash value is 0 to 223In -1 closed loop space, according to
The key of more cache servers calculates the hash value of more cache servers using hash function, according to the key of storing data,
The hash value that storing data is calculated using hash function judges the hash value of storing data in closed loop sky by storage rule clockwise
Between in cache server in more cache servers, target cache server is obtained, by storing data storage to target
Cache server, for this purpose, also not needing to do integrally data cached move even if newly-increased cache server and turning, it is intended to solve existing
Distributed cache system in, because of the mode of hash modulus, in newly-increased cache server, need to do whole data cached migration
The problem of.
As shown in Fig. 2, the embodiment of the present application proposes a kind of data storage device 1 based on distributed cache system, device 1
Module 12 is obtained including configuration module 11, first, the first computing module 13, second obtains module 14, the second computing module 15, sentences
Disconnected module 16 and memory module 17.
Configuration module 11, for configuring a hash function, wherein the hash value of key is calculated by the hash function,
The hash value is 0 to 223In -1 closed loop space.
It configures a hash function to input key in hash function, exports corresponding hash value.Hash function calculates
The hash value of key, and hash value is 0 to 223In -1 closed loop space, that is to say, that calculated, obtained by hash function
Hash value is all 0 to 223In -1 closed loop space.Closed loop space refers to numerical value since 0 to 223- 1, then 223- 1 lower one
A numerical value is 0 closed loop recycled.
In the present embodiment, the realization of the hash algorithms such as MD4, MD5, SHA-1, SHA256 can be used in hash function.
Hash function is the function of the hash algorithm of MD4, MD5, SHA-1 or SHA256.
First obtains module 12, for obtaining the key of more cache servers.
From distributed cache system, the key of more cache servers, in the present embodiment, cache server are obtained
Key is the IP of cache server or the title of cache server.For this purpose, the IP or title of more cache servers are obtained,
To get the key of more cache servers.The key of cache server is to pass through hash letter for inputting in hash function
Number calculates the hash value of cache server.
First computing module 13 calculates institute using the hash function for the key according to the more cache servers
State the hash value of more cache servers.
After the key for getting more cache servers, start to calculate the hash value of cache server, utilize
Hash function calculates, and by the key input hash function of each cache server, calculates the hash value of each cache server, according to
Calculated result obtains the hash value of more cache servers.
Second obtains module 14, for obtaining the key of storing data.
After the hash value for obtaining more cache servers, the key of storing data is obtained.In the present embodiment, it stores
The key of data is the field name of data.For this purpose, the field name of data is obtained, to get the key of storing data.It deposits
The key for storing up data is that the hash value of storing data is calculated by hash function for inputting in hash function.
In the present embodiment, the second acquisition module 14 includes:
First sub- detection module, it is current with the presence or absence of the storing data for waiting storage for detecting;
First sub-acquisition module then obtains the key of the storing data for the storing data if it exists.
In distributed cache system, detection currently whether there is the storing data for waiting storage, if it exists storing data,
Then obtain the key of storing data.Storing data if it does not exist, then the storage number that detection is currently stored with the presence or absence of waiting again
According to.
Second computing module 15 calculates the storage using the hash function for the key according to the storing data
The hash value of data.
After getting the key of storing data, starts to calculate the hash value of storing data, utilize hash function
It calculates, by the key input hash function of storing data, the hash value for calculating storing data is stored according to calculated result
The hash value of data.
Judgment module 16, for being existed according to hash value, the hash value of the storing data of the more cache servers
The distribution in the closed loop space judges that the hash value of the storing data takes close to the more cachings by storage rule clockwise
A hash value being engaged in the hash value of device obtains target cache server.
After the hash value, the hash value of storing data of more cache servers of acquisition, according to more cache servers
Hash value, the hash value of storing data in the distribution in closed loop space, and judge storing data by storage rule clockwise
A hash value of the hash value in the hash value of more cache servers, then according to pair of hash value and cache server
It should be related to, obtain target cache server.Storage rule clockwise be in closed loop space, in the direction of the clock, storing data
Close first cache server of hash value hash value, the corresponding caching clothes of the hash value of first cache server
Business device is the target cache server of storing data.
Memory module 17, for storing the storing data to the target cache server.
After obtaining target cache server, by storing data storage to target cache server.
In the present embodiment, device 1 includes:
Detection module, for detecting in distributed cache system with the presence or absence of newly-increased cache server;
Third obtains module and then obtains the newly-increased buffer service for the newly-increased cache server if it exists
The key of device;
4th computing module calculates institute using the hash function for the key according to the newly-increased cache server
State the hash value of newly-increased cache server;
First judgment module, for the hash value according to the newly-increased cache server, the target cache server
Hash value, the hash value of the storing data in the distribution in the closed loop space, judge institute by the storage rule clockwise
State hash value of the hash value close to the newly-increased cache server, the hash value of the target cache server of storing data
In a hash value, obtain fresh target cache server.
It after obtaining target cache server, is detected, is detected in distributed caching in distributed cache system
Newly-increased caching is obtained if detecting the presence of newly-increased cache server with the presence or absence of newly-increased cache server in system
The key of server obtains the IP or title of newly-increased cache server in the present embodiment, to get newly-increased delay
Deposit the key of server.After the key for getting newly-increased cache server, start the hash to newly-increased cache server
Value is calculated, and is calculated using hash function, by the key input hash function of newly-increased cache server, is calculated newly-increased
The hash value of cache server obtains the hash value of newly-increased cache server according to calculated result.Obtaining newly-increased caching
After the hash value of server, according to the hash value of newly-increased cache server, the hash value of storing data in closed loop space
Distribution, and press storage rule clockwise and judge the hash value of the close newly-increased cache server of the hash value of storing data, mesh
A hash value in the hash value of cache server is marked, then according to the corresponding relationship of hash value and cache server, is obtained
Fresh target cache server.
First judgment module includes:
First sub- judgment module, for the hash value according to the newly-increased cache server, the target cache service
The hash value of device, the hash value of the storing data are judged in the distribution in the closed loop space by the storage rule clockwise
The hash value of the storing data is close to the hash value of the newly-increased cache server, the hash of the target cache server
A hash value in value;
First sub- determination module, if the hash value for the storing data is close to the newly-increased cache server
Hash value then determines that fresh target cache server is newly-increased cache server;
Second sub- determination module, if for the storing data hash value close to the target cache server hash
Value, then determine fresh target cache server for target cache server.
According to storage rule clockwise, by hash value, the hash value of target cache server of newly-increased cache server
It is compared with the hash value of storing data, if the hash value of the close newly-increased cache server of the hash value of storing data,
Fresh target cache server is newly-increased cache server;If the hash value of storing data is close to the hash of target cache server
Value, then fresh target cache server is target cache server.
Accordingly, memory module 17 includes:
First sub- memory module, for storing the storing data to the fresh target cache server.
After obtaining fresh target cache server, by storing data storage to fresh target cache server.
In the present embodiment, device 1 includes:
First detection module, for detect the target cache server whether delay machine;
First identification module, if the target cache server delay machine is used for, according to the more cache servers
Hash value and according to the storage rule clockwise, identifies the target cache server in the distribution in the closed loop space
Hash value next cache server hash value, obtain fresh target cache server.
It after obtaining target cache server, is detected in distributed cache system, detects target cache service
Device whether delay machine, if target cache server is delay machine, according to the hash value of more cache servers closed loop space point
Cloth, and according to storage rule clockwise, identify the hash of next cache server of the hash value of target cache server
Value, obtains the hash value of next cache server, after the hash value for obtaining next cache server, according to next
The corresponding cache server of hash value of cache server obtains fresh target cache server.
Accordingly, memory module 17 includes:
Second sub- memory module, for storing the storing data to the fresh target cache server.
After obtaining fresh target cache server, by storing data storage to fresh target cache server.
In the present embodiment, device 1 includes:
Second detection module whether there is deleted buffer service for detecting in the more cache servers
Device;
Second identification module, for the deleted cache server if it exists, then according to the more buffer services
The hash value of device and according to the storage rule clockwise, identifies described deleted slow in the distribution in the closed loop space
The hash value of next cache server of the hash value of server is deposited, the first cache server is obtained;
5th obtains module, for obtaining the corresponding data of the deleted cache server from database, obtains
Data to be stored;
First memory module, for storing the data to be stored to first cache server.
After by storing data storage to target cache server, detection is in more cache servers with the presence or absence of
The cache server of deletion is needed if there is deleted cache server by the data on deleted cache server
It is migrated, for this purpose, deleted cache server if it exists, then according to the hash value of more cache servers in closed loop space
Distribution, and according to storage rule clockwise, identify next buffer service of the hash value of deleted cache server
The hash value of device obtains the hash value of next cache server, after the hash value for obtaining next cache server, root
According to the corresponding cache server of hash value of next cache server, the first cache server is obtained.It is obtained from database
The corresponding data of deleted cache server, obtain data to be stored, by data to be stored storage to the first cache server,
Complete the Data Migration on deleted cache server.
In conclusion calculating the hash value of key by hash function, hash value is 0 to 223In -1 closed loop space, according to
The key of more cache servers calculates the hash value of more cache servers using hash function, according to the key of storing data,
The hash value that storing data is calculated using hash function judges the hash value of storing data in closed loop sky by storage rule clockwise
Between in cache server in more cache servers, target cache server is obtained, by storing data storage to target
Cache server, for this purpose, also not needing to do integrally data cached move even if newly-increased cache server and turning, it is intended to solve existing
Distributed cache system in, because of the mode of hash modulus, in newly-increased cache server, need to do whole data cached migration
The problem of.
As shown in figure 3, also providing a kind of computer equipment in the embodiment of the present application, which can be service
Device, internal structure can be as shown in Figure 3.The computer equipment includes processor, the memory, net connected by system bus
Network interface and database.Wherein, the processor of the Computer Design is for providing calculating and control ability.The computer equipment
Memory includes non-volatile memory medium, built-in storage.The non-volatile memory medium is stored with operating system, computer journey
Sequence and database.The internal memory provides environment for the operation of operating system and computer program in non-volatile memory medium.
The database of the computer equipment is for storing the data such as the model of the date storage method based on distributed cache system.The meter
The network interface for calculating machine equipment is used to communicate with external terminal by network connection.When the computer program is executed by processor
To realize a kind of date storage method based on distributed cache system.
Above-mentioned processor executes the step of above-mentioned date storage method based on distributed cache system: one hash of configuration
Function, wherein calculating the hash value of key by the hash function, the hash value is 0 to 223In -1 closed loop space;It obtains
The key of more cache servers;According to the key of the more cache servers, described more are calculated using the hash function
The hash value of cache server;Obtain the key of storing data;According to the key of the storing data, the hash function meter is utilized
Calculate the hash value of the storing data;Existed according to the hash value of the more cache servers, the hash value of the storing data
The distribution in the closed loop space judges that the hash value of the storing data takes close to the more cachings by storage rule clockwise
A hash value being engaged in the hash value of device obtains target cache server;The storing data is stored to the target and is delayed
Deposit server.
In one embodiment, the hash of the above-mentioned hash value according to the more cache servers, the storing data
It is worth the distribution in the closed loop space, judges that the hash value of the storing data is slow close to described more by storage rule clockwise
After the step of depositing a hash value in the hash value of server, obtaining target cache server, by the storing data
Before the step of storing the target cache server, comprising:
It detects in distributed cache system with the presence or absence of newly-increased cache server;The newly-increased caching clothes if it exists
Business device, then obtain the key of the newly-increased cache server;
According to the key of the newly-increased cache server, the newly-increased buffer service is calculated using the hash function
The hash value of device;
According to the hash value of the newly-increased cache server, the hash value of the target cache server, the storage
The hash value of data is judged the hash value of the storing data by the storage rule clockwise in the distribution in the closed loop space
A hash value in the hash value, the hash value of the target cache server of the newly-increased cache server, is obtained
Obtain fresh target cache server.
In one embodiment, the hash of the above-mentioned hash value according to the more cache servers, the storing data
It is worth the distribution in the closed loop space, judges that the hash value of the storing data is slow close to described more by storage rule clockwise
After the step of depositing a hash value in the hash value of server, obtaining target cache server, by the storing data
Before the step of storing the target cache server, comprising:
Detect the target cache server whether delay machine;
It is empty in the closed loop according to the hash value of the more cache servers if the target cache server delay machine
Between distribution, and according to the storage rule clockwise, identify the next slow of the hash value of the target cache server
The hash value of server is deposited, fresh target cache server is obtained.
In one embodiment, it is above-mentioned by storing data storage to the target cache server the step of in, packet
It includes:
By storing data storage to the fresh target cache server.
In one embodiment, it is above-mentioned by storing data storage to the target cache server the step of after,
Include:
Detection whether there is deleted cache server in the more cache servers;
The deleted cache server if it exists is then closed according to the hash value of the more cache servers described
The distribution of annular space, and according to the storage rule clockwise, identify the hash value of the deleted cache server
The hash value of next cache server obtains the first cache server;
The corresponding data of the deleted cache server are obtained from database, obtain data to be stored;
By data to be stored storage to first cache server.
In one embodiment, the key of above-mentioned cache server is the IP of cache server or the name of cache server
Claim.
In one embodiment, the key of above-mentioned storing data is the field name of data.
It will be understood by those skilled in the art that structure shown in Fig. 3, only part relevant to application scheme is tied
The block diagram of structure does not constitute the restriction for the computer equipment being applied thereon to application scheme.
The computer equipment of the embodiment of the present application calculates the hash value of key by hash function, and hash value is 0 to 223-1
Closed loop space in, according to the key of more cache servers, the hash value of more cache servers is calculated using hash function,
According to the key of storing data, the hash value of storing data is calculated using hash function, judges storage number by storage rule clockwise
According to cache server of the hash value in closed loop space in more cache servers, obtain target cache server, will
Storing data is stored to target cache server, for this purpose, also not needing to do integrally data cached move even if newly-increased cache server
Turn, it is intended to solve in existing distributed cache system, because the mode of hash modulus is needed in newly-increased cache server
The problem of doing whole data cached migration.
One embodiment of the application also provides a kind of computer readable storage medium, is stored thereon with computer program, calculates
Machine program realizes a kind of date storage method based on distributed cache system when being executed by processor, specifically: configuration one
Hash function, wherein calculating the hash value of key by the hash function, the hash value is 0 to 223In -1 closed loop space;
Obtain the key of more cache servers;According to the key of the more cache servers, using described in hash function calculating
The hash value of more cache servers;Obtain the key of storing data;According to the key of the storing data, the hash letter is utilized
Number calculates the hash value of the storing data;According to the hash of the hash value of the more cache servers, the storing data
It is worth the distribution in the closed loop space, judges that the hash value of the storing data is slow close to described more by storage rule clockwise
A hash value in the hash value of server is deposited, target cache server is obtained;By storing data storage to the mesh
Mark cache server.
In one embodiment, the hash of the above-mentioned hash value according to the more cache servers, the storing data
It is worth the distribution in the closed loop space, judges that the hash value of the storing data is slow close to described more by storage rule clockwise
After the step of depositing a hash value in the hash value of server, obtaining target cache server, by the storing data
Before the step of storing the target cache server, comprising:
It detects in distributed cache system with the presence or absence of newly-increased cache server;The newly-increased caching clothes if it exists
Business device, then obtain the key of the newly-increased cache server;
According to the key of the newly-increased cache server, the newly-increased buffer service is calculated using the hash function
The hash value of device;
According to the hash value of the newly-increased cache server, the hash value of the target cache server, the storage
The hash value of data is judged the hash value of the storing data by the storage rule clockwise in the distribution in the closed loop space
A hash value in the hash value, the hash value of the target cache server of the newly-increased cache server, is obtained
Obtain fresh target cache server.
In one embodiment, the hash of the above-mentioned hash value according to the more cache servers, the storing data
It is worth the distribution in the closed loop space, judges that the hash value of the storing data is slow close to described more by storage rule clockwise
After the step of depositing a hash value in the hash value of server, obtaining target cache server, by the storing data
Before the step of storing the target cache server, comprising:
Detect the target cache server whether delay machine;
It is empty in the closed loop according to the hash value of the more cache servers if the target cache server delay machine
Between distribution, and according to the storage rule clockwise, identify the next slow of the hash value of the target cache server
The hash value of server is deposited, fresh target cache server is obtained.
In one embodiment, it is above-mentioned by storing data storage to the target cache server the step of in, packet
It includes:
By storing data storage to the fresh target cache server.
In one embodiment, it is above-mentioned by storing data storage to the target cache server the step of after,
Include:
Detection whether there is deleted cache server in the more cache servers;
The deleted cache server if it exists is then closed according to the hash value of the more cache servers described
The distribution of annular space, and according to the storage rule clockwise, identify the hash value of the deleted cache server
The hash value of next cache server obtains the first cache server;
The corresponding data of the deleted cache server are obtained from database, obtain data to be stored;
By data to be stored storage to first cache server.
In one embodiment, the key of above-mentioned cache server is the IP of cache server or the name of cache server
Claim.
In one embodiment, the key of above-mentioned storing data is the field name of data.
The storage medium of the embodiment of the present application calculates the hash value of key by hash function, and hash value is 0 to 223- 1
In closed loop space, according to the key of more cache servers, the hash value of more cache servers, root are calculated using hash function
According to the key of storing data, the hash value of storing data is calculated using hash function, judges storing data by storage rule clockwise
Cache server of the hash value in closed loop space in more cache servers, obtain target cache server, will deposit
Data storage is stored up to target cache server, for this purpose, also not needing to do integrally data cached move even if newly-increased cache server
Turn, it is intended to solve in existing distributed cache system, because the mode of hash modulus is needed in newly-increased cache server
The problem of doing whole data cached migration.
Those of ordinary skill in the art will appreciate that realizing all or part of the process in above-described embodiment method, being can be with
Relevant hardware is instructed to complete by computer program, the computer program can be stored in a non-volatile computer
In read/write memory medium, the computer program is when being executed, it may include such as the process of the embodiment of above-mentioned each method.Wherein,
Any reference used in provided herein and embodiment to memory, storage, database or other media,
Including non-volatile and/or volatile memory.Nonvolatile memory may include read-only memory (ROM), programming ROM
(PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM) or flash memory.Volatile memory may include
Random access memory (RAM) or external cache.By way of illustration and not limitation, RAM is available in many forms,
Such as static state RAM (SRAM), dynamic ram (DRAM), synchronous dram (SDRAM), double speed are according to rate SDRAM (SSRSDRAM), enhancing
Type SDRAM (ESDRAM), synchronization link (Synchl ink) DRAM (SLDRAM), memory bus (Rambus) direct RAM
(RDRAM), direct memory bus dynamic ram (DRDRAM) and memory bus dynamic ram (RDRAM) etc..
The foregoing is merely the preferred embodiments of the application, not to limit the application, all essences in the application
Made any modifications, equivalent replacements, and improvements etc. within mind and principle should all include within the scope of protection of this application.
Claims (10)
1. a kind of date storage method based on distributed cache system, which is characterized in that the described method includes:
A hash function is configured, wherein calculating the hash value of key by the hash function, the hash value is 0 to 223-1
Closed loop space in;
Obtain the key of more cache servers;
According to the key of the more cache servers, the hash of the more cache servers is calculated using the hash function
Value;
Obtain the key of storing data;
According to the key of the storing data, the hash value of the storing data is calculated using the hash function;
According to the hash value of the more cache servers, the hash value of the storing data the closed loop space distribution,
One of the hash value of the storing data in the hash value of the more cache servers is judged by storage rule clockwise
A hash value obtains target cache server;
By storing data storage to the target cache server.
2. the date storage method according to claim 1 based on distributed cache system, which is characterized in that at described
According to the hash value of the more cache servers, the hash value of the storing data the closed loop space distribution, by up time
Needle storage rule judges a hash of the hash value of the storing data in the hash value of the more cache servers
After the step of value, acquisition target cache server, the storing data is being stored to the step to the target cache server
Before rapid, comprising:
It detects in distributed cache system with the presence or absence of newly-increased cache server;The newly-increased buffer service if it exists
Device then obtains the key of the newly-increased cache server;
According to the key of the newly-increased cache server, the newly-increased cache server is calculated using the hash function
Hash value;
According to the hash value of the newly-increased cache server, the hash value of the target cache server, the storing data
Hash value in the distribution in the closed loop space, judge that the hash value of the storing data is close by the storage rule clockwise
A hash value in the hash value of the newly-increased cache server, the hash value of the target cache server obtains new
Target cache server.
3. the date storage method according to claim 1 based on distributed cache system, which is characterized in that at described
According to the hash value of the more cache servers, the hash value of the storing data the closed loop space distribution, by up time
Needle storage rule judges a hash of the hash value of the storing data in the hash value of the more cache servers
After the step of value, acquisition target cache server, the storing data is being stored to the step to the target cache server
Before rapid, comprising:
Detect the target cache server whether delay machine;
If the target cache server delay machine, according to the hash value of the more cache servers in the closed loop space
Distribution, and according to the storage rule clockwise, identify next caching clothes of the hash value of the target cache server
The hash value of business device, obtains fresh target cache server.
4. based on the date storage method of distributed cache system according to claim 2 or 3, which is characterized in that
It is described by storing data storage to the target cache server the step of in, comprising:
By storing data storage to the fresh target cache server.
5. the date storage method according to claim 1 based on distributed cache system, which is characterized in that incited somebody to action described
After the step of storing data storage is to the target cache server, comprising:
Detection whether there is deleted cache server in the more cache servers;
The deleted cache server if it exists, then it is empty in the closed loop according to the hash value of the more cache servers
Between distribution, and according to the storage rule clockwise, identify the next of the hash value of the deleted cache server
The hash value of a cache server obtains the first cache server;
The corresponding data of the deleted cache server are obtained from database, obtain data to be stored;
By data to be stored storage to first cache server.
6. the date storage method according to claim 1 based on distributed cache system, which is characterized in that the caching
The key of server is the IP of cache server or the title of cache server.
7. the date storage method according to claim 1 based on distributed cache system, which is characterized in that the storage
The key of data is the field name of data.
8. a kind of data storage device based on distributed cache system, which is characterized in that described device includes:
Configuration module, for configuring a hash function, wherein the hash value of key is calculated by the hash function, it is described
Hash value is 0 to 223In -1 closed loop space;
First obtains module, for obtaining the key of more cache servers;
First computing module calculates described more using the hash function for the key according to the more cache servers
The hash value of cache server;
Second obtains module, for obtaining the key of storing data;
Second computing module calculates the storing data using the hash function for the key according to the storing data
Hash value;
Judgment module, for being closed according to hash value, the hash value of the storing data of the more cache servers described
The distribution of annular space judges the hash value of the storing data close to the more cache servers by storage rule clockwise
A hash value in hash value obtains target cache server;
Memory module, for storing the storing data to the target cache server.
9. a kind of computer equipment, including memory and processor, the memory are stored with computer program, feature exists
In the processor realizes method described in any one of claims 1 to 7 when executing computer program the step of.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer program
The step of method described in any one of claims 1 to 7 is realized when being executed by processor.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811558902.1A CN109739930A (en) | 2018-12-19 | 2018-12-19 | Date storage method, device based on distributed cache system, computer equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811558902.1A CN109739930A (en) | 2018-12-19 | 2018-12-19 | Date storage method, device based on distributed cache system, computer equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109739930A true CN109739930A (en) | 2019-05-10 |
Family
ID=66360656
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811558902.1A Pending CN109739930A (en) | 2018-12-19 | 2018-12-19 | Date storage method, device based on distributed cache system, computer equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109739930A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110245028A (en) * | 2019-05-13 | 2019-09-17 | 平安科技(深圳)有限公司 | Message storage method, device, computer equipment and the storage medium of IoT-MQ |
WO2021042923A1 (en) * | 2019-09-06 | 2021-03-11 | 平安国际智慧城市科技股份有限公司 | Data sharding storage method and apparatus, and terminal and computer-readable storage mediium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120297010A1 (en) * | 2011-05-18 | 2012-11-22 | Alibaba Group Holding Limited | Distributed Caching and Cache Analysis |
CN104050270A (en) * | 2014-06-23 | 2014-09-17 | 成都康赛信息技术有限公司 | Distributed storage method based on consistent Hash algorithm |
CN105007328A (en) * | 2015-07-30 | 2015-10-28 | 山东超越数控电子有限公司 | Network cache design method based on consistent hash |
CN107483519A (en) * | 2016-06-08 | 2017-12-15 | Tcl集团股份有限公司 | A kind of Memcache load-balancing methods and its system |
-
2018
- 2018-12-19 CN CN201811558902.1A patent/CN109739930A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120297010A1 (en) * | 2011-05-18 | 2012-11-22 | Alibaba Group Holding Limited | Distributed Caching and Cache Analysis |
CN104050270A (en) * | 2014-06-23 | 2014-09-17 | 成都康赛信息技术有限公司 | Distributed storage method based on consistent Hash algorithm |
CN105007328A (en) * | 2015-07-30 | 2015-10-28 | 山东超越数控电子有限公司 | Network cache design method based on consistent hash |
CN107483519A (en) * | 2016-06-08 | 2017-12-15 | Tcl集团股份有限公司 | A kind of Memcache load-balancing methods and its system |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110245028A (en) * | 2019-05-13 | 2019-09-17 | 平安科技(深圳)有限公司 | Message storage method, device, computer equipment and the storage medium of IoT-MQ |
CN110245028B (en) * | 2019-05-13 | 2023-08-25 | 平安科技(深圳)有限公司 | Message storage method, device, computer equipment and storage medium of IoT-MQ |
WO2021042923A1 (en) * | 2019-09-06 | 2021-03-11 | 平安国际智慧城市科技股份有限公司 | Data sharding storage method and apparatus, and terminal and computer-readable storage mediium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110535969B (en) | Data storage method, device, storage medium and equipment based on block chain network | |
CN108965381A (en) | Implementation of load balancing, device, computer equipment and medium based on Nginx | |
CN108011929A (en) | Data request processing method, apparatus, computer equipment and storage medium | |
CN104580226A (en) | Session data sharing system and method | |
CN109739930A (en) | Date storage method, device based on distributed cache system, computer equipment | |
CN111651523B (en) | MySQL data synchronization method and system of Kubernetes container platform | |
CN107870726A (en) | Date storage method and device, server based on redundancy scheme | |
CN103986779B (en) | A kind of application data transmission method, device and terminal device | |
CN112153133B (en) | Data sharing method, device and medium | |
CN106021468A (en) | Updating method and system for distributed caches and local caches | |
CN106407224A (en) | Method and device for file compaction in KV (Key-Value)-Store system | |
CN104580432A (en) | Memcached system, memory cache data provision method and device, memory cache data maintenance method and device as well as cluster maintenance method and device | |
CN111324623A (en) | Resource transfer data checking method and device, computer equipment and storage medium | |
CN100488109C (en) | Performance data additional collecting system and method in telecommunication network management | |
CN112839076B (en) | Data storage method, data reading method, gateway, electronic equipment and storage medium | |
CN107391770A (en) | A kind of method, apparatus of processing data, equipment and storage medium | |
CN110795395A (en) | File deployment system and file deployment method | |
CN113031864B (en) | Data processing method and device, electronic equipment and storage medium | |
CN111209271A (en) | Electric power data complementary acquisition method and device, computer equipment and storage medium | |
CN106033322A (en) | Method and device for data storage | |
CN111881150A (en) | Web application program offline data processing method and device | |
CN106021566A (en) | Method, device and system for improving concurrent processing capacity of single database | |
CN108614847A (en) | A kind of caching method and system of data | |
CN112328573A (en) | Database migration method and system in kubernets cluster | |
CN108243207B (en) | A kind of date storage method of network cloud disk |
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 |