Method and apparatus for processing a directory, storage medium, and processor
By building key-value pairs of directory identifiers, file name hash values and directory item number, the read inaccuracy problem caused by multiple directory items under the same inode number is solved, and the accurate positioning and efficient reading of directory items are achieved.
Patent Information
- Application Number
- CN202210212739.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-04
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2042-03-04
AI Technical Summary
In a file system based on key-value storage, when using the inode number as the offset position of the directory item, the accuracy of reading the directory item is low because the same inode may correspond to multiple directory items.
By obtaining the directory identifier of the target file and the hash value of the target file name, combining the number of the target directory item, a target key-value pair is constructed, and stored in the target database, and the target hash value and target number are used as the offset position of the target directory item.
Improves the accuracy of reading directory items, ensuring that directory items in the target directory can be read accurately during directory query.
Smart Images

Figure CN114691610B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distributed file storage technology, and in particular, to a method and device for processing directories, a storage medium, and a processor. Background Art
[0002] With the rapid development of network technology, the storage requirements of various network applications are increasing. To improve storage efficiency, distributed file systems have been proposed. Linux defines interfaces such as readdir to read the contents of directories in a distributed file system. When querying a directory, directory entries are read based on the offset position of the directory entry. The process of reading directory entries is generally as follows: The first readdir specifies the offset position as 0, and subsequent readdir operations specify the offset position as the offset position of the last directory entry returned in the previous operation, until the returned directory entry list is empty. For a file system based on key-value storage, the inode number is used as the offset position of the directory entry. However, there are some problems with this method: The same inode may correspond to multiple directory entries, and according to the inode number, the desired directory entry cannot be accurately queried.
[0003] Regarding the problem in the related art that using the inode number as the offset position of the directory entry may lead to low accuracy in reading directory entries because the same inode number may correspond to multiple directory entries, no effective solution has been proposed yet. Summary of the Invention
[0004] The main objective of this application is to provide a method and device for processing directories, a storage medium, and a processor, so as to solve the problem in the related art that using the inode number as the offset position of the directory entry may lead to low accuracy in reading directory entries because the same inode number may correspond to multiple directory entries.
[0005] To achieve the above objective, according to one aspect of this application, a method for processing directories is provided. The method includes: obtaining a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; obtaining a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; using the target hash value and the target number as a target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; obtaining a target key-value pair with the target key as the key and the target directory entry as the value, and forming the target directory through the target key-value pair, where the target directory is stored in a target database.
[0006] Further, obtaining the target directory entry corresponding to the target file includes: querying the first directory entry of the target key-value pair corresponding to the target hash value to obtain a query result; if the query result is empty, the target number is a preset value one; if the query result is not empty, determining the maximum number of the first directory entry in the query result; adding one to the maximum number to obtain a preset value two, and the preset value two is the target number; obtaining the inode number, and using the target number and the inode number as the target directory entry.
[0007] Further, obtaining the target key corresponding to the target file includes: obtaining the directory identifier of the target file, where the directory identifier is used to identify the target directory; obtaining the target file name of the target file, and performing a hash calculation on the target file name to obtain the target hash value; using the directory identifier, the target hash value, and the target file name as the target key.
[0008] Further, after forming the target directory through the target key-value pair, the method further includes: obtaining a first query request for the target file, where the query request at least includes: the target file name of the target file and the directory identifier; calculating the target hash value corresponding to the target file name, and querying the second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; sorting the second directory entry according to the target number of the second directory entry to obtain a first target set; and feeding back the first target set to the target object.
[0009] Further, after forming the target directory through the target key-value pair, the method further includes: obtaining a second query request for the target directory, where the second query request at least includes: the directory identifier and an initial offset position, and the initial offset position is a preset value three; querying the target directory in the target database according to the directory identifier; starting from the directory entry in the first key-value pair of the target directory and reading to obtain a second target set, where the second target set at least includes: all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory; and feeding back the second target set to the target object.
[0010] Further, starting from the directory entry in the first key-value pair of the target directory, the target set two is obtained, including: starting from the directory entry in the first key-value pair of the target directory, a preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, where the offset positions corresponding to the third directory entries are greater than or equal to the initial offset position; taking the offset position corresponding to the last directory entry in the third directory entries as the initial offset position; according to the initial offset position, directory entries are read in the target directory to obtain a preset number of fourth directory entries and the offset positions corresponding to the fourth directory entries, where the offset positions corresponding to the fourth directory entries are greater than the initial offset position; continuing to execute the step of taking the offset position corresponding to the last directory entry in the fourth directory entries as the initial offset position until all directory entries in the target directory are read; taking all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory as the target set two.
[0011] Further, obtaining a preset number of third directory entries and the offset positions corresponding to the third directory entries starting from the directory entry in the first key-value pair of the target directory includes: determining the first offset position corresponding to the directory entry in the first key-value pair according to the first key-value pair of the target directory; judging whether the first offset position is greater than or equal to the initial offset position; if the first offset position is greater than or equal to the initial offset position, the directory entry in the first key-value pair is the third directory entry; continuing to execute the step of determining the second offset position corresponding to the directory entry in the second key-value pair according to the second key-value pair of the target directory until the preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, or all directory entries of the target directory are read.
[0012] To achieve the above object, according to another aspect of the present application, a directory processing device is provided. The device includes: a first obtaining unit, configured to obtain a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; a second obtaining unit, configured to obtain a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; a determining unit, configured to use the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; a building unit, configured to use the target key as the key and the target directory entry as the value to obtain a target key-value pair, and build the target directory through the target key-value pair, where the target directory is stored in a target database.
[0013] Further, the second obtaining unit includes: a query module, configured to query a first directory entry of a target key-value pair corresponding to the target hash value to obtain a query result; a first determination module, configured to, if the query result is empty, set the target number to a preset value one; a second determination module, configured to, if the query result is not empty, determine a maximum number of the first directory entry in the query result; a third determination module, configured to increment the maximum number by one to obtain a preset value two, and the preset value two is the target number; and a first obtaining module, configured to obtain the inode number, and use the target number and the inode number as the target directory entry.
[0014] Further, the first obtaining unit includes: a second obtaining module, configured to obtain a directory identifier of the target file, where the directory identifier is used to identify the target directory; a calculation module, configured to obtain a target file name of the target file and perform a hash calculation on the target file name to obtain the target hash value; and a fourth determination module, configured to use the directory identifier, the target hash value, and the target file name as the target key.
[0015] Further, the apparatus further includes: a third obtaining unit, configured to, after forming the target directory by using the target key-value pair, obtain a first query request for the target file, where the query request at least includes: the target file name of the target file and the directory identifier; a calculation unit, configured to calculate a target hash value corresponding to the target file name, and query a second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; a sorting unit, configured to sort the second directory entries according to the target numbers of the second directory entries to obtain a first target set; and a first feedback unit, configured to feedback the first target set to a target object.
[0016] Further, the apparatus further includes: a fourth obtaining unit, configured to, after forming the target directory by using the target key-value pair, obtain a second query request for the target directory, where the second query request at least includes: the directory identifier and an initial offset position, and the initial offset position is a preset value three; a query unit, configured to query the target directory in the target database according to the directory identifier; a reading unit, configured to start reading from a directory entry in a first key-value pair of the target directory to obtain a second target set, where the second target set at least includes: all directory entries in the target directory and offset positions corresponding to all directory entries in the target directory; and a second feedback unit, configured to feedback the second target set to the target object.
[0017] Further, the reading unit includes: a first reading module, configured to start reading from the directory entry in the first key-value pair of the target directory, to obtain a preset number of third directory entries and the offset positions corresponding to the third directory entries, wherein the offset positions corresponding to the third directory entries are greater than or equal to the initial offset position; a fifth determining module, configured to use the offset position corresponding to the last directory entry among the third directory entries as the initial offset position; a second reading module, configured to, according to the initial offset position, read directory entries in the target directory, to obtain a preset number of fourth directory entries and the offset positions corresponding to the fourth directory entries, wherein the offset positions corresponding to the fourth directory entries are greater than the initial offset position; an execution module, configured to continue to execute the step of using the offset position corresponding to the last directory entry among the fourth directory entries as the initial offset position until all directory entries in the target directory have been read; a sixth determining module, configured to use all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory as the target set two.
[0018] Further, the first reading module includes: a first determining sub-module, configured to determine, according to the first key-value pair of the target directory, the first offset position corresponding to the directory entry in the first key-value pair; a judgment sub-module, configured to judge whether the first offset position is greater than or equal to the initial offset position; a second determining sub-module, configured to, if the first offset position is greater than or equal to the initial offset position, use the directory entry in the first key-value pair as the third directory entry; and an execution sub-module, configured to continue to execute the step of determining, according to the second key-value pair of the target directory, the second offset position corresponding to the directory entry in the second key-value pair until the preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, or all directory entries of the target directory have been read.
[0019] To achieve the above object, according to another aspect of the present application, there is provided a computer-readable storage medium storing a program, wherein when the program runs, it controls the device where the storage medium is located to execute the processing method of the directory described in any one of the above.
[0020] To achieve the above object, according to another aspect of the present application, there is provided a processor for running a program, wherein when the program runs, it executes the processing method of the directory described in any one of the above.
[0021] Through the present application, the following steps are adopted: obtaining a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; obtaining a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; using the target hash value and the target number as a target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; using the target key as the key and the target directory entry as the value to obtain a target key-value pair, and forming a target directory through the target key-value pair, where the target directory is stored in a target database, which solves the problem in the related art that when using the inode number as the offset position of the directory entry, since the same inode number may correspond to multiple directory entries, the accuracy of reading the directory entry is relatively low. By using the directory identifier, the target hash value corresponding to the target file name of the target file, and the target file name as the target key, and the target directory entry as the value to obtain a target key-value pair, and forming a target directory through the target key-value pair, and then using the target hash value and the target number as the target offset position of the target directory entry, when performing directory query, the directory entry in the target directory can be accurately read according to the target offset position, thereby achieving the effect of improving the accuracy of reading the directory entry. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings that form a part of this application are used to provide a further understanding of this application. The schematic embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation to this application. In the accompanying drawings:
[0023] Figure 1 is a flowchart of a method for processing a directory according to an embodiment of this application;
[0024] Figure 2 is a schematic diagram of a device for processing a directory according to an embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] It should be noted that, without conflict, the embodiments in this application and the features in the embodiments may be combined with each other. The following will refer to the accompanying drawings and combine the embodiments to describe this application in detail.
[0026] In order to enable those skilled in the art to better understand the solution of this application, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application.
[0027] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of this application are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that such data used can be interchanged under appropriate circumstances, so as to implement the embodiments of the present application described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0028] The present invention will be described below in conjunction with preferred implementation steps. Figure 1 is a flowchart of a method for processing a directory provided according to an embodiment of the present application, as Figure 1 shown, the method includes the following steps:
[0029] Step S101, obtain a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name.
[0030] Specifically, a target key corresponding to the target file is constructed by the target identifier, the target file name, and the hash value corresponding to the target file name. For example, for the target file file1, the hash value corresponding to file1 is file1 => 584b61, and the directory identifier is 90b9, so the corresponding target key is D90b9 584b61 file1.
[0031] Step S102, obtain a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file.
[0032] Specifically, a target directory entry corresponding to the target file is obtained, and the target directory entry needs to include the target number of the target directory entry and the inode number. For example, the target number of the target directory entry is 0, and the inode number is 0x90ba, then the corresponding target directory entry is {serial = 0, inode = 0x90ba,...}.
[0033] Step S103, use the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory.
[0034] Specifically, the above-mentioned target hash value and target number are formed into the target offset position of the target directory entry. For example, a 24-bit target hash value and an 8-bit target number are used as the target offset position of the target directory entry, and the offset position of the above-mentioned target directory entry is 584b6100. It should be noted that the number of bits of the target hash value and the target number can be set according to the actual situation.
[0035] Step S104: Using the target key as the key and the target directory entry as the value, obtain the target key-value pair, and form the target directory through the target key-value pair, where the target directory is stored in the target database.
[0036] Specifically, using the target key as the key and the target directory entry as the value, form the target key-value pair. For example, if the target key is D90b9584b61 file1 and the target directory entry is {serial = 0, inode = 0x90ba,...}, then the corresponding target key-value pair is D 90b9 584b61 file1-->{serial = 0, inode = 0x90ba,...}. The key-value pairs of the target directory are sorted in ascending order of the key. The key can be a string of any length. The key-value pairs in a certain directory are as follows:
[0037] D 90b9 584b61 file1-->{serial = 0, inode = 0x90ba,...}
[0038] D 90b9 584b61 filex-->{serial = 1, inode = 0x90c1,...}
[0039] D 90b9 584c11 file2-->{serial = 0, inode = 0x90bb,...}
[0040] D 90b9 584cc1 file3-->{serial = 0, inode = 0x90bc,...}
[0041] D 90b9 584d71 file4-->{serial = 0, inode = 0x90bd,...}.
[0042] In summary, through the directory identifier, using the target hash value corresponding to the target file name and the target file name as the target key, and the target directory entry as the value, obtain the target key-value pair, and form the target directory through the target key-value pair. Then, using the target hash value and the target number as the target offset position of the target directory entry, when performing directory queries, the directory entry in the target directory can be accurately read according to the target offset position, improving the accuracy of reading the directory entry.
[0043] Optionally, in the method for processing a directory provided in the embodiments of the present application, obtaining a target directory entry corresponding to a target file includes: querying a first directory entry of a target key-value pair corresponding to a target hash value to obtain a query result; if the query result is empty, the target number is a preset value one; if the query result is not empty, determining the maximum number of the first directory entry in the query result; adding one to the maximum number to obtain a preset value two, and the preset value two is the target number; obtaining an inode number, and using the target number and the inode number as the target directory entry.
[0044] Specifically, calculate a target hash value according to the target file name, and then query all existing directory entries under the target hash value. If the query result is empty, the target number of the target directory entry is 0 (i.e., the above-mentioned preset value one); if the query result is not empty, the target number of the target directory entry is the maximum value of the existing target numbers +1. Then obtain the inode number, and use the target number and the inode number as the target directory entry. Through the above steps, when the hash values are the same, different directory entries can be accurately distinguished by the target number.
[0045] Optionally, in the method for processing a directory provided in the embodiments of the present application, obtaining a target key corresponding to a target file includes: obtaining a directory identifier of the target file, where the directory identifier is used to identify the target directory; obtaining the target file name of the target file, and performing a hash calculation on the target file name to obtain a target hash value; using the directory identifier, the target hash value, and the target file name as the target key.
[0046] Specifically, obtaining the target key includes: obtaining the directory identifier of the target file, then performing a hash calculation on the target file name through a hash algorithm to obtain a target hash value, and then using the directory identifier, the target hash value, and the target file name as the target key. The hash algorithm can map a string of variable length to a binary string of fixed length, and this binary string of fixed length is the target hash value, and the target hash value has the characteristics of stability and reliability.
[0047] Optionally, in the method for processing a directory provided in the embodiments of the present application, after forming a target directory through a target key-value pair, the method further includes: obtaining a first query request for a target file, where the query request at least includes: the target file name and the directory identifier of the target file; calculating a target hash value corresponding to the target file name, and querying a second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; sorting the second directory entries according to the target numbers of the second directory entries to obtain a first target set; feeding back the first target set to a target object.
[0048] Specifically, when a query request for a target file is needed, obtain query request one for the target file. Query request one needs to include the target file name of the target file and a directory identifier. Calculate the target hash value from the target file name, and then query the second directory entry in the key-value pair corresponding to the target hash value in the target directory corresponding to the directory identifier. The second directory entry may be one or multiple. If there are multiple second directory entries, then sort the second directory entries according to the target number of the second directory entry to obtain target set one, and then feedback target set one to the query personnel (i.e., the above-mentioned target object). Through the above steps, the target file can be accurately queried and obtained.
[0049] Optionally, in the directory processing method provided in the embodiments of the present application, the method further includes: obtaining query request two for the target directory, where query request two at least includes: a directory identifier and an initial offset position, and the initial offset position is preset value three; according to the directory identifier, query the target directory in the target database; start reading from the directory entry in the first key-value pair of the target directory to obtain target set two, where target set two at least includes: all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory; feedback target set two to the target object.
[0050] Specifically, when it is necessary to query which directory entries are in the target directory, obtain query request two for the target directory. Query request two needs to include a directory identifier and an initial offset position. When querying, if you don't know which directory entries there are and don't know the offset position (offset) of the directory entries, then use offset = 0 (i.e., the above-mentioned preset value three), that is, start reading from the first item of the directory. Find the corresponding target directory according to the directory identifier, start reading from the directory entry in the first key-value pair of the target directory to obtain target set two, and then feedback target set two to the query personnel. For example, target set two includes:
[0051] name = file1 offset = 584b6100;
[0052] name = filex offset = 584b6101;
[0053] name = file2 offset = 584c1100;
[0054] name = file3 offset = 584cc100;
[0055] name = file4 offset = 584d7100.
[0056] Through the above steps, all directory entries in the target directory can be accurately queried and obtained.
[0057] Optionally, in the method for processing a directory provided in the embodiments of the present application, starting from the directory entry in the first key-value pair of the target directory, a target set two is obtained, including: starting from the directory entry in the first key-value pair of the target directory, a preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, where the offset position corresponding to the third directory entry is greater than or equal to the initial offset position; taking the offset position corresponding to the last directory entry in the third directory entry as the initial offset position; according to the initial offset position, reading directory entries in the target directory to obtain a preset number of fourth directory entries and the offset positions corresponding to the fourth directory entries, where the offset position corresponding to the fourth directory entry is greater than the initial offset position; continuing to execute the step of taking the offset position corresponding to the last directory entry in the fourth directory entry as the initial offset position until all directory entries in the target directory are read; taking all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory as the target set two.
[0058] Specifically, taking the following directory as an example, the obtaining of the target set two is described:
[0059] D 90b9 584b61 file1-->{serial=0,inode=0x90ba,...}
[0060] D 90b9 584b61 filex-->{serial=1,inode=0x90c1,...}
[0061] D 90b9 584c11 file2-->{serial=0,inode=0x90bb,...}
[0062] D 90b9 584cc1 file3-->{serial=0,inode=0x90bc,...}
[0063] D 90b9 584d71 file4-->{serial=0,inode=0x90bd,...}
[0064] Assume that 2 directory entries are returned at a time, then the process of reading the directory is as follows:
[0065] The first call:
[0066] Client: readdir(dirid=90b9,offset=0)
[0067] Server: offset=0=>hash_index=0,serial=0
[0068] Start reading from the first key greater than or equal to D90b9000000:
[0069] D 90b9 584b61 file1 => name = file1 offset = 584b6100, greater than the passed-in offset, return this directory entry;
[0070] D 90b9 584b61 filex => name = filex offset = 584b6101, greater than the passed-in offset, return this directory entry;
[0071] Get the third directory entry and the offset position of the third directory entry:
[0072] name = file1 offset = 584b6100
[0073] name = filex offset = 584b6101.
[0074] Second call:
[0075] Client: readdir(dirid = 90b9, offset = 584b6101) / / Use the offset of the last file returned last time as the offset for this call;
[0076] Server: offset = 584b6101 => hash_index = 584b61, serial = 1;
[0077] Start reading from the first key greater than or equal to D90b9584b61:
[0078] D 90b9 584b61 file1 => name = file1 offset = 584b6100, less than the passed-in offset, skip
[0079] D 90b9 584b61 filex => name = filex offset = 584b6101, equal to the passed-in offset, skip
[0080] D 90b9 584c11 file2 => name = file2 offset = 584c1100, greater than the passed-in offset, return
[0081] D 90b9 584cc1 file3 => name = file2 offset = 584cc100, greater than the passed-in offset, return
[0082] Obtain the fourth directory entry and its offset position:
[0083] name=file2 offset=584c1100
[0084] name=file3 offset=584cc100。
[0085] The third call:
[0086] Client: readdir(dirid=90b9,offset=584cc100)
[0087] Server: offset=584cc100=>hash_index=584cc1, serial=0
[0088] Start reading from the first key greater than or equal to D90b9584cc1:
[0089] D 90b9 584cc1 file3=>name=file3 offset=584cc100, equal to the passed-in offset, skip
[0090] D 90b9 584d71 file4=>name=file4 offset=584d7100, equal to the passed-in offset, return
[0091] At this time, all directory entries in the directory have been read, exit;
[0092] Since there is only one directory entry, it can be confirmed that the end of the directory has been read, then the corresponding target set two is:
[0093] name=file1 offset=584b6100;
[0094] name=filex offset=584b6101;
[0095] name=file2 offset=584c1100;
[0096] name=file3 offset=584cc100;
[0097] name=file4 offset=584d7100。
[0098] Through the above process, the directory entries can be accurately located through the offset position, and when a certain directory entry is deleted, the next directory entry to be read can still be accurately located through the offset position.
[0099] Optionally, in the method for processing a directory provided in the embodiments of the present application, reading from the directory entry in the first key-value pair of the target directory to obtain a preset number of third directory entries and the offset positions corresponding to the third directory entries includes: determining, according to the first key-value pair of the target directory, the first offset position corresponding to the directory entry in the first key-value pair; judging whether the first offset position is greater than or equal to the initial offset position; if the first offset position is greater than or equal to the initial offset position, the directory entry in the first key-value pair is the third directory entry; continuing to execute the step of determining, according to the second key-value pair of the target directory, the second offset position corresponding to the directory entry in the second key-value pair until a preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, or all directory entries of the target directory have been read.
[0100] Specifically, reading the third directory entry and the offset position corresponding to the third directory entry includes: querying the first key-value pair of the target directory, and then determining, according to the first key-value pair, the first offset position corresponding to the directory entry in the first key-value pair. When the first offset position is greater than or equal to the initial offset position, the directory entry in the first key-value pair is the third directory entry, and a preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained according to the above method.
[0101] In the method for processing a directory provided in the embodiments of the present application, by obtaining a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; obtaining a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; using the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; using the target key as the key and the target directory entry as the value to obtain a target key-value pair, and forming a target directory through the target key-value pair, where the target directory is stored in a target database, which solves the problem in the related art that when using the inode number as the offset position of the directory entry, since the same inode number may correspond to multiple directory entries, the accuracy of reading the directory entry is relatively low. By using the directory identifier, the target hash value corresponding to the target file name of the target file, and the target file name as the target key, and the target directory entry as the value to obtain a target key-value pair, and forming a target directory through the target key-value pair, and then using the target hash value and the target number as the target offset position of the target directory entry, when performing directory query, the directory entry in the target directory can be accurately read according to the target offset position, thereby achieving the effect of improving the accuracy of reading the directory entry.
[0102] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0103] The embodiment of the present application also provides a processing device for a directory. It should be noted that the processing device for the directory in the embodiment of the present application can be used to execute the processing method for the directory provided in the embodiment of the present application. The following introduces the processing device for the directory provided in the embodiment of the present application.
[0104] Figure 2 is a schematic diagram of the processing device for the directory according to the embodiment of the present application. As Figure 2 shown, the device includes: a first acquisition unit 201, a second acquisition unit 202, a determination unit 203, and a construction unit 204.
[0105] The first acquisition unit 201 is used to acquire a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name.
[0106] The second acquisition unit 202 is used to acquire a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file.
[0107] The determination unit 203 is used to use the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory.
[0108] The construction unit 204 is used to obtain a target key-value pair with the target key as the key and the target directory entry as the value, and construct a target directory through the target key-value pair, where the target directory is stored in the target database.
[0109] The directory processing device provided by the embodiment of the present application obtains a target key corresponding to a target file through a first acquisition unit 201, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; a second acquisition unit 202 obtains a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; a determination unit 203 uses the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; an assembly unit 204 uses the target key as the key and the target directory entry as the value to obtain a target key-value pair, and forms a target directory through the target key-value pair, where the target directory is stored in a target database, which solves the problem in the related art that when using the inode number as the offset position of the directory entry, since the same inode number may correspond to multiple directory entries, the accuracy of reading the directory entry is relatively low. By using the directory identifier, the target hash value corresponding to the target file name of the target file, and the target file name as the target key, and the target directory entry as the value, a target key-value pair is obtained, and a target directory is formed through the target key-value pair. Then, by using the target hash value and the target number as the target offset position of the target directory entry, when performing a directory query, the directory entry in the target directory can be accurately read according to the target offset position, thereby achieving the effect of improving the accuracy of reading the directory entry.
[0110] Optionally, in the directory processing device provided by the embodiment of the present application, the second acquisition unit 202 includes: a query module, configured to query a first directory entry of a target key-value pair corresponding to the target hash value to obtain a query result; a first determination module, configured to set the target number to a preset value one if the query result is empty; a second determination module, configured to determine the maximum number of the first directory entry in the query result if the query result is not empty; a third determination module, configured to add one to the maximum number to obtain a preset value two, and the preset value two is the target number; a first acquisition module, configured to acquire the inode number, and use the target number and the inode number as the target directory entry.
[0111] Optionally, in the directory processing device provided by the embodiment of the present application, the first acquisition unit includes: a second acquisition module, configured to acquire a directory identifier of the target file, where the directory identifier is used to identify the target directory; a calculation module, configured to acquire the target file name of the target file and perform a hash calculation on the target file name to obtain the target hash value; a fourth determination module, configured to use the directory identifier, the target hash value, and the target file name as the target key.
[0112] Optionally, in the directory processing device provided in the embodiments of the present application, the device further includes: a third acquisition unit, configured to, after forming a target directory through a target key-value pair, acquire a first query request for a target file, where the query request at least includes: a target file name of the target file and a directory identifier; a calculation unit, configured to calculate a target hash value corresponding to the target file name, and query a second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; a sorting unit, configured to sort the second directory entries according to the target numbers of the second directory entries to obtain a first target set; a first feedback unit, configured to feedback the first target set to a target object.
[0113] Optionally, in the directory processing device provided in the embodiments of the present application, the device further includes: a fourth acquisition unit, configured to, after forming a target directory through a target key-value pair, acquire a second query request for the target directory, where the second query request at least includes: a directory identifier and an initial offset position, and the initial offset position is a preset value three; a query unit, configured to query the target directory in the target database according to the directory identifier; a reading unit, configured to start reading from the directory entry in the first key-value pair of the target directory to obtain a second target set, where the second target set at least includes: all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory; a second feedback unit, configured to feedback the second target set to the target object.
[0114] Optionally, in the directory processing device provided in the embodiments of the present application, the reading unit includes: a first reading module, configured to start reading from the directory entry in the first key-value pair of the target directory to obtain a preset number of third directory entries and the offset positions corresponding to the third directory entries, where the offset positions corresponding to the third directory entries are greater than or equal to the initial offset position; a fifth determination module, configured to use the offset position corresponding to the last directory entry in the third directory entries as the initial offset position; a second reading module, configured to read directory entries in the target directory according to the initial offset position to obtain a preset number of fourth directory entries and the offset positions corresponding to the fourth directory entries, where the offset positions corresponding to the fourth directory entries are greater than the initial offset position; an execution module, configured to continue to execute the step of using the offset position corresponding to the last directory entry in the fourth directory entries as the initial offset position until all directory entries in the target directory are read; a sixth determination module, configured to use all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory as the second target set.
[0115] Optionally, in the processing device of the directory provided in the embodiments of the present application, the first reading module includes: a first determination sub-module, configured to determine a first offset position corresponding to an entry in the first key-value pair according to the first key-value pair of the target directory; a judgment sub-module, configured to judge whether the first offset position is greater than or equal to the initial offset position; a second determination sub-module, configured to, if the first offset position is greater than or equal to the initial offset position, determine that the entry in the first key-value pair is the third entry; and an execution sub-module to continue to execute the step of determining a second offset position corresponding to the entry in the second key-value pair according to the second key-value pair of the target directory until a preset number of third entries and the offset positions corresponding to the third entries are obtained, or all the entries of the target directory are read.
[0116] The processing device of the directory includes a processor and a memory. The above-mentioned first obtaining unit 201, second obtaining unit 202, determining unit 203, and constructing unit 204 are all stored in the memory as program units, and the corresponding functions are implemented by the processor executing the above program units stored in the memory.
[0117] The processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and accurate query of the directory can be achieved by adjusting the kernel parameters.
[0118] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM), and / or forms such as non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory includes at least one storage chip.
[0119] The embodiments of the present invention provide a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the directory processing method is implemented.
[0120] The embodiments of the present invention provide a processor, and the processor is used to run a program, wherein when the program runs, the directory processing method is executed.
[0121] The embodiments of the present invention provide a device, the device includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, the following steps are implemented: obtaining a target directory entry corresponding to a target file, where the target directory entry at least includes: a target number and an inode number of the target directory entry, and the inode number is used to identify the target file; using the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; using the target key as the key and the target directory entry as the value to obtain a target key-value pair, and constructing a target directory through the target key-value pair, where the target directory is stored in the target database.
[0122] Optionally, obtaining the target directory entry corresponding to the target file includes: querying the first directory entry of the target key-value pair corresponding to the target hash value to obtain a query result; if the query result is empty, the target number is a preset value one; if the query result is non-empty, determining the maximum number of the first directory entry in the query result; adding one to the maximum number to obtain a preset value two, and the preset value two is the target number; obtaining the inode number, and using the target number and the inode number as the target directory entry.
[0123] Optionally, obtaining the target key corresponding to the target file includes: obtaining the directory identifier of the target file, where the directory identifier is used to identify the target directory; obtaining the target file name of the target file and performing a hash calculation on the target file name to obtain a target hash value; using the directory identifier, the target hash value, and the target file name as the target key.
[0124] Optionally, after forming the target directory through the target key-value pairs, the method further includes: obtaining a first query request for the target file, where the query request at least includes: the target file name of the target file and the directory identifier; calculating the target hash value corresponding to the target file name, and querying the second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; sorting the second directory entry according to the target number of the second directory entry to obtain a first target set; and feeding back the first target set to the target object.
[0125] Optionally, after forming the target directory through the target key-value pairs, the method further includes: obtaining a second query request for the target directory, where the second query request at least includes: the directory identifier and an initial offset position, and the initial offset position is a preset value three; querying the target directory in the target database according to the directory identifier; starting from the directory entry in the first key-value pair of the target directory and reading to obtain a second target set, where the second target set at least includes: all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory; and feeding back the second target set to the target object.
[0126] Optionally, start reading from the directory entry in the first key-value pair of the target directory, and obtain target set two, including: start reading from the directory entry in the first key-value pair of the target directory to obtain a preset number of third directory entries and the offset positions corresponding to the third directory entries, where the offset position corresponding to the third directory entry is greater than or equal to the initial offset position; use the offset position corresponding to the last directory entry in the third directory entries as the initial offset position; based on the initial offset position, read directory entries in the target directory to obtain a preset number of fourth directory entries and the offset positions corresponding to the fourth directory entries, where the offset position corresponding to the fourth directory entry is greater than the initial offset position; continue to execute the step of using the offset position corresponding to the last directory entry in the fourth directory entries as the initial offset position until all directory entries in the target directory have been read; use all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory as target set two.
[0127] Optionally, starting to read from the directory entry in the first key-value pair of the target directory to obtain a preset number of third directory entries and the offset positions corresponding to the third directory entries includes: determining, according to the first key-value pair of the target directory, the first offset position corresponding to the directory entry in the first key-value pair; determining whether the first offset position is greater than or equal to the initial offset position; if the first offset position is greater than or equal to the initial offset position, the directory entry in the first key-value pair is the third directory entry; continue to execute the step of determining, according to the second key-value pair of the target directory, the second offset position corresponding to the directory entry in the second key-value pair until a preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, or all directory entries of the target directory have been read. The device in this article may be a server, a PC, a PAD, a mobile phone, etc.
[0128] This application also provides a computer program product, which, when executed on a data processing device, is adapted to execute a program initialized with the following method steps: obtaining a target directory entry corresponding to a target file, where the target directory entry at least includes: the target number of the target directory entry and the inode number, and the inode number is used to identify the target file; using the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; using the target key as the key and the target directory entry as the value to obtain a target key-value pair, and forming a target directory through the target key-value pair, where the target directory is stored in the target database.
[0129] Optionally, obtaining the target directory entry corresponding to the target file includes: querying the first directory entry of the target key-value pair corresponding to the target hash value to obtain a query result; if the query result is empty, the target number is a preset value one; if the query result is not empty, determining the maximum number of the first directory entry in the query result; adding one to the maximum number to obtain a preset value two, and the preset value two is the target number; obtaining the inode number, and using the target number and the inode number as the target directory entry.
[0130] Optionally, obtaining the target key corresponding to the target file includes: obtaining the directory identifier of the target file, where the directory identifier is used to identify the target directory; obtaining the target file name of the target file, and performing a hash calculation on the target file name to obtain a target hash value; using the directory identifier, the target hash value, and the target file name as the target key.
[0131] Optionally, after forming the target directory through the target key-value pair, the method further includes: obtaining a first query request for the target file, where the query request at least includes: the target file name of the target file and the directory identifier; calculating the target hash value corresponding to the target file name, and querying the second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; sorting the second directory entry according to the target number of the second directory entry to obtain a first target set; and feeding back the first target set to the target object.
[0132] Optionally, the method further includes: obtaining a second query request for the target directory, where the second query request at least includes: the directory identifier and an initial offset position, and the initial offset position is a preset value three; querying the target directory in the target database according to the directory identifier; starting from the directory entry in the first key-value pair of the target directory and reading to obtain a second target set, where the second target set at least includes: all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory; and feeding back the second target set to the target object.
[0133] Optionally, start reading from the directory entry in the first key-value pair of the target directory, and obtain Target Set Two, which includes: starting from the directory entry in the first key-value pair of the target directory, obtaining a preset number of third directory entries and the corresponding offset positions of the third directory entries, where the offset position corresponding to the last directory entry among the third directory entries is greater than or equal to the initial offset position; using the offset position corresponding to the last directory entry among the third directory entries as the initial offset position; based on the initial offset position, reading directory entries in the target directory to obtain a preset number of fourth directory entries and the corresponding offset positions of the fourth directory entries, where the offset position corresponding to the fourth directory entry is greater than the initial offset position; continue to execute the step of using the offset position corresponding to the last directory entry among the fourth directory entries as the initial offset position until all directory entries in the target directory have been read; using all directory entries in the target directory and the corresponding offset positions of all directory entries in the target directory as Target Set Two.
[0134] Optionally, starting from the directory entry in the first key-value pair of the target directory, obtaining a preset number of third directory entries and the corresponding offset positions of the third directory entries includes: determining the first offset position corresponding to the directory entry in the first key-value pair according to the first key-value pair of the target directory; determining whether the first offset position is greater than or equal to the initial offset position; if the first offset position is greater than or equal to the initial offset position, then the directory entry in the first key-value pair is the third directory entry; continue to execute the step of determining the second offset position corresponding to the directory entry in the second key-value pair according to the second key-value pair of the target directory until a preset number of third directory entries and the corresponding offset positions of the third directory entries are obtained, or all directory entries in the target directory have been read.
[0135] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0136] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowcharts and / or block diagrams, and the combination of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate for implementing the process Figure 1one or more processes and / or blocks Figure 1 a device for the functions specified in one or more blocks
[0137] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured article including an instruction device that implements the processes Figure 1 one or more processes and / or blocks Figure 1 the functions specified in one or more blocks
[0138] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are performed on the computer or other programmable device to produce a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in the processes Figure 1 one or more processes and / or blocks Figure 1 the functions specified in one or more blocks
[0139] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0140] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
[0141] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
[0142] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the element.
[0143] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0144] The above are only embodiments of the present application and are not used to limit the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A method for processing a directory, characterized in that Including: Obtain a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; Obtain a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; Use the target hash value and the target number as a target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; Use the target key as the key and the target directory entry as the value to obtain a target key-value pair, and form the target directory through the target key-value pair, where the target directory is stored in a target database.
2. The method according to claim 1, characterized in that, Obtaining the target directory entry corresponding to the target file includes: Query a first directory entry of a target key-value pair corresponding to the target hash value to obtain a query result; If the query result is empty, the target number is a preset value one; If the query result is not empty, determine the maximum number of the first directory entry in the query result; Add one to the maximum number to obtain a preset value two, and the preset value two is the target number; Obtain the inode number, and use the target number and the inode number as the target directory entry.
3. The method according to claim 1, wherein Obtaining the target key corresponding to the target file includes: Obtain the directory identifier of the target file, where the directory identifier is used to identify the target directory; Obtain the target file name of the target file, and perform a hash calculation on the target file name to obtain the target hash value; Use the directory identifier, the target hash value, and the target file name as the target key.
4. The method according to claim 1, wherein After forming the target directory through the target key-value pair, the method further includes: Obtain a first query request of the target file, where the query request at least includes: the target file name of the target file and the directory identifier; Calculate the target hash value corresponding to the target file name, and query a second directory entry corresponding to the target hash value in the target directory corresponding to the directory identifier; Sort the second directory entry according to the target number of the second directory entry to obtain a first target set; Feed back the first target set to a target object.
5. The method according to claim 1, wherein After forming the target directory through the target key-value pair, the method further includes: Obtain a second query request of the target directory, where the second query request at least includes: the directory identifier and an initial offset position, and the initial offset position is a preset value three; Query the target directory in the target database according to the directory identifier; Start reading from the directory entry in the first key-value pair of the target directory to obtain a second target set, where the second target set at least includes: all directory entries in the target directory and offset positions corresponding to all directory entries in the target directory; Feed back the second target set to a target object.
6. The method according to claim 5, wherein Start reading from the directory entry in the first key-value pair of the target directory, and obtain Target Set Two including: Start reading from the directory entry in the first key-value pair of the target directory, and obtain a preset number of third directory entries and the offset positions corresponding to the third directory entries, where the offset positions corresponding to the third directory entries are greater than or equal to the initial offset position; Use the offset position corresponding to the last directory entry among the third directory entries as the initial offset position; According to the initial offset position, read directory entries in the target directory, and obtain a preset number of fourth directory entries and the offset positions corresponding to the fourth directory entries, where the offset positions corresponding to the fourth directory entries are greater than the initial offset position; Continue to execute the step of using the offset position corresponding to the last directory entry among the fourth directory entries as the initial offset position until all directory entries in the target directory are read; Use all directory entries in the target directory and the offset positions corresponding to all directory entries in the target directory as Target Set Two.
7. The method according to claim 6, characterized in that, Start reading from the directory entry in the first key-value pair of the target directory, and obtaining a preset number of third directory entries and the offset positions corresponding to the third directory entries includes: Determine the first offset position corresponding to the directory entry in the first key-value pair according to the first key-value pair of the target directory; Judge whether the first offset position is greater than or equal to the initial offset position; If the first offset position is greater than or equal to the initial offset position, the directory entry in the first key-value pair is the third directory entry; Continue to execute the step of determining the second offset position corresponding to the directory entry in the second key-value pair according to the second key-value pair of the target directory until the preset number of third directory entries and the offset positions corresponding to the third directory entries are obtained, or all directory entries of the target directory are read.
8. A processing device for a directory, characterized in that Including: A first acquisition unit for acquiring a target key corresponding to a target file, where the target key includes: a directory identifier, a target hash value corresponding to the target file name of the target file, and the target file name; A second acquisition unit for acquiring a target directory entry corresponding to the target file, where the target directory entry at least includes: a target number of the target directory entry and an inode number, and the inode number is used to identify the target file; A determination unit for using the target hash value and the target number as the target offset position of the target directory entry, where the target offset position is used to locate the target directory entry when reading the target directory; An assembly unit for obtaining a target key-value pair with the target key as the key and the target directory entry as the value, and assembling the target directory through the target key-value pair, where the target directory is stored in a target database.
9. A computer-readable storage medium, characterized in that, The storage medium stores a program, where the program executes the directory processing method according to any one of claims 1 to 7.
10. A processor, characterized in that, The processor is used to run the program, where the program executes the directory processing method according to any one of claims 1 to 7 when running.
Citation Information
Patent Citations
Directory processing method, server and storage medium
CN113760853A
Key value database-based data storage method and retrieval method and corresponding devices
CN114090575A