Distributed data storage method and device
Patent Information
- Application Number
- CN202410767939.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-10
Smart Images

Figure CN118626562A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a distributed data storage method and device. Background Art
[0002] With the rapid development of the Internet, the amount of data in various applications has increased rapidly, and distributed databases have become the first choice for the transformation of applications with large amounts of data. The two most critical and difficult points in using distributed databases are the selection and design of distribution keys and sharding strategies. It is necessary to comprehensively consider business characteristics and data volume to select appropriate distribution keys and sharding strategies. Common sharding keys include auto-increment fields (or auto-increment fields with local value restrictions, such as the first few bits are fixed as time values such as year, month, and day, and the last few bits are auto-increment values), snowflake ID fields, or globally unique business fields (such as mobile phone numbers, personal ID numbers, etc.). Common data sharding strategies include range sharding, hash modulo sharding, consistent hash sharding, etc.
[0003] At present, many application systems use self-increment values as the primary key fields of core business tables. In the case of using distributed databases, this value will be used as the data sharding key first. Other operation record tables and additional information tables around the core business object table will use the distribution key of the main table as the distribution key of the subsidiary table or associated table. This design can well improve system performance, including query performance and business write operation performance, and minimize distributed transactions. However, this design may cause data imbalance after long-term operation. For example, some hot business object data has high operation frequency, operation history records and additional information are more, and the data volume of the sharding node where the data is located grows very fast. Non-hot business object data has low operation frequency, related operation records and additional information are less, and the data volume of the sharding node where the data is located grows slowly. After serious data imbalance occurs, regular data migration can alleviate this problem, but data migration involves changes in the location of data shards, and it is necessary to modify the sharding key or modify the global sharding key mapping table. During the migration period, the data cannot be queried or operated, which has a great impact on the business. Summary of the invention
[0004] In view of the problems in the prior art, an embodiment of the present invention provides a distributed data storage method and device, which can at least partially solve the problems in the prior art.
[0005] In one aspect, the present invention provides a distributed data storage method, comprising:
[0006] Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0007] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0008] If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0009] The shard key tail number prohibition table is dynamically updated according to the amount of data corresponding to each shard calculated at regular intervals, including:
[0010] Calculate the amount of data corresponding to each shard, and compare the amount of data in the shard with the baseline shard;
[0011] The comparison benchmark shard includes one of the shard with the second largest amount of data, the shard with the smallest amount of data, and the average amount of data of the remaining shards excluding the shard with the largest amount of data;
[0012] If it is determined that the amount of data corresponding to the shard with the largest amount of data exceeds the amount of data of the comparison benchmark shard by a preset proportion, the preset decimal corresponding to the shard with the largest amount of data is written into the shard key decimal prohibition table, and the effective time of the shard key decimal prohibition table is updated to the start time of the scheduled calculation.
[0013] Wherein, the distributed data storage method further comprises:
[0014] If it is determined that the comparison results of the data amounts of any two shards are less than the preset number, the shard key tail number prohibition table is restored to an initialized state, and the effective time of the shard key tail number prohibition table is updated to the timing calculation start time.
[0015] Wherein, the distributed data storage method further comprises:
[0016] If it is determined that the amount of data corresponding to the shard with the largest amount of data exceeds the amount of data of the comparison benchmark shard by less than a preset proportion, and the comparison result of the amount of data corresponding to the shard with the largest amount of data and the amount of data of at least one shard is greater than or equal to the preset number, the shard key tail digit prohibition table is maintained unchanged, and the effective time of the shard key tail digit prohibition table is updated to the start time of the scheduled calculation.
[0017] Wherein, the distributed data storage method further comprises:
[0018] If it is determined that the tail number of the shard key update value of the update calculation result is in the shard key tail number prohibition table, continue to add 1 to the shard key update value of the update calculation result until the tail number of the latest shard key update value is not in the shard key tail number prohibition table, and return the latest shard key update value to the application service, so that the application service can store the corresponding data in the corresponding shard according to the latest shard key update value.
[0019] Wherein, the distributed data storage method further comprises:
[0020] Clear the shard key tail number prohibition table and its corresponding effective time in the shard key tail number prohibition table change queue before the preset time.
[0021] Wherein, the distributed data storage method is executed through a shard key generation service.
[0022] In one aspect, the present invention provides a distributed data storage device, comprising:
[0023] An update unit, used to receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0024] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0025] A storage unit is used to return the shard key update value of the update calculation result to the application service if it is determined that the decimal point of the shard key update value of the update calculation result is not in the shard key decimal point prohibition table, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0026] In another aspect, an embodiment of the present invention provides an electronic device, including: a processor, a memory, and a bus, wherein:
[0027] The processor and the memory communicate with each other via the bus;
[0028] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the following method:
[0029] Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0030] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0031] If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0032] An embodiment of the present invention provides a non-transitory computer-readable storage medium, including:
[0033] The non-transitory computer-readable storage medium stores computer instructions, which cause the computer to execute the following method:
[0034] Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0035] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0036] If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0037] The distributed data storage method and device provided by the embodiment of the present invention receive a new data request sent by an application service after the effective time of a shard key tail number prohibition table, add 1 to a pre-stored shard key update value, and obtain a shard key update value of an updated calculation result; wherein the shard key tail number prohibition table is included in a shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; if it is determined that the tail number of the shard key update value of the updated calculation result is not in the shard key tail number prohibition table, the shard key update value of the updated calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the updated calculation result, so as to smoothly solve the data skew problem without affecting the application. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0039] Figure 1 It is a flow chart of a distributed data storage method provided by an embodiment of the present invention.
[0040] Figure 2 It is a flow chart of a distributed data storage method provided by another embodiment of the present invention.
[0041] Figure 3 It is a schematic diagram of the structure of a distributed data storage device provided by an embodiment of the present invention.
[0042] Figure 4 A schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention. It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other arbitrarily.
[0044] Explanation of related terms:
[0045] Hash: Generally translated as "hash", it is to transform an input of any length into an output of fixed length through a hash algorithm, and the output is the hash value. This conversion is a compression mapping, that is, the space of hash values is usually much smaller than the space of inputs, and different inputs may hash to the same output, so it is impossible to uniquely determine the input value from the hash value. Simply put, it is a function that compresses a message of any length into a message digest of a fixed length.
[0046] Consistent hashing algorithm: It is a special hashing algorithm that aims to solve the problem of distributed caching. When removing or adding a server, the mapping relationship between existing service requests and the servers that process the requests can be changed as little as possible. Consistent hashing solves the problems of dynamic scaling in the Distributed Hash Table (DHT) that exist in simple hashing algorithms.
[0047] Data sharding: refers to splitting the data stored in a single location (such as a database) according to certain data partitioning rules. The split data is stored in multiple locations (such as databases, tables, data partitions, etc.) in a dispersed manner to improve performance bottlenecks and availability. The rules used to divide data are called data sharding rules, and the key information for dividing data in the rules is called sharding keys.
[0048] Shard key: A field used to determine the shard where the data will be distributed. The selection of the shard key should be designed based on a comprehensive consideration of the data volume and business characteristics.
[0049] Range sharding: Shard data by administrative region, time range, data type, and other fields, and put the data with the same field value in the same shard. This type of sharding may locally concentrate data within certain ranges, greatly improving the performance of range queries, but it may cause data skew problems.
[0050] Hash modulo sharding: Shard the data using a hash modulo algorithm according to a field whose value is globally unique or whose value range is relatively dispersed. This strategy can basically ensure even data distribution and reduce data skew problems when the data volume is large and the field value used as the sharding key is globally unique or has few duplicates.
[0051] Consistent hash sharding: An optimization algorithm based on the hash modulus sharding algorithm. It uses the consistent hashing algorithm for sharding calculations, reducing the amount of data that needs to be re-sharded and migrated when sharding nodes are increased or decreased.
[0052] Figure 1 FIG. 1 is a flow chart of a distributed data storage method provided by an embodiment of the present invention. Figure 1 As shown, the distributed data storage method provided by the embodiment of the present invention includes:
[0053] Step S1: receiving a new data request sent by the application service after the effective time of the shard key tail number prohibition table, adding 1 to the pre-stored shard key update value to obtain the shard key update value of the updated calculation result;
[0054] Among them, the shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a time.
[0055] Step S2: If it is determined that the decimal point of the shard key update value of the update calculation result is not in the shard key decimal point prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0056] In the above step S1, the device receives a new data request sent by the application service after the effective time of the shard key tail number prohibition table, adds 1 to the pre-stored shard key update value, and obtains the shard key update value of the updated calculation result;
[0057] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the amount of data corresponding to each shard calculated at a fixed time. The device can be a computer device that executes the method, for example, a server. It should be noted that the acquisition and analysis of data involved in the embodiments of the present invention are authorized by the user.
[0058] In the above step S2, if the device determines that the last digit of the shard key update value of the update calculation result is not in the shard key last digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0059] The main technical ideas of the present invention are first described as follows:
[0060] 1) Hash modulus algorithm hashModeN: Use the basic hash modulus algorithm. For example, if there are three distributed nodes, denoted as node0, node1, and node2, the distribution keys with the last digits 1, 4, and 7 will fall on node1 after hash modulus, the distribution keys with the last digits 2, 5, and 8 will fall on node2 after hash modulus, and the distribution keys with the last digits 0, 3, 6, and 9 will fall on node0 after hash modulus.
[0061] 2) ForbidNumList: A list of numbers, each of which can be any number from 0 to 9. It is the last digit to be skipped when the shard key is incrementally generated. Different time periods may correspond to different ForbidNumLists. The initialization state of the ForbidNumList is [0], which means that shard keys with a last digit of 0 are not generated to ensure data balance of the first three nodes. Different initialization states can be set according to the number of initial nodes.
[0062] 3) Self-increment shard key generation rule: Use the incremental rule. Each time a new shard key value is generated, add 1 to the previous shard key value. If the digit after adding 1 coincides with the number in the shard key digit prohibition table for the current time period, continue to increase by 1 until the digit of the new shard key value does not coincide with the number in the shard key digit prohibition table.
[0063] 4) Self-increment shard key generation service ShardKeyCreateService: Provides self-increment shard key value generation service, and records the previous shard key value LastShardKey and the shard key tail number prohibition table change queue ForbidNumChangeQue. The queue saves the correspondence between the rule change time point and the shard key tail number prohibition table, such as [{20230101:[0]}].
[0064] 5) Data volume collection of data sharding nodes and recalculation of sharding key tail number prohibition table: The data volume of each data sharding node is collected regularly, and a new sharding key tail number prohibition table is calculated according to the set rules. If it is the same as the current rules, it will skip and enter the next data collection cycle. If it is found that the data volume of a shard such as node0 is too large, exceeding the other shards by a fixed percentage value such as 20%, then the shard can be considered as not wanting to receive new data in the future, which means that the distribution key tail number should not contain 0, 3, 6, 9, and a new sharding key tail number prohibition table [0, 3, 6, 9] is formed, and a new data is added to the ForbidNumChangeQue queue as shown below:
[0065] [{20230201:[0,3,6,9]},{20230101:[0]}].
[0066] 6) Data sharding operation: When adding new data, first call ShardKeyCreateService to obtain the sharding key ShardKey, and then use the hashModeN algorithm to calculate the node corresponding to the data.
[0067] 7) Data query: When querying data, directly use the shard key to perform hashModeN to obtain the shard information where the data is located, and then query the data in the corresponding shard.
[0068] Step 5 in the above process will be executed regularly, and the frequency can be determined based on the change in the amount of data in the application over a period of time.
[0069] Through the above process, dynamic data sharding strategy adjustment can be achieved, and the data skew problem can be smoothly solved without data migration.
[0070] Dynamically updating the shard key tail number prohibition table according to the regularly calculated data amount corresponding to each shard, including:
[0071] Calculate the amount of data corresponding to each shard, and compare the amount of data in the shard with the baseline shard;
[0072] Among them, the comparison benchmark shard includes one of the shard with the second largest data volume, the shard with the smallest data volume and the average data volume of the remaining shards excluding the shard with the largest data volume; for example, the data volume of node0 is c0, the data volume of node1 is c1, and the data volume of node2 is c2. If c2 is greater than c1 and greater than c0, if the comparison benchmark shard is the shard with the second largest data volume, c2 will be compared with c1.
[0073] If the comparison base shard is the shard with the least amount of data, c2 is compared with c0.
[0074] If the comparison base shard is the average data volume, c2 is compared with (c1+c0) / 2.
[0075] If it is determined that the amount of data corresponding to the shard with the largest amount of data exceeds the amount of data of the comparison reference shard by a preset ratio, the preset tail number corresponding to the shard with the largest amount of data is written into the shard key tail number prohibition table, and the effective time of the shard key tail number prohibition table is updated to the timing calculation start time. The preset ratio can be set independently according to actual conditions, and can be selected as 20%.
[0076] The distributed data storage method further includes:
[0077] If it is determined that the comparison result of the data volume of any two shards is less than the preset number, the shard key tail number prohibition table is restored to the initialization state, and the effective time of the shard key tail number prohibition table is updated to the timing calculation start time. The preset number can be set independently according to actual conditions.
[0078] The distributed data storage method further includes:
[0079] If it is determined that the amount of data corresponding to the shard with the largest amount of data exceeds the amount of data of the comparison reference shard by less than a preset ratio, and the comparison result of the amount of data corresponding to the shard with the largest amount of data and the amount of data of at least one shard is greater than or equal to the preset amount, the shard key tail number prohibition table is kept unchanged, and the effective time of the shard key tail number prohibition table is updated to the timing calculation start time. If the comparison result of the amount of data corresponding to the shard with the largest amount of data and the amount of data corresponding to all other shards is less than the preset amount, the shard key tail number prohibition table is restored to the initialization state [0], and the effective time of the shard key tail number prohibition table is updated to the timing calculation start time.
[0080] The distributed data storage method further includes:
[0081] If it is determined that the tail number of the shard key update value of the update calculation result is in the shard key tail number prohibition table, continue to add 1 to the shard key update value of the update calculation result until the tail number of the latest shard key update value is not in the shard key tail number prohibition table, and return the latest shard key update value to the application service, so that the application service can store the corresponding data in the corresponding shard according to the latest shard key update value.
[0082] like Figure 2 As shown, the examples are as follows:
[0083] The data volume of an interbank account reconciliation system is at the level of hundreds of millions. A distributed database is used for data sharding, with 3 shards. The core business tables of the system are: interbank account basic information table bnk_account_base, account details table bnk_account_detail, account balance change details table bnk_account_balance_detail, account statement information table bnk_account_check_detail, and the self-increment key value limited by the time information in the bnk_account_base table (such as 2023010100000000, the first 8 digits are the YYYYMMDD date value segment, and the last 8 digits are the self-increment value segment) is used as the shard key. The account details table, account balance change details table, and account statement information table are all associated with the interbank account basic information table, and the self-increment key value of the interbank account basic information table is used as the association key and data shard key. This sharding scheme can make the data of the basic information table of interbank accounts evenly distributed on the three shards. However, due to the uneven data volume of account balance change details, statement information and other related information, there is more hot account information and less non-hot account information. After the system has been running for a long time, there may be imbalanced data among the three shards. This method can dynamically and smoothly adjust the distribution of new data without migrating historical data, and achieve the final balanced distribution of data. The specific implementation process is as follows:
[0084] 1. The shard key generation service ShardKeyCreateService initializes the shard key tail number prohibition table change queue ForbidNumChangeQue and the previous shard key value LastShardKey (pre-stored shard key update value), where ForbidNumChangeQue information contains the correspondence between the rule change time and the shard key tail number prohibition table, such as [{20230101:[0]}]. LastSharkKey can obtain the last saved value from the persistence device or extract the current maximum value from the database.
[0085] 2. On January 1, 2023, the application service AppService received a request for basic information of a newly created interbank account, and requested the shard key generation service ShardKeyCreateService to generate a new shard key value ShardKey1. ShardKeyCreateService queries ForbidNumChangeQue and LastSharkKey information, obtains the shard key tail number prohibition table and the previous shard key value corresponding to the current time period, and adds 1 to the LastSharkKey value to obtain the new value NewShardKey. The tail number of the new value NewShardKey is matched with the value in the shard key tail number prohibition table. If a match is found, NewShardKey is increased by 1 and matched again until there is no matching value in a certain matching process. Then the NewShardKey at this time is returned to AppService as ShardKey1, and LastShardKey is updated to NewShardKey.
[0086] 3. The shard key generation service ShardKeyCreateService periodically calculates the total amount of data for each data shard node, and calculates the distribution key tail number prohibition table for the next time period according to the set rules. For example, on the evening of January 31, 2023, it is found that the data volume of node0 has exceeded 20% of node1, meeting the pre-set suspension rules. New data needs to fall into node1 and node2, and the shard key tail number cannot be [0,3,6,9]. Update ForbidNumChangeQue to: {20230201: [0,3,6,9], 20230101: [0]}. From February 1, 2023, data shard node node0 will temporarily not receive new interbank account basic information data (newly added associated information of existing interbank account basic information and data using the original account information self-increment value as the distribution key will still fall into the original data shard), and new interbank account basic information data will fall into node1 and node2.
[0087] 4. On February 2, 2023, AppService received a request for basic information of a new interbank account, and requested the shard key generation service ShardKeyCreateService to generate a new shard key value ShardKey2. ShardKeyCreateService queries ForbidNumChangeQue and LastSharkKey information, obtains the shard key tail number prohibition table [0,3,6,9] corresponding to the current time period and the previous shard key value LastSharkKey (assuming it is 2023020100000002), and adds 1 to the LastSharkKey value to obtain the new value. NewShardKey = 2023020100000003. Match the last digit 3 of the new value NewShardKey with the values in the shard key last digit forbidden table [0,3,6,9]. If it matches 3, skip the last digit and add 1 to NewShardKey to calculate the new value 2023020100000004. Then, match it with the list [0,3,6,9] again in a loop. If the match fails after the loop ends, the new NewShardKey = 2023020100000004 is returned to AppService as ShardKey2, and LastShardKey is updated to NewShardKey.
[0088] 5. Two months later, on March 30, 2023, ShardKeyCreateService periodically calculated the total amount of data on each data shard node and found that the data volume of the three nodes was balanced. The ForbidNumChangeQue information was updated to: {20230401: [0], 20230201: [0,3,6,9], 20230101: [0]}. Starting from April 1, 2023, new data can be recorded in the three shard nodes.
[0089] 6. By repeating the above steps, the data sharding of the entire database is in an overall regional balance state. The system can adjust the frequency of node calculation according to the growth rate of business data, that is, adjust the time interval of scheduled calculation. The above example is 1 month.
[0090] The distributed data storage method further includes:
[0091] Clear the shard key tail number prohibition table and its corresponding effective time in the shard key tail number prohibition table change queue before the preset time. The preset time can be set independently according to the actual situation. For example, on March 1, 2023, 20230201: [0, 3, 6, 9], 20230101: [0] will be cleared from ForbidNumChangeQue, so as to save information storage space as much as possible.
[0092] The distributed data storage method provided by the embodiment of the present invention receives a new data request sent by an application service after the effective time of a shard key tail number prohibition table, adds 1 to a pre-stored shard key update value, and obtains a shard key update value of an updated calculation result; wherein the shard key tail number prohibition table is included in a shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; if it is determined that the tail number of the shard key update value of the updated calculation result is not in the shard key tail number prohibition table, the shard key update value of the updated calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the updated calculation result, so as to smoothly solve the data skew problem without affecting the application.
[0093] It should be noted that the distributed data storage method provided in the embodiment of the present invention can be used in the financial field, and can also be used in any technical field other than the financial field. The embodiment of the present invention does not limit the application field of the distributed data storage method.
[0094] Figure 3 is a schematic diagram of the structure of a distributed data storage device provided by an embodiment of the present invention. Figure 3 As shown, the distributed data storage device provided by the embodiment of the present invention includes an updating unit 301 and a storage unit 302, wherein:
[0095] The update unit 301 is used to receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the update calculation result; wherein the shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; the storage unit 302 is used to return the shard key update value of the update calculation result to the application service if it is determined that the tail number of the shard key update value of the update calculation result is not in the shard key tail number prohibition table, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0096] Specifically, the update unit 301 in the device is used to receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result; wherein the shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; the storage unit 302 is used to return the shard key update value of the updated calculation result to the application service if it is determined that the tail number of the shard key update value of the updated calculation result is not in the shard key tail number prohibition table, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the updated calculation result.
[0097] The distributed data storage device provided by the embodiment of the present invention receives a new data request sent by an application service after the effective time of a shard key tail number prohibition table, adds 1 to a pre-stored shard key update value, and obtains a shard key update value of an updated calculation result; wherein the shard key tail number prohibition table is included in a shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; if it is determined that the tail number of the shard key update value of the updated calculation result is not in the shard key tail number prohibition table, the shard key update value of the updated calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the updated calculation result, so as to smoothly solve the data skew problem without affecting the application.
[0098] The embodiments of the present invention provide an embodiment of a distributed data storage device which can be specifically used to execute the processing flow of the above-mentioned method embodiments. Its functions are not described in detail here, and reference can be made to the detailed description of the above-mentioned method embodiments.
[0099] Figure 4 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as Figure 4 As shown, the electronic device includes: a processor (processor) 401, a memory (memory) 402 and a bus 403;
[0100] The processor 401 and the memory 402 communicate with each other via a bus 403;
[0101] The processor 401 is used to call the program instructions in the memory 402 to execute the methods provided by the above method embodiments, for example, including:
[0102] Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0103] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0104] If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0105] This embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can perform the methods provided by the above method embodiments, for example, including:
[0106] Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0107] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0108] If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0109] This embodiment provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program enables the computer to execute the methods provided by the above method embodiments, for example, including:
[0110] Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result;
[0111] The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time;
[0112] If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
[0113] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0114] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0115] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0116] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0117] In the description of this specification, the description with reference to the terms "one embodiment", "a specific embodiment", "some embodiments", "for example", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0118] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A distributed data storage method, characterized in that: include: Receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result; The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; If it is determined that the tail digit of the shard key update value of the update calculation result is not in the shard key tail digit prohibition table, the shard key update value of the update calculation result is returned to the application service, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
2. The distributed data storage method according to claim 1, characterized in that: Dynamically updating the shard key tail number prohibition table according to the regularly calculated data amount corresponding to each shard, including: Calculate the amount of data corresponding to each shard, and compare the amount of data in the shard with the baseline shard; The comparison benchmark shard includes one of the shard with the second largest amount of data, the shard with the smallest amount of data, and the average amount of data of the remaining shards excluding the shard with the largest amount of data; If it is determined that the amount of data corresponding to the shard with the largest amount of data exceeds the amount of data of the comparison benchmark shard by a preset proportion, the preset decimal corresponding to the shard with the largest amount of data is written into the shard key decimal prohibition table, and the effective time of the shard key decimal prohibition table is updated to the start time of the scheduled calculation.
3. The distributed data storage method according to claim 2, characterized in that: The distributed data storage method further includes: If it is determined that the comparison results of the data amounts of any two shards are less than the preset number, the shard key tail number prohibition table is restored to an initialized state, and the effective time of the shard key tail number prohibition table is updated to the timing calculation start time.
4. The distributed data storage method according to claim 3, characterized in that: The distributed data storage method further includes: If it is determined that the amount of data corresponding to the shard with the largest amount of data exceeds the amount of data of the comparison benchmark shard by less than a preset proportion, and the comparison result of the amount of data corresponding to the shard with the largest amount of data and the amount of data of at least one shard is greater than or equal to the preset number, the shard key tail digit prohibition table is maintained unchanged, and the effective time of the shard key tail digit prohibition table is updated to the start time of the scheduled calculation.
5. The distributed data storage method according to any one of claims 1 to 4, characterized in that: The distributed data storage method further includes: If it is determined that the tail number of the shard key update value of the update calculation result is in the shard key tail number prohibition table, continue to add 1 to the shard key update value of the update calculation result until the tail number of the latest shard key update value is not in the shard key tail number prohibition table, and return the latest shard key update value to the application service, so that the application service can store the corresponding data in the corresponding shard according to the latest shard key update value.
6. The distributed data storage method according to any one of claims 1 to 4, characterized in that: The distributed data storage method further includes: Clear the shard key tail number prohibition table and its corresponding effective time in the shard key tail number prohibition table change queue before the preset time.
7. The distributed data storage method according to any one of claims 1 to 4, characterized in that: The distributed data storage method is executed by a shard key generation service.
8. A distributed data storage device, characterized in that: include: An update unit, used to receive a new data request sent by the application service after the effective time of the shard key tail number prohibition table, add 1 to the pre-stored shard key update value, and obtain the shard key update value of the updated calculation result; The shard key tail number prohibition table is included in the shard key tail number prohibition table change queue, and the effective time of the shard key tail number prohibition table and the shard key tail number prohibition table in the shard key tail number prohibition table change queue is dynamically updated according to the data amount corresponding to each shard calculated at a fixed time; A storage unit is used to return the shard key update value of the update calculation result to the application service if it is determined that the decimal point of the shard key update value of the update calculation result is not in the shard key decimal point prohibition table, so that the application service can store the corresponding data in the corresponding shard according to the shard key update value of the update calculation result.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
