Transaction log segment file processing method, storage medium and equipment
By obtaining the encryption and compression status of log pages in the KingbaseES database and performing targeted processing, the problem of difficulty in mixing encryption and compression of XLOG logs is solved, the operating efficiency and accuracy of the database are improved, and resource waste is reduced.
Patent Information
- Application Number
- CN202310218888.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2024-09-10
AI Technical Summary
Existing technology makes it difficult to perform a mixed operation of encryption and compression on XLOG logs in the KingbaseES database, resulting in resource waste and performance loss, as well as the risk of data errors.
By obtaining the encryption and compression status of the log page during the writing process of the transaction log, and performing targeted processing on the log page according to the preset compression and encryption scheme, it supports mixed operations of encryption and compression, including data in the interval to be encrypted and to be compressed. Perform corresponding processing and store corresponding tags in the header of the log page.
It achieves accurate processing of data pages that need to be encrypted and/or compressed, reduces resource waste and performance loss, and improves the operating efficiency and processing accuracy of the database.
Smart Images

Figure CN118626458A
Abstract
Description
Technical Field
[0001] The present invention relates to database technology, and in particular to a method, storage medium and device for processing transaction log segment files. Background Art
[0002] In the DynamoDB database (KES database for short), the transaction log actually refers to the XLOG log, which may contain user data. If the XLOG log containing user data is not encrypted, once an illegal person obtains these unencrypted XLOG logs containing user data, the user data can be obtained through a simple XLOG log playback operation, resulting in user information leakage. Therefore, in order to prevent user information from being leaked from the XLOG log, the XLOG log key is required to encrypt the XLOG log to protect user information. There are some existing encryption and decryption methods. The XLOG log encryption function is turned on to encrypt and decrypt the data in the XLOG log write cache in units of the default page size.
[0003] In addition, in some scenarios, the XLOG log volume is large, and a large amount of XLOG logs will occupy a lot of bandwidth. Therefore, in these scenarios, the XLOG log needs to be compressed to reduce the XLOG log volume.
[0004] However, the current compression method usually only compresses part of the data (page data) in the XLOG log in the XLOG log writing process, and is completely separated from the XLOG log encryption process, making it difficult to implement mixed operations of encryption and compression of the XLOG log. In addition, the existing encryption and compression methods mostly occur in two threads, which occupies a large amount of database resources, not only causing a waste of database resources and performance loss, but also may cause data errors due to unnecessary encryption or compression operations. Summary of the invention
[0005] In view of the above problems, a method, storage medium and device for processing transaction log segment files are proposed to overcome the above problems or at least partially solve the above problems.
[0006] An object of the present invention is to provide a method for processing transaction log segment files, which can support mixed operations of encrypting and compressing log pages.
[0007] A further object of the present invention is to improve the accuracy of processing log pages.
[0008] In particular, the present invention provides a method for processing a transaction log segment file, the transaction log segment file comprising a plurality of log pages, each log page comprising at least a portion of a transaction log; and the processing method comprises:
[0009] In the transaction log writing process, get the log page;
[0010] Get the encryption and compression status of the log page on disk;
[0011] The log page is processed according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page.
[0012] Optionally, the encryption and compression status includes encryption only, compression only, encryption and compression required, and encryption or compression not required; and
[0013] The preset compression encryption scheme is the same as the number of encryption and compression states, and they are set one by one;
[0014] The preset compression encryption scheme and the corresponding relationship between the preset compression encryption scheme and the encryption and compression states are pre-stored in the database.
[0015] Optionally, when the encryption and compression state of the log page is that encryption and compression are required, the step of processing the log page according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page includes:
[0016] Compress the data in the to-be-compressed interval of the log page;
[0017] Perform data alignment on the data in the compressed interval of the log page;
[0018] The log page is encrypted using the compressed interval after data alignment as the encryption granularity.
[0019] Optionally, the log page includes a sequentially arranged log page header, an additional storage space of a predetermined length, and a data area; and
[0020] The log page header is used to store the transaction log encryption mark and transaction log compression mark;
[0021] The additional storage space of predetermined length is used to store the length of the compressed interval;
[0022] The interval to be compressed is the data area where the data area of the log page is located.
[0023] Optionally, after the step of compressing the data in the to-be-compressed interval of the log page, the processing method further comprises:
[0024] Writing the length of the compressed interval into the additional storage space of the predetermined length;
[0025] Write the transaction log encryption flag and transaction log compression flag to the log page header.
[0026] Optionally, when the encryption and compression state of the log page is that only encryption is required, the step of processing the log page according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page includes:
[0027] Perform data alignment processing on the data in the to-be-encrypted interval of the log page;
[0028] The log page is encrypted using the encryption granularity of the interval to be encrypted after data alignment.
[0029] Optionally, when the encryption and compression state of the log page is that only compression is required, the step of processing the log page according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page includes:
[0030] Compress the data in the to-be-compressed interval of the log page.
[0031] Optionally, when the encryption and compression state of the log page is that encryption or compression is not required, the step of processing the log page according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page includes:
[0032] Skips encryption and compression of log pages.
[0033] According to another aspect of the present invention, a machine-readable storage medium is provided, on which a machine executable program is stored. When the machine executable program is executed by a processor, any of the above transaction log segment file processing methods is implemented.
[0034] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements any of the above-mentioned transaction log segment file processing methods when executing the machine executable program.
[0035] The transaction log segment file processing method of the present invention obtains log pages in the writing process of the transaction log, obtains the encryption and compression status of the log pages in the disk, and processes the log pages according to a preset compression encryption scheme corresponding to the encryption and compression status of the log pages, thereby ensuring accurate and targeted processing of data pages that need to be encrypted and / or compressed, and can support mixed operations of encrypting and compressing log pages, reducing the waste of database resources and performance loss caused by frequent encryption and compression operations, avoiding unnecessary waste of database resources, and thus improving the operation efficiency of the database.
[0036] Furthermore, the encryption and compression states in the transaction log segment file processing method of the present invention include encryption only, compression only, encryption and compression required, and encryption or compression not required. The preset compression encryption schemes and the number of encryption and compression states are the same and are set one-to-one. The preset compression encryption schemes and the correspondence between the preset compression encryption schemes and the encryption and compression states are pre-stored in a database, which refines the encryption and compression states of the log pages and improves the accuracy of targeted processing of the log pages.
[0037] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0039] Figure 1 is a flow chart of a method for processing a transaction log segment file according to an embodiment of the present invention;
[0040] Figure 2 is a schematic diagram of the structure of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0041] Figure 3 is a schematic diagram of the structure of a log page in a method for processing a transaction log segment file according to another embodiment of the present invention;
[0042] Figure 4 It is a structural schematic diagram of the encryption and compression process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0043] Figure 5 It is a structural schematic diagram of an encryption process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0044] Figure 6 It is a structural schematic diagram of a log page compression process in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0045] Figure 7 It is a structural schematic diagram of a decryption and decompression process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0046] Figure 8is a structural schematic diagram of a decryption process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0047] Fig. 9 It is a structural schematic diagram of a decompression process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention;
[0048] Fig.10 is a flow chart of a method for processing a transaction log segment file according to another embodiment of the present invention;
[0049] Fig.11 is a schematic diagram of the structure of a machine-readable storage medium according to an embodiment of the present invention; and
[0050] Fig.12 is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to enable the scope of the present invention to be fully communicated to those skilled in the art.
[0052] In order to solve the above technical problem, an embodiment of the present invention proposes a method for processing a transaction log segment file. Figure 1 FIG. 1 is a schematic flow chart of a method for processing a transaction log segment file according to an embodiment of the present invention. The method for processing a transaction log segment file may generally include:
[0053] Step S102, in the transaction log writing process, a log page is obtained. It should be noted that the transaction log segment file includes a plurality of log pages, and each log page includes at least a portion of the transaction log.
[0054] Step S104, obtaining the encryption and compression status of the log page in the disk.
[0055] Step S106, obtaining the to-be-encrypted interval of the to-be-encrypted data page.
[0056] Step S108, processing the log page according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page.
[0057] The transaction log segment file processing method of the present embodiment obtains log pages and the encryption and compression status of the log pages in the disk during the writing process of the transaction log, and processes the log pages according to a preset compression encryption scheme corresponding to the encryption and compression status of the log pages, thereby ensuring accurate and targeted processing of data pages that need to be encrypted and / or compressed, supporting mixed operations of encrypting and compressing log pages, reducing the waste of database resources and performance loss caused by frequent encryption and compression operations, avoiding unnecessary waste of database resources, and thus improving the operation efficiency of the database.
[0058] It should be noted that KingbaseES refers to the Renmin University of China Kingbase database management system KingbaseES, which is a general relational database management system. Those skilled in the art should be able to recognize that in some optional embodiments, the transaction log segment file processing method of the present invention can be applied to the KES database, and in other optional embodiments, the transaction log segment file processing method of the present invention can also be applied to other relational databases.
[0059] For the KES database, the transaction log actually refers to the XLOG log (or WAL log), which records in detail the operation process of the service process on the KES database. The log page actually refers to the XLOG log page, or simply page. In the KES database, the default size of the XLOG log page is usually 8KB, that is, page_size = 8KB. Each XLOG log segment file consists of multiple XLOG log pages of fixed size. If the size of the XLOG log segment file is 16MB and the size of each XLOG log page is 8KB, then an XLOG log segment file contains 2048 XLOG log pages.
[0060] In one embodiment, the encryption and compression states include encryption only, compression only, encryption and compression, and neither encryption nor compression. That is, for an XLOG log page, there are four states in the disk: (1) only encrypted; (2) only compressed; (3) both encrypted and compressed; (4) neither encrypted nor compressed.
[0061] On this basis, the preset compression encryption scheme and the number of encryption and compression states are the same and are set in one-to-one correspondence. The preset compression encryption scheme and the corresponding relationship between the preset compression encryption scheme and the encryption and compression states are pre-stored in the database.
[0062] The encryption and compression states in the transaction log segment file processing method of this embodiment include encryption only, compression only, encryption and compression required, and encryption or compression not required. The preset compression encryption schemes and the number of encryption and compression states are the same and are set one-to-one. The preset compression encryption schemes and the corresponding relationship between the preset compression encryption schemes and the encryption and compression states are pre-stored in the database, which refines the encryption and compression states of the XLOG log page and improves the accuracy of the targeted processing of the XLOG log page.
[0063] Combine the following Figure 2-Figure 6 , describes the preset compression and encryption schemes under different encryption and compression states.
[0064] Figure 2 The diagram is a schematic diagram of the structure of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention. Figure 3 FIG. 1 is a schematic diagram of a partial structure of a transaction log segment file in a method for processing a transaction log segment file according to an embodiment of the present invention. Figure 2 and Figure 3 As shown, the XLOG log page includes a page header and a data area arranged in sequence. The page header is preset with a first preset position for storing an XLOG log encryption mark and a second preset position for storing an XLOG log compression mark.
[0065] Specifically, Figure 3 As shown, the first preset position may be the 4th bit (recorded as XLR_ENCRYPTION_TOKEN, the first 3 bits have been used) of the "uint16xlp_info" variable in the page header of the XLOG log page. The XLOG log compression flag may be set to 1.
[0066] In addition, if Figure 3 As shown, the second preset position may be the fifth bit (recorded as XLR_COMPRESS_TOKEN, the first three bits have been used) of the "uint16xlp_info" variable in the page header of the XLOG log page. The XLOG log compression flag may be set to 1.
[0067] On this basis, after the above step S106, the processing method of the present invention may further include the following steps: in the reading process of the XLOG log, obtaining the XLOG log page; reading the data content in the first preset position and the second preset position of the XLOG log page; determining the preset decompression and decryption scheme corresponding to the XLOG log page according to the read data content to process the XLOG log page.
[0068] In a specific embodiment, the step of reading the data content in the first preset position and the second preset position of the XLOG log page can be specifically performed as follows: reading the data content of the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16 xlp_info" variable in the page header of the XLOG log page, wherein the read data content may include the following 4 composition situations:
[0069] 1) 00: indicates that this XLOG log page is neither compressed nor encrypted;
[0070] 2) 01: indicates that this XLOG log page is only encrypted;
[0071] 3) 10: indicates that this XLOG log page is only compressed;
[0072] 4) 11: Indicates that this XLOG log page is both compressed and encrypted.
[0073] Figure 4 FIG. 1 is a schematic diagram of a structure of a log page encryption and compression process in a method for processing a transaction log segment file according to an embodiment of the present invention. Figure 4 In the illustrated embodiment, the encryption and compression status of the XLOG log page is that encryption and compression are required.
[0074] In the case that the encryption and compression status of the XLOG log page is that encryption and compression are required, the above step S106 may include the following steps: compressing the data in the interval to be compressed of the XLOG log page; performing data alignment on the data in the compressed interval of the XLOG log page; using the compressed interval after the data alignment as the encryption granularity, encrypting the XLOG log page. That is, in the case that the encryption and compression status of the XLOG log page in the disk is that it needs to be both encrypted and compressed, using the interval to be compressed of the XLOG log page as the encryption granularity and the compression granularity, the XLOG log page is first compressed, and then encrypted, so as to achieve a hybrid operation of encryption and compression of the XLOG log page.
[0075] like Figure 4 As shown, the XLOG log page includes a sequentially arranged page header, an additional storage space of a predetermined length, and a data area. The page header is used to store the XLOG log encryption mark and the XLOG log compression mark. The additional storage space of a predetermined length is used to store the length of the compressed interval. On this basis, the interval to be compressed is the data area where the data area of the XLOG log page is located.
[0076] In a specific embodiment, after the above step of compressing the data in the interval to be compressed of the XLOG log page, the processing method of the present invention may further include: writing the length of the compressed interval into an additional storage space of a predetermined length; and writing the XLOG log encryption mark and the XLOG log compression mark into the page header.
[0077] Specifically, the step of writing the XLOG log encryption mark and the XLOG log compression mark into the page header can be specifically performed as follows: setting the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16 xlp_info" variable in the page header of the XLOG log page to 1.
[0078] Figure 5 FIG. 1 is a schematic diagram of a log page encryption process in a transaction log segment file processing method according to an embodiment of the present invention. Figure 5 In the illustrated embodiment, the encryption and compression status of the XLOG log page is that only encryption is required.
[0079] In the case that the encryption and compression status of the XLOG log page is that only encryption is required, the above step S106 may include the following steps: performing data alignment processing on the data in the to-be-encrypted interval of the XLOG log page; using the to-be-encrypted interval after the data alignment processing as the encryption granularity, and performing encryption processing on the XLOG log page. That is, in the case that the encryption and compression status of the XLOG log page in the disk is that only encryption is required, only the to-be-encrypted interval of the XLOG log page is used as the encryption granularity, and only the XLOG log page is encrypted.
[0080] like Figure 5 As shown, the XLOG log page includes a page header and a data area arranged in sequence. The page header is used to store the XLOG log encryption mark and the XLOG log compression mark. On this basis, the interval to be encrypted is the data area where the data area of the XLOG log page is located.
[0081] In a specific embodiment, after the above step of encrypting the XLOG log page, the processing method of the present invention may further include: writing the XLOG log encryption tag into the page header. Specifically, the 4th bit XLR_ENCRYPTION_TOKEN of the "uint16 xlp_info" variable in the page header of the XLOG log page is set to 1.
[0082] Figure 6FIG. 1 is a schematic diagram of a log page compression process in a transaction log segment file processing method according to an embodiment of the present invention. Figure 6 In the illustrated embodiment, the encryption and compression status of the XLOG log page is that only compression is required.
[0083] When the encryption and compression status of the XLOG log page is that only compression is required, the above step S106 may include the following steps: compressing the data in the interval to be compressed of the XLOG log page. That is, when the encryption and compression status of the XLOG log page in the disk is that only compression is required, only the interval to be compressed of the XLOG log page is used as the compression granularity, and only the XLOG log page is compressed.
[0084] like Figure 6 As shown, the XLOG log page includes a sequentially arranged page header, an additional storage space of a predetermined length, and a data area. The page header is used to store the XLOG log encryption mark and the XLOG log compression mark. The additional storage space of a predetermined length is used to store the length of the compressed interval. On this basis, the interval to be compressed is the data area where the data area of the XLOG log page is located.
[0085] In a specific embodiment, after the above step of compressing the data in the to-be-compressed interval of the XLOG log page, the processing method of the present invention may further include: writing the length of the compressed interval into an additional storage space of a predetermined length; and writing an XLOG log compression mark into the page header.
[0086] Specifically, the step of writing the XLOG log compression mark into the page header may be specifically performed as follows: setting the fifth bit XLR_COMPRESS_TOKEN of the "uint16 xlp_info" variable in the page header of the XLOG log page to 1.
[0087] In one embodiment, when the encryption and compression status of the XLOG log page is that encryption or compression is not required, the above step S106 may include the following steps: skipping the encryption and compression operations on the XLOG log page. That is, when the encryption and compression status of the XLOG log page in the disk is that it is neither encrypted nor compressed, skipping the encryption and compression operations on the XLOG log page. In addition, for the XLOG log page whose encryption and compression status is that encryption or compression is not required, the data in the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16 xlp_info" variable in its page header are both 0.
[0088] Figure 7 FIG. 1 is a schematic diagram of a decryption and decompression process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention. Figure 7 In the embodiment shown, the XLOG log page is an encrypted and compressed XLOG log page. Figure 7 In the illustrated embodiment, the data content read from the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16xlp_info" variable in the page header of the XLOG log page is 11.
[0089] In the case where the read data content is 11, the above step of processing the XLOG log page according to the preset decompression and decryption scheme corresponding to the XLOG log page determined according to the read data content may include the following steps: obtaining the length of the compressed interval in the XLOG log page; calculating the length of the alignment padding data generated by the data alignment processing; calculating the length of the encrypted interval; obtaining and decrypting the data in the encrypted interval; removing the additional storage space of the predetermined length and the alignment padding data; calculating the length of the compressed interval before compression; decompressing the data in the compressed interval; putting the decompressed data in the compressed interval into the page header of the XLOG log page, and obtaining the decrypted and decompressed XLOG log page. That is, in the case where the XLOG log page is an encrypted and compressed XLOG log page, the XLOG log page is first decrypted, and then the XLOG log page is decompressed, so as to realize the mixed operation of decryption and decompression of the XLOG log page.
[0090] In a specific embodiment, the decryption operation process can be specifically performed as follows:
[0091] (1) Read the 4 bytes after the page header of the XLOG log page to obtain the length of the compressed interval in the XLOG log page, compressed_len;
[0092] (2) Calculate the length pad_len of the alignment pad data generated by the data alignment process. The specific calculation formula is pad_len=N-need_encrypt_len%N, where N is the alignment reference in the data alignment process and can be 16 in KES;
[0093] (3) Calculate the length of the encrypted interval encrypted_len, the specific calculation formula is encrypted_len = need_encrypt_len + pad_len;
[0094] (4) Read the encrypted data of length encrypted_len from the back of the page header and decrypt it;
[0095] (5) Remove the 4 bytes added after the page header and the alignment padding data;
[0096] Calculate the length of the encrypted interval in the XLOG log page before encryption, need_encrypt_len. The specific calculation formula is need_encrypt_len = 8KB-page_header_len. In KES, the length of each XLOG log page is 8KB by default. Page_header_len is the length of the page header of the XLOG log page, which is a fixed value.
[0097] (6) Calculate the length of the compressed interval before compression, need_compress_len. The specific calculation formula is need_compress_len = 8KB – page_header_len. In KES, the length of each XLOG log page is 8KB by default, and the length of the page header of each XLOG log page, page_header_len, is a fixed value.
[0098] (7) According to the lengths of the compressed interval before and after compression, need_compress_len and compressed_len, a compression algorithm such as pglz is used to decompress the data in the compressed interval;
[0099] (8) After the decompressed compressed interval data is placed in the page header of the XLOG log page, the additional storage space of the predetermined length is removed to obtain the decompressed XLOG log page;
[0100] (9) Remove the XLOG log encryption mark and the XLOG log compression mark in the page header to obtain the XLOG log page before encryption and compression.
[0101] Figure 8 FIG. 1 is a schematic diagram of a decryption process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention. Figure 8 In the embodiment shown, the XLOG log page is an encrypted and uncompressed XLOG log page. Figure 8In the illustrated embodiment, the data content read from the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16 xlp_info" variable in the page header of the XLOG log page is 01.
[0102] In the case where the read data content is 01, the above step of processing the XLOG log page according to the preset decompression and decryption scheme corresponding to the XLOG log page determined according to the read data content may include the following steps: calculating the length of the encrypted interval in the XLOG log page before encryption; calculating the length of the alignment padding data generated by the data alignment process; calculating the length of the encrypted interval; obtaining and decrypting the data in the encrypted interval; and placing the decrypted data in the encrypted interval into the page header of the XLOG log page to obtain the decrypted XLOG log page. That is, in the case where the XLOG log page is an encrypted but uncompressed XLOG log page, only the decryption operation is performed on the XLOG log page.
[0103] In a specific embodiment, the decryption operation process can be specifically performed as follows:
[0104] (1) Calculate the length of the encrypted interval in the XLOG log page before encryption, need_encrypt_len. The specific calculation formula is need_encrypt_len = 8KB-page_header_len. In KES, the length of each XLOG log page is 8KB by default. page_header_len is the length of the page header of the XLOG log page, which is a fixed value.
[0105] (2) Calculate the length pad_len of the alignment pad data generated by the data alignment process. The specific calculation formula is pad_len=N-need_encrypt_len%N, where N is the alignment reference in the data alignment process and can be 16 in KES;
[0106] (3) Calculate the length of the encrypted interval encrypted_len, the specific calculation formula is encrypted_len = need_encrypt_len + pad_len;
[0107] (4) Read the encrypted data of length encrypted_len from the back of the page header and decrypt it;
[0108] (5) After the decrypted encrypted interval data is placed in the page header of the XLOG log page, the alignment padding data is removed to obtain the decrypted XLOG log page;
[0109] (6) Remove the XLOG log encryption mark in the page header to obtain the XLOG log page before encryption.
[0110] Fig. 9 FIG. 1 is a schematic diagram of a decompression process of a log page in a method for processing a transaction log segment file according to an embodiment of the present invention. Fig. 9 In the embodiment shown, the XLOG log page is an encrypted and compressed XLOG log page. Fig. 9 In the illustrated embodiment, the data content read from the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16 xlp_info" variable in the page header of the XLOG log page is 10.
[0111] In the case where the read data content is 10, the above step of processing the XLOG log page according to the preset decompression and decryption scheme corresponding to the XLOG log page determined according to the read data content may include the following steps: obtaining the length of the compressed interval in the XLOG log page; calculating the length of the compressed interval before compression; decompressing the data in the compressed interval; and placing the decompressed data in the compressed interval into the page header of the XLOG log page to obtain the decompressed XLOG log page. That is, in the case where the XLOG log page is an unencrypted but compressed XLOG log page, only the XLOG log page is decompressed.
[0112] In a specific embodiment, the decryption operation process can be specifically performed as follows:
[0113] (1) Read the 4 bytes after the page header of the XLOG log page to obtain the length of the compressed interval in the XLOG log page, compressed_len;
[0114] (2) Calculate the length of the compressed interval before compression, need_compress_len. The specific calculation formula is need_compress_len = 8KB – page_header_len. In KES, the length of each XLOG log page is 8KB by default, and the length of the page header of each XLOG log page, page_header_len, is a fixed value.
[0115] (3) According to the lengths of the compressed interval before and after compression, need_compress_len and compressed_len, a compression algorithm such as pglz is used to decompress the data in the compressed interval;
[0116] (4) Read the encrypted data of length encrypted_len from the back of the page header and decrypt it;
[0117] (5) After the decompressed compressed interval data is placed in the page header of the XLOG log page, the additional storage space of the predetermined length is removed to obtain the decompressed XLOG log page;
[0118] (6) Remove the XLOG log compression mark in the page header to obtain the XLOG log page before compression.
[0119] Fig.10 FIG. 1 is a flow chart of a method for processing a transaction log segment file according to another embodiment of the present invention. Fig.10 The process steps of this embodiment are described in detail.
[0120] Step S1002: In the XLOG log writing process, obtain the XLOG log page.
[0121] Step S1004, obtaining the encryption and compression status of the XLOG log page in the disk. It should be noted that the encryption and compression status may include only encryption, only compression, encryption and compression, and no encryption or compression.
[0122] Step S1006: When the encryption and compression status of the XLOG log page is that encryption and compression are required, compression processing is performed on the data in the to-be-compressed interval of the XLOG log page.
[0123] Step S1008, write the length of the compressed interval into the additional storage space of the predetermined length. Specifically, the additional storage space of the predetermined length can be set to 4 bytes after the page header of the XLOG log page. On this basis, this step can be specifically performed as follows: record the length of the compressed interval as compressed_len, and store compressed_len in the 4 bytes after the page header of the XLOG log page. At this time, the compressed interval is located after the aforementioned additional 4 bytes.
[0124] Step S1010: Use the compressed interval as the interval to be encrypted. The length of the interval to be encrypted is need_encrypt_len=compressed_len.
[0125] Step S1012, data alignment is performed on the data in the encryption interval. In this step, the length of the alignment padding data in the data alignment process, pad_len, is first calculated, and the specific calculation formula is pad_len = N-need_encrypt_len%N, where N is the alignment reference in the data alignment process, which can be 16 in KES, and then the alignment padding data is placed behind the 4 bytes added after the page header.
[0126] Step S1014: encrypt the XLOG log page using the to-be-encrypted interval after the data alignment process as the encryption granularity.
[0127] Step S1016, write the XLOG log encryption mark and the XLOG log compression mark into the page header of the XLOG log page. Specifically, the 4th bit XLR_ENCRYPTION_TOKEN and the 5th bit XLR_COMPRESS_TOKEN of the "uint16xlp_info" variable in the page header of the XLOG log page are both set to 1. At this point, this process ends.
[0128] The transaction log segment file processing method of the present embodiment obtains the XLOG log page in the XLOG log writing process, obtains the encryption and compression status of the XLOG log page in the disk, and processes the XLOG log page according to a preset compression encryption scheme corresponding to the encryption and compression status of the XLOG log page, thereby ensuring accurate and targeted processing of data pages that need to be encrypted and / or compressed, supporting mixed operations of encrypting and compressing the XLOG log page, reducing the waste of database resources and performance loss caused by frequent encryption and compression operations, avoiding unnecessary waste of database resources, and thus improving the operation efficiency of the database.
[0129] This embodiment also provides a machine-readable storage medium and a computer device. Fig.11 is a schematic diagram of the structure of a machine-readable storage medium 10 according to an embodiment of the present invention, Fig.12 is a schematic diagram of the structure of a computer device 20 according to an embodiment of the present invention.
[0130] The machine-readable storage medium 10 stores a machine executable program 11 thereon. When the machine executable program 11 is executed by a processor, the method for processing a transaction log segment file of any of the above embodiments is implemented.
[0131] The computer device 20 may include a memory 220, a processor 210, and a machine executable program 11 stored in the memory 220 and running on the processor 210, and the processor 210 implements the transaction log segment file processing method of any of the above embodiments when executing the machine executable program 11.
[0132] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes may be made to the above method.
[0133] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A method for processing a transaction log segment file, wherein the transaction log segment file comprises a plurality of log pages, each of the log pages comprises at least a portion of a transaction log; and the processing method comprises: In the transaction log writing process, get the log page; Obtain the encryption and compression status of the log page on disk; The log page is processed according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page.
2. The method for processing transaction log segment files according to claim 1, wherein: The encryption and compression states include encryption only, compression only, encryption and compression, and no encryption or compression; and The preset compression encryption scheme is the same as the number of the encryption and compression states, and is set in one-to-one correspondence; The preset compression encryption scheme and the corresponding relationship between the preset compression encryption scheme and the encryption and compression states are pre-stored in a database.
3. The method for processing a transaction log segment file according to claim 2, In the case that the encryption and compression state of the log page requires encryption and compression, the step of processing the log page according to a preset compression encryption scheme corresponding to the encryption and compression state of the log page includes: Compressing the data in the to-be-compressed interval of the log page; Performing data alignment processing on the data in the compressed interval of the log page; The log page is encrypted using the compressed interval after data alignment as the encryption granularity.
4. The method for processing transaction log segment files according to claim 3, wherein: The log page includes a sequentially arranged log page header, an additional storage space of a predetermined length, and a data area; and The log page header is used to store a transaction log encryption mark and a transaction log compression mark; The additional storage space of predetermined length is used to store the length of the compressed interval; The interval to be compressed is the data area where the data area of the log page is located.
5. The method for processing transaction log segment files according to claim 4, wherein: After the step of compressing the data in the to-be-compressed interval of the log page, the processing method further includes: Writing the length of the compressed interval into the additional storage space of the predetermined length; The transaction log encryption mark and the transaction log compression mark are written into the log page header.
6. The method for processing transaction log segment files according to claim 2, wherein: In the case that the encryption and compression state of the log page is that only encryption is required, the step of processing the log page according to the preset compression encryption scheme corresponding to the encryption and compression state of the log page includes: Performing data alignment processing on the data in the to-be-encrypted interval of the log page; The log page is encrypted using the to-be-encrypted interval after the data alignment process as the encryption granularity.
7. The method for processing transaction log segment files according to claim 2, wherein: In the case that the encryption and compression state of the log page is that only compression is required, the step of processing the log page according to the preset compression encryption scheme corresponding to the encryption and compression state of the log page includes: The data in the to-be-compressed interval of the log page is compressed.
8. The method for processing transaction log segment files according to claim 2, wherein: When the encryption and compression state of the log page is that encryption or compression is not required, the step of processing the log page according to the preset compression encryption scheme corresponding to the encryption and compression state of the log page includes: Skips encryption and compression of the log page.
9. A machine-readable storage medium having a machine executable program stored thereon, wherein the machine executable program, when executed by a processor, implements the method for processing a transaction log segment file according to any one of claims 1 to 8.
10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the transaction log segment file processing method according to any one of claims 1 to 8 when executing the machine executable program.
Citation Information
Patent Citations
Transaction log caching method and device, equipment and storage medium
CN111694806A
Method for realizing WAL log transparent encryption and decryption in PostgreSQL database
CN114329607A
Fixed record media conversion with data compression and encryption
US20190050417A1
