Data migration method and device, computer equipment and storage medium
By determining resource costs and selecting target slots based on slot usage information in the database cluster, the problem of low data migration efficiency in the prior art is solved, and more efficient and fast data migration is achieved.
Patent Information
- Application Number
- CN202411769382.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-02-28
AI Technical Summary
Existing database clusters are inefficient and slow during data migration, making it difficult to alleviate storage pressure and load pressure.
When receiving the data migration instruction, the slot resource cost is determined based on the slot usage information of each slot in the database cluster, the appropriate target slot is selected and the data migration strategy is formulated to achieve data migration.
Improve the efficiency and speed of data migration, optimize the resource utilization of database clusters, and alleviate storage and load pressure.
Smart Images

Figure CN119536661A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a data migration method, device, computer equipment and storage medium. Background Art
[0002] When a certain application has a large number of user visits, using only one server to provide database services to users will inevitably affect the user experience. This requires multiple servers to jointly provide database services to users, thus forming a so-called database cluster. As the number of user visits gradually increases, the storage and processing capabilities of the database cluster will also reach the upper limit of the cluster capacity, which requires data migration to alleviate the storage and load pressure of the original server.
[0003] At present, according to the storage rules of the database cluster, the data that meets the migration conditions is often found and exported from the source database instance one by one, and then the data exported from the source database instance is imported into the target database instance one by one. However, the entire migration operation process of the above method is cumbersome and time-consuming, resulting in low data migration efficiency and slow migration speed. Summary of the invention
[0004] Based on this, it is necessary to provide a data migration method, apparatus, computer device and storage medium to address the above technical problems, which can improve the efficiency and speed of data migration.
[0005] In a first aspect, the present application provides a data migration method, comprising:
[0006] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0007] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0008] According to the data migration strategy, the data stored in the target slot is migrated.
[0009] In one embodiment, the slot usage information of each slot includes the central processing unit CPU usage, memory usage and network usage of the slot;
[0010] The determining the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster includes:
[0011] For each slot, the square of the difference between the CPU usage of the slot and a preset constant is used as the first cost;
[0012] The square of the difference between the memory usage rate of the slot and the preset constant is used as the second cost;
[0013] The square of the difference between the network usage rate of the slot and the preset constant is used as the third cost;
[0014] A slot resource cost of the slot is determined according to the first cost, the second cost, and the third cost.
[0015] In one embodiment, determining a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot includes:
[0016] The slots whose slot resource cost is greater than the preset slot threshold are all regarded as candidate slots;
[0017] The candidate database to which each candidate slot belongs is used as the target database;
[0018] Determining the initial resource cost of the target database according to the slot resource cost of each slot in the target database;
[0019] A target slot for migration and a data migration strategy corresponding to the target slot are determined according to the initial resource cost of the target database.
[0020] In one embodiment, determining a target slot for migration and a data migration strategy corresponding to the target slot according to the initial resource cost of the target database includes:
[0021] For each candidate slot, according to the initial resource cost of the target database to which the candidate slot belongs, determine the migration benefit information of migrating the data in the candidate slot from the target database to other databases; wherein the other databases are databases in the database cluster other than the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes a migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database;
[0022] According to the migration benefit information corresponding to each candidate slot, a target slot for migration is selected from each candidate slot, and a data migration strategy corresponding to the target slot is determined.
[0023] In one embodiment, determining migration benefit information of migrating data in the candidate slot from the target database to another database according to the initial resource cost of the target database to which the candidate slot belongs includes:
[0024] For each database in the other databases, determining an initial resource cost of the database according to a slot resource cost of each slot in the database;
[0025] Determine a target resource cost of the database after migrating the data in the candidate slot to the database, and a target resource cost of the target database to which the candidate slot belongs;
[0026] The migration benefit value of the data in the candidate slot from the target database to the database is determined according to the initial resource cost and the target resource cost of the database and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs.
[0027] In one embodiment, determining the migration benefit value of migrating the data in the candidate slot from the target database to the database according to the initial resource cost and the target resource cost of the database, and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs, includes:
[0028] Taking the difference between the initial resource cost and the target resource cost of the database as the first benefit value;
[0029] taking the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs as the second benefit value;
[0030] The sum of the first benefit value and the second benefit value is used as a migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0031] In one embodiment, selecting a target slot for migration and a data migration strategy corresponding to the target slot from each candidate slot according to the migration benefit information corresponding to each candidate slot includes:
[0032] The candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration;
[0033] Taking the target database to which the target slot belongs as the source database;
[0034] The other database corresponding to the maximum migration benefit value is used as the destination database;
[0035] A data migration strategy corresponding to the target slot is determined according to the target slot, the source database, and the destination database.
[0036] In a second aspect, the present application further provides a data migration device, including:
[0037] an information determination module, configured to determine a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster when receiving a data migration instruction for the database cluster;
[0038] A strategy determination module, used to determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0039] The data migration module is used to migrate the data stored in the target slot according to the data migration strategy.
[0040] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0041] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0042] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0043] According to the data migration strategy, the data stored in the target slot is migrated.
[0044] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0045] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0046] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0047] According to the data migration strategy, the data stored in the target slot is migrated.
[0048] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0049] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0050] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0051] According to the data migration strategy, the data stored in the target slot is migrated.
[0052] The above data migration method, device, computer equipment and storage medium, when receiving a data migration instruction for a database cluster, determine the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster, and determine the target slot for migration and the data migration strategy corresponding to the target slot according to the slot resource cost of each slot; further, according to the data migration strategy, migrate the data stored in the target slot. The above scheme obtains slot-level information in the database cluster, that is, slot usage information, to obtain more detailed information in the database cluster, and according to the slot usage information, ensures the accuracy of the slot resource cost of each slot determined; further, according to the slot resource cost of each slot, the specific usage of each candidate database in the database cluster can be analyzed more finely, thereby ensuring the accuracy of the determined target slot and the data migration strategy corresponding to the target slot; further, it can be ensured that after the data stored in the target slot is migrated according to the data migration strategy, the resource utilization of the database cluster can be improved, and the speed and efficiency of data migration can also be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0054] Figure 1 A schematic diagram of a data migration method in one embodiment;
[0055] Figure 2 A schematic diagram of a process for determining a slot resource cost of each slot in an embodiment;
[0056] Figure 3 A schematic diagram of a process for determining a target slot and a data migration strategy in one embodiment;
[0057] Figure 4 A schematic diagram of a process for determining a target slot and a data migration strategy in another embodiment;
[0058] Figure 5 A schematic diagram of a process for determining migration benefit information in one embodiment;
[0059] Figure 6 A schematic diagram of a process for determining migration benefit information in another embodiment;
[0060] Figure 7 An architectural diagram of a Redis cluster in one embodiment;
[0061] Figure 8 is a flow chart of a data migration method in another embodiment;
[0062] Fig. 9 is a structural block diagram of a data migration device in one embodiment;
[0063] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0064] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0065] The data migration method provided in the embodiment of the present application can be applied in a database cluster, especially in the application environment of a Redis cluster. The data migration method provided in the embodiment of the present application can be executed by a computer device, which can be a server or a terminal with powerful computing capabilities.
[0066] In an exemplary embodiment, Figure 1 As shown, a data migration method is provided, which is described by taking the method applied to a server as an example, and specifically includes the following steps:
[0067] S101 , when a data migration instruction for a database cluster is received, a slot resource cost of each slot is determined according to slot usage information of each slot of a candidate database in the database cluster.
[0068] The database cluster refers to the concept of combining multiple database instances (nodes) to form an overall system; in the embodiment of the present application, the database cluster can be a Redis cluster, which is a low-latency, highly available NoSQL database. It is widely adopted by many enterprise developers and cloud vendors due to its simple use, high performance, and mature ecology; the data migration instruction is used to instruct the migration of data in the database cluster.
[0069] The slots in the database are used to store data; for example, the slots in the Redis cluster are used to store key-value data. The slot usage information represents the usage of the slot. In the embodiment of the present application, the slot usage information includes but is not limited to the central processing unit (CPU) usage time, CPU usage rate, number of successful calls, number of failed calls, total memory usage, memory usage rate, network inflow, network outflow and network usage rate. The slot resource cost of the slot represents the cost of the resources consumed by the slot to store data.
[0070] Optionally, the data migration instruction can be triggered actively or passively. For example, the database cluster monitoring system can periodically detect the usage and resource utilization of the database cluster, and actively trigger the data migration instruction when it is detected that the database cluster meets the data migration conditions; the data migration instruction can also be passively triggered by the user through the management side of the database cluster.
[0071] Furthermore, the monitoring system can regularly monitor the usage of the slots of each database in the database cluster and dynamically obtain the slot usage information of each slot. Therefore, the slot agent can obtain the slot usage information of each slot from the monitoring system.
[0072] Alternatively, for a database cluster that does not have a slot-level monitoring function, you can also modify the kernel of the database cluster to increase the collection of slot-level monitoring information.
[0073] S102: Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot.
[0074] Among them, the target slot is the slot for data migration; the data migration strategy is a strategy for instructing the database cluster to specifically execute data migration. In an embodiment of the present application, the data migration strategy includes the source database to which the target slot belongs and the destination database to which the data in the target slot is migrated.
[0075] Optionally, the database resource cost of each candidate database can be calculated based on the slot resource cost of each slot, and then based on the data migration rule, the benefit function in the data migration process is constructed according to the slot resource cost of each slot, and the benefit function is solved with the maximum benefit function as the goal. Finally, according to the solution results, the target slot, source database and destination database for migration are selected, and the data migration strategy corresponding to the target slot is formulated.
[0076] S103: Migrate the data stored in the target slot according to the data migration strategy.
[0077] In the above data migration method, when receiving a data migration instruction for a database cluster, the slot resource cost of each slot is determined according to the slot usage information of each slot of the candidate database in the database cluster, and the target slot for migration and the data migration strategy corresponding to the target slot are determined according to the slot resource cost of each slot; further, the data stored in the target slot is migrated according to the data migration strategy. The above scheme obtains slot-level information in the database cluster, that is, slot usage information, to obtain more detailed information in the database cluster, and according to the slot usage information, the accuracy of the slot resource cost of each slot is guaranteed; further, according to the slot resource cost of each slot, the specific usage of each candidate database in the database cluster can be analyzed more finely, thereby ensuring the accuracy of the determined target slot and the data migration strategy corresponding to the target slot; further, it can be ensured that after the data stored in the target slot is migrated according to the data migration strategy, the resource utilization of the database cluster can be improved, and the speed and efficiency of data migration can also be improved.
[0078] It should be noted that if the database cluster is a Redis cluster, in the prior art, the monitoring system of the Redis cluster can only monitor the operation status at the node level. Therefore, in an embodiment of the present application, the Redis kernel can be extended to increase the monitoring information of the acquisition slot level. Specifically, the data structure of slotToKeys is extended to increase the CPU usage time, number of successful calls, number of failed calls, total memory used, network inflow and network outflow at the slot level. The client data structure is extended to increase the slot_info field of the slotToKeys pointer type to represent the statistical information of the slot involved in the current command. Before each command is executed, the getNodeByQuery function is called to calculate the slot value of the key, and the corresponding slotToKeys structure is saved to the slot_info field in the client. In the call function, after the command is executed, if the slot_info pointer is legal, the CPU execution time of the corresponding slot and the cumulative size of the successful call, number of failed calls, and requested network message are updated.
[0079] Trigger the scenario of adding a new key, modify the slotToKeyAddEntry function, increase and record the memory usage of the corresponding slot; in the scenario of deleting the KEY, modify the slotToKeyDelEntry, reduce and record the memory usage of the corresponding slot; in the scenario of overwriting the key, modify the slotToKeyReplaceEntry function to update the change in the memory usage of the corresponding slot. When the data content of the collection type changes, update the memory usage of the corresponding slot according to the specific command. Extend the _addReplyToBufferOrList function, in the scenario of writing back the response message to the client, if the current client's slot_info pointer is legal, increase the cumulative size of the response message of the corresponding slot. Modify the clusterCommand function, add a subcommand slotinfo, which will read all the slotToKeys data structures owned by the current node and display the monitoring information of all the current Redis slots. Add a call to the Redis command cluster slotinfo, and add the corresponding indicator return.
[0080] Optionally, in one embodiment, the slot usage information of each slot includes the CPU usage rate, memory usage rate and network usage rate of the slot; in this case, Figure 2 As shown, a method for determining the slot resource cost of each slot is provided to refine S101, and specifically includes the following steps:
[0081] S201: For each slot, the square of the difference between the CPU usage of the slot and a preset constant is used as a first cost.
[0082] The first cost represents the cost of using the CPU. In the embodiment of the present application, the preset constant is 1.
[0083] Optionally, for each slot, the square of the difference between the CPU usage of the slot and a preset constant is used as the first cost, as represented by the following formula (1):
[0084] (1)
[0085] in, represents the first cost, Indicates CPU usage.
[0086] S202: The square of the difference between the memory usage rate of the slot and a preset constant is used as the second cost.
[0087] The second cost represents the cost of using the memory.
[0088] Optionally, for each slot, the square of the difference between the memory usage of the slot and a preset constant is used as the first cost, as represented by the following formula (2):
[0089] (2)
[0090] in, represents the second cost, Indicates memory usage.
[0091] S203: The square of the difference between the network usage rate of the slot and a preset constant is used as the third cost.
[0092] Among them, the third cost represents the cost of using the network.
[0093] Optionally, for each slot, the square of the difference between the network usage rate of the slot and a preset constant is used as the first cost, as shown in the following formula (3):
[0094] (3)
[0095] in, represents the third cost, Indicates network usage.
[0096] S204: Determine a slot resource cost of the slot according to the first cost, the second cost, and the third cost.
[0097] Optionally, the process of determining the slot resource cost of the slot according to the first cost, the second cost and the third cost can be expressed by the following formula (4):
[0098] (4)
[0099] in, is the resource cost of the slot.
[0100] In this embodiment, by introducing CPU utilization, memory utilization and network utilization, a method for calculating the slot resource cost of each slot is provided, thereby ensuring the accuracy of the determined slot resource cost and the convenience of the process of determining the slot resource cost.
[0101] Optionally, in one embodiment, Figure 3 As shown, a method for determining a target slot and a data migration strategy is provided to refine the above S102, and specifically includes the following steps:
[0102] S301, taking slots whose slot resource costs are greater than a preset slot threshold as candidate slots.
[0103] The candidate slot is a slot that meets the data migration conditions; the preset slot threshold is a preset slot resource cost threshold.
[0104] Optionally, the slot resource cost of each slot and a preset slot threshold may be compared, and slots whose slot resource cost is greater than the preset slot threshold are taken as candidate slots.
[0105] S302: Take the candidate database to which each candidate slot belongs as the target database.
[0106] Optionally, the candidate database to which each candidate slot belongs can be used as the target database.
[0107] S303: Determine the initial resource cost of the target database according to the slot resource cost of each slot in the target database.
[0108] The initial resource cost of the target database represents the cost consumed when all resources in the target database are used.
[0109] Optionally, the slot resource costs of the slots in the target database may be accumulated, and the accumulated sum may be used as the initial resource cost of the target database.
[0110] S304: Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the initial resource cost of the target database.
[0111] Optionally, since the initial resource cost of the target database to some extent represents the cost of resources consumed by the target database for storing data, the target database with the highest initial resource cost can be used as the source database in the data migration strategy, and the target database with the lowest initial resource cost can be used as the destination database; further, the candidate slot with the highest slot resource cost in the source database can be used as the target slot. Then, the target slot for migration and the data migration strategy corresponding to the target slot can be determined.
[0112] In this embodiment, the candidate slots are determined by introducing a preset slot threshold, thereby ensuring the accuracy of the determined candidate slots; further, by introducing the target database and the initial resource cost of the target database, the accuracy of the determined target slots and the data migration strategy corresponding to the target slots is ensured, thereby ensuring the resource utilization of the database cluster after data migration according to the data migration strategy.
[0113] Optionally, in one embodiment, Figure 4 As shown, a method for determining a target slot and a data migration strategy is provided to refine the above S304, and specifically includes the following steps:
[0114] S401 , for each candidate slot, determining migration benefit information of migrating data in the candidate slot from the target database to another database according to the initial resource cost of the target database to which the candidate slot belongs.
[0115] Among them, other databases are databases in the database cluster except the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes but is not limited to the migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database.
[0116] Optionally, for each candidate slot, a benefit prediction model can be introduced, and the initial resource cost of the target database to which the candidate slot belongs can be input into the benefit prediction model, so that the benefit prediction model analyzes and calculates the initial resource cost of the target database to which the candidate slot belongs based on the model parameters, so as to predict the migration benefit information of migrating the data in the candidate slot from the target database to other databases.
[0117] S402: Select a target slot for migration from each candidate slot according to the migration benefit information corresponding to each candidate slot, and determine a data migration strategy corresponding to the target slot.
[0118] Optionally, in order to ensure that data migration can improve resource utilization, the candidate slot corresponding to the maximum migration benefit value can be used as the target slot for migration; the target database to which the target slot belongs can be used as the source database; other databases corresponding to the maximum migration benefit value can be used as the destination database; and the data migration strategy corresponding to the target slot can be determined based on the target slot, the source database and the destination database.
[0119] It should be noted that, in order to ensure the accuracy of the determined target slot, a benefit threshold may be introduced to further verify the target slot. Specifically, the migration benefit value of the target slot may be compared with the benefit preset, and when the migration benefit value is greater than the benefit threshold, the data of the target slot is migrated.
[0120] In this embodiment, the migration benefit information of migrating the data in the candidate slot from the target database to other databases is determined based on the initial resource cost of the target database to which the candidate slot belongs. This is equivalent to predicting the benefits obtained by each candidate database in the database cluster after the data migration, thereby ensuring the accuracy of the determined target slot and data migration strategy.
[0121] Optionally, in one embodiment, Figure 5 As shown, a method for determining migration benefit information is provided to refine the above S401, which specifically includes the following steps:
[0122] S501 , for each database in other databases, determine the initial resource cost of the database according to the slot resource cost of each slot in the database.
[0123] The initial resource cost of the database represents the resource cost consumed by the database for storing data.
[0124] Optionally, for each database in other databases, the slot resource costs of all slots in the database may be accumulated, and the accumulated sum may be used as the initial resource cost of the database.
[0125] S502, determining a target resource cost of the database after migrating the data in the candidate slot to the database, and a target resource cost of the target database to which the candidate slot belongs.
[0126] The target resource cost of the database represents the resources consumed by the database for storing data after the data migration; the target resource cost of the target database represents the resources consumed by the target database for storing data after the data migration.
[0127] Optionally, it may be pre-assumed that the data in the candidate slot is migrated to the database, and the target resource cost of the database after the data migration and the target resource cost of the target database to which the candidate slot belongs are calculated.
[0128] S503, determining a migration benefit value of migrating data in the candidate slot from the target database to the database according to the initial resource cost and the target resource cost of the database and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs.
[0129] Optionally, based on a pre-built migration benefit calculation formula, the initial resource cost and target resource cost of the database, as well as the initial resource cost and target resource cost of the target database to which the candidate slot belongs can be substituted into the migration benefit calculation formula to obtain the migration benefit value of the data in the candidate slot from the target database to the database.
[0130] In this embodiment, by introducing the initial resource cost of the database, the target resource cost of the database, and the target resource cost of the target database to which the candidate slot belongs, a method is provided to quickly and accurately determine the migration benefit value of the data in the candidate slot from the target database to the database.
[0131] Optionally, in one embodiment, Figure 6 As shown, a method for determining migration benefit information is provided to refine the above S503, which specifically includes the following steps:
[0132] S601: The difference between the initial resource cost and the target resource cost of the database is taken as a first benefit value.
[0133] The first benefit value is a benefit value after data migration is performed on a database in other databases.
[0134] Optionally, a difference may be made between the initial resource cost and the target resource cost of the database, and the obtained difference may be used as the first benefit value.
[0135] S602: Taking the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs as the second benefit value.
[0136] The second benefit value is a benefit value after data migration of the target database to which the candidate slot belongs.
[0137] Optionally, a difference may be made between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs, and the obtained difference is used as the second benefit value.
[0138] S603: Taking the sum of the first benefit value and the second benefit value as the migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0139] Optionally, the sum of the first benefit value and the second benefit value may be used as a migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0140] In this embodiment, by introducing the first benefit value and the second benefit value, a method is provided to quickly and accurately calculate the migration benefit value of data in the candidate slot from the target database to the database.
[0141] Exemplarily, based on the above embodiment, this embodiment takes the database cluster as a Redis cluster as an example. Figure 7 As shown in the figure, the architecture diagram of building a Redis cluster. Among them, the Redis cluster contains multiple Redis, and each Redis cluster is deployed with a monitoring component Redis Exporter for monitoring Redis; the monitoring system Prometheus monitors the operation of Redis through the monitoring component Redis Exporter, and issues an alarm through the alarm system when any Redis is detected to be abnormal. Slot Agent is an agent component introduced to execute the data migration method provided in the embodiment of the present application; Zookeeper is a component that provides distributed application coordination services. In Figure 7 In the application environment shown in the figure, when the Redis kernel is extended to collect slot-level monitoring information, the data migration process can be implemented through the slot agent by following the steps below:
[0142] Step 1: Read and update the metadata configuration from Zookeeper according to the local configuration file, and select a group master node based on the election mechanism of Zookeeper.
[0143] Step 2: The master node of the slot agent automatically queries Prometheus for monitoring information of all slots during the configured operation and maintenance time, and uses metadata to obtain complete information of all nodes. The slot resource cost corresponding to each slot is calculated and sorted from high to low cost. According to the configuration, only n slots with the highest cost and greater than a specific configuration threshold are selected each time to calculate the migration plan. Furthermore, based on the slot resource cost corresponding to each slot, the initial resource cost of each Redis is calculated.
[0144] Step 3: Assume that a slot has been migrated to another Redis, and recalculate the target resource costs of the two Redis, and calculate the difference in the resource costs of Redis. Calculate all nodes in the Redis cluster and select the combination with the largest reduction in Redis resource costs. If it is greater than the preset resource reduction threshold, the Slot Agent will publish the slot migration task to Zookeeper, that is, create a task node on Zookeeper.
[0145] Step 4: The Slot Agent node monitors the migration task node of Zookeeper and tries to register a sequence temporary node on its child node. If the registered temporary node sequence value is the smallest, it means that the task has been preempted; otherwise, it fails, deletes the temporary node, and tries to preempt other tasks.
[0146] Step 5: After the slot agent grabs the migration task, it updates the Zookeeper node information of the migration task, changes the status of the migration task to "started", and then starts to execute the command on the target node: CLUSTER SETSLOT {slot}importing {source node name}, and executes the command on the source node: CLUSTER SETSLOT {slot} migrating {target node name}. After success, it updates the Zookeeper node information of the migration task, changes the status of the migration task to "migrating", and repeatedly executes the commands: CLUSTER GETKEYSINSLOT {slot} {pipeline} and MIGRATE{host} {port} 0 {timeout} REPLACE AUTH {password} KEYS key [key ...] on the source node to migrate. When all keys are migrated, it updates the Zookeeper node information of the migration task and changes the status of the migration task to "migration completed". Subsequently, it executes: CLUSTER SETSLOT {slot} node {target node name} on all nodes of the cluster. After success, the Zookeeper node of the migration task is deleted, and the migration task record is appended to another Zookeeper node.
[0147] On the management side, combined with slot monitoring information, add the slot migration function of the visual interface, and publish the migration task by adding the node of the migration task to Zookeeper.
[0148] Figure 8 FIG. 1 is a flow chart of a data migration method in another embodiment. Based on the above embodiment, this embodiment provides an optional example of a data migration method. Figure 8 The specific implementation process is as follows:
[0149] S801 : upon receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster.
[0150] The slot usage information of each slot includes the CPU usage rate, memory usage rate and network usage rate of the slot.
[0151] Optionally, for each slot, the square of the difference between the CPU usage of the slot and a preset constant is used as the first cost; the square of the difference between the memory usage of the slot and a preset constant is used as the second cost; the square of the difference between the network usage of the slot and the preset constant is used as the third cost; and the slot resource cost of the slot is determined based on the first cost, the second cost and the third cost.
[0152] S802: All slots whose slot resource costs are greater than a preset slot threshold are taken as candidate slots.
[0153] S803: Take the candidate database to which each candidate slot belongs as the target database.
[0154] S804: Determine the initial resource cost of the target database according to the slot resource cost of each slot in the target database.
[0155] S805 , determining migration benefit information of migrating the data in the candidate slot from the target database to another database according to the initial resource cost of the target database to which the candidate slot belongs.
[0156] Among them, other databases are databases in the database cluster except the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes the migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database.
[0157] Optionally, for each database in other databases, determine the initial resource cost of the database based on the slot resource cost of each slot in the database; determine the target resource cost of the database after migrating the data in the candidate slot to the database, and the target resource cost of the target database to which the candidate slot belongs; take the difference between the initial resource cost and the target resource cost of the database as the first benefit value; take the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs as the second benefit value; and take the sum of the first benefit value and the second benefit value as the migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0158] S806: According to the migration benefit information, the candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration.
[0159] S807: Use the target database to which the target slot belongs as the source database.
[0160] S808, taking other databases corresponding to the maximum migration benefit value as the destination database.
[0161] S809: Determine a data migration strategy corresponding to the target slot according to the target slot, the source database, and the destination database.
[0162] S810: Migrate data stored in the target slot according to the data migration strategy.
[0163] The specific process of the above S801-S810 can refer to the description of the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0164] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0165] Based on the same inventive concept, the embodiment of the present application also provides a data migration device for implementing the data migration method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more data migration device embodiments provided below can refer to the limitations on the data migration method above, and will not be repeated here.
[0166] In an exemplary embodiment, Fig. 9 As shown, a data migration device 900 is provided, including: an information determination module 910, a strategy determination module 920 and a data migration module 930, wherein:
[0167] The information determination module 910 is used to determine the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster when receiving the data migration instruction for the database cluster.
[0168] The strategy determination module 920 is used to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the slot resource cost of each slot.
[0169] The data migration module 930 is used to migrate the data stored in the target slot according to the data migration strategy.
[0170] The above data migration device, when receiving a data migration instruction for a database cluster, determines the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster, and determines the target slot for migration and the data migration strategy corresponding to the target slot according to the slot resource cost of each slot; further, according to the data migration strategy, migrates the data stored in the target slot. The above scheme obtains slot-level information in the database cluster, that is, slot usage information, to obtain more detailed information in the database cluster, and ensures the accuracy of the slot resource cost of each slot determined according to the slot usage information; further, according to the slot resource cost of each slot, the specific usage of each candidate database in the database cluster can be analyzed more finely, thereby ensuring the accuracy of the determined target slot and the data migration strategy corresponding to the target slot; further, it can be ensured that after the data stored in the target slot is migrated according to the data migration strategy, the resource utilization of the database cluster can be improved, and the speed and efficiency of data migration can also be improved.
[0171] In one embodiment, the slot usage information of each slot includes the CPU usage rate, memory usage rate and network usage rate of the slot; the information determination module 910 is specifically used to:
[0172] For each slot, the square of the difference between the CPU usage of the slot and the preset constant is used as the first cost; the square of the difference between the memory usage of the slot and the preset constant is used as the second cost; the square of the difference between the network usage of the slot and the preset constant is used as the third cost; the slot resource cost of the slot is determined based on the first cost, the second cost and the third cost.
[0173] In one embodiment, the policy determination module 920 includes:
[0174] The slot determination unit is used to take the slots whose slot resource costs are greater than a preset slot threshold as candidate slots.
[0175] The database determination unit is used to take the candidate database to which each candidate slot belongs as the target database.
[0176] The cost determination unit is used to determine the initial resource cost of the target database according to the slot resource cost of each slot in the target database.
[0177] The strategy determination unit is used to determine a target slot for migration and a data migration strategy corresponding to the target slot according to an initial resource cost of a target database.
[0178] In one embodiment, the policy determination unit includes:
[0179] The information acquisition subunit is used to determine, for each candidate slot, the migration benefit information of migrating the data in the candidate slot from the target database to other databases based on the initial resource cost of the target database to which the candidate slot belongs; wherein the other databases are databases in the database cluster other than the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes the migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database.
[0180] The strategy determination subunit is used to select a target slot for migration from each candidate slot according to the migration benefit information corresponding to each candidate slot, and determine the data migration strategy corresponding to the target slot.
[0181] In one embodiment, the information acquisition subunit includes:
[0182] The first determining slave unit is used to determine, for each database of other databases, an initial resource cost of the database according to the slot resource cost of each slot in the database.
[0183] The second determining slave unit is used to determine the target resource cost of the database after the data in the candidate slot is migrated to the database, and the target resource cost of the target database to which the candidate slot belongs.
[0184] The information acquisition slave unit is used to determine the migration benefit value of migrating data in the candidate slot from the target database to the database based on the initial resource cost and target resource cost of the database and the initial resource cost and target resource cost of the target database to which the candidate slot belongs.
[0185] In one embodiment, the information acquisition slave unit is specifically used for:
[0186] The difference between the initial resource cost and the target resource cost of the database is taken as the first benefit value; the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs is taken as the second benefit value; the sum of the first benefit value and the second benefit value is taken as the migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0187] In one embodiment, the policy determination subunit is specifically configured to:
[0188] The candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration; the target database to which the target slot belongs is used as the source database; other databases corresponding to the maximum migration benefit value are used as destination databases; and the data migration strategy corresponding to the target slot is determined based on the target slot, the source database and the destination database.
[0189] Each module in the above data migration device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0190] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data migration method is implemented.
[0191] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0192] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0193] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0194] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0195] Migrate the data stored in the target slot according to the data migration strategy.
[0196] In one embodiment, the slot usage information of each slot includes the CPU usage rate, memory usage rate and network usage rate of the slot; when the processor executes the computer program to determine the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster, the following steps are also implemented:
[0197] For each slot, the square of the difference between the CPU usage of the slot and the preset constant is used as the first cost; the square of the difference between the memory usage of the slot and the preset constant is used as the second cost; the square of the difference between the network usage of the slot and the preset constant is used as the third cost; the slot resource cost of the slot is determined based on the first cost, the second cost and the third cost.
[0198] In one embodiment, when the processor executes the computer program to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the slot resource cost of each slot, the processor further implements the following steps:
[0199] All slots whose slot resource costs are greater than a preset slot threshold are taken as candidate slots; the candidate databases belonging to each candidate slot are taken as target databases; the initial resource cost of the target database is determined based on the slot resource costs of each slot in the target database; the target slot for migration and the data migration strategy corresponding to the target slot are determined based on the initial resource cost of the target database.
[0200] In one embodiment, when the processor executes the computer program to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the initial resource cost of the target database, the following steps are further implemented:
[0201] For each candidate slot, the migration benefit information of migrating the data in the candidate slot from the target database to other databases is determined based on the initial resource cost of the target database to which the candidate slot belongs; wherein the other databases are databases in the database cluster other than the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes a migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database; based on the migration benefit information corresponding to each candidate slot, a target slot for migration is selected from each candidate slot, and a data migration strategy corresponding to the target slot is determined.
[0202] In one embodiment, when the processor executes the computer program to determine the migration benefit information of migrating the data in the candidate slot from the target database to another database according to the initial resource cost of the target database to which the candidate slot belongs, the processor further implements the following steps:
[0203] For each database in other databases, determine the initial resource cost of the database according to the slot resource cost of each slot in the database; determine the target resource cost of the database after migrating the data in the candidate slot to the database, and the target resource cost of the target database to which the candidate slot belongs; determine the migration benefit value of migrating the data in the candidate slot from the target database to the database according to the initial resource cost and target resource cost of the database, and the initial resource cost and target resource cost of the target database to which the candidate slot belongs.
[0204] In one embodiment, when the processor executes the computer program to determine the migration benefit value of migrating the data in the candidate slot from the target database to the database based on the initial resource cost and the target resource cost of the database, and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs, the following steps are further implemented:
[0205] The difference between the initial resource cost and the target resource cost of the database is taken as the first benefit value; the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs is taken as the second benefit value; the sum of the first benefit value and the second benefit value is taken as the migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0206] In one embodiment, when the processor executes the computer program to select a target slot for migration and a data migration strategy corresponding to the target slot from each candidate slot according to the migration benefit information corresponding to each candidate slot, the processor further implements the following steps:
[0207] The candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration; the target database to which the target slot belongs is used as the source database; other databases corresponding to the maximum migration benefit value are used as destination databases; and the data migration strategy corresponding to the target slot is determined based on the target slot, the source database and the destination database.
[0208] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0209] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0210] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0211] Migrate the data stored in the target slot according to the data migration strategy.
[0212] In one embodiment, the slot usage information of each slot includes the CPU usage rate, memory usage rate and network usage rate of the slot; when the processor executes the computer program to determine the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster, the following steps are also implemented:
[0213] For each slot, the square of the difference between the CPU usage of the slot and the preset constant is used as the first cost; the square of the difference between the memory usage of the slot and the preset constant is used as the second cost; the square of the difference between the network usage of the slot and the preset constant is used as the third cost; the slot resource cost of the slot is determined based on the first cost, the second cost and the third cost.
[0214] In one embodiment, when the processor executes the computer program to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the slot resource cost of each slot, the processor further implements the following steps:
[0215] All slots whose slot resource costs are greater than a preset slot threshold are taken as candidate slots; the candidate databases belonging to each candidate slot are taken as target databases; the initial resource cost of the target database is determined based on the slot resource costs of each slot in the target database; the target slot for migration and the data migration strategy corresponding to the target slot are determined based on the initial resource cost of the target database.
[0216] In one embodiment, when the processor executes the computer program to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the initial resource cost of the target database, the following steps are further implemented:
[0217] For each candidate slot, the migration benefit information of migrating the data in the candidate slot from the target database to other databases is determined based on the initial resource cost of the target database to which the candidate slot belongs; wherein the other databases are databases in the database cluster other than the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes a migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database; based on the migration benefit information corresponding to each candidate slot, a target slot for migration is selected from each candidate slot, and a data migration strategy corresponding to the target slot is determined.
[0218] In one embodiment, when the processor executes the computer program to determine the migration benefit information of migrating the data in the candidate slot from the target database to another database according to the initial resource cost of the target database to which the candidate slot belongs, the processor further implements the following steps:
[0219] For each database in other databases, determine the initial resource cost of the database according to the slot resource cost of each slot in the database; determine the target resource cost of the database after migrating the data in the candidate slot to the database, and the target resource cost of the target database to which the candidate slot belongs; determine the migration benefit value of migrating the data in the candidate slot from the target database to the database according to the initial resource cost and target resource cost of the database, and the initial resource cost and target resource cost of the target database to which the candidate slot belongs.
[0220] In one embodiment, when the processor executes the computer program to determine the migration benefit value of migrating the data in the candidate slot from the target database to the database based on the initial resource cost and the target resource cost of the database, and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs, the following steps are further implemented:
[0221] The difference between the initial resource cost and the target resource cost of the database is taken as the first benefit value; the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs is taken as the second benefit value; the sum of the first benefit value and the second benefit value is taken as the migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0222] In one embodiment, when the processor executes the computer program to select a target slot for migration and a data migration strategy corresponding to the target slot from each candidate slot according to the migration benefit information corresponding to each candidate slot, the processor further implements the following steps:
[0223] The candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration; the target database to which the target slot belongs is used as the source database; other databases corresponding to the maximum migration benefit value are used as destination databases; and the data migration strategy corresponding to the target slot is determined based on the target slot, the source database and the destination database.
[0224] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0225] When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster;
[0226] Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot;
[0227] Migrate the data stored in the target slot according to the data migration strategy.
[0228] In one embodiment, the slot usage information of each slot includes the CPU usage rate, memory usage rate and network usage rate of the slot; when the processor executes the computer program to determine the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster, the following steps are also implemented:
[0229] For each slot, the square of the difference between the CPU usage of the slot and the preset constant is used as the first cost; the square of the difference between the memory usage of the slot and the preset constant is used as the second cost; the square of the difference between the network usage of the slot and the preset constant is used as the third cost; the slot resource cost of the slot is determined based on the first cost, the second cost and the third cost.
[0230] In one embodiment, when the processor executes the computer program to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the slot resource cost of each slot, the processor further implements the following steps:
[0231] All slots whose slot resource costs are greater than a preset slot threshold are taken as candidate slots; the candidate databases belonging to each candidate slot are taken as target databases; the initial resource cost of the target database is determined based on the slot resource costs of each slot in the target database; the target slot for migration and the data migration strategy corresponding to the target slot are determined based on the initial resource cost of the target database.
[0232] In one embodiment, when the processor executes the computer program to determine the target slot for migration and the data migration strategy corresponding to the target slot according to the initial resource cost of the target database, the following steps are further implemented:
[0233] For each candidate slot, the migration benefit information of migrating the data in the candidate slot from the target database to other databases is determined based on the initial resource cost of the target database to which the candidate slot belongs; wherein the other databases are databases in the database cluster other than the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes a migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database; based on the migration benefit information corresponding to each candidate slot, a target slot for migration is selected from each candidate slot, and a data migration strategy corresponding to the target slot is determined.
[0234] In one embodiment, when the processor executes the computer program to determine the migration benefit information of migrating the data in the candidate slot from the target database to another database according to the initial resource cost of the target database to which the candidate slot belongs, the processor further implements the following steps:
[0235] For each database in other databases, determine the initial resource cost of the database according to the slot resource cost of each slot in the database; determine the target resource cost of the database after migrating the data in the candidate slot to the database, and the target resource cost of the target database to which the candidate slot belongs; determine the migration benefit value of migrating the data in the candidate slot from the target database to the database according to the initial resource cost and target resource cost of the database, and the initial resource cost and target resource cost of the target database to which the candidate slot belongs.
[0236] In one embodiment, when the processor executes the computer program to determine the migration benefit value of migrating the data in the candidate slot from the target database to the database based on the initial resource cost and the target resource cost of the database, and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs, the following steps are further implemented:
[0237] The difference between the initial resource cost and the target resource cost of the database is taken as the first benefit value; the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs is taken as the second benefit value; the sum of the first benefit value and the second benefit value is taken as the migration benefit value of migrating the data in the candidate slot from the target database to the database.
[0238] In one embodiment, when the processor executes the computer program to select a target slot for migration and a data migration strategy corresponding to the target slot from each candidate slot according to the migration benefit information corresponding to each candidate slot, the processor further implements the following steps:
[0239] The candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration; the target database to which the target slot belongs is used as the source database; other databases corresponding to the maximum migration benefit value are used as destination databases; and the data migration strategy corresponding to the target slot is determined based on the target slot, the source database and the destination database.
[0240] It should be noted that the data involved in this application (including but not limited to data used for analysis, storage, display, etc.) are all information and data fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0241] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0242] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0243] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A data migration method, characterized in that: The method comprises: When receiving a data migration instruction for a database cluster, determining a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster; Determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot; According to the data migration strategy, the data stored in the target slot is migrated.
2. The method according to claim 1, characterized in that The slot usage information of each slot includes the CPU usage, memory usage and network usage of the slot; The determining the slot resource cost of each slot according to the slot usage information of each slot of the candidate database in the database cluster includes: For each slot, the square of the difference between the CPU usage of the slot and a preset constant is used as the first cost; The square of the difference between the memory usage rate of the slot and the preset constant is used as the second cost; The square of the difference between the network usage rate of the slot and the preset constant is used as the third cost; A slot resource cost of the slot is determined according to the first cost, the second cost, and the third cost.
3. The method according to claim 1, characterized in that Determining a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot includes: The slots whose slot resource cost is greater than the preset slot threshold are all regarded as candidate slots; The candidate database to which each candidate slot belongs is used as the target database; Determining the initial resource cost of the target database according to the slot resource cost of each slot in the target database; A target slot for migration and a data migration strategy corresponding to the target slot are determined according to the initial resource cost of the target database.
4. The method according to claim 3, characterized in that The determining, according to the initial resource cost of the target database, a target slot for migration and a data migration strategy corresponding to the target slot includes: For each candidate slot, according to the initial resource cost of the target database to which the candidate slot belongs, determine the migration benefit information of migrating the data in the candidate slot from the target database to other databases; wherein the other databases are databases in the database cluster other than the target database to which the candidate slot belongs; the migration benefit information corresponding to each candidate slot includes a migration benefit value corresponding to each database in the other databases, and the benefit value corresponding to each database represents the benefit obtained after the data in the candidate slot is migrated from the target database to the database; According to the migration benefit information corresponding to each candidate slot, a target slot for migration is selected from each candidate slot, and a data migration strategy corresponding to the target slot is determined.
5. The method according to claim 4, characterized in that The determining, according to the initial resource cost of the target database to which the candidate slot belongs, migration benefit information of migrating the data in the candidate slot from the target database to another database includes: For each database in the other databases, determining an initial resource cost of the database according to a slot resource cost of each slot in the database; Determine a target resource cost of the database after migrating the data in the candidate slot to the database, and a target resource cost of the target database to which the candidate slot belongs; The migration benefit value of the data in the candidate slot from the target database to the database is determined according to the initial resource cost and the target resource cost of the database and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs.
6. The method according to claim 5, characterized in that Determining the migration benefit value of migrating the data in the candidate slot from the target database to the database according to the initial resource cost and the target resource cost of the database, and the initial resource cost and the target resource cost of the target database to which the candidate slot belongs, includes: Taking the difference between the initial resource cost and the target resource cost of the database as the first benefit value; taking the difference between the initial resource cost and the target resource cost of the target database to which the candidate slot belongs as the second benefit value; The sum of the first benefit value and the second benefit value is used as a migration benefit value of migrating the data in the candidate slot from the target database to the database.
7. The method according to claim 4, characterized in that The step of selecting a target slot for migration and a data migration strategy corresponding to the target slot from the candidate slots according to the migration benefit information corresponding to the candidate slots includes: The candidate slot corresponding to the maximum migration benefit value is used as the target slot for migration; Taking the target database to which the target slot belongs as the source database; The other database corresponding to the maximum migration benefit value is used as the destination database; A data migration strategy corresponding to the target slot is determined according to the target slot, the source database, and the destination database.
8. A data migration device, characterized in that: The device comprises: an information determination module, configured to determine a slot resource cost of each slot according to slot usage information of each slot of a candidate database in the database cluster when receiving a data migration instruction for the database cluster; A strategy determination module, used to determine a target slot for migration and a data migration strategy corresponding to the target slot according to the slot resource cost of each slot; The data migration module is used to migrate the data stored in the target slot according to the data migration strategy.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: 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.