Data storage method and device

Through the dynamic classification storage method combined with vertical and horizontal splitting, the complexity and performance problems of data storage in financial trading systems are solved, and efficient data storage and processing are achieved.

CN112925859BActive Publication Date: 2024-10-22CHINA CONSTRUCTION BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110352541.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-31
Publication Date
2024-10-22
Estimated Expiration
2041-03-31

AI Technical Summary

Technical Problem

The existing centralized storage strategy cannot meet the high-performance requirements of financial transaction systems, especially when the amount of data is large and the transaction scenarios are complex. The simple sharding and splitting strategy is very intrusive to the system and cannot meet the needs of complex financial business scenarios. And distributed transactions affect transaction performance.

Method used

Adopt a dynamic data classification storage method, combining vertical splitting and horizontal splitting to store closely related data together, determine its category through the operation information of the statistical data table, and select appropriate routing strategies and sharding based on the category Key setting rules reduce distributed transactions and improve system performance.

Benefits of technology

It realizes data storage of dynamically deployed solutions under big data volume, meets the needs of complex financial transaction scenarios, reduces distributed transactions, and improves transaction performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112925859B_ABST
    Figure CN112925859B_ABST
Patent Text Reader

Abstract

The present invention discloses a data storage method and device, and relates to the field of big data technology. A specific implementation of the method includes: obtaining multiple data tables to be stored, classifying the multiple data tables to be stored, and obtaining multiple table groups to be stored; for each table group to be stored, determining the target database cluster corresponding to the table group to be stored; determining the routing strategy corresponding to the table group to be stored, and according to the routing strategy, storing the data tables to be stored in the table group to be stored to the corresponding shards in the target database cluster. This implementation can dynamically classify and store data, and store closely related data together by combining vertical splitting and horizontal splitting, meeting the needs of distributed storage, and meeting the needs of complexity of multi-scenario data storage; reducing distributed transactions and improving the performance of distributed systems in processing data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of big data technology, and in particular to a data storage method and device. Background Art

[0002] With the rapid development of the financial industry, competition among banks is becoming increasingly fierce. In order to reduce application costs, major banks have put distributed transformation on the agenda. The characteristics of the bank's transaction system are that there are many transaction types, complex transaction scenarios, and a large amount of stored data, and the data is centrally stored in the DB2 database. At present, the amount of data in the database tables in the system can reach up to tens of billions, and most of the data amounts range from tens of millions to billions. In the process of distributed storage transformation, data needs to be migrated from the DB2 database to a database system based on open source or self-developed. The existing centralized storage strategy is subject to the performance of the data node server and cannot meet the performance requirements of the transaction. The distributed transformation approach is to split the data by setting up a unified sharding key to meet the requirements of uniform data distribution and multi-shard distribution. However, simply splitting the shards will cause the following problems: Since the processes, conditions, and data structures of each business scenario are different, the use of a unified sharding strategy cannot meet the complex scenario requirements of financial business; the use of a unified sharding strategy has a large intrusion on the existing system and requires application reconstruction; 5. In the scenario of transactions across multiple tables, the data involved is stored in different shards, which will cause distributed transactions and affect the performance of transactions. Therefore, there is an urgent need for a solution for dynamic data deployment in the case of large data volumes, which is not affected by the database type, meets the complex transaction scenarios of finance and improves the performance of transactions. Summary of the invention

[0003] In view of this, an embodiment of the present invention provides a data storage method and device, which can dynamically classify and store data, combine vertical splitting and horizontal splitting to store closely related data together, meet the needs of distributed storage, and at the same time meet the needs of complexity of multi-scenario data storage; reduce distributed transactions and improve the performance of distributed systems in processing data.

[0004] To achieve the above object, according to one aspect of an embodiment of the present invention, a data storage method is provided, the method being applied to a distributed storage system, the distributed storage system comprising a plurality of database clusters, each of the database clusters comprising a plurality of shards; the method comprising:

[0005] Acquire multiple data tables to be stored, classify the multiple data tables to be stored, and obtain multiple table groups to be stored, wherein each table group to be stored includes at least one data table to be stored;

[0006] For each table group to be stored, determining a target database cluster corresponding to the table group to be stored;

[0007] Determine a routing strategy corresponding to the table group to be stored, and store the data tables to be stored in the table group to be stored on corresponding shards in the target database cluster according to the routing strategy.

[0008] Optionally, classifying the multiple data tables to be stored includes:

[0009] For each data table to be stored, collecting statistics on operation information of the data table to be stored;

[0010] The category of the data table to be stored is determined according to the operation information.

[0011] Optionally, the operation information includes the number of operations per unit time of one or more of the following operations: insert, delete, modify, query and cursor;

[0012] Determining the category of the data table to be stored according to the operation information includes:

[0013] The category of the data table to be stored is determined according to the number of operations of the one or more operations within a unit time.

[0014] Optionally, determining the category of the to-be-stored data table according to the number of operations of the one or more operations within a unit time includes:

[0015] When the number of operations of the query operation is greater than or equal to a first threshold, and the number of operations of the insert operation, delete operation, modify operation and cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is a query category;

[0016] When the number of operations of the insert operation is greater than or equal to a first threshold, and the number of operations of the query operation, the delete operation, the modify operation, and the cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is an insert category;

[0017] When the difference between the operation times of the query operation, the insert operation, the delete operation, the modify operation and the cursor operation is less than or equal to a third threshold, the category of the data table to be stored is an update category.

[0018] Optionally, determining a routing strategy corresponding to the table group to be stored, and storing the data table to be stored in the table group to be stored to a corresponding shard in the target database cluster according to the routing strategy includes:

[0019] If the category of the table group to be stored is a query category, the table group to be stored is stored on each shard in the target database cluster;

[0020] If the category of the table group to be stored is an insert type or an update type, determine the shard key setting rule of the target database cluster, determine the shard corresponding to each data table to be stored in the table group to be stored according to the shard key setting rule, and store the data table to be stored on its corresponding shard.

[0021] Optionally, according to the shard key setting rule, determining the shard corresponding to each to-be-stored data table in the to-be-stored table group includes:

[0022] Determine a main table from the multiple data tables to be stored in the table group to be stored, and use the other data tables to be stored in the table group to be stored except the main table as sub-tables;

[0023] According to the shard key setting rule, determining a target shard corresponding to the main table in the target database cluster;

[0024] A target sub-table associated with the main table is determined from the sub-tables, and the target shard is used as a shard corresponding to the target sub-table.

[0025] Optionally, determining a main table from a plurality of data tables to be stored in the table group to be stored includes:

[0026] Determine the association weights between the data tables to be stored in the table group to be stored;

[0027] According to the association weight, a main table is determined from the data tables to be stored in the table group to be stored.

[0028] Optionally, according to the shard key setting rule, determining a target shard corresponding to the main table in the target database cluster includes:

[0029] According to the shard key setting rule, each record of the main table is calculated to determine the target shard corresponding to the record;

[0030] Taking the target shard as the shard corresponding to the target sub-table includes: for each record to be stored in the target sub-table, determining a target record associated with the record to be stored in the main table, and taking the target shard where the target record is located as the shard corresponding to the record to be stored.

[0031] Optionally, the method further includes: hashing and storing sub-tables other than the target sub-table on shards of the target database cluster.

[0032] Optionally, hashing and storing subtables other than the target subtable on shards of the target database cluster includes: calculating primary keys of the other subtables using a hash algorithm to obtain hash values; and determining shards corresponding to the other subtables according to the hash values.

[0033] Optionally, the method further includes: generating an association information topology map according to an association relationship between the main table and the target sub-table.

[0034] Optionally, determining the association weights between the data tables to be stored in the table group to be stored includes:

[0035] Randomly select two data tables to be stored from the group of tables to be stored, use one of the data tables to be stored as a first data table, and use the other data table to be stored as a second data table;

[0036] Determine whether the first data table and the second data table are modified in the same transaction;

[0037] If yes, the number of the transactions is counted, and the number is used as the association weight between the first data table and the second data table.

[0038] Optionally, before acquiring a plurality of data tables to be stored, the method further includes:

[0039] For each of the database clusters, determine a shard key setting rule corresponding to the database cluster, and determine a shard key for each shard in the database cluster according to the shard key setting rule, so that the shard key has one or more of the following characteristics:

[0040] The shard key is associated with a data item common to the data stored on the shard;

[0041] The shard key has nothing to do with the business scenario;

[0042] The change frequency of the shard key is less than a preset value.

[0043] To achieve the above object, according to another aspect of an embodiment of the present invention, a data storage device is provided, the device is applied to a distributed storage system, the distributed storage system includes a plurality of database clusters, each of the database clusters includes a plurality of shards; the method includes:

[0044] A classification module, used for acquiring a plurality of data tables to be stored, classifying the plurality of data tables to be stored, and obtaining a plurality of table groups to be stored, wherein each table group to be stored includes at least one of the data tables to be stored;

[0045] A cluster determination module, configured to determine, for each table group to be stored, a target database cluster corresponding to the table group to be stored;

[0046] The shard determination module is used to determine the routing strategy corresponding to the table group to be stored, and store the data table to be stored in the table group to be stored on the corresponding shard in the target database cluster according to the routing strategy.

[0047] Optionally, the device further includes a shard key setting module, configured to:

[0048] For each of the database clusters, determine a shard key setting rule corresponding to the database cluster, and determine a shard key for each shard in the database cluster according to the shard key setting rule, so that the shard key has one or more of the following characteristics:

[0049] The shard key is associated with a data item common to the data stored on the shard;

[0050] The shard key has nothing to do with the business scenario;

[0051] The change frequency of the shard key is less than a preset value.

[0052] Optionally, the classification module is further used to: for each data table to be stored, collect statistics on operation information of the data table to be stored; and determine the category of the data table to be stored according to the operation information.

[0053] Optionally, the operation information includes the number of operations per unit time of one or more of the following operations: insert, delete, modify, query and cursor;

[0054] The classification module is further used to determine the category of the data table to be stored according to the number of operations of the one or more operations within a unit time.

[0055] Optionally, the classification module is also used for: when the number of operations of the query operation is greater than or equal to a first threshold, and the number of operations of the insert operation, delete operation, modify operation and cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is a query category; when the number of operations of the insert operation is greater than or equal to the first threshold, and the number of operations of the query operation, delete operation, modify operation and cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is an insert category; when the difference between the number of operations of the query operation, insert operation, delete operation, modify operation and cursor operation is less than or equal to a third threshold, the category of the data table to be stored is an update category.

[0056] Optionally, the fragmentation determination module is further configured to:

[0057] If the category of the table group to be stored is a query category, the table group to be stored is stored on each shard in the target database cluster;

[0058] If the category of the table group to be stored is an insert type or an update type, determine the shard key setting rule of the target database cluster, determine the shard corresponding to each data table to be stored in the table group to be stored according to the shard key setting rule, and store the data table to be stored on its corresponding shard.

[0059] Optionally, the fragmentation determination module is further configured to:

[0060] Determine a main table from the multiple data tables to be stored in the table group to be stored, and use the other data tables to be stored in the table group to be stored except the main table as sub-tables;

[0061] According to the shard key setting rule, determining a target shard corresponding to the main table in the target database cluster;

[0062] A target sub-table associated with the main table is determined from the sub-tables, and the target shard is used as a shard corresponding to the target sub-table.

[0063] Optionally, the shard determination module is further used to: determine association weights between the data tables to be stored in the table group to be stored; and determine a main table from the data tables to be stored in the table group to be stored according to the association weights.

[0064] Optionally, the fragmentation determination module is further configured to:

[0065] According to the shard key setting rule, each record of the main table is calculated to determine the target shard corresponding to the record;

[0066] Taking the target shard as the shard corresponding to the target sub-table includes: for each record to be stored in the target sub-table, determining a target record associated with the record to be stored in the main table, and taking the target shard where the target record is located as the shard corresponding to the record to be stored.

[0067] Optionally, the shard determination module is further used to: hash and store other sub-tables except the target sub-table on the shards of the target database cluster.

[0068] Optionally, the shard determination module is further used to: calculate the primary key of the other sub-table using a hash algorithm to obtain a hash value; and determine the shard corresponding to the other sub-table according to the hash value.

[0069] Optionally, the device further comprises a topology map generating module, configured to generate a correlation information topology map according to the correlation relationship between the main table and the target sub-table.

[0070] Optionally, the fragmentation determination module is further configured to:

[0071] Randomly select two data tables to be stored from the group of tables to be stored, use one of the data tables to be stored as a first data table, and use the other data table to be stored as a second data table;

[0072] Determine whether the first data table and the second data table are modified in the same transaction;

[0073] If yes, the number of the transactions is counted, and the number is used as the association weight between the first data table and the second data table.

[0074] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, there is provided an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the data storage method of an embodiment of the present invention.

[0075] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the data storage method of the embodiment of the present invention is implemented.

[0076] An embodiment of the above invention has the following advantages or beneficial effects: by obtaining multiple data tables to be stored, the multiple data tables to be stored are classified to obtain multiple table groups to be stored, wherein each table group to be stored includes at least one data table to be stored; for each table group to be stored, a target database cluster corresponding to the table group to be stored is determined; a routing strategy corresponding to the table group to be stored is determined, and according to the routing strategy, the data tables to be stored in the table group to be stored are stored on the corresponding shards in the target database cluster, so that data can be dynamically classified and stored, and closely related data can be stored together by combining vertical splitting and horizontal splitting, so as to meet the needs of distributed storage and the complexity of multi-scenario data storage; distributed transactions are reduced and the performance of distributed systems in processing data is improved.

[0077] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0079] Figure 1 is a schematic diagram of the main process of the data storage method according to an embodiment of the present invention;

[0080] Figure 2 is a schematic diagram of the architecture of a distributed storage system according to an embodiment of the present invention;

[0081] Figure 3 is a schematic diagram of a sub-process of a data storage method according to an embodiment of the present invention;

[0082] Figure 4 is a schematic diagram of main modules of a data storage device according to an embodiment of the present invention;

[0083] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0084] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0085] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0086] Figure 1 is a flow chart of the main steps of the data storage method according to an embodiment of the present invention. Figure 1 As shown, the method includes:

[0087] Step S101: acquiring a plurality of data tables to be stored, and classifying the plurality of data tables to be stored to obtain a plurality of table groups to be stored, wherein each table group to be stored includes at least one of the data tables to be stored;

[0088] Step S102: for each table group to be stored, determining a target database cluster corresponding to the table group to be stored;

[0089] Step S103: determining a routing strategy corresponding to the table group to be stored, and storing the data tables to be stored in the table group to be stored on corresponding shards in the target database cluster according to the routing strategy.

[0090] The data storage method of the embodiment of the present invention can be applied to a distributed storage system. The distributed storage system includes multiple database clusters, and different database clusters are used to store different types of data. Each database cluster includes multiple shards, that is, each database cluster includes multiple databases. Each shard has a shard key, and different shards are distinguished by the shard key. Different shards store different data. The distributed storage system of this embodiment first splits the database vertically (that is, splits the database vertically into multiple database clusters), and then splits it horizontally (splits each database cluster into multiple shards), so that related data is deployed on the same shard, reducing distributed transactions and significantly improving the performance of the distributed storage system.

[0091] In the method of the embodiment of the present invention, before storing the data table to be stored, it is necessary to determine the shard key of each shard. As an optional embodiment, the shard key of each shard can be determined according to the following process:

[0092] For each of the database clusters, determine a shard key setting rule corresponding to the database cluster, and determine a shard key for each shard in the database cluster according to the shard key setting rule, so that the shard key has one or more of the following characteristics:

[0093] The shard key is associated with a data item common to the data stored on the shard;

[0094] The shard key has nothing to do with the business scenario;

[0095] The change frequency of the shard key is less than a preset value.

[0096] Specifically, in order to make the sharding key have the above characteristics, when setting the sharding key: try to select an existing data column, and most data tables contain this column, that is, to ensure that there is no need to change the structure of the data table on a large scale. Specifically, a column of the stored data table or the result of calculating a column (such as hash calculation) can be selected as the sharding key; try to select a field with no business meaning, and the change of this field will not be rigid business, and will not cause large-scale application transformation; try to select a field that is not affected by the change of business data, that is, the change is not large, otherwise it may cause large-scale data migration. Therefore, in this embodiment, the sharding key can be generated according to the fields of the associated columns between the data tables. For the application scenario of the banking business system, the fields of the associated columns between the data tables are generally account information, bank card number information and customer number information. Then, when setting the sharding key, it can be set according to the provincial bank number corresponding to the account information and the customer number corresponding to the account number, or it can be set according to the provincial bank number corresponding to the card number and the customer number corresponding to the card number, or it can be set according to the provincial bank number and the customer number corresponding to the customer number.

[0097] In an optional embodiment, the distributed storage system may further include an application routing cluster, which is used to store sharding key setting rules. The application routing cluster may also store the storage location of the data, that is, record the location information of the data on the database cluster. The distributed storage system adopts a two-layer architecture, with the upper layer being the application routing cluster and the lower layer being the database cluster. The distributed storage system stores different sharding key setting rules (data sharding rules) through the application routing cluster, and the addition and modification of the sharding key setting rules will also be dynamically reflected in the application routing cluster, thereby realizing dynamic data storage and meeting the complexity of multi-scenario data deployment.

[0098] As a specific example, Figure 2 As shown, the distributed storage system includes an application routing cluster and multiple database clusters, each database cluster includes multiple shards, that is, each database cluster includes multiple databases. Each shard has a shard key, and different shards are distinguished by the shard key.

[0099] In this embodiment, the database cluster can be classified into three categories, which are used to store query data, insert data and update data. Among them, query data refers to data with read-only attributes. This type of data is generally a parameter data table. This type of data is usually not modified or the modification frequency is low. The storage location of the data table is not sensitive, the data is not real-time sensitive, and can be accessed across data sources. Insert data refers to flow data tables and detail data tables. The volume of this type of data is large, the growth volume is extremely large, and there is a need to clean up by time. The data is usually not modified or the modification frequency is low. This type of data can be written outside the transaction (i.e. asynchronous processing, the insertion of this type of data will not affect the submission or rollback of the corresponding transaction). Update data is usually a confidence data table. This type of data is modified frequently. The storage location of the data table is sensitive. When the data changes, the data update of other tables may be required to be submitted or rolled back synchronously. The application routing cluster can use nosql (non-relational database) to store the location relationship information between the data and the cluster where it is located, which can be used to route to the shard where the data is located. The user accesses the distributed storage system through the application cluster, obtains routing information through the application routing cluster, and routes to the corresponding shard.

[0100] The distributed storage system of this embodiment can meet the complexity of data deployment in multiple scenarios, and can dynamically redeploy data, and can be applied to banking business systems.

[0101] After determining the shard keys of each shard of the distributed storage system, data may be stored in the distributed storage system according to steps S101-S103.

[0102] Regarding step S101, in the above embodiment, the database clusters are classified, and each type of database cluster stores one type of data. Therefore, in this step, the data tables to be stored need to be classified to determine the database clusters corresponding to each data table to be stored.

[0103] Specifically, the data tables to be stored can be classified according to the following process:

[0104] For each data table to be stored, counting the operation information of the data table to be stored; wherein the operation information includes the number of operations of one or more of the following operations per unit time: insert, delete, modify, query and cursor;

[0105] According to the operation information, the category of the data table to be stored is determined. That is, according to the number of operations of the one or more operations in a unit time, the category of the data table to be stored is determined. When the number of operations of the query operation is greater than or equal to the first threshold, and the number of operations of the insert operation, delete operation, modify operation and cursor operation is less than or equal to the second threshold, the category of the data table to be stored is the query category; when the number of operations of the insert operation is greater than or equal to the first threshold, and the number of operations of the query operation, delete operation, modify operation and cursor operation is less than or equal to the second threshold, the category of the data table to be stored is the insert category; when the difference between the number of operations of the query operation, insert operation, delete operation, modify operation and cursor operation is less than or equal to the third threshold, the category of the data table to be stored is the update category. Among them, the first threshold, the second threshold and the third threshold can be flexibly set according to the application scenario, and the present invention is not limited here. As an example, the number of query operations on the data tables to be stored of the query class is greater than the number of other operations; the number of insert operations on the data tables to be stored of the insert class is greater than the number of other operations; there is no difference in the order of magnitude of the number of operations on the data tables to be stored of the update class.

[0106] For step S102, the data tables to be stored belonging to the query class are stored in the database cluster of the query class, the data tables to be stored belonging to the insert class are stored in the database cluster of the insert class, and the data tables to be stored belonging to the update class are stored in the database cluster of the update class.

[0107] For step S103, after determining the database cluster corresponding to the data table to be stored, it is necessary to determine the shard corresponding to the data table to be stored. Specifically, first determine the routing strategy corresponding to each type of table group to be stored, and then store the data table to be stored in the table group to be stored to the corresponding shard in the target database cluster according to the routing strategy.

[0108] More specifically, if the category of the table group to be stored is a query class, the table group to be stored is stored on each shard in the target database cluster. For the data tables to be stored of the query class, since the main usage scenario of this type of data table is query, a single storage node (i.e., a single database) can meet the storage requirements of the full amount of data. Therefore, this type of data table to be stored can be stored on any shard in the database cluster of the query class. In order to disperse the query pressure of a single storage node, this type of data table to be stored can be stored on each shard in the database cluster of the query class. In an optional embodiment, it is not necessary to determine the main table and sub-table in the table group to be stored of the query class, and the data tables to be stored of this class can be directly written to all shards in the database cluster of the query class.

[0109] If the category of the table group to be stored is an insert type or an update type, determine the shard key setting rule of the target database cluster, determine the shard corresponding to each data table to be stored in the table group to be stored according to the shard key setting rule, and store the data table to be stored on its corresponding shard.

[0110] For a distributed storage system, the fewer cross-shard access scenarios within the same transaction, the fewer distributed transactions generated, and the better the system's performance in processing data. Based on this premise, for the data tables to be stored of the insert and update types, this embodiment adopts a data storage model based on association relationships to store the data tables to be stored with association relationships in the same shard. In this data model, it is necessary to first determine the main table and sub-table in the table group to be stored (if there is only one data table to be stored in the table group to be stored, the data table to be stored is the main table), then determine the shard corresponding to the main table, and store the main table on the shard, and then store the target sub-table with an association relationship with the main table on the shard, wherein the target sub-table has the same fields as the main table. For sub-tables that have no association relationship with the main table, they can be hashed and stored on any shard in the database cluster (the database cluster refers to the database cluster corresponding to the main table).

[0111] More specifically, the main table can be determined based on the association weights between the data tables to be stored in the table group to be stored. Figure 3 As shown, the association weights between the data tables to be stored can be determined according to the following process:

[0112] Step S301: arbitrarily selecting two data tables to be stored from the table group to be stored, taking one of the data tables to be stored as a first data table and the other data table to be stored as a second data table;

[0113] Step S302: Determine whether the first data table and the second data table are modified in the same transaction;

[0114] Step S303: If yes, count the number of the transactions and use the number as the association weight between the first data table and the second data table.

[0115] In this embodiment, a quantifiable indicator is introduced, namely, the association weight Ω between data tables. Ω ab Indicates the association weight between data table a and data table b. If data table a and data table b are modified simultaneously in N transactions, the association weight between data table a and data table b is N, where N is an integer.

[0116] After obtaining the association weights between the data tables to be stored, the sum of the association weights between each data table to be stored and other data tables to be stored can be counted, and the data table to be stored having the largest sum of association weights with other data tables to be stored is taken as the main table.

[0117] As an example, assume that there are five data tables to be stored, namely, data table a, data table b, data table c, data table d, and data table e, and the association weights between them are shown in the following Table 1:

[0118] Table 1:

[0119] a b c d e a NA 2 3 5 4 b 2 NA 1 4 3 c 3 1 NA 2 0 d 5 4 2 NA 1 e 4 3 0 1 NA

[0120] According to the statistics of this table: the sum of the association weights between data table a and other data tables is 14; the sum of the association weights between data table b and other data tables is 10; the sum of the association weights between data table c and other data tables is 6; the sum of the association weights between data table d and other data tables is 12; the sum of the association weights between data table e and other data tables is 8. The sum of the association weights between data table a and other data tables is the largest, so data table a is the main table, and data tables b, c, d and e are sub-tables.

[0121] After determining the main table and the target sub-table, first calculate each record of the main table to determine the target shard corresponding to the record, then for each record to be stored in the target sub-table, determine the target record associated with the record to be stored in the main table, and use the target shard where the target record is located as the shard corresponding to the record to be stored, and finally hash and store the other sub-tables except the target sub-table on the shard of the target database cluster. Specifically, first determine the shard key setting rule of the database cluster corresponding to the main table, and then calculate each record of the main table according to the shard key setting rule to determine the target shard corresponding to the record. For example, assuming that the field of the same column of the target sub-table and the main table is account information, and the shard key setting rule corresponding to the main table is set according to the provincial bank number corresponding to the account information and the customer number corresponding to the account number, then for each record of the main table, calculate according to the provincial bank number corresponding to the account information in the record and the customer number corresponding to the account information, and the calculation result is recorded as the shard key of the target shard. Then, for each record to be stored in the target subtable, a target record with the same account information as the record to be stored is determined in the main table, and the target shard where the target record is located is used as the shard corresponding to the record to be stored.

[0122] Subtables that are not associated with the main table (i.e., subtables that have no associated columns with the main table) are not very popular, and it is meaningless to forcibly associate them with the main table, so the data of such tables is hashed and stored. Therefore, for subtables other than the target subtable (i.e., subtables that are not associated with the main table, and subtables that have no associated columns with the main table), they can be hashed on the shards of the target database cluster according to the following process:

[0123] Calculate the primary key of the other subtable using a hash algorithm to obtain a hash value;

[0124] According to the hash value, the shards corresponding to the other sub-tables are determined.

[0125] Specifically, firstly, the primary key of each record in other subtables is calculated using a hash algorithm to obtain a hash value, assuming that the hash value is a 7-digit number. Then, the shard key corresponding to the pre-divided interval into which the hash value falls is determined, and the record is stored in the shard corresponding to the shard key.

[0126] In an optional embodiment, the method further includes generating an association information topology map according to the association relationship between the main table and the target sub-table. Specifically, the association columns (generally account information, bank card number information, customer number information) between the relevant main table and the target sub-table can be counted, and a topology map between different main tables and target sub-tables can be drawn according to the association columns. The topology map is used to count the association relationship information between the main table and the target sub-table, that is, the associated columns, and the shard key generation rule of the main table can be more determined according to the topology map.

[0127] The data storage method of the embodiment of the present invention obtains multiple data tables to be stored, classifies the multiple data tables to be stored, and obtains multiple table groups to be stored, wherein each table group to be stored includes at least one data table to be stored; for each table group to be stored, determines a target database cluster corresponding to the table group to be stored; determines a routing strategy corresponding to the table group to be stored, and stores the data tables to be stored in the table group to be stored on corresponding shards in the target database cluster according to the routing strategy, and can dynamically classify and store data, and store closely related data together in combination with vertical splitting and horizontal splitting, thereby meeting the needs of distributed storage and the complexity of multi-scenario data storage; reduces distributed transactions and improves the performance of distributed systems in processing data.

[0128] Figure 4 4 is a schematic diagram of the structure of a data storage device 400 according to an embodiment of the present invention, wherein the device is applied to a distributed storage system, wherein the distributed storage system includes a plurality of database clusters, and each of the database clusters includes a plurality of shards. Figure 4 As shown, the device 400 includes:

[0129] The classification module 401 is used to obtain a plurality of data tables to be stored, classify the plurality of data tables to be stored, and obtain a plurality of table groups to be stored, wherein each table group to be stored includes at least one of the data tables to be stored;

[0130] A cluster determination module 402 is used to determine, for each table group to be stored, a target database cluster corresponding to the table group to be stored;

[0131] The shard determination module 403 is used to determine the routing strategy corresponding to the table group to be stored, and store the data tables to be stored in the table group to be stored on the corresponding shards in the target database cluster according to the routing strategy.

[0132] Optionally, the device also includes a shard key setting module, which is used to: for each of the database clusters, determine the shard key setting rules corresponding to the database cluster, and determine the shard key of each shard in the database cluster according to the shard key setting rules, so that the shard key has one or more of the following characteristics: the shard key is related to the data items shared by the data stored on the shard; the shard key is independent of the business scenario; the change frequency of the shard key is less than a preset value.

[0133] Optionally, the classification module 401 is further configured to: for each data table to be stored, collect statistics on operation information of the data table to be stored; and determine the category of the data table to be stored according to the operation information.

[0134] Optionally, the operation information includes the number of operations per unit time of one or more of the following operations: insert, delete, modify, query and cursor;

[0135] The classification module 401 is further used to determine the category of the data table to be stored according to the number of operations of the one or more operations within a unit time.

[0136] Optionally, the classification module 401 is also used for: when the number of operations of the query operation is greater than or equal to a first threshold, and the number of operations of the insert operation, delete operation, modify operation and cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is a query category; when the number of operations of the insert operation is greater than or equal to a first threshold, and the number of operations of the query operation, delete operation, modify operation and cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is an insert category; when the difference between the number of operations of the query operation, insert operation, delete operation, modify operation and cursor operation is less than or equal to a third threshold, the category of the data table to be stored is an update category.

[0137] Optionally, the shard determination module 403 is further used to: if the category of the table group to be stored is a query category, then store the table group to be stored on each shard in the target database cluster; if the category of the table group to be stored is an insert category or an update category, then determine the shard key setting rule of the target database cluster, determine the shard corresponding to each data table to be stored in the table group to be stored according to the shard key setting rule, and store the data table to be stored on its corresponding shard.

[0138] Optionally, the shard determination module 403 is further used to: determine a main table from multiple data tables to be stored in the table group to be stored, and use other data tables to be stored in the table group to be stored except the main table as sub-tables; determine a target shard corresponding to the main table in the target database cluster according to the shard key setting rule; determine a target sub-table having an association relationship with the main table from the sub-tables, and use the target shard as the shard corresponding to the target sub-table.

[0139] Optionally, the shard determination module 403 is further configured to: determine association weights between the data tables to be stored in the table group to be stored; and determine a main table from the data tables to be stored in the table group to be stored according to the association weights.

[0140] Optionally, the shard determination module 403 is further used to: calculate each record of the main table according to the shard key setting rule to determine the target shard corresponding to the record; taking the target shard as the shard corresponding to the target sub-table includes: for each record to be stored in the target sub-table, determining a target record associated with the record to be stored in the main table, and taking the target shard where the target record is located as the shard corresponding to the record to be stored.

[0141] Optionally, the shard determination module 403 is further configured to: hash and store other sub-tables except the target sub-table on the shards of the target database cluster.

[0142] Optionally, the shard determination module 403 is further used to: calculate the primary key of the other sub-table using a hash algorithm to obtain a hash value; and determine the shard corresponding to the other sub-table according to the hash value.

[0143] Optionally, the device further comprises a topology map generating module, configured to generate a correlation information topology map according to the correlation relationship between the main table and the target sub-table.

[0144] Optionally, the shard determination module 403 is also used to: arbitrarily select two data tables to be stored from the group of tables to be stored, use one of the data tables to be stored as the first data table, and use the other data table to be stored as the second data table; determine whether the first data table and the second data table are modified in the same transaction; if so, count the number of transactions and use the number as the association weight of the first data table and the second data table.

[0145] The data storage device of the embodiment of the present invention obtains multiple data tables to be stored, classifies the multiple data tables to be stored, and obtains multiple table groups to be stored, wherein each table group to be stored includes at least one data table to be stored; for each table group to be stored, determines a target database cluster corresponding to the table group to be stored; determines a routing strategy corresponding to the table group to be stored, and stores the data tables to be stored in the table group to be stored on corresponding shards in the target database cluster according to the routing strategy, and can dynamically classify and store data, and store closely related data together by combining vertical splitting and horizontal splitting, thereby meeting the needs of distributed storage and the complexity of multi-scenario data storage; reduces distributed transactions and improves the performance of distributed systems in processing data.

[0146] The above device can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.

[0147] Figure 5 An exemplary system architecture 500 is shown to which the data storage method or data storage device according to the embodiment of the present invention can be applied.

[0148] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0149] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0150] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0151] The server 505 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using the terminal devices 501, 502, and 503. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information and product information) to the terminal device.

[0152] It should be noted that the data storage method provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the data storage device is generally arranged in the server 505 .

[0153] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0154] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0155] like Figure 6As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a hash access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0156] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0157] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.

[0158] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a hash access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0159] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0160] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a sending module, an acquisition module, a determination module, and a first processing module. The names of these modules do not, in some cases, constitute a limitation on the unit itself. For example, the sending module may also be described as a "module for sending a picture acquisition request to the connected server."

[0161] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:

[0162] Acquire multiple data tables to be stored, classify the multiple data tables to be stored, and obtain multiple table groups to be stored, wherein each table group to be stored includes at least one data table to be stored;

[0163] For each table group to be stored, determining a target database cluster corresponding to the table group to be stored;

[0164] When there are multiple data tables to be stored in the table group to be stored, a main table is determined from the multiple data tables to be stored in the table group to be stored, and the other data tables to be stored in the table group to be stored except the main table are used as sub-tables; a target shard corresponding to the main table is determined in the target database cluster, and the main table is stored in the target shard; a target sub-table having an association relationship with the main table is determined from the sub-tables, and the target sub-table is stored in the target shard.

[0165] The technical solution of the embodiment of the present invention can dynamically classify and store data, and combine vertical splitting and horizontal splitting to store closely related data together, meet the needs of distributed storage, and at the same time meet the needs of complexity of multi-scenario data storage; reduce distributed transactions and improve the performance of distributed systems in processing data.

[0166] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A data storage method, characterized in that: The method is applied to a distributed storage system, wherein the distributed storage system includes a plurality of database clusters, each of which includes a plurality of shards; the method includes: Acquire multiple data tables to be stored, classify the multiple data tables to be stored, and obtain multiple table groups to be stored, wherein each table group to be stored includes at least one data table to be stored; For each table group to be stored, determining a target database cluster corresponding to the table group to be stored; Determine a routing strategy corresponding to the table group to be stored, and store the data tables to be stored in the table group to be stored on the corresponding shards in the target database cluster according to the routing strategy, including: if the category of the table group to be stored is a query category, store the table group to be stored on each shard in the target database cluster; if the category of the table group to be stored is an insert category or an update category, determine a shard key setting rule of the target database cluster, determine the shard corresponding to each data table to be stored in the table group to be stored according to the shard key setting rule, and store the data tables to be stored on their corresponding shards.

2. The method according to claim 1, characterized in that: Classifying the multiple data tables to be stored includes: For each data table to be stored, collecting statistics on operation information of the data table to be stored; According to the operation information, the category of the data table to be stored is determined.

3. The method according to claim 2, characterized in that The operation information includes the number of operations per unit time of one or more of the following operations: insert, delete, modify, query and cursor; Determining the category of the data table to be stored according to the operation information includes: The category of the data table to be stored is determined according to the number of operations of the one or more operations within a unit time.

4. The method according to claim 3, characterized in that Determining the category of the to-be-stored data table according to the number of operations of the one or more operations within a unit time includes: When the number of operations of the query operation is greater than or equal to a first threshold, and the number of operations of the insert operation, delete operation, modify operation and cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is a query category; When the number of operations of the insert operation is greater than or equal to a first threshold, and the number of operations of the query operation, the delete operation, the modify operation, and the cursor operation are all less than or equal to a second threshold, the category of the data table to be stored is an insert category; When the difference between the operation times of the query operation, the insert operation, the delete operation, the modify operation and the cursor operation is less than or equal to a third threshold, the category of the data table to be stored is an update category.

5. The method according to claim 1, characterized in that Determining, according to the shard key setting rule, the shard corresponding to each to-be-stored data table in the to-be-stored table group includes: Determine a main table from the multiple data tables to be stored in the table group to be stored, and use the other data tables to be stored in the table group to be stored except the main table as sub-tables; According to the shard key setting rule, determining a target shard corresponding to the main table in the target database cluster; A target subtable associated with the main table is determined from the subtables, and the target shard is used as a shard corresponding to the target subtable, wherein the target subtable has the same columns as the main table.

6. The method according to claim 5, characterized in that Determining a main table from a plurality of to-be-stored data tables of the to-be-stored table group includes: Determine the association weights between the data tables to be stored in the table group to be stored; According to the association weight, a main table is determined from the data tables to be stored in the table group to be stored.

7. The method according to claim 6, characterized in that Determining the target shard corresponding to the main table in the target database cluster according to the shard key setting rule includes: According to the shard key setting rule, each record of the main table is calculated to determine the target shard corresponding to the record; Taking the target shard as the shard corresponding to the target sub-table includes: for each record to be stored in the target sub-table, determining a target record associated with the record to be stored in the main table, and taking the target shard where the target record is located as the shard corresponding to the record to be stored.

8. The method according to claim 5, characterized in that The method further comprises: The sub-tables other than the target sub-table are hashed and stored on the shards of the target database cluster.

9. The method according to claim 8, characterized in that The step of hashing and storing the sub-tables other than the target sub-table on the shards of the target database cluster includes: Calculate the primary key of the other subtable using a hash algorithm to obtain a hash value; According to the hash value, the shards corresponding to the other sub-tables are determined.

10. The method according to claim 5, characterized in that The method further comprises: According to the association relationship between the main table and the target sub-table, a correlation information topology map is generated.

11. The method according to claim 6, characterized in that Determining the association weights between the data tables to be stored in the table group to be stored includes: Randomly select two data tables to be stored from the group of tables to be stored, use one of the data tables to be stored as a first data table, and use the other data table to be stored as a second data table; Determine whether the first data table and the second data table are modified in the same transaction; If yes, the number of the transactions is counted, and the number is used as the association weight between the first data table and the second data table.

12. The method according to claim 1, characterized in that Before acquiring a plurality of data tables to be stored, the method further includes: For each of the database clusters, determine a shard key setting rule corresponding to the database cluster, and determine a shard key for each shard in the database cluster according to the shard key setting rule, so that the shard key has one or more of the following characteristics: The shard key is associated with a data item common to the data stored on the shard; The shard key has nothing to do with the business scenario; The change frequency of the shard key is less than a preset value.

13. A data storage device, characterized in that: The device is applied to a distributed storage system, wherein the distributed storage system includes a plurality of database clusters, each of which includes a plurality of shards; the device includes: A classification module, used for acquiring a plurality of data tables to be stored, classifying the plurality of data tables to be stored, and obtaining a plurality of table groups to be stored, wherein each table group to be stored includes at least one of the data tables to be stored; A cluster determination module, configured to determine, for each table group to be stored, a target database cluster corresponding to the table group to be stored; The shard determination module is used to determine the routing strategy corresponding to the table group to be stored, and store the data tables to be stored in the table group to be stored on the corresponding shards in the target database cluster according to the routing strategy, including: if the category of the table group to be stored is a query category, the table group to be stored is stored on each shard in the target database cluster; if the category of the table group to be stored is an insert category or an update category, the shard key setting rule of the target database cluster is determined, and according to the shard key setting rule, the shard corresponding to each data table to be stored in the table group to be stored is determined, and the data table to be stored is stored on its corresponding shard.

14. The device according to claim 13, characterized in that The device also includes a shard key setting module, which is used to: For each of the database clusters, determine a shard key setting rule corresponding to the database cluster, and determine a shard key for each shard in the database cluster according to the shard key setting rule, so that the shard key has one or more of the following characteristics: The shard key is associated with a data item common to the data stored on the shard; The shard key has nothing to do with the business scenario; The change frequency of the shard key is less than a preset value.

15. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 12.

16. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 12 is implemented.