Database cluster index page recovery method and related product
By obtaining the empty pages to be removed in the database cluster, recording and recycling transaction numbers, and determining the minimum visible transaction numbers, the problem of difficulty in recycling hollow pages in the Btree index is solved, safe and efficient empty page recycling is achieved, and the resource utilization and execution efficiency of the database cluster is improved.
Patent Information
- Application Number
- CN202411048112.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2025-03-11
AI Technical Summary
In a primary and secondary cluster based on log stream replication, when the backup node plays the primary node operation log, page reuse may cause huge playback delays between the primary and secondary nodes, and the Btree index cannot determine whether the empty page can be safely recycled.
By obtaining the empty page to be removed in the host index tree, removing and recording the recycling transaction number, determining the minimum visible transaction number of the database cluster, and determining whether the recycling conditions are met based on the recycling transaction number and the minimum visible transaction number. If it meets the recycling, the empty page will be recycled.
Taking into account the execution of the primary and secondary databases, safely recycle empty pages in the database cluster, improve the resource utilization rate and index execution efficiency of the database cluster, and reduce overhead.
Smart Images

Figure CN119597751A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a method for recovering a database cluster index page and related products. Background Art
[0002] Most disk-based relational databases support Btree indexes because Btree indexes are comprehensive in terms of concurrent performance, point query, range query, and uniqueness support. In some scenarios with a large number of additions and deletions, if most of the index items are added in sequence, such as some time series data and numbered data, the index will have empty pages that cannot be used by new index items. Recycling and reusing these empty pages is an important technology for optimizing the use of index space. In order to achieve better concurrent capabilities, Btree indexes will not perform large-scale blocking during scanning. Even if a page is removed from the tree, it is impossible to determine whether there is a scan that has just released the father or brother node page and linked to it, and it is difficult to determine whether it can be recycled and reused.
[0003] In a master-slave cluster based on log stream replication, the slave node implements data replication by replaying the operation log of the master node, and the slave node also processes read requests. When replaying a page on the slave node, it is also necessary to consider whether there are concurrent queries on the slave node that may access the page, which may cause a huge playback delay between the master and slave nodes. Summary of the invention
[0004] In view of the above problems, the present invention proposes a method for recovering database cluster index pages and related products that overcome the above problems or at least partially solve the above problems.
[0005] An object of the present invention is to consider the execution status of the primary and standby databases simultaneously, thereby safely reclaiming empty pages in a database cluster.
[0006] A further object of the present invention is to improve the utilization rate of database cluster resources.
[0007] In particular, the present invention provides a method for reclaiming a database cluster index page, which comprises:
[0008] Get the empty page to be removed in the host index tree, where the host index tree is the index tree in the host of the database cluster, and the empty page is the index page with empty data record inside the page;
[0009] Remove the empty page and record the corresponding recycling transaction number of the empty page. The recycling transaction number is the next transaction number to be assigned by the host when removing the empty page.
[0010] Determine the minimum visible transaction number in the database cluster. The minimum visible transaction number includes the minimum visible transaction number of the master and the minimum visible transaction number of the standby in the database cluster.
[0011] Determine whether the empty page removed from the host index tree meets the recycling conditions based on the recycling transaction number and the minimum visible transaction number;
[0012] If so, reclaim the empty page.
[0013] Optionally, before the step of obtaining the empty page to be removed in the host index tree, the step further includes: obtaining a reclaim instruction for reclaiming the empty page;
[0014] The step of determining the minimum visible transaction number in the database cluster includes: obtaining a host snapshot of the host at the time when the database cluster receives a response to the recycle instruction; and determining the minimum visible transaction number of the host according to the host snapshot.
[0015] Optionally, the step of determining the minimum visible transaction number of the host according to the host snapshot includes:
[0016] Get the host detection transaction number recorded in the host snapshot. The host detection transaction number is the next transaction number that the host will allocate when the host snapshot is generated.
[0017] Obtain the host execution transaction number corresponding to the transaction in the execution state in the host, and use the host execution transaction number that is smaller than the host detection transaction number as the host visible transaction number;
[0018] The smallest host execution transaction number among the host visible transaction numbers is selected as the host minimum visible transaction number.
[0019] Optionally, the step of determining the minimum visible transaction number in the database cluster further includes:
[0020] The minimum visible transaction number fed back by the standby machine in the database cluster and whose feedback time is closest to the response time is obtained as the minimum visible transaction number of the standby machine.
[0021] Optionally, the step of the standby machine feeding back the standby machine's minimum visible transaction number includes:
[0022] Generate a snapshot of the standby machine in the standby machine;
[0023] Get the standby machine detection transaction number recorded in the standby machine snapshot. The standby machine detection transaction number is the next transaction number that the standby machine will allocate when the standby machine snapshot is generated.
[0024] Obtain the standby machine execution transaction number corresponding to the transaction in execution state in the standby machine, and use the standby machine execution transaction number that is smaller than the standby machine detection transaction number as the standby machine visible transaction number;
[0025] The smallest standby machine execution transaction number is selected from the standby machine visible transaction numbers as the standby machine minimum visible transaction number.
[0026] Optionally, the step of judging whether the empty page removed from the host index tree meets the recycling condition according to the recycling transaction number and the minimum visible transaction number includes:
[0027] Determine whether the minimum visible transaction number of the master and the minimum visible transaction number of the standby are both greater than or equal to the recycling transaction number;
[0028] If so, it is determined that the empty page is allowed to be recycled.
[0029] Optionally, after the step of reclaiming the empty page, the following step is further included:
[0030] Replay the host's empty page recovery operation on the standby machine.
[0031] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for reclaiming database cluster index pages are implemented.
[0032] According to yet another aspect of the present invention, a computer program product is provided, which includes a computer program. When the computer program is executed by a processor, the computer program implements the steps of any of the above-mentioned methods for reclaiming index pages of a database cluster.
[0033] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements any of the above-mentioned steps of the database cluster index page recycling method when executing the machine executable program.
[0034] The database cluster index page recycling method of the present invention obtains an empty page to be removed in a host index tree, the host index tree is an index tree in a host of a database cluster, and an empty page is an index page whose internal data record is empty; removes the empty page and records the recycling transaction number corresponding to the empty page, the recycling transaction number is the next transaction number to be assigned by the host when removing the empty page; determines the minimum visible transaction number in the database cluster, the minimum visible transaction number includes the minimum visible transaction number of the host and the minimum visible transaction number of the standby in the database cluster; judges whether the empty page removed from the host index tree meets the recycling condition according to the recycling transaction number and the minimum visible transaction number; if so, recycles the empty page. Through this method, it is possible to compare the minimum visible transaction number with the recycling transaction number recorded in the removed empty page to determine whether the removed empty page can be safely recycled while considering the host and standby of the database cluster at the same time, thereby improving the resource utilization of the database cluster and the execution efficiency of the index without excessively increasing the overhead of the database cluster.
[0035] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0037] Figure 1 is a schematic flow chart of a method for recycling a database cluster index page according to an embodiment of the present invention;
[0038] Figure 2 is a flow chart of a method for recycling a database cluster index page according to another embodiment of the present invention;
[0039] Figure 3 is a schematic diagram of a computer-readable storage medium of a method for recycling a database cluster index page according to an embodiment of the present invention;
[0040] Figure 4 is a schematic diagram of a computer program product of a method for reclaiming a database cluster index page according to an embodiment of the present invention; and
[0041] Figure 5 The figure is a schematic diagram of a computer device for a method for recycling a database cluster index page according to an embodiment of the present invention. DETAILED DESCRIPTION
[0042] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0043] In a database cluster, high availability, performance optimization, and data protection are generally provided in the database cluster through the master and standby architecture design to ensure stable service operation and data consistency. In the master database cluster, the master usually bears the responsibility for write operations and handles all write data updates, insertions, modifications, and deletions. It is the authoritative source of data and ensures data consistency. The standby is mainly responsible for read operations and is responsible for processing query requests, reducing the burden on the master and improving system read performance. Since both need to keep data synchronized, the processing method for empty pages should also be consistent. Generally, the master synchronizes data updates to the standby through log files. However, due to the possible delay between the master and the standby, when the master recycles some empty pages, the standby must wait for the completion of such transactions before it can synchronize the master's recycling operations because some transactions are still being executed. The master and the standby will cause different degrees of playback delays due to the length of time such transactions are executed.
[0044] To this end, the present invention proposes the following method to solve the playback delay caused by reclaiming empty pages between the primary and standby machines.
[0045] Figure 1 1 is a flow chart of a method for reclaiming a database cluster index page according to an embodiment of the present invention. In this embodiment, the flow chart generally includes:
[0046] Step S101, obtain the empty page to be removed in the host index tree. The host index tree is the index tree in the host of the database cluster, and the empty page is the index page with empty data records inside the page. For example, in the index tree of the Btree index, each node may have multiple data pages, which are generally called index pages, and are generally used to store multiple data records. When there are many deletion instructions, there may be a situation where all the data records in some index pages are deleted. Such index pages with empty internal data records are generally called empty pages. It is very likely that the empty pages will not be reused in the subsequent use process, so such empty pages need to be recycled and reused. Prior to this, since it is impossible to determine whether such empty pages have been scanned by index pages linked to other nodes, it is difficult to determine whether they can be recycled and reused.
[0047] Optionally, before the step of obtaining the empty page to be removed in the host index tree, the method may also generally include: obtaining a recycling instruction for recycling the empty page. In some optional embodiments, the recycling instruction may be obtained by a technician in the field actively sending it through the database, or the database may automatically generate the recycling instruction according to a pre-set program, such as a set periodic empty page recycling and cleaning function. The technicians in the field may choose the method for obtaining the recycling instruction according to the actual situation.
[0048] Step S102, remove the empty page and record the corresponding recovery transaction number of the empty page. The transaction number refers to the transaction number that is generated in sequence and incrementally when each transaction is executed in the database, so as to distinguish different transactions. The transaction number is unique and incremental for each transaction, and the transaction number created earlier is smaller than the transaction number created later. In this step, when the data page on the index tree becomes idle due to the deletion operation, the database will not delete it permanently, but remove it from the index tree and wait for subsequent reuse. The removal method can generally be to add a mark or move it to the free list. Those skilled in the art can set the removal method according to the actual situation. In addition, when removing the empty page, it is also necessary to record its corresponding recovery transaction number, and the recovery transaction number is the next transaction number to be assigned by the database when removing the empty page.
[0049] Step S103, determining the minimum visible transaction number in the database cluster. The minimum visible transaction number may generally include the minimum visible transaction number of the master and the minimum visible transaction number of the standby in the database cluster.
[0050] In some optional embodiments, for the minimum visible transaction number of the host, the step of determining the minimum visible transaction number in the database cluster may generally include: obtaining a host snapshot of the host at the moment when the database cluster receives a response to the recycle instruction; determining the minimum visible transaction number of the host based on the host snapshot. The snapshot is a function provided by the database management system, which can capture and create a logical copy of the database at a certain point in time without actually copying all the physical data. This function allows users or applications to query the database status at this point in time without affecting the real-time operation or data of the database. Through the snapshot, it is possible to determine whether the empty pages in the database at this time can be safely reclaimed without affecting the normal operation of the database.
[0051] Optionally, the step of determining the minimum visible transaction number of the host according to the host snapshot can generally also include: obtaining the host detection transaction number recorded in the host snapshot, the host detection transaction number is the next transaction number to be assigned by the host when the host snapshot is generated; obtaining the host execution transaction number corresponding to the transaction in the execution state in the host, and taking the host execution transaction number that is smaller than the host detection transaction number as the host visible transaction number; selecting the smallest host execution transaction number from the host visible transaction number as the minimum visible transaction number of the host. In a multi-version database, since the transactions in the snapshot have visibility, that is, since the transactions are generated incrementally, in order to avoid mutual influence between different transactions, only transactions with transaction numbers smaller than their own transaction numbers can be used as visible transaction numbers, and only visible transaction numbers can affect each other. In this step, while generating a snapshot, it is necessary to determine which of the existing transactions in the current database are visible transaction numbers. After determining the visible transaction number, the minimum visible transaction number can be found according to the incremental characteristics of the transaction number, that is, the earliest transaction still running in this snapshot is found as the minimum visible transaction number of the host.
[0052] In other optional embodiments, the logic for obtaining the minimum visible transaction number of the standby machine is similar to that of the minimum visible transaction number of the host machine. The step of determining the minimum visible transaction number in the database cluster may generally further include: obtaining the minimum visible transaction number fed back by the standby machine in the database cluster and the feedback time being closest to the response time as the minimum visible transaction number of the standby machine. It should be noted that the feedback time of the standby machine feeding back the standby machine's minimum visible transaction number may be a periodic feedback set by the system, or it may be a feedback operation synchronously executed by the standby machine when the host machine receives a recycle instruction. Those skilled in the art may select corresponding feedback measures according to the actual performance of the database cluster.
[0053] Optionally, the step of the standby machine feeding back the standby machine's minimum visible transaction number may generally include: generating a standby machine snapshot in the standby machine; obtaining the standby machine detection transaction number recorded in the standby machine snapshot, the standby machine detection transaction number being the next transaction number to be assigned by the standby machine when the standby machine snapshot is generated; obtaining the standby machine execution transaction number corresponding to the transaction in execution state in the standby machine, and using the standby machine execution transaction number that is smaller than the standby machine detection transaction number as the standby machine visible transaction number; selecting the smallest standby machine execution transaction number among the standby machine visible transaction numbers as the standby machine minimum visible transaction number.
[0054] Step S104, judging whether the recycling condition is met. In some optional embodiments, the method of judging whether the recycling condition is met is generally to judge whether the empty page is allowed to be recycled based on the minimum visible transaction number and the recycling transaction number recorded in the removed empty page.
[0055] Optionally, the step of judging whether the empty page removed from the host index tree meets the recycling condition according to the recycling transaction number and the minimum visible transaction number can generally include: judging whether the host minimum visible transaction number and the standby minimum visible transaction number in the minimum visible transaction number are both greater than or equal to the recycling transaction number; if so, judging that the empty page is allowed to be recycled. If the host minimum visible transaction number and the standby minimum visible transaction number in the database cluster are both greater than or equal to the recycling transaction number recorded when the empty page is removed from the host index tree, it means that the earliest transaction in the transaction still running in the current database cluster is no longer associated with the empty page, so it can be determined that the empty page at this time will basically not be referenced by other transactions, and can then be safely recycled.
[0056] Step S105: If the answer in step S104 is yes, reclaim the empty page.
[0057] This method can determine whether the removed empty page can be safely recycled by comparing the minimum visible transaction number with the recycling transaction number recorded in the removed empty page while considering the master and backup machines of the database cluster at the same time. This will improve the resource utilization of the database cluster and the execution efficiency of the index without increasing the overhead of the database cluster too much.
[0058] In some optional embodiments, after the step of reclaiming the empty page, the following step may be generally included: replaying the empty page reclaiming operation of the master in the standby machine. In a database cluster, the master and standby machines generally choose to synchronize data between the master and standby machines through log stream replication, that is, by replaying the operation log of the master. Therefore, when the master determines that the empty page to be recycled will not cause a playback delay between the master and standby machines, the empty page reclaimed by the master is replayed in the standby machine to achieve synchronous recycling between the master and standby machines.
[0059] In addition, in some other optional embodiments, when recording the recovery transaction number of each empty page, those skilled in the art may also choose to record the last transaction number in the empty page, and subsequently only need to determine that the minimum visible transaction number is greater than this transaction number to determine that the empty page can be recovered. However, considering that there may be a large number of index pages in the database system, if each empty page is recorded individually according to this scheme, a large amount of database resources may be consumed. Therefore, the method of the present invention comprehensively considers the actual needs of the database and the corresponding database resource consumption, and selects a unified record to remove the empty page from the index tree. The next transaction number to be assigned by the database, thereby ensuring that the normal recovery of most empty pages is met. Those skilled in the art can choose the recording method of the recovery transaction number according to the actual resource consumption ratio of the database.
[0060] In some optional embodiments, the transaction number may generally include: a commit sequence number, which is a monotonically increasing sequence number and corresponds one-to-one to transactions in the database. Among them, the commit sequence number (CSN) can generally be used to complete the visibility judgment of MVCC (Multi-Version Concurrency Control, MVCC for short) based on the snapshot mechanism of CSN. The basic principles are as follows:
[0061] The database generally assigns a monotonically increasing sequence number / logical timestamp to each submitted transaction and uniquely associates it with the transaction's XID to record the order in which each transaction was submitted. When a transaction snapshot is required, the next CSN number of the current system is obtained and recorded in the current snapshot.
[0062] When you need to use the snapshot to determine the visibility of a transaction, you can obtain the CSN number corresponding to the transaction and compare it with the CSN number recorded in the snapshot. If and only if the CSN number of the transaction is smaller than the CSN number of the snapshot, the transaction is visible to this snapshot; otherwise, if the CSN number of the transaction is smaller than the CSN number of the snapshot, or the transaction has not yet generated a corresponding CSN number, the transaction is not visible to this snapshot.
[0063] A person skilled in the art may also select a mark having the same characteristics as the submission sequence number as the transaction number in the present method according to actual conditions.
[0064] Figure 2 FIG. 1 is a flow chart of a method for reclaiming a database cluster index page according to another embodiment of the present invention. In this embodiment, the flow chart generally includes:
[0065] Step S201, obtaining a recycle instruction for reclaiming an empty page. In some optional embodiments, the recycle instruction may be obtained by a person skilled in the art actively sending it through the database, or the database may automatically generate the recycle instruction according to a pre-set program, such as a set periodic empty page recycle cleaning function. A person skilled in the art may select a method for obtaining the recycle instruction according to actual conditions.
[0066] Step S202, obtain the empty page to be removed in the host index tree. The host index tree is the index tree in the host of the database cluster, and the empty page is the index page with empty data records inside the page. For example, in the index tree of the Btree index, each node may have multiple data pages, and this data page is generally called an index page, which is generally used to store multiple data records. When there are many deletion instructions, there may be a situation where all the data records in some index pages are deleted. For such index pages with empty internal data records, they are generally called empty pages. It is very likely that the empty pages will not be reused in the subsequent use process, so it is necessary to recycle and reuse such empty pages. Prior to this, since it is impossible to determine whether such empty pages have been scanned by index pages linked to other nodes, it is difficult to determine whether they can be recycled and reused.
[0067] Step S203, remove the empty page and record the recovery transaction number corresponding to the empty page. In this step, when the data page on the index tree becomes idle due to the deletion operation, the database will not delete it permanently, but remove it from the index tree and wait for subsequent reuse. The removal method can generally be to add a mark or move it to a free list. Those skilled in the art can set the removal method according to actual conditions. In addition, when removing the empty page, it is also necessary to record its corresponding recovery transaction number, and the recovery transaction number is the next transaction number to be assigned by the database when removing the empty page.
[0068] Step S204, scanning the database for empty pages removed from the index tree.
[0069] Step S205, obtaining the minimum visible transaction number of the host in the host and the minimum visible transaction number of the standby in the standby. Optionally, the step of obtaining the minimum visible transaction number of the host may also generally include: obtaining the host detection transaction number recorded in the host snapshot, the host detection transaction number being the next transaction number to be assigned by the host when the host snapshot is generated; obtaining the host execution transaction number corresponding to the transaction in the execution state in the host, and using the host execution transaction number that is smaller than the host detection transaction number as the host visible transaction number; selecting the smallest host execution transaction number from the host visible transaction numbers as the host minimum visible transaction number.
[0070] Similarly, the step of obtaining the minimum visible transaction number of the standby machine can generally include: obtaining the minimum visible transaction number fed back by the standby machine in the database cluster and the feedback time closest to the response time as the minimum visible transaction number of the standby machine. It should be noted that the feedback time of the standby machine feeding back the minimum visible transaction number of the standby machine can be a periodic feedback set by the system, or it can be a feedback operation synchronously executed by the standby machine when the host receives a recovery instruction. Those skilled in the art can select corresponding feedback measures according to the actual performance of the database cluster.
[0071] Step S206, determine whether the minimum visible transaction number of the host and the minimum visible transaction number of the standby are both greater than or equal to the recycling transaction number. If the minimum visible transaction number of the host and the minimum visible transaction number of the standby in the database cluster are both greater than or equal to the recycling transaction number recorded when the empty page is removed from the host index tree, it means that the current database cluster is still in the running transaction, and the earliest transaction is no longer associated with the empty page. Therefore, it can be determined that the empty page at this time will basically not be referenced by other transactions, and can then be safely recycled.
[0072] Step S207: If the result of step S206 is yes, it is determined that the empty page is allowed to be reclaimed, and the empty page is reclaimed.
[0073] Step S208, replay the empty page recovery operation of the master in the standby machine. In a database cluster, the master and standby machines generally choose to synchronize data between the master and standby machines through log stream replication, that is, by replaying the operation log of the master. Therefore, when the master determines that the recovered empty page will not cause a playback delay between the master and standby machines, the empty page recovered by the master is replayed in the standby machine to achieve synchronous recovery between the master and standby machines.
[0074] This method can determine whether the removed empty page can be safely recycled by comparing the minimum visible transaction number with the recycling transaction number recorded in the removed empty page while considering the master and backup machines of the database cluster at the same time. This will improve the resource utilization of the database cluster and the execution efficiency of the index without increasing the overhead of the database cluster too much.
[0075] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0076] This embodiment also provides a computer-readable storage medium 301 , a computer program product 401 , and a computer device 501 . Figure 3 is a schematic diagram of a computer-readable storage medium of a method for recycling a database cluster index page according to an embodiment of the present invention; Figure 4 is a schematic diagram of a computer program product of a method for reclaiming a database cluster index page according to an embodiment of the present invention; and Figure 5Schematic diagram of a computer device for a database cluster index page recycling method according to an embodiment of the present invention. A computer program product 401 includes a computer program 302, which implements the steps of any of the above-mentioned database cluster index page recycling methods when executed by a processor 303. A computer-readable storage medium 301 stores the above-mentioned computer program 302, which implements the steps of any of the above-mentioned database cluster index page recycling methods when executed by a processor 303. A computer device 501 may include a memory 502, a processor 303, and a computer program 302 stored in the memory 502 and running on the processor 303.
[0077] The computer program 302 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-dependent instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages and a procedural programming language. The computer program 302 may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet Service Provider). In some embodiments, to perform aspects of the present invention, electronic circuits including, for example, programmable logic circuits, Field-Programmable Gate Arrays (FPGAs), or Programmable Logic Arrays (PLAs) may execute computer-readable program instructions by utilizing state information of the computer-readable program instructions to personalize the electronic circuits.
[0078] In the description of this embodiment, computer program product 401 is a related product including computer program 302 .
[0079] For the purposes of the description of this embodiment, computer readable storage medium 301 is a tangible device capable of retaining and storing computer program 302, which can be any device that can contain, store, communicate, propagate or transmit a program for use with or in conjunction with an instruction execution system, device or apparatus. More specific examples (a non-exhaustive list) of computer readable storage medium 301 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.
[0080] Computer device 501 can be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, computer device 501 can be a cloud computing node. Computer device 501 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module can include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. Computer device 501 can be implemented in a distributed cloud computing environment where remote processing devices linked by a communication network perform tasks. In a distributed cloud computing environment, program modules can be located on a local or remote computing system storage medium including a storage device.
[0081] The computer device 501 may include a processor 303 adapted to execute stored instructions, and a memory 502 that provides temporary storage space for the operation of the instructions during operation. The processor 303 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 502 may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0082] The computer device 501 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is typically shown as a communication network.
[0083] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A method for reclaiming a database cluster index page, comprising: Obtaining an empty page to be removed in a host index tree, wherein the host index tree is an index tree in a host of the database cluster, and the empty page is an index page in which data records inside the page are empty; Removing the empty page and recording a recycling transaction number corresponding to the empty page, where the recycling transaction number is the next transaction number to be allocated by the host when removing the empty page; Determine a minimum visible transaction number in the database cluster, where the minimum visible transaction number includes a minimum visible transaction number of a master machine and a minimum visible transaction number of a standby machine in the database cluster; Determining whether the empty page removed from the host index tree meets the recycling condition according to the recycling transaction number and the minimum visible transaction number; If so, the empty page is reclaimed.
2. The method for reclaiming a database cluster index page according to claim 1, wherein: Before the step of obtaining the empty page to be removed in the host index tree, the step further includes: obtaining a recycling instruction for recycling the empty page; The step of determining the minimum visible transaction number in the database cluster includes: obtaining a host snapshot of the host at the moment when the database cluster receives a response to the recycle instruction; and determining the minimum visible transaction number of the host according to the host snapshot.
3. The method for reclaiming a database cluster index page according to claim 2, wherein: The step of determining the minimum visible transaction number of the host according to the host snapshot comprises: Obtaining a host detection transaction number recorded in the host snapshot, where the host detection transaction number is the next transaction number to be allocated by the host when the host snapshot is generated; Obtaining a host execution transaction number corresponding to a transaction in execution state in the host, and using the host execution transaction number that is smaller than the host detection transaction number as the host visible transaction number; The smallest host execution transaction number is selected from the host visible transaction numbers as the host minimum visible transaction number.
4. The method for reclaiming a database cluster index page according to claim 2, wherein: The step of determining the minimum visible transaction number in the database cluster further comprises: The minimum visible transaction number fed back by the standby machine in the database cluster and whose feedback time is closest to the response time is obtained as the minimum visible transaction number of the standby machine.
5. The method for reclaiming a database cluster index page according to claim 4, wherein: The step of the standby machine feeding back the standby machine's minimum visible transaction number comprises: Generate a backup machine snapshot in the backup machine; Obtaining a standby machine detection transaction number recorded in the standby machine snapshot, where the standby machine detection transaction number is the next transaction number to be allocated to the standby machine when the standby machine snapshot is generated; Obtaining a standby machine execution transaction number corresponding to a transaction in execution state in the standby machine, and using the standby machine execution transaction number that is smaller than the standby machine detection transaction number as the standby machine visible transaction number; The smallest standby machine execution transaction number is selected from the standby machine visible transaction numbers as the standby machine minimum visible transaction number.
6. The method for reclaiming a database cluster index page according to claim 1, wherein: The step of judging whether the empty page removed from the host index tree meets the recycling condition according to the recycling transaction number and the minimum visible transaction number comprises: Determine whether the minimum visible transaction number of the host and the minimum visible transaction number of the standby machine in the minimum visible transaction number are both greater than or equal to the recycling transaction number; If so, it is determined that the empty page is allowed to be recycled.
7. The method for reclaiming a database cluster index page according to claim 1, wherein: The step of reclaiming the empty page also includes: The host computer replays the reclaiming operation of the empty page in the standby computer.
8. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for reclaiming a database cluster index page according to any one of claims 1 to 7 are implemented.
9. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method for reclaiming a database cluster index page according to any one of claims 1 to 7.
10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the steps of the database cluster index page recycling method according to any one of claims 1 to 7 when executing the machine executable program.