Disclosure of Invention
In view of this, the present invention provides a data processing method, device and system for a distributed database, so as to reduce the overhead of data processing of the distributed database, and further improve the data processing performance of the distributed database.
In one aspect, the present invention provides a data processing method for a distributed database, where the distributed database includes: the data processing method of the distributed database comprises the following steps:
the storage node receives the log information sent by the coordination node, and constructs a queue in a memory for storing the log information to form a log queue;
sequentially reading the stored log information from the log queue according to the first-in first-out order, and writing the read log information into a hard disk;
sorting the log information according to a log serial number, and distinguishing the log information according to a transaction ID;
analyzing data change operation in the log information to generate a new data page;
and writing and backing up data according to the new data page.
Further, the step of writing and backing up data according to the new data page comprises: the outdated data is periodically purged to free up space.
Further, the step of analyzing the data change operation in the log information and generating a new data page includes: judging whether data fragmentation is needed or not;
and when the data fragmentation is determined to be needed, finding the fragmentation position, and executing the steps of writing and backing up data according to the new data page according to the fragmentation position.
Further, the distributed database is a Postgres-XL distributed database.
In another aspect, the present invention further provides a data processing system for a distributed database, including:
the log receiving module is used for receiving the log information sent by the coordination node, and constructing a queue in a memory for storing the log information to form a log queue;
the log updating module is used for sequentially reading the stored log information from the log queue according to a first-in first-out order and writing the read log information into a hard disk;
the log sorting and sorting module is used for sorting the log information according to the log serial number and distinguishing the log information according to the transaction ID;
the log analysis module is used for analyzing the data change operation in the log information to generate a new data page;
and the data writing module is used for writing and backing up data according to the new data page.
Further, the data processing apparatus of the distributed database further includes: and the data cleaning module is used for periodically cleaning the expired data to release the space.
Further, the log parsing module is further configured to: and judging whether the data fragmentation is needed, finding the fragmentation position when the data fragmentation is needed, and writing and backing up the data according to the fragmentation position and the new data page.
Further, the distributed database is a Postgres-XL distributed database.
In another aspect, the present invention further provides a data processing system for a distributed database, including: the memory is used for receiving the log information sent by the coordination node and constructing a queue for storing the log information sent by the coordination node to form a log queue;
the hard disk is used for sequentially reading the stored log information from the log queue according to the first-in first-out order and storing the read log information and the data page;
the CPU is used for sequencing the log information according to the log serial number and distinguishing the log information according to the transaction ID; analyzing data change operation in the log information to generate a new data page; and writing and backing up data according to the new data page.
Further, the CPU is further configured to: and judging whether the data fragmentation is needed, finding the fragmentation position when the data fragmentation is needed, and writing and backing up data according to the fragmentation position and the new data page.
According to the data processing method, device and system of the distributed database, only the redo log is constructed when the coordination node needs to write data into the data node; the data node puts the log sent by the coordinating node into a memory queue, then removes the log from the queue and makes the log persistent to the hard disk; and the data nodes merge the log records to generate the data of the latest version, and the data is converted into data blocks (namely data pages) required by the database. Because only logs are written between the coordination nodes of Postgres-XL (PGXL) and the data nodes, files such as data pages, metadata and the like are not written, and data construction work is handed to the data nodes, the writing efficiency and the overall performance of the PGXL distributed database are greatly improved.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
It should be noted that, in the case of no conflict, the features in the following embodiments and examples may be combined with each other; moreover, all other embodiments that can be derived by one of ordinary skill in the art from the embodiments disclosed herein without making any creative effort fall within the scope of the present disclosure.
It is noted that various aspects of the embodiments are described below within the scope of the appended claims. It should be apparent that the aspects described herein may be embodied in a wide variety of forms and that any specific structure and/or function described herein is merely illustrative. Based on the disclosure, one skilled in the art should appreciate that one aspect described herein may be implemented independently of any other aspects and that two or more of these aspects may be combined in various ways. For example, an apparatus may be implemented and/or a method practiced using any number of the aspects set forth herein. Additionally, such an apparatus may be implemented and/or such a method may be practiced using other structure and/or functionality in addition to one or more of the aspects set forth herein.
Fig. 1 is a flowchart of a data processing method for a distributed database according to an exemplary first embodiment of the present invention, and as shown in fig. 1, the data processing method for a distributed database according to the present invention includes:
step 101: the storage node receives the log sent by the coordination node, and in order to avoid the problem caused by the transmission speed being higher than the processing speed, a queue is constructed in the memory to store the received log record (i.e. the log information), so as to form a log queue.
Step 102: and sequentially reading log records from the log queue according to the first-in first-out order, and persistently writing the log records into the hard disk. The change of the user to the data is persisted to the hard disk, and the persistence of the transaction is realized.
Step 103: the log records are sorted according to the log serial number and are sorted according to the transaction ID so as to distinguish the operation of each transaction, and the isolation of the transactions is ensured.
Step 104: and analyzing the data change operation in the log so as to generate a new data page.
Step 105: and writing and backing up data according to the new data page.
Preferably, because PGXL is a distributed database, if data fragmentation is needed, step 105 can first find the corresponding location of the data fragmentation, write the data, and copy the data to the backup data fragment. This process ensures transaction consistency using the quorum protocol.
Further preferably, after the data is successfully written, the data node sends a confirmation message to the coordinating node to inform the coordinating node that the data persistence process is completed. If the transaction fails, all data operations in the transaction roll back, so that the atomicity of the transaction is realized.
Further preferably, step 105 may be followed by: periodically, expired data, such as identified deleted data, is cleared, freeing space.
In the embodiment, when the coordination node needs to write data into the data node, only the redo log is constructed; the data node puts the log sent by the coordinating node into a memory queue, then removes the log from the queue and makes the log persistent to the hard disk; and the data nodes merge the log records to generate the data of the latest version, and the data is converted into data blocks (namely data pages) required by the database. Because only logs are written between the coordination nodes of Postgres-XL (PGXL) and the data nodes, files such as data pages, metadata and the like are not written, and data construction work is handed to the data nodes, the writing efficiency and the overall performance of the PGXL distributed database are greatly improved.
Fig. 2 is a flowchart of a data processing method of a distributed database according to an exemplary second embodiment of the present invention. Fig. 2 is a preferred embodiment of the process shown in fig. 1. As shown in fig. 2, the data processing method of the distributed database includes:
1. the storage node receives the log sent by the coordination node, and in order to avoid the problem caused by the fact that the transmission speed is higher than the processing speed, a queue is constructed in the memory of the storage node to store the received log record.
2. And sequentially reading the log records from the log receiving queue in a first-in first-out mode, and persistently writing the log records into the hard disk. This process is extremely simple, with no additional operations, and therefore fast.
3. The log records are sorted by log sequence number and sorted by transaction ID grouping. Therefore, the operation of each transaction can be distinguished, and the isolation of the transactions is ensured.
4. Analyzing the data change operation in the log so as to generate a new data page, which is the same as the recovery process by using the WAL log when the system fails: and analyzing the WAL log, acquiring the modified snapshot of the data page stored in the WAL log, and restoring the modified snapshot to a data buffer area similar to a traditional database.
5. Because PGXL is a distributed database, does the decision need to split the data?
6. If necessary, find the corresponding position of the data fragment.
7. And writing data and persisting the data to the hard disk.
8. And copying data into the backup data slice, and ensuring the consistency of transactions by using a quorom protocol.
9. Is it determined whether writing of copied data succeeded?
10. If the transaction fails, all data operations in the transaction roll back, so that the atomicity of the transaction is realized.
11. If the data persistence process is successful, the data node sends a confirmation message to the coordination node to tell the coordination node that the data persistence process is completed. The change of the user to the data is persisted to the hard disk, and the persistence of the transaction is realized.
12. Periodically, the hard disk space is released by using the expired data of the Vacuum process, such as the identified deletion data.
According to the embodiment, only the log is transmitted and written, so that the network overhead and the IO overhead are reduced, and the performance is improved; the log already contains the relevant operations of all users, and the data operation in the transaction is ensured to be either completely successful or completely failed by only analyzing the log, so that the atomicity of the transaction is realized; the log is sorted and sorted into data pages at the storage node, and the consistency of the transaction is ensured by utilizing the self quorum protocol of the PGXL; the logs are sorted and sorted at the storage nodes to distinguish the operation of each transaction, so that the isolation of the transactions is ensured; and the change of the user to the data is persisted to the hard disk by only analyzing the log, so that the persistence of the transaction is realized.
Fig. 3 is a block diagram of a data processing apparatus of a distributed database according to an exemplary third embodiment of the present invention. The embodiments shown in fig. 1 and fig. 2 can be applied to this embodiment, specifically, as shown in fig. 3, the data processing apparatus of the distributed database includes:
the log receiving module 301 is configured to receive a log sent by the coordinating node, store the log in a queue data structure of a memory of the storage node, and send a log record to the log updating module 302.
And the log updating module 302 is used for receiving log records from the log receiving module 301, persistently writing the log records into the hard disk, and sending the log records to the log sorting and sorting module 303.
And the log sorting and sorting module 303 is used for sorting the log records, sorting the log records according to the transaction ID groups, and sending the sorted log records to the log analysis module 304.
The log parsing module 304 is used to parse the data change operation in the log, construct a new data page, and send the new data page to the data writing module 305.
The data writing module 305 is used for persistently writing a new data page to the hard disk, copying the data to the data page copying node, and receiving a cleaning request sent by a data cleaning module (not shown in the figure). The data cleaning module is used to clean out expired data, release hard disk space, and send a cleaning command to the write data writing module 305 to complete cleaning.
The log of the embodiment already contains the relevant operations of all users, and the data operation in the transaction is ensured to be either completely successful or completely failed by only analyzing the log, so that the atomicity of the transaction is realized; the logs are sorted and sorted into data pages at the storage nodes by only analyzing the logs, and the consistency of transactions is ensured by utilizing the self quorum protocol of the PGXL; the log is sorted and sorted at the storage node by only analyzing the log to distinguish the operation of each transaction, so that the isolation of the transaction is ensured; and the change of the user to the data is persisted to the hard disk by only analyzing the log, so that the persistence of the transaction is realized.
Fig. 4 is a block diagram of a data processing system of a distributed database according to an exemplary fourth embodiment of the present invention. The embodiments shown in fig. 1 to fig. 3 can be applied to this embodiment, and specifically, as shown in fig. 4, the data processing system of the distributed database includes:
the memory is used for receiving the logs sent by the coordination node and storing the logs in a queue data structure of the memory of the storage node; specifically, the method is used for receiving the log information sent by the coordinating node, and constructing a queue for storing the log information sent by the coordinating node to form a log queue.
Hard disk, which is used to persist log record and data page; specifically, the method and the device are used for sequentially reading the stored log information from the log queue according to a first-in first-out order, and storing the read log information and the data page.
The CPU is used for processing the logs, including sorting, arranging and analyzing the logs, searching for overdue data and the like; specifically, the log sorting device is used for sorting the log information according to a log serial number and distinguishing the log information according to a transaction ID; analyzing data change operation in the log information to generate a new data page; and writing and backing up data according to the new data page.
Preferably, the CPU is further configured to: and judging whether the data fragmentation is needed, finding the fragmentation position when the data fragmentation is needed, and writing and backing up data according to the fragmentation position and the new data page.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.