WO2023142543A1 - 分布式数据库的主备切换方法、装置及可读存储介质 - Google Patents

分布式数据库的主备切换方法、装置及可读存储介质 Download PDF

Info

Publication number
WO2023142543A1
WO2023142543A1 PCT/CN2022/126078 CN2022126078W WO2023142543A1 WO 2023142543 A1 WO2023142543 A1 WO 2023142543A1 CN 2022126078 W CN2022126078 W CN 2022126078W WO 2023142543 A1 WO2023142543 A1 WO 2023142543A1
Authority
WO
WIPO (PCT)
Prior art keywords
data node
data
active
standby
statement
Prior art date
Application number
PCT/CN2022/126078
Other languages
English (en)
French (fr)
Inventor
裴晨光
周家晶
苗浩
吕苏
Original Assignee
中国银联股份有限公司
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 中国银联股份有限公司 filed Critical 中国银联股份有限公司
Publication of WO2023142543A1 publication Critical patent/WO2023142543A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1435Saving, restoring, recovering or retrying at system level using file system or storage system metadata
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support

Definitions

  • the invention belongs to the field of databases, and in particular relates to a master-standby switching method, device and readable storage medium of a distributed database.
  • the database stores data in a multi-copy manner.
  • the main database goes down abnormally, it will automatically switch the standby database to the main database to restore the service. Determining the abnormality of the main database requires multiple confirmations, so as to avoid misjudgments caused by network chatter.
  • the RTO of mainstream databases in the industry such as DB2, TDSQL, GoldenDB, and GuassDB is basically between 10 and 60 seconds. All transactions routed to this instance will fail during the period of active/standby switchover. For example, for centralized databases, all routing All transactions to this instance will fail; for distributed databases, all transactions routed to this node will fail. In some key business scenarios or systems that are more sensitive to the success rate, a transaction failure of tens to tens of seconds will also cause a large loss.
  • the present invention provides the following solutions.
  • a method for active-standby switching of a distributed database includes one or more agents and a plurality of data nodes connected to the agents.
  • the method includes: when the first data node goes down, the second A data node performs active-standby switchover; during the process of active-standby switchover for the first data node, the proxy routes the transaction switch originally routed to the first data node to the second data node; and, when the active-standby switch of the first data node After the switching is completed, the agent switches the routing of the transaction routed to the second data node to the first data node.
  • the method further includes: when the agent continuously detects that the preset response corresponding to the first data node exceeds the preset number of errors, and/or, detects the preset response corresponding to the first data node When the duration of the error report reaches a preset duration, it is determined that the first data node is down; wherein, the preset response error report is used to indicate that the database is down.
  • the method further includes: after the master/standby switchover of the first data node is completed, if the statement routed to the first data node misses data, rerouting the statement to the second data node.
  • the method further includes: after the active-standby switchover of the first data node is completed, relocating the data in the second data node back to the first data node.
  • the method further includes: when relocating the data in the second data node back to the first data node, if the statement routed to the first data node misses the data, rerouting the statement to the second data node .
  • the business transaction is composed of two transactions with strong correlation, wherein transaction 1 is an insert statement, transaction 2 is a query statement and/or an update statement, and when the master-standby switchover of the first data node is completed Afterwards, if the query statement and/or update statement routed to the first data node misses data, the statement is rerouted to the second data node.
  • the second data node is a redundant data node in the distributed database, and is in an idle state when the first data node does not go down.
  • an active/standby switchover device for a distributed database
  • the distributed database includes one or more agents and multiple data nodes connected to the agents
  • the device includes: an active/standby switchover module for when the first When the data node is down, perform active-standby switchover for the first data node; the routing switch module is used to enable the agent to switch the route of the transaction originally routed to the first data node during the process of active-standby switchover for the first data node to the second data node; and, after the master/standby switchover of the first data node is completed, the agent switches the transaction routed to the second data node to the first data node.
  • an active-standby switching device for a distributed database, including: at least one processor; and a memory connected to the at least one processor in communication; wherein, the memory stores instructions executable by the at least one processor, The instructions are executed by at least one processor, so that the at least one processor can perform: the method of the first aspect.
  • a computer-readable storage medium stores a program, and when the program is executed by a multi-core processor, the multi-core processor executes the method in the first aspect.
  • One of the advantages of the above embodiment is that the number of transaction failures during the master-standby switchover of the database can be reduced.
  • Fig. 1 is a schematic structural diagram of the hardware operating environment of the active-standby switching method of a distributed database according to an embodiment of the present invention
  • FIG. 2 is a schematic flow diagram of a master/standby switching method of a distributed database according to an embodiment of the present invention
  • FIG. 3 is a schematic diagram of a distributed database architecture according to an embodiment of the present invention.
  • Fig. 4 is a schematic diagram of transaction composition of a business transaction according to an embodiment of the present invention.
  • Fig. 5 is a schematic structural diagram of an active-standby switching device for a distributed database according to an embodiment of the present invention.
  • FIG. 6 is a schematic structural diagram of an active/standby switching device for a distributed database according to yet another embodiment of the present invention.
  • A/B can mean A or B; "and/or” in this article is just an association relationship describing associated objects, indicating that there can be three relationships, For example, A and/or B may mean that A exists alone, A and B exist simultaneously, and B exists alone.
  • first”, “second”, etc. are used for descriptive purposes only, and should not be understood as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined by “first”, “second”, etc. may expressly or implicitly include one or more of that feature. In the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
  • FIG. 1 is a schematic structural diagram of a hardware operating environment involved in the solution of the embodiment of the present invention.
  • FIG. 1 is a schematic structural diagram of a hardware operating environment of the active-standby switchover method of the distributed database.
  • the active-standby switching device based on the distributed database in the embodiment of the present invention may be a terminal device such as a PC or a portable computer.
  • the active/standby switching device of the distributed database may include: a processor 1001 , such as a CPU, a network interface 1004 , a user interface 1003 , a memory 1005 , and a communication bus 1002 .
  • the communication bus 1002 is used to realize connection and communication between these components.
  • the user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 can be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory.
  • the memory 1005 may also be a storage device independent of the aforementioned processor 1001 .
  • the active-standby switching device structure of the distributed database shown in Figure 1 does not constitute a limitation on the active-standby switching device of the distributed database, and may include more or less components than those shown in the illustration, Or combine certain components, or different component arrangements.
  • the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an information transmission program based on blockchain.
  • the operating system is a program that manages and controls the hardware and software resources of the active-standby switching device of the distributed database, and supports the running of the active-standby switching program of the distributed database and other software or programs.
  • the user interface 1003 is mainly used to receive requests, data, etc. sent by the first terminal, the second terminal, and the monitoring terminal;
  • the network interface 1004 is mainly used to connect the background server and The background server performs data communication;
  • the processor 1001 can be used to call the active-standby switching program of the distributed database stored in the memory 1005, and perform the following operations:
  • the master-backup switchover is performed for the first data node; during the master-backup switchover process for the first data node, the agent switches the transaction originally routed to the first data node to the second a data node; and, after the master/standby switchover of the first data node is completed, the proxy routes the transaction switching route routed to the second data node to the first data node.
  • Fig. 2 is a schematic flow diagram of a master/standby switching method of a distributed database according to an embodiment of the present application.
  • the execution subject may be one or more electronic devices; from the perspective of program, Correspondingly, the execution subject may be a program carried on these electronic devices.
  • the execution subject of the method may be the processor in the embodiment shown in FIG. 1 .
  • Fig. 3 is an architecture diagram of a distributed database according to an embodiment of the present application
  • the distributed database includes a plurality of agents, such as agent 1, agent 2, and a plurality of data nodes, including a first data node, a second data node, etc.
  • the first data node may be a common node running in a distributed database.
  • the second data node may be a redundant node specially set in the distributed database to be used as a temporary backup node when the first data node goes down.
  • the second data node may also be an ordinary node running in the distributed database, instead of being only temporarily reserved.
  • the method shown in FIG. 2 is further described below in conjunction with FIG. 3, and the method may include the following steps:
  • the agent when determining whether the first data node is down, due to the unavoidable network jitter, in order to avoid overly sensitive switching behavior, when the agent continuously detects that the preset response error corresponding to the first data node exceeds When the number of transactions is preset, and/or, when it is detected that the duration of the preset response error report corresponding to the first data node reaches the preset duration, it is determined that the first data node is down.
  • the preset response error is used to indicate that the database is down.
  • the application connection agent sends a request (SQL statement), the agent identifies the sub-database field in the SQL statement, obtains the data node information according to the built-in algorithm, and forwards the SQL statement to the corresponding data node, such as the first data node, and then the first data node will return a response to the proxy, and the proxy will process the response and send it to the application.
  • the agent detects the response error and further identifies whether it is a specific error code. Specifically, it can identify whether the response error is a SQL statement logic error.
  • the error reported in this response is the error reported in the above default response. Furthermore, when it is detected within a short period of time that the number of error reports for the preset response of the first data node reaches the preset number, or the duration of the error report reaches the preset duration, it can be determined that the first data node is down. As a result, overly sensitive switching behavior can be avoided.
  • the agent switches the transaction originally routed to the first data node to the second data node; thus, it can ensure the master-backup switchover of the downtime first data node During the process, subsequent transactions can continue.
  • the proxy routes the transaction switching route routed to the second data node to the first data node.
  • the statement routed to the first data node misses data
  • the statement is rerouted to the second data node. Since the second data node temporarily assumes the role of the first data node during the active-standby switchover process, the data of this period is stored internally. However, subsequent transactions after the route is switched back to the first data node may still be related to this period. The data is related, so the above method can avoid transaction failure.
  • the data in the second data node may be directly migrated back to the first data node. In this way, the integrity of the data in the first data node can be guaranteed, and subsequent frequent rerouting to the second data node to obtain data can be avoided.
  • the data in the second data node may also continue to remain in the second data node without being relocated to the first data node.
  • the statement routed to the first data node misses data
  • the statement is rerouted to the second data node. It can be understood that it will take some time to relocate the data in the second data node back to the first data node. During this process, in order to avoid transaction errors, the above method can be used until the data relocation is completed.
  • a business transaction can be composed of two transactions with strong correlation.
  • the transaction 1 is an insert (Insect) statement
  • the transaction 2 is a query (Select) statement and/or an update (Update) statement
  • the query (Select) statement and/or update (Update) statement of transaction 2 It is very likely that the data will not be hit.
  • first and second are used for descriptive purposes only, and cannot be interpreted as indicating or implying relative importance or implicitly specifying the quantity of indicated technical features.
  • the features defined as “first” and “second” may explicitly or implicitly include at least one of these features.
  • “plurality” means at least two, such as two, three, etc., unless otherwise specifically defined.
  • the embodiment of the present invention also provides a master-standby switchover device for a distributed database, which is used to execute the master-standby switchover method for a distributed database provided in any one of the above embodiments.
  • the distributed database includes one or more agent and multiple data nodes connected to the agent.
  • Fig. 5 is a schematic structural diagram of an active-standby switching device for a distributed database provided by an embodiment of the present invention.
  • the device 500 includes:
  • the active/standby switching module 501 is configured to perform active/standby switching on the first data node when the first data node is down;
  • a route switching module 502 configured to enable the agent to switch the transaction route originally routed to the first data node to the second data node during the master-standby switchover process for the first data node; and, After the master-standby switchover of the first data node is completed, the proxy is made to route the transaction switch routed to the second data node to the first data node.
  • Fig. 6 is a device according to an embodiment of the present application, which is used to execute the active-standby switching method of the distributed database shown in Fig. 2, the device includes: at least one processor; and a memory connected to at least one processor in communication ; Wherein, the memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor, so that at least one processor can execute the methods described in the above-mentioned embodiments.
  • a non-volatile computer storage medium for a master-standby switchover method of a distributed database on which computer-executable instructions are stored, and the computer-executable instructions are configured to be executed when run by a processor : the method described in the foregoing embodiments.
  • the device, device, and computer-readable storage medium provided in the embodiments of the present application correspond to the method one-to-one. Therefore, the device, device, and computer-readable storage medium also have beneficial technical effects similar to their corresponding methods.
  • the beneficial technical effect of the method has been described in detail, therefore, the beneficial technical effect of the device, equipment and computer-readable storage medium will not be repeated here.
  • the embodiments of the present invention may be provided as methods, systems or computer program products. Accordingly, the present invention can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • a computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions
  • the device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
  • a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information.
  • Information may be computer readable instructions, data structures, modules of a program, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic tape cartridge, tape magnetic disk storage or other magnetic storage device or any other non-transmission medium that can be used to store information that can be accessed by a computing device.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • ROM read only memory
  • EEPROM Electrically Erasable Programmable Read-

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Library & Information Science (AREA)
  • Quality & Reliability (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Hardware Redundancy (AREA)

Abstract

本发明提供了分布式数据库的主备切换方法、装置、系统及可读存储介质,该分布式数据库包括一个或多个代理以及与代理连接的多个数据节点,该方法包括:当第一数据节点发生宕机时,对第一数据节点进行主备切换;在对第一数据节点进行主备切换过程中,代理将原本路由到第一数据节点的交易切换路由至第二数据节点;以及,当第一数据节点的主备切换完成后,代理将路由到第二数据节点的交易切换路由至第一数据节点。利用上述方法,能够减少数据库主备切换过程中的交易失败情况。

Description

分布式数据库的主备切换方法、装置及可读存储介质
本申请要求于2022年01月27日提交的、申请号为202210099404.5、标题为“分布式数据库的主备切换方法、装置及可读存储介质”的中国专利申请的优先权,该中国专利申请的公开内容以引用的方式并入本文。
技术领域
本发明属于数据库领域,具体涉及分布式数据库的主备切换方法、装置及可读存储介质。
背景技术
本部分旨在为权利要求书中陈述的本发明的实施方式提供背景或上下文。此处的描述不因为包括在本部分中就承认是现有技术。
数据库存储数据采用多副本方式,当主库异常宕机后会自动将备库切换为主库,从而恢复服务。判定主库异常需要经过多次确认,从而避免网络抖造成的误判。业界主流数据库如DB2、TDSQL、GoldenDB、GuassDB等RTO基本都在10到60秒之间,在主备切换这段时间内路由到这个实例的所有交易都会失败,如:对于集中式数据库,全部路由到该实例的交易都会失败;对于分布式数据库,路由到该节点的交易会全部失败。在某些重点业务场景或者对成功率较为敏感的系统中,十几秒到几十秒的交易失败也会造成较大的损失。
因此,如何进行数据库节点的主备切换是一个亟待解决的问题。
发明内容
针对上述现有技术中存在的问题,提出了一种分布式数据库的主备切换方法、装置及计算机可读存储介质,利用这种方法、装置及计算机可读存储介质,能够解决上述问题。
本发明提供了以下方案。
第一方面,提供一种分布式数据库的主备切换方法,分布式数据库包括一个或多个代理以及与代理连接的多个数据节点,方法包括:当第一数据节点发生宕机时,对第一数据节点进行主备切换;在对第一数据节点进行主备切换过程中,代理将原本路由到第一数据节点的 交易切换路由至第二数据节点;以及,当第一数据节点的主备切换完成后,代理将路由到第二数据节点的交易切换路由至第一数据节点。
在一实施例中,该方法还包括:当代理连续检测到对应于第一数据节点的预设应答报错超过预设笔数时,和/或,检测到对应于第一数据节点的预设应答报错的持续时间达到预设时长,确定第一数据节点发生宕机;其中,预设应答报错用于指示数据库宕机。
在一实施例中,该方法还包括:当第一数据节点的主备切换完成后,如路由到第一数据节点语句未命中数据,则将语句重新路由至第二数据节点。
在一实施例中,该方法还包括:当第一数据节点的主备切换完成后,将第二数据节点内的数据搬迁回第一数据节点。
在一实施例中,该方法还包括:在将第二数据节点内的数据搬迁回第一数据节点时,如路由到第一数据节点语句未命中数据,则将语句重新路由至第二数据节点。
在一实施例中,该业务交易由具有强关联性两个事务组成,其中事务1内为插入语句,事务2内为查询语句和/或更新语句,以及当第一数据节点的主备切换完成后,如路由到第一数据节点的查询语句和/或更新语句未命中数据,则将语句重新路由至第二数据节点。
在一实施例中,第二数据节点为分布式数据库中的冗余数据节点,在第一数据节点未发生宕机的情况下处于空闲状态。
第二方面,提供一种分布式数据库的主备切换装置,其中,分布式数据库包括一个或多个代理以及与代理连接的多个数据节点,装置包括:主备切换模块,用于当第一数据节点发生宕机时,对第一数据节点进行主备切换;路由切换模块,用于在对第一数据节点进行主备切换过程中,使代理将原本路由到第一数据节点的交易切换路由至第二数据节点;以及,当第一数据节点的主备切换完成后,使代理将路由到第二数据节点的交易切换路由至第一数据节点。
第三方面,提供一种分布式数据库的主备切换装置,包括:至少一个处理器;以及,与至少一个处理器通信连接的存储器;其中,存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行:如第一方面的方法。
第四方面,提供一种计算机可读存储介质,计算机可读存储介质存储有程序,当程序被多核处理器执行时,使得多核处理器执行如第一方面的方法。
上述实施例的优点之一,能够减少数据库主备切换期间的交易失败笔数。
本发明的其他优点将配合以下的说明和附图进行更详细的解说。
应当理解,上述说明仅是本发明技术方案的概述,以便能够更清楚地了解本发明的技术手段,从而可依照说明书的内容予以实施。为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举例说明本发明的具体实施方式。
附图说明
通过阅读下文的示例性实施例的详细描述,本领域普通技术人员将明白本文所述的优点和益处以及其他优点和益处。附图仅用于示出示例性实施例的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的标号表示相同的部件。在附图中:
图1为根据本发明一实施例的分布式数据库的主备切换方法的硬件运行环境的结构示意图;
图2为根据本发明一实施例的分布式数据库的主备切换方法的流程示意图;
图3为根据本发明一实施例的分布式数据库的架构示意图;
图4为根据本发明一实施例的业务交易的事务组成示意图;
图5为根据本发明一实施例的分布式数据库的主备切换装置的结构示意图。
图6为根据本发明又一实施例的分布式数据库的主备切换装置的结构示意图。
在附图中,相同或对应的标号表示相同或对应的部分。
具体实施方式
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域技术人员。
在本申请实施例的描述中,应理解,诸如“包括”或“具有”等术语旨在指示本说明书中所公开的特征、数字、步骤、行为、部件、部分或其组合的存在,并且不旨在排除一个或多个其他特征、数字、步骤、行为、部件、部分或其组合存在的可能性。
除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。
术语“第一”、“第二”等仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”等的特征可以明示或者隐含地 包括一个或者更多个该特征。在本申请实施例的描述中,除非另有说明,“多个”的含义是两个或两个以上。
本申请中的所有代码都是示例性的,本领域技术人员根据所使用的编程语言,具体的需求和个人习惯等因素会在不脱离本申请的思想的条件下想到各种变型。
另外还需要说明的是,在不冲突的情况下,本发明中的实施例及实施例中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本发明。
如图1所示,图1是本发明实施例方案涉及的硬件运行环境的结构示意图。
需要说明的是,图1即可为分布式数据库的主备切换方法的硬件运行环境的结构示意图。本发明实施例基于分布式数据库的主备切换设备可以是PC,便携计算机等终端设备。
如图1所示,该分布式数据库的主备切换设备可以包括:处理器1001,例如CPU,网络接口1004,用户接口1003,存储器1005,通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。
本领域技术人员可以理解,图1中示出的分布式数据库的主备切换设备结构并不构成对分布式数据库的主备切换设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
如图1所示,作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及基于区块链的信息传输程序。其中,操作系统是管理和控制分布式数据库的主备切换设备硬件和软件资源的程序,支持分布式数据库的主备切换程序以及其它软件或程序的运行。
在图1所示的分布式数据库的主备切换设备中,用户接口1003主要用于接收第一终端、第二终端和监管终端发送的请求、数据等;网络接口1004主要用于连接后台服务器与后台服务器进行数据通信;而处理器1001可以用于调用存储器1005中存储的分布式数据库的主备切换程序,并执行以下操作:
当第一数据节点发生宕机时,对第一数据节点进行主备切换;在对第一数据节点进行主备切换过程中,代理将原本路由到第一数据节点的交易切换至路由到第二数据节点;以及,当第一数据节点的主备切换完成后,代理将路由到第二数据节点的交易切换回路由至第一数据节点。
由此,能够减少数据库主备切换期间的交易失败笔数。
图2为根据本申请一实施例的分布式数据库的主备切换方法的流程示意图,在该流程中,从设备角度而言,执行主体可以是一个或者多个电子设备;从程序角度而言,执行主体相应地可以是搭载于这些电子设备上的程序。在本实施例中,方法的执行主体可以是图1所示实施例中的处理器。
图3为根据本申请一实施例的分布式数据库的架构图,该分布式数据库包括多个代理,比如代理1、代理2,以及多个数据节点,包括第一数据节点、第二数据节点等。本实施例中,第一数据节点可以是在分布式数据库中运行的普通节点。第二数据节点可以是在分布式数据库中特意设置的冗余节点,以专门用于第一数据节点发生宕机时的临时备用节点。可选地,第二数据节点也可以是在分布式数据库中运行的普通节点,而并非只临时备用。
以下结合图3对图2所示的方法进行进一步描述,该方法可以包括以下步骤:
202、当第一数据节点发生宕机时,对第一数据节点进行主备切换。
在一些实施例中,在确定第一数据节点是否发生宕机时,由于网络抖动不可避免,为避免过于敏感的切换行为,可以当代理连续检测到对应于第一数据节点的预设应答报错超过预设笔数时,和/或,检测到对应于第一数据节点的预设应答报错的持续时间达到预设时长时,再确定第一数据节点发生宕机。其中,预设应答报错用于指示数据库宕机。
例如,在正常交易情况下,应用连接代理发送请求(SQL语句),代理识别该SQL语句中的分库字段,根据内置算法得到数据节点信息,将SQL语句转发到对应数据节点,例如第一数据节点,之后第一数据节点会返回应答给代理,代理将应答处理后发送给应用。然而,如果代理发送给第一数据节点的请求报错,代理检测到应答报错后进一步识别是否是特定报错码,具体可以识别该应答报错是否是SQL语句逻辑报错,如是则认为该异常为数据库宕机,该应答报错为上述预设应答报错。进而,当短时间内检测到针对该第一数据节点的预设应答报错的报错笔数达到预设笔数,或者报错持续时间达到预设时长,则可以确定第一数据节点发生宕机。由此,可以避免过于敏感的切换行为。
204、在对第一数据节点进行主备切换过程中,代理将原本路由到第一数据节点的交易切换至路由到第二数据节点;由此可以保证在宕机的第一数据节点主备切换过程中,后续交易可以继续进行。
206、当第一数据节点的主备切换完成后,代理将路由到第二数据节点的交易切换回路由至第一数据节点。
在一些实施例中,当第一数据节点的主备切换完成后,如路由到第一数据节点语句未命中数据,则将语句重新路由至第二数据节点。由于第二数据节点在主备切换过程中临时承 担了第一数据节点的角色,因此内部保存这一时段的数据,然而在路由切换回该第一数据节点之后的后续交易仍然可能与这一时段的数据相关,因此采用上述方法可以避免发生交易失败。
在一些实施例中,当第一数据节点的主备切换完成后,可以直接将第二数据节点内的数据搬迁回第一数据节点。如此,可以保证第一数据节点内的数据完整度,避免后续需要频繁重新路由到第二数据节点来获取数据。
可选地,第二数据节点内的数据也可继续保留在第二数据节点中,而无需搬迁至第一数据节点。
在一些实施例中,在将第二数据节点内的数据搬迁回第一数据节点时,如路由到第一数据节点语句未命中数据,则将语句重新路由至第二数据节点。可以理解,将第二数据节点内的数据搬迁回第一数据节点需要一段时间,在此过程中,为避免交易发生错误,可以采用上述方法,直至数据搬迁完成。
在一些实施例中,业务交易可以由具有强关联性两个事务组成,参考图4,其中事务1内为插入(Insect)语句,事务2内为查询(Select)语句和/或更新(Update)语句,由于上述事务1和事务2具有强关联性,并且在事务1和事务2之间存在时间t。因此,如在事务1发生在第一数据节点的主备切换时,而事务2发生在第一数据节点的主备切换之后,则事务2的查询(Select)语句和/或更新(Update)语句很可能无法命中数据。因此,可以当第一数据节点的主备切换完成后,如路由到第一数据节点的查询(Select)语句和/或更新(Update)未命中数据,则将语句重新路由至第二数据节点。
在本说明书的描述中,参考术语“一些可能的实施方式”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。
此外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。在本发明的描述中,“多个”的含义是至少两个,例如两个,三个等,除非另有明确具体的限定。
流程图中或在此以其他方式描述的任何过程或方法描述可以被理解为,表示包括一个或更多个用于实现特定逻辑功能或过程的步骤的可执行指令的代码的模块、片段或部分,并且本发明的优选实施方式的范围包括另外的实现,其中可以不按所示出或讨论的顺序,包括根据所涉及的功能按基本同时的方式或按相反的顺序,来执行功能,这应被本发明的实施例所属技术领域的技术人员所理解。
关于本申请实施例的方法流程图,将某些操作描述为以一定顺序执行的不同的步骤。这样的流程图属于说明性的而非限制性的。可以将在本文中所描述的某些步骤分组在一起并且在单个操作中执行、可以将某些步骤分割成多个子步骤、并且可以以不同于在本文中所示出的顺序来执行某些步骤。可以由任何电路结构和/或有形机制(例如,由在计算机设备上运行的软件、硬件(例如,处理器或芯片实现的逻辑功能)等、和/或其任何组合)以任何方式来实现在流程图中所示出的各个步骤。
基于相同的技术构思,本发明实施例还提供一种分布式数据库的主备切换装置,用于执行上述任一实施例所提供的分布式数据库的主备切换方法,分布式数据库包括一个或多个代理以及与代理连接的多个数据节点。图5为本发明实施例提供的一种分布式数据库的主备切换装置结构示意图。
如图5所示,装置500包括:
主备切换模块501,用于当第一数据节点发生宕机时,对所述第一数据节点进行主备切换;
路由切换模块502,用于在对所述第一数据节点进行所述主备切换过程中,使所述代理将原本路由到所述第一数据节点的交易切换路由至第二数据节点;以及,当所述第一数据节点的主备切换完成后,使所述代理将路由到所述第二数据节点的交易切换路由至所述第一数据节点。
需要说明的是,本申请实施例中的装置可以实现前述方法的实施例的各个过程,并达到相同的效果和功能,这里不再赘述。
图6为根据本申请一实施例的装置,用于执行图2所示出的分布式数据库的主备切换方法,该装置包括:至少一个处理器;以及,与至少一个处理器通信连接的存储器;其中,存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行上述实施例所述的方法。
根据本申请的一些实施例,提供了分布式数据库的主备切换方法的非易失性计算机存储介质,其上存储有计算机可执行指令,该计算机可执行指令设置为在由处理器运行时执行:上述实施例所述的方法。
本申请中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于装置、设备和计算机可读存储介质实施例而言,由于其基本相似于方法实施例,所以其描述进行了简化,相关之处可参见方法实施例的部分说明即可。
本申请实施例提供的装置、设备和计算机可读存储介质与方法是一一对应的,因此,装置、设备和计算机可读存储介质也具有与其对应的方法类似的有益技术效果,由于上面已经对方法的有益技术效果进行了详细说明,因此,这里不再赘述装置、设备和计算机可读存储介质的有益技术效果。
本领域内的技术人员应明白,本发明的实施例可提供为方法、系统或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。此外,尽管在附图中以特定顺序描述了本发明方法的操作,但是,这并非要求或者暗示必须按照该特定顺序来执行这些操作,或是必须执行全部所示的操作才能实现期望的结果。附加地或备选地,可以省略某些步骤,将多个步骤合并为一个步骤执行,和/或将一个步骤分解为多个步骤执行。
虽然已经参考若干具体实施方式描述了本发明的精神和原理,但是应该理解,本发明并不限于所公开的具体实施方式,对各方面的划分也不意味着这些方面中的特征不能组合以进行受益,这种划分仅是为了表述的方便。本发明旨在涵盖所附权利要求的精神和范围内所包括的各种修改和等同布置。

Claims (10)

  1. 一种分布式数据库的主备切换方法,所述分布式数据库包括一个或多个代理以及与所述代理连接的多个数据节点,所述方法包括:
    当第一数据节点发生宕机时,对所述第一数据节点进行主备切换;
    在对所述第一数据节点进行所述主备切换过程中,所述代理将原本路由到所述第一数据节点的交易切换路由至第二数据节点;以及,
    当所述第一数据节点的主备切换完成后,所述代理将路由到所述第二数据节点的交易切换路由至所述第一数据节点。
  2. 根据权利要求1所述的方法,其中,还包括:
    当所述代理连续检测到对应于所述第一数据节点的预设应答报错超过预设笔数时,和/或,检测到对应于所述第一数据节点的所述预设应答报错的持续时间达到预设时长,确定所述第一数据节点发生宕机;其中,所述预设应答报错用于指示数据库宕机。
  3. 根据权利要求1或2所述的方法,其中,还包括:
    当所述第一数据节点的主备切换完成后,如路由到所述第一数据节点语句未命中数据,则将所述语句重新路由至所述第二数据节点。
  4. 根据权利要求1-3中任一项所述的方法,其中,还包括:
    当所述第一数据节点的主备切换完成后,将所述第二数据节点内的数据搬迁回所述第一数据节点。
  5. 根据权利要求4所述的方法,其中,还包括:
    在将所述第二数据节点内的数据搬迁回所述第一数据节点时,如路由到所述第一数据节点语句未命中数据,则将所述语句重新路由至所述第二数据节点。
  6. 根据权利要求3-5中任一项所述的方法,其中,业务交易由具有强关联性两个事务组成,其中事务1内为插入语句,事务2内为查询语句和/或更新语句,以及当所述第一数据节点的主备切换完成后,如路由到所述第一数据节点的查询语句和/或更新语句未命中数据,则将所述语句重新路由至所述第二数据节点。
  7. 根据权利要求1-6中任一项所述的方法,其中,还包括:
    所述第二数据节点为所述分布式数据库中的冗余数据节点,在所述第一数据节点未发生宕机的情况下处于空闲状态。
  8. 一种分布式数据库的主备切换装置,所述分布式数据库包括一个或多个代理以及与所述代理连接的多个数据节点,所述装置包括:
    主备切换模块,用于当第一数据节点发生宕机时,对所述第一数据节点进行主备切换;
    路由切换模块,用于在对所述第一数据节点进行所述主备切换过程中,使所述代理将原本路由到所述第一数据节点的交易切换路由至第二数据节点;以及,当所述第一数据节点的主备切换完成后,使所述代理将路由到所述第二数据节点的交易切换路由至所述第一数据节点。
  9. 一种分布式数据库的主备切换装置,包括:
    至少一个处理器;以及,与至少一个处理器通信连接的存储器;其中,存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行:如权利要求1-7中任一项所述的方法。
  10. 一种计算机可读存储介质,所述计算机可读存储介质存储有程序,当所述程序被多核处理器执行时,使得所述多核处理器执行如权利要求1-7中任一项所述的方法。
PCT/CN2022/126078 2022-01-27 2022-10-19 分布式数据库的主备切换方法、装置及可读存储介质 WO2023142543A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210099404.5A CN114443768A (zh) 2022-01-27 2022-01-27 分布式数据库的主备切换方法、装置及可读存储介质
CN202210099404.5 2022-01-27

Publications (1)

Publication Number Publication Date
WO2023142543A1 true WO2023142543A1 (zh) 2023-08-03

Family

ID=81370228

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/126078 WO2023142543A1 (zh) 2022-01-27 2022-10-19 分布式数据库的主备切换方法、装置及可读存储介质

Country Status (2)

Country Link
CN (1) CN114443768A (zh)
WO (1) WO2023142543A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117093406A (zh) * 2023-10-18 2023-11-21 浙江印象软件有限公司 日志中心的维护方法及系统

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114443768A (zh) * 2022-01-27 2022-05-06 中国银联股份有限公司 分布式数据库的主备切换方法、装置及可读存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190179939A1 (en) * 2017-12-11 2019-06-13 International Business Machines Corporation Distributed database having blockchain attributes
CN112783982A (zh) * 2021-02-07 2021-05-11 腾讯科技(深圳)有限公司 数据处理方法、装置、系统、计算机设备和存储介质
CN113254536A (zh) * 2021-06-09 2021-08-13 蚂蚁金服(杭州)网络技术有限公司 数据库事务处理方法、系统、电子设备及存储介质
CN114443768A (zh) * 2022-01-27 2022-05-06 中国银联股份有限公司 分布式数据库的主备切换方法、装置及可读存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190179939A1 (en) * 2017-12-11 2019-06-13 International Business Machines Corporation Distributed database having blockchain attributes
CN112783982A (zh) * 2021-02-07 2021-05-11 腾讯科技(深圳)有限公司 数据处理方法、装置、系统、计算机设备和存储介质
CN113254536A (zh) * 2021-06-09 2021-08-13 蚂蚁金服(杭州)网络技术有限公司 数据库事务处理方法、系统、电子设备及存储介质
CN114443768A (zh) * 2022-01-27 2022-05-06 中国银联股份有限公司 分布式数据库的主备切换方法、装置及可读存储介质

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117093406A (zh) * 2023-10-18 2023-11-21 浙江印象软件有限公司 日志中心的维护方法及系统
CN117093406B (zh) * 2023-10-18 2024-02-09 浙江印象软件有限公司 日志中心的维护方法及系统

Also Published As

Publication number Publication date
CN114443768A (zh) 2022-05-06

Similar Documents

Publication Publication Date Title
WO2023142543A1 (zh) 分布式数据库的主备切换方法、装置及可读存储介质
US11163653B2 (en) Storage cluster failure detection
WO2019085875A1 (zh) 存储集群的配置修改方法、存储集群及计算机系统
US9031910B2 (en) System and method for maintaining a cluster setup
US10838829B2 (en) Method and apparatus for loading data from a mirror server and a non-transitory computer readable storage medium
US20230041089A1 (en) State management methods, methods for switching between master application server and backup application server, and electronic devices
US10795913B2 (en) Synching and reading arrangements for multi-regional active/active databases
CN102158540A (zh) 分布式数据库实现系统及方法
WO2020143410A1 (zh) 数据存储方法及装置、电子设备、存储介质
CN105069152B (zh) 数据处理方法及装置
US20230098190A1 (en) Data processing method, apparatus, device and medium based on distributed storage
WO2021057108A1 (zh) 一种读数据方法、写数据方法及服务器
JP2021524104A (ja) マスター・スタンドバイコンテナシステム切替
WO2017097006A1 (zh) 一种实时数据容错处理方法及系统
CN112307045A (zh) 一种数据同步方法及系统
JP2021051532A (ja) 計算機システム
CN113157701A (zh) 一种oracle数据库的双活机制部署方法及装置
CN111488247B (zh) 一种管控节点多次容错的高可用方法及设备
CN111400273B (zh) 数据库扩容方法、装置、电子设备及机器可读存储介质
CN115982101B (zh) 基于多机房副本放置策略的机房数据迁移方法与装置
TWI531903B (zh) 用於資料備份的存儲系統及備份方法
CN111752892B (zh) 分布式文件系统及其实现方法、管理系统、设备及介质
WO2023029485A1 (zh) 数据处理方法、装置、计算机设备及计算机可读存储介质
CN113342496A (zh) 单实例进程切换方法、系统及存储介质
CN109753292A (zh) 一种在多单实例数据库服务中部署多个应用的方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22923342

Country of ref document: EP

Kind code of ref document: A1