Data storage method and device
By obtaining the recording information of slot identification and index files, determining the target data page and storing data, the problem of data loss in data migration and load balancing storage in the prior art is solved, and efficient data management and fast and accurate reading and writing are achieved.
Patent Information
- Application Number
- CN202411886301.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2044-12-20
AI Technical Summary
When existing data storage methods migrate or load-balanced storage, they are prone to data loss, affecting the data migration speed and data recovery efficiency during database transformation, resulting in poor database data storage effect.
By obtaining the slot identifier of the target row and the column data to be stored, the record information between the slot identifier and the data page stored in the index file is retrieved, the target data page is determined and the data is stored, and multiple data pages and index pages containing common page headers and non-common page headers are created to realize the mapping relationship between the slot identifier and the page.
It improves the management efficiency of data storage, enhances the speed and accuracy of data reading and writing, avoids data loss, and improves the data recovery efficiency of the database.
Smart Images

Figure CN119806417B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a data storage method and device. Background Art
[0002] With the advent of the big data era, the robustness of data storage engines has become a focus of user attention. In particular, the development of data storage engines focuses on how to quickly store massive amounts of data for accurate reading.
[0003] Currently, when migrating or load-balancing existing data, it's typically done by fixed columns or rows within an entire table or block of data. However, this requires the redeployment of multiple storage nodes, which can easily lead to data loss and affect the speed and accuracy of data migration. This significantly reduces the efficiency of data recovery during database transformation and impacts the storage quality of the data within the database. Summary of the Invention
[0004] In view of this, the present invention provides a data storage method and device, the main purpose of which is to solve the problem of poor data reading and writing efficiency in existing databases.
[0005] According to one aspect of the present invention, there is provided a data storage method, comprising:
[0006] Obtaining a slot identifier of a target row and column data to be stored, wherein the slot identifier is generated based on a distribution key of the target row;
[0007] Retrieving an index file, wherein the index file stores record information between different slot identifiers and data pages, wherein the data pages are used to store data;
[0008] A target data page corresponding to the slot identifier is determined based on the record information, and the column data to be stored is stored in the target data page.
[0009] Furthermore, determining the target data page corresponding to the slot identifier based on the index file includes:
[0010] If the slot identifier is found in the index file, the target data page of the record information matching the slot identifier is retrieved;
[0011] If the slot identifier is not found in the index file, a target data page of the slot identifier is generated, and record information of the slot identifier and the target data page is generated and stored in the index file.
[0012] Furthermore, before obtaining the slot identifier of the target row and the column data to be stored, the method further includes:
[0013] Create multiple data pages and index pages including common page headers and non-common page headers in a preset storage area;
[0014] The public page header stores basic page information, the non-public page header of the index page stores index level and index type, and the non-public page header of the data page stores slot identification and page attribute information.
[0015] Furthermore, after storing the column data to be stored in the target data page, the method further includes:
[0016] Obtaining a target index page corresponding to the target data page;
[0017] Generate a data index according to storage information of the column data to be stored in the target data page;
[0018] The data index is stored in the target index page, and the index level and index type of the index page are updated based on the data index.
[0019] Furthermore, the target data page includes a first-write page and a current-write page, and storing the to-be-stored column data in the target data page includes:
[0020] If the slot identifier is found in the index file, the column data to be stored is stored in the current write page.
[0021] If the slot identifier is not found in the index file, the column data to be stored is stored in the first write page.
[0022] Furthermore, before obtaining the slot identifier of the target row and the column data to be stored, the method further includes:
[0023] After responding to a storage request for a data table, retrieving row data from the data table in units of rows and storing the data in the transaction buffer;
[0024] In response to a row data storage request submitted by the transaction buffer, the row data is converted into column data to be stored.
[0025] Furthermore, after storing the column data to be stored in the target data page, the method further includes:
[0026] In response to a read instruction of target data, determining a read slot identifier of the target data and retrieving the index file;
[0027] If the read slot identifier is found in the index file, searching for a reference data page matching the read slot identifier and a reference index page corresponding to the reference data page based on all non-public page headers;
[0028] The storage information of the target data is queried from the reference index page, and the data content is read from the reference data page according to the storage information.
[0029] Furthermore, the method further comprises:
[0030] Creating a system page, wherein the system page stores home page information of all index pages;
[0031] When the system is restarted, the system page is read, and all slot identifiers and data pages corresponding to the slot identifiers are read from the home page information to reconstruct the index file.
[0032] According to another aspect of the present invention, there is provided a data storage device comprising:
[0033] An acquisition module, configured to acquire a slot identifier of a target row and column data to be stored, wherein the slot identifier is generated based on a distribution key of the target row;
[0034] A calling module, configured to call an index file, wherein the index file stores record information between different slot identifiers and data pages, wherein the data pages are used to store data;
[0035] A storage module is configured to determine a target data page corresponding to the slot identifier based on the record information, and store the column data to be stored in the target data page.
[0036] Furthermore, the storage module is specifically used to retrieve the target data page that matches the record information with the slot identifier if the slot identifier is found from the index file; if the slot identifier is not found from the index file, generate the target data page with the slot identifier, and generate the record information of the slot identifier and the target data page, and store them in the index file.
[0037] Furthermore, the device further comprises:
[0038] A creation module is used to create multiple data pages and index pages containing public page headers and non-public page headers in a preset storage area; wherein the public page header stores page basic information, the non-public page header of the index page stores index level and index type, and the non-public page header of the data page stores slot identification and page attribute information.
[0039] Furthermore, the device further comprises: a generating module,
[0040] The acquisition module is further configured to acquire a target index page corresponding to the target data page;
[0041] The generating module is configured to generate a data index according to storage information of the column data to be stored in the target data page;
[0042] The storage module is further configured to store the data index in the target index page, and update the index level and index type of the index page based on the data index.
[0043] Furthermore, the target data page includes a first-written page and a current-written page.
[0044] The storage module is further configured to store the column data to be stored in the current write page if the slot identifier is found in the index file, and to store the column data to be stored in the first write page if the slot identifier is not found in the index file.
[0045] Furthermore, the device also includes: a conversion module, which is used to respond to a storage request of the data table, retrieve the row data in the data table in row units and store them in the transaction buffer; when responding to a row data storage request submitted by the transaction buffer, convert the row data into column data to be stored.
[0046] Furthermore, the creation module is also used to respond to a read instruction of the target data, determine the read slot identifier of the target data, and call the index file; if the read slot identifier is queried in the index file, the reference data page matching the read slot identifier and the reference index page corresponding to the reference data page are queried based on all non-public page headers; the storage information of the target data is queried from the reference index page, and the data content is read from the reference data page according to the storage information.
[0047] According to another aspect of the present invention, a storage medium is provided, wherein the storage medium stores at least one executable instruction, and the executable instruction enables a processor to execute an operation corresponding to the above-mentioned data storage method.
[0048] According to another aspect of the present invention, there is provided a terminal, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus;
[0049] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute an operation corresponding to the above-mentioned data storage method.
[0050] By means of the above technical solution, the technical solution provided by the embodiment of the present invention has at least the following advantages:
[0051] The present invention provides a data storage method and device. Compared with the prior art, the embodiment of the present invention obtains the slot identifier of a target row and the column data to be stored, wherein the slot identifier is generated by the distribution key of the target row; retrieves an index file, wherein the index file stores record information between different slot identifiers and data pages, and the data page is used to store data; determines the target data page corresponding to the slot identifier based on the record information, and stores the column data to be stored in the target data page, thereby realizing the storage of column data after forming a mapping relationship between the slot identifier and the page, thereby greatly improving the management efficiency of data storage, thereby improving the speed and accuracy of data reading and writing.
[0052] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0054] Figure 1 A flow chart of a data storage method provided by an embodiment of the present invention is shown;
[0055] Figure 2 A schematic diagram of a method for querying index records and data pages provided by an embodiment of the present invention is shown;
[0056] Figure 3 A block diagram of a data storage device according to an embodiment of the present invention is shown;
[0057] Figure 4 A schematic structural diagram of a terminal provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0058] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0059] The embodiment of the present invention provides a data storage method, such as Figure 1As shown, the method includes:
[0060] 101. Obtain the slot identifier of the target row and the column data to be stored.
[0061] In an embodiment of the present invention, as the execution end of the data storage method, the current execution subject can be a server for processing various business data, such as a cloud server, or a terminal device with data functions and storage functions, which is not specifically limited in the embodiment of the present invention. Among them, the target behavior is a row in the data form to be stored, so that the data in this row can be retrieved and stored as the column data to be stored. In addition, in an embodiment of the present invention, the slot identifier is generated for the distribution key of the target row, that is, each row in the data form corresponds to a distribution key, and the value obtained by calculating the hash value of the distribution key is used as the slot number, so as to serve as the retrieval basis for each row of data.
[0062] 102. Retrieve the index file.
[0063] In an embodiment of the present invention, an index file is pre-stored in the current execution end. In this case, the index file stores record information between different slot identifiers and data pages. The record information is used to represent the record content when each slot identifier is recorded when storing column data in the data page, so that the data page corresponding to this slot identifier can be quickly found. This embodiment of the present invention does not specifically limit this. In addition, in an embodiment of the present invention, data pages are used to store data, that is, multiple data pages are pre-created in the current execution end to store column data in page form, and each data page stores the column data corresponding to a row. This embodiment of the present invention does not specifically limit this.
[0064] 103. Determine a target data page corresponding to the slot identifier based on the record information, and store the column data to be stored in the target data page.
[0065] In this embodiment of the present invention, after the current execution end retrieves the index file, it first searches the record information. At this time, if the record information contains a target data page for which a slot identifier has been recorded, the target data page corresponding to the slot identifier is found, and the column data to be stored is stored in the target data page. If the record information does not contain a target data page corresponding to the slot identifier, it indicates that data has not been previously stored for the target row. Therefore, a new data page corresponding to the slot identifier is generated as the target data page, and the column data to be stored is stored in the target data page.
[0066] In another embodiment of the present invention, for further definition and explanation, the step of determining the target data page corresponding to the slot identifier based on the index file includes:
[0067] If the slot identifier is found in the index file, the target data page of the record information matching the slot identifier is retrieved;
[0068] If the slot identifier is not found in the index file, a target data page of the slot identifier is generated, and record information of the slot identifier and the target data page is generated and stored in the index file.
[0069] In an embodiment of the present invention, to speed up data storage and avoid tedious queries, the current execution end first searches the index file for a slot identifier when determining a target data page to determine whether record information exists. If the slot identifier can be found in the index file, it indicates that record information for the column data has already been stored. Therefore, the target data page whose slot identifier matches the record information is retrieved. If the slot identifier is not found in the index file, it indicates that the column data has not been previously stored. Therefore, a target data page corresponding to the slot identifier is generated, and a new record information is generated and updated in the index file for subsequent queries.
[0070] It should be noted that the data page for the first time a slot identifier is generated can be the homepage, and the data page for a slot identifier that has already been generated can be the current page. In a specific implementation scenario, if the slot identifier cannot be found in the recorded information, it means that the data storage content corresponding to the slot identifier has not been recorded. Therefore, the data page for the generated slot identifier is the first write page. Correspondingly, if the slot identifier is found in the recorded information, it means that the data storage content corresponding to the slot identifier has already been recorded. Therefore, the data page corresponding to the slot identifier is the current write page, which is not specifically limited in the embodiments of the present invention.
[0071] In another embodiment of the present invention, for further definition and explanation, before the step of obtaining the slot identifier of the target row and the column data to be stored, the method further includes:
[0072] A plurality of data pages and index pages including a common page header and a non-common page header are created in a preset storage area.
[0073] In order to improve the accuracy and convenience of data storage and reading, and to achieve the purpose of flexible data management, the current execution end pre-creates multiple pages and divides them into data pages and index pages. Specifically, when creating multiple pages, you can choose to divide the area in the preset storage area in the cache or hard disk area of the current execution entity as the basic unit for storing data. In addition, each page stores the same size of data and contains a public page header and a non-public page header. In this case, the index page is used to store the index content of the data storage. The public page header stores page basic information, the non-public page header of the index page stores the index level and index type, and the non-public page header of the data page stores the slot identifier and page attribute information. The page basic information includes information such as page type, stored data type and next page number, page management protocol, version number and flag information. The index level is used to represent the level of index formed by data stored in the data page, and the index type is used to represent the type of index formed by data stored in the data page. The page attribute information includes column index, column type and compression level information, etc. This embodiment of the present invention does not specifically limit this.
[0074] In another embodiment of the present invention, for further definition and explanation, after storing the column data to be stored in the target data page, the method further includes:
[0075] Obtaining a target index page corresponding to the target data page;
[0076] Generate a data index according to storage information of the column data to be stored in the target data page;
[0077] The data index is stored in the target index page, and the index level and index type of the index page are updated based on the data index.
[0078] In order to speed up the writing efficiency of data, after the column data is stored in the target data page, the current execution end obtains the target index page of the target data page. If the target data page is newly generated, the corresponding target index page is also newly generated. If the target data page already exists, the existing target index page can be obtained. The embodiment of the present invention does not make specific limitations. Furthermore, a data index is generated according to the storage information of the column data to be stored in the target data page, wherein the storage information may include but is not limited to the storage location, storage type, etc., so as to generate a corresponding data index. In addition, the current execution end stores the generated data index in the target index page and updates the corresponding index level and index type. At this time, since the column data is stored in the order of instructions or time, the corresponding data index can also be stored in the target index page under the previous data index in the order of instructions or time, and the corresponding index level and index type are updated, such as the first-level index, second-level index, etc., and the full-text index, ordinary index, etc. The embodiment of the present invention does not make specific limitations.
[0079] In another embodiment of the present invention, for further definition and explanation, the step of storing the to-be-stored column data in the target data page includes:
[0080] If the slot identifier is found in the index file, the column data to be stored is stored in the current write page.
[0081] If the slot identifier is not found in the index file, the column data to be stored is stored in the first write page.
[0082] Since the target data page includes the first write page and the current write page, in order to meet the management effectiveness of different data storage, when storing the column data to be stored in the target data page, in a specific implementation scenario, first query from the index file whether there is a slot identifier. If so, the column data to be stored is stored in the current write page. If the slot identifier is not found, the column data to be stored is stored in the first write page.
[0083] It should be noted that since the slot identifier is obtained by calculating the hash value of the distribution key of each row, a maximum of 65535 slot identifiers can be obtained in the storage space in the embodiment of the present invention, so that the current execution end can search according to the slot identifier when reading and writing data. The embodiment of the present invention does not make specific limitations.
[0084] In another embodiment of the present invention, for further definition and explanation, before the step of obtaining the slot identifier of the target row and the column data to be stored, the method further includes:
[0085] After responding to a storage request for a data table, retrieving row data from the data table in units of rows and storing the data in the transaction buffer;
[0086] In response to a row data storage request submitted by the transaction buffer, the row data is converted into column data to be stored.
[0087] In order to speed up the data storage speed and improve the data storage effectiveness, the current execution end can also receive storage requests generated for the data table before obtaining the slot identifier. At this time, the storage request includes but is not limited to updates to the storage disk or backups of the storage disk, etc., which are not specifically limited in the embodiment of the present invention. After the current execution end responds to the storage request, it retrieves the data of each row in the data table in row units and stores them in order to the transaction buffer. Then, after the transaction buffer submits the row data storage request, the current execution end converts the row data into column data to be stored, so that when writing, the column data corresponding to the target row can be directly retrieved. This is not specifically limited in the embodiment of the present invention. In addition, the transaction buffer is an area used to temporarily store uncommitted data changes in the transaction during database transaction processing. The current execution end can create a corresponding transaction buffer before executing steps 101-103 to meet different data storage requirements.
[0088] In another embodiment of the present invention, for further definition and explanation, after storing the column data to be stored in the target data page, the method further includes:
[0089] In response to a read instruction of target data, determining a read slot identifier of the target data and retrieving the index file;
[0090] If the read slot identifier is found in the index file, searching for a reference data page matching the read slot identifier and a reference index page corresponding to the reference data page based on all non-public page headers;
[0091] The storage information of the target data is queried from the reference index page, and the data content is read from the reference data page according to the storage information.
[0092] In order to achieve the purpose of effective reading, after receiving the read instruction of the target data, the current execution end determines the read slot identifier of the target data, such as querying the distribution key of the row for calculation, and calling the index file. Among them, since the index file stores the record information between different slot identifiers and data pages, the slot identifier is queried from the index file. At this time, if the non-public page header of the created page contains information such as the slot identifier and page attribute information, the corresponding reference data page and the reference index page corresponding to the reference data page can be queried according to the slot identifier. Furthermore, the storage information of the target data is queried from the reference index page, so that the data content is read from the reference data page according to the storage information.
[0093] In another embodiment of the present invention, for further definition and explanation, the steps further include:
[0094] Create system page;
[0095] When the system is restarted, the system page is read, and all slot identifiers and data pages corresponding to the slot identifiers are read from the home page information to reconstruct the index file.
[0096] In order to prevent the system from being unable to recover data normally when it crashes and to achieve rapid recovery of read and write functions, the current execution end creates a system page while creating data pages and storage pages. The system page stores the home page information of all index pages. After the system of the current execution end is restarted, this system page is read, and all slot identifiers are read from the home page information of all index pages. At this time, since each slot identifier corresponds to all data pages of the column data of a target row, the slot identifier and the first write position of the corresponding column data and the current write position of the column data corresponding to the slot identifier in the home page information of the index page can be quickly read when the system crashes, thereby achieving rapid recovery of the index and normal read and write functions.
[0097] In a scenario of an embodiment of the present invention, Figure 2 In the query method of index records and data pages shown, the index file includes a current page index record information and a home page index record information. At this time, each slot identifier corresponds to a current page index record information and a home page index record information, so that after determining the slot identifier, the corresponding data page as the current write page, or the data page as the first write page, can be found from the index record information. The embodiment of the present invention does not make specific limitations.
[0098] An embodiment of the present invention provides a data storage method. Compared with the prior art, the embodiment of the present invention obtains the slot identifier of a target row and the column data to be stored, wherein the slot identifier is generated by the distribution key of the target row; retrieves an index file, wherein the index file stores record information between different slot identifiers and data pages, and the data page is used to store data; determines a target data page corresponding to the slot identifier based on the record information, and stores the column data to be stored in the target data page, thereby realizing the storage of column data after forming a mapping relationship between the slot identifier and the page, thereby greatly improving the management efficiency of data storage, thereby improving the speed and accuracy of data reading and writing.
[0099] Furthermore, as a response to the above Figure 1 To implement the method shown in FIG, an embodiment of the present invention provides a data storage device, such as Figure 3 As shown, the device includes:
[0100] An acquisition module 21 is configured to acquire a slot identifier of a target row and column data to be stored, wherein the slot identifier is generated based on a distribution key of the target row.
[0101] A retrieval module 22 is configured to retrieve an index file, wherein the index file stores record information between different slot identifiers and data pages, wherein the data pages are used to store data;
[0102] The storage module 23 is configured to determine a target data page corresponding to the slot identifier based on the record information, and store the column data to be stored in the target data page.
[0103] Furthermore, the storage module is specifically used to retrieve the target data page that matches the record information with the slot identifier if the slot identifier is found from the index file; if the slot identifier is not found from the index file, generate the target data page with the slot identifier, and generate the record information of the slot identifier and the target data page, and store them in the index file.
[0104] Furthermore, the device further comprises:
[0105] A creation module is used to create multiple data pages and index pages containing public page headers and non-public page headers in a preset storage area; wherein the public page header stores page basic information, the non-public page header of the index page stores index level and index type, and the non-public page header of the data page stores slot identification and page attribute information.
[0106] Furthermore, the device further comprises: a generating module,
[0107] The acquisition module is further configured to acquire a target index page corresponding to the target data page;
[0108] The generating module is configured to generate a data index according to storage information of the column data to be stored in the target data page;
[0109] The storage module is further configured to store the data index in the target index page, and update the index level and index type of the index page based on the data index.
[0110] Furthermore, the target data page includes a first-written page and a currently written page.
[0111] The storage module is further configured to store the column data to be stored in the current write page if the slot identifier is found in the index file, and to store the column data to be stored in the first write page if the slot identifier is not found in the index file.
[0112] Furthermore, the device also includes: a conversion module, which is used to respond to a storage request of the data table, retrieve the row data in the data table in row units and store them in the transaction buffer; when responding to a row data storage request submitted by the transaction buffer, convert the row data into column data to be stored.
[0113] Furthermore, the creation module is also used to respond to a read instruction of the target data, determine the read slot identifier of the target data, and call the index file; if the read slot identifier is queried in the index file, the reference data page matching the read slot identifier and the reference index page corresponding to the reference data page are queried based on all non-public page headers; the storage information of the target data is queried from the reference index page, and the data content is read from the reference data page according to the storage information.
[0114] An embodiment of the present invention provides a data storage device. Compared with the prior art, the embodiment of the present invention obtains the slot identifier of a target row and the column data to be stored, wherein the slot identifier is generated by the distribution key of the target row; retrieves an index file, wherein the index file stores record information between different slot identifiers and data pages, and the data page is used to store data; determines the target data page corresponding to the slot identifier based on the record information, and stores the column data to be stored in the target data page, thereby realizing the storage of column data after forming a mapping relationship between the slot identifier and the page, thereby greatly improving the management efficiency of data storage, thereby improving the speed and accuracy of data reading and writing.
[0115] According to one embodiment of the present invention, a storage medium is provided, wherein the storage medium stores at least one executable instruction, and the computer executable instruction can execute the data storage method in any of the above method embodiments.
[0116] Figure 4 A schematic structural diagram of a terminal provided according to an embodiment of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the terminal.
[0117] like Figure 4 As shown, the terminal may include: a processor (processor) 302, a communication interface (Communications Interface) 304, a memory (memory) 306, and a communication bus 308.
[0118] The processor 302 , the communication interface 304 , and the memory 306 communicate with each other via a communication bus 308 .
[0119] The communication interface 304 is used to communicate with other devices such as clients or other servers.
[0120] The processor 302 is configured to execute the program 310 , and specifically may execute the relevant steps in the above-mentioned data storage method embodiment.
[0121] Specifically, the program 310 may include program codes, which include computer operation instructions.
[0122] Processor 302 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the terminal may be processors of the same type, such as one or more CPUs, or processors of different types, such as one or more CPUs and one or more ASICs.
[0123] The memory 306 is used to store the program 310. The memory 306 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0124] The program 310 may be specifically configured to cause the processor 302 to perform the following operations:
[0125] Obtaining a slot identifier of a target row and column data to be stored, wherein the slot identifier is generated based on a distribution key of the target row;
[0126] Retrieving an index file, wherein the index file stores record information between different slot identifiers and data pages, wherein the data pages are used to store data;
[0127] A target data page corresponding to the slot identifier is determined based on the record information, and the column data to be stored is stored in the target data page.
[0128] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, centralized on a single computing device, or distributed across a network of multiple computing devices. Alternatively, they can be implemented using program code executable by a computing device, which can then be stored in a storage device and executed by the computing device. In some cases, the steps shown or described can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0129] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention.
Claims
1. A data storage method, characterized in that: include: Obtaining a slot identifier of a target row and column data to be stored, wherein the slot identifier is generated based on a distribution key of the target row; Retrieving an index file, wherein the index file stores record information between different slot identifiers and data pages, wherein the data pages are used to store data; A target data page corresponding to the slot identifier is determined based on the record information, and the column data to be stored is stored in the target data page.
2. The method according to claim 1, characterized in that Determining the target data page corresponding to the slot identifier based on the index file includes: If the slot identifier is found in the index file, the target data page of the record information matching the slot identifier is retrieved; If the slot identifier is not found in the index file, a target data page of the slot identifier is generated, and record information of the slot identifier and the target data page is generated and stored in the index file.
3. The method according to claim 2, characterized in that Before obtaining the slot identifier of the target row and the column data to be stored, the method further includes: Create multiple data pages and index pages including common page headers and non-common page headers in a preset storage area; The public page header stores basic page information, the non-public page header of the index page stores index level and index type, and the non-public page header of the data page stores slot identification and page attribute information.
4. The method according to claim 3, characterized in that After storing the column data to be stored in the target data page, the method further includes: Obtaining a target index page corresponding to the target data page; Generate a data index according to storage information of the column data to be stored in the target data page; The data index is stored in the target index page, and the index level and index type of the index page are updated based on the data index.
5. The method according to claim 3, characterized in that The target data page includes a first-write page and a current-write page, and storing the to-be-stored column data in the target data page includes: If the slot identifier is found in the index file, the column data to be stored is stored in the current write page; If the slot identifier is not found in the index file, the column data to be stored is stored in the first write page.
6. The method according to claim 1, characterized in that Before obtaining the slot identifier of the target row and the column data to be stored, the method further includes: After responding to a storage request for a data table, retrieving row data from the data table in units of rows and storing the data in the transaction buffer; In response to a row data storage request submitted by the transaction buffer, the row data is converted into column data to be stored.
7. The method according to claim 1, characterized in that After storing the column data to be stored in the target data page, the method further includes: In response to a read instruction of target data, determining a read slot identifier of the target data and retrieving the index file; If the read slot identifier is found in the index file, searching for a reference data page matching the read slot identifier and a reference index page corresponding to the reference data page based on all non-public page headers; The storage information of the target data is queried from the reference index page, and the data content is read from the reference data page according to the storage information.
8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: Creating a system page, wherein the system page stores home page information of all index pages; When the system is restarted, the system page is read, and all slot identifiers and data pages corresponding to the slot identifiers are read from the home page information to reconstruct the index file.
9. A data storage device, characterized in that: include: An acquisition module, configured to acquire a slot identifier of a target row and column data to be stored, wherein the slot identifier is generated based on a distribution key of the target row; A calling module, configured to call an index file, wherein the index file stores record information between different slot identifiers and data pages, wherein the data pages are used to store data; A storage module is configured to determine a target data page corresponding to the slot identifier based on the record information, and store the column data to be stored in the target data page.
10. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to claim 1 are implemented.
11. A computer device comprising a memory, a processor, and a computer program stored in the memory, wherein: The processor executes the computer program to implement the steps of the method according to claim 1.
Citation Information
Patent Citations
File operation method and apparatus
CN105550345A
Storage control device, storage control method and recording medium
CN110134618A