Method, device, equipment and medium for batch importing secondary index data of HBase database
By traversing HFile files in the HBase database, parsing and converting the data and then writing them into ES in batches, the problem of low efficiency in multi-condition queries and batch imports of the HBase database is solved, and secondary index data is quickly imported, improving query performance and Reduces cluster load.
Patent Information
- Application Number
- CN202210180042.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-02-25
AI Technical Summary
The HBase database is inefficient when querying with multiple conditions, especially in scenarios with large amounts of data and multiple queries, resulting in a long query time. In addition, the index reconstruction efficiency through full table scan after batch import of HFile files is slow, resulting in high pressure on the HBase database, which may Stop business access.
By traversing the HFile file with the specified path in the HBase database, parsing it into the preset format data, converting it into Result format, building an ES client and writing it into ES in batches, replacing the full table scan method to import incremental secondary index data to avoid Impact on HBase database business.
It improves the execution speed of secondary index data import in HBase database, reduces cluster load, improves query performance, and avoids interruption of business access.
Smart Images

Figure CN114528298B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and more specifically to a method, device, equipment and readable medium for batch importing secondary index data of an HBase database. Background Art
[0002] HBase database (a distributed, column-oriented open source database that can store massive amounts of data, with underlying data files stored in HDFS) is a commonly used distributed database in the big data field. It supports data storage of hundreds of billions of rows and millions of columns. However, HBase database itself only provides queries based on row keys and full table scans. When it comes to combined queries with multiple conditions, it can only be performed through full table scans, which is inefficient. Multi-condition combined queries are relatively common in big data application scenarios. Currently, the Indexer (a secondary indexing tool) in our products is modified based on the open source HBase-indexer. It synchronizes HBase secondary index data in real time based on HBase WAL logs (a solution to make up for the lack of multi-condition combined queries in HBase database itself) and writes it to ES (an open source search engine based on Apache Lucene (TM) with very powerful data retrieval and analysis functions). It does not bring invasive code to the HBase database and does not affect the writing performance. This requirement can improve the efficiency of the HBase database secondary index and meet the full-text indexing scenario. In the scenario of large-volume multi-query combination, the query time can be reduced from hours to seconds, and the combined query performance is greatly improved. However, in production scenarios, Hfile files are generated and imported into HBase in batches to increase data writing speed and reduce cluster load. This data writing method does not go through the WAL log, so the indexer cannot synchronize to this part of the data. It can only reconstruct this part of the index data through full table scanning + timestamp filtering after the HFile is imported. This method is inefficient, slow, and puts a lot of pressure on the HBase database. In serious cases, it may even stop business access to the HBase database. Summary of the invention
[0003] In view of this, the purpose of the embodiments of the present invention is to propose a method, device, equipment and readable medium for batch importing secondary index data of an HBase database. By using the technical solution of the present invention, it is possible to replace the original HBase database full table scan method to import incremental secondary index data into ES, without affecting the business of the HBase database, and the execution speed is greatly improved.
[0004] Based on the above purpose, one aspect of an embodiment of the present invention provides a method for batch importing secondary index data of an HBase database, comprising the following steps:
[0005] Traverse all HFile files under the specified path in the HBase database and obtain the absolute path of each HFile file;
[0006] Parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained;
[0007] Convert the data in the preset format into the data in the Result format;
[0008] Build an ES client and write the data in Result format into ES in batches through the ES client.
[0009] According to an embodiment of the present invention, parsing each HFile file into data in a preset format includes:
[0010] Parse the HFile file into data in the format of row+family+qualify+value+type+timestamp.
[0011] According to an embodiment of the present invention, converting data in a preset format into data in a Result format includes:
[0012] Convert the data in the preset format into data in the HfileRecord format, and add the compareTo data to the data in the HfileRecord format;
[0013] Aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format;
[0014] The data in the Result format is screened and filtered according to the index information to exclude data outside the index information.
[0015] According to one embodiment of the present invention, constructing an ES client and writing data in Result format into the ES in batches through the ES client includes:
[0016] Build an ES client based on the ES connection parameters entered by the user. The ES connection parameters include timeout, batch write size, and ES cluster parameters.
[0017] The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
[0018] Another aspect of the embodiments of the present invention further provides a device for batch importing secondary index data of an HBase database, the device comprising:
[0019] The acquisition module is configured to traverse all HFile files under the specified path in the HBase database and obtain the absolute path of each HFile file;
[0020] A parsing module, wherein the parsing module is configured to parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained;
[0021] A conversion module, the conversion module is configured to convert data in a preset format into data in a Result format;
[0022] Import the module. The import module is configured to build an ES client and write the data in the Result format into ES in batches through the ES client.
[0023] According to one embodiment of the present invention, the parsing module is further configured to:
[0024] Parse the HFile file into data in the format of row+family+qualify+value+type+timestamp.
[0025] According to one embodiment of the present invention, the conversion module is further configured to:
[0026] Convert the data in the preset format into data in the HfileRecord format, and add the compareTo data to the data in the HfileRecord format;
[0027] Aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format;
[0028] The data in the Result format is screened and filtered according to the index information to exclude data outside the index information.
[0029] According to one embodiment of the present invention, the import module is further configured as:
[0030] Build an ES client based on the ES connection parameters entered by the user. The ES connection parameters include timeout, batch write size, and ES cluster parameters.
[0031] The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
[0032] Another aspect of the embodiments of the present invention further provides a computer device, the computer device comprising:
[0033] At least one processor; and a memory storing computer instructions executable on the processor, wherein the instructions implement the steps of any one of the above methods when executed by the processor.
[0034] According to another aspect of the embodiments of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the above methods are implemented.
[0035] The present invention has the following beneficial technical effects: the method for batch importing secondary index data of an HBase database provided by an embodiment of the present invention traverses all HFile files under a specified path in the HBase database and obtains the absolute path of each HFile file; parses each HFile file into data in a preset format according to the absolute path of the HFile file obtained; converts the data in the preset format into data in the Result format; builds an ES client, and writes the data in the Result format into the ES in batches through the ES client. The technical solution can replace the original HBase database full table scan method to import incremental secondary index data into ES, does not affect the business of the HBase database, and greatly improves the execution speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A schematic flowchart of a method for batch importing secondary index data of an HBase database according to an embodiment of the present invention;
[0038] Figure 2 A schematic diagram of data processing and batch import according to an embodiment of the present invention;
[0039] Figure 3 A schematic diagram of a device for batch importing secondary index data of an HBase database according to an embodiment of the present invention;
[0040] Figure 4 is a schematic diagram of a computer device according to an embodiment of the present invention;
[0041] Figure 5 FIG. 1 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the embodiments of the present invention are further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0043] Based on the above purpose, a first aspect of an embodiment of the present invention provides an embodiment of a method for batch importing secondary index data of an HBase database. Figure 1 Shown is a schematic flow chart of the method.
[0044] like Figure 1 As shown in , the method may include the following steps:
[0045] S1 traverses all HFile files under the specified path in the HBase database and obtains the absolute path of each HFile file.
[0046] You can build an HDFS client to traverse the specified path in the HBase database, determine the path type (file, directory) and file type (HFile, other file), and obtain the absolute path of each HFile file.
[0047] S2 parses each HFile file into data in a preset format according to the absolute path of the HFile file obtained.
[0048] The data in the preset format is row + family + qualify + value + type + timestamp (Cell data format), that is, the data content corresponding to the above keywords is filtered or extracted from the HFile file, and the various data contents are combined to form the data in the preset format. Each HFile file performs the same operation, that is, multiple Cell data formats can be obtained.
[0049] S3 converts the data in the preset format into data in the Result format.
[0050] Then convert each of the above Cell data formats into HfileRecord format data, and add compariTo data for sorting and comparison of the output in the map stage. In the Reduce stage, aggregate according to the row field, combine the data from the single-row and single-column HfileRecord format data into the single-row and multi-column Result format data, and screen and filter according to the index information to eliminate the data outside the index column.
[0051] S4 builds an ES client and writes the data in Result format into ES in batches through the ES client.
[0052] Build an ES client based on the ES connection parameters entered by the user (such as timeout, batch write size, and ES cluster parameters), and then write the data in the above Result format into ES in batches to complete the batch import of secondary index data. Figure 2 shown.
[0053] The technical solution of the present invention can replace the original HBase database full table scanning method, does not affect the business of the HBase database, and greatly improves the execution speed.
[0054] In a preferred embodiment of the present invention, parsing each HFile file into data in a preset format includes:
[0055] Parse the HFile file into data in the format of row+family+qualify+value+type+timestamp. Row, family, qualify, value, type, and timestamp can be understood as keywords, that is, the parsed data only includes the content corresponding to the above keywords.
[0056] In a preferred embodiment of the present invention, converting the data in a preset format into data in a Result format includes:
[0057] Convert the data in the preset format into data in the HfileRecord format, and add the compareTo data to the data in the HfileRecord format;
[0058] Aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format;
[0059] The data in the Result format is screened and filtered according to the index information to exclude data outside the index information.
[0060] In a preferred embodiment of the present invention, constructing an ES client and writing data in Result format into the ES in batches through the ES client includes:
[0061] Build an ES client based on the ES connection parameters entered by the user. The ES connection parameters include timeout, batch write size, and ES cluster parameters.
[0062] The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
[0063] Through the technical solution of the present invention, the original HBase database full table scan method can be replaced to import incremental secondary index data into ES, which does not affect the business of the HBase database and greatly improves the execution speed.
[0064] It should be noted that a person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program, and the above-mentioned program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. The above-mentioned computer program embodiment can achieve the same or similar effect as any of the above-mentioned method embodiments corresponding thereto.
[0065] In addition, the method disclosed in the embodiment of the present invention can also be implemented as a computer program executed by a CPU, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the CPU, the above functions defined in the method disclosed in the embodiment of the present invention are performed.
[0066] Based on the above purpose, the second aspect of the embodiment of the present invention provides a device for batch importing secondary index data of HBase database, such as Figure 3 As shown, the device 200 includes:
[0067] The acquisition module is configured to traverse all HFile files under the specified path in the HBase database and obtain the absolute path of each HFile file;
[0068] A parsing module, wherein the parsing module is configured to parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained;
[0069] A conversion module, the conversion module is configured to convert data in a preset format into data in a Result format;
[0070] Import the module. The import module is configured to build an ES client and write the data in the Result format into ES in batches through the ES client.
[0071] In a preferred embodiment of the present invention, the parsing module is further configured to:
[0072] Parse the HFile file into data in the format of row+family+qualify+value+type+timestamp.
[0073] In a preferred embodiment of the present invention, the conversion module is further configured to:
[0074] Convert the data in the preset format into data in the HfileRecord format, and add the compareTo data to the data in the HfileRecord format;
[0075] Aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format;
[0076] The data in the Result format is screened and filtered according to the index information to exclude data outside the index information.
[0077] In a preferred embodiment of the present invention, the import module is further configured as:
[0078] Build an ES client based on the ES connection parameters entered by the user. The ES connection parameters include timeout, batch write size, and ES cluster parameters.
[0079] The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
[0080] Based on the above purpose, a third aspect of an embodiment of the present invention provides a computer device. Figure 4 FIG. 2 is a schematic diagram of an embodiment of a computer device provided by the present invention. Figure 4 As shown, the embodiment of the present invention includes the following apparatus: at least one processor 21; and a memory 22, the memory 22 stores computer instructions 23 that can be run on the processor, and when the instructions are executed by the processor, the following method is implemented:
[0081] Traverse all HFile files under the specified path in the HBase database and obtain the absolute path of each HFile file;
[0082] Parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained;
[0083] Convert the data in the preset format into the data in the Result format;
[0084] Build an ES client and write the data in Result format into ES in batches through the ES client.
[0085] In a preferred embodiment of the present invention, parsing each HFile file into data in a preset format includes:
[0086] Parse the HFile file into data in the format of row+family+qualify+value+type+timestamp.
[0087] In a preferred embodiment of the present invention, converting the data in a preset format into data in a Result format includes:
[0088] Convert the data in the preset format into data in the HfileRecord format, and add the compareTo data to the data in the HfileRecord format;
[0089] Aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format;
[0090] The data in the Result format is screened and filtered according to the index information to exclude data outside the index information.
[0091] In a preferred embodiment of the present invention, constructing an ES client and writing data in Result format into the ES in batches through the ES client includes:
[0092] Build an ES client based on the ES connection parameters entered by the user. The ES connection parameters include timeout, batch write size, and ES cluster parameters.
[0093] The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
[0094] Based on the above purpose, a fourth aspect of an embodiment of the present invention provides a computer-readable storage medium. Figure 5 FIG. 2 is a schematic diagram of an embodiment of a computer-readable storage medium provided by the present invention. Figure 5 As shown, the computer readable storage medium 31 stores a computer program 32 that performs the following method when executed by a processor:
[0095] Traverse all HFile files under the specified path in the HBase database and obtain the absolute path of each HFile file;
[0096] Parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained;
[0097] Convert the data in the preset format into the data in the Result format;
[0098] Build an ES client and write the data in Result format into ES in batches through the ES client.
[0099] In a preferred embodiment of the present invention, parsing each HFile file into data in a preset format includes:
[0100] Parse the HFile file into data in the format of row+family+qualify+value+type+timestamp.
[0101] In a preferred embodiment of the present invention, converting the data in a preset format into data in a Result format includes:
[0102] Convert the data in the preset format into data in the HfileRecord format, and add the compareTo data to the data in the HfileRecord format;
[0103] Aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format;
[0104] The data in the Result format is screened and filtered according to the index information to exclude data outside the index information.
[0105] In a preferred embodiment of the present invention, constructing an ES client and writing data in Result format into the ES in batches through the ES client includes:
[0106] Build an ES client based on the ES connection parameters entered by the user. The ES connection parameters include timeout, batch write size, and ES cluster parameters.
[0107] The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
[0108] In addition, the method disclosed in the embodiment of the present invention can also be implemented as a computer program executed by a processor, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the above functions defined in the method disclosed in the embodiment of the present invention are performed.
[0109] In addition, the above method steps and system units may also be implemented using a controller and a computer-readable storage medium for storing a computer program that enables the controller to implement the above steps or unit functions.
[0110] It will also be appreciated by those skilled in the art that various exemplary logic blocks, modules, circuits and algorithm steps described in conjunction with the disclosure herein can be implemented as electronic hardware, computer software or a combination of the two. In order to clearly illustrate this interchangeability of hardware and software, a general description has been given to the functions of various schematic components, blocks, modules, circuits and steps. Whether this function is implemented as software or hardware depends on specific applications and the design constraints imposed on the entire system. Those skilled in the art can implement the function in various ways for each specific application, but this implementation decision should not be interpreted as causing a departure from the disclosed scope of the embodiments of the present invention.
[0111] In one or more exemplary designs, the function can be implemented in hardware, software, firmware or any combination thereof. If implemented in software, the function can be stored on a computer-readable medium or transmitted by a computer-readable medium as one or more instructions or codes. Computer-readable media include computer storage media and communication media, and the communication media include any media that helps to transfer a computer program from one location to another. The storage medium can be any available medium that can be accessed by a general or special computer. As an example and not limiting, the computer-readable medium may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage devices, disk storage devices or other magnetic storage devices, or any other medium that can be used to carry or store the required program code in the form of an instruction or data structure and can be accessed by a general or special computer or a general or special processor. In addition, any connection can be appropriately referred to as a computer-readable medium. For example, if a coaxial cable, optical fiber cable, twisted pair, digital subscriber line (DSL) or wireless technologies such as infrared, radio and microwaves are used to send software from a website, server or other remote source, the above-mentioned coaxial cable, optical fiber cable, twisted pair, DSL or wireless technologies such as infrared, radio and microwaves are all included in the definition of the medium. As used herein, disk and disc include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk, Blu-ray disc, wherein disks usually reproduce data magnetically, while optical discs reproduce data optically with lasers. Combinations of the above should also be included within the scope of computer-readable media.
[0112] The above are exemplary embodiments disclosed in the present invention, but it should be noted that various changes and modifications may be made without departing from the scope disclosed in the embodiments of the present invention as defined in the claims. The functions, steps and / or actions of the method claims according to the disclosed embodiments described herein do not need to be performed in any particular order. In addition, although the elements disclosed in the embodiments of the present invention may be described or required in individual form, they may also be understood as multiple unless explicitly limited to the singular.
[0113] It should be understood that, as used herein, the singular forms "a", "an" are intended to include the plural forms as well, unless the context clearly supports an exception. It should also be understood that, as used herein, "and / or" refers to any and all possible combinations including one or more of the associated listed items.
[0114] The serial numbers of the embodiments disclosed in the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0115] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0116] A person skilled in the art should understand that the discussion of any of the above embodiments is only exemplary and is not intended to imply that the scope of the disclosure of the embodiments of the present invention (including the claims) is limited to these examples; under the concept of the embodiments of the present invention, the technical features in the above embodiments or different embodiments can also be combined, and there are many other changes in different aspects of the embodiments of the present invention as above, which are not provided in detail for the sake of simplicity. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present invention should be included in the protection scope of the embodiments of the present invention.
Claims
1. A method for batch importing secondary index data of an HBase database, characterized in that: The following steps are involved: Traverse all HFile files under the specified path in the HBase database and obtain the absolute path of each HFile file; Parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained; Convert the data in the preset format into the data in the Result format; Build an ES client, and write the data in the Result format into the ES in batches through the ES client; Parsing each HFile file into data in a preset format includes: parsing the HFile file into data in the format of row+family+qualify+value+type+timestamp; Converting the data in a preset format into data in a Result format includes: converting the data in a preset format into data in an HfileRecord format, and adding compariTo data to the data in the HfileRecord format; aggregating the data in the HfileRecord format according to the row field to combine the single-row and single-column data in the HfileRecord format into single-row and multi-column data in the Result format; and screening and filtering the data in the Result format according to the index information to exclude data outside the index information.
2. The method according to claim 1, characterized in that Build an ES client and write the data in the Result format into ES in batches through the ES client: Build an ES client based on the ES connection parameters entered by the user, including timeout, batch write size, and ES cluster parameters; The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
3. A device for batch importing secondary index data of an HBase database, characterized in that: The device comprises: An acquisition module, wherein the acquisition module is configured to traverse all HFile files under a specified path in the HBase database and obtain the absolute path of each HFile file; A parsing module, wherein the parsing module is configured to parse each HFile file into data in a preset format according to the absolute path of the HFile file obtained; A conversion module, wherein the conversion module is configured to convert data in a preset format into data in a Result format; An import module, wherein the import module is configured to build an ES client and write the data in the Result format into the ES in batches through the ES client; The parsing module is further configured to: parse the HFile file into data in the format of row+family+qualify+value+type+timestamp; The conversion module is also configured to: convert data in a preset format into data in HfileRecord format, and add compariTo data to the data in HfileRecord format; aggregate the data in HfileRecord format according to the row field to combine the single-row and single-column data in HfileRecord format into single-row and multi-column data in Result format; and screen and filter the data in Result format according to index information to exclude data outside the index information.
4. The device according to claim 3, characterized in that The import module is also configured as: Build an ES client based on the ES connection parameters entered by the user, including timeout, batch write size, and ES cluster parameters; The data in the Result format is written into the ES in batches through the ES client to complete the batch import of the secondary index data.
5. A computer device, characterized in that: include: at least one processor; as well as A memory, wherein the memory stores computer instructions executable on the processor, wherein the instructions, when executed by the processor, implement the steps of the method according to any one of claims 1 to 2.
6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
A large data processing method for educational resources
CN106649516A
Commodity resource data processing method
CN106649523A
Big data component monitoring method and device and electronic equipment
CN112000548A
Systems, methods and computer readable media for performing a domain-specific metasearch, and visualizing search results therefrom
US20050278321A1
