Disaster recovery processing method based on database fragmentation, electronic equipment and storage medium

Through the database sharding method, it automatically responds to disaster recovery switching messages and obtains and synchronizes the main library, solving the problem of low disaster recovery switching efficiency caused by manual manual operations in the existing technology, and achieving efficient and accurate disaster recovery switching.

CN119739567APending Publication Date: 2025-04-01INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411952989.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

In the prior art, disaster recovery switching requires manual operation, resulting in inefficiency and cannot meet the rapid growth of distributed databases.

Method used

Through a database sharding method, in response to the disaster recovery switching message, the first main library in the production resource pool is obtained and configured as a write-ban state, the second main library in the disaster recovery resource pool is obtained, and synchronized with the first main library, and finally the second main library is configured as a readable and write state to realize automated disaster recovery switching.

Benefits of technology

It realizes automated disaster recovery switching, improves disaster recovery switching efficiency and accuracy, reduces manual intervention, and can better support the rapid growth of distributed databases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739567A_ABST
    Figure CN119739567A_ABST
Patent Text Reader

Abstract

The invention discloses a disaster recovery processing method based on database fragments, electronic equipment and a storage medium, and relates to a distributed technology, and the method comprises the steps: obtaining a first main library of a first fragment in a production resource pool in response to a first disaster recovery switching message, and configuring the first main library to be in a write forbidding state; a second main library of a second fragment in a disaster recovery resource pool is obtained, the second fragment is a disaster recovery fragment of the first fragment, and the first disaster recovery switching message is used for switching a used database from the first main library to the second main library; and synchronizing the second main library with the first main library, and configuring the second main library to be in a read-write state. The disaster recovery backup switching from the first main library to the second main library is automatically completed, and the disaster recovery backup switching efficiency is improved. Switching is carried out by taking the fragment as a unit, so that the database in a certain fragment in the distributed database can be switched more accurately, and the accuracy of disaster recovery backup switching is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed technology, and in particular to a disaster recovery processing method, electronic equipment and storage medium based on database sharding. Background Art

[0002] With the development of distributed technology, the application of distributed databases is becoming more and more popular. A distributed database is a database that stores data in different physical locations or computers.

[0003] During the production process, the distributed database maintains two clusters, one is the production cluster and the other is the disaster recovery cluster. When the production cluster fails and cannot be used, it switches to the disaster recovery cluster to provide database services.

[0004] However, currently, the disaster recovery switching process requires manual operation, which results in low efficiency of disaster recovery switching. How to improve the efficiency of disaster recovery switching has become an urgent problem to be solved. Summary of the invention

[0005] The present invention provides a disaster recovery processing method, electronic equipment and storage medium based on database sharding, so as to solve the problem of low disaster recovery switching efficiency when disaster recovery switching is currently performed manually.

[0006] According to one aspect of the present invention, a disaster recovery processing method based on database sharding is provided, comprising:

[0007] In response to the first disaster recovery switching message, obtaining a first master library of a first shard in a production resource pool, and configuring the first master library to be in a write-forbidden state;

[0008] Acquire a second master database of a second shard in a disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch a used database from the first master database to the second master database;

[0009] The second main library is synchronized with the first main library, and the second main library is configured to be in a readable and writable state.

[0010] According to another aspect of the present invention, a disaster recovery processing device based on database sharding is provided, comprising:

[0011] A first master library acquisition module, configured to acquire a first master library of a first shard in a production resource pool in response to a first disaster recovery switching message, and configure the first master library to be in a write-forbidden state;

[0012] A second master database acquisition module is used to acquire a second master database for a second shard in a disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch a used database from the first master database to the second master database;

[0013] The switching module is used to synchronize the second main library with the first main library and configure the second main library to be in a readable and writable state.

[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0015] at least one processor; and

[0016] a memory communicatively connected to the at least one processor; wherein,

[0017] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the disaster recovery processing method based on database sharding described in any embodiment of the present invention.

[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the disaster recovery processing method based on database sharding described in any embodiment of the present invention when executed.

[0019] The technical solution of the embodiment of the present invention, in response to the first disaster recovery switching message, obtains the first main library of the first shard in the production resource pool, and configures the first main library to be in a write-disabled state; obtains the second main library of the second shard in the disaster recovery resource pool, the second shard is the disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch the used database from the first main library to the second main library; synchronizes the second main library with the first main library, and configures the second main library to be in a readable and writable state. Compared with the current manual disaster recovery switching between the first main library and the second main library, the technical solution provided by the embodiment of the present invention can automatically respond to the first disaster recovery switching information from the distributed database, configure the second main library to be in a readable and writable state after configuring the first main library to be in a write-disabled state, and synchronize the second main library with the first main library. If the synchronization is successful, the disaster recovery switching is completed. The disaster recovery switching from the first main library to the second main library is automatically completed, and the disaster recovery switching efficiency is improved. Switching is performed in units of shards, so that the database in a shard in the distributed database can be switched more accurately, and the accuracy of disaster recovery switching is improved.

[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 It is a schematic diagram of a system architecture applicable to a disaster recovery processing method based on database sharding provided in an embodiment of the present invention;

[0023] Figure 2 It is a flowchart of a disaster recovery processing method based on database sharding provided by an embodiment of the present invention;

[0024] Figure 3 It is a flowchart of another disaster recovery processing method based on database sharding provided by an embodiment of the present invention;

[0025] Figure 4 It is a structural schematic diagram of a disaster recovery processing device based on database sharding provided by an embodiment of the present invention;

[0026] Figure 5 It is a structural schematic diagram of an electronic device for implementing a disaster recovery processing method based on database sharding according to an embodiment of the present invention. DETAILED DESCRIPTION

[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0029] The information collected by the embodiments of the present invention is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good customs, and provide corresponding operation portals for users to choose to authorize or refuse. Provide users with corresponding operation portals for users to choose to agree or refuse the results of automated decision-making; if the user chooses to refuse, the expert decision-making process will be entered to avoid relevant legal risks and public opinion risks.

[0030] With the development of distributed technology, the application of distributed databases is becoming more and more popular. A distributed database is a database that stores data in different physical locations or computers.

[0031] During the production process, the distributed database maintains two clusters, one is the production cluster and the other is the disaster recovery cluster. When the production cluster fails and cannot be used, it switches to the disaster recovery cluster to provide database services.

[0032] However, currently, the disaster recovery switching process requires manual operation. When switching a distributed database, there are many steps involved, most of which require manual intervention. The overall switching efficiency and switching accuracy are relatively low. With the gradual promotion and use of distributed databases, the number of nodes is increasing rapidly, and the current switching time efficiency can no longer meet the requirements. How to improve the efficiency of disaster recovery switching has become an urgent problem to be solved.

[0033] Figure 1 The schematic diagram of the system architecture applicable to the disaster recovery processing method based on database sharding provided by the embodiment of the present invention includes an application request unit, a self-service unit, a production resource pool and a disaster recovery resource pool. Among them, the production resource pool and the disaster recovery resource pool both have a resource pool unit and a database management console.

[0034] The request unit is used to receive a first disaster recovery switching message submitted by an application, and the message includes the address information of the first shard that specifically needs to be switched for disaster recovery. The self-service unit is used to respond to the first disaster recovery switching message, obtain the first master library of the first shard in the production resource pool, and configure the first master library to be in a write-disabled state; obtain the second master library of the second shard in the disaster recovery resource pool. The second master library is synchronized with the first master library, and the second master library is configured to be in a readable and writable state. The resource pool unit is used to manage the physical machine resources of the resource pool (such as the production resource pool or the disaster recovery resource pool), including information such as the container address, the park to which it belongs, the processor, the memory, the network, and the disk storage. Among them, the container is a container that carries a master library or a backup library. The production resource pool and the disaster recovery resource pool can be located in different parks, for example, the production resource pool is located in a park in Shanghai, and the disaster recovery resource pool is located in a park in Beijing. The database management console is used to manage the database, and can provide functions such as database command issuance, query of information such as role status, and database high availability during the disaster recovery switching process.

[0035] like Figure 1 As shown, the production resource pool is located in Park A, and maintains multiple shards for user 1 and multiple shards for user 2. Each shard includes a main library and at least one backup library. For the production resource pool, each main library has three backup libraries. For the disaster recovery resource pool, each main library has one backup library. The database provides synchronous mapping of the main library between the production resource pool and the disaster recovery resource pool. For example, the content of the first main library of user 1 in shard a in the production resource pool and the second main library of user 1 in shard a in the disaster recovery resource pool are synchronously mapped. The content of the main library x of user 2 in shard a in the production resource pool and the main library y of user 2 in shard a in the disaster recovery resource pool are synchronously mapped.

[0036] Figure 2 This is a flowchart of a disaster recovery processing method based on database sharding provided by an embodiment of the present invention. This embodiment is applicable to the situation where a distributed database performs disaster recovery switching. The method can be executed by a disaster recovery processing device based on database sharding. The disaster recovery processing device based on database sharding can be implemented in the form of hardware and / or software. The disaster recovery processing device based on database sharding can be configured in electronic devices such as personal computers and servers. Figure 1 As shown, the method includes:

[0037] S101. In response to a first disaster recovery switching message, obtain a first master library of a first shard in a production resource pool, and configure the first master library to be in a write-disabled state.

[0038] The first disaster recovery switching message may include the identifier of the first master database to be switched. The database management console interface of the production resource pool is called according to the identifier of the first master database to obtain the latest database in the first shard, that is, the first master database.

[0039] It should be noted that the database management console has the function of maintaining high availability of the database in the production resource pool. By accessing the database management console, the currently available first main database can be obtained. The state of the first main database is configured to be write-disabled. In the write-disabled state, new data cannot be written to the first main database.

[0040] Optionally, obtaining the first master database of the first shard in the production resource pool can be implemented in the following manner:

[0041] Obtain a target user associated with a first shard, where the first shard is used to store database data of the target user; determine one or more first associated shards according to the target user; each first associated shard has a one-to-one corresponding second associated shard in a disaster recovery resource pool; and perform disaster recovery switching according to the first associated shard and the corresponding second associated shard.

[0042] The first disaster recovery switching message may be for a certain first main database or for a certain user identifier. If it is for the first main database, only the first main database may be switched for disaster recovery. If it is for a certain user, the first associated shard associated with the user is determined based on the association between the user and the shard. After multiple first associated shards are determined, the disaster recovery switching of the main databases in multiple first associated shards may be performed in parallel through concurrent processes. The main databases in some of the first associated shards in all the first associated shards may be switched for disaster recovery as required.

[0043] The above implementation method can switch multiple shards on a user basis, realize synchronous switching of multiple shards associated with the user, and improve disaster recovery switching efficiency.

[0044] Furthermore, before obtaining the first master library of the first shard in the production resource pool in response to the first disaster recovery switching message, the method further includes:

[0045] A first disaster recovery switching message is received from a database application according to a database switching requirement; or a first disaster recovery switching message is received from a disaster recovery detection application according to a disaster recovery detection result.

[0046] The database application can be any application program that uses the data in the database, or any database management application that can manage the data in the database. The distributed database can have a disaster recovery detection application for monitoring the operating status of the database cluster in the shard. When a failure such as downtime of the main database in a shard is detected, the first disaster recovery switching message can be triggered.

[0047] The above implementation can trigger the first disaster recovery switching message according to the database switching requirement or the disaster recovery detection result, thereby realizing flexible disaster recovery switching. Moreover, the disaster recovery switching can be automatically triggered through data interaction, without the need for manual judgment on whether to perform disaster recovery switching, thereby improving the efficiency and usability of disaster recovery switching.

[0048] S102: Obtain a second master database for a second shard in a disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard.

[0049] The first disaster recovery switch message is used to switch the used database from the first main database to the second main database.

[0050] The disaster recovery resource pool and the production resource pool are pre-configured with a corresponding relationship. According to the pre-configured corresponding relationship, the address (IP address) of the second main database can be obtained through the database management console of the disaster recovery resource pool, and then the second main database can be accessed.

[0051] S103: Synchronize the second main library with the first main library, and configure the second main library to be in a readable and writable state.

[0052] The second main library is configured to be in a readable and writable state. At this time, the state of the second main library is changed from a read-only state to a readable and writable state. The read-only state is equivalent to a write-forbidden state. When the second main library is in a readable and writable state, the second main library can be synchronized according to the data in the first main library, so that the data content in the second main library is consistent with the data content in the first main library.

[0053] Optionally, synchronizing the second main library with the first main library may be implemented in the following manner:

[0054] Obtain first transaction information of the first main database and second transaction information of the second main database; determine whether the second main database is synchronized with the first main database according to the first transaction information and the second transaction information; if not, synchronize the second main database with the first main database.

[0055] Each master database has a transaction information for indicating the latest completed transaction. Optionally, the transaction information can be a global transaction identifier (GTID). The first transaction information is obtained through the database management console of the production resource pool, and the second transaction information is obtained through the database management console of the disaster recovery resource pool.

[0056] According to the first transaction information and the second transaction information, it can be determined whether the transaction progress processed by the first main database and the second main database is the same, and further whether the first main database and the second main database are synchronized.

[0057] The above implementation method can accurately determine whether the first main database and the second main database are synchronized according to the transaction information, avoid disaster recovery switching before the announcement, and improve the reliability of disaster recovery switching.

[0058] Optionally, based on the above implementation, synchronizing the second main library with the first main library may be implemented as follows:

[0059] Perform a preset number of query synchronization results at a preset time interval. If, within the preset number of times, the synchronization results are all inconsistent between the first transaction information and the second transaction information, a disaster recovery switching interrupt is triggered; if, within the preset number of times, the synchronization results are all consistent between the first transaction information and the second transaction information, it is determined that the second main database is synchronized with the first main database.

[0060] Optionally, the preset time interval may be 1 second, and the preset number of times may be 60 times. This means that if the second master database cannot be synchronized with the first master database within 60 seconds, a disaster recovery switching interruption is triggered. When the interruption is triggered, the disaster recovery switching process is exited, and a message is sent to the database administrator so that the database administrator can manually check.

[0061] The above implementation can timely trigger disaster recovery switching interruption when the first main database and the second main database cannot complete synchronization, avoid long-term invalid synchronization, and improve the abnormal handling efficiency of disaster recovery switching.

[0062] Furthermore, after configuring the second main library to be in a readable and writable state, the method further includes:

[0063] A reverse replication relationship is established in which the second master database is mapped to the first master database, and the reverse replication relationship is used for the first master database to perform synchronous update according to the data in the first master database.

[0064] The above implementation method can establish a reverse replication relationship between the second main library and the first main library after the disaster recovery switch, and the reverse replication relationship is to synchronize the content of the second main library to the first main library. The reverse replication relationship can provide a switching basis for switching back from the second main library to the first main library again, realize bidirectional switching between the first main library and the second main library, and improve ease of use.

[0065] Furthermore, after configuring the second main library to be in a readable and writable state, the method further includes:

[0066] After a preset switching time, a second disaster recovery switching message is triggered, where the second disaster recovery switching message is used to switch the used database from the second primary database to the first primary database;

[0067] Get the second master library of the second shard in the disaster recovery resource pool, and configure the second master library to be write-forbidden; get the first master library of the first shard in the production resource pool, synchronize the first master library with the second master library, and configure the first master library to be readable and writable. In actual operation, the relevant departments require the production resource pool to be restored after the disaster recovery drill.

[0068] When the second disaster recovery switch message is triggered, the second main database in the disaster recovery resource pool is switched back to the first main database in the production resource pool.

[0069] The above implementation method can rewrite and switch back to the production resource pool after switching to the disaster recovery resource pool after a preset switching time. When switching back to the production resource pool, automatic switching can also be achieved without manual switching, thereby improving the switching efficiency of databases in different resource pools.

[0070] The disaster recovery processing method based on database sharding of the embodiment of the present invention, in response to the first disaster recovery switching message, obtains the first main library of the first shard in the production resource pool, and configures the first main library to be in a write-disabled state; obtains the second main library of the second shard in the disaster recovery resource pool, the second shard is the disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch the used database from the first main library to the second main library; synchronizes the second main library with the first main library, and configures the second main library to be in a readable and writable state. Compared with the current manual disaster recovery switching between the first main library and the second main library, the disaster recovery processing method based on database sharding provided by the embodiment of the present invention can automatically respond to the first disaster recovery switching information by the distributed database, configure the second main library to be in a readable and writable state after configuring the first main library to be in a write-disabled state, and synchronize the second main library with the first main library. If the synchronization is successful, the disaster recovery switching is completed. The disaster recovery switching from the first main library to the second main library is automatically completed, and the disaster recovery switching efficiency is improved. Switching in shards can more accurately switch the database in a shard in the distributed database, thereby improving the accuracy of disaster recovery switching.

[0071] Figure 3 It is a flowchart of a disaster recovery processing method based on database sharding provided by an embodiment of the present invention, which is applied to a distributed database disaster recovery switching scenario and can be executed by the self-service unit described in the above embodiment, including:

[0072] S201, receiving a first disaster recovery switching message sent by a database application according to a database switching requirement; or receiving a first disaster recovery switching message sent by a disaster recovery detection application according to a disaster recovery detection result.

[0073] S202: In response to the first disaster recovery switching message, obtain a first master library of a first shard in a production resource pool, and configure the first master library to be in a write-disabled state.

[0074] S203, obtaining a target user associated with the first shard, where the first shard is used to store database data of the target user; determining one or more first associated shards according to the target user; each first associated shard has a one-to-one corresponding second associated shard in the disaster recovery resource pool; configuring the master database in each associated shard in the production resource pool to be in a write-disabled state.

[0075] S204: Obtain a second master database for a second shard in the disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard.

[0076] The first disaster recovery switch message is used to switch the used database from the first main database to the second main database.

[0077] S205. Obtain first transaction information of the first main database and second transaction information of the second main database; determine whether the second main database is synchronized with the first main database according to the first transaction information and the second transaction information; if not, synchronize the second main database with the first main database.

[0078] S206. Query the synchronization results a preset number of times at a preset time interval. If the synchronization results are that the first transaction information and the second transaction information are inconsistent within the preset number of times, trigger a disaster recovery switch interruption; if the synchronization results are that the first transaction information and the second transaction information are consistent within the preset number of times, determine that the second main database is synchronized with the first main database.

[0079] S207: Configure the second master database to be in a readable and writable state. Configure the master database in each associated shard in the disaster recovery resource pool to be in a readable and writable state.

[0080] S208: Establish a reverse replication relationship in which the second master database is mapped to the first master database, wherein the reverse replication relationship is used for the first master database to synchronously update the data in the first master database.

[0081] S209. After a preset switching time, trigger a second disaster recovery switching message, where the second disaster recovery switching message is used to switch the used database from the second main database to the first main database; obtain the second main database of the second shard in the disaster recovery resource pool, and configure the second main database to be in a write-disabled state.

[0082] S210: Obtain a first main library of a first shard in a production resource pool, synchronize the first main library with the second main library, and configure the first main library to be in a readable and writable state.

[0083] Figure 4 FIG. 1 is a schematic diagram of a schematic diagram of a disaster recovery processing device based on database sharding provided by an embodiment of the present invention, and the device is applicable to the case where a distributed database performs disaster recovery switching. Figure 4 As shown, the device includes: a first main library acquisition module 31, a second main library acquisition module 32 and a switching module 33.

[0084] A first master library acquisition module 31 is used to obtain a first master library of a first shard in a production resource pool in response to a first disaster recovery switching message, and configure the first master library to be in a write-forbidden state;

[0085] A second master database acquisition module 32 is used to acquire a second master database for a second shard in the disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch the used database from the first master database to the second master database;

[0086] The switching module 33 is used to synchronize the second main library with the first main library and configure the second main library to be in a readable and writable state.

[0087] Based on the above embodiment, optionally, a reverse replication module is further included, and the reverse replication module is used to: after the second main library is configured to be readable and writable, establish a reverse replication relationship mapping the second main library to the first main library, and the reverse replication relationship is used for the first main library to synchronize and update according to the data in the first main library.

[0088] Based on the above embodiment, optionally, the first main library acquisition module 31 is used to:

[0089] Obtain a target user associated with a first shard, where the first shard is used to store database data of the target user;

[0090] Determine one or more first associated shards according to the target user; each first associated shard has a one-to-one corresponding second associated shard in the disaster recovery resource pool;

[0091] Disaster recovery switching is performed according to the first associated shard and the corresponding second associated shard.

[0092] Based on the above embodiment, optionally, the switching module 33 is used to:

[0093] Obtain first transaction information of the first main database and second transaction information of the second main database;

[0094] Determine whether the second main database is synchronized with the first main database according to the first transaction information and the second transaction information;

[0095] If they are not synchronized, synchronize the second main database with the first main database.

[0096] Based on the above embodiment, optionally, the switching module 33 is further used for:

[0097] Perform a preset number of query synchronization results at a preset time interval, and if the synchronization results are all inconsistent between the first transaction information and the second transaction information within the preset number of times, triggering a disaster recovery switching interruption;

[0098] If within the preset number of times, the synchronization results are that the first transaction information is consistent with the second transaction information, it is determined that the second main database is synchronized with the first main database.

[0099] On the basis of the above embodiment, optionally, a receiving module is also included, which is used to receive a first disaster recovery switching message sent by a database application according to a database switching requirement before obtaining the first main database of the first shard in the production resource pool in response to the first disaster recovery switching message; or, receive a first disaster recovery switching message sent by a disaster recovery detection application according to a disaster recovery detection result.

[0100] On the basis of the above embodiment, optionally, a reverse switching module 33 is further included, which is used to trigger a second disaster recovery switching message after configuring the second main library to be in a readable and writable state and after a preset switching time, wherein the second disaster recovery switching message is used to switch the database in use from the second main library to the first main library; obtain the second main library of the second shard in the disaster recovery resource pool, and configure the second main library to be in a write-disabled state; obtain the first main library of the first shard in the production resource pool, synchronize the first main library with the second main library, and configure the first main library to be in a readable and writable state.

[0101] The disaster recovery processing device based on database sharding in the embodiment of the present invention comprises a first main library acquisition module 31, which is used to respond to the first disaster recovery switching message, acquire the first main library of the first shard in the production resource pool, and configure the first main library to be in a write-disabled state; a second main library acquisition module 32, which is used to acquire the second main library of the second shard in the disaster recovery resource pool, the second shard being the disaster recovery shard of the first shard, and the first disaster recovery switching message being used to switch the used database from the first main library to the second main library; and a switching module 33, which is used to synchronize the second main library with the first main library, and configure the second main library to be in a readable and writable state. Compared with the current manual disaster recovery switching between the first main library and the second main library, the disaster recovery processing device based on database sharding provided in the embodiment of the present invention can automatically respond to the first disaster recovery switching information from the distributed database, configure the second main library to be in a readable and writable state after configuring the first main library to be in a write-disabled state, and synchronize the second main library with the first main library. If the synchronization is successful, the disaster recovery switching is completed. The disaster recovery switching from the first main library to the second main library is automatically completed, and the disaster recovery switching efficiency is improved. Switching in shards can more accurately switch the database in a shard in the distributed database, thereby improving the accuracy of disaster recovery switching.

[0102] The disaster recovery processing device based on database sharding provided in the embodiment of the present invention can execute the disaster recovery processing method based on database sharding provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0103] Figure 51 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0104] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0105] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0106] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a disaster recovery processing method based on database sharding.

[0107] In some embodiments, the disaster recovery processing method based on database sharding can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the disaster recovery processing method based on database sharding described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to execute the disaster recovery processing method based on database sharding in any other appropriate manner (for example, by means of firmware).

[0108] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0109] The computer program for implementing the database sharding-based disaster recovery processing method of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program can be executed completely on the machine, partially on the machine, partially on the machine and partially on a remote machine as an independent software package, or completely on a remote machine or server.

[0110] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to execute a disaster recovery processing method based on database sharding, the method comprising:

[0111] In response to the first disaster recovery switching message, obtaining a first master library of a first shard in a production resource pool, and configuring the first master library to be in a write-forbidden state;

[0112] Acquire a second master database of a second shard in a disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch a used database from the first master database to the second master database;

[0113] The second main library is synchronized with the first main library, and the second main library is configured to be in a readable and writable state.

[0114] Based on the above embodiment, optionally, after configuring the second main library to be in a readable and writable state, the method further includes:

[0115] A reverse replication relationship is established in which the second master database is mapped to the first master database, and the reverse replication relationship is used for the first master database to perform synchronous update according to the data in the first master database.

[0116] Based on the above embodiment, optionally, obtaining the first main library of the first shard in the production resource pool includes:

[0117] Obtain a target user associated with a first shard, where the first shard is used to store database data of the target user;

[0118] Determine one or more first associated shards according to the target user; each first associated shard has a one-to-one corresponding second associated shard in the disaster recovery resource pool;

[0119] Disaster recovery switching is performed according to the first associated shard and the corresponding second associated shard.

[0120] Based on the above embodiment, optionally, synchronizing the second main library with the first main library includes:

[0121] Obtain first transaction information of the first main database and second transaction information of the second main database;

[0122] Determine whether the second main database is synchronized with the first main database according to the first transaction information and the second transaction information;

[0123] If they are not synchronized, synchronize the second main database with the first main database.

[0124] Based on the above embodiment, optionally, synchronizing the second main library with the first main library includes:

[0125] Perform a preset number of query synchronization results at a preset time interval, and if the synchronization results are all inconsistent between the first transaction information and the second transaction information within the preset number of times, triggering a disaster recovery switching interruption;

[0126] If within the preset number of times, the synchronization results are that the first transaction information is consistent with the second transaction information, it is determined that the second main database is synchronized with the first main database.

[0127] Based on the above embodiment, optionally, before obtaining the first master library of the first shard in the production resource pool in response to the first disaster recovery switching message, the method further includes:

[0128] receiving a first disaster recovery switching message sent by a database application according to a database switching requirement; or,

[0129] A first disaster recovery switching message is received, which is sent by the disaster recovery detection application according to the disaster recovery detection result.

[0130] Based on the above embodiment, optionally, after configuring the second main library to be in a readable and writable state, the method further includes:

[0131] After a preset switching time, a second disaster recovery switching message is triggered, where the second disaster recovery switching message is used to switch the used database from the second primary database to the first primary database;

[0132] Obtain a second master database of a second shard in the disaster recovery resource pool, and configure the second master database to be in a write-forbidden state;

[0133] Obtain a first master library of a first shard in a production resource pool, synchronize the first master library with the second master library, and configure the first master library to be in a readable and writable state.

[0134] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0135] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0136] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0137] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0138] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

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

Claims

1. A disaster recovery processing method based on database sharding, characterized in that: include: In response to the first disaster recovery switching message, obtaining a first master library of a first shard in a production resource pool, and configuring the first master library to be in a write-forbidden state; Acquire a second master database of a second shard in a disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch a used database from the first master database to the second master database; The second main library is synchronized with the first main library, and the second main library is configured to be in a readable and writable state.

2. The method according to claim 1, characterized in that: After configuring the second main library to be in a readable and writable state, the method further includes: A reverse replication relationship is established in which the second master database is mapped to the first master database, and the reverse replication relationship is used for the first master database to perform synchronous update according to the data in the first master database.

3. The method according to claim 1, characterized in that: Get the first master database of the first shard in the production resource pool, including: Obtain a target user associated with a first shard, where the first shard is used to store database data of the target user; Determine one or more first associated shards according to the target user; each first associated shard has a one-to-one corresponding second associated shard in the disaster recovery resource pool; Disaster recovery switching is performed according to the first associated shard and the corresponding second associated shard.

4. The method according to claim 1, characterized in that: Synchronizing the second main library with the first main library includes: Obtain first transaction information of the first main database and second transaction information of the second main database; Determine whether the second main database is synchronized with the first main database according to the first transaction information and the second transaction information; If they are not synchronized, synchronize the second main database with the first main database.

5. The method according to claim 4, characterized in that: Synchronizing the second main library with the first main library includes: Perform a preset number of query synchronization results at a preset time interval, and if the synchronization results are all inconsistent between the first transaction information and the second transaction information within the preset number of times, triggering a disaster recovery switching interruption; If within the preset number of times, the synchronization results are that the first transaction information is consistent with the second transaction information, it is determined that the second main database is synchronized with the first main database.

6. The method according to claim 1, characterized in that: Before obtaining the first master library of the first shard in the production resource pool in response to the first disaster recovery switching message, the method further includes: receiving a first disaster recovery switching message sent by a database application according to a database switching requirement; or, A first disaster recovery switching message is received, which is sent by the disaster recovery detection application according to the disaster recovery detection result.

7. The method according to claim 2, characterized in that: After configuring the second main library to be in a readable and writable state, the method further includes: After a preset switching time, a second disaster recovery switching message is triggered, where the second disaster recovery switching message is used to switch the used database from the second primary database to the first primary database; Obtain a second master database of a second shard in the disaster recovery resource pool, and configure the second master database to be in a write-forbidden state; Obtain a first master library of a first shard in a production resource pool, synchronize the first master library with the second master library, and configure the first master library to be in a readable and writable state.

8. A disaster recovery processing device based on database sharding, characterized in that: include: A first master library acquisition module, configured to acquire a first master library of a first shard in a production resource pool in response to a first disaster recovery switching message, and configure the first master library to be in a write-forbidden state; A second master database acquisition module is used to acquire a second master database for a second shard in a disaster recovery resource pool, where the second shard is a disaster recovery shard of the first shard, and the first disaster recovery switching message is used to switch a used database from the first master database to the second master database; The switching module is used to synchronize the second main library with the first main library and configure the second main library to be in a readable and writable state.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the disaster recovery processing method based on database sharding as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the disaster recovery processing method based on database sharding described in any one of claims 1 to 7 when executed.