A method for replaying logs on a data node, a data node and a system
By replaying transaction commit logs and page operation logs in parallel on the data nodes, the problem of slow log playback speed on the standby machine is solved and the efficiency of database recovery is improved.
Patent Information
- Application Number
- CN202010615640.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-06-30
AI Technical Summary
With the existing log playback method, after a server failure, the backup machine needs to play back all logs before it can provide data services, resulting in slow log playback speed and affecting database recovery time.
The transaction submission log and page operation log are played back in parallel through multiple threads on the data node, and the transaction submission log and page operation log are played back independently to reduce synchronization between threads and improve the playback speed.
By replaying logs in parallel, the log playback speed is significantly accelerated, the waiting time after the standby machine is upgraded to the master machine, and the database recovery efficiency is improved.
Smart Images

Figure CN113868028B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of database technology, and in particular to a method for replaying a log on a data node, a data node, and a system. Background Art
[0002] In order to ensure the normal operation of the server, at least two data nodes are usually established in the server, one data node as the master and the other data nodes as the backup. Under normal circumstances, the master provides data services, and the backup guarantees data consistency with the master by replaying the transaction logs in the master. When the master fails or shuts down for other reasons, the backup will be promoted to the master, that is, the backup will provide data services.
[0003] However, if there are unfinished logs on the standby machine, the standby machine needs to replay all logs before it can provide data services. Therefore, in order to enable the standby machine to provide data services as quickly as possible, the standby machine will randomly assign the logs to be replayed to multiple threads, so that multiple threads can replay logs in parallel to increase the playback speed of logs.
[0004] In the existing log playback method, all logs corresponding to a transaction must be played back before the log corresponding to the next transaction can be played back, so the log playback speed is still not fast enough. Summary of the invention
[0005] The embodiments of the present application provide a method for replaying logs on a data node, a data node, and a database system. The method can speed up the playback of logs.
[0006] In a first aspect, the present application provides a method for replaying logs on a data node, wherein multiple threads are running on the data node; the method comprises:
[0007] The data node obtains multiple logs, and the multiple logs include at least one transaction commit log and at least one page operation log. Each transaction commit log in the at least one transaction commit log includes a transaction commit operation, and each page operation log in the at least one page operation log includes one or more operations on a page. Specifically, the page operation log may only include an insert operation on a row in a specific page; in addition to an insert operation on a row in a specific page, the page operation log may also include a delete operation on another row in the specific page; the page operation log may include an insert operation on two rows in a specific page, and a delete operation on a row in the specific page.
[0008] The data node replays at least one transaction commit log through a first thread among multiple threads. Generally, the first thread replays at least one transaction commit log in sequence according to the log sequence number LSN of the transaction commit log. The data node replays at least one page operation log through at least one second thread among multiple threads. All page operation logs containing operations on the same page in the at least one page operation log are replayed by the same second thread. The same second thread can replay page operation logs containing operations on different pages. The process of the first thread replaying at least one transaction commit log is independent of the process of at least one second thread replaying at least one page operation log.
[0009] Since the playback of all page operation logs containing operations on the same page is performed by the same second thread, there is no need to synchronize the playback progress of the logs between threads. Compared with the playback of all page operation logs containing operations on the same page being performed by multiple second threads, the playback speed of the logs can be accelerated. The process of the first thread playing back the transaction commit log is independent of the process of any second thread playing back the page operation log. Therefore, even if the transaction commit log corresponding to the current transaction has not been played back, the page operation log corresponding to the next transaction can be played back, thereby further accelerating the playback speed.
[0010] In one implementation, the data node obtains multiple logs including: obtaining at least one transaction commit log and at least one operation log from a buffer; the data node parses at least one operation log at a page granularity to obtain at least one page operation log, each operation log in the at least one operation log contains operations on one or more pages; the at least one page operation log includes a first page operation log, and a log sequence number LSN of the first page operation log is the same as the LSN of the operation log obtained by parsing the first page operation log.
[0011] Compared with reading logs from a data storage device, reading multiple logs from a buffer can reduce the number of input / output I / O times of the data storage device, speed up log reading, and thus speed up log playback; and this implementation method provides a feasible solution for obtaining page operation logs.
[0012] In one implementation, the method also includes: the data node determines the maximum visible LSN, the maximum visible LSN is used to indicate the playback progress of the log; all transaction commit logs in at least one transaction commit log whose log sequence number LSN is less than or equal to the maximum visible LSN are played back, and all page operation logs in at least one page operation log whose log sequence number LSN is less than or equal to the maximum visible LSN are played back.
[0013] If the LSN corresponding to one of the multiple logs is the first LSN, and all transaction commit logs whose LSN is less than or equal to the first LSN in at least one transaction commit log are replayed, and all page operation logs whose LSN is less than or equal to the first LSN in at least one page operation log are replayed, the first LSN is used as the maximum visible LSN, thereby avoiding the situation where the maximum visible LSN error is caused by discontinuous log playback. Therefore, the maximum visible LSN in this implementation can more accurately represent the playback progress of the log, so as to ensure data consistency through the playback progress.
[0014] In one implementation, the data node replays at least one transaction commit log through the first thread among multiple threads, including: the data node replays at least one transaction commit log in LSN order on the initial version of the first page through the first thread among multiple threads to obtain multiple versions of the first page, and each version of the multiple versions of the first page is associated with at least one of the at least one transaction commit log. Among them, the embodiment of the present application does not specifically limit the number of versions of the first page. The multiple versions of the first page include a first version of the first page, and a second version of the first page generated based on the first version of the first page, and the second version of the first page is obtained by replaying the transaction commit log associated with the first version of the first page in LSN order on the first version of the first page.
[0015] Based on multiple versions of the first page, you can view the content of the first page after replaying any transaction commit log.
[0016] In one implementation, the method further includes: after obtaining multiple versions of the first page, the data node writes the multiple versions of the first page into a double write file; the data node writes the multiple versions of the first page in the Double write file into a data file.
[0017] The data node first writes multiple versions of the first page into the Double write file, and then writes the multiple versions of the first page from the Double write file into the Data file, thereby ensuring that the multiple versions of the first page are not damaged.
[0018] In one implementation, on the initial version of the first page, each time a certain number of transaction commit logs are replayed, a version of the first page is generated, so the number of transaction commit logs associated with each of the multiple versions of the first page is the same.
[0019] In one implementation, on the initial version of the first page, a version of the first page is generated each time a transaction commit log of a period of time is replayed, so the transaction commit log associated with each of the multiple versions of the first page has the same replay time.
[0020] In one implementation, the method further includes: in response to a first indication, the first indication is used to query the playback progress of at least one transaction commit log, and the data node plays back the transaction commit log associated with the baseline version of the first page in LSN order on the baseline version of the first page until the first transaction commit log is played back to obtain the target version of the first page. The first indication can be in multiple forms. The baseline version of the first page is a version associated with the first transaction commit log among multiple versions of the first page, and the first transaction commit log is a log with the largest LSN among at least one transaction commit log, and the LSN is less than or equal to the maximum visible LSN;
[0021] A playback progress of at least one transaction commit representation log is determined based on the target version of the first page.
[0022] Based on multiple versions of the first page and the maximum visible LSN, the log playback progress can be fed back in real time and accurately to ensure data consistency.
[0023] In one implementation, the data node replays at least one page operation log through at least one second thread among multiple threads, including: the data node replays all page operation logs containing operations on the second page in at least one page operation log in LSN order on the initial version of the second page through a second thread among the multiple threads to obtain multiple versions of the second page, and each version of the multiple versions of the second page is associated with at least one of all page operation logs containing operations on the second page. Among them, the embodiment of the present application does not specifically limit the number of versions of the second page. The multiple versions of the second page include a first version of the second page, and a second version of the second page generated based on the first version of the second page, and the second version of the second page is obtained by replaying the page operation log associated with the first version of the second page in LSN order on the first version of the second page.
[0024] Based on multiple versions of the second page, you can view the content of the second page after replaying any page operation log.
[0025] In one implementation, the method further includes: after obtaining multiple versions of the second page, the data node writes the multiple versions of the second page into a double write file; the data node writes the multiple versions of the second page in the Double write file into a data file.
[0026] The data node first writes the multiple versions of the second page into the Double write file, and then writes the multiple versions of the second page from the Double write file into the Data file, thereby ensuring that the multiple versions of the second page are not damaged.
[0027] In one implementation, on the initial version of the second page, each time a certain number of transaction commit logs are replayed, a version of the second page is generated, so the number of page operation logs associated with each of the multiple versions of the second page is the same.
[0028] In one implementation, on the initial version of the second page, a version of the second page is generated each time a page operation log of a certain period of time is replayed, so the page operation log associated with each of the multiple versions of the second page has the same replay time.
[0029] In one implementation, the method further includes: in response to a second indication, the second indication is used to query the playback progress of at least one page operation log, the data node plays back the transaction commit log associated with the target version of the second page in LSN order on the baseline version of the second page until the first page operation log is played back to obtain the target version of the second page; the baseline version of the second page is a version associated with the first page operation log among multiple versions of the second page, and the first page operation log is a log with the largest LSN among all page operation logs containing operations on the second page, and the LSN is less than or equal to the maximum visible LSN;
[0030] At least one page operation log is determined based on the target version of the second page to represent the playback progress of the log.
[0031] Based on multiple versions of the second page and the maximum visible LSN, the log playback progress can be fed back in real time and accurately to ensure data consistency.
[0032] A second aspect of the present application provides a data node, on which multiple threads run; the data node includes:
[0033] an acquisition unit, configured to acquire a plurality of logs, the plurality of logs comprising at least one transaction commit log and at least one page operation log, each transaction commit log in the at least one transaction commit log comprising a transaction commit operation, and each page operation log in the at least one page operation log comprising one or more operations on a page;
[0034] A first playback unit, configured to play back at least one transaction commit log through a first thread among the multiple threads;
[0035] A second playback unit, configured to play back at least one page operation log through at least one second thread among the multiple threads, wherein all page operation logs containing operations on the same page in the at least one page operation log are played back by the same second thread;
[0036] The process of the first thread replaying at least one transaction commit log is independent of the process of the at least one second thread replaying at least one page operation log.
[0037] In one implementation, an acquisition unit is used to acquire at least one transaction commit log and at least one operation log from a buffer; parse at least one operation log to obtain at least one page operation log, each operation log in the at least one operation log contains operations on one or more pages; at least one page operation log includes a first page operation log, and an LSN of the first page operation log is the same as the LSN of the operation log obtained by parsing the first page operation log.
[0038] In one implementation, the data node also includes a determination unit for determining a maximum visible LSN, where the maximum visible LSN is used to indicate the playback progress of the log; all transaction commit logs in at least one transaction commit log whose log sequence number LSN is less than or equal to the maximum visible LSN are played back, and all page operation logs in at least one page operation log whose log sequence number LSN is less than or equal to the maximum visible LSN are played back.
[0039] In one implementation, a first playback unit is used to play back at least one transaction commit log on an initial version of a first page in LSN order through a first thread among multiple threads to obtain multiple versions of the first page, each of the multiple versions of the first page is associated with at least one of the at least one transaction commit log; the multiple versions of the first page include a first version of the first page, and a second version of the first page generated based on the first version of the first page, the second version of the first page is obtained by playing back the transaction commit log associated with the first version of the first page in LSN order on the first version of the first page.
[0040] In one implementation, the data node further includes a writing unit, which is used to write the multiple versions of the first page into a double write file; and write the multiple versions of the first page in the Double write file into a data file.
[0041] In one implementation, the number of transaction commit logs associated with each of the multiple versions of the first page is the same, or the playback time of the transaction commit logs associated with each of the multiple versions of the first page is the same.
[0042] In one implementation, the first playback unit is also used to respond to a first indication, where the first indication is used to query the playback progress of at least one transaction commit log, and to play back the transaction commit log associated with the baseline version of the first page in LSN order on the baseline version of the first page until the first transaction commit log is played back to obtain the target version of the first page.
[0043] The base version of the first page is a version associated with the first transaction commit log among multiple versions of the first page, and the first transaction commit log is a log with the largest LSN among at least one transaction commit log, and the LSN is less than or equal to the maximum visible LSN;
[0044] The first page-based target version is used to represent the playback progress of at least one transaction commit log.
[0045] In one implementation, the second playback unit is used to play back all page operation logs containing operations on the second page in at least one page operation log in LSN order on the initial version of the second page through a second thread among the multiple threads to obtain multiple versions of the second page, each version of the multiple versions of the second page is associated with at least one of all page operation logs containing operations on the second page.
[0046] The multiple versions of the second page include a first version of the second page and a second version of the second page generated based on the first version of the second page. The second version of the second page is obtained by replaying the page operation log associated with the first version of the second page in LSN order on the first version of the second page.
[0047] In one implementation, the data node further includes a writing unit, which is used to write the multiple versions of the second page into a double write file; and write the multiple versions of the second page in the Double write file into a data file.
[0048] In one implementation, the number of page operation logs associated with each of the multiple versions of the second page is the same, or the playback time of the page operation log associated with each of the multiple versions of the second page is the same.
[0049] In one implementation, the second playback unit is further configured to respond to a second indication, the second indication being used to query the playback progress of at least one page operation log, and to play back the transaction commit log associated with the baseline version of the second page in LSN order on the baseline version of the second page until the first page operation log is played back to obtain a target version of the second page;
[0050] The base version of the second page is a version associated with the first page operation log among multiple versions of the second page, and the first page operation log is a log with the largest LSN among all page operation logs containing operations on the second page, and the LSN is less than or equal to the maximum visible LSN;
[0051] A playback progress of at least one page operation log is determined based on the target version of the second page.
[0052] The third aspect of the present application provides a data node, comprising: at least one processor and a memory, the memory storing computer execution instructions that can be run on the processor, when the computer execution instructions are executed by the processor, the data node executes the method for replaying logs on the data node as described in any one of the embodiments of the first aspect above.
[0053] In a fourth aspect, the present application provides a chip or a chip system, which includes at least one processor and a communication interface, the communication interface and the at least one processor are interconnected by a line, and the at least one processor is used to run a computer program or instruction to execute the method for replaying logs on a data node as described in any one of the embodiments of the first aspect above.
[0054] A fifth aspect of the present application provides a computer storage medium, the computer storage medium is used to store computer software instructions used by the above-mentioned terminal device, which includes a program designed for executing a data node;
[0055] The data node may be the data node described in the third aspect above.
[0056] A sixth aspect of the present application provides a computer program product, which includes computer software instructions, which can be loaded by a processor to implement a method for replaying logs on a data node as described in any one of the embodiments of the first aspect above.
[0057] A seventh aspect of the present application provides a database system, including: a host machine and at least one backup machine.
[0058] The master is used to send logs to at least one standby machine;
[0059] Each of the at least one standby machine is used to play back the log according to the method described in any one of the implementations of the first aspect above.
[0060] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0061] The playback of all page operation logs containing operations on the same page is performed by the same second thread, so there is no need to synchronize the playback progress of the logs between threads. Compared with the playback of all page operation logs containing operations on the same page being performed by multiple second threads, the playback speed of the logs can be accelerated; the process of the first thread playing back the transaction commit log is independent of the process of any second thread playing back the page operation log, so even if the transaction commit log corresponding to the current transaction has not been played back, the page operation log corresponding to the next transaction can be played back, thereby further accelerating the playback speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1A It is a schematic diagram of a stand-alone database system;
[0063] Figure 1B It is a schematic diagram of a cluster database system using a shared-nothing architecture;
[0064] Figure 2This is a schematic diagram of a first embodiment of a method for replaying a log in an embodiment of the present application;
[0065] Figure 3 This is a schematic diagram of a second embodiment of the method for replaying logs in an embodiment of the present application;
[0066] Figure 4 A schematic diagram of a third embodiment of the method for replaying a log in an embodiment of the present application;
[0067] Figure 5 A schematic diagram of a fourth embodiment of a method for replaying a log in an embodiment of the present application;
[0068] FIG6( a ) is a schematic diagram of a first architecture of a database system in an embodiment of the present application;
[0069] FIG6( b ) is a schematic diagram of a first architecture of a database system in an embodiment of the present application;
[0070] Figure 7 This is a schematic diagram of a second architecture of a database system in an embodiment of the present application;
[0071] Figure 8 This is a schematic diagram of the third architecture of the database system in the embodiment of the present application;
[0072] Fig. 9 A schematic diagram of an embodiment of a data node in an embodiment of the present application;
[0073] Fig.10 A schematic diagram of an embodiment of a data node in an embodiment of the present application;
[0074] Fig.11 Schematic diagram of the structure of the database system in the embodiment of the present application. DETAILED DESCRIPTION
[0075] The following describes the embodiments of the present application in conjunction with the accompanying drawings. Obviously, the described embodiments are only embodiments of a part of the present application, rather than all embodiments. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0076] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0077] The method provided in the embodiment of the present application can be applied to a database system. A database system (database system) generally consists of the following three parts: (1) Database (DB), which refers to a collection of organized, shareable data stored in a computer for a long time. The data in the database is organized, described and stored according to a certain mathematical model, has low redundancy, high data independence and easy scalability, and can be shared by various users. (2) Hardware, including data storage devices required to store data, such as memory and / or disk. (3) Software, including DBMS (database management system). DBMS is the core software of the database system. It is a system software used to scientifically organize and store data, and efficiently acquire and maintain data. The database engine is the core component of DBMS.
[0078] Specifically, Figure 1A As shown, Figure 1A This is a schematic diagram of a cluster database system that uses a shared-nothing architecture. Each data node has its own exclusive hardware resources (such as data storage), operating system, and database, and the data nodes communicate with each other through a network. Under this system, in order to improve the ability of the database system to resist failures, one of the data nodes is usually used as the host to provide database services, and the other data nodes are used as backup machines. When the host fails, or the host load is heavy, one or more backup machines will be selected as the host to provide database services. In order to ensure data consistency between the backup machine and the host, the host needs to continuously synchronize the log to the backup machine through streaming replication, and replay the log on the backup machine. Based on this, the method provided in the embodiment of the present application can be used to replay the log on the backup machine. In addition, since the host may be shut down and then pulled up again, the method provided in the embodiment of the present application can also be used to replay the log on the host. In Figure 1A Like the cluster database system shown in the figure, the data nodes here can be either physical machines or virtual machines.
[0079] Among them, Figure 1A In the example, coordination node 1 and coordination node 2 serve as the entry points for clients to connect to the database system; the transaction management node is used to provide management services for database transactions; and the cluster management node is used to provide cluster management services.
[0080] In all embodiments of the present application, the data storage of the database system includes but is not limited to solid state drives (SSDs), disk arrays, or other types of non-transitory computer-readable media. Figure 1A Although the database is not shown in 1B, it should be understood that the database is stored in the data storage. Those skilled in the art will understand that a database system may include fewer or more components than those shown in 1B, or include Figure 1A The components shown in the figure are different components. Figure 1A Only components more relevant to the implementation disclosed in the embodiments of the present application are shown. Figure 1A 4 data nodes are described in the figure, but those skilled in the art can understand that a cluster database system can include any number of data nodes. The database management system functions of each data node can be implemented by an appropriate combination of software, hardware and / or firmware running on each data node.
[0081] Above Figure 1A The database system includes data nodes. The structure of data nodes is introduced below with reference to the attached figure. Figure 1BAs shown, an embodiment of the present application provides a data node 100, including: at least one processor 104, a non-transitory computer-readable medium (non-transitory computer-readable medium) 106 storing executable code, and a database management system 108. The executable code is configured to implement the components and functions of the database management system 108 when executed by at least one processor 104. The non-transitory computer-readable medium 106 may include one or more non-volatile memories. As an example, the non-volatile memory includes a semiconductor memory device, such as an erasable programmable read only memory (EPROM), an electrically erasable programmable read only memory (EEPROM) and a flash memory; a disk, such as an internal hard disk or a removable disk, a magneto optical disk, and a CD ROM and a DVD-ROM. In addition, the non-transitory computer-readable medium 106 may also include any device configured as a main memory. At least one processor 104 may include any type of general computing circuit or dedicated logic circuit, such as a field-programmable gate array (FPGA) or an application specific integrated circuit (ASIC). At least one processor 104 may also be one or more processors coupled to one or more semiconductor substrates, such as a CPU.
[0082] The database management system 108 may be a relational database management system (RDBMS). The database management system 108 supports structured query language (SQL). Generally, SQL refers to a special programming language specifically used to manage data stored in a relational database. SQL may refer to various types of data-related languages, including, for example, data definition languages and data manipulation languages, wherein the scope of SQL may include data insertion, query, update and deletion, schema creation and modification, and data access control. In addition, in some examples, SQL may include descriptions related to various language elements, including clauses, expressions, predicates, and query statements, which are also often referred to as "queries". For example, clauses may refer to various components of statements and queries, and in some cases, clauses may be considered optional. In addition, expressions may be configured to generate scalar values and / or tables including data columns and / or rows. In addition, predicates may be configured to specify conditions for adjusting the effects of statements and queries.
[0083] A query statement is a request to view, access and / or manipulate data stored in a database. The database management system 108 can receive a query in SQL format (referred to as an SQL query) from the database client 102. The SQL query can also be referred to as an SQL statement. Generally, the database management system 108 generates a query result corresponding to the query by accessing relevant data from the database and manipulating the relevant data, and returns the query result to the database client 102. A database is a collection of data organized, described and stored according to a certain mathematical model. A database may include one or more database structures or formats, such as row storage and column storage. A database is usually stored in a data storage device, such as Figure 1B The external data storage 120 in the non-transitory computer readable medium 106. When the database is stored in the non-transitory computer readable medium 106, the database management system 108 is an in-memory database management system.
[0084] Database client 102 may include any type of device or application configured to interact with database management system 108. In some examples, database client 102 includes one or more application servers.
[0085] The database management system 108 includes an SQL engine 110, an execution engine 122, and a storage engine 134. The SQL engine 110 generates a corresponding execution plan based on the SQL statement submitted by the client 102, such as a query, and the execution engine 122 operates according to the execution plan of the statement to generate the query result. The storage engine 134 is responsible for managing the data of the table and the actual content of the index on the file system, and also manages the cache Cache, buffer Buffer, transaction, log and other data during runtime. For example, the storage engine 134 can write the execution result of the execution engine 122 to the data storage 120 through physical I / O. The SQL engine 110 includes a parser 112 and an optimizer 114, wherein the parser 110 is used to perform grammatical and semantic analysis of the SQL statement, expand the view in the query, and divide it into small query blocks. The optimizer 114 generates a set of execution plans that may be used for the statement, estimates the cost of each execution plan, compares the cost of the plan, and finally selects an execution plan with the lowest cost.
[0086] Based on the above description, it can be known that when the main machine is pulled up again after being shut down, and on the standby machine, logs need to be replayed. Moreover, whether the main machine is pulled up again or the standby machine is promoted to the main machine, external services can only be provided after the logs are replayed. Therefore, if the speed of replaying logs is not fast enough, the database recovery time will be longer.
[0087] In the scenario where a host in a single-click database system or cluster database system is shut down and then pulled up again, if the speed of replaying logs is not fast enough, it will cause a long waiting time before the host provides external services after being pulled up again, so that the waiting time exceeds the recovery time objective (RTO), where RTO refers to the maximum tolerable time that a computer, system, network or application stops working after a failure or disaster occurs. In the scenario where the backup machine replays logs, if the speed of replaying logs is not fast enough, logs will accumulate on the backup machine, which will lead to a long waiting time before the backup machine provides external services after being promoted to the main machine, so that the waiting time exceeds the RTO.
[0088] To this end, an embodiment of the present application provides a method for playing back logs on a data node. Specifically, the logs are divided into transaction commit logs and logs related to page operations, and different threads are used for the transaction commit logs and the logs related to page operations, respectively. Therefore, there is no need to play back the logs on a transaction basis; and multiple threads can also be used to play back the logs related to page operations to further speed up the transaction playback.
[0089] In the embodiment of the present application, the log may be a redo log; it should be noted that the method provided in the embodiment of the present application may also be adaptively adjusted, and then the adjusted method may be used to replay other logs such as rolling back undo logs.
[0090] Specifically, see Figure 2 , an embodiment of the present application provides an embodiment of a method for replaying logs on a data node. In this embodiment, multiple threads are running on the data node. Based on this, the method in the embodiment of the present application includes:
[0091] Step 101: A data node obtains multiple logs.
[0092] The multiple logs include at least one transaction commit log and at least one page operation log. Each transaction commit log in the at least one transaction commit log contains transaction commit operations. Each page operation log in the at least one page operation log contains one or more operations on a page.
[0093] The embodiments of the present application do not specifically limit the number and types of operations on the same page contained in the page operation log. For example, the page operation log may only contain an insert operation on a row in a specific page; for example, in addition to an insert operation on a row in a specific page, the page operation log may also contain a delete operation on another row in the specific page; for another example, the page operation log may contain an insert operation on two rows in a specific page, and a delete operation on one row in the specific page.
[0094] There are many methods for obtaining multiple logs, which are not specifically limited in the embodiments of the present application; among them, the methods for obtaining transaction commit logs and page operation logs may be different. The method for obtaining multiple logs will be specifically introduced later.
[0095] Step 102: The data node replays at least one transaction commit log through a first thread among multiple threads.
[0096] After obtaining the multiple logs, the first thread plays back the transaction commit logs in the multiple logs.
[0097] There are many methods for the first thread to replay the transaction commit log, for example, performing a transaction commit operation in a transaction commit log on an initial page to update the initial page; then performing a transaction commit operation in the next transaction commit log on the updated initial page to further update the updated initial page; repeating the above process can achieve the replay of the transaction commit log, and finally obtain the most recently updated version of the initial page. In the process of replaying the transaction commit log, the initial page can be a blank page or a non-blank page already existing in the database.
[0098] The order in which the first thread plays back the transaction commit logs is usually to play back the transaction commit logs in sequence according to the log sequence numbers LSN of the transaction commit logs to ensure data consistency.
[0099] In addition, other methods can also be used to replay transaction submission, which will be introduced in detail later.
[0100] Step 103: The data node replays at least one page operation log through at least one second thread among the multiple threads.
[0101] When there are multiple page operation logs, multiple second threads may be used to play back the page operation logs in parallel to increase the playback speed of the page operation logs.
[0102] If multiple second threads are used for parallel playback, all page operation logs containing operations on the same page in at least one page operation log are played back by the same second thread.
[0103] It is understandable that the same second thread can replay page operation logs containing operations on different pages. For example, all page operation logs containing operations on page 11 and all page operation logs containing operations on page 22 can be replayed by the same second thread.
[0104] Similar to replaying the transaction commit log, replaying the page operation log also needs to be performed on an initial page. The difference is that the initial page can be a blank page or a non-blank page that already exists in the database. Specifically, taking the all-page operation log containing operations on a certain initial page as an example, if the all-page operation log containing operations on the initial page is replayed by a second thread, then only one second thread needs to obtain the initial page; and if the all-page operation log containing operations on the initial page is replayed by two second threads respectively, then both second threads need to obtain the initial page. Therefore, replaying all-page operation logs containing operations on the same page by the same second thread can reduce the operations of the second thread to obtain the initial page.
[0105] Similarly, the order in which the second thread plays back the page operation log is usually to play back the page operation log in sequence according to the LSN of the page operation log to ensure data consistency. Therefore, if all page operation logs containing operations on the same page are played back by multiple second threads, in order to ensure data consistency, the playback progress of the logs needs to be synchronized between the multiple second threads to ensure that they are played back in sequence according to the LSN of the page operation log. If all page operation logs containing operations on the same page are played back by the same second thread, the playback progress of the logs does not need to be synchronized between the multiple second threads.
[0106] The process of the first thread replaying at least one transaction commit log is independent of the process of at least one second thread replaying at least one page operation log. It can also be understood that the process of the first thread replaying at least one transaction commit log is parallel to the process of at least one second thread replaying at least one page operation log, and does not interfere with each other. Specifically, corresponding to the transaction commit log and page operation log of the same transaction, the process of the first thread replaying the transaction commit log and the second thread replaying the page operation log are performed independently, the first thread does not need to synchronize the playback progress of the transaction commit log with the second thread, and the second process does not need to synchronize the playback progress of the page operation log with the first thread, so the process of the first thread replaying the transaction commit log can be performed without waiting for the second thread to complete the playback of the page operation log. For different transactions, the process of the first thread replaying the transaction commit log and the second thread replaying the page operation log is also performed independently. Specifically, the second thread can replay the page operation log corresponding to the next transaction without waiting for the first thread to complete the playback of the transaction commit log corresponding to the current transaction.
[0107] The following is an example to illustrate the process of replaying logs in the embodiment of the present application. Figure 3 As shown, in this example, the log of the first transaction includes page operation log 1 and transaction commit log 2, and the log of the second transaction includes page operation log 3, page operation log 4 and transaction commit log 5, and page operation log 1 and page operation log 3 correspond to the same page. Using the method provided in the embodiment of the present application to play back the logs, page operation log 1 and page operation log 3 are played back by the second thread 1, page operation log 4 is played back by the second thread 2, and transaction commit log 2 and transaction commit log 5 are played back by the first thread.
[0108] During the log playback process, for the first transaction, the process of the first thread playing back the transaction commit log 2 is independent of the process of the second thread 1 playing back the page operation log 1. There is no need to wait for the completion of the playback of the page operation log 1 to play back the transaction commit log 2, so there is no need to synchronize the log playback progress between the first thread and the second thread 1; for the second transaction, the process of the first thread playing back the transaction commit log 5 is independent of the process of the second thread 1 playing back the page operation log 3, and the process of the first thread playing back the transaction commit log 5 is independent of the process of the second thread 2 playing back the page operation log 4, so there is no need to synchronize the log playback progress between the first thread and the second thread 1, and there is no need to synchronize the log playback progress between the first thread and the second thread 2.
[0109] Furthermore, since the page operation logs 1 and 3 corresponding to the same page are replayed by the second thread 1, and the page operation log 4 is replayed by the second thread 2, the log playback between the second thread 1 and the second thread 2 is also independent, and there is no need to synchronize the log playback progress.
[0110] Based on the above description, it can be known that in an embodiment of the present application, the playback of all page operation logs containing operations on the same page is performed by the same second thread, so there is no need to synchronize the playback progress of the logs between threads. Compared with the playback of all page operation logs containing operations on the same page being performed by multiple second threads, the playback speed of the logs can be accelerated; the process of the first thread playing back the transaction commit log is independent of the process of any second thread playing back the page operation log, so even if the transaction commit log corresponding to the current transaction has not been played back, the page operation log corresponding to the next transaction can be played back, thereby further accelerating the playback speed.
[0111] The specific process of obtaining multiple logs is introduced below.
[0112] First, a data node can read multiple logs from data storage or buffers.
[0113] The buffer is a piece of memory used to interact with the data storage device to read and write logs. When the master synchronizes logs to the standby machine through streaming replication, the logs will first be synchronized to the standby machine's buffer, and then the logs in the buffer will be refreshed to the data storage device. It should be noted that the logs in the buffer will not be cleared until they are read during the log playback process, so the logs will not be cleared from the buffer due to being refreshed to the data storage device.
[0114] Therefore, when the master and the standby are in streaming replication, multiple logs can be read from the buffer; when the master and the standby are not in streaming replication, for example, when the master is shut down and restarted, multiple logs can be read from the data storage.
[0115] It is understandable that, compared with reading logs from a data storage device, reading multiple logs from a buffer can reduce the number of input / output I / Os of the data storage device, speed up the log reading speed, and thus speed up the log playback speed.
[0116] Typically, the multiple logs include transaction commit logs and operation logs, wherein the operation logs can be understood as logs related to a table, specifically including operations on one or more pages in a table. In addition, each of the multiple logs corresponds to an LSN.
[0117] Based on the above description, exemplarily, the data node obtaining multiple logs includes: the data node parsing at least one operation log to obtain at least one page operation log, and each operation log in the at least one operation log includes operations on one or more pages.
[0118] It should be noted that the process of data node parsing operation logs is performed at the page granularity; for example, if the operation log contains a total of 15 operations on 10 pages, then the operation log will be parsed into 10 page operation logs, that is, multiple operations corresponding to the same page are included in one page operation log.
[0119] The operation log has the same LSN as the page operation log obtained by parsing the operation log. Specifically, the at least one page operation log includes a first page operation log, and the LSN of the first page operation log is the same as the LSN of the operation log obtained by parsing the first page operation log.
[0120] For example, if one operation log is parsed to obtain five page operation logs, the LSNs of the five page operation logs are all the same as the LSN of the operation log.
[0121] It should be understood that if multiple threads on a data node synchronize the playback progress of the log with each other, the data node can obtain the playback progress of the log based on the synchronization result, so that the user can view the playback progress of the log. However, in the embodiment of the present application, the playback progress of the log does not need to be synchronized between the first thread and the second thread, and the playback progress of the log does not need to be synchronized between the second threads. Therefore, the playback progress of the log cannot be obtained through synchronization between threads.
[0122] For this reason, Figure 2 As shown, based on the foregoing embodiments, in another embodiment of the method for replaying logs on a data node provided by the present application, the method further includes:
[0123] Step 104: The data node determines the maximum visible LSN, which is used to indicate the playback progress of the log.
[0124] Among them, all transaction commit logs whose log sequence number LSN is less than or equal to the maximum visible LSN in at least one transaction commit log are replayed, and all page operation logs whose log sequence number LSN is less than or equal to the maximum visible LSN in at least one page operation log are replayed.
[0125] It is understandable that, since when there are multiple second threads, the multiple second threads are parallel and independent, and the process of the first thread playing back the transaction commit log is independent of the process of the second thread playing back the page operation log, discontinuous log playback may occur.
[0126] For example, the LSN of the transaction commit log currently being replayed by the first thread is 100, while the LSN of the page operation log currently being replayed by the second thread is 90, that is, some logs with LSNs between 90 and 100 have not been replayed. At this time, 100 cannot be used as the maximum visible LSN, and only 90 can be used as the maximum visible LSN.
[0127] Based on the above description, it can be known that in the embodiment of the present application, the LSN corresponding to one of the multiple logs is the first LSN, and all transaction commit logs with LSN less than or equal to the first LSN in at least one transaction commit log are replayed, and all page operation logs with LSN less than or equal to the first LSN in at least one page operation log are replayed, then the first LSN is used as the maximum visible LSN, so as to avoid the situation where the maximum visible LSN error is caused by discontinuous log playback. Therefore, the maximum visible LSN in the embodiment of the present application can more accurately represent the playback progress of the log, so as to ensure the consistency of the data through the playback progress.
[0128] The foregoing describes a method for a first thread to replay at least one transaction commit log. The following describes another method for a first thread to replay at least one transaction commit log.
[0129] Specifically, as an implementable manner, the data node replays at least one transaction commit log through a first thread among multiple threads, including:
[0130] The data node replays at least one transaction commit log in LSN order on an initial version of the first page through a first thread among multiple threads to obtain multiple versions of the first page, wherein each version of the multiple versions of the first page is associated with at least one of the at least one transaction commit log.
[0131] The multiple versions of the first page include a first version of the first page and a second version of the first page generated based on the first version of the first page, wherein the second version of the first page is obtained by replaying a transaction commit log associated with the first version of the first page in LSN order on the first version of the first page.
[0132] Specifically, the process of the first thread replaying at least one transaction commit log to obtain multiple versions of the first page may be as follows:
[0133] The first thread in the data node sequentially associates a certain number of transaction commit logs with version A (i.e., the initial version) of the first page according to the LSN of at least one transaction commit log in ascending order;
[0134] The data node then generates version B of the first page based on version A of the first page and the transaction commit log associated with version A of the first page. At this point, two versions of the first page are obtained.
[0135] Next, the first thread in the data node may continue to associate a certain number of transaction commit logs with version B of the first page in order according to the LSN of the at least one transaction commit log from small to large.
[0136] The data node then generates version C of the first page based on version B of the first page and the transaction commit log associated with version B of the first page. At this point, three versions of the first page are obtained.
[0137] By repeating the above steps, the playback of at least one transaction commit log can be completed, and multiple versions including the initial version of the first page can be obtained.
[0138] It is understandable that after obtaining multiple versions of the first page including the initial version of the first page, the multiple versions of the first page are usually stored in the memory. In order to reduce the memory occupation of the multiple versions of the first page and prevent the multiple versions of the first page from disappearing due to the shutdown of the data node, the multiple versions of the first page are usually written to the data storage.
[0139] In the embodiment of the present application, multiple methods can be used to write multiple versions of the first page into the data storage device, for example, the data node can directly write multiple versions of the first page into the data file in the data storage device. Since there is a risk of damaging the multiple versions of the first page when directly writing the multiple versions of the first page into the Data file, the data node can write the multiple versions of the first page into a double write file; then, write the multiple versions of the first page in the Double write file into the data file, thereby ensuring that the multiple versions of the first page are not damaged.
[0140] The embodiment of the present application does not specifically limit the number of versions of the first page, that is, the multiple versions of the first page may include two versions, or may include three or more versions; the embodiment of the present application does not specifically limit the number of transaction submission logs associated with each version of the multiple versions of the first page.
[0141] Exemplarily, each of the multiple versions of the first page is associated with the same number of transaction commit logs, that is, on the initial version of the first page, each time a certain number of transaction commit logs are replayed, a version of the first page is generated.
[0142] Exemplarily, on the initial version of the first page, a transaction commit log is played back for a period of time to generate a version of the first page, that is, the transaction commit log associated with each of the multiple versions of the first page has the same playback time.
[0143] Based on the above description, it is known that the transaction commit operation in the transaction commit log can be continuously performed on the initial page, so that the initial page can be continuously updated. By using this method to replay at least one transaction commit log, only the most recently updated version of the initial page can be obtained. In the embodiment of the present application, multiple versions of the first page can be obtained in the end. Based on the multiple versions of the first page, the content of the first page after replaying any transaction commit log can be viewed.
[0144] Specifically, based on the foregoing embodiments, in another embodiment of the method for replaying logs on a data node provided by the present application, the method further includes:
[0145] In response to a first indication, the first indication is used to query the playback progress of at least one transaction commit log, and the data node plays back the transaction commit log associated with the baseline version of the first page in LSN order on the baseline version of the first page until the first transaction commit log is played back to obtain the target version of the first page.
[0146] The baseline version of the first page is a version associated with the first transaction commit log among multiple versions of the first page, and the first transaction commit log is a log with the largest LSN among at least one transaction commit log, and the LSN is less than or equal to the maximum visible LSN.
[0147] Finally, a playback progress of at least one transaction commit log is determined based on the target version of the first page.
[0148] For example, the multiple versions of the first page include the first version of the first page, the second version of the first page, and the third version of the first page. Each version of the first page is associated with three transaction commit logs, wherein the LSNs of the three transaction commit logs associated with the first version of the first page are 2, 5, and 8, respectively; the LSNs of the three transaction commit logs associated with the second version of the first page are 12, 15, and 18, respectively; and the LSNs of the three transaction commit logs associated with the third version of the first page are 22, 25, and 28, respectively.
[0149] If the maximum visible LSN is 19, the transaction commit log with LSN 18 is the first transaction commit log, and the baseline version of the first page is the version associated with the transaction commit log with LSN 18, that is, the second version of the first page. The transaction commit logs with LSNs 12, 15, and 18 are replayed on the second version of the first page in sequence, and the target version of the first page is finally obtained. The target version of the first page can be used to indicate the playback progress of the log.
[0150] If the maximum visible LSN is 25, and the transaction commit log with LSN 25 is the first transaction commit log, the baseline version of the first page is the version associated with the transaction commit log with LSN 25, that is, the third version of the first page. The transaction commit logs with LSNs of 22 and 25 are replayed in sequence on the third version of the first page, and finally the target version of the first page is obtained, which can be used to indicate the playback progress of the log.
[0151] It should be noted that there are many forms of the first indication, and the embodiments of the present application do not specifically limit this.
[0152] The foregoing describes a method for the second thread to replay at least one page operation log. The following describes another method for the second thread to replay at least one page operation log.
[0153] Specifically, as an implementable manner, the data node replays at least one page operation log through at least one second thread among the multiple threads, including:
[0154] The data node replays, by a second thread among the plurality of threads, all page operation logs in at least one page operation log that contain operations on the second page in LSN order on the initial version of the second page to obtain multiple versions of the second page, each version of the multiple versions of the second page being associated with at least one of all page operation logs that contain operations on the second page;
[0155] The multiple versions of the second page include a third version and a fourth version generated based on the third version, where the fourth version is obtained by replaying a transaction commit log associated with the third version in LSN order on the third version.
[0156] Specifically, the process of the second thread replaying at least one page operation log to obtain multiple versions of the second page may be as follows:
[0157] The second thread in the data node sequentially associates a certain number of page operation logs with version D (that is, the initial version) of the second page according to the LSN of at least one page operation log in ascending order;
[0158] Then the data node generates version E of the second page according to version D of the second page and the page operation log associated with version D of the second page. At this point, two versions of the second page are obtained.
[0159] Next, the second thread in the data node may continue to associate a certain number of page operation logs with version E of the second page in order according to the LSN of the at least one page operation log from small to large.
[0160] The data node then generates version F of the second page based on version E of the second page and the transaction commit log associated with version E of the second page. At this point, three versions of the second page are obtained.
[0161] By repeating the above steps, the playback of at least one page operation log can be completed, and multiple versions including the initial version of the second page can be obtained.
[0162] Similarly, after obtaining multiple versions of the first page including the initial version of the second page, the multiple versions of the second page are usually stored in the memory. In order to reduce the memory occupancy of the multiple versions of the second page and prevent the multiple versions of the second page from disappearing due to the shutdown of the data node, the multiple versions of the second page are usually written to the data storage.
[0163] In the embodiment of the present application, multiple methods can be used to write multiple versions of the second page into the data storage device, for example, the data node can directly write multiple versions of the second page into the data file in the data storage device. Since there is a risk of damaging the multiple versions of the second page when directly writing the multiple versions of the second page into the Data file, the data node can write the multiple versions of the second page into a double write file; then, write the multiple versions of the second page in the Double write file into the data file, thereby ensuring that the multiple versions of the second page are not damaged.
[0164] The embodiment of the present application does not specifically limit the number of versions of the second page, that is, the multiple versions of the second page may include two versions, or may include three or more versions; the embodiment of the present application does not specifically limit the number of page operation logs associated with each version in the multiple versions of the second page.
[0165] Exemplarily, on the initial version of the second page, each time a certain number of transaction commit logs are replayed, a version of the second page is generated, so the number of page operation logs associated with each of the multiple versions of the second page is the same.
[0166] Exemplarily, on the initial version of the second page, a version of the second page is generated each time a page operation log of a period of time is replayed, that is, the page operation log associated with each of the multiple versions of the second page has the same replay time.
[0167] Based on the above description, it is known that the page operations in the page operation log can be continuously performed on the initial page, so that the initial page can be continuously updated. By replaying at least one page operation log in this way, only the most recently updated version of the initial page can be obtained. In the embodiment of the present application, multiple versions of the second page can be obtained in the end. Based on the multiple versions of the second page, the content of the second page after replaying any page operation log can be viewed.
[0168] Specifically, based on the foregoing embodiments, in another embodiment of the method for replaying logs on a data node provided by the present application, the method further includes:
[0169] In response to the second indication, which is used to query the playback progress of at least one page operation log, the data node plays back the transaction commit log associated with the baseline version of the second page in LSN order on the baseline version of the second page until the first page operation log is played back to obtain the target version of the second page;
[0170] Among them, the baseline version of the second page is the version associated with the first page operation log among multiple versions of the second page, and the first page operation log is the log with the largest LSN among all page operation logs containing operations on the second page, and the LSN is less than or equal to the maximum visible LSN.
[0171] Finally, the playback progress of at least one page operation log is determined based on the target version of the second page.
[0172] For example, the multiple versions of the second page include the first version of the second page, the second version of the second page, and the third version of the second page. Each version of the second page is associated with three page operation logs, wherein the LSNs of the three page operation logs associated with the first version of the second page are 1, 3, and 4, respectively; the LSNs of the three page operation logs associated with the second version of the second page are 6, 7, and 9, respectively; and the LSNs of the three page operation logs associated with the third version of the second page are 10, 12, and 14, respectively.
[0173] If the maximum visible LSN is 8, the page operation log with LSN 7 is the first page operation log, and the baseline version of the second page is the version associated with the page operation log with LSN 7, that is, the second version of the second page. The page operation logs with LSNs 6 and 7 are replayed in sequence on the second version of the second page, and finally the target version of the second page is obtained, which can be used to indicate the playback progress of the log.
[0174] If the maximum visible LSN is 13, the page operation log with LSN 12 is the first page operation log, and the baseline version of the second page is the version associated with the page operation log with LSN 12, that is, the third version of the second page. The page operation logs with LSNs 10 and 12 are replayed on the third version of the second page in sequence, and finally the target version of the second page is obtained, which can be used to indicate the playback progress of the log.
[0175] It should be noted that there are many forms of the first indication, and the embodiments of the present application do not specifically limit this.
[0176] In combination with the above-mentioned multiple embodiments, it can be known that in the process of playing back the log, the data node generates multiple versions of the first page and multiple versions of the second page. According to the multiple versions of the first page and the multiple versions of the second page, the playback progress of the log can be viewed, and the content of the first page after any transaction commit log is played back can be viewed, and the content of the second page after any page operation log is played back can also be viewed. Therefore, if the method for playing back the log provided in the embodiment of the present application is applied to the backup machine of the cluster database system, the backup machine can be readable; further, the host is used to write data, and the backup machine is used to read data, thereby reducing the load when the host is used to read and write data at the same time.
[0177] For ease of understanding, the following Figure 4 and Figure 5 The method for replaying a log provided in an embodiment of the present application is further described.
[0178] like Figure 4 and Figure 5 As shown, the application scenario of this example is that the master synchronizes logs to the slave through streaming replication, and then the slave plays back the logs.
[0179] Specifically, the example includes:
[0180] Step 201, the host sends the log to the standby machine. Specifically, the host can send the log generated by the host to the standby machine through the Walsender thread, and the standby machine receives the log sent by the host through the Walreceiver thread, and the received log is stored in the buffer.
[0181] Step 202: The standby machine stores the received log into the data storage through the Walreceiver thread, and sends a message to the master machine, indicating that the log has been written into the data storage.
[0182] Step 203: The byte stream is read from the buffer of the read thread in the data node.
[0183] from Figure 4 As can be seen in Figure 1, data nodes can also read byte streams from data storage.
[0184] There is no order between step 203 and step 202. For example, step 202 and step 203 can be performed simultaneously. Figure 5 In the example, step 202 is performed first, and then step 203 is performed.
[0185] Step 204: The decoding thread in the data node decodes the byte stream into multiple logs.
[0186] Step 205, the dispatcher thread in the data node sends the transaction commit log in the multiple logs to the Parse Redo Record thread, and sends the operation log in the multiple logs to the Trxn Manager thread. Figure 4 In the example, the Read thread, the Decode thread, and the Dispatcher thread all belong to the log distribution module. The process of decoding the byte stream is not described in Figure 4 Shown in.
[0187] Step 206: The Parse Redo Record thread in the data node parses the operation log into a page operation log with the page as the granularity, and then sends the page operation log to the Page Redo Manager thread.
[0188] It should be noted that the process of the Parse Redo Record thread parsing the operation log can be understood by referring to the relevant description in the aforementioned embodiment, which will not be described in detail here.
[0189] Step 207: Based on the fact that the operation log is a log related to the table, the Page Redo Manager thread creates a hash table using the table and the page as key-value pairs.
[0190] In the hash table, all page operation logs corresponding to the same page form a chain, corresponding to a label, and the page operation logs in the same chain are arranged in sequence according to LSN, and the newly received page operation log is placed at the end of the chain. Figure 4 As shown, the page operation log under label 1 is the operation log corresponding to one page, the page operation log under label 2 is the operation log corresponding to one page, and the page operation log under label 3 is the operation log corresponding to another page.
[0191] exist Figure 4 In the , the Parse Redo Record thread and Page Redo Manager thread belong to the parsing classification module. Among them, the process of Parse Redo Record thread parsing operation logs is not described in Figure 4 Shown in.
[0192] Step 208: The Page Redo Manager thread adds the page operation log to the queue of the Page RedoWorker thread according to the hash table.
[0193] Among them, all page operation logs containing operations on the same page are located in the queue of the same Page Redo Worker thread and are arranged in sequence by LSN. It should be noted that, in the queue of the same Page Redo Worker thread, it is only necessary to ensure that all page operation logs containing operations on the same page are arranged in sequence by LSN, and the order of page operation logs containing operations on different pages can be arbitrary.
[0194] Step 209: The Page Redo Worker thread plays back the page operation log in the queue.
[0195] It should be noted that the process of the Page Redo Worker thread replaying the page operation log can be understood by referring to the relevant description of the replaying the page operation log in the aforementioned embodiment, and will not be described in detail here.
[0196] Step 210: while the Page Redo Worker thread is replaying the page operation log, multiple versions of the page of the page operation log are generated.
[0197] It should be noted that the process of generating multiple versions of a page of a page operation log can be understood by referring to the relevant description of replaying the page operation log in the aforementioned embodiment, and will not be described in detail here.
[0198] Step 211, the Trxn Manager thread adds the transaction submission log to the queue of the Trxn Worker thread.
[0199] Among them, the transaction commit logs are arranged in the queue of the Trxn Worker thread in sequence according to LSN.
[0200] Step 212: The Trxn Worker thread replays the transaction commit log in the queue.
[0201] Among them, Page Redo Worker thread and Trxn Worker thread belong to the log playback module.
[0202] It should be noted that the process of the Trxn Worker thread replaying the transaction submission log can be understood by referring to the relevant description of replaying the transaction submission log in the aforementioned embodiment, which will not be repeated here.
[0203] Step 213: while the Trxn Worker thread is replaying the transaction commit log, multiple versions of the pages of the transaction commit log are generated.
[0204] It should be noted that the process of generating multiple versions of a page of a transaction commit log can be understood by referring to the relevant description of replaying a transaction commit log in the aforementioned embodiment, and will not be described in detail here.
[0205] Step 214 , the data writing thread writes multiple versions of the page into the Double write file and the Data file, wherein the data writing thread belongs to the data writing module.
[0206] It should be noted that the process of writing multiple versions of a page into the Double write file and the Data file can be understood by referring to the relevant description of writing multiple versions of a page into the data storage in the aforementioned embodiment, and will not be described in detail here.
[0207] from Figure 4 As can be seen, multiple versions of the page can be read by the backup machine, that is, they can provide read services to the client.
[0208] In the above-mentioned embodiments, the playback of transaction commit logs and page operation logs is introduced. In addition, the logs may also include checkpoint logs, table space creation logs, table space deletion logs, data space creation logs, and data space deletion logs.
[0209] Among them, the Checkpoint log contains the operation of regularly refreshing the data in the buffer to the data storage; the create tablespace log contains the operation of creating a new table, and correspondingly, the delete tablespace log contains the operation of deleting a table; the create dataspace log contains the operation of creating a database, and correspondingly, the delete dataspace log contains the operation of deleting the database.
[0210] It should be noted that the first thread can be used to play back the Checkpoint log, that is, the first thread is used to play back the transaction commit log and the Checkpoint log. At this time, the process of the first thread playing back the Checkpoint log and the process of the second thread playing back the page operation log may interact, but the process of the first thread playing back the transaction commit log and the process of the second thread playing back the page operation log are independent.
[0211] Another thread may be used to replay the creation of tablespace logs, deletion of tablespace logs, creation of dataspace logs, and deletion of dataspace logs. For example, the Page Redo Manager thread may be used to replay the creation of tablespace logs, deletion of tablespace logs, creation of dataspace logs, and deletion of dataspace logs. It is understandable that the operations in the creation of tablespace logs, deletion of tablespace logs, creation of dataspace logs, and deletion of dataspace logs will cause page changes. Therefore, the process of replaying the creation of tablespace logs, deletion of tablespace logs, creation of dataspace logs, and deletion of dataspace logs may interact with the process of the second thread replaying the page operation log.
[0212] The above describes the method for replaying logs provided in the embodiments of the present application. The following describes several scenarios in which the method can be applied.
[0213] Scenario 1: As shown in Figures 6(a) and 6(b), the log playback method provided in the embodiment of the present application can be applied to a simple database with one host and multiple backup machines. In Figures 6(a) and 6(b), there are two backup machines. As shown in Figure 6(a), when the host is operating normally, the host synchronizes logs to the two backup machines. As shown in Figure 6(b), when the host is abnormally shut down, one of the two backup machines is promoted to the host and synchronizes logs to the other backup machine.
[0214] Therefore, on both standby machines, the log playback method provided in the embodiment of the present application can be used to play back logs, which can improve the speed of log playback, avoid the accumulation of a large number of logs on the standby machine, and also improve the speed of putting the standby machine into use after being promoted to the main machine.
[0215] Scene 2: Figure 7 As shown, the log playback method provided in the embodiment of the present application can be applied to a terminal cloud platform. The terminal cloud platform includes a production room AZ, a coordination node CN, a transaction management node GTM and a data node DN. Among them, all machines in the same room are in the same AZ, such as Figure 7 As shown in the figure, the terminal cloud platform includes two AZs. Multiple CNs can be deployed in each computer room as the entrance for application clients to connect. Figure 7 In the system, two CNs are set up in each computer room. Figure 7 In the terminal cloud platform, there are 6 GTMs, one of which is the main one and the other GTMs are backup ones. Figure 7 In the terminal cloud platform, there are 24 data nodes DN, of which 4 DN are hosts and each host corresponds to 5 DNs as backup machines.
[0216] Similarly, on the DN serving as a backup machine, the log playback method provided in the embodiments of the present application can be used to perform log playback, which can increase the speed of log playback, avoid the accumulation of a large number of logs on the backup machine, and also increase the speed at which the backup machine is put into use after being promoted to the main machine.
[0217] The third scene: Figure 8 As shown, the log playback method provided in the embodiment of the present application can be applied to a public cloud platform. Figure 7 The architecture of the terminal cloud platform shown is similar. Please refer to the above related description for details. Figure 8 The number of each component in the public cloud platform shown may be determined by the scale of the public cloud platform.
[0218] Similarly, on the DN serving as a backup machine, the log playback method provided in the embodiments of the present application can be used to perform log playback, which can increase the speed of log playback, avoid the accumulation of a large number of logs on the backup machine, and also increase the speed at which the backup machine is put into use after being promoted to the main machine.
[0219] See also Fig. 9 , a schematic diagram of the structure of a data node in an embodiment of the present application. Fig. 9 As shown, the embodiment of the present application provides an embodiment of a data node, and multiple threads are running on the data node; the data node includes:
[0220] The acquisition unit 301 is used to acquire multiple logs, where the multiple logs include at least one transaction commit log and at least one page operation log, each transaction commit log in the at least one transaction commit log includes a transaction commit operation, and each page operation log in the at least one page operation log includes one or more operations on a page;
[0221] A first playback unit 302, configured to play back at least one transaction commit log through a first thread among multiple threads;
[0222] A second playback unit 303 is used to play back at least one page operation log through at least one second thread among the multiple threads, and all page operation logs containing operations on the same page in the at least one page operation log are played back by the same second thread;
[0223] The process of the first thread replaying at least one transaction commit log is independent of the process of the at least one second thread replaying at least one page operation log.
[0224] In another embodiment of the data node provided in the embodiment of the present application, the acquisition unit 301 is used to obtain at least one transaction commit log and at least one operation log from the buffer; parse the at least one operation log to obtain at least one page operation log, each operation log in the at least one operation log contains operations on one or more pages; the at least one page operation log includes a first page operation log, and the LSN of the first page operation log is the same as the LSN of the operation log obtained by parsing the first page operation log.
[0225] In another embodiment of the data node provided by the embodiment of the present application, the data node also includes a determination unit 304, which is used to determine the maximum visible LSN, and the maximum visible LSN is used to indicate the playback progress of the log; all transaction commit logs in at least one transaction commit log whose log sequence number LSN is less than or equal to the maximum visible LSN are played back, and all page operation logs in at least one page operation log whose log sequence number LSN is less than or equal to the maximum visible LSN are played back.
[0226] In another embodiment of the data node provided in an embodiment of the present application, a first playback unit 302 is used to play back at least one transaction commit log in LSN order on an initial version of a first page through a first thread among multiple threads to obtain multiple versions of the first page, each of the multiple versions of the first page is associated with at least one of the at least one transaction commit log; the multiple versions of the first page include a first version of the first page, and a second version of the first page generated based on the first version of the first page, the second version of the first page is obtained by playing back the transaction commit log associated with the first version of the first page in LSN order on the first version of the first page.
[0227] In another embodiment of the data node provided in the embodiment of the present application, the data node further includes a writing unit 305 for writing multiple versions of the first page into a double write file; and writing multiple versions of the first page in the Double write file into a data file.
[0228] In another embodiment of the data node provided in the embodiment of the present application, the number of transaction commit logs associated with each of the multiple versions of the first page is the same, or the playback time of the transaction commit logs associated with each of the multiple versions of the first page is the same.
[0229] In another embodiment of the data node provided in an embodiment of the present application, the first playback unit 302 is also used to respond to a first indication, where the first indication is used to query the playback progress of at least one transaction commit log, and to play back the transaction commit log associated with the baseline version of the first page in LSN order on the baseline version of the first page until the first transaction commit log is played back to obtain the target version of the first page.
[0230] The base version of the first page is a version associated with the first transaction commit log among multiple versions of the first page, and the first transaction commit log is a log with the largest LSN among at least one transaction commit log, and the LSN is less than or equal to the maximum visible LSN;
[0231] The first page-based target version is used to represent the playback progress of at least one transaction commit log.
[0232] In another embodiment of the data node provided in an embodiment of the present application, a second playback unit 303 is used to play back all page operation logs containing operations on the second page in at least one page operation log in LSN order on the initial version of the second page through a second thread among multiple threads to obtain multiple versions of the second page, each version of the multiple versions of the second page is associated with at least one of all page operation logs containing operations on the second page.
[0233] The multiple versions of the second page include a first version of the second page and a second version of the second page generated based on the first version of the second page. The second version of the second page is obtained by replaying the page operation log associated with the first version of the second page in LSN order on the first version of the second page.
[0234] In another embodiment of the data node provided in the embodiment of the present application, the data node further includes a writing unit 305 for writing multiple versions of the second page into a double write file; and writing multiple versions of the second page in the Double write file into a data file.
[0235] In another embodiment of the data node provided in the embodiment of the present application, the number of page operation logs associated with each of the multiple versions of the second page is the same, or the playback time of the page operation logs associated with each of the multiple versions of the second page is the same.
[0236] In another embodiment of the data node provided in the embodiment of the present application, the second playback unit 303 is further used to respond to the second indication, the second indication is used to query the playback progress of at least one page operation log, and on the baseline version of the second page, replay the transaction commit log associated with the target version of the second page in LSN order until the first page operation log is played back to obtain the target version of the second page;
[0237] The base version of the second page is a version associated with the first page operation log among multiple versions of the second page, and the first page operation log is a log with the largest LSN among all page operation logs containing operations on the second page, and the LSN is less than or equal to the maximum visible LSN;
[0238] A playback progress of the at least one page operation log is determined based on the target version of the second page.
[0239] See also Fig.10 In an embodiment of the present application, a data node may include one or more processors 401 , a memory 402 , and a communication interface 403 .
[0240] The memory 402 may be a temporary storage or a permanent storage. Furthermore, the processor 401 may be configured to communicate with the memory 402 and execute a series of instruction operations in the memory 402 on the data node.
[0241] In this embodiment, the processor 401 may execute the aforementioned Fig. 9 The operations performed by the data nodes in the illustrated embodiment will not be described in detail here.
[0242] In this embodiment, the specific functional module division in the processor 401 can be the same as the above Fig. 9The functional module division method described in is similar and will not be repeated here.
[0243] The embodiment of the present application also provides a chip or a chip system, which includes at least one processor and a communication interface, the communication interface and the at least one processor are interconnected through a line, and the at least one processor is used to run a computer program or instruction to execute the aforementioned Fig. 9 The operations performed by the data nodes in the illustrated embodiment will not be described in detail here.
[0244] The communication interface in the chip may be an input / output interface, a pin or a circuit, etc.
[0245] The embodiment of the present application also provides a first implementation of a chip or a chip system, wherein the chip or chip system described above in the present application further includes at least one memory, and the at least one memory stores instructions. The memory may be a storage unit inside the chip, such as a register, a cache, etc., or may be a storage unit of the chip (e.g., a read-only memory, a random access memory, etc.).
[0246] An embodiment of the present application also provides a computer storage medium, which is used to store computer software instructions used for the above-mentioned control device, including a program designed for executing a data node.
[0247] The data node can be as described above Fig. 9 Describes the data node.
[0248] The present application also provides a computer program product, which includes computer software instructions, which can be loaded by a processor to implement the above Figure 2 and Figure 5 The process of any one of the methods provided in .
[0249] See also Fig.11 The embodiment of the present application also provides a database system, including a host machine 501 and at least one backup machine 502.
[0250] The host 501 is used to send logs to at least one standby machine 502; each of the at least one standby machine 502 is used to Figure 2 and Figure 5 The method provided in any one of the above can be used to replay the log.
[0251] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0252] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0253] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0254] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0255] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
Claims
1. A method for replaying logs on a data node, It is characterized in that A plurality of threads are running on the data node; the method comprises: The data node obtains a plurality of logs, wherein the plurality of logs include at least one transaction commit log and at least one page operation log, each of the at least one transaction commit log includes a transaction commit operation, and each of the at least one page operation log includes one or more operations on a page; The data node plays back the at least one transaction commit log through a first thread among the multiple threads; The data node plays back the at least one page operation log through at least one second thread among the multiple threads, and all page operation logs containing operations on the same page in the at least one page operation log are played back by the same second thread; The process of the first thread replaying the at least one transaction commit log is independent of the process of the at least one second thread replaying the at least one page operation log.
2. The method according to claim 1, It is characterized in that The data node obtains multiple logs including: The data node parses at least one operation log to obtain the at least one page operation log, each operation log in the at least one operation log includes operations on one or more pages; The at least one page operation log includes a first page operation log, and a log sequence number LSN of the first page operation log is the same as an LSN of an operation log obtained by parsing the first page operation log.
3. The method according to claim 1 or 2, It is characterized in that The method further comprises: The data node determines a maximum visible log sequence number LSN, where the maximum visible LSN is used to indicate the playback progress of the log; All transaction commit logs in the at least one transaction commit log whose LSN is less than or equal to the maximum visible LSN are replayed, and all page operation logs in the at least one page operation log whose log sequence number LSN is less than or equal to the maximum visible LSN are replayed.
4. The method according to claim 3, It is characterized in that The data node replays the at least one transaction commit log through a first thread among the multiple threads, including: The data node replays the at least one transaction commit log in LSN order on an initial version of the first page through a first thread among the multiple threads to obtain multiple versions of the first page, each version of the multiple versions of the first page being associated with at least one of the at least one transaction commit log; The multiple versions of the first page include a first version of the first page, and a second version of the first page generated based on the first version of the first page, wherein the second version of the first page is obtained by replaying a transaction commit log associated with the first version of the first page in LSN order on the first version of the first page.
5. The method according to claim 4, It is characterized in that The number of transaction commit logs associated with each of the multiple versions of the first page is the same, or the playback time of the transaction commit logs associated with each of the multiple versions of the first page is the same.
6. The method according to claim 4 or 5, It is characterized in that The method further comprises: In response to a first indication, the first indication being used to query the playback progress of the at least one transaction commit log, the data node plays back the transaction commit logs associated with the baseline version in LSN order on the baseline version of the first page until the first transaction commit log is played back to obtain a target version of the first page; The base version of the first page is a version associated with the first transaction commit log among multiple versions of the first page, and the first transaction commit log is a log with the largest LSN among the at least one transaction commit log, and the LSN is less than or equal to the maximum visible LSN; A playback progress of the at least one transaction commit log is determined based on a target version of the first page.
7. The method according to claim 3, It is characterized in that The data node replays the at least one page operation log through at least one second thread among the multiple threads, including: The data node replays, by a second thread among the multiple threads, all page operation logs in the at least one page operation log that contain operations on the second page in LSN order on the initial version of the second page to obtain multiple versions of the second page, each version of the multiple versions of the second page being associated with at least one of all page operation logs that contain operations on the second page; The multiple versions of the second page include a first version of the second page and a second version of the second page generated based on the first version of the second page, and the second version of the second page is obtained by replaying the page operation log associated with the first version of the second page in LSN order on the first version of the second page.
8. The method according to claim 7, It is characterized in that The number of page operation logs associated with each of the multiple versions of the second page is the same, or the playback time of the page operation logs associated with each of the multiple versions of the second page is the same.
9. The method according to claim 7 or 8, It is characterized in that The method further comprises: In response to a second indication, the second indication is used to query the playback progress of the at least one page operation log, the data node plays back the transaction commit log associated with the baseline version in LSN order on the baseline version of the second page until the first page operation log is played back to obtain a target version of the second page; The base version of the second page is a version associated with the first page operation log among multiple versions of the second page, and the first page operation log is a log having the largest LSN among all page operation logs containing operations on the second page, and whose LSN is less than or equal to the maximum visible LSN; A playback progress of the at least one page operation log is determined based on the target version of the second page.
10. A data node, It is characterized in that Multiple threads are running on the data node; The data nodes include: an acquisition unit, configured to acquire a plurality of logs, wherein the plurality of logs include at least one transaction commit log and at least one page operation log, each of the at least one transaction commit log includes a transaction commit operation, and each of the at least one page operation log includes one or more operations on a page; A first playback unit, configured to play back the at least one transaction commit log through a first thread among the multiple threads; A second playback unit, configured to play back the at least one page operation log through at least one second thread among the multiple threads, wherein all page operation logs containing operations on the same page in the at least one page operation log are played back by the same second thread; The process of the first thread replaying the at least one transaction commit log is independent of the process of the at least one second thread replaying the at least one page operation log.
11. A data node, It is characterized in that include: At least one processor and a memory, the memory storing computer executable instructions that can be run on the processor, when the computer executable instructions are executed by the processor, the data node executes the method as described in any one of claims 1-9 above.
12. A computer-readable storage medium storing one or more computer-executable instructions, It is characterized in that When the computer-executable instructions are executed by a processor, the processor performs the method as described in any one of claims 1 to 9 above.
13. A database system, It is characterized in that include: A master machine and at least one backup machine; The host is used to send logs to the at least one standby machine; Each of the at least one standby machine is used to play back the log according to the method described in any one of claims 1 to 9 above.
