Data processing method, medium, apparatus, and computing device

By storing data identifiers and log sequence numbers in the metadata hash table of the slave node, the problem of read exceptions caused by insufficient slave node memory is solved, ensuring the accuracy of data reading and user experience.

CN117591552BActive Publication Date: 2026-11-27NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311363697.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-19
Publication Date
2026-11-27
Estimated Expiration
2043-10-19

AI Technical Summary

Technical Problem

Insufficient memory on the slave node prevents it from storing new physical pages, leading to read errors.

Method used

By storing data identification information, starting log sequence number, and data length in the metadata hash table of the slave node, the location of the log record in the log file is determined, and the log record is replayed to read the data, reducing the memory usage of the slave node.

Benefits of technology

It enables accurate data reading even when slave nodes are low on memory, avoiding memory bloat and MySQL memory exhaustion issues, thus ensuring data reading accuracy and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117591552B_ABST
    Figure CN117591552B_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure provide a data processing method, relating to the field of cloud database. The data processing method comprises: in response to receiving a read request of first data, determining whether the first data is stored in a first memory of a slave node; in response to the first data not being stored in the first memory, determining a starting log sequence number of a first log record in a metadata hash table according to identification information of the first data; determining a starting position of the first log record in a log file according to the starting log sequence number; determining the first log record in the log file according to the starting position; and replaying the first log record to read the first data in the first log record according to a length of the first data. The present disclosure can reduce the memory occupation of the slave node by storing the metadata hash table in the first memory, thereby realizing accurate reading of data in a shared storage medium. Furthermore, embodiments of the present disclosure provide a medium, an apparatus and a computing device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this disclosure relate to the field of cloud databases, and more specifically, the embodiments of this disclosure relate to data processing methods, media, apparatus, and computing devices. Background Technology

[0002] This section is intended to provide background or context for embodiments of this disclosure. The description herein is not intended to imply that it is prior art simply because it is included in this section.

[0003] MySQL is one of the most popular open-source databases. With the development of computer technology, more and more cloud-native databases are being developed based on MySQL. Taking PolarDB as an example, PolarDB includes multiple MySQL compute nodes, which are divided into master nodes and slave nodes. Master nodes access shared storage media remotely over the network in read-write mode, while slave nodes access shared storage media remotely over the network in read-only mode. To enable slave nodes to provide query services, when the master node modifies the data in a physical page, it needs to generate a corresponding log. Slave nodes obtain the new physical page by replaying this log, thus maintaining transaction state and data synchronization with the master node.

[0004] Because slave nodes have limited memory, if a slave node runs out of memory, it needs to perform physical page eviction to free up memory. During the physical page eviction process, new physical pages obtained through log replay may be evicted. If the slave node needs to read this new physical page again later, it can only try to read it from the shared storage medium. However, in order to improve performance, the master node will not frequently flush the data of new physical pages to the shared storage medium, which may cause the slave node to read old pages from the shared storage medium, i.e., past pages.

[0005] In related technologies, to solve the past page problem, the physical page eviction of slave nodes is usually restricted. Although this prevents the reading of past pages, it may cause the memory of slave nodes to swell. If the memory of a slave node is exhausted, new physical pages cannot be stored, resulting in the inability to read new physical pages and thus causing data reading anomalies. Summary of the Invention

[0006] This disclosure provides a data processing method, medium, apparatus, and computing device to solve the problem of abnormal data reading caused by the inability to read new physical pages due to the exhaustion of the slave node's memory, resulting in the inability to store new physical pages.

[0007] In a first aspect of this disclosure, a data processing method is provided, applied to a slave node of a cloud database. The cloud database also includes a master node, which is used to read and write data and generate read and write log records. The log files corresponding to the log records are stored in a shared storage medium of the cloud database. The slave node achieves data synchronization with the master node by replaying the log records. The data processing method includes: in response to receiving a read request for first data, determining whether the first data is stored in the first memory of the slave node, the first data being data written in the master node, the read request carrying identification information of the first data, the identification information of the first data being used to identify the data table where the first data is located and the physical page of the first data in the data table; in response to the first data not being stored in the first memory, determining the starting log sequence number of the first log record in a metadata hash table based on the identification information of the first data, the metadata hash table storing the identification information of the first data, the starting log sequence number, and the length of the first data, the first log record corresponding to the first data, and the metadata hash table being stored in the first memory; determining the starting position of the first log record in the log file based on the starting log sequence number; determining the first log record in the log file based on the starting position; and replaying the first log record to read the first data from the first log record according to the length of the first data.

[0008] In one embodiment of this disclosure, the slave node further includes a log record hash table, which stores identification information of the first data and a second log record. The second log record corresponds to second data of a preset length in the master node, and the log record hash table is stored in the second memory of the slave node. Before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, the data processing method further includes: in response to the first data not being stored in the first memory, determining the identification information of the first data in the log record hash table; determining whether the second log record contains the first log record based on the identification information of the first data; and in response to the second log record containing the first log record and the minimum log sequence number value of the first log record being greater than or equal to the version number value of the physical page, replaying the first log record to read the first data.

[0009] In another embodiment of this disclosure, determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data includes: in response to the second log record not containing the first log record, or the minimum log sequence number value being less than the version number value, determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data.

[0010] In another embodiment of this disclosure, determining whether the second log record contains the first log record based on the identification information of the first data includes: in response to finding the identification information of the first data in the log record hash table, determining that the second log record contains the first log record; in response to not finding the identification information of the first data in the log record hash table, determining that the second log record does not contain the first log record.

[0011] In another embodiment of this disclosure, the metadata hash table also stores the termination log number of the first log record, which is used to indicate the replay termination position of the first log record.

[0012] In another embodiment of this disclosure, the method further includes: in response to the storage duration of metadata information in the metadata hash table being longer than a preset duration, asynchronously executing a first operation, the first operation being used to instruct the deletion of metadata information with a storage duration longer than the preset duration, the metadata information including the identification information of the first data, the starting log sequence number, the length of the first data, and the ending log sequence number; or, in response to the storage duration of a second log record in the log record hash table being longer than the preset duration, asynchronously executing a second operation, the second operation being used to instruct the deletion of the second log record with a storage duration longer than the preset duration.

[0013] In another embodiment of this disclosure, before determining the starting log number of the first log record in the metadata hash table based on the identification information of the first data, the method further includes: parsing the first log record in the log file to obtain metadata information; and storing the metadata information in the metadata hash table.

[0014] In yet another embodiment of this disclosure, the method further includes: determining whether the metadata hash table is referenced; and locking the metadata hash table in response to the metadata hash table not being referenced.

[0015] In another embodiment of this disclosure, the method further includes: splitting the metadata hash table according to the identification information stored in the metadata hash table to obtain multiple metadata hash sub-tables, all of which are in a locked state; correspondingly, determining the starting log sequence number of the first log record in the metadata hash table according to the identification information of the first data, including: determining the target metadata hash sub-table in the multiple metadata hash sub-tables according to the identification information of the first data; and determining the starting log sequence number in the target metadata hash sub-table after de-locking the target metadata hash sub-table.

[0016] In yet another embodiment of this disclosure, the method further includes: reading the first data from the first memory in response to the presence of first data stored in the first memory.

[0017] In yet another embodiment of this disclosure, the method further includes: performing a master-slave switchover operation in response to detecting an anomaly in the master node.

[0018] In a second aspect of the present disclosure, a medium is provided that stores computer execution instructions, which, when executed by a processor, are used to implement the data processing method of the first aspect.

[0019] In a third aspect of this disclosure, a data processing apparatus is provided, applied to a slave node of a cloud database. The cloud database further includes a master node, which is used to read and write data and generate read and write log records. The log files corresponding to the log records are stored in a shared storage medium of the cloud database. The slave node achieves data synchronization with the master node by replaying the log records. The data processing apparatus includes: a first determining module, used to determine whether the first data is stored in the first memory of the slave node in response to receiving a read request for first data. The first data is data written in the master node. The read request carries identification information of the first data, which is used to identify the data table where the first data is located and the data table in which the first data is stored. The table contains physical pages; a second determining module, used to determine the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, in response to the absence of first data in the first memory; the metadata hash table stores the identification information, starting log sequence number, and length of the first data, and the first log record corresponds to the first data, and the metadata hash table is stored in the first memory; a third determining module, used to determine the starting position of the first log record in the log file based on the starting log sequence number; a fourth determining module, used to determine the first log record in the log file based on the starting position; and a reading module, used to replay the first log record to read the first data from the first log record according to the length of the first data.

[0020] In a fourth aspect of the present disclosure, a computing device is provided, comprising: a processor and a memory connected to the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to implement the data processing method as described in the first aspect.

[0021] According to the data processing method, medium, apparatus, and computing device of this disclosure, a metadata hash table is stored in the first memory of the slave node. This metadata hash table stores identifier information of first data, the starting log sequence number of the first log record, and the length of the first data. Using the identifier information of the first data, the starting log sequence number corresponding to the identifier information can be determined in the metadata hash table. Based on the starting log sequence number, the starting position of the first log record in the log file can be determined. Thus, based on this starting position, the first log record can be located in the log file stored on the shared storage medium. By replaying the first log record, the first data can be read according to its length. Since the first memory of the slave node only stores a small metadata hash table, while the larger log file is stored on the shared storage medium, the usage of the first memory can be reduced. Even if a new physical page appears, the data in the new physical page can be accurately read from the shared storage medium through the metadata hash table, thereby ensuring that the user can read the data normally and accurately, providing a better user experience. Attached Figure Description

[0022] The above and other objects, features, and advantages of this disclosure will become readily apparent from the following detailed description of exemplary embodiments, taken in conjunction with the accompanying drawings. Several embodiments of this disclosure are illustrated in the drawings by way of example and not limitation, in which:

[0023] Figure 1 This is a schematic diagram of the architecture of PolarDB, a cloud-native database based on relevant technologies.

[0024] Figure 2 This is a schematic diagram of the architecture for redo replication based on relevant technologies;

[0025] Figure 3 A schematic diagram illustrating the correct physical page read from a node according to relevant technologies;

[0026] Figure 4 This is a diagram illustrating the process of reading past pages from a node based on relevant technologies.

[0027] Figure 5 This is a diagram illustrating the process of removing pages from nodes based on limitations imposed by relevant technologies.

[0028] Figure 6 This is a structural diagram of the insert type log record based on relevant technologies;

[0029] Figure 7 This is a schematic diagram illustrating an application scenario of a data processing method according to an embodiment of the present disclosure;

[0030] Figure 8This is a flowchart illustrating a data processing method according to an embodiment of the present disclosure;

[0031] Figure 9 This is a schematic diagram illustrating a user reading data according to an embodiment of the present disclosure;

[0032] Figure 10 This is a schematic diagram of the structure of a data table according to an embodiment of the present disclosure;

[0033] Figure 11 This is a schematic diagram of the structure of a storage medium according to an embodiment of the present disclosure;

[0034] Figure 12 This is a schematic diagram of the structure of a data processing apparatus according to an embodiment of the present disclosure;

[0035] Figure 13 This is a schematic diagram of the structure of a computing device according to an embodiment of the present disclosure.

[0036] In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts. Detailed Implementation

[0037] The principles and spirit of this disclosure will now be described with reference to several exemplary embodiments. It should be understood that these embodiments are given merely to enable those skilled in the art to better understand and implement this disclosure, and are not intended to limit the scope of this disclosure in any way. Rather, these embodiments are provided to make this disclosure more thorough and complete, and to fully convey the scope of this disclosure to those skilled in the art.

[0038] Those skilled in the art will recognize that embodiments of this disclosure can be implemented as a system, apparatus, device, method, or computer program product. Therefore, this disclosure can be specifically implemented in the following forms: entirely hardware, entirely software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.

[0039] According to embodiments of this disclosure, a data processing method, medium, apparatus, and computing device are proposed.

[0040] In this article, it is important to understand that the terms used have the following meanings:

[0041] MySQL: Currently the most popular open-source relational database, widely used in business scenarios such as the Internet, e-commerce, and finance. It adopts the traditional Shared-Nothing architecture, and the master node and slave node use Binlog for data replication and state synchronization.

[0042] Shared-Nothing architecture: A traditional database system implementation architecture that adopts a coupled model of compute nodes and storage nodes, that is, a complete database system consists of one compute node and one storage node, and multiple compute nodes do not share storage nodes.

[0043] Binlog is a binary file used to record user-generated Structured Query Language (SQL) information about database updates. For example, SQL statements that modify database tables and their contents are recorded in the binlog, but queries on databases, tables, etc., are not recorded.

[0044] Binlog replication: In traditional MySQL, data is synchronized between the master and slave nodes through the Binlog. Since the Binlog contains logical modification information of the database, it is also called logical replication.

[0045] Shared-Storage architecture: Unlike the Shared-Nothing architecture, the Shared-Storage architecture allows multiple compute nodes to access the same storage node (shared storage medium), enabling efficient expansion of compute nodes and storage nodes.

[0046] Cloud-native databases generally refer to relational databases based on shared storage. Most of them are developed by public cloud vendors based on MySQL. Currently used cloud-native databases include AWS Aurora, Aliyun PolarDB, CynosDB, etc.

[0047] InnoDB Buffer Pool: InnoDB is the storage engine for MySQL databases and can be used to implement transaction systems; the Buffer Pool is InnoDB's memory buffer, serving as a write buffer and read cache.

[0048] Transaction isolation levels: InnoDB offers four transaction isolation levels: Read Uncommitted, Read Committed (RC), Repeatable Read (RR), and Serializable. Online applications are typically configured with RC or RR.

[0049] RC: A transaction will not read data that has been modified but not committed by another concurrent transaction. This isolation level avoids "dirty reads" but cannot avoid "phantom reads" and "non-repeatable reads".

[0050] RR: It can guarantee that when the same data is read multiple times in the same transaction, the result returned is the same, which can avoid "dirty read" and "non-repeatable read".

[0051] Dirty read: refers to a transaction reading data that has not been committed by other transactions.

[0052] Phantom reads: When the amount of data changes before and after a transaction, users encounter unpredictable problems.

[0053] Non-repeatable reads refer to inconsistencies in queries within the same transaction.

[0054] Redo logs, also known as transaction logging, are a method used in relational databases to achieve transactional data persistence. For performance reasons, when a transaction is committed, the new data generated by the transaction (also called dirty pages, which are modified during transaction execution; when the content of a physical page in memory (also called a data page) is inconsistent with the content of a physical page on disk, we call this physical page a dirty page) is not flushed to storage. Instead, the log record is persisted first, and then the dirty pages are asynchronously flushed back. The log record documents every modification made by the transaction.

[0055] Log Sequence Number (LSN): Log records are generally identified using LSNs, which monotonically increase. Each dirty page also has a corresponding LSN, representing the log record corresponding to the last modification made to that page by a transaction. Therefore, the age of a page can also be determined by its LSN. When all dirty pages corresponding to log records before a certain LSN have been flushed to storage, the space occupied by log records before that LSN can be reclaimed, meaning that the checkpoint has been advanced to that LSN.

[0056] Mini-transaction (mtr) is a unit that guarantees the atomicity of changes to a number of Pages (InnoDB physical pages). (This refers to the "A" in ACID properties of the database system, meaning that during the process of modifying several Pages, either all changes succeed or all fail.) An mtr contains several log records, each corresponding to a specific Page.

[0057] Redo replication: Unlike traditional Binlog replication, it uses log records for data replication between master and slave nodes. The master node sends log records to the slave nodes, and the slave nodes update their in-memory state by applying the logs (Redo Apply). Because the log records contain physical modification information of the database, it is also called physical replication.

[0058] Transaction View (ReadView): This is a list that stores transaction IDs. It records which other transactions in MySQL are executing and have not yet been committed when the current transaction is executed. In other words, it records which active read and write transactions are currently in the system.

[0059] Data Definition Language (DDL): Used to define database objects, such as databases, tables, and fields.

[0060] Data Manipulation Language (DML): Used to perform CRUD operations on data in database tables.

[0061] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.

[0062] Furthermore, the number of any elements in the accompanying drawings is for illustrative purposes only and not for limitation, and any naming is for distinction only and has no limiting meaning.

[0063] The principles and spirit of this disclosure will be explained in detail below with reference to several representative embodiments. Invention Overview

[0065] The inventors have discovered that with the development of computer technology, there are more and more cloud-native databases developed based on MySQL, such as PolarDB. Figure 1 The PolarDB architecture diagram shown includes three MySQL compute nodes and one shared storage medium. The three MySQL compute nodes consist of one primary node and two read-only slave nodes. The shared storage medium contains n storage media, designated S1, S2, ..., Sn. The primary node accesses the shared storage medium remotely over the network in read-write mode, while the slave nodes access it in read-only mode. The compute nodes are typically cloud servers, and the shared storage medium is a distributed file system that can be mounted on multiple compute nodes, located remotely over the network and connected to the compute nodes via a storage network.

[0066] exist Figure 1In the PolarDB architecture shown, because the compute nodes and shared storage medium are separate, it is very easy to expand the compute nodes to increase read and write capabilities. For example, to expand write capabilities, only the CPU and memory specifications of the master node cloud host need to be increased, without needing to determine whether the physical server hosting the cloud host has sufficient storage space. To expand read capabilities, more slave nodes can be created; current cloud-native databases generally support a maximum of 15 slave nodes. Since all compute nodes access the same shared storage medium, there is no need to copy stored data when expanding read capabilities, greatly saving storage costs. In addition, users use the storage space on the shared storage medium on demand, paying less for less use and more for more use, which can further save storage costs.

[0067] In order to Figure 1 The PolarDB architecture shown illustrates that slave nodes provide query services. This requires synchronizing the transaction state of the master node to the slave nodes and establishing a transaction view based on this, achieving RR and RC transaction isolation levels. Furthermore, it's necessary to synchronize database or table metadata operations (DDL), as well as user and permission changes, to the slave nodes. Therefore, master-slave synchronization is required based on Redo replication; that is, replaying log records ensures that the transaction state and various metadata on the slave nodes remain consistent with the master node.

[0068] The architecture diagram for Redo replication can be as follows: Figure 2 As shown, the master node can include a message receiving thread, a message sending thread, a log persistence thread, and a buffer pool. The slave node can include a message sending thread, a message receiving thread, a log replay thread, and a buffer pool. The shared storage medium includes a data storage medium and a log storage medium. During redo replication, the master node writes changed data to its own buffer pool and synchronizes the changed data to the data storage medium. Upon transaction commit, the log persistence thread writes log records to the log storage medium. The master node informs the slave node of new log records via the message sending thread. The slave node receives the message about the new log records via the message receiving thread and notifies the log replay thread. The log replay thread reads the log records from the log storage medium and performs parallel replay of the log records, thus storing the changed data from the data storage medium to its own buffer pool, allowing the slave node to read the changed data from the buffer pool. The slave node notifies the master node of the log replay completion message via the message sending thread; this message includes operations such as transaction state synchronization, DDL, DML, user, and permission settings. The master node receives the log replay completion message via the message receiving thread and performs subsequent operations.

[0069] Through such Figure 2 The redo replication architecture diagram shown guarantees that the slave nodes read the correct version of the page content. Reading the correct version of the page from the slave nodes can be done as follows: Figure 3 As shown in the diagram, the LSN of physical page P1 in the master node is 100, the LSN of physical page P1 stored in the shared storage medium is 100, and the LSN of physical page P1 read from the shared storage medium is also 100. When the master node modifies physical page P1 to obtain physical page P2, the LSN of physical page P2 is 200. The master node stores the log record with LSN = 200 in the shared storage medium. Before physical page P2 is flushed to disk, after receiving the message from the master node that a new log record has been added, the slave node reads the newly added log record with LSN = 200 from the shared storage medium. After replaying the log record, it obtains the latest physical page P2 with LSN 200. This ensures that the memory states of the master node and the slave node are consistent.

[0070] Figure 3 In the illustrated process, if the slave node has insufficient space in its buffer pool, it will discard the latest physical page P2 that has been replayed. If the slave node needs to read the page from the shared storage medium again later, since the master node has not flushed the latest physical page P2 to the shared storage medium, it will read the old page P1 from the shared storage medium instead of the latest physical page P2. In other words, the old page appears, such as... Figure 4 As shown.

[0071] At time T1, the master node modifies the LSN of physical page P1 from 100 to 200, obtains the latest physical page P2 with LSN 200, and stores the log with LSN=200 in the shared storage medium; at this time, the slave node reads physical page P1 with LSN=100 from the shared storage medium.

[0072] At time T2, the master node notifies the slave node that new logs have been generated;

[0073] At time T3, the slave node reads and replays the log of LSN=200 from the shared storage medium and obtains the latest physical page P2 of LSN=200;

[0074] At time T4, due to insufficient storage space in the slave node's buffer pool, the latest physical page P2 is evicted from the buffer pool;

[0075] At time T5, when the slave node reads a page again, the latest physical page P2 has been evicted from the buffer pool. Therefore, the slave node needs to read the page from the shared storage medium. However, the master node has not flushed the latest physical page P2 to the shared storage medium for a long time. As a result, the page read by the slave node from the shared storage medium is not the latest physical page P2, but the old page P1. This causes the slave node to read incorrect page data.

[0076] To address the issue of retrieving past pages from a node, two solutions have been proposed in related technologies. The first solution is to restrict page eviction from the node, such as... Figure 5 As shown, the master node sets a checkpoint between time points T1 and T2, and the slave node sets a replay point between time points T4 and T5. Before the replay point, the master node allows page flushing to disk; after the replay point, the master node does not allow page flushing to disk. Before the checkpoint, the slave node allows page replacement; after the checkpoint, the slave node does not allow page replacement. That is, in the slave node, if the LSN of a physical page is greater than the checkpoint of the master node, the slave node cannot replace the physical page. Although this scheme can solve the problem of slave nodes reading past pages, because it restricts the replacement of pages by slave nodes, it may cause the buffer pool memory of the slave nodes to swell. In extreme scenarios, it may cause the buffer pool memory of the slave nodes to run out, resulting in blocking users from reading new physical pages and causing user data reading anomalies.

[0077] The second approach is to cache log records after the checkpoint on the master node in a log record hash table. This way, if a slave node reads a past page, it can use Redo Apply to generate the latest physical page version. While this approach solves the problem of slave nodes reading past pages, it requires caching log records after the checkpoint. Log records generally consist of three parts: log type (Type), metadata such as space ID and page number, and the corresponding data body. The data in the body is unpredictable; different types correspond to different body data, and the body occupies a large portion of the log record's space. Figure 6 As shown, the node uses the Meta section of the log record to find the physical page that needs to be replayed, and uses the Body section of the log record to perform the specific replay operation to read the data.

[0078] according to Figure 6 As can be seen, the main content of the log records is in the Body section, which occupies the majority of the memory of the log record hash table. Furthermore, the master node needs to generate log records first before the slave nodes can replay them. The slave nodes take a long time to replay log records, which is slow. Therefore, there is a certain gap between the checkpoints of the master node and the replay points of the slave nodes. This results in a very large amount of log record data that needs to be cached, requiring a large amount of memory to maintain the log record hash table. In extreme scenarios, this can lead to MySQL memory exhaustion (Out Of Memory, or OOM), which can block users from reading new physical pages and cause abnormal user data reading issues.

[0079] Therefore, this disclosure proposes a data processing method in which a slave node can parse log records to obtain metadata information such as the identifier of the data to be read, the starting log sequence number of the corresponding log record, and the length of the data to be read. This metadata information is stored in a metadata hash table, which is then stored in the slave node's buffer pool. When a slave node receives a read request for data to be read, it determines the identifier of the data to be read carried in the read request. Then, it reads the metadata hash table corresponding to the log record from its own buffer pool to determine the starting log sequence number corresponding to the identifier of the data to be read. Based on the starting log sequence number, it can determine the starting position of the log record corresponding to the data to be read in the log file, and based on the starting position, locate the log record in the log file on the shared storage medium. By replaying the log record, the data to be read can be retrieved according to its length.

[0080] Since slave nodes do not need to restrict page eviction and do not store the body portion of log records in the slave node's buffer pool, the memory usage of the slave node's buffer pool can be reduced. This avoids the problems of the slave node's buffer pool running out of memory and MySQL memory exhaustion. Therefore, the data processing method proposed in this disclosure can solve the problem of slave nodes reading past pages while ensuring that users can read data normally and accurately, thus providing users with a better experience.

[0081] After introducing the basic principles of this disclosure, various non-limiting embodiments of this disclosure will be described in detail below.

[0082] Application Scenarios Overview

[0083] First refer to Figure 7 , Figure 7 This diagram illustrates an application scenario of a data processing method according to an embodiment of the present disclosure. The data processing method provided by the present disclosure can be applied to... Figure 7 The data processing system shown may include a master node, slave nodes, and shared storage media. The master node includes master node memory and a log sending thread. The master node memory caches user-written data and log records generated during data writing. The slave nodes include a first memory, a second memory, a log receiving thread, a replay coordination thread, a user read thread, and a memory reclamation thread. The first memory stores the slave node's cached data and a metadata hash table, while the second memory stores a log record hash table. The shared storage media includes data storage media and log storage media.

[0084] In the above application scenario, when a user performs a write operation on the master node, the master node generates a first log record corresponding to the first data, stores the first data and the first log record in the master node's memory, then sends the first data to the data storage medium to store the data, and sends the first log record to the log storage medium to store the first log record. After generating the first log record, the master node notifies the slave nodes of the newly added log record through a log sending thread.

[0085] In the above application scenario, the slave node receives messages about newly added log records through a log receiving thread to read the first log record from the log storage medium. The replay coordination thread in the slave node parses the first log record to obtain metadata information such as the identifier information of the first data, the starting log sequence number of the first log record, and the length of the first data, and stores the metadata information in a metadata hash table. In addition, the replay coordination thread can also retrieve the second log record corresponding to the second data of a preset length from the master node in the log storage medium and store the second log record in a log record hash table.

[0086] In the above application scenario, when a user performs a read operation, they initiate a read request to read the first piece of data, which carries the identifier information of the first piece of data. If the master node is functioning normally, the first piece of data can be read directly from the master node's memory based on its identifier information.

[0087] In the above application scenario, if the master node malfunctions, the first data needs to be read from the slave node. That is, the slave node's user read thread determines, based on the identifier information of the first data, whether the cached data stored in the first memory includes the first data, i.e., whether the first data is stored in the first memory. If the first data is stored in the first memory, it is read directly from the first memory. If the first data is not stored in the first memory, it determines whether the first log record can be read from the log record hash table in the second memory. If the second log record contains the first log record, the first log record is replayed to read the first data. If the second log record does not contain the first log record, the starting log sequence number corresponding to the identifier information of the first data is determined in the metadata hash table, and the starting position of the first log record in the log file is determined based on the starting log sequence number. Then, the first log record is located in the log file based on the starting position, allowing it to be replayed and read from the first log record according to its length. Returning the first data to the user allows the user to read the latest data.

[0088] In the above application scenario, to reduce the overflow issues of the first and second memory, expired resources in the metadata hash table and log record hash table can be cleaned up by the memory reclamation thread of the slave node. That is, metadata information stored in the metadata hash table for a longer period than a preset time, and second log records stored in the log record hash table for a longer period than a preset time, are deleted.

[0089] In the above application scenario, since the log record hash table stores the second log record, and the length of the second data corresponding to the second log record is preset, the size of the second memory is controllable. Furthermore, the metadata hash table stores metadata information, which occupies very little memory, thus reducing the usage of the first memory. In addition, the memory reclamation thread of the slave node will reclaim the first and second memory, further reducing the usage of the first and second memory. This prevents the slave node from running out of memory and the MySQL memory from being exhausted. This not only solves the problem of the slave node reading past pages, but also ensures that users can read data normally and accurately, bringing a better user experience.

[0090] Exemplary methods

[0091] The following is combined Figure 7 Application scenarios, refer to Figure 8 This document describes a data processing method according to exemplary embodiments of the present disclosure. It should be noted that this data processing method is applied to a slave node of a cloud database. Furthermore, the above application scenarios are shown only to facilitate understanding of the spirit and principles of this disclosure, and the embodiments of this disclosure are not limited in any way. Rather, the embodiments of this disclosure can be applied to any applicable scenario.

[0092] Figure 8 A flowchart illustrating a data processing method according to an embodiment of the present disclosure is shown. Figure 8 The data processing method includes the following steps:

[0093] S801: In response to receiving a read request for the first data, determine whether the first data is stored in the first memory of the slave node. The first data is the data written in the master node. The read request carries the identification information of the first data.

[0094] In this step, the cloud database also includes a master node, which is used to read and write data and generate read and write log records. The log files corresponding to the log records are stored in the shared storage medium of the cloud database. The slave nodes synchronize data with the master node by replaying the log records.

[0095] Specifically, the first memory of a slave node can be the slave node's buffer pool. Since the storage space of the first memory is limited, the first memory may or may not store the first data. Therefore, when reading the first data, it is necessary to determine whether the first data is stored in the first memory.

[0096] Optionally, the identification information of the first data is used to identify the data table where the first data resides and the physical page of the first data within the data table. When a user needs to read the first data, they can send a read request carrying the identification information of the first data to the slave node, so that the slave node can determine that the user needs to read the first data based on the identification information of the first data.

[0097] S802: In response to the fact that the first data is not stored in the first memory, determine the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data.

[0098] In this step, the metadata hash table stores the identifier information of the first data, the starting log sequence number of the first log record, and the length of the first data. The first log record corresponds to the first data, and the metadata hash table is stored in the first memory.

[0099] Specifically, after writing the first piece of data, the master node generates a first log record corresponding to that first piece of data. The metadata hash table stores the identifier information for the first piece of data, which can be space_id and page_no. Space_id identifies the data table where the first piece of data resides, and page_no identifies the physical page where the first piece of data resides within that data table. The starting log sequence number is the start_lsn information of the first log record, and the length of the first piece of data is the length of the body portion of the first log record.

[0100] In one optional implementation, if the first data is not stored in the first memory, the first data needs to be read from the shared storage medium. Therefore, it is necessary to query the metadata hash table for the starting log sequence number corresponding to the identification information of the first data and the length of the first data corresponding to the identification information of the first data, based on the identification information of the first data carried in the read request.

[0101] Optionally, in the metadata hash table, the identifier information of the first data is stored as a key, and the starting log sequence number and the length of the first data are stored as values. After receiving a read request, the identifier information of the same first data as in the read request can be determined in the metadata hash table, and then the starting log sequence number and the length of the first data corresponding to the identifier information of the first data can be determined in the metadata hash table.

[0102] Optionally, the starting log sequence number can be represented by start_lsn, which indicates the offset of the first log record in the log file from the beginning.

[0103] S803: Determine the starting position of the first log record in the log file based on the starting log sequence number.

[0104] In this step, after determining the starting log number of the first log record, that is, determining the starting position offset of the first log record in the log file, the starting position of the first log record in the log file can be determined.

[0105] S804: Determine the first log record in the log file based on the starting position.

[0106] In this step, after determining the starting position of the first log record in the log file, the first log record can be located in the log file according to the starting position.

[0107] Optionally, since the log file is stored in a shared storage medium, the first log record is also stored in the shared storage medium.

[0108] S805: Replay the first log record to read the first data from the first log record based on the length of the first data.

[0109] In this step, after locating the first log record in the shared storage medium, the slave node can replay the first log record. Furthermore, the length of the first data has been determined, which is also the length of the body portion of the first log record. Since the byte type of the body portion in the first log record differs from the byte type of the other portions, the body portion can be determined from the first log record based on its byte type. Then, based on the length of the body portion, the content of the body portion can be read from the first log record, thus reading the first data, thereby achieving data synchronization between the slave and master nodes.

[0110] The data processing method disclosed herein stores a metadata hash table in the first memory of the slave node. This metadata hash table stores the identifier information of the first data, the starting log sequence number of the first log record, and the length of the first data. Using the identifier information of the first data, the starting log sequence number corresponding to that identifier can be determined in the metadata hash table. Based on the starting log sequence number, the starting position of the first log record in the log file can be determined. Thus, based on this starting position, the first log record can be located in the log file stored on the shared storage medium. By replaying the first log record, the first data can be read according to its length. Since the first memory of the slave node only stores a small metadata hash table, while the larger log file is stored on the shared storage medium, the memory usage of the first memory can be reduced. Even if a new physical page appears, the data in the new physical page can be accurately read from the shared storage medium using the metadata hash table, thereby ensuring that users can read data normally and accurately, providing a better user experience.

[0111] In one embodiment of this disclosure, the slave node further includes a log record hash table, which stores identification information of the first data and a second log record. The second log record corresponds to second data of a preset length in the master node, and the log record hash table is stored in the second memory of the slave node. Before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, the data processing method further includes: in response to the first data not being stored in the first memory, determining the identification information of the first data in the log record hash table; determining whether the second log record contains the first log record based on the identification information of the first data; and in response to the second log record containing the first log record and the minimum log sequence number value of the first log record being greater than or equal to the version number value of the physical page, replaying the first log record to read the first data.

[0112] In this embodiment, the second memory is a separate block of memory allocated on the slave node, distinct from the first memory. In the log record hash table, the identifier information of the first data is stored as a key, and the second log record is stored as a value. The identifier information in the log record hash table is the same as the identifier information in the metadata hash table.

[0113] Specifically, by storing a second data of a preset length in the second memory, it is possible to query whether the first data is stored in the second memory, based on the identifier information of the first data, even if the first data is not stored in the first memory. That is, by using the identifier information of the first data, the corresponding first log record is located in the second log record. If the second log record contains the first log record, and the minimum log sequence number of the first log record is greater than or equal to the version number of the physical page, the first data can be read directly from the second memory by replaying the second log record. Since the speed at which a slave node reads data from memory is greater than the speed at which it reads data from shared storage media, the latency when the slave node reads the first data can be reduced, thus improving the efficiency of the slave node in reading the first data.

[0114] For example, the physical page containing the first data is P, and the version number of physical page P is 150. When reading the first data, the system first searches for it in the first memory. If the first data is not found in the first memory, it queries the log record hash table in the second memory. If the first log record can be located in the log record hash table using the identifier information of the first data, the minimum log number (LSN) of the first log record can be determined. If the minimum LSN is greater than or equal to 150, it means that the log record hash table contains all log records of physical page P. Therefore, the Body part of the first log record can be directly retrieved from the second memory. Thus, the first data can be read by replaying the first log record without accessing the metadata hash table again.

[0115] Optionally, the preset length can be a preset length starting from the checkpoint of the master node, and this checkpoint can be configured with an adjustable value, i.e., checkpoint+M, where M is an adjustable value. If the storage space of the second memory is sufficient and the business is sensitive to read latency, the value of M can be reduced, thus storing enough body data; if the storage space of the second memory is insufficient, or the business is not sensitive to read latency, the value of M can be increased. Therefore, while ensuring that the second memory is sufficient, the I / O rate of reading the first data from the slave node can be reduced as much as possible, thereby reducing read latency.

[0116] In another embodiment of this disclosure, determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data includes: in response to the second log record not containing the first log record, or the minimum log sequence number value being less than the version number value, determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data.

[0117] In this embodiment, if the first data is not stored in the first memory, the second log record does not contain the first log record, or the minimum log sequence number of the first log record is less than the version number of the physical page, then it is determined that the first data cannot be read from either the first memory or the second memory. Therefore, the first data needs to be read from the shared storage medium.

[0118] Specifically, by using the identification information of the first data, it can be determined whether the identification information of the first data can be found in the metadata hash table. If the identification information of the first data can be found in the metadata hash table, the starting log number of the first log record can be determined based on the identification information of the first data, and the starting position of the first log record in the log file can be determined based on the starting log number. Thus, the first log record can be located in the log file based on the starting position, and the first data can be read by replaying the first log record.

[0119] Optionally, a "dual-hash" mechanism is introduced, namely, a metadata hash table and a redo hash table. Since the memory-intensive log files are stored in shared storage, meaning the body of the first log record is stored there, and the metadata hash table occupies very little memory, the memory usage of the first record can be reduced. This avoids the problem of the slave node running out of memory, thus resolving the "past page" issue and ensuring that users can read the first data correctly and accurately. By allocating a second memory slot on the slave node to store the redo hash table, if the first data can be read from the redo hash table, the read latency of the slave node reading the first data can be reduced, providing a better user experience. Based on the dual-hash mechanism, user data reading can be performed as follows... Figure 9 As shown.

[0120] Figure 9 A schematic diagram illustrating a user reading data according to an embodiment of the present disclosure is shown. Figure 9 In the first memory location, the cached data and metadata hash table of the slave nodes are stored; in the second memory location, the log record hash table is stored. The log record hash table stores multiple log records in a linked list format (in... Figure 9 In the table, log record 1, log record 2, ..., log record n ​​are used to represent log records. Multiple metadata records are stored in a linked list format in the metadata hash table. Figure 9In the metadata information (represented by metadata information 1, metadata information 2, ..., metadata information n), when a user initiates a read request, if the cached data of the slave node in the first memory includes the first data, that is, the first data is stored in the first memory, then the first data is read directly; if the first data is not stored in the first memory, then it is determined whether the first log record is stored in the log record hash table, that is, whether the first log record is included among multiple log records; if the first log record is included among multiple log records, then the first log record is replayed directly to read the first data; if the first log record is not included among multiple log records, then it is determined whether the corresponding identifier information can be found in the metadata hash table based on the identifier information of the first data. If the corresponding identifier information can be found in the metadata hash table, then the first log record is determined in the shared storage medium based on the metadata information corresponding to the identifier information, and thus the first data is read by replaying the first log record.

[0121] In one alternative implementation, if the first data is not stored in the first memory, the slave node can use the Runtime Apply mechanism to push the ongoing replay of the first log record to the slave node's user read thread. In this way, when the user actually accesses the physical page where the first data is located (the slave node responds to the read request for the first data), the first log record is replayed in the second memory or in the shared storage medium. This can reduce the waste of network bandwidth resources caused by invalid replay operations and ensure that the user reads the correct data.

[0122] In another embodiment of this disclosure, determining whether the second log record contains the first log record based on the identification information of the first data includes: in response to finding the identification information of the first data in the log record hash table, determining that the second log record contains the first log record; in response to not finding the identification information of the first data in the log record hash table, determining that the second log record does not contain the first log record.

[0123] In this embodiment, the identifier information of the first data stored in the log record hash table is the same as the identifier information of the first data stored in the metadata hash table. If the identifier information of the first data can be found in the log record hash table, it is assumed that the log record hash table stores the first log record corresponding to the first data. That is, the second log record contains the first log record, so the first log record can be directly replayed to read the first data. Since the log record hash table is stored in the second memory, the efficiency of reading the first data in the second memory is higher than that of reading the first data in the shared storage medium. Therefore, the read latency of reading the first data from the slave node can be reduced, providing a better user experience.

[0124] In the above embodiments, if the identifier information of the first data cannot be found in the log record hash table, it is assumed that the first log record corresponding to the first data is not stored in the log record hash table, that is, the second log record does not contain the first log record. In this case, since the first data cannot be read from the first memory and the second memory, it needs to be read from the shared storage medium. The shared storage medium stores the log file, which occupies a large amount of memory, i.e., the body part of the first log record, and the metadata hash table occupies very little memory. Therefore, the memory usage of the first memory can be reduced, thus avoiding the problem of the slave node running out of memory. This solves the "past page" problem and ensures that the user can read the first data normally and accurately.

[0125] In another embodiment of this disclosure, the metadata hash table also stores the termination log number of the first log record, which is used to indicate the replay termination position of the first log record.

[0126] In this embodiment, each physical page has a corresponding version number. The first log record is replayed on the physical page. After the first log record replay is complete, the value of the termination log sequence number needs to be assigned to the version number of the physical page where the first data resides, indicating that the first log record has been replayed to the physical page where the first data resides. When other data needs to be read subsequently, the termination log sequence number can be used to determine which physical page the previous replay ended on, and then the log record replay can continue, without having to repeat the replay of the first log record from the starting log sequence number. Therefore, the problem of low data reading efficiency caused by repeated log record replay can be reduced, as can the problem of data reading errors caused by repeated log record replay can also be reduced.

[0127] In another embodiment of this disclosure, the data processing method further includes: asynchronously executing a first operation in response to the storage duration of metadata information in the metadata hash table being longer than a preset duration, the first operation being used to instruct the deletion of metadata information with a storage duration longer than the preset duration, the metadata information including the identification information of the first data, the starting log sequence number, the length of the first data, and the ending log sequence number; or, asynchronously executing a second operation in response to the storage duration of a second log record in the log record hash table being longer than the preset duration, the second operation being used to instruct the deletion of the second log record with a storage duration longer than the preset duration.

[0128] In this embodiment, although the metadata hash table occupies very little memory, the storage space of the first memory is also limited. If the storage space of the first memory is not maintained in a timely manner, insufficient storage space will result due to excessive storage of the metadata hash table. Therefore, expired memory resources in the first memory can be reclaimed, that is, metadata information with a storage duration longer than a preset duration can be deleted to save storage resources in the first memory. Similarly, the storage space of the second memory is also limited. Therefore, expired memory resources in the second memory can be reclaimed, that is, second log records with a storage duration longer than a preset duration need to be deleted to save storage resources in the second memory.

[0129] Optionally, to improve the device utilization of slave nodes, expired memory resources can be asynchronously reclaimed by adding a background thread. That is, the operation of reclaiming expired memory resources and the operation of reading the first data are executed asynchronously.

[0130] In another embodiment of this disclosure, before determining the starting log number of the first log record in the metadata hash table based on the identification information of the first data, the data processing method further includes: parsing the first log record in the log file to obtain metadata information; and storing the metadata information in the metadata hash table.

[0131] In this embodiment, metadata information is pre-stored in a metadata hash table. After generating the first log record, the master node sends a message to the slave nodes to indicate that a new log record has been generated. Upon receiving this message, the slave nodes read the first log record from the shared storage medium, then parse it to obtain metadata information such as the identifier of the first data, the starting log sequence number, the length of the first data, and the ending log sequence number. The identifier of the first data includes the identifier of the data table where the first data resides and the identifier of the physical page where the first data resides. The structure of the data table is as follows... Figure 10 As shown.

[0132] Figure 10 A schematic diagram of the structure of a data table according to an embodiment of the present disclosure is shown. Figure 10In this context, a data table includes multiple physical pages, and each physical page includes multiple caches. Each cache stores information about a log record, including the log record's state, the identifier of the data table containing the data in the log record, the identifier of the physical page containing the data in the log record, and a list of modification information corresponding to the data in the log record. Each modification information in the list includes the type of the log record, the data length corresponding to the data in the log record, the start log sequence number, and the end log sequence number of the log record. The data of the log record is not stored in the data table. The data of the log record can be read from the shared storage medium through the start log sequence number of the log record.

[0133] In the above embodiments, after obtaining metadata information such as the identifier information, start log sequence number, length of the first data, and end log sequence number, the metadata information can be stored in a metadata hash table. This way, when a read request for the first data is subsequently received, the first log record can be replayed in the shared storage medium based on the metadata information stored in the metadata hash table, thereby retrieving the first data. Since the metadata hash table occupies very little memory, there is no problem of the slave node running out of memory, thus solving the "past page" problem and ensuring that the user can read the first data normally and accurately.

[0134] Optionally, after parsing the first log record in the log file to obtain metadata information, in addition to storing the metadata information in the metadata hash table, the identification information of the first data can also be stored separately so that users can obtain the identification information of the first data. In this way, when users need to read the first data, they can send the identification information of the first data along with the read request to the slave node so that the slave node can query the identification information of the first data in the metadata hash table.

[0135] In another embodiment of this disclosure, the data processing method further includes: determining whether the metadata hash table is referenced; and locking the metadata hash table in response to the metadata hash table not being referenced.

[0136] In this embodiment, if the metadata hash table is being accessed by one or more threads, data conflicts may occur. For example, one or more threads may be reading data that has already been modified by other threads, i.e., there is a concurrency conflict problem. To reduce the concurrency conflict problem of the metadata hash table, a reference counting lock-free approach can be adopted to determine the number of references to the metadata hash table. The reference count can then be used to determine whether locking is required for the metadata hash table.

[0137] Specifically, if the reference count is not 0, it means that a thread is currently accessing the metadata hash table. To reduce concurrency conflicts, the metadata hash table cannot be modified, and to ensure that the thread currently accessing the metadata hash table can access it normally, the metadata hash table cannot be locked. If the reference count is 0, it means that no thread is currently accessing the metadata hash table. In this case, the metadata hash table can be locked, so that no thread can access the metadata hash table and modify it, thereby reducing concurrency conflicts. Thread access to the metadata hash table can also be referred to as thread referencing the metadata hash table.

[0138] In another embodiment of this disclosure, the data processing method further includes: splitting the metadata hash table according to the identification information stored in the metadata hash table to obtain multiple metadata hash sub-tables, all of which are in a locked state; correspondingly, determining the starting log sequence number of the first log record in the metadata hash table according to the identification information of the first data, including: determining the target metadata hash sub-table in the multiple metadata hash sub-tables according to the identification information of the first data; and determining the starting log sequence number in the target metadata hash sub-table after de-locking the target metadata hash sub-table.

[0139] In this embodiment, locking the metadata hash table may lead to lock contention, meaning that when multiple threads simultaneously request access to the locked metadata hash table, they may encounter a situation where each thread waits for the lock to be released. To reduce lock contention, a delocking process can be performed. Specifically, the metadata hash table is split according to the identifier information stored within it, resulting in multiple metadata hash sub-tables, each with its own identifier. Then, all of these sub-tables are locked, resulting in multiple locked metadata hash sub-tables.

[0140] In the above embodiments, when determining the starting log sequence number in the metadata hash table, the target metadata hash sub-table can be located among multiple metadata hash sub-tables based on the identifier information of the first data. After de-locking the target metadata hash sub-table, it can be accessed to determine the starting log sequence number corresponding to the identifier information of the first data. This allows the starting position of the first log record in the log file to be determined based on the starting log sequence number, and the first log record can be located in the log file based on the starting position. This enables the replay of the first log record in the shared storage medium, allowing the first data to be read from the first log record according to its length.

[0141] In yet another embodiment of this disclosure, the data processing method further includes: reading the first data from the first memory in response to the presence of first data stored in the first memory.

[0142] In this embodiment, since reading the first data from the slave node's memory is more efficient than reading it from the shared storage medium, the slave node's first memory can be accessed first. If the first data is stored in the first memory, it can be read directly, thereby reducing the read latency of the first data. If the first data is not stored in the first memory, the second memory can be accessed. If the first data is also not stored in the second memory, it needs to be read from the shared storage medium.

[0143] In yet another embodiment of this disclosure, the data processing method further includes: performing a master-slave switchover operation in response to detecting an anomaly in the master node.

[0144] In this embodiment, to free the management of cluster node roles in the cloud database from manual operation, the Raft algorithm can be introduced into the cloud database to automate the management of cluster node roles. In the cloud database cluster, the master node corresponds to the leader role in the Raft protocol, and the slave nodes correspond to the follower role. When the master node fails, the slave node needs to switch over to become the new master node.

[0145] Specifically, the new master node needs to provide read and write services. While providing these services, the new master node only accesses the metadata hash table and replays the first log record when a user needs to access the latest page. Since the slave node has already switched to the new master node, the new master node can asynchronously perform the operation of cleaning up and deleting the metadata information corresponding to the first log record after the first log record replay is complete, thus shortening the master-slave switchover time.

[0146] The data processing method proposed in this disclosure, based on the open-source MySQL database, proposes a physical replication scheme based on a metadata hash table. Specifically, physical replication is divided into three stages: log record parsing stage, cached page replay stage, and metadata hash table maintenance stage. In the log record parsing stage, the slave node only records the metadata information of the log records during parsing. In the cached page replay stage, physical pages in the slave node's memory, i.e., cached pages, can be replayed. For physical pages not in the slave node's memory, the Runtime Apply mechanism ensures that users read the correct data. In the metadata hash table maintenance stage, the slave node maintains the metadata information recorded in the log record parsing stage in a global metadata hash table, thereby saving slave node memory. This prevents MySQL memory exhaustion, eliminates the need for slave nodes to restrict physical page eviction, and avoids slave node memory bloat. Therefore, new physical pages can be read normally, ensuring that users read the correct data.

[0147] Furthermore, the data processing method proposed in this disclosure also introduces a "dual-hash" mechanism, namely, a metadata hash table and a log record hash table. Since the memory-intensive log files are stored in a shared storage medium, while the metadata hash table occupies very little memory, the memory usage of the slave nodes can be reduced, thus preventing the slave nodes from running out of memory and resolving the "past page" problem. This ensures that users can read data normally and accurately. By allocating a separate memory block in the slave node to store the log record hash table, if data can be read from the log record hash table, the read latency of the slave node can be reduced, providing a better user experience.

[0148] The data processing method proposed in this disclosure can be used with InnoDB. Because it involves minimal intrusion into the InnoDB kernel, requires fewer modifications, and does not alter the Redo physical format, it offers better operability.

[0149] Exemplary media

[0150] After introducing the methods of exemplary embodiments of this disclosure, the following references are made. Figure 11 The storage medium of the exemplary embodiments of this disclosure will be described.

[0151] refer to Figure 11As shown, the storage medium 1100 stores a program product for implementing the above-described method according to an embodiment of the present disclosure. This program product may be a portable compact disc read-only memory (CD-ROM) and includes computer-executable instructions, and can run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto.

[0152] The program product may employ any combination of one or more readable media. A readable media may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0153] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying readable program code. This propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium.

[0154] Program code for performing the operations disclosed herein can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java and C++, and conventional procedural programming languages ​​such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing devices can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN).

[0155] Exemplary device

[0156] Having introduced the medium of exemplary embodiments of this disclosure, the following references are made to... Figure 12The data processing apparatus of the exemplary embodiments of this disclosure is described below, used to implement the methods in any of the above method embodiments. Its implementation principle and technical effects are similar, and will not be repeated here. It should be noted that this data processing apparatus is applied to a slave node of a cloud database. The cloud database also includes a master node, which is used for reading and writing data and generating read / write log records. The log files corresponding to the log records are stored in the shared storage medium of the cloud database. The slave node achieves data synchronization with the master node by replaying the log records.

[0157] Figure 12 A schematic diagram of the structure of a data processing apparatus according to an embodiment of the present disclosure is shown. Figure 12 The data processing device 1200 includes:

[0158] The first determining module 1201 is used to respond to receiving a read request for first data and determine whether the first data is stored in the first memory of the slave node. The first data is the data written in the master node. The read request carries the identification information of the first data. The identification information of the first data is used to identify the data table where the first data is located and the physical page of the first data in the data table.

[0159] The second determining module 1202 is used to respond to the fact that the first data is not stored in the first memory, and determine the starting log sequence number of the first log record in the metadata hash table according to the identification information of the first data. The metadata hash table stores the identification information, starting log sequence number and length of the first data. The first log record corresponds to the first data. The metadata hash table is stored in the first memory.

[0160] The third determining module 1203 is used to determine the starting position of the first log record in the log file based on the starting log sequence number;

[0161] The fourth determination module 1204 is used to determine the first log record in the log file based on the starting position;

[0162] The reading module 1205 is used to replay the first log record in order to read the first data from the first log record according to the length of the first data.

[0163] Optionally, the slave node further includes a log record hash table, which stores the identification information of the first data and the second log record. The second log record corresponds to the second data of a preset length in the master node. The log record hash table is stored in the second memory of the slave node. The data processing device 1200 further includes: a first processing module (not shown), configured to, before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, determine the identification information of the first data in the log record hash table in response to the first data not being stored in the first memory; determine whether the second log record contains the first log record based on the identification information of the first data; and, in response to the second log record containing the first log record and the minimum log sequence number value of the first log record being greater than or equal to the version number value of the physical page, replay the first log record to read the first data.

[0164] Optionally, the second determining module 1202 is used to determine the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data in the following manner: in response to the second log record not containing the first log record, or the minimum log sequence number value being less than the version number value, the starting log sequence number of the first log record is determined in the metadata hash table based on the identification information of the first data.

[0165] Optionally, the first processing module is configured to determine whether the second log record contains the first log record based on the identification information of the first data in the following manner: in response to finding the identification information of the first data in the log record hash table, it is determined that the second log record contains the first log record; in response to not finding the identification information of the first data in the log record hash table, it is determined that the second log record does not contain the first log record.

[0166] Optionally, the metadata hash table also stores the termination log number of the first log record, which is used to indicate the replay termination position of the first log record.

[0167] Optionally, the data processing device 1200 further includes: a first execution module (not shown), configured to asynchronously execute a first operation in response to a storage duration of metadata information in the metadata hash table exceeding a preset duration, the first operation being configured to instruct the deletion of metadata information with a storage duration exceeding the preset duration, the metadata information including the identification information of the first data, the start log sequence number, and the length and end log sequence number of the first data; or, in response to a storage duration of a second log record in the log record hash table exceeding the preset duration, asynchronously execute a second operation, the second operation being configured to instruct the deletion of the second log record with a storage duration exceeding the preset duration.

[0168] Optionally, the data processing device 1200 further includes: a storage module (not shown), used to parse the first log record in the log file to obtain metadata information before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data; and to store the metadata information in the metadata hash table.

[0169] Optionally, the data processing apparatus 1200 further includes: a second processing module (not shown) for determining whether the metadata hash table is referenced; and locking the metadata hash table in response to the metadata hash table not being referenced.

[0170] Optionally, the data processing device 1200 further includes: a splitting module (not shown), used to split the metadata hash table according to the identification information stored in the metadata hash table to obtain multiple metadata hash sub-tables, all of which are in a locked state; correspondingly, the second determining module 1202 is used to determine the starting log sequence number of the first log record in the metadata hash table according to the identification information of the first data in the following way: determining the target metadata hash sub-table in the multiple metadata hash sub-tables according to the identification information of the first data; and determining the starting log sequence number in the target metadata hash sub-table after de-locking the target metadata hash sub-table.

[0171] Optionally, the data processing device 1200 further includes a third processing module for reading the first data from the first memory in response to the presence of first data stored in the first memory.

[0172] Optionally, the data processing device 1200 further includes a second execution module, used to perform a master-slave switchover operation in response to detecting an anomaly in the master node.

[0173] Exemplary computing device

[0174] Having described the methods, media, and apparatus of exemplary embodiments of this disclosure, the following references... Figure 13 A computing device according to an exemplary embodiment of the present disclosure will be described.

[0175] Figure 13 The computing device 1300 shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments disclosed herein.

[0176] like Figure 13As shown, the computing device 1300 is presented in the form of a general-purpose computing device. The components of the computing device 1300 may include, but are not limited to: at least one processing unit 1301, at least one storage unit 1302, and a bus 1303 connecting different system components (including the processing unit 1301 and the storage unit 1302). The at least one storage unit 1302 stores computer-executable instructions; the at least one processing unit 1301 includes a processor that executes the computer-executable instructions to implement the methods described above.

[0177] Bus 1303 includes a data bus, a control bus, and an address bus.

[0178] Storage unit 1302 may include readable media in the form of volatile memory, such as random access memory (RAM) 1321 and / or cache memory 1322, and may further include readable media in the form of non-volatile memory, such as read-only memory (ROM) 1323.

[0179] Storage unit 1302 may also include a program / utility 1325 having a set (at least one) of program modules 1324, such program modules 1324 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.

[0180] The computing device 1300 can also communicate with one or more external devices 1304 (e.g., keyboard, pointing device, etc.). This communication can be performed via an input / output interface 1305, which may also be referred to as I / O interface 1305. Furthermore, the computing device 1300 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via a network adapter 1306. Figure 13 As shown, network adapter 1306 communicates with other modules of computing device 1300 via bus 1303. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with computing device 1300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0181] It should be noted that although several units / modules or sub-units / modules of the data processing apparatus have been mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, according to embodiments of this disclosure, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided and embodied by multiple units / modules.

[0182] Furthermore, although the operations of the methods disclosed herein are described in a specific order in the accompanying drawings, this does not require or imply that these operations must be performed in that specific order, or that all of the operations shown must be performed to achieve the desired result. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.

[0183] While the spirit and principles of this disclosure have been described with reference to several specific embodiments, it should be understood that this disclosure is not limited to the disclosed specific embodiments, and the division of aspects does not imply that features in these aspects cannot be combined for benefit; such division is merely for convenience of expression. This disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims

1. A data processing method applied to a slave node of a cloud database, wherein the cloud database further includes a master node, the master node is used to read and write data and generate read and write log records, the log files corresponding to the log records are stored in the shared storage medium of the cloud database, and the slave node achieves data synchronization with the master node by replaying the log records; The data processing method includes: In response to receiving a read request for first data, it is determined whether the first data is stored in the first memory of the slave node. The first data is data written in the master node. The read request carries the identification information of the first data. The identification information of the first data is used to identify the data table where the first data is located and the physical page of the first data in the data table. In response to the fact that the first data is not stored in the first memory, the starting log sequence number of the first log record is determined in the metadata hash table according to the identification information of the first data. The metadata hash table stores the identification information of the first data, the starting log sequence number and the length of the first data. The first log record corresponds to the first data. The metadata hash table is stored in the first memory. Based on the starting log sequence number, determine the starting position of the first log record in the log file; The first log record is determined in the log file based on the starting position; Play back the first log record to read the first data from the first log record according to the length of the first data.

2. The data processing method according to claim 1, wherein the slave node further includes a log record hash table, the log record hash table stores the identification information of the first data and the second log record, the second log record corresponds to the second data of a preset length in the master node, and the log record hash table is stored in the second memory of the slave node; Before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, the method further includes: In response to the fact that the first data is not stored in the first memory, the identification information of the first data is determined in the log record hash table; Based on the identification information of the first data, determine whether the second log record contains the first log record; In response to the second log record containing the first log record, and the minimum log sequence number value of the first log record being greater than or equal to the version number value of the physical page, the first log record is replayed to read the first data.

3. The data processing method according to claim 2, wherein determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data includes: In response to the second log record not containing the first log record, or the minimum log sequence number value being less than the version number value, the starting log sequence number of the first log record is determined in the metadata hash table based on the identification information of the first data.

4. The data processing method according to claim 2 or 3, wherein determining whether the second log record contains the first log record based on the identification information of the first data includes: In response to finding the identifier information of the first data in the log record hash table, it is determined that the second log record contains the first log record; In response to the fact that the identifier information of the first data is not found in the log record hash table, it is determined that the second log record does not contain the first log record.

5. The data processing method according to claim 2 or 3, wherein the metadata hash table further stores the termination log number of the first log record, the termination log number being used to indicate the replay termination position of the first log record.

6. The data processing method according to claim 5 further includes: In response to the fact that the storage duration of metadata information in the metadata hash table is longer than a preset duration, a first operation is executed asynchronously. The first operation is used to indicate the deletion of metadata information with a storage duration longer than the preset duration. The metadata information includes the identification information of the first data, the starting log sequence number, the length of the first data, and the ending log sequence number. Alternatively, in response to the second log record in the log record hash table having a storage duration greater than a preset duration, a second operation is performed asynchronously, the second operation being used to instruct the deletion of the second log record having a storage duration greater than the preset duration.

7. The data processing method according to claim 6, before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, further comprising: The first log record in the log file is parsed to obtain the metadata information; The metadata information is stored in the metadata hash table.

8. The data processing method according to claim 7 further includes: Determine whether the metadata hash table is referenced; In response to the fact that the metadata hash table is not referenced, the metadata hash table is locked.

9. The data processing method according to claim 7, further comprising: Based on the identification information stored in the metadata hash table, the metadata hash table is split to obtain multiple metadata hash sub-tables, all of which are in a locked state. Accordingly, determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data includes: Based on the identification information of the first data, the target metadata hash table is determined from the plurality of metadata hash tables; After delocking the target metadata hash sub-table, the starting log sequence number is determined in the target metadata hash sub-table.

10. The data processing method according to any one of claims 1 to 3, further comprising: In response to the fact that the first data is stored in the first memory, the first data is read from the first memory.

11. The data processing method according to any one of claims 1 to 3, further comprising: In response to the detection of an anomaly in the master node, a master-slave switchover operation is performed.

12. A medium storing computer-executable instructions, which, when executed by a processor, are used to implement the data processing method as described in any one of claims 1 to 11.

13. A data processing apparatus applied to a slave node of a cloud database, the cloud database further comprising a master node, the master node being used for reading and writing data and generating read and write log records, the log files corresponding to the log records being stored in a shared storage medium of the cloud database, and the slave node achieving data synchronization with the master node by replaying the log records; The data processing device includes: The first determining module is configured to, in response to receiving a read request for first data, determine whether the first data is stored in the first memory of the slave node, wherein the first data is data written in the master node, and the read request carries identification information of the first data, wherein the identification information of the first data is used to identify the data table where the first data is located and the physical page of the first data in the data table; The second determining module is used to determine the starting log sequence number of the first log record in the metadata hash table in response to the first data not being stored in the first memory, based on the identification information of the first data. The metadata hash table stores the identification information of the first data, the starting log sequence number, and the length of the first data. The first log record corresponds to the first data, and the metadata hash table is stored in the first memory. The third determining module is used to determine the starting position of the first log record in the log file based on the starting log sequence number; The fourth determining module is used to determine the first log record in the log file based on the starting position; The reading module is used to replay the first log record in order to read the first data from the first log record according to the length of the first data.

14. The data processing apparatus according to claim 13, wherein the slave node further comprises a log record hash table, the log record hash table storing identification information of the first data and a second log record, the second log record corresponding to second data of a preset length in the master node, and the log record hash table being stored in the second memory of the slave node; the data processing apparatus further comprises: The first processing module is configured to, before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data, determine the identification information of the first data in the log record hash table in response to the first data not being stored in the first memory; determine whether the second log record contains the first log record based on the identification information of the first data; and, in response to the second log record containing the first log record and the minimum log sequence number value of the first log record being greater than or equal to the version number value of the physical page, replay the first log record to read the first data.

15. The data processing apparatus according to claim 14, wherein the second determining module is configured to determine the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data in the following manner: In response to the second log record not containing the first log record, or the minimum log sequence number value being less than the version number value, the starting log sequence number of the first log record is determined in the metadata hash table based on the identification information of the first data.

16. The data processing apparatus according to claim 14 or 15, wherein the first processing module is configured to determine whether the second log record contains the first log record based on the identification information of the first data in the following manner: In response to finding the identifier information of the first data in the log record hash table, it is determined that the second log record contains the first log record; In response to the fact that the identifier information of the first data is not found in the log record hash table, it is determined that the second log record does not contain the first log record.

17. The data processing apparatus according to any one of claims 13 to 15, wherein the metadata hash table further stores the termination log number of the first log record, the termination log number being used to indicate the playback termination position of the first log record.

18. The data processing apparatus according to claim 17, further comprising: The first execution module is configured to asynchronously execute a first operation in response to the storage duration of metadata information in the metadata hash table being longer than a preset duration. The first operation is configured to instruct the deletion of metadata information with a storage duration longer than the preset duration. The metadata information includes the identifier information of the first data, the starting log sequence number, the length of the first data, and the ending log sequence number. Alternatively, in response to the second log record in the log record hash table having a storage duration greater than a preset duration, a second operation is performed asynchronously, the second operation being used to instruct the deletion of the second log record having a storage duration greater than the preset duration.

19. The data processing apparatus according to claim 18, further comprising: The storage module is used to parse the first log record in the log file to obtain the metadata information before determining the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data. The metadata information is stored in the metadata hash table.

20. The data processing apparatus according to claim 19, further comprising: The second processing module is used to determine whether the metadata hash table is referenced; in response to the metadata hash table not being referenced, the metadata hash table is locked.

21. The data processing apparatus according to claim 19, further comprising: The splitting module is used to split the metadata hash table according to the identification information stored in the metadata hash table to obtain multiple metadata hash sub-tables, all of which are in a locked state; Accordingly, the second determining module is used to determine the starting log sequence number of the first log record in the metadata hash table based on the identification information of the first data in the following manner: Based on the identification information of the first data, the target metadata hash table is determined from the plurality of metadata hash tables; After delocking the target metadata hash sub-table, the starting log sequence number is determined in the target metadata hash sub-table.

22. The data processing apparatus according to any one of claims 13 to 15, further comprising: The third processing module is used to read the first data from the first memory in response to the first data being stored in the first memory.

23. The data processing apparatus according to any one of claims 13 to 15, further comprising: The second execution module is used to perform a master-slave switchover operation in response to the detection of an anomaly in the master node.

24. A computing device, comprising: A processor, and a memory connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the data processing method as described in any one of claims 1 to 11.

Citation Information

Patent Citations

  • Data synchronization processing method, electronic equipment and storage medium

    CN113934745A

  • Database dirt brushing control method and control system

    CN116382981A