Movatterモバイル変換


[0]ホーム

URL:


CN114598711B - Data migration method, device, equipment and medium - Google Patents

Data migration method, device, equipment and medium
Download PDF

Info

Publication number
CN114598711B
CN114598711BCN202210324045.9ACN202210324045ACN114598711BCN 114598711 BCN114598711 BCN 114598711BCN 202210324045 ACN202210324045 ACN 202210324045ACN 114598711 BCN114598711 BCN 114598711B
Authority
CN
China
Prior art keywords
database service
node
slave node
server
slave
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210324045.9A
Other languages
Chinese (zh)
Other versions
CN114598711A (en
Inventor
郭添伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bigo Technology Pte Ltd
Original Assignee
Bigo Technology Pte Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bigo Technology Pte LtdfiledCriticalBigo Technology Pte Ltd
Priority to CN202210324045.9ApriorityCriticalpatent/CN114598711B/en
Publication of CN114598711ApublicationCriticalpatent/CN114598711A/en
Application grantedgrantedCritical
Publication of CN114598711BpublicationCriticalpatent/CN114598711B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

Abstract

The application discloses a data migration method, a device, equipment and a medium. After the migration instruction of the database service is acquired, a first slave node is newly built for the database service in the second server, and the data stored in the master node corresponding to the database service is synchronized to the first slave node. If the target node is determined to be the master node corresponding to the database service, when the first slave node is determined to complete data synchronization, updating the state of the first slave node to a writable state, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node, so that the client can write data in the first slave node through the address information of the master node recorded in the name service. And closing the target node and determining that the first slave node continuously works as the master node corresponding to the database service, thereby ensuring the stability and the availability of the database service and reducing the time for causing the database service abnormality due to data migration.

Description

Data migration method, device, equipment and medium
Technical Field
The present disclosure relates to the field of data migration technologies, and in particular, to a data migration method, device, apparatus, and medium.
Background
Redis is an open source, support network, memory-based, distributed, optionally persistent, key-value pair storage database written using ANSI C. Based on advantages of Redis, such as simplicity, high performance, stability, and the like, some systems can select Redis as a database of services.
In the architecture of micro services, a system may consist of hundreds or thousands of micro services, each with its own independent database, and therefore use Redis instances of the same order of magnitude. Wherein, the Redis instance refers to a process started by the Redis on the server. In order to ensure high availability of micro services and avoid deploying too many Redis instances associated with the micro services, one micro service is generally adopted to associate two Redis instances, one is used as a Redis Master node (Master), and the other is used as a disaster recovery scheme of a Redis slave node (Replica). Meanwhile, in order to ensure resource balance, a resource manager can frequently control the Redis instances associated with the micro-services to migrate among different servers at random. In the process of migrating a Redis instance associated with a certain micro service under the disaster recovery scheme, if a Redis main node associated with the micro service fails or a server where the Redis main node is located is abnormal, the associated Redis main node cannot be automatically determined again for the micro service, and the micro service needs to be manually switched. In the time period before the manual switching is completed, the micro service can not normally provide service to the outside, and the availability of the micro service is affected. Therefore, how to improve the availability of database services becomes a key to improving the quality of micro services.
Disclosure of Invention
The embodiment of the application provides a data migration method, device, equipment and medium, which are used for solving the problem of low availability of the existing database service.
The embodiment of the application provides a data migration method, which comprises the following steps:
obtaining a migration instruction of a database service; the migration instruction is used for migrating the target node of the database service from a first server to a second server;
creating a first slave node for the database service in the second server, and synchronizing data stored in a master node corresponding to the database service to the first slave node;
if the target node is the master node corresponding to the database service, updating the state of the first slave node into a writable state when the first slave node is determined to complete data synchronization, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node;
and closing the target node, and determining the first slave node to continue working as the master node corresponding to the database service.
The embodiment of the application provides a data migration device, which comprises:
The acquisition unit is used for acquiring a migration instruction of the database service; the migration instruction is used for migrating the target node of the database service from a first server to a second server;
the first processing unit is used for creating a first slave node for the database service in the second server and synchronizing data stored in a master node corresponding to the database service into the first slave node;
the updating unit is used for updating the state of the first slave node into a writable state when the first slave node is determined to finish data synchronization if the target node is the master node corresponding to the database service, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node;
and the second processing unit is used for closing the target node and determining that the first slave node continuously works as the master node corresponding to the database service.
The application provides a data migration device, which at least comprises a processor and a memory, wherein the processor is used for implementing the steps of the data migration method when executing a computer program stored in the memory.
The present application provides a computer readable storage medium storing a computer program which when executed by a processor implements the steps of a data migration method as described above.
The present application provides a computer program product comprising: computer program code for causing a computer to carry out the steps of the data migration method as described above when said computer program code is run on a computer.
In the data migration process, after the migration instruction of the database service is acquired, a first slave node can be newly built for the database service in the second server, and the data stored in the master node corresponding to the database service is synchronized into the first slave node, so that manual intervention is not needed, and the data migration efficiency is improved. If the target node is determined to be the master node corresponding to the database service, when the first slave node is determined to complete data synchronization, the state of the first slave node can be updated to be a writable state, and the address information of the master node corresponding to the database service in the name service is updated according to the address information of the first slave node, so that the client can write data in the first slave node through the address information of the master node recorded in the name service. And then closing the target node and determining that the first slave node works as the master node corresponding to the database service, thereby ensuring that the database service always corresponds to the master node, ensuring the stability and the availability of the database service, and reducing the time for abnormal database service caused by data migration.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic diagram of a data migration process according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a specific data migration flow provided in the present application;
fig. 3 is a schematic node switching diagram corresponding to a specific target node provided in an embodiment of the present application;
fig. 4 is a schematic node switching diagram corresponding to a specific target node provided in an embodiment of the present application;
fig. 5 is a schematic flow chart of a primary node failover provided in an embodiment of the present application;
fig. 6 is a schematic structural diagram of a data migration device according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a data migration device according to an embodiment of the present application.
Detailed Description
The present application will be described in further detail below with reference to the attached drawings, wherein it is apparent that the described embodiments are only some, but not all embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
Those skilled in the art will appreciate that embodiments of the present application may be implemented as a system, apparatus, device, method, or computer program product. Thus, the present application may be embodied in the form of: complete hardware, complete software (including firmware, resident software, micro-code, etc.), or a combination of hardware and software.
In this document, it should be understood that any number of elements in the drawings is for illustration and not limitation, and that any naming is used only for distinction and not for any limitation.
For ease of understanding, some of the concepts involved in the embodiments of this application are explained below:
redis (Remote Dictionary Server ): an open source, support network, memory-based, distributed, optionally persistent key-value pair storage database written using ANSI C.
Sentinel (Sentinel): a special dis provides high availability capability for dis.
Master node (Master): the master node of the Redis instance may provide read and write operations.
Slave node (Replica): the slave node of the Redis instance can be understood as a copy of the Master, typically providing only read operations.
Name service: the name service stores basic information of the service, and the service can acquire information of the other side service by inquiring the name service.
In a conventional architecture, redis instances are generally divided according to service dimensions, and all services related to the same service use the same Redis instance, and a system including multiple services generally only uses dozens of Redis instances. These Redis instances are typically deployed in specific servers and do not migrate frequently between servers. By combining a Redis one-master-multi-slave deployment mode with a Sentinel technology, high availability of database services can be ensured. When data in the Redis instance needs to be migrated, maintenance personnel can migrate through manual operation or script operation in the planned time. In the data migration process, any Replica can be used as a new Master, so that the migration step can be completed by switching and updating the routing information through a Sentinel command.
As system architectures evolve, systems employing micro-services architecture emerge. In the architecture of micro services, a system may consist of hundreds or thousands of micro services, each with its own independent database, and therefore use Redis instances of the same order of magnitude. Wherein, the Redis instance refers to a process started by the Redis on the server. In order to ensure high availability of micro services and avoid deploying too many Redis instances associated with the micro services, one micro service is generally adopted to associate two Redis instances, one is used as a Redis Master node (Master), and the other is used as a disaster recovery scheme of a Redis slave node (Replica). Meanwhile, in order to ensure resource balance, a resource manager can frequently control the Redis instances associated with the micro-services to migrate among different servers at random. For example, to reduce the time required for a service to invoke data in a Redis instance, the Redis instance may be deployed in the same server as the service; or, in order to ensure the load balance of each server, migrating the data stored in the Redis instance on one server with higher load to another server with lower load. In the process of migrating a certain micro-service associated Redis instance under the disaster recovery scheme, if a micro-service associated Redis master node fails or a server where the Redis master node is located is abnormal, the associated Redis master node cannot be automatically determined again for the micro-service, and the micro-service is required to be manually switched, so that a great deal of manpower is required in the data migration process, and the data migration quality and efficiency cannot be ensured. And in the time period before the manual switching is completed, the micro service can not normally provide service to the outside, and the usability of the micro service is affected.
In order to solve the above problems, the present application provides a data migration method, apparatus, device, and medium. In the data migration process, after the migration instruction of the database service is acquired, a first slave node can be newly built for the database service in the second server, and the data stored in the master node corresponding to the database service is synchronized into the first slave node, so that manual intervention is not needed, and the data migration efficiency is improved. If the target node is determined to be the master node corresponding to the database service, when the first slave node is determined to complete data synchronization, the state of the first slave node can be updated to be a writable state, and the address information of the master node corresponding to the database service in the name service is updated according to the address information of the first slave node, so that the client can write data in the first slave node through the address information of the master node recorded in the name service. And then closing the target node and determining that the first slave node works as the master node corresponding to the database service, thereby ensuring that the database service always corresponds to the master node, ensuring the stability and the availability of the database service, and reducing the time for abnormal database service caused by data migration.
It should be noted that, the application scenario set forth in the foregoing embodiments is merely for convenience of describing the exemplary scenario set forth, and is not a limitation of the application scenario of a data migration method, apparatus, device and medium provided in the embodiments of the present application. One skilled in the art should appreciate that the data migration method, apparatus, device and medium provided in the embodiments of the present application may be applied to all application scenarios where data migration is required, for example, product online.
Example 1:
fig. 1 is a schematic diagram of a data migration process according to an embodiment of the present application, where the process includes:
s101: obtaining a migration instruction of a database service; the migration instruction is used for migrating the target node of the database service from a first server to a second server.
The data migration method provided by the embodiment of the application is applied to electronic equipment (for convenience of description, recorded as data migration equipment), and the data migration equipment can be intelligent equipment such as a mobile terminal, a computer and the like, and can also be a server, such as an application server, a resource scheduler and the like.
In the embodiment of the present application, when a certain node of a database service needs to be migrated, for example, a certain Redis instance of the Redis service may determine the node as a target node, and determine a server (denoted as a second server) to which the target node is to be migrated from other servers except a server (denoted as a first server) where the node is currently located. And then generating a migration instruction of the database service according to the address information of the target node, the address information of the first server and the address information of the second server. The target node may be a master node corresponding to the database service, or may be a slave node corresponding to the database service. The data migration equipment can migrate the target node of the database service from the first server to the second server by adopting the data migration method provided by the application based on the migration instruction.
The second server may be determined from the other servers according to the loads respectively corresponding to the other servers, for example, the other server with the smallest load may be determined as the second server according to the loads respectively corresponding to the other servers. The second server may be determined from the other servers according to the remaining storage spaces corresponding to the other servers, respectively. Of course, it may also be configured by a worker.
It should be noted that, the method for specifically determining the loads corresponding to the other servers respectively belongs to the prior art, for example, determining according to the resource utilization rate of the other servers, and the like, in the specific implementation process, the method can be flexibly set according to the actual requirements, which is not limited in detail herein.
In one example, the need for data migration may be determined by at least one of:
in the first mode, when the master node corresponding to the database service works normally, abnormal alarm information of the first server is received.
In the actual application process, the conditions of hardware abnormality, maintenance and the like of the first server may exist, so that the target node has the risk of being unable to normally provide services. Therefore, in the application, when the first server is abnormal, the server for monitoring the health state of the first server can monitor that the first server is abnormal and generate alarm information of the abnormality of the first server. When the main node corresponding to the database service works normally, the data migration equipment receives the alarm information, and determines that the database service provided on the first server needs to perform data migration when the node on the first server is at risk of being unable to provide the service normally.
And secondly, determining that the load of the first server reaches a preset load threshold.
In order to ensure load balancing among the servers, in the application, when the data migration device monitors that the load of a certain server is too high, data migration can be performed on data stored by the server, and migration instructions of database services can be obtained. The load threshold is preset, and the data migration device acquires the load of each server in real time, and determines, for each server, whether the load of the server reaches the preset load threshold. When the load of the server reaches the preset load threshold, the server is determined to have too high load, and the database service provided on the server is determined to need data migration. When the load of the server is determined not to reach the preset load threshold, the load of the server is not high, data migration is not needed to be carried out on the data stored by the server, and the next server is acquired.
For example, after the data migration device obtains the load of the first server, it is determined that the load of the first server reaches a preset load threshold, and it is determined that the database service provided on the first server needs to perform data migration.
It should be noted that, in the actual use process, the two modes may be combined, that is, when the master node corresponding to the database service works normally, the alarm information of the abnormality of the first server where the target node corresponding to the database service is located is received, and it is determined that the load of the first server reaches the preset load threshold, and then it is determined that the target node needs to perform data migration.
S102: and creating a first slave node for the database service in the second server, and synchronizing data stored in a master node corresponding to the database service into the first slave node.
In the application, after the data migration device receives the migration instruction of the database service and determines the second server, a slave node (denoted as a first slave node) can be newly built for the database service in the second server. The data migration device may send a control instruction for creating the first slave node to the second server, so that the second server creates the first slave node for the database service after receiving the control instruction, and returns address information of the first slave node to the data migration device.
In one example, in the data migration process, if the data migration is needed by the master node, the data stored by the master node can be directly and synchronously stored in the newly-built node; if the data migration is needed by the slave node, the master node corresponding to the database service can be determined, and the data stored in the master node are synchronously stored in the new node. Therefore, in the application, after receiving a migration instruction of a certain database service, the data migration device may determine a master node corresponding to the database service, determine that a second server newly establishes a first slave node for the database service, and then synchronously store data stored in the master node corresponding to the database service into the first slave node.
For example, if the type of the target node is a master node, that is, the target node is a master node corresponding to the database service, and the data migration device determines that the data to be synchronously stored originates from the server where the target node is located, after the data migration device creates a first slave node for the database service on the second server, the data migration device sends address information of the first slave node and address information of the second server to the target node of the database service in the first server, so as to inform the database service of the first server to synchronously store the data stored in the target node into the first slave node; the database service in the subsequent first server synchronously stores the data stored in the target node into the first slave node according to the received address information of the first slave node and the address information of the second server.
For another example, if the type of the target node is a slave node, the data migration device determines that the data to be synchronously stored originates from a server (denoted as a third server) where the master node corresponding to the target node is located, after the data migration device establishes a first slave node for the database service on the second server, the data migration device sends address information of the first slave node and address information of the second server to the target node of the database service in the third server, so as to inform the database service in the third server to synchronously store the data stored in the target node into the first slave node; and the database service in the subsequent third server synchronously stores the data stored in the master node corresponding to the database service into the first slave node according to the received address information of the first slave node and the address information of the second server, so that the data stored in the target node is synchronously stored into the first slave node.
In the application, a fault-tolerant mechanism is preconfigured to ensure the availability of the database service in the process of data migration through the fault-tolerant mechanism. For example, after the migration instruction of the database service is obtained, it may be determined whether the node corresponding to the current database service meets a preset fault tolerance mechanism. If the node corresponding to the current database service is determined to meet the preset fault tolerance mechanism, the data stored in the master node corresponding to the database service can be synchronized to the first slave node; if the node corresponding to the current database service does not meet the preset fault tolerance mechanism, the step of synchronizing the data stored in the master node corresponding to the database service to the first slave node is not executed, so that the availability and stability of the database service are ensured.
The nodes corresponding to the database service comprise a master node corresponding to the database service and a slave node corresponding to the database service.
In one example, it may be determined that the node corresponding to the database service satisfies a preset fault tolerance mechanism by at least one of:
mode 1, determining that a master node corresponding to the database service and at least one slave node corresponding to the database service work normally.
In order to ensure that the slave nodes disaster recovery at the moment in the data migration process or avoid the data loss of the database service caused by the failure of the target node in the data migration process, in the application, if the data migration is to be performed, the normal work of the master node corresponding to the database service and at least one slave node corresponding to the database service is required to be ensured, so that the data stored in the target node can be ensured to be restored through other nodes except the target node corresponding to the database service in the process of migrating the data stored in the subsequent target node even if the target node fails, and the data stored in the target node is prevented from being lost. Therefore, whether the node corresponding to the database service meets a preset fault tolerance mechanism can be determined by judging whether the master node corresponding to the database service and at least one slave node corresponding to the database service work normally. If the master node corresponding to the database service and at least one slave node corresponding to the database service both work normally, and it is determined that the node corresponding to the database service meets a preset fault tolerance mechanism, a step of synchronizing data stored in the master node corresponding to the database service to the first slave node may be performed. If the master node corresponding to the database service or all the slave nodes corresponding to the database service do not work normally, determining that the node corresponding to the database service does not meet a preset fault tolerance mechanism, and not performing the subsequent step of synchronizing the data stored in the master node corresponding to the database service to the first slave node.
And 2, determining that the target node is a master node corresponding to the database service, wherein the second server is different from the server where at least one slave node corresponding to the database service is located.
In order to avoid single point problems, the stability of the database service is affected, and the master node of the database service cannot be migrated to the server where any slave node corresponding to the database service is located. Therefore, whether the node corresponding to the database service meets a preset fault-tolerant mechanism can be determined by judging whether the type of the target node is a master node and whether the second server is different from the server corresponding to the database service in which at least one slave node is located. If the type of the target node is determined to be the master node, that is, the target node is the master node corresponding to the database service, and the second server is different from the server where at least one slave node corresponding to the database service is located, and it is determined that the node corresponding to the database service meets the preset fault-tolerant mechanism, a step of synchronizing data stored in the master node corresponding to the database service to the first slave node may be performed. If the type of the target node is determined to be the master node, and the second server is the same as the server where any slave node corresponding to the database service is located, and if the node corresponding to the database service is determined not to meet the preset fault tolerance mechanism, the step of synchronizing the data stored in the master node corresponding to the database service to the first slave node is not performed.
And 3, determining that the target node is a slave node corresponding to the database service, wherein the second server is different from the server where the master node corresponding to the database service is located.
Similarly, to avoid a single point problem, the stability of the database service is affected, and the slave node of the database service cannot migrate to the server where the master node corresponding to the database service is located. Therefore, in the present application, whether the node corresponding to the database service satisfies the preset fault tolerance mechanism may be determined by determining whether the type of the target node is a slave node, and whether the second server is different from the server where the master node corresponding to the database service is located. If the type of the target node is determined to be a slave node, and the second server is different from the server where the master node corresponding to the database service is located, and it is determined that the node corresponding to the database service meets a preset fault tolerance mechanism, a step of synchronizing data stored in the master node corresponding to the database service into the first slave node may be performed. If the type of the target node is determined to be the slave node, and the second server is the same as the server where the master node corresponding to the database service is located, and if the node corresponding to the database service is determined not to meet the preset fault tolerance mechanism, the step of synchronizing the data stored in the master node corresponding to the database service to the first slave node is not performed.
S103: if the target node is the master node corresponding to the database service, when the first slave node is determined to complete data synchronization, updating the state of the first slave node into a writable state, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node.
Since the master node can perform read-write operation, the slave node can only perform read operation, and the request (query) sent by the client is mainly processed by the master node. Therefore, when the type of the target node is the master node, the state of the first slave node can be updated to a writable state when the first slave node is determined to complete data synchronization, and the address information of the master node corresponding to the database service in the name service is updated according to the address information of the first slave node, so that the client can write data in the first slave node through the address information of the master node recorded in the name service, thereby being beneficial to determining the first slave node as the master node corresponding to the database service in the following.
In an application scenario, in order to monitor the status of each node conveniently, and ensure the stability and availability of the database service, a Sentinel may be used to monitor each node, and the routing information and types of each node are stored in the Sentinel.
S104: and closing the target node, and determining the first slave node to work as the master node corresponding to the database service.
If the target node is the master node corresponding to the database service, after the first slave node completes data synchronization, the master node of the database service needs to be switched. If a conventional Sentinel command is used for switching the master node, a certain time is required to be spent, so that the master node interrupts reconnection in the switching process, the client requests the database service in the reconnection process to be in a continuous failure state, and after the subsequent reconnection, the data requested by the client is written in the master node corresponding to the database service, so that the risk of losing the data may exist. Therefore, in the application, after the state of the first slave node is updated to a writable state, the target node is closed, the first slave node is determined to work as the master node corresponding to the database service, and after the target node is closed, the client tries to inquire the name service to acquire the address information of the latest master node, so that the switching from the target node to the first slave node, namely the switching of the master node for realizing the database service, is realized, the database service is ensured to always correspond to the master node, the stability and the availability of the database service are ensured, and the time for causing the database service abnormality due to data migration is reduced.
In another example, after updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node, before the target node is closed, the method further includes:
if the target node is a master node corresponding to the database service and a request sent by a client is received, a rejection instruction is sent to the client, and the first slave node is determined to work as the master node corresponding to the database service; the refusing instruction is used for refusing the request sent by the response client.
In the application, after updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node, if the data migration device receives the request sent by the client, the data migration device may reject the request sent by the responding client by sending a rejection instruction, such as a (dis) command, to the client without closing the target node, and determine that the first slave node works as the master node corresponding to the database service, so that the client tries to query the name service to obtain the address information of the latest master node of the database service after receiving the rejection instruction, thereby realizing active closing of the target node and switching of the master node of the database service.
In one example, the method further comprises:
if the target node is the slave node corresponding to the database service and the first slave node completes data synchronization, closing the target node and determining that the first slave node continues to work as the slave node corresponding to the database service.
In this application, the type of the target node may also be a slave node, that is, the target node serves the corresponding slave node for the database. Therefore, if the target node is the slave node corresponding to the database service and it is determined that the first slave node completes data synchronization, the target node may be directly turned off, and it is determined that the first slave node continues to work as the slave node corresponding to the database service.
It should be noted that, the data migration device may send the address information of the first slave node to the device storing the address information of the slave node corresponding to the database service, so that the devices may update the address information of the slave node corresponding to the database service according to the address information of the first slave node, thereby ensuring stability of the database service and facilitating management of the database service by the devices.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, R1 needs to migrate from server B to server C. Firstly, a new Replica (R2) is built in the server C, data stored by M1 are synchronously stored in R2, R1 is closed, cache information of R1 is cleared, for example, the cache information of R1 is deleted from Sentinel, and the R2 is determined to continue to work as a slave node corresponding to the database service.
In this application, when the type of the target node is a master node, in the process of migrating the target node from the first server to the second server, determination of a slave node (denoted as a second slave node) corresponding to the database service as the master node should be avoided. Wherein the creation time of the second slave node is earlier than the creation time of the first slave node. Therefore, after the migration instruction of the database service is acquired, before the first slave node is determined to work as the master node corresponding to the database service, the second slave node is kept to be the slave node corresponding to the database service. Illustratively, maintaining the second slave node servicing the database with the corresponding slave node may be accomplished by modifying the priority of the second slave node.
In an example, during the data migration process, any node corresponding to the database service may be abnormal, so as to ensure stability and high availability of the database service, in this application, different processing may be performed on the node corresponding to the database service according to different situations. Exemplary cases where any node corresponding to the target service fails include the following:
and in the first case, when the type of the target node is a master node, if the target node is abnormal and the first slave node does not complete data synchronization, stopping continuously synchronizing the data to the first slave node, and rolling back the node corresponding to the database service.
In the present application, rollback of a node corresponding to a database service refers to a master node corresponding to the database service and a slave node corresponding to the database service before the first slave node is created, deleted, and the data migration is adopted.
In one example, after rollback is performed on a node corresponding to a database service, the target node abnormality, that is, the main node abnormality corresponding to the database service, is considered, so that the main node cannot normally provide services to the outside. Therefore, in order to ensure high availability of the database service, in the present application, when an abnormality occurs in a master node corresponding to the database service, a failure automatic switching mechanism may be adopted to actively switch a slave node corresponding to the database service to a master node corresponding to the database service.
If the master node corresponding to the database service is determined to be faulty, determining a target slave node which is allowed to be switched to the master node corresponding to the database service from at least one slave node corresponding to the database service;
determining that the state of the target slave node is a writable state, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the target slave node;
and determining the target slave node to work as a master node corresponding to the database service.
In the present application, when it is determined that the master node corresponding to the database service fails, a target slave node that is allowed to be switched to the master node may be determined from the slave nodes corresponding to the database service. In an exemplary embodiment, the slave node with higher priority may be determined as the target slave node according to the priority corresponding to the at least one slave node corresponding to the database service, or any slave node may be determined as the target slave node from the at least one slave node corresponding to the database service, or the target slave node may be determined from the at least one slave node corresponding to the database service by a manual configuration method. Of course, the above methods of determining the target slave node may be combined with each other, for example, the slave node with the higher priority may be determined as the target slave node according to the priority corresponding to at least one slave node corresponding to the database service, but if the priorities corresponding to at least one slave node corresponding to the database service are the same, any slave node may be determined as the target slave node from at least one slave node corresponding to the database service.
Considering that the master node can perform read-write operation, the slave node can only perform read operation, and the request (query) sent by the client is mainly processed by the master node. Therefore, in the application, after the target slave node is determined, the state of the target slave node can be updated to be in a writable state, and the address information of the master node corresponding to the database service in the name service is updated according to the address information of the target slave node, so that the client can write data in the target slave node through the address information of the master node recorded in the name service, thereby being beneficial to determining the target slave node as the master node corresponding to the database service in the following steps. The data migration device may then determine that the target slave node is operating as the master node to which the database service corresponds. For example, the data migration device may send notification information to the target slave node and the device that manages node information corresponding to the database service, so as to notify the target slave node and the device that manages node information corresponding to the database service, where the target slave node operates as a master node corresponding to the database service.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, M1 needs to migrate from server a to server C. Firstly, M1 needs to synchronize data from server a to newly built Replica (R2) on server C, if M1 is determined to be abnormal in the process of synchronizing data to R2 by M1, and M1 does not complete synchronizing data to R2, stopping data synchronization, continuing to adopt M1 as a Master, R1 as a Replica, and subsequently switching R1 to a new Master depending on a fault automatic switching mechanism.
And in the second case, when the type of the target node is a master node, if the target node is abnormal and the first slave node completes data synchronization, continuing to execute the step of data migration.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, M1 needs to migrate from server a to server C. Firstly, M1 needs to synchronize data from server a to newly built Replica (R2) on server C, in the process of synchronizing data to R2 by M1, if it is determined that M1 is abnormal and M1 has completed synchronizing data to R2, the step of data migration is continuously executed, for example, the state of R1 is updated to a writable state, and according to the address information of R1, the address information of the Master node corresponding to the database service in the name service is updated, R2 is used as a new Master, R1 is used as Replica, and M1 is closed.
And thirdly, when the type of the target node is a master node, if the first slave node is abnormal and the first slave node is not determined to be the master node corresponding to the database service, rolling back the node corresponding to the database service.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, M1 needs to migrate from server a to server C. First, M1 needs to synchronize data from server a to newly created Replica (R2) on server C, and if it is determined that R2 is abnormal and R2 is not adopted as a new Master in the process of synchronizing data to R2 by M1, deleting R2 newly created on server and continuing to adopt M1 as a Master and R1 as Replica.
And fourthly, when the type of the target node is a master node, if the first slave node is determined to be the master node corresponding to the database service and the first slave node is abnormal, which indicates that the master node corresponding to the database service is abnormal, a fault automatic switching mechanism can be adopted to actively switch the slave node corresponding to the database service to the master node corresponding to the database service.
It should be noted that, the process of actively switching the slave node corresponding to the database service to the master node corresponding to the database service by adopting the failure automatic switching mechanism is described in the above case one, and the repetition is not repeated.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, M1 needs to migrate from server a to server C. First, M1 needs to synchronize data from server a to newly created Replica (R2) on server C, after M1 completes data synchronization to R2, if it is determined that R2 is adopted as a new Master and is abnormal, R1 is determined as a Master node corresponding to the database service. And determining the state of R1 as a writable state, and updating the address information of the Master in the name service according to the address information of R1.
And fifthly, when the type of the target node is a slave node, deleting the target node if the target node is determined to be abnormal.
In one example, when the type of the target node is a slave node, if it is determined that the target node is abnormal and the first slave node does not complete data synchronization, continuing to synchronize the data to the first slave node and deleting the target node.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, R1 needs to migrate from server B to server C. First, M1 needs to synchronize data from server a to newly created duplicate (R2) on server C, and in the process of synchronizing data to R2 by M1, if it is determined that R1 is abnormal and data synchronization between M1 and R2 is not completed, the data is continuously synchronized to R2 and R1 is deleted.
In another example, when the type of the target node is a slave node, if it is determined that the target node is abnormal and the first slave node completes data synchronization, the target node is directly deleted.
For example, suppose Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, R1 needs to migrate from server B to server C. Firstly, M1 needs to synchronize data from server a to newly built Replica (R2) on server C, and in the process of synchronizing data from M1 to R2, if it is determined that R1 is abnormal, and M1 completes data synchronization with R2, R1 is directly deleted.
And in the sixth case, when the type of the target node is a slave node, if the first slave node is abnormal and the second slave node is not deleted, rolling back the node corresponding to the database service, and deleting the first slave node.
In the data migration process, after the migration instruction of the database service is acquired, a first slave node can be newly built for the database service in the second server, and the data stored in the master node corresponding to the database service is synchronized into the first slave node, so that manual intervention is not needed, and the data migration efficiency is improved. If the target node is determined to be the master node corresponding to the database service, when the first slave node is determined to complete data synchronization, the state of the first slave node can be updated to be a writable state, and the address information of the master node corresponding to the database service in the name service is updated according to the address information of the first slave node, so that the client can write data in the first slave node through the address information of the master node recorded in the name service. And then closing the target node and determining that the first slave node works as the master node corresponding to the database service, thereby ensuring that the database service always corresponds to the master node, ensuring the stability and the availability of the database service, and reducing the time for abnormal database service caused by data migration.
Example 2:
the following describes a data migration method provided in the present application through a specific embodiment, and fig. 2 is a schematic diagram of a specific data migration flow provided in the present application, where the flow includes:
s201: obtaining a migration instruction of a database service; the migration instruction is used for migrating the target node of the database service from the first server to the second server.
Before a migration instruction of a database service is acquired, when a main node corresponding to the database service works normally, abnormal alarm information of the first server is received; and/or determining that the load of the first server reaches a preset load threshold.
S202: and determining that the node corresponding to the database service meets a preset fault tolerance mechanism.
In one example, determining that the node corresponding to the database service meets the preset fault tolerance mechanism includes at least one of:
determining that a master node corresponding to the database service and at least one slave node corresponding to the database service work normally;
determining that the target node is a master node corresponding to the database service, wherein the second server is different from the server where at least one slave node corresponding to the database service is located;
And determining that the target node is a slave node corresponding to the database service, and that the second server is different from the server where the master node corresponding to the database service is located.
S203: and judging whether the type of the target node is a main node, if so, executing S204, otherwise, executing S208.
S204: and establishing a first slave node for database service in the second server, and synchronously storing the data stored by the target node into the first slave node.
S205: when the first slave node is determined to complete data synchronization, maintaining the second slave node serving the corresponding slave node for the database; wherein the creation time of the second slave node is earlier than the creation time of the first slave node.
S206: the state of the first slave node is updated to a writable state.
S207: and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node, closing the target node, and determining that the first slave node continues to work as the master node corresponding to the database service.
Fig. 3 is a schematic node switching diagram corresponding to a specific target node according to an embodiment of the present application. As shown in fig. 3, assume that Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, and that M1 needs to migrate from server a to server C. Firstly, constructing a new Replica (R2) in a server C, synchronously storing data stored in M1 into R2, and determining that the data synchronization is completed; then, maintaining the slave node corresponding to the R1 serving for the database by modifying the priority of the R1, so that the slave node cannot be lifted to a Master, and setting the state of the R2 as a writable state; then, according to the address information of R2, updating the address information of the Master corresponding to the database service in the name service, and closing M1. Since M1 is closed, when R2 is determined to complete data synchronization, one available Replica can be selected from two replicas corresponding to the database service to become a new Master. Since R1 is set to be unable to be promoted to Master, R2 will become a new Master, i.e., R2 will be determined to be M2, R1 will be changed to Replica of M2, M1 will be changed to Replica of M2 (R3), at which time the information of R3 is removed, e.g., from Sentinel and name service. After M1 stops servicing, the client will attempt to query the name service to obtain the latest Master address, i.e. the address of R2, since R2 is writable, data is written in R2, and since M1 has been turned off, the problem of overwriting the data written by R2 due to synchronization problems does not occur. Finally, since the Sentinel defaults to changing other nodes of the new Master to the Replica node of the new Master, M1 is converted to Replica (R3) of M2, and the information of R3 is removed at this time, and the Master migration flow is completed.
S208: and creating a first slave node for the database service in the second server, and synchronizing the data stored in the master node corresponding to the database service into the first slave node.
S209: if the first slave node is determined to complete data synchronization, the first slave node is determined to work as the slave node corresponding to the database service.
Fig. 4 is a schematic node switching diagram corresponding to a specific target node according to an embodiment of the present application. As shown in fig. 4, assume that Master (M1) is deployed at server a and duplicate (R1) is deployed at server B, R1 needs to migrate from server B to server C. First, a new Replica (R2) is built in the server C, and the data stored in M1 is synchronously stored in R2. R1 is turned off and R1 cache information is cleaned up, such as R1 cache information in name service and Sentinel.
S210: if the master node corresponding to the database service is abnormal, determining a target slave node which is allowed to be switched to the master node corresponding to the database service from at least one slave node corresponding to the database service.
S211: and determining the state of the target slave node as a writable state, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the target slave node.
S212: and determining the target slave node to work as a master node corresponding to the database service.
Fig. 5 is a schematic flow chart of a master node failover according to an embodiment of the present application, and as shown in fig. 5, it is assumed that the states of target slave nodes are monitored by Sentinel a to Sentinel C. When determining that the Master corresponding to the database service is abnormal, the Sentinel senses the fault and ascends the Replica corresponding to the database service, and the Sentinel broadcasts a message containing the name of the Replica and from which old address the Master is switched to which new address. The sentry Checker (Sentinel Checker) subscribes to the message broadcast by Sentinel, and when Sentinel Checker 0-Sentinel Checker2 monitors the master-slave switching message, a Name Service (Name Service) is notified to update the address information of the master node corresponding to the database Service. A client (client) tries reconnection after sensing that the connection of a main node before updating of the database service is abnormal through a sent request (query); and obtaining the address information of the latest master node of the database service by inquiring the name service, then connecting with a new master node, and continuing to serve.
It will be appreciated by those skilled in the art that in the above-described method of the specific embodiments, the written order of steps is not meant to imply a strict order of execution but rather should be construed according to the function and possibly inherent logic of the steps.
Example 3:
the application further provides a data migration device, and fig. 6 is a schematic structural diagram of the data migration device, where the device includes:
an obtaining unit 61, configured to obtain a migration instruction of a database service; the migration instruction is used for migrating the target node of the database service from a first server to a second server;
a first processing unit 62, configured to create a first slave node for the database service in the second server, and synchronize data stored in a master node corresponding to the database service to the first slave node;
an updating unit 63, configured to update, if the target node is a master node corresponding to the database service, a state of the first slave node to a writable state when it is determined that the first slave node completes data synchronization, and update address information of the master node corresponding to the database service in a name service according to address information of the first slave node;
and the second processing unit 64 is configured to close the target node, and determine that the first slave node continues to work as the master node corresponding to the database service.
The principle of solving the problem of the data migration device provided by the embodiment of the application is the same as that of solving the problem of the data migration method, and specific content can be found in the embodiment of the method.
Example 4:
fig. 7 is a schematic structural diagram of a data migration device provided in an embodiment of the present application, and on the basis of the foregoing embodiments, the embodiment of the present application further provides a data migration device, as shown in fig. 7, including: the processor 71, the communication interface 72, the memory 73 and the communication bus 74, wherein the processor 71, the communication interface 72 and the memory 73 complete communication with each other through the communication bus 74;
the memory 73 has stored therein a computer program which, when executed by the processor 71, causes the processor 71 to perform the steps of:
obtaining a migration instruction of a database service; the migration instruction is used for migrating the target node of the database service from a first server to a second server;
creating a first slave node for the database service in the second server, and synchronizing data stored in a master node corresponding to the database service to the first slave node;
if the target node is the master node corresponding to the database service, updating the state of the first slave node into a writable state when the first slave node is determined to complete data synchronization, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node;
And closing the target node, and determining the first slave node to continue working as the master node corresponding to the database service.
Since the principle of the data migration device for solving the problem is similar to that of the data migration method, the implementation of the data migration device can refer to the implementation of the method, and the repetition is omitted.
Example 5:
on the basis of the above embodiments, the embodiments of the present application further provide a computer readable storage medium, in which a computer program executable by a processor is stored, which when executed on the processor causes the processor to perform the steps of:
obtaining a migration instruction of a database service; the migration instruction is used for migrating the target node of the database service from a first server to a second server;
creating a first slave node for the database service in the second server, and synchronizing data stored in a master node corresponding to the database service to the first slave node;
if the target node is the master node corresponding to the database service, updating the state of the first slave node into a writable state when the first slave node is determined to complete data synchronization, and updating the address information of the master node corresponding to the database service in the name service according to the address information of the first slave node;
And closing the target node, and determining the first slave node to continue working as the master node corresponding to the database service.
The principle of solving the problem by using the computer readable medium provided by the embodiment of the application is the same as that of solving the problem by using the data migration method, and specific content can be seen in the embodiment of the method.

Claims (10)

CN202210324045.9A2022-03-292022-03-29Data migration method, device, equipment and mediumActiveCN114598711B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202210324045.9ACN114598711B (en)2022-03-292022-03-29Data migration method, device, equipment and medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202210324045.9ACN114598711B (en)2022-03-292022-03-29Data migration method, device, equipment and medium

Publications (2)

Publication NumberPublication Date
CN114598711A CN114598711A (en)2022-06-07
CN114598711Btrue CN114598711B (en)2024-04-16

Family

ID=81813344

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202210324045.9AActiveCN114598711B (en)2022-03-292022-03-29Data migration method, device, equipment and medium

Country Status (1)

CountryLink
CN (1)CN114598711B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115150400B (en)*2022-07-052024-04-30普联技术有限公司Service fault processing method and device, cloud service platform and storage medium

Citations (11)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106027290A (en)*2016-05-122016-10-12深圳市永兴元科技有限公司Fault processing method and device
WO2018019023A1 (en)*2016-07-272018-02-01腾讯科技(深圳)有限公司Data disaster recovery method, apparatus and system
WO2020015366A1 (en)*2018-07-182020-01-23华为技术有限公司Method and device for data migration
CN111078667A (en)*2019-12-122020-04-28腾讯科技(深圳)有限公司Data migration method and related device
US10657154B1 (en)*2017-08-012020-05-19Amazon Technologies, Inc.Providing access to data within a migrating data partition
CN111200532A (en)*2020-01-022020-05-26广州虎牙科技有限公司Method, device, equipment and medium for master-slave switching of database cluster node
WO2020253596A1 (en)*2019-06-212020-12-24深圳前海微众银行股份有限公司High availability method and apparatus for redis cluster
CN112269693A (en)*2020-10-232021-01-26北京浪潮数据技术有限公司Node self-coordination method, device and computer readable storage medium
CN112306993A (en)*2020-11-062021-02-02平安科技(深圳)有限公司Data reading method, device and equipment based on Redis and readable storage medium
CN113127444A (en)*2020-01-152021-07-16中移(苏州)软件技术有限公司Data migration method, device, server and storage medium
CN114116671A (en)*2021-11-252022-03-01深圳Tcl新技术有限公司 Database migration method, system, server and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN107526659B (en)*2016-06-212021-02-12伊姆西Ip控股有限责任公司Method and apparatus for failover

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106027290A (en)*2016-05-122016-10-12深圳市永兴元科技有限公司Fault processing method and device
WO2018019023A1 (en)*2016-07-272018-02-01腾讯科技(深圳)有限公司Data disaster recovery method, apparatus and system
US10657154B1 (en)*2017-08-012020-05-19Amazon Technologies, Inc.Providing access to data within a migrating data partition
WO2020015366A1 (en)*2018-07-182020-01-23华为技术有限公司Method and device for data migration
WO2020253596A1 (en)*2019-06-212020-12-24深圳前海微众银行股份有限公司High availability method and apparatus for redis cluster
CN111078667A (en)*2019-12-122020-04-28腾讯科技(深圳)有限公司Data migration method and related device
CN111200532A (en)*2020-01-022020-05-26广州虎牙科技有限公司Method, device, equipment and medium for master-slave switching of database cluster node
CN113127444A (en)*2020-01-152021-07-16中移(苏州)软件技术有限公司Data migration method, device, server and storage medium
CN112269693A (en)*2020-10-232021-01-26北京浪潮数据技术有限公司Node self-coordination method, device and computer readable storage medium
CN112306993A (en)*2020-11-062021-02-02平安科技(深圳)有限公司Data reading method, device and equipment based on Redis and readable storage medium
CN114116671A (en)*2021-11-252022-03-01深圳Tcl新技术有限公司 Database migration method, system, server and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
混合云存储架构下分布式大数据异步迁移系统设计;谢梦怡;《电子设计工程》;第第27卷卷(第第23期期);45-49页*

Also Published As

Publication numberPublication date
CN114598711A (en)2022-06-07

Similar Documents

PublicationPublication DateTitle
US11360854B2 (en)Storage cluster configuration change method, storage cluster, and computer system
CN110784350B (en)Design method of real-time high-availability cluster management system
CN108306955B (en)Large-scale interconnection clustering method for vehicle-mounted terminals
CN112463448B (en) Distributed cluster database synchronization method, device, device and storage medium
JP6905161B2 (en) Management methods, systems, and devices for master and standby databases
CN111045745A (en)Method and system for managing configuration information
CN107168970A (en)A kind of distributed file system HDFS management method, apparatus and system
CN103036719A (en)Cross-regional service disaster method and device based on main cluster servers
CN112100004A (en)Management method and storage medium of Redis cluster node
CN115562911B (en)Virtual machine data backup method, device, system, electronic equipment and storage medium
CN113515574B (en)Data synchronization method and device
CN113467873A (en)Virtual machine scheduling method and device, electronic equipment and storage medium
US10452321B2 (en)Storage system and control method therefor
CN113590049A (en)Storage volume cross-node cloning method, device, equipment and readable medium
CN114598711B (en)Data migration method, device, equipment and medium
CN113766004A (en)Disaster recovery system, method and storage medium based on multi-cloud platform
CN109474694A (en) A management and control method and device for a NAS cluster based on a SAN storage array
CN114925052B (en)Method, apparatus, device and computer readable medium for restarting database
CN112269693B (en)Node self-coordination method, device and computer readable storage medium
CN117407125B (en)Pod high availability implementation method, device, equipment and readable storage medium
CN116185697B (en) Container cluster management method, device, system, electronic equipment and storage medium
CN107644035B (en)Database system and deployment method thereof
CN119094313A (en) Data processing method, device, electronic device and computer readable storage medium
CN113434340A (en)Server and cache cluster fault rapid recovery method
CN104052799A (en)Method for achieving high availability storage through resource rings

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp