WO2022143065A1 - Database probing method and apparatus - Google Patents

Database probing method and apparatus Download PDF

Info

Publication number
WO2022143065A1
WO2022143065A1 PCT/CN2021/136568 CN2021136568W WO2022143065A1 WO 2022143065 A1 WO2022143065 A1 WO 2022143065A1 CN 2021136568 W CN2021136568 W CN 2021136568W WO 2022143065 A1 WO2022143065 A1 WO 2022143065A1
Authority
WO
WIPO (PCT)
Prior art keywords
detection
database
target
historical
record
Prior art date
Application number
PCT/CN2021/136568
Other languages
French (fr)
Chinese (zh)
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 WO2022143065A1 publication Critical patent/WO2022143065A1/en

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/21Design, administration or maintenance of databases
    • G06F16/219Managing data history or versioning
    • 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
    • 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/23Updating

Definitions

  • the invention relates to the field of databases, in particular to a method and device for detecting activation of a database.
  • databases have been widely used in various industries. Among them, in the process of data transmission between the application server and the database, in order to ensure that the business data can be completely stored in the database, before data transmission, the database corresponding to the application server needs to be probed to determine the database. availability.
  • the database detection result is usually determined according to the feedback of the database to the query instruction.
  • the execution result of the query command can still be fed back based on the standby database, resulting in lower accuracy of the database probing result.
  • the technical problem to be solved by the present invention is to overcome the defect of low accuracy of the database detection results in the prior art, thereby providing a database detection method and device.
  • a first aspect of the present application provides a database detection method, which is applied to a database detection device, and the method includes:
  • the target database is a database corresponding to the current application server
  • the target historical detection record is a historical detection record corresponding to the current application server in a preset detection table.
  • determining the status of the target database according to the update of the target historical detection record by the target database including:
  • the target database is in a normal state.
  • the method further includes:
  • the target historical detection record includes: the historical sending time corresponding to the historical detection and modification instruction;
  • the method further includes:
  • the method further includes:
  • the method before obtaining the detection request of the current application server, the method further includes:
  • the acquisition of the active detection request of the current application server is specifically:
  • the probe request is obtained.
  • a second aspect of the present application provides a database detection method, which is applied to a target database, and the method includes:
  • the detection activity modification instruction update the target historical detection activity record to obtain the updated target historical detection activity record
  • the target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
  • updating the target historical detection record according to the detection modification instruction including:
  • the historical sending time is the sending time of the historical detection and modification instruction.
  • a third aspect of the present application provides a database detection device, comprising: an acquisition module, a detection module and a determination module;
  • the obtaining module is used to obtain the active detection request of the current application server
  • the detection module is configured to send a detection modification instruction to a preset detection table of the target database according to the detection request, so that the target database can perform the detection and activation record of the target according to the detection modification instruction. renew;
  • the determining module is configured to determine the state of the target database according to the update status of the target historical detection record of the target database;
  • the target database is a database corresponding to the current application server
  • the target historical detection record is a historical detection record corresponding to the current application server in a preset detection table.
  • the determining module is specifically used for:
  • the target database is in a normal state.
  • the determining module is further used for:
  • the target historical detection record includes: the historical sending time corresponding to the historical detection and modification instruction;
  • the determining module is also used for:
  • the determining module is further used for:
  • the obtaining module is further used for:
  • the acquisition module is specifically used for:
  • the probe request is obtained.
  • a fourth aspect of the present application provides an electronic device, including: at least one processor and a memory;
  • the memory stores computer-executable instructions
  • the at least one processor executes the computer-implemented instructions stored in the memory to cause the at least one processor to perform the methods described above in the first aspect and various possible designs of the first aspect, or the second aspect and Various possible designs of the second aspect described the method.
  • a fifth aspect of the present application provides a storage medium containing computer-executable instructions, when executed by a computer processor, the computer-executable instructions are used to perform the above first aspect and various possible designs of the first aspect.
  • the database detection method and device provided by the present application obtain the detection request of the current application server; send detection modification instructions to the preset detection table of the target database according to the detection request, so that the target database can be modified according to the detection request.
  • the detection modification instruction is used to update the target historical detection record; the state of the target database is determined according to the update of the target historical detection record by the target database; wherein, the target database is the current The database corresponding to the application server, where the target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
  • the database detection method provided by the above scheme, by presetting a detection table in the target database, and judging whether a write operation can be performed on the detection table, that is, judging whether a write operation can be performed on the target database, and then determine whether the target database is In the normal state, the availability of the target database is reasonably detected, which improves the accuracy of the database detection results.
  • FIG. 1 is a schematic structural diagram of a database activation system based on an embodiment of the application
  • FIG. 2 is a schematic structural diagram of another database activation system based on an embodiment of the application.
  • FIG. 3 is a schematic flowchart of a database detection method according to an embodiment of the present application.
  • FIG. 4 is a schematic flowchart of another database detection method provided in an embodiment of the present application.
  • FIG. 5 is a schematic flowchart of yet another database detection method provided by an embodiment of the present application.
  • FIG. 6 is a schematic structural diagram of a database activation device provided by an embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the database is usually probed based on a database query instruction (for example, a select query statement). If the database can normally feed back the instruction execution result, it is determined that the database is normal and data interaction with the application server can be performed. If the database cannot feed back the instruction execution result, it is determined that the database is abnormal, and the application server is switched to another standby database for data interaction.
  • the semi-synchronous standby database is usually used as the standby database, so when the main database is probed, the data manipulation language function of the main database may appear (Data Manipulation Language, DML for short) is blocked, but the execution result of the query command can still be fed back.
  • the existing database detection technology only detects the readable state of the database, so that the availability of the database cannot be reasonably detected.
  • the database detection method and device obtain the detection request of the current application server; Update the target historical detection record according to the detection modification instruction; determine the status of the target database according to the update of the target database to the target historical detection record; wherein, the target database is the database corresponding to the current application server, and the target historical detection The record is the historical probe record corresponding to the current application server in the preset probe table.
  • the database detection method provided by the above scheme, by presetting a detection table in the target database, and judging whether a write operation can be performed on the detection table, that is, judging whether a write operation can be performed on the target database, and then determine whether the target database is In the normal state, the availability of the target database is reasonably detected, which improves the accuracy of the database detection results.
  • the database activation method and device provided by the embodiments of the present application are suitable for performing activation detection processing on a target database, so as to detect the availability of the target database.
  • FIG. 1 it is a schematic structural diagram of a database activation system based on an embodiment of the application, which mainly includes multiple databases and multiple application servers.
  • the current application server will switch the transaction to other databases (eg database 1, database 2, database n, etc.).
  • the current application server can use the database activation device to probe the target database, and then determine whether the transaction can be switched back.
  • FIG. 2 it is a schematic structural diagram of another database activation system based on the embodiment of the application, which mainly includes a target database, a database activation device for detecting activation of the target database, and a database activation device for sending detection
  • the current application server for live requests.
  • the database detection device After receiving the detection request sent by the current application server, the database detection device sends a detection modification instruction to the target database to modify the detection table in the target database accordingly. Update the status to determine whether the status of the target database is normal.
  • the database detection device sends a corresponding detection result to the current application server, and the current application server determines to perform transaction switchback according to the detection result, and performs data transaction based on the target database.
  • the embodiments of the present application provide a database detection method, which is used to solve the defect of low accuracy of database detection results in the prior art.
  • the execution body of the embodiment of the present application is a database activation device, and the database activation device is deployed on electronic devices, such as servers, desktop computers, notebook computers, tablet computers, and other electronic devices that can be used to detect activation of databases.
  • a schematic flowchart of a database detection method provided in an embodiment of the present application, the method includes:
  • Step 201 obtaining a detection request of the current application server
  • the target database is used to control the main database under the semi-synchronous configuration to wait for the standby database to return an Acknowledgement (ACK for short) report.
  • the parameter of the time of the text rpl_semi_sync_master_timeout, the initial value is 10000, and the unit is milliseconds.
  • this parameter is necessary to adjust this parameter to an infinite value to prevent the active database from switching to the asynchronous standby database due to the timeout of waiting time.
  • the load of the target database is reduced. You can obtain the number of transaction failures between the current application server and the target database; determine whether the number of transaction failures is greater than the preset number of failures threshold; if the number of transaction failures is greater than the preset number of failures threshold, after a preset time interval, determine whether Whether the target database is offline; if the target database is not offline, obtain a probe request.
  • the preset number of failures threshold is 20 and the preset time interval is 20 seconds
  • the current application server sends new transaction data.
  • the detection request of the current application server is obtained, and the detection of the target database is performed to detect the availability of the target database.
  • the business automatic isolation program is a set of independent scripts used to control the mutual judgment of the main and standby databases.
  • Step 202 sending a detection and activation modification instruction to a preset detection activation table of the target database according to the detection activation request, so that the target database updates the target historical detection activation record according to the detection activation modification instruction;
  • the preset detection table is used to store historical detection records corresponding to each application server connected to the target database, and the detection modification instruction is used to update the target historical detection records corresponding to the current application server in the preset detection table.
  • the above-mentioned preset detection table can be established in the target database.
  • the embodiments of the present application provide an exemplary detection table structure:
  • each application server can be used to perform detection in a way that each application server corresponds to a row, that is, the preset detection table can be managed by branch.
  • the above-mentioned "clientip” corresponds to the IP list of the application server on the line, and is marked in the preset detection table in a combined manner.
  • the IP address of the application server can be used as a marker.
  • the "clientip" field value of 192.168.1.1 corresponding to the target database is 19216811.
  • the IP addresses of the application servers in the same local area network are different.
  • Step 203 Determine the status of the target database according to the update status of the target historical detection record of the target database.
  • the target database receives the detection modification instruction and executes the detection modification instruction, under the condition that the state of the target database is the normal state, the target historical detection record corresponding to the current application server Updates are made by modifying the instructions.
  • Step 2031 judging whether the target history detection record is updated successfully
  • Step 2032 in the case that the target historical detection record is successfully updated, determine that the target database is in a normal state.
  • the target database in the case that the update of the historical detection record of the target fails, it is determined that the target database is in an abnormal state.
  • target historical detection record may include the historical sending time corresponding to the historical detection modification instruction.
  • an update instruction (for example, an update update statement) may be used to update the historical detection record in the target database, so as to determine whether the target database is currently in a blocking state.
  • the target database when the target database is in a blocked state, the DML of the target database is blocked, so that the historical detection record of the target cannot be updated. Therefore, it can be determined that the target database is abnormal, that is, the target database is in an abnormal state. On the contrary, it can be determined that the target database is in a normal state and can be used for data transactions, and the current application server can perform a switchback of transaction data.
  • the updated target historical detection record is the same as the original target historical detection record, it is impossible to determine whether the target historical detection record is updated. If it is successful, it will affect the accuracy of the detection results.
  • the historical sending time is the time when the detection and modification instructions are sent before the current time, that is, the historical sending time of the historical detection and modification instructions.
  • the detection results of the detection modification instructions are distinguished.
  • the initial value of "update_time” in the preset detection table is the time when the preset detection table is successfully established to the database, which can be used to record the historical sending time.
  • a detection request of a current application server is obtained; a detection modification instruction is sent to a preset detection table of a target database according to the detection request, so that the target database can be modified according to the detection activation instruction , update the target historical detection record; determine the state of the target database according to the update of the target database to the target historical detection record; wherein, the target database is the database corresponding to the current application server, and the target historical detection record is the current application server The corresponding historical exploration records in the preset exploration table.
  • the database detection method provided by the above scheme, by presetting a detection table in the target database, and judging whether a write operation can be performed on the detection table, that is, judging whether a write operation can be performed on the target database, and then determine whether the target database is In the normal state, the availability of the target database is reasonably detected, which improves the accuracy of the database detection results.
  • the historical sending time in the target historical detection record and the current sending time of the detection modification instruction are used as the basis for judging whether it is updated, so as to avoid repetition and further improve the accuracy of the database detection result.
  • the embodiment of the present application provides a database detection method, which is used to solve the defect of low accuracy of database detection results in the prior art.
  • the execution body of the embodiment of the present application is the target database provided by the above embodiment.
  • FIG. 5 it is a schematic flowchart of still another database detection method provided by the embodiment of the present application, and the method includes:
  • Step 401 obtaining a detection and modification instruction corresponding to the current application server
  • Step 402 update the historical detection record of the target to obtain the updated historical detection record of the target.
  • the target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
  • updating the target historical detection activity record according to the detection activity modification instruction includes:
  • Step 4021 obtaining the sending time of the detection and modification instruction
  • Step 4022 Update the historical sending time in the historical detection record of the target to the sending time of the detection modification instruction.
  • the historical sending time is the sending time of the historical detection and modification instruction.
  • the database activation method provided by the embodiment of the present application corresponds to the database activation method performed by the database activation device provided in the above-mentioned embodiment, and the implementation manner and principle are the same, and are not described again.
  • the embodiments of the present application provide a database detection device, which is used to solve the defect of low accuracy of database detection results in the prior art.
  • FIG. 6 which is a schematic structural diagram of a database detection device provided in an embodiment of the present application, the device 50 includes an acquisition module 501 , a detection module 502 , and a determination module 503 .
  • the acquiring module is used to acquire the detection request of the current application server; the detection module is used to send the detection modification instruction to the preset detection table of the target database according to the detection request, so that the target database can modify the instruction according to the detection activation , to update the target historical detection record; the determining module is used to determine the status of the target database according to the update of the target database to the target historical detection record; wherein, the target database is the database corresponding to the current application server, and the target historical detection The record is the historical probe record corresponding to the current application server in the preset probe table.
  • the determining module is specifically used for:
  • the target database is in a normal state.
  • the determining module is further configured to:
  • the target historical detection record includes: the historical sending time corresponding to the historical detection modification instruction;
  • the determining module is further configured to:
  • the acquisition module is further used for:
  • the database activation device provided in the embodiment of the present application is used to execute the database activation method provided in the above-mentioned embodiment, and the implementation manner is the same as the principle, which will not be repeated.
  • the embodiments of the present application further provide an electronic device for executing the methods provided by the foregoing embodiments.
  • the electronic device 60 includes: at least one processor 61 and a memory 62;
  • the at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the instructions of the method according to any one of the preceding embodiments.
  • An electronic device provided by an embodiment of the present application is used to execute the database activation method provided by the above-mentioned embodiment, and the implementation manner is the same as the principle, which will not be repeated.
  • Embodiments of the present application provide a storage medium containing computer-executable instructions, where the storage medium stores computer-executed instructions, and when the processor executes the computer-executed instructions, the method provided in any of the above embodiments is implemented.
  • the storage medium containing the computer-executable instructions of the embodiments of the present application can be used to store the computer-executable instructions of the database detection method provided in the foregoing embodiments.

Abstract

A database probing method and apparatus. The method comprises: acquiring a probing request of a current application server (201); according to the probing request, sending a probing modification instruction to a preset probing table of a target database, so that the target database updates a target historical probing record according to the probing modification instruction (202); and according to the update status of the target historical probing record in the target database, determining the state of the target database (203), wherein the target database is a database corresponding to the current application server, and the target historical probing record is a historical probing record corresponding to the current application server in the preset probing table. By means of presetting a probing table in the target database, and determining whether a write operation can be performed on the probing table, it is determined whether the target database is in a normal state, and reasonable detection is performed on the availability of the target database, thereby improving the accuracy of a database probing result.

Description

数据库探活方法及装置Database detection method and device
相关申请的交叉引用CROSS-REFERENCE TO RELATED APPLICATIONS
本申请要求于2020年12月28日提交中国专利局,申请号为202011596870.1,发明名称为“一种数据库探活方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed on December 28, 2020 with the application number 202011596870.1 and the invention titled "A method and device for database detection activation", the entire contents of which are incorporated herein by reference middle.
技术领域technical field
本发明涉及数据库领域,具体涉及一种数据库探活方法及装置。The invention relates to the field of databases, in particular to a method and device for detecting activation of a database.
背景技术Background technique
随着网络技术的发展,数据库已经广泛应用到各个行业。其中,在应用服务器与数据库进行数据传输的过程时,为了保证业务数据可以完整地存储至数据库,在进行数据传输前,需要对与该应用服务器对应的数据库进行探活处理,以确定该数据库的可用性。With the development of network technology, databases have been widely used in various industries. Among them, in the process of data transmission between the application server and the database, in order to ensure that the business data can be completely stored in the database, before data transmission, the database corresponding to the application server needs to be probed to determine the database. availability.
在现有技术中,通常是根据数据库对查询指令的反馈情况,确定数据库探活结果。但是,在数据库中的主库发生故障的情况下,依然可以基于备库反馈查询指令的执行结果,导致数据库探活结果的准确性较低。In the prior art, the database detection result is usually determined according to the feedback of the database to the query instruction. However, in the case of failure of the primary database in the database, the execution result of the query command can still be fed back based on the standby database, resulting in lower accuracy of the database probing result.
发明内容SUMMARY OF THE INVENTION
因此,本发明要解决的技术问题在于克服现有技术中的数据库探活结果的准确性较低的缺陷,从而提供一种数据库探活方法及装置。Therefore, the technical problem to be solved by the present invention is to overcome the defect of low accuracy of the database detection results in the prior art, thereby providing a database detection method and device.
本申请第一个方面提供一种数据库探活方法,应用于数据库探活装置,所述方法包括:A first aspect of the present application provides a database detection method, which is applied to a database detection device, and the method includes:
获取当前应用服务器的探活请求;Get the probe request of the current application server;
根据所述探活请求向目标数据库的预设探活表发送探活修改指令,以使所述目标数据库根据所述探活修改指令,对目标历史探活记录进行更新;Send a detection activity modification instruction to a preset detection activity table of the target database according to the detection activity request, so that the target database updates the target historical detection activity record according to the detection activity modification instruction;
根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态;Determine the state of the target database according to the update of the target historical detection record by the target database;
其中,所述目标数据库为所述当前应用服务器对应的数据库,所述目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。The target database is a database corresponding to the current application server, and the target historical detection record is a historical detection record corresponding to the current application server in a preset detection table.
可选的,所述根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态,包括:Optionally, determining the status of the target database according to the update of the target historical detection record by the target database, including:
判断所述目标历史探活记录是否更新成功;Judging whether the historical detection record of the target is successfully updated;
在所述目标历史探活记录更新成功的情况下,确定所述目标数据库为正常状态。In the case that the historical detection record of the target is successfully updated, it is determined that the target database is in a normal state.
可选的,所述方法还包括:Optionally, the method further includes:
在所述目标历史探活记录更新失败的情况下,确定所述目标数据库为异常状态。In the case that the update of the historical detection record of the target fails, it is determined that the target database is in an abnormal state.
可选的,所述目标历史探活记录中包括:历史探活修改指令对应的历史发送时间;Optionally, the target historical detection record includes: the historical sending time corresponding to the historical detection and modification instruction;
则在所述根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态之前,所述方法还包括:Then, before determining the state of the target database according to the update situation of the target historical detection record of the target database, the method further includes:
判断所述历史发送时间是否更改为所述探活修改指令对应的发送时间;Determine whether the historical sending time is changed to the sending time corresponding to the detection and modification instruction;
在所述历史发送时间更改为所述探活修改指令对应的发送时间的情况下,确定所述目标历史探活记录更新成功。In the case that the historical sending time is changed to the sending time corresponding to the probing modification instruction, it is determined that the target historical probing record is updated successfully.
可选的,所述方法还包括:Optionally, the method further includes:
在所述历史发送时间没有更改的情况下,确定所述目标历史探活记录更新失败。In the case that the historical sending time is not changed, it is determined that the update of the historical detection record of the target has failed.
可选的,所述获取当前应用服务器的探活请求之前,所述方法还包括:Optionally, before obtaining the detection request of the current application server, the method further includes:
获取所述当前应用服务器与所述目标数据库之间的交易失败次数;Obtain the number of transaction failures between the current application server and the target database;
判断所述交易失败次数是否大于预设失败次数阈值;Judging whether the number of transaction failures is greater than a preset number of failures threshold;
在所述交易失败次数大于预设失败次数阈值的情况下,在预设时间间隔后,判断所述目标数据库是否下线;In the case that the number of transaction failures is greater than the preset failure number threshold, after a preset time interval, determine whether the target database is offline;
所述获取当前应用服务器的探活请求,具体为:The acquisition of the active detection request of the current application server is specifically:
在所述目标数据库没有下线的情况下,获取所述探活请求。In the case that the target database is not offline, the probe request is obtained.
本申请第二个方面提供一种数据库探活方法,应用于目标数据库,所述方法包括:A second aspect of the present application provides a database detection method, which is applied to a target database, and the method includes:
获取当前应用服务器所对应的探活修改指令;Obtain the detection and modification instructions corresponding to the current application server;
根据所述探活修改指令,对目标历史探活记录进行更新,以得到更新后的目标历史探活记录;According to the detection activity modification instruction, update the target historical detection activity record to obtain the updated target historical detection activity record;
其中,所述目标历史探活记录是当前应用服务器在预设探活表中所对应的历史 探活记录。Wherein, the target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
可选的,所述根据所述探活修改指令,对目标历史探活记录进行更新,包括:Optionally, updating the target historical detection record according to the detection modification instruction, including:
获取所述探活修改指令的发送时间;obtaining the sending time of the detection and modification instruction;
将所述目标历史探活记录中的历史发送时间,更新为所述探活修改指令的发送时间;Update the historical sending time in the target historical detection record to the sending time of the detection and modification instruction;
其中,所述历史发送时间为历史探活修改指令的发送时间。The historical sending time is the sending time of the historical detection and modification instruction.
本申请第三个方面提供一种数据库探活装置,包括:获取模块、探活模块和确定模块;A third aspect of the present application provides a database detection device, comprising: an acquisition module, a detection module and a determination module;
所述获取模块,用于获取当前应用服务器的探活请求;The obtaining module is used to obtain the active detection request of the current application server;
所述探活模块,用于根据所述探活请求向目标数据库的预设探活表发送探活修改指令,以使所述目标数据库根据所述探活修改指令,对目标历史探活记录进行更新;The detection module is configured to send a detection modification instruction to a preset detection table of the target database according to the detection request, so that the target database can perform the detection and activation record of the target according to the detection modification instruction. renew;
所述确定模块,用于根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态;The determining module is configured to determine the state of the target database according to the update status of the target historical detection record of the target database;
其中,所述目标数据库为所述当前应用服务器对应的数据库,所述目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。The target database is a database corresponding to the current application server, and the target historical detection record is a historical detection record corresponding to the current application server in a preset detection table.
可选的,所述确定模块,具体用于:Optionally, the determining module is specifically used for:
判断所述目标历史探活记录是否更新成功;Judging whether the historical detection record of the target is successfully updated;
在所述目标历史探活记录更新成功的情况下,确定所述目标数据库为正常状态。In the case that the historical detection record of the target is successfully updated, it is determined that the target database is in a normal state.
可选的,所述确定模块,还用于:Optionally, the determining module is further used for:
在所述目标历史探活记录更新失败的情况下,确定所述目标数据库为异常状态。In the case that the update of the historical detection record of the target fails, it is determined that the target database is in an abnormal state.
可选的,所述目标历史探活记录中包括:历史探活修改指令对应的历史发送时间;Optionally, the target historical detection record includes: the historical sending time corresponding to the historical detection and modification instruction;
则所述确定模块,还用于:Then the determining module is also used for:
判断所述历史发送时间是否更改为所述探活修改指令对应的发送时间;Determine whether the historical sending time is changed to the sending time corresponding to the detection and modification instruction;
在所述历史发送时间更改为所述探活修改指令对应的发送时间的情况下,确定所述目标历史探活记录更新成功。In the case that the historical sending time is changed to the sending time corresponding to the probing modification instruction, it is determined that the target historical probing record is updated successfully.
可选的,所述确定模块,还用于:Optionally, the determining module is further used for:
在所述历史发送时间没有更改的情况下,确定所述目标历史探活记录更新失 败。In the case that the historical transmission time is not changed, it is determined that the update of the historical detection record of the target has failed.
可选的,所述获取模块,还用于:Optionally, the obtaining module is further used for:
获取所述当前应用服务器与所述目标数据库之间的交易失败次数;Obtain the number of transaction failures between the current application server and the target database;
判断所述交易失败次数是否大于预设失败次数阈值;Judging whether the number of transaction failures is greater than a preset number of failures threshold;
在所述交易失败次数大于预设失败次数阈值的情况下,在预设时间间隔后,判断所述目标数据库是否下线;In the case that the number of transaction failures is greater than the preset failure number threshold, after a preset time interval, determine whether the target database is offline;
所述获取模块,具体用于:The acquisition module is specifically used for:
在所述目标数据库没有下线的情况下,获取所述探活请求。In the case that the target database is not offline, the probe request is obtained.
本申请第四个方面提供一种电子设备,包括:至少一个处理器和存储器;A fourth aspect of the present application provides an electronic device, including: at least one processor and a memory;
所述存储器存储计算机执行指令;the memory stores computer-executable instructions;
所述至少一个处理器执行所述存储器存储的计算机执行指令,使得所述至少一个处理器执行如上第一个方面以及第一个方面各种可能的设计所述的方法,或第二个方面以及第二个方面各种可能的设计所述的方法。The at least one processor executes the computer-implemented instructions stored in the memory to cause the at least one processor to perform the methods described above in the first aspect and various possible designs of the first aspect, or the second aspect and Various possible designs of the second aspect described the method.
本申请第五个方面提供一种包含计算机可执行指令的存储介质,所述计算机可执行指令在由计算机处理器执行时用于执行如上第一个方面以及第一个方面各种可能的设计所述的方法,或第二个方面以及第二个方面各种可能的设计所述的方法。A fifth aspect of the present application provides a storage medium containing computer-executable instructions, when executed by a computer processor, the computer-executable instructions are used to perform the above first aspect and various possible designs of the first aspect. The method described, or the method described in the second aspect and various possible designs of the second aspect.
本申请技术方案,具有如下优点:The technical solution of the present application has the following advantages:
本申请提供的数据库探活方法及装置,通过获取当前应用服务器的探活请求;根据所述探活请求向目标数据库的预设探活表发送探活修改指令,以使所述目标数据库根据所述探活修改指令,对目标历史探活记录进行更新;根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态;其中,所述目标数据库为所述当前应用服务器对应的数据库,所述目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。上述方案提供的数据库探活方法,通过在目标数据库中预设探活表,并判断是否可对该探活表进行写操作,即判断是否可对该目标数据库进行写操作,进而确定目标数据库是否为正常状态,对目标数据库的可用性进行了合理的检测,提高了数据库探活结果的准确性。The database detection method and device provided by the present application obtain the detection request of the current application server; send detection modification instructions to the preset detection table of the target database according to the detection request, so that the target database can be modified according to the detection request. The detection modification instruction is used to update the target historical detection record; the state of the target database is determined according to the update of the target historical detection record by the target database; wherein, the target database is the current The database corresponding to the application server, where the target historical detection record is the historical detection record corresponding to the current application server in the preset detection table. The database detection method provided by the above scheme, by presetting a detection table in the target database, and judging whether a write operation can be performed on the detection table, that is, judging whether a write operation can be performed on the target database, and then determine whether the target database is In the normal state, the availability of the target database is reasonably detected, which improves the accuracy of the database detection results.
附图说明Description of drawings
为了更清楚地说明本发明具体实施方式或现有技术中的技术方案,下面将对具体实施方式或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面 描述中的附图是本发明的一些实施方式,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。In order to illustrate the specific embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the specific embodiments or the prior art. Obviously, the accompanying drawings in the following description The drawings are some embodiments of the present invention, and for those of ordinary skill in the art, other drawings can also be obtained according to these drawings.
图1为本申请实施例基于的一种数据库探活系统的结构示意图;1 is a schematic structural diagram of a database activation system based on an embodiment of the application;
图2为本申请实施例基于的另一种数据库探活系统的结构示意图;2 is a schematic structural diagram of another database activation system based on an embodiment of the application;
图3为本申请实施例提供的一种数据库探活方法的流程示意图;3 is a schematic flowchart of a database detection method according to an embodiment of the present application;
图4为本申请实施例提供的另一种数据库探活方法的流程示意图;4 is a schematic flowchart of another database detection method provided in an embodiment of the present application;
图5为本申请实施例提供的再一种数据库探活方法的流程示意图;5 is a schematic flowchart of yet another database detection method provided by an embodiment of the present application;
图6为本申请实施例提供的数据库探活装置的结构示意图;6 is a schematic structural diagram of a database activation device provided by an embodiment of the present application;
图7为本申请实施例提供的电子设备的结构示意图。FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
具体实施例specific embodiment
下面将结合附图对本发明的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
在现有技术中,通常是基于数据库的查询指令(例如:select查询语句)对数据库进行探活处理。若数据库可以正常反馈指令执行结果,则确定数据库正常,可以与应用服务器进行数据交互,若数据库无法反馈指令执行结果,则确定数据库异常,则将应用服务器切换到其他备用数据库进行数据交互。但是,目前为了保证主库和备库中数据的一致性,通常采用半同步备库作为备库,所以在对主库进行探活时,可能会出现主库数据操纵语言功能(Data Manipulation Language,简称DML)受阻,但是依然可以反馈查询指令执行结果的情况。例如,主备库之间出现了网络闪断,但由于半同步原理,主库即便DML受阻,也依然可以反馈查询指令执行结果。也就是说,现有的数据库探活技术仅对数据库的可读状态进行检测,导致无法对数据库的可用性进行合理的检测。In the prior art, the database is usually probed based on a database query instruction (for example, a select query statement). If the database can normally feed back the instruction execution result, it is determined that the database is normal and data interaction with the application server can be performed. If the database cannot feed back the instruction execution result, it is determined that the database is abnormal, and the application server is switched to another standby database for data interaction. However, at present, in order to ensure the consistency of the data in the main database and the standby database, the semi-synchronous standby database is usually used as the standby database, so when the main database is probed, the data manipulation language function of the main database may appear (Data Manipulation Language, DML for short) is blocked, but the execution result of the query command can still be fed back. For example, there is a network outage between the main and standby databases, but due to the semi-synchronization principle, even if the DML is blocked, the main database can still feed back the execution result of the query command. That is to say, the existing database detection technology only detects the readable state of the database, so that the availability of the database cannot be reasonably detected.
针对上述问题,本申请实施例提供的数据库探活方法及装置,通过获取当前应用服务器的探活请求;根据探活请求向目标数据库的预设探活表发送探活修改指令,以使目标数据库根据探活修改指令,对目标历史探活记录进行更新;根据目标数据库对目标历史探活记录的更新情况,确定目标数据库的状态;其中,目标数据库为当前应用服务器对应的数据库,目标历史探活记录是当前应用服务器在预设探 活表中所对应的历史探活记录。上述方案提供的数据库探活方法,通过在目标数据库中预设探活表,并判断是否可对该探活表进行写操作,即判断是否可对该目标数据库进行写操作,进而确定目标数据库是否为正常状态,对目标数据库的可用性进行了合理的检测,提高了数据库探活结果的准确性。In view of the above problems, the database detection method and device provided by the embodiments of the present application obtain the detection request of the current application server; Update the target historical detection record according to the detection modification instruction; determine the status of the target database according to the update of the target database to the target historical detection record; wherein, the target database is the database corresponding to the current application server, and the target historical detection The record is the historical probe record corresponding to the current application server in the preset probe table. The database detection method provided by the above scheme, by presetting a detection table in the target database, and judging whether a write operation can be performed on the detection table, that is, judging whether a write operation can be performed on the target database, and then determine whether the target database is In the normal state, the availability of the target database is reasonably detected, which improves the accuracy of the database detection results.
下面这几个具体的实施例可以相互结合,对于相同或相似的概念或过程可能在某些实施例中不再赘述。下面将结合附图,对本发明的实施例进行描述。The following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present invention will be described below with reference to the accompanying drawings.
首先,对本申请所基于的数据库探活系统的结构进行说明:First, the structure of the database detection system on which this application is based is explained:
本申请实施例提供的数据库探活方法及装置,适用于对目标数据库进行探活处理,以对目标数据库的可用性进行检测。如图1所示,为本申请实施例基于的一种数据库探活系统的结构示意图,主要包括多个数据库和多个应用服务器,图1中的当前应用服务器所对应的目标数据库发生故障时,当前应用服务器将把交易切换至其他数据库(如数据库1、数据库2、数据库n等)。在与其他数据库进行数据交易的过程中,当前应用服务器可以利用数据库探活装置,对目标数据库进行探活,进而确定是否可以进行交易回切。The database activation method and device provided by the embodiments of the present application are suitable for performing activation detection processing on a target database, so as to detect the availability of the target database. As shown in FIG. 1 , it is a schematic structural diagram of a database activation system based on an embodiment of the application, which mainly includes multiple databases and multiple application servers. When the target database corresponding to the current application server in FIG. 1 fails, The current application server will switch the transaction to other databases (eg database 1, database 2, database n, etc.). In the process of data transaction with other databases, the current application server can use the database activation device to probe the target database, and then determine whether the transaction can be switched back.
其中,如图2所示,为本申请实施例基于的另一种数据库探活系统的结构示意图,主要包括目标数据库、用于对目标数据库进行探活的数据库探活装置,以及用于发送探活请求的当前应用服务器。具体地,该数据库探活装置在接收到当前应用服务器发送的探活请求后,向目标数据库发送探活修改指令,以对目标数据库中的探活表进行相应的修改,根据该探活表的更新情况,判断该目标数据库的状态是否正常。在确定该目标数据库为正常状态的情况下,数据库探活装置向当前应用服务器发送相应的探活结果,当前应用服务器根据该探活结果确定进行交易回切,并基于该目标数据库进行数据交易。Wherein, as shown in FIG. 2 , it is a schematic structural diagram of another database activation system based on the embodiment of the application, which mainly includes a target database, a database activation device for detecting activation of the target database, and a database activation device for sending detection The current application server for live requests. Specifically, after receiving the detection request sent by the current application server, the database detection device sends a detection modification instruction to the target database to modify the detection table in the target database accordingly. Update the status to determine whether the status of the target database is normal. When it is determined that the target database is in a normal state, the database detection device sends a corresponding detection result to the current application server, and the current application server determines to perform transaction switchback according to the detection result, and performs data transaction based on the target database.
本申请实施例提供了一种数据库探活方法,用于解决现有技术中的数据库探活结果的准确性较低的缺陷。本申请实施例的执行主体为数据库探活装置,数据库探活装置部署于电子设备,比如服务器、台式电脑、笔记本电脑、平板电脑及其他可用于对数据库进行探活处理的电子设备。The embodiments of the present application provide a database detection method, which is used to solve the defect of low accuracy of database detection results in the prior art. The execution body of the embodiment of the present application is a database activation device, and the database activation device is deployed on electronic devices, such as servers, desktop computers, notebook computers, tablet computers, and other electronic devices that can be used to detect activation of databases.
如图3所示,为本申请实施例提供的一种数据库探活方法的流程示意图,该方法包括:As shown in FIG. 3 , a schematic flowchart of a database detection method provided in an embodiment of the present application, the method includes:
步骤201,获取当前应用服务器的探活请求; Step 201, obtaining a detection request of the current application server;
需要说明的是,在本申请实施例提供的数据库探活方法应用于半同步数据库的情况下,目标数据库中用于控制半同步配置下主库等待备库返回确认字符 (Acknowledgement,简称ACK)报文的时间的参数:rpl_semi_sync_master_timeout,初始值为10000,单位为毫秒。为了保障主备库数据的一致性,需要将该参数调整为无限大,以避免主库因等待时间超时而切换至异步备库。It should be noted that, in the case where the database activation method provided in the embodiment of the present application is applied to a semi-synchronous database, the target database is used to control the main database under the semi-synchronous configuration to wait for the standby database to return an Acknowledgement (ACK for short) report. The parameter of the time of the text: rpl_semi_sync_master_timeout, the initial value is 10000, and the unit is milliseconds. In order to ensure the data consistency of the active and standby databases, it is necessary to adjust this parameter to an infinite value to prevent the active database from switching to the asynchronous standby database due to the timeout of waiting time.
具体地,在一实施例中,为了减少不必要的数据库探活处理,以降低目标数据库的负载。可以通过获取当前应用服务器与目标数据库之间的交易失败次数;判断交易失败次数是否大于预设失败次数阈值;在交易失败次数大于预设失败次数阈值的情况下,在预设时间间隔后,判断目标数据库是否已下线;在目标数据库没有下线的情况下,获取探活请求。Specifically, in one embodiment, in order to reduce unnecessary database probing processing, the load of the target database is reduced. You can obtain the number of transaction failures between the current application server and the target database; determine whether the number of transaction failures is greater than the preset number of failures threshold; if the number of transaction failures is greater than the preset number of failures threshold, after a preset time interval, determine whether Whether the target database is offline; if the target database is not offline, obtain a probe request.
示例性的,若预设失败次数阈值为20次,预设时间间隔为20秒,则在当前应用服务器与目标数据库之间的交易失败次数达到20次时,当前应用服务器将新的交易数据发送至其他数据库进行存储,在20秒后,判断目标数据库是否已做下线处理,若在20秒之内一直未做下线处理,则可以初步确定目标数据库的故障已经修复。其中,为了进一步确定目标数据库的故障是否已经彻底解除,以保障目标数据库的可用性,则获取当前应用服务器的探活请求,并对目标数据库进行探活处理,以对目标数据库的可用性进行检测。Exemplarily, if the preset number of failures threshold is 20 and the preset time interval is 20 seconds, then when the number of transaction failures between the current application server and the target database reaches 20, the current application server sends new transaction data. Store it in another database. After 20 seconds, determine whether the target database has been offline. If it has not been offline within 20 seconds, it can be preliminarily determined that the fault of the target database has been repaired. Among them, in order to further determine whether the fault of the target database has been completely eliminated to ensure the availability of the target database, the detection request of the current application server is obtained, and the detection of the target database is performed to detect the availability of the target database.
需要解释的是,目前的数据库的下线处理可以是基于部署在主库和备库的业务自动隔离程序来实现的,业务自动隔离程序是一套独立的脚本,用于控制主备库互相判断对方的端口是否正常,在确定对方的端口为异常状态的情况下,进行数据库下线处理。以避免应用服务器在数据库异常的情况下向其发送交易数据,导致大量的数据交易失败。It needs to be explained that the offline processing of the current database can be realized based on the business automatic isolation program deployed in the main database and the standby database. The business automatic isolation program is a set of independent scripts used to control the mutual judgment of the main and standby databases. Check whether the port of the other party is normal. If it is determined that the port of the other party is in an abnormal state, perform database offline processing. In order to avoid the application server sending transaction data to the database in the case of abnormality, resulting in the failure of a large number of data transactions.
步骤202,根据探活请求向目标数据库的预设探活表发送探活修改指令,以使目标数据库根据探活修改指令,对目标历史探活记录进行更新; Step 202, sending a detection and activation modification instruction to a preset detection activation table of the target database according to the detection activation request, so that the target database updates the target historical detection activation record according to the detection activation modification instruction;
其中,预设探活表用于存储与目标数据库连接的各应用服务器对应的历史探活记录,探活修改指令用于更新预设探活表中与当前应用服务器对应的目标历史探活记录。The preset detection table is used to store historical detection records corresponding to each application server connected to the target database, and the detection modification instruction is used to update the target historical detection records corresponding to the current application server in the preset detection table.
需要说明的是,为了保障目标数据库中交易数据的安全性,避免目标数据库中的交易数据因探活操作而遭到破坏,可以在目标数据库中建立上述的预设探活表。It should be noted that, in order to ensure the security of the transaction data in the target database and prevent the transaction data in the target database from being damaged due to the detection operation, the above-mentioned preset detection table can be established in the target database.
示例性的,本申请实施例提供一种示例性的探活表结构:Exemplarily, the embodiments of the present application provide an exemplary detection table structure:
Figure PCTCN2021136568-appb-000001
Figure PCTCN2021136568-appb-000001
Figure PCTCN2021136568-appb-000002
Figure PCTCN2021136568-appb-000002
其中,由于一个目标数据库可以为多个应用服务器提供数据交易的服务,若为每个应用服务器分别建立对应的预设探活表,将会占用目标数据库的大量存储资源,所以为了缓解目标数据库的存储压力,可以建立一个供各应用服务器共用的预设探活表。但是在极端的场景下,如多个应用服务器同时发起探活请求,则可能会出现锁等待的情况,也会对目标数据库的性能产生影响。因此,为了保障目标数据库的性能,避免热点行的存在,可以采用各应用服务器单独对应一行的方式进行探活,即可以对预设探活表进行分行管理。例如:上述“clientip”对应线上的应用服务器的IP列表,通过组合的方式在预设探活表中进行标记。为了保证各应用服务器的标识不重复,以避免数据库探活出现故障,可以采用应用服务器的IP地址作为标记。如192.168.1.1对应到目标数据库的“clientip”字段值为19216811。其中,在同一局域网中的各应用服务器的IP地址是不同的。Among them, since a target database can provide data transaction services for multiple application servers, if a corresponding preset detection table is established for each application server, it will occupy a large amount of storage resources of the target database. To store pressure, it is possible to establish a preset detection table shared by all application servers. However, in extreme scenarios, such as multiple application servers sending active detection requests at the same time, lock waiting may occur, which will also affect the performance of the target database. Therefore, in order to ensure the performance of the target database and avoid the existence of hot-spot rows, each application server can be used to perform detection in a way that each application server corresponds to a row, that is, the preset detection table can be managed by branch. For example, the above-mentioned "clientip" corresponds to the IP list of the application server on the line, and is marked in the preset detection table in a combined manner. In order to ensure that the identifiers of each application server are not duplicated and to avoid the failure of database detection, the IP address of the application server can be used as a marker. For example, the "clientip" field value of 192.168.1.1 corresponding to the target database is 19216811. The IP addresses of the application servers in the same local area network are different.
步骤203,根据目标数据库对目标历史探活记录的更新情况,确定目标数据库的状态。Step 203: Determine the status of the target database according to the update status of the target historical detection record of the target database.
具体地,在目标数据库接收到探活修改指令,并执行该探活修改指令后,在目标数据库的状态为正常状态的情况下,当前应用服务器所对应的目标历史探活记录将因执行探活修改指令而得到更新。Specifically, after the target database receives the detection modification instruction and executes the detection modification instruction, under the condition that the state of the target database is the normal state, the target historical detection record corresponding to the current application server Updates are made by modifying the instructions.
在上述实施例的基础上,为了进一步提高目标数据库的探活结果的准确性,以确定目标数据库的可用性,如图4为本申请实施例提供的另一种数据库探活方法的流程示意图,作为一种可实施的方式,在上述实施例的基础上,在一实施例中,根据目标数据库对目标历史探活记录的更新情况,确定数据库的状态,包括:On the basis of the above-mentioned embodiment, in order to further improve the accuracy of the detection result of the target database and determine the availability of the target database, as shown in FIG. An implementable manner, on the basis of the above-mentioned embodiment, in one embodiment, according to the update situation of the target historical detection activity record of the target database, to determine the status of the database, including:
步骤2031,判断目标历史探活记录是否更新成功; Step 2031, judging whether the target history detection record is updated successfully;
步骤2032,在目标历史探活记录更新成功的情况下,确定目标数据库为正常状态。 Step 2032, in the case that the target historical detection record is successfully updated, determine that the target database is in a normal state.
相应的,在一实施例中,在目标历史探活记录更新失败的情况下,确定目标数据库为异常状态。Correspondingly, in an embodiment, in the case that the update of the historical detection record of the target fails, it is determined that the target database is in an abnormal state.
需要说明的是,目标历史探活记录可以包括历史探活修改指令对应的历史发送时间。It should be noted that the target historical detection record may include the historical sending time corresponding to the historical detection modification instruction.
示例性的,可以采用更新指令(例如:update更新语句)对目标数据库中的历 史探活记录进行更新,以判断目标数据库当前是否处于阻塞状态。其中,在目标数据库处于阻塞状态的情况下,目标数据库的DML受阻,导致目标历史探活记录无法更新,因此可以确定目标数据库发生了异常,即目标数据库为异常状态。相反的,可以确定目标数据库为正常状态,可用于数据交易,当前应用服务器可进行交易数据的回切。Exemplarily, an update instruction (for example, an update update statement) may be used to update the historical detection record in the target database, so as to determine whether the target database is currently in a blocking state. Wherein, when the target database is in a blocked state, the DML of the target database is blocked, so that the historical detection record of the target cannot be updated. Therefore, it can be determined that the target database is abnormal, that is, the target database is in an abnormal state. On the contrary, it can be determined that the target database is in a normal state and can be used for data transactions, and the current application server can perform a switchback of transaction data.
具体地,在一实施例中,为了避免探活修改指令的执行结果出现重复,即更新后的目标历史探活记录和原目标历史探活记录相同,也就无法判断目标历史探活记录是否更新成功,影响探活结果的准确性。Specifically, in one embodiment, in order to avoid repetition of the execution results of the detection modification instruction, that is, the updated target historical detection record is the same as the original target historical detection record, it is impossible to determine whether the target historical detection record is updated. If it is successful, it will affect the accuracy of the detection results.
因此,针对上述问题,可以通过判断历史发送时间是否更改为探活修改指令对应的发送时间;在历史发送时间更改为探活修改指令对应的发送时间的情况下,确定目标历史探活记录更新成功。相应的,在历史发送时间没有更改的情况下,确定目标历史探活记录更新失败。Therefore, in view of the above problems, it is possible to determine whether the historical sending time is changed to the sending time corresponding to the detection and activation modification instruction; if the historical sending time is changed to the sending time corresponding to the detection and activation modification instruction, it is determined that the historical detection and activation record of the target has been successfully updated. . Correspondingly, if the historical sending time is not changed, it is determined that the update of the historical detection activity record of the target fails.
其中,历史发送时间是当前时刻之前发送探活修改指令的时间,即历史探活修改指令的历史发送时间,也就是说,根据发送时间的不同,对各探活修改指令进行区分,进而对各探活修改指令的探活结果进行区分。Among them, the historical sending time is the time when the detection and modification instructions are sent before the current time, that is, the historical sending time of the historical detection and modification instructions. The detection results of the detection modification instructions are distinguished.
示例性的,预设探活表中的“update_time”的初始值为该预设探活表成功建立至数据库的时间,可用于记录历史发送时间。探活修改指令可以为:update is_online set update_time=now()where clientip=`当前应用服务器IP地址`,用于将预设探活表中的“update_time”修改为当前时间。在确定当前应用服务器对应的预设探活表中的“update_time”已被修改为对应的探活指令发送时间的情况下,确定目标历史探活记录更新成功,反之则确定目标历史探活记录更新失败。Exemplarily, the initial value of "update_time" in the preset detection table is the time when the preset detection table is successfully established to the database, which can be used to record the historical sending time. The detection modification instruction can be: update is_online set update_time=now() where clientip=`current application server IP address`, which is used to modify "update_time" in the preset detection table to the current time. If it is determined that the "update_time" in the preset detection table corresponding to the current application server has been modified to the corresponding detection command sending time, it is determined that the historical detection record of the target has been updated successfully; otherwise, it is determined that the historical detection record of the target has been updated. fail.
本申请实施例提供的一种数据库探活方法,获取当前应用服务器的探活请求;根据探活请求向目标数据库的预设探活表发送探活修改指令,以使目标数据库根据探活修改指令,对目标历史探活记录进行更新;根据目标数据库对目标历史探活记录的更新情况,确定目标数据库的状态;其中,目标数据库为当前应用服务器对应的数据库,目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。上述方案提供的数据库探活方法,通过在目标数据库中预设探活表,并判断是否可对该探活表进行写操作,即判断是否可对该目标数据库进行写操作,进而确定目标数据库是否为正常状态,对目标数据库的可用性进行了合理的检测,提高了数据库探活结果的准确性。并且,以目标历史探活记录中的历史发送时间和当前的探活修改指令的发送时间,作为其是否更新的判断依据,避免出现重复,进一步提 高了数据库探活结果的准确性。In a database detection method provided by an embodiment of the present application, a detection request of a current application server is obtained; a detection modification instruction is sent to a preset detection table of a target database according to the detection request, so that the target database can be modified according to the detection activation instruction , update the target historical detection record; determine the state of the target database according to the update of the target database to the target historical detection record; wherein, the target database is the database corresponding to the current application server, and the target historical detection record is the current application server The corresponding historical exploration records in the preset exploration table. The database detection method provided by the above scheme, by presetting a detection table in the target database, and judging whether a write operation can be performed on the detection table, that is, judging whether a write operation can be performed on the target database, and then determine whether the target database is In the normal state, the availability of the target database is reasonably detected, which improves the accuracy of the database detection results. In addition, the historical sending time in the target historical detection record and the current sending time of the detection modification instruction are used as the basis for judging whether it is updated, so as to avoid repetition and further improve the accuracy of the database detection result.
本申请实施例提供了一种数据库探活方法,用于解决现有技术中的数据库探活结果的准确性较低的缺陷。本申请实施例的执行主体为上述实施例提供的目标数据库。The embodiment of the present application provides a database detection method, which is used to solve the defect of low accuracy of database detection results in the prior art. The execution body of the embodiment of the present application is the target database provided by the above embodiment.
如图5所示,为本申请实施例提供的再一种数据库探活方法的流程示意图,该方法包括:As shown in FIG. 5, it is a schematic flowchart of still another database detection method provided by the embodiment of the present application, and the method includes:
步骤401,获取当前应用服务器所对应的探活修改指令; Step 401, obtaining a detection and modification instruction corresponding to the current application server;
步骤402,根据探活修改指令,对目标历史探活记录进行更新,以得到更新后的目标历史探活记录。 Step 402 , according to the detection modification instruction, update the historical detection record of the target to obtain the updated historical detection record of the target.
其中,目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。The target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
具体地,在一实施例中,根据探活修改指令,对目标历史探活记录进行更新,包括:Specifically, in one embodiment, updating the target historical detection activity record according to the detection activity modification instruction includes:
步骤4021,获取探活修改指令的发送时间;Step 4021, obtaining the sending time of the detection and modification instruction;
步骤4022,将目标历史探活记录中的历史发送时间,更新为探活修改指令的发送时间。Step 4022: Update the historical sending time in the historical detection record of the target to the sending time of the detection modification instruction.
其中,历史发送时间为历史探活修改指令的发送时间。The historical sending time is the sending time of the historical detection and modification instruction.
本申请实施例提供的数据库探活方法,与上述实施例提供的由数据库探活装置执行的数据库探活方法相对应,其实现方式与原理相同,不再赘述。The database activation method provided by the embodiment of the present application corresponds to the database activation method performed by the database activation device provided in the above-mentioned embodiment, and the implementation manner and principle are the same, and are not described again.
本申请实施例提供了一种数据库探活装置,用于解决现有技术中的数据库探活结果的准确性较低的缺陷。如图6所示,为本申请实施例提供的数据库探活装置的结构示意图,该装置50包括:获取模块501、探活模块502和确定模块503。The embodiments of the present application provide a database detection device, which is used to solve the defect of low accuracy of database detection results in the prior art. As shown in FIG. 6 , which is a schematic structural diagram of a database detection device provided in an embodiment of the present application, the device 50 includes an acquisition module 501 , a detection module 502 , and a determination module 503 .
其中,获取模块,用于获取当前应用服务器的探活请求;探活模块,用于根据探活请求向目标数据库的预设探活表发送探活修改指令,以使目标数据库根据探活修改指令,对目标历史探活记录进行更新;确定模块,用于根据目标数据库对目标历史探活记录的更新情况,确定目标数据库的状态;其中,目标数据库为当前应用服务器对应的数据库,目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。Wherein, the acquiring module is used to acquire the detection request of the current application server; the detection module is used to send the detection modification instruction to the preset detection table of the target database according to the detection request, so that the target database can modify the instruction according to the detection activation , to update the target historical detection record; the determining module is used to determine the status of the target database according to the update of the target database to the target historical detection record; wherein, the target database is the database corresponding to the current application server, and the target historical detection The record is the historical probe record corresponding to the current application server in the preset probe table.
具体地,在一实施例中,确定模块,具体用于:Specifically, in an embodiment, the determining module is specifically used for:
判断目标历史探活记录是否更新成功;Determine whether the target's historical detection record is successfully updated;
在目标历史探活记录更新成功的情况下,确定目标数据库为正常状态。In the case that the historical detection record of the target is successfully updated, it is determined that the target database is in a normal state.
具体地,在一实施例中,确定模块,还用于:Specifically, in an embodiment, the determining module is further configured to:
在目标历史探活记录更新失败的情况下,确定目标数据库为异常状态。In the case that the update of the target historical detection record fails, it is determined that the target database is in an abnormal state.
具体地,在一实施例中,目标历史探活记录中包括:历史探活修改指令对应的历史发送时间;Specifically, in one embodiment, the target historical detection record includes: the historical sending time corresponding to the historical detection modification instruction;
则确定模块,还用于:then determines the module, and is also used to:
判断历史发送时间是否更改为探活修改指令对应的发送时间;Determine whether the historical sending time has been changed to the sending time corresponding to the activation modification instruction;
在历史发送时间更改为探活修改指令对应的发送时间的情况下,确定目标历史探活记录更新成功。If the historical sending time is changed to the sending time corresponding to the probing modification instruction, it is determined that the target historical probing record is updated successfully.
具体地,在一实施例中,确定模块,还用于:Specifically, in an embodiment, the determining module is further configured to:
在历史发送时间没有更改的情况下,确定目标历史探活记录更新失败。In the case that the historical sending time has not changed, it is determined that the update of the historical detection activity record of the target fails.
具体地,在一实施例中,获取模块,还用于:Specifically, in one embodiment, the acquisition module is further used for:
获取当前应用服务器与目标数据库之间的交易失败次数;Get the number of transaction failures between the current application server and the target database;
判断交易失败次数是否大于预设失败次数阈值;Determine whether the number of transaction failures is greater than the preset number of failures threshold;
在交易失败次数大于预设失败次数阈值的情况下,在预设时间间隔后,判断目标数据库是否下线;In the case that the number of transaction failures is greater than the preset number of failures threshold, after a preset time interval, determine whether the target database is offline;
则获取模块,具体用于:Then get the module, specifically for:
在目标数据库没有下线的情况下,获取探活请求。Obtain a probe request when the target database is not offline.
本申请实施例提供的数据库探活装置,用于执行上述实施例提供的数据库探活方法,其实现方式与原理相同,不再赘述。The database activation device provided in the embodiment of the present application is used to execute the database activation method provided in the above-mentioned embodiment, and the implementation manner is the same as the principle, which will not be repeated.
本申请实施例还提供了一种电子设备,用于执行上述实施例提供的方法。The embodiments of the present application further provide an electronic device for executing the methods provided by the foregoing embodiments.
如图7所示,为本申请实施例提供的电子设备的结构示意图。该电子设备60包括:至少一个处理器61和存储器62;As shown in FIG. 7 , it is a schematic structural diagram of an electronic device provided in an embodiment of the present application. The electronic device 60 includes: at least one processor 61 and a memory 62;
其中,至少一个处理器执行存储器存储的计算机执行指令,使得至少一个处理器执行如前述实施例中任一项的方法的指令。Wherein, the at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the instructions of the method according to any one of the preceding embodiments.
本申请实施例提供的一种电子设备,用于执行上述实施例提供的数据库探活方法,其实现方式与原理相同,不再赘述。An electronic device provided by an embodiment of the present application is used to execute the database activation method provided by the above-mentioned embodiment, and the implementation manner is the same as the principle, which will not be repeated.
本申请实施例提供了一种包含计算机可执行指令的存储介质,存储介质中存储有计算机处理器执行指令,当处理器执行计算机执行指令时,实现如上任一实施例提供的方法。Embodiments of the present application provide a storage medium containing computer-executable instructions, where the storage medium stores computer-executed instructions, and when the processor executes the computer-executed instructions, the method provided in any of the above embodiments is implemented.
本申请实施例的包含计算机可执行指令的存储介质,可用于存储前述实施例中提供的数据库探活方法的计算机执行指令,其实现方式与原理相同,不再赘述。The storage medium containing the computer-executable instructions of the embodiments of the present application can be used to store the computer-executable instructions of the database detection method provided in the foregoing embodiments.
显然,上述实施例仅仅是为清楚地说明所作的举例,而并非对实施方式的限定。对于所属领域的普通技术人员来说,在上述说明的基础上还可以做出其它不同形式的变化或变动。这里无需也无法对所有的实施方式予以穷举。而由此所引伸出的显而易见的变化或变动仍处于本发明创造的保护范围之中。Obviously, the above-mentioned embodiments are only examples for clear description, and are not intended to limit the implementation manner. For those of ordinary skill in the art, changes or modifications in other different forms can also be made on the basis of the above description. There is no need and cannot be exhaustive of all implementations here. And the obvious changes or changes derived from this are still within the protection scope of the present invention.

Claims (11)

  1. 一种数据库探活方法,应用于数据库探活装置,其中,所述方法包括:A database detection method, applied to a database detection device, wherein the method comprises:
    获取当前应用服务器的探活请求;Get the probe request of the current application server;
    根据所述探活请求向目标数据库的预设探活表发送探活修改指令,以使所述目标数据库根据所述探活修改指令,对目标历史探活记录进行更新;Send a detection activity modification instruction to a preset detection activity table of the target database according to the detection activity request, so that the target database updates the target historical detection activity record according to the detection activity modification instruction;
    根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态;Determine the state of the target database according to the update of the target historical detection record by the target database;
    其中,所述目标数据库为所述当前应用服务器对应的数据库,所述目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。The target database is a database corresponding to the current application server, and the target historical detection record is a historical detection record corresponding to the current application server in a preset detection table.
  2. 根据权利要求1所述的数据库探活方法,其中,所述根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态,包括:The database detection method according to claim 1, wherein the determining the status of the target database according to the update of the target historical detection record by the target database comprises:
    判断所述目标历史探活记录是否更新成功;Judging whether the historical detection record of the target is successfully updated;
    在所述目标历史探活记录更新成功的情况下,确定所述目标数据库为正常状态;In the case that the historical detection record of the target is successfully updated, determine that the target database is in a normal state;
    在所述目标历史探活记录更新失败的情况下,确定所述目标数据库为异常状态。In the case that the update of the historical detection record of the target fails, it is determined that the target database is in an abnormal state.
  3. 根据权利要求2所述的数据库探活方法,其中,所述目标历史探活记录中包括:历史探活修改指令对应的历史发送时间;The database detection method according to claim 2, wherein the target historical detection record includes: the historical sending time corresponding to the historical detection modification instruction;
    在所述根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态之前,所述方法还包括:Before determining the state of the target database according to the update status of the target historical detection record of the target database, the method further includes:
    判断所述历史发送时间是否更改为所述探活修改指令对应的发送时间;Determine whether the historical sending time is changed to the sending time corresponding to the detection and modification instruction;
    在所述历史发送时间更改为所述探活修改指令对应的发送时间的情况下,确定所述目标历史探活记录更新成功;In the case where the historical sending time is changed to the sending time corresponding to the probing modification instruction, it is determined that the target historical probing record is updated successfully;
    在所述历史发送时间没有更改的情况下,确定所述目标历史探活记录更新失败。In the case that the historical sending time is not changed, it is determined that the update of the historical detection record of the target has failed.
  4. 根据权利要求1所述的数据库探活方法,其中,所述获取当前应用服务器的探活请求之前,所述方法还包括:The database detection method according to claim 1, wherein, before acquiring the detection request of the current application server, the method further comprises:
    获取所述当前应用服务器与所述目标数据库之间的交易失败次数;Obtain the number of transaction failures between the current application server and the target database;
    判断所述交易失败次数是否大于预设失败次数阈值;Judging whether the number of transaction failures is greater than a preset number of failures threshold;
    在所述交易失败次数大于预设失败次数阈值的情况下,在预设时间间隔后,判 断所述目标数据库是否下线;In the case that the number of transaction failures is greater than the preset number of failures threshold, after a preset time interval, determine whether the target database is offline;
    所述获取当前应用服务器的探活请求,具体为:The acquisition of the active detection request of the current application server is specifically:
    在所述目标数据库没有下线的情况下,获取所述探活请求。In the case that the target database is not offline, the probe request is obtained.
  5. 根据权利要求1所述的数据库探活方法,其中,在根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态之后,所述方法还包括:The database detection method according to claim 1, wherein after determining the state of the target database according to the update of the target historical detection record by the target database, the method further comprises:
    在确定所述目标数据库的状态为正常状态的情况下,向所述当前应用服务器发送对应的探活结果,以使所述当前应用服务器根据所述探活结果进行交易回切。When it is determined that the state of the target database is a normal state, a corresponding detection result is sent to the current application server, so that the current application server performs transaction switchback according to the detection result.
  6. 一种数据库探活方法,应用于目标数据库,其中,所述方法包括:A database detection method, applied to a target database, wherein the method comprises:
    获取数据库探活装置发送的当前应用服务器所对应的探活修改指令;Obtain the detection modification instruction corresponding to the current application server sent by the database detection device;
    根据所述探活修改指令,对目标历史探活记录进行更新,以得到更新后的目标历史探活记录;According to the detection activity modification instruction, update the target historical detection activity record to obtain the updated target historical detection activity record;
    将所述更新后的目标历史探活记录发送至数据库探活装置,以使所述数据库探活装置根据所述更新后的目标历史探活记录,确定所述目标数据库的状态;sending the updated target historical detection record to the database detection device, so that the database detection device determines the state of the target database according to the updated target historical detection record;
    其中,所述目标历史探活记录是当前应用服务器在预设探活表中所对应的历史探活记录。The target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
  7. 根据权利要求6所述的数据库探活方法,其中,所述根据所述探活修改指令,对目标历史探活记录进行更新,包括:The database detection method according to claim 6, wherein the updating the target historical detection record according to the detection modification instruction comprises:
    获取所述探活修改指令的发送时间;obtaining the sending time of the detection and modification instruction;
    将所述目标历史探活记录中的历史发送时间,更新为所述探活修改指令的发送时间;Update the historical sending time in the target historical detection record to the sending time of the detection and modification instruction;
    其中,所述历史发送时间为历史探活修改指令的发送时间。The historical sending time is the sending time of the historical detection and modification instruction.
  8. 一种数据库探活装置,其中,所述装置包括:获取模块、探活模块和确定模块;A database detection device, wherein the device comprises: an acquisition module, a detection module and a determination module;
    所述获取模块,用于获取当前应用服务器的探活请求;The obtaining module is used to obtain the active detection request of the current application server;
    所述探活模块,用于根据所述探活请求向目标数据库的预设探活表发送探活修改指令,以使所述目标数据库根据所述探活修改指令,对目标历史探活记录进行更新;The detection module is configured to send a detection modification instruction to a preset detection table of the target database according to the detection request, so that the target database can perform the detection and activation record of the target according to the detection modification instruction. renew;
    所述确定模块,用于根据所述目标数据库对所述目标历史探活记录的更新情况,确定所述目标数据库的状态;The determining module is configured to determine the state of the target database according to the update status of the target historical detection record of the target database;
    其中,所述目标数据库为所述当前应用服务器对应的数据库,所述目标历史探 活记录是当前应用服务器在预设探活表中所对应的历史探活记录。Wherein, the target database is the database corresponding to the current application server, and the target historical detection record is the historical detection record corresponding to the current application server in the preset detection table.
  9. 一种数据库探活系统,其中,所述系统包括数据库探活装置、目标数据库以及当前应用服务器,所述数据库探活装置用于执行如权利要求1-5任一项所述的方法,所述目标数据库用于执行如权利要求6或7所述的方法。A database detection system, wherein the system includes a database detection device, a target database and a current application server, the database detection device is used to execute the method according to any one of claims 1-5, the The target database is used to perform the method of claim 6 or 7.
  10. 一种电子设备,其中,所述电子设备包括:至少一个处理器和存储器;An electronic device, wherein the electronic device includes: at least one processor and a memory;
    所述存储器存储计算机执行指令;the memory stores computer-executable instructions;
    所述至少一个处理器执行所述存储器存储的计算机执行指令,使得所述至少一个处理器执行如权利要求1-5任一项所述的方法,或权利要求6或7所述的方法。The at least one processor executes computer-implemented instructions stored in the memory to cause the at least one processor to perform the method of any one of claims 1-5, or the method of claim 6 or 7.
  11. 一种包含计算机可执行指令的存储介质,其中,所述计算机可执行指令在由计算机处理器执行时用于执行如权利要求1-5任一项所述的方法,或权利要求6或7所述的方法。A storage medium containing computer-executable instructions, wherein the computer-executable instructions, when executed by a computer processor, are used to perform the method of any one of claims 1-5, or the method of claim 6 or 7. method described.
PCT/CN2021/136568 2020-12-28 2021-12-08 Database probing method and apparatus WO2022143065A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011596870.1 2020-12-28
CN202011596870.1A CN114691640A (en) 2020-12-28 2020-12-28 Database survival detection method and device

Publications (1)

Publication Number Publication Date
WO2022143065A1 true WO2022143065A1 (en) 2022-07-07

Family

ID=82131666

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/136568 WO2022143065A1 (en) 2020-12-28 2021-12-08 Database probing method and apparatus

Country Status (2)

Country Link
CN (1) CN114691640A (en)
WO (1) WO2022143065A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108241469A (en) * 2016-12-27 2018-07-03 北京金山云网络技术有限公司 A kind of date storage method, apparatus and system
WO2019062022A1 (en) * 2017-09-30 2019-04-04 平安科技(深圳)有限公司 Database modification method and application server
CN109587258A (en) * 2018-12-14 2019-04-05 北京金山云网络技术有限公司 Activating method and device are visited in a kind of service
CN109739674A (en) * 2018-12-17 2019-05-10 网联清算有限公司 Method for detecting abnormality, device and the storage medium of transaction data base
CN111726337A (en) * 2020-05-14 2020-09-29 北京邮电大学 Equipment asset detection method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108241469A (en) * 2016-12-27 2018-07-03 北京金山云网络技术有限公司 A kind of date storage method, apparatus and system
WO2019062022A1 (en) * 2017-09-30 2019-04-04 平安科技(深圳)有限公司 Database modification method and application server
CN109587258A (en) * 2018-12-14 2019-04-05 北京金山云网络技术有限公司 Activating method and device are visited in a kind of service
CN109739674A (en) * 2018-12-17 2019-05-10 网联清算有限公司 Method for detecting abnormality, device and the storage medium of transaction data base
CN111726337A (en) * 2020-05-14 2020-09-29 北京邮电大学 Equipment asset detection method and device

Also Published As

Publication number Publication date
CN114691640A (en) 2022-07-01

Similar Documents

Publication Publication Date Title
US10360113B2 (en) Transaction recovery in a transaction processing computer system employing multiple transaction managers
US6742059B1 (en) Primary and secondary management commands for a peripheral connected to multiple agents
KR100711396B1 (en) Server duplexing method and duplexed server system
KR100575497B1 (en) Fault tolerant computer system
US7900085B2 (en) Backup coordinator for distributed transactions
US7318138B1 (en) Preventing undesired trespass in storage arrays
US7747717B2 (en) Fast application notification in a clustered computing system
US7293194B2 (en) Method and device for switching database access part from for-standby to currently in use
US10185636B2 (en) Method and apparatus to virtualize remote copy pair in three data center configuration
US20200019543A1 (en) Method, apparatus and device for updating data, and medium
US20140081927A1 (en) Data node fencing in a distributed file system
US20080288812A1 (en) Cluster system and an error recovery method thereof
US7899897B2 (en) System and program for dual agent processes and dual active server processes
US9164864B1 (en) Minimizing false negative and duplicate health monitoring alerts in a dual master shared nothing database appliance
CN106843749A (en) Write request processing method, device and equipment
US11784905B2 (en) Method and apparatus for ensuring continued device operational reliability in cloud-degraded mode
US9069632B2 (en) Message processing
US10860411B2 (en) Automatically detecting time-of-fault bugs in cloud systems
WO2022143065A1 (en) Database probing method and apparatus
CN112732492A (en) Extraction backup method and system based on cloud database
CN113596195B (en) Public IP address management method, device, main node and storage medium
US20220138177A1 (en) Fault tolerance for transaction mirroring
JP2004110801A (en) Technique for inspecting propriety of re-initialized channel-to-channel connection
US8533331B1 (en) Method and apparatus for preventing concurrency violation among resources
US8601224B2 (en) Control unit for storage apparatus and method for controlling storage apparatus

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: 21913806

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21913806

Country of ref document: EP

Kind code of ref document: A1