WO2013097115A1 - 文件目录存储方法、检索方法和设备 - Google Patents

文件目录存储方法、检索方法和设备 Download PDF

Info

Publication number
WO2013097115A1
WO2013097115A1 PCT/CN2011/084820 CN2011084820W WO2013097115A1 WO 2013097115 A1 WO2013097115 A1 WO 2013097115A1 CN 2011084820 W CN2011084820 W CN 2011084820W WO 2013097115 A1 WO2013097115 A1 WO 2013097115A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
character
current
pointer
sibling
Prior art date
Application number
PCT/CN2011/084820
Other languages
English (en)
French (fr)
Inventor
晏勇文
曾祥勇
张�浩
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to PCT/CN2011/084820 priority Critical patent/WO2013097115A1/zh
Priority to CN2011800036614A priority patent/CN103299297A/zh
Publication of WO2013097115A1 publication Critical patent/WO2013097115A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices

Definitions

  • the present invention relates to the field of data storage technologies, and in particular, to a file directory storage method, a retrieval method, and a device. Background technique
  • a container In an object-based storage service (OBS), a container is a logical storage container of an object, and the container name is globally unique within 0BS.
  • OBS object-based storage service
  • a user uploads an object, it does not provide directory structure information, but simply supplies the string containing the file path to the OBS as the object key.
  • a data table is created to record which objects are in the container.
  • the key name of the container is the row name
  • the column name of the row is the object name.
  • the row corresponding to the container in which the object is located is incremented by one column.
  • a container contains an object with the object name as follows:
  • the object name will have a lot of duplicate prefix strings when stored, which requires a large storage space.
  • all the object names containing the prefix to be queried must be taken out first. , consumes more disk 10 instructions and memory, and the more objects in the container, the slower the query response speed.
  • the present invention provides a file directory storage method, including:
  • the dictionary tree is composed of nodes, each node stores one character of the object name, and is stored in the same container.
  • the present invention provides a file. Directory retrieval methods, including:
  • the query information includes a prefix of a directory name, a directory separator, and a label
  • the subtree that needs to be traversed according to the prefix of the directory name in the dictionary tree corresponding to the container; start traversing from the root of the subtree, add each character found to the string buffer, and find the location After the directory separator is used, the substring name of the string before the directory separator in the string buffer is returned to the user, or after the leaf node is found, the string buffer is The string before the leaf node is composed of the file name returned to the user.
  • the present invention provides a file directory storage device, including: a receiving module, configured to receive an upload object message of the user, where the upload object message includes an object name and information of a container where the object is located;
  • a recording module configured to record the object name on a dictionary tree corresponding to the container where the object is located, where the dictionary tree is composed of nodes, each node stores one character of the object name, and is stored in the same container The same characters in different object names share the same node on the dictionary tree.
  • the invention provides a file directory retrieval device, comprising:
  • a receiving module configured to receive query information sent by a user, where the query information includes a prefix of a directory name, a directory separator, and a tag;
  • a search module configured to find, according to the prefix of the directory name, a subtree that needs to be traversed on a dictionary tree corresponding to the container; and, continue to traverse from the root of the subtree, and add each character found to the string to be slowed down Punching area, and after finding the directory separator, returning the sub-directory name of the string before the directory separator in the string buffer to the user, or, after finding the leaf node, the character
  • the string consisting of the string before the leaf node in the string buffer is returned to the user. Save, you can make different object names share the same character, each node shares the same character, avoiding the problem that the characters caused by each object name may be stored repeatedly, which can be reduced when saving.
  • FIG. 1 is a schematic flowchart of an embodiment of a file directory storage method according to the present invention.
  • FIG. 2 is a schematic flowchart of adding an object name to a dictionary tree according to an embodiment of the present invention
  • FIG. 3 is a schematic diagram of a dictionary tree formed in an embodiment of the present invention
  • FIG. 4 is a schematic flowchart of deleting an object name in a dictionary tree according to an embodiment of the present invention
  • FIG. 5 is a schematic diagram of dictionary tree storage according to an embodiment of the present invention
  • FIG. 6 is a schematic flowchart of reconstructing a dictionary tree in an embodiment of the present invention.
  • FIG. 7 is a schematic flow chart of an embodiment of a file directory retrieval method according to the present invention.
  • FIG. 8 is a schematic flowchart of an embodiment of a file directory storage device according to the present invention.
  • FIG. 9 is a schematic flow chart of an embodiment of a file directory retrieval device according to the present invention. detailed description
  • Step 11 An OBS receives an upload object message of a user, where the upload object message includes information about an object name and a container where the object is located;
  • the user can upload an object through the client.
  • the uploading object information may carry a character string indicating the absolute path of the object and information indicating which container the object is stored in.
  • the string indicating the absolute path of the object is the object name, such as c: ⁇ photo ⁇ image.jpg, etc.
  • the container may indicate the storage location of the object name, for example, different object names may be stored in different containers. Multiple object names can be stored in each container.
  • Step 12 The OBS records the object name on a dictionary tree corresponding to the container where the object is located, the dictionary tree is composed of nodes, and each node stores one character of the object name, and is stored in the same implementation of the present invention. In the example, you can create a dictionary tree for each container and store the object name through the dictionary tree. Before the user does not upload the object, each container can first create a dictionary tree containing only the virtual root node (root), which serves as the basis for subsequent object names.
  • root virtual root
  • the dictionary tree has a tree structure, including a root node and a child node under the root node, the child node can be divided into an intermediate node and a leaf node, the intermediate node refers to the node and the child node, and the leaf node refers to the last node of the path. .
  • the dictionary tree is also called the Trie tree or the character search tree.
  • a string is scattered over a complete path from the root node to the leaf node. The same prefix string, the path where the prefix string is located will be shared by the string with the same prefix, and the storage space can be saved by prefix collapse.
  • All nodes of the dictionary tree can be stored as an array.
  • Each node contains 4 parts: characters, node type, right sibling pointer, son pointer.
  • the character is a single-byte character, indicating which single-byte character is stored in the corresponding node; the node type indicates whether the corresponding node is an intermediate node or a leaf node; the node pointed to by the right sibling pointer has the same parent node as the node. , but the lexicographic order is greater than the node of the node; the node pointed to by the son pointer is a child of the node.
  • FIG. 2 is a schematic flowchart of adding an object name to a dictionary tree according to an embodiment of the present invention, including: Step 201: The OBS receives an object name to be saved and encodes the object name.
  • the character encoding may be different between the client and the OBS.
  • the client may use ASCII encoding
  • the OBS uses UTF-8 encoding.
  • the two characters represent the same character, they will adopt different representations.
  • the character “medium” is ASCII coded as "0xD6 OxDO”
  • the UTF-8 code is "0x4E 0x2D,,.
  • the character string sent by the client needs to be encoded into the code used in the OBS.
  • the client uses the same encoding as OBS, it can also not perform character encoding.
  • Step 202 The OBS extracts the first character in the object name to be saved.
  • Step 203 Start searching from the root node of the dictionary tree.
  • Step 204 Determine whether there is a node containing the character on the established path, and if yes, go to step 205, otherwise go to step 206.
  • c: ⁇ photo ⁇ image.jpg is the object name uploaded by the user for the first time, then only the root node exists in the dictionary tree, and the node containing the "c" character does not exist on the established path.
  • c: ⁇ photo ⁇ image.jpg has been uploaded, then c: ⁇ photo ⁇ 201107 ⁇ page.html will be the "c" where the node containing the character already exists on the path.
  • Step 205 Extract the next character of the object name and continue to search downward from the next node of the existing node containing the character, and then repeat step 204 and subsequent steps.
  • the characters extracted in sequence may be 8-bit unsigned characters.
  • Step 206 Add a node containing the character to the dictionary tree.
  • Step 207 Determine whether the node containing the character has a left and/or right sibling node. If there is a left sibling node and a right sibling node, perform step 208. If there is only a right sibling node, perform step 209, if only the left sibling node Then step 210 is performed.
  • the left sibling node has the same parent node as the node containing the character, and the lexicographic order is smaller than the node containing the character and already exists, and the right sibling node has the same parent node as the node containing the character, and The lexicographic order is greater than the node that contains the character and already exists.
  • the right sibling pointer of the left sibling of the node points to the node, and the right sibling pointer of the node points to the right sibling of the node.
  • c: ⁇ photo ⁇ image.jpg has been uploaded, then when the user uploads c: ⁇ photo ⁇ 201107 ⁇ page.html, for the "2", the parent node of the node where "2" is located is included.
  • “c: ⁇ photoV, the last node of " ⁇ ”, and the parent node of the node where "i” has been uploaded is also the node containing the last " ⁇ ” in "c: ⁇ photoV, and the character”
  • the lexicographic order of 2" is less than "i", so the node containing "2” is the left sibling of the node containing "i”.
  • the lexicographical order of "2" is expressed as decimal in decimal
  • the lexicographical order of "i” is expressed as decimal in 105, that is, the lexicographical order of "2" is less than "i,,.
  • Step 208 Point the right sibling pointer of the left sibling node to the node containing the character, and point the right sibling pointer of the node containing the character to the right sibling node. Then step 211 and its subsequent steps are performed.
  • Example ⁇ has uploaded c: ⁇ photo ⁇ image.jpg and c: ⁇ photo ⁇ ll.doc, and uploaded c: ⁇ photo ⁇ 201107 ⁇ page.html, then the node containing "2" is saved as a left and right brother. Node, at this point, the right sibling pointer of the node containing "1" points to the node containing "2", and the right sibling pointer of the node containing "2" points to the node containing "i”.
  • Step 209 Point the parent node's son pointer to the node containing the character, and point the right sibling pointer of the node containing the character to the right sibling node. Then step 211 and its subsequent steps are performed.
  • Step 210 Point the right sibling pointer of the left sibling node to the node containing the character, and set the right sibling pointer of the node containing the character to be empty. Then perform step 21 1 and its subsequent steps.
  • Step 211 Determine whether all the characters of the object name have been traversed, that is, whether the character is the last character of the object name. If yes, go to step 212, otherwise go to step 213.
  • the current character is a "c" character
  • the "c” character is not the last character because there is a character. If the current character is "g”, then there is no character after "g". One character.
  • Step 212 Set the node type of the node containing the character to a leaf node.
  • Step 213 Set the node type of the node containing the character as an intermediate node, and then repeat step 205 and subsequent steps.
  • the node type of the node containing the "c" character is the intermediate node, and then the above process starts from “:".
  • FIG. 3 A schematic diagram of the dictionary tree, see FIG. 3, for the common prefix "c: ⁇ photoV,” is only stored once in this embodiment, which is different from the storage in the prior art twice.
  • Step 401 The OBS receives an object name to be deleted, and performs character encoding on the object name to be deleted.
  • OBS can character encode the object name uploaded by the client.
  • Step 402 The OBS extracts the first character in the object name to be deleted.
  • the object c: ⁇ photo ⁇ image.jpg is to be deleted on the dictionary tree shown in FIG. 3, the first character of the object name to be deleted is "c".
  • Step 403 Start searching from the root node of the dictionary tree.
  • Step 404 Determine whether there is a node containing the character on the established path. If yes, go to step 405; otherwise, go to step 411.
  • Step 405 Add the node containing the character to the delete list.
  • the node containing "c" is added to the delete list.
  • Step 406 Determine whether the extracted character is the last character of the object name to be deleted, and if yes, go to step 408; otherwise, go to step 407.
  • Step 407 Extract the next character of the object name to be deleted. Then repeat step 404 and its subsequent steps.
  • Step 408 traverse the deletion list in reverse order, that is, sequentially extract the nodes from the nodes of the deletion list that contain the last character.
  • the obtained deletion list is a node list including the following character c: ⁇ photo ⁇ image.jpg, and processing starts from the node including the last "g".
  • Step 409 Determine whether the current node has a sibling node. If yes, go to step 410. Otherwise, repeat step 408 and subsequent steps.
  • the extracted current node is the last "g".
  • the current node has no siblings, and then processes the node containing "p" in "jpg", of course, according to The dictionary tree shown in Figure 3 still does not have sibling nodes.
  • the extracted current node is a node containing "i", since "i" has a left sibling node, the next step is performed.
  • Step 410 Perform pointer modification according to the situation of the sibling node of the current node.
  • the right sibling pointer of the left sibling node of the current node is modified to point to the right sibling node of the current node; if the current node has only the left sibling node, the right of the left sibling node is modified.
  • the sibling pointer is empty; if the current node has only the right sibling node, the son pointer of the parent node of the current node is modified to point to the right sibling node.
  • the above describes the process of adding an object name to the dictionary tree and deleting it from the dictionary tree.
  • the information of the dictionary tree can be added to the database.
  • FIG. 5 is a schematic diagram of a dictionary tree storage according to an embodiment of the present invention, wherein a block represents a node of a dictionary tree, and a data structure of a node corresponding to the uploaded object name is a character, a node type, a right sibling pointer, and a son pointer. .
  • the character connection from the root node to the leaf node through the son pointer is an object name
  • the sibling pointer points to a forked path of the shared prefix string object name
  • the left sibling node is always smaller than the right sibling node in the lexicographic order.
  • the slice represents a piece of data in the dictionary tree (default 1M size, configurable).
  • RECORD represents a piece of data in the dictionary tree (default 1M size, configurable).
  • a new piece of data is allocated for use by the dictionary tree, and each piece of data is used as a column of the database. storage. Reading and writing the dictionary tree from the database is performed in units of data slices.
  • blockO is the default root node, and the characters in it default to "OxFF".
  • the node corresponding to the object name is different.
  • the data structure definition of the root node does not include the right sibling pointer.
  • the corresponding position can be set to the default value (such as OxFFFFFFFF). ), that is, the right brother pointer to the root node is invalid (the root node is special), the son pointer points to the node corresponding to the block numbered 0x1, since the character stored in the block of 0x1 is "c", the son of the root node The pointer points to the node containing "c".
  • the other nodes are the nodes corresponding to the object names, and their data structures are characters, node types, right sibling pointers, and son pointers.
  • the node type is represented by "0" for the intermediate node, "1" for the leaf node, and "OxFFFFFFFF" for the right brother.
  • the character in the node corresponding to block 104858 is "g”
  • the node type is the intermediate node
  • the right brother is the node corresponding to the block numbered 0xl9999F
  • the son node is the node corresponding to the block numbered 0xl999B.
  • the database can be interacted with in units of data slices.
  • the prefix query can only access the data pieces distributed by the nodes to ensure that the object size growth in the container does not affect the response time of the prefix query.
  • the dictionary tree can be periodically reconstructed, thereby reducing the slice of the data slice read from the database by the prefix query. Number, the performance of the prefix query does not deteriorate.
  • FIG. 6 is a schematic flowchart of rebuilding a dictionary tree according to an embodiment of the present invention, including:
  • Step 601 Read the first data piece of the dictionary tree into the memory from the database
  • Step 602 The root node of the dictionary tree obtained in the first piece of data
  • Step 603 Obtain the next node as the current node according to the son pointer of the root node; wherein, for the root node, the next node obtained according to the son pointer is the node containing the first character.
  • Step 604 Determine whether the current node is in the data slice that has been read into the memory. If the step 606 is performed, otherwise step 605 is performed.
  • Step 605 Read the data piece containing the current node into the memory from the database.
  • Step 606 Determine whether the current node is a leaf node. If step 608 is performed, otherwise step 607 is performed.
  • Step 607 Determine a new current node. Step 604 and its subsequent steps are then repeated. Wherein, the next node of the original current node can be obtained as the new current node according to the son pointer of the original current node. Alternatively, the right sibling node of the original current node may be determined as the new current node according to the original right sibling pointer of the current node.
  • Step 608 splicing the characters included in the nodes on the entire path to form a complete object name.
  • Step 609 Insert the full object name into another new dictionary tree.
  • Step 610 Determine whether the original dictionary tree traversal is completed. If yes, go to step 611, otherwise go to step 612.
  • Step 611 End.
  • the new dictionary tree can then be stored in the database.
  • Step 612 Continue to traverse the dictionary tree. For example, a new node that is not traversed in the original dictionary tree is selected as the current node, and then repeats from step 604.
  • all the object names in the container are recorded in the dictionary tree, and the storage capacity and memory are saved by the prefix node sharing, and the depth-first traversal of the dictionary tree is used to improve the response time of the OBS prefix query.
  • the entire dictionary tree is fragmented, so that the prefix query only accesses the data pieces distributed by the nodes to ensure that the object size growth in the container does not affect the response time of the prefix query.
  • FIG. 7 is a schematic flowchart of a method for retrieving a file directory according to an embodiment of the present invention, including: Step 701: The OBS receives query information sent by a user, and performs character encoding on a prefix, a directory separator, and a tag of a directory name in the query information.
  • the OBS needs to first character-code the string sent by the client.
  • Step 702 The OBS reads the first data piece of the dictionary tree corresponding to the container that the user needs to access from the database into the memory.
  • Step 703 Find the prefix of the directory name starting from the root node of the dictionary tree of the first piece of data.
  • Step 704 Determine whether the prefix of the directory name has a subtree. If yes, go to step 705. Otherwise, go to step 712.
  • the subtree with the prefix of the last character node as the root node in the dictionary tree is the subtree of the prefix.
  • the prefix "c: ⁇ photoV” For example, to query the prefix "c: ⁇ photoV,”, see Figure 3.
  • the node that traverses "c" in the dictionary tree to the node containing the last " ⁇ " is rooted with the node containing the " ⁇ " character.
  • the subtree of the node is a subtree of the prefix of the directory name.
  • Step 705 Continue deep traversal from the root node of the subtree. For example, the next node is found in the subtree root node in turn as the current node.
  • the subtree root node is the node containing the last character of the prefix. For example, the node containing the last " ⁇ " in "c: ⁇ photoV,” is the subtree root node.
  • Step 706 Add the characters contained in the current node to the string buffer.
  • Step 707 Determine whether the character contained in the current node is equal to the directory separator. If yes, go to step 708; otherwise, go to step 709.
  • Step 708 Record the query to the subdirectory, and compose the characters in the string buffer into subdirectory names.
  • Step 709 Determine whether the current node is a leaf node, and if yes, perform step 710, Then step 711 is performed.
  • Step 710 Record the query to the file, and compose the characters in the string buffer into file names.
  • Step 71 Determine whether to traverse the complete subtree. If yes, go to step 712, otherwise go to step 713.
  • Step 712 End.
  • Step 713 Continue to traverse the subtree. For example, a node that is not traversed is selected as the new current node, and then step 706 and subsequent steps are repeated.
  • the marker can be used to indicate the starting point of the return. If the marker is empty, the first subdirectory name or file name returned from the query is returned. If the marker is not empty, the lexicographic order is used. A subdirectory name or file name greater than the marker indicates to start returning.
  • the object name may be a subdirectory name or a file name.
  • the obtained subdirectory name or file name is returned to the user as long as the found subdirectory name or file name reaches the maximum value (1000) or the subtree traversal ends. If the marker is not empty, the subdirectory name or file name of the lexicographical order greater than the value of the marker is found to reach the maximum value (1000) or the subtree traversal ends, and the obtained lexicographical order is larger than the value of the marker and the number reaches the maximum value. Or the subdirectory name or file name at the end of the subtree traversal is returned to the user.
  • the metadata information of the file such as creation time, permissions, etc., can also be returned.
  • FIG. 8 is a schematic flowchart of a file directory storage device according to an embodiment of the present invention, including a receiving module 81 and a recording module 82.
  • the receiving module 81 is configured to receive an upload object message of the user, where the object to be uploaded includes the object name and the container where the object is located.
  • the recording module 82 is configured to record the object name on a dictionary tree corresponding to the container where the object is located, the dictionary tree is composed of nodes, each node stores one character of the object name, and is stored in the same Differently selected in the container, the node includes the following contents: a character, a node type, a right sibling pointer, and a son pointer.
  • the recording module includes a determining submodule, a creating submodule, and a setting submodule; Extracting a character of the object name as a current character, and determining whether a node including the current character already exists on the dictionary tree, and if so, notifying the setting submodule to set a node type and a pointer of the node including the current character, and continuing Extract the next name of the object name a character as a current character, if not present, the notification creation sub-module adds a node containing the current character; a creation sub-module for adding a node containing the current character, and notifying the setting sub-module to set the current character
  • the node type and pointer of the node; the setting submodule is used to set the node type and pointer of the node containing the current character.
  • the setting submodule is specifically configured to:
  • the right brother pointer is set to null;
  • the son pointer of the parent node of the right sibling node points to the node containing the current character
  • the right sibling pointer of the node containing the current character points to the right sibling node
  • the right sibling pointer of the left sibling node points to the node containing the current character
  • the right sibling pointer of the node containing the current character points to the right sibling node
  • the deleting module is configured to sequentially extract the character of the object name to be deleted as the current character; start searching from the root node of the dictionary tree, determine whether there is a node containing the current character on the dictionary tree, and when present, include The node of the current character is added to the delete list; after all the nodes containing the characters of the object name to be deleted are added to the delete list, the descending order traverses the delete list to obtain the current node, and when the left node and the right sibling node exist in the current node, The right sibling pointer of the left sibling node points to the right sibling node.
  • the right sibling pointer of the left sibling node is modified to be empty.
  • the son pointer of the parent node is modified. Point to the right sibling node.
  • the method further includes: a storage module, configured to save the information of the dictionary tree to the database in units of data slices.
  • the method further includes: a reconstruction module, configured to read the first piece of data into the memory from the database; obtain the root node from the first piece of data, and select the node as the current node from the root node; Whether the node is in the piece of data that has been read into memory, and when it is not in, According to the data in the library, the data piece containing the current node is read into the memory; whether the current node is a leaf node, and when the leaf node is not a leaf node, the new current node is selected again until the current node is a leaf node, and the characters of the node on the entire path are included.
  • After composing the object name insert it into another new dictionary tree and store it in the database. Reduces the storage space, reduces memory consumption during queries, reduces disk 10 consumption, and improves response speed.
  • FIG. 9 is a schematic structural diagram of an embodiment of a file directory retrieval device according to the present invention, including a receiving module 91 and a searching module 92.
  • the receiving module 91 is configured to receive query information sent by a user, where the query information includes a prefix of a directory name and a directory separator.
  • the searching module 92 is configured to sequentially traverse the nodes of the already established dictionary tree, find the subtree in which the prefix of the directory name is located; and, continue to traverse from the root of the subtree, and add each character found to the string a buffer, and after finding the directory separator, returning the string before the directory separator in the string buffer to the user, or, after finding the leaf node, The string before the leaf node in the string buffer forms the file name and returns it to the user.
  • the method further includes: establishing a module, configured to establish a dictionary tree by using the file directory storage method as described above.
  • the occupied storage space can be reduced during storage, the memory consumption is reduced during the query, the disk 10 consumption is reduced, and the response speed is improved.
  • the foregoing program may be stored in a computer readable storage medium, and the program is executed when executed.
  • the foregoing steps include the steps of the foregoing method embodiments; and the foregoing storage medium includes: a medium that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供一种文件目录存储方法、检索方法和设备。该方法包括接收用户的上传对象消息,所述上传对象消息中包括对象名和对象所在容器的信息;将所述对象名记录在所述对象所在容器对应的字典树上,所述字典树由节点组成,每个节点存储所述对象名的一个字符,且存储在同一个容器内的不同的对象名中的相同的字符共用所述字典树上的相同的节点。本发明实施例可以在保存时减少占用的存储空间,在查询时降低内存消耗、降低磁盘IO消耗并提高响应速度。

Description

文件目录存储方法、 检索方法和设备
技术领域 本发明涉及数据存储技术领域, 尤其涉及一种文件目录存储方法、 检 索方法和设备。 背景技术
分布式对象存储系统( object-based storage service, OBS ) 内, 容器是 对象(object ) 的逻辑上的存储容器, 容器名在 0BS内全局唯一。 用户上 传对象时, 并不提供目录结构信息, 只是将包含文件路径的字符串作为对 象名 (object key )提供给 OBS。 OBS内会创建一个数据表用于记录容器 内有哪些对象, 该数据表中, 以容器名为行的键值, 行内列名为对象名。 用户每上传一个对象, 该对象所在的容器对应的行增加一列。 用户在查询 时, 将需要查询的目录名称的前缀、 目录分隔符等参数提交给 OBS , 0BS 取出所有包含该目录名称的列进行匹配, 并将符合条件的结果返回给用 户。
例如, 某个容器内含有对象名如下所示的对象:
c:\photo\image.jpg
c:\photo\201 107\page.html
c:\photo\201 107\image2.png
c:\photo\201107\readme.txt
c:\photo\201 108\page2.htm
c:\photo\201 108\05\default.html
当用户查询该容器内以 "c:\photo" 目录下有哪些对象时, 查询条件包 括: 目录名称的前缀(prefix ) = "c:\photoV, , 目录分隔符 ( delimiter ) = "\" , 标记 ( marker ) = "" , 最大数目 (max-keys ) =1000时。 0BS首 先会将目录名称的前缀为 "c:\photoV, 的列取出, 即取出上述的六个对象 名, 逐个分析每个对象名, 如果对象名中目录名称的前缀后面的子字符串 不包含分隔符 "\" ,则将子字符串作为文件名返回, 否则将目录名称的前 缀与 "\" 之间的子字符串作为子目录名返回, 因此, OBS向用户返回的 结果如下:
文件名:
image.jpg
子目录名:
201107
201108
从上述描述可以看出, 对象名在存储时会存在很多的重复前缀字符串, 需要占用较大的存储空间; 另外, 在查询时, 首先需要将所有的包含要查询 的前缀的对象名全部取出, 消耗了较多的磁盘 10指令和内存, 并且容器内对 象数量越多, 查询响应速度越慢。 发明内容 本发明提供一种文件目录存储方法、 检索方法和设备, 用于解决现有 技术中每个对象名均要分别存储一次引起的问题。
本发明提供一种文件目录存储方法, 包括:
接收用户的上传对象消息, 所述上传对象消息中包括对象名和对象所 在容器的信息;
将所述对象名记录在所述对象所在容器对应的字典树上, 所述字典树 由节点组成, 每个节点存储所述对象名的一个字符, 且存储在同一个容器 本发明提供一种文件目录检索方法, 包括:
接收用户发送的查询信息, 所述查询信息包括目录名称的前缀、 目录 分隔符和标 i己;
根据所述目录名称的前缀在所在容器对应的字典树上查找到需要遍 历的子树;从子树根开始遍历,将查找到的每个字符添加到字符串緩冲区, 并在查找到所述目录分隔符后, 将字符串緩冲区内的所述目录分隔符前的 字符串组成子目录名返回给用户, 或者, 在查找到叶子节点后, 将字符串 緩冲区内的所述目录叶子节点前的字符串组成文件名返回给用户。
本发明提供一种文件目录存储设备, 包括: 接收模块, 用于接收用户的上传对象消息, 所述上传对象消息中包括 对象名和对象所在容器的信息;
记录模块, 用于将所述对象名记录在所述对象所在容器对应的字典树 上, 所述字典树由节点组成, 每个节点存储所述对象名的一个字符, 且存 储在同一个容器内的不同的对象名中的相同的字符共用所述字典树上的 相同的节点。
本发明提供一种文件目录检索设备, 包括:
接收模块, 用于接收用户发送的查询信息, 所述查询信息包括目录名 称的前缀、 目录分隔符和标记;
查找模块, 用于根据所述目录名称的前缀在所在容器对应的字典树上 查找到需要遍历的子树; 以及, 从子树根开始继续遍历, 将查找到的每个 字符添加到字符串緩冲区, 并在查找到所述目录分隔符后, 将字符串緩冲 区内的所述目录分隔符前的字符串组成子目录名返回给用户, 或者, 在查 找到叶子节点后, 将字符串緩冲区内的叶子节点前的字符串组成文件名返 回给用户。 进行保存, 可以使得不同的对象名在具有相同的字符时, 每个相同的字符 共用一个节点, 避免了每个对象名分别存储时引起的字符可能被重复存储 的问题, 可以在保存时减少占用的存储空间, 在查询时降低内存消耗、 降 低磁盘 10消耗并提高响应速度。 附图说明 为了更清楚地说明本发明实施例中的技术方案, 下面将对实施例描述 中所需要使用的附图作一简单地介绍, 显而易见地, 下面描述中的附图是 本发明的一些实施例, 对于本领域普通技术人员来讲, 在不付出创造性劳 动性的前提下, 还可以根据这些附图获得其他的附图。
图 1为本发明文件目录存储方法一实施例的流程示意图;
图 2为本发明实施例中在字典树上增加对象名的流程示意图; 图 3为本发明实施例中形成的字典树的示意图;
图 4为本发明实施例中在字典树上删除对象名的流程示意图; 图 5为本发明实施例中字典树存储示意图;
图 6为本发明实施例中重建字典树的流程示意图;
图 7为本发明文件目录检索方法一实施例的流程示意图;
图 8为本发明文件目录存储设备一实施例的流程示意图;
图 9为本发明文件目录检索设备一实施例的流程示意图。 具体实施方式
为使本发明实施例的目的、 技术方案和优点更加清楚, 下面将结合本 发明实施例中的附图, 对本发明实施例中的技术方案进行清楚、 完整地描 述, 显然, 所描述的实施例是本发明一部分实施例, 而不是全部的实施例。 基于本发明中的实施例, 本领域普通技术人员在没有做出创造性劳动前提 下所获得的所有其他实施例, 都属于本发明保护的范围。
图 1为本发明文件目录存储方法一实施例的流程示意图, 包括: 步骤 11 : OBS接收用户的上传对象消息, 所述上传对象消息包括对 象名和对象所在容器的信息;
其中, 用户可以通过客户端上传对象, 当用户上传对象时, 可以在上 传对象信息中携带表明对象的绝对路径的字符串和表明将对象保存在哪 个容器的信息。 其中, 表明对象的绝对路径的字符串为对象名, 例如上述 的 c:\photo\image.jpg等; 容器可以表明对象名的存储位置, 例如, 不同的 对象名可以存储在不同的容器内, 每个容器内可以存储多个对象名。 步骤 12: OBS将所述对象名记录在所述对象所在容器对应的字典树上, 所述字 典树由节点组成, 每个节点存储所述对象名的一个字符, 且存储在同一个 本发明实施例中, 可以为每个容器创建一个字典树, 通过字典树存储 对象名。 在用户没有上传对象之前, 每个容器内可以首先创建一个只包含 虚拟根节点 (root ) 的字典树, 以便作为后续对象名的基础。
字典树具有树形结构, 包括根节点和根节点下的子节点, 子节点可以 分为中间节点和叶子节点, 中间节点是指该节点后续还有子节点, 叶子节 点是指路径的最后一个节点。 字典树也称为 Trie树或者字符查找树, 一个 字符串会被分散到从根节点到叶子节点的一个完整的路径上, 对于具有相 同的前缀的字符串, 前缀字符串所在的路径会被具有相同前缀的字符串共 用, 可以通过前缀坍塌节约存储空间。
字典树的所有节点可以以数组方式存储, 每个节点包含 4部分内容: 字符、 节点类型、 右兄弟指针、 儿子指针。 其中的字符为单字节字符, 表 明对应的节点中保存哪个单字节的字符; 节点类型表明对应的节点是中间 节点还是叶子节点; 右兄弟指针指向的节点是与该节点具有相同的父节 点,但字典序大于该节点的节点;儿子指针指向的节点是该节点的子节点。
本实施例通过将文件目录以字典树的形式进行保存, 可以使得不同的 对象名在具有相同的字符时, 每个相同的字符共用一个节点, 避免了每个 对象名分别存储时引起的字符可能被重复存储的问题, 可以在保存时减少 占用的存储空间, 在查询时降低内存消耗、 降低磁盘 10消耗并提高响应 速度。
图 2为本发明实施例中在字典树上增加对象名的流程示意图, 包括: 步骤 201 : OBS接收要保存的对象名并将对象名进行字符编码。
其中, 由于客户端与 OBS 采用的字符编码方式可能不同, 例如, 客 户端可能采用 ASCII编码, 而 OBS采用的是 UTF-8编码, 两者在表示同 一个字符时将采用不同的表示方式,以字符 "中"为例, ASCII编码为 " 0xD6 OxDO" , 而 UTF-8编码为 "0x4E 0x2D,, 。 为了 OBS后续处理, 首先需 要将客户端发送的字符串编码成 OBS内使用的编码。
当然, 如果客户端与 OBS 采用同样的编码方式, 也可以不进行字符 编码。
步骤 202: OBS提取要保存的对象名内的第一个字符。
假设用户上传的对象名为:
c:\photo\image.jpg
此时, 第一个字符为 "c" 。
步骤 203: 从字典树的根节点开始查找。
步骤 204: 判断已经建立的路径上是否存在包含该字符的节点, 若是, 执行步骤 205 , 否则执行步骤 206。
例如, 上述的 c:\photo\image.jpg是用户首次上传的对象名, 那么该字 典树上只存在根节点, 则已经建立的路径上不存在包含 "c" 字符的节点。 又例 如 , 假设 已 经 上传 过 c:\photo\image.jpg , 那 么 再上传 c:\photo\201107\page.html 时其中的 "c" 就是路径上已经存在包含该字符 的节点。
步骤 205: 提取对象名的下一个字符并从已经存在的包含该字符的节 点的下一个节点上继续向下查找, 之后重复执行步骤 204及其后续步骤。
其中, 本实施例中, 依次提取的字符可以为 8bit无符号字符。
步骤 206: 在字典树上增加包含该字符的节点。
例如, 对于 c:\photo\image.jpg 中的 "c" , 将在原来只包含根节点的 字典树内增加一个新的节点, 该新的节点内的符号为 "c" 。
步骤 207: 判断包含该字符的节点是否存在左和 /或右兄弟节点, 如果 存在左兄弟节点和右兄弟节点, 执行步骤 208 , 如果仅有右兄弟节点则执 行步骤 209, 如果仅有左兄弟节点则执行步骤 210。
其中, 左兄弟节点是与包含该字符的节点具有相同的父节点, 并且字 典序小于包含该字符的节点并已经存在的节点, 右兄弟节点是与包含该字 符的节点具有相同的父节点, 并且字典序大于包含该字符的节点并已经存 在的节点。对于一个节点,该节点的左兄弟节点的右兄弟指针指向该节点, 该节点的右兄弟指针指向该节点的右兄弟节点。
例如, 对于 c:\photo\image.jpg 中的 "c" , 由于其是首次上传的对象 名内的字符, 其没有左、 右兄弟节点。
又例如, 已经上传 了 c:\photo\image.jpg , 那 么用 户 在上传 c:\photo\201107\page.html时, 对于其中的 "2" , 由于 "2" 所在的节点的 父节点是包含 "c:\photoV, 中的最后一个 "\" 的节点, 而已经上传的 "i" 所在的节点的父节点也是包含 "c:\photoV, 中的最后一个 "\" 的节点, 而 且字符 "2" 的字典序小于 "i" , 因此, 包含 "2" 的节点是包含 "i" 的 节点的左兄弟节点。 例如, 对于 ASCII编码, "2" 的字典序以十进制表 示为 50, "i" 的字典序以十进制表示为 105 , 也就是 "2" 的字典序小于 "i,,。
又例如, 已经上传了 c:\photo\image.jpg以及 c:\photo\l l .doc, 假设用 户又上传 c:\photo\201107\page.html, 那么, 由于 "2" 、 " 1 " 和 "i" 所 在的节点的父节点均是包含 "c:\photoV, 中的最后一个 "\" 的节点, 并且, "2" 的字典序大于 " 1 " 且小于 "i" , 因此包含字符 "2" 的节点的左兄 弟节点是包含 " 1 " 的节点, 右兄弟节点是包含 "i" 的节点。
步骤 208: 将左兄弟节点的右兄弟指针指向包含该字符的节点, 并且 将包含该字符的节点的右兄弟指针指向右兄弟节点。 之后执行步骤 211及 其后续步骤。
例 ^口, 已经上传了 c:\photo\image.jpg 以及 c:\photo\l l .doc , 又上传 c:\photo\201107\page.html后, 那么包含 "2" 的节点存成左右兄弟节点, 此时, 将包含 " 1 " 的节点的右兄弟指针指向包含 "2" 的节点, 并且将包 含 "2" 的节点的右兄弟指针指向包含 "i" 的节点。
步骤 209: 将父节点的儿子指针指向包含该字符的节点, 并且将包含 该字符的节点的右兄弟指针指向右兄弟节点。 之后执行步骤 211及其后续 步骤。
例如,已经上传了 c:\photo\image.jpg,又上传 c:\photo\201107\page.html 时, 那么包含 "2" 的节点仅存在右兄弟节点, 此时, 将包含 "\" 的节点 的儿子指针指向包含 "2" 的节点, 并将包含 "2" 的节点的右兄弟指针指 向包含 "i" 的节点。 另外, 本实施例中如果没有特别说明, "\" 是指 "c:\photoV, 中的最后一个 "\" 。
步骤 210: 将左兄弟节点的右兄弟指针指向包含该字符的节点, 并且 将包含该字符的节点的右兄弟指针置为空。 之后执行步骤 21 1及其后续步 骤。
例如,先上传的是 c:\photo\201107\page.html,又上传 c:\photo\image.jpg 后, 那么 "i" 仅存成左兄弟节点, 此时, 将包含 "2" 的节点的右兄弟指 针指向包含 "i" 的节点。
步骤 211 : 判断是否已经遍历完对象名的所有字符, 也就是判断该字 符是否为对象名的最后一个字符,若是,执行步骤 212,否则执行步骤 213。
例如, 如果当前的字符为 "c" 字符, 由于后续还有字符, 则 "c" 字 符不是最后一个字符, 如果当前的字符为 "g" , 则由于 "g" 之后没有字 符了, 则为最后一个字符。
步骤 212: 将包含该字符的节点的节点类型设置为叶子节点。
例如, 对于 c:\photo\image.jpg, 其中的最后一个 "g" , 其是要上传的 对象名的最后一个字符, 则将包含该 "g" 的节点的节点类型设置为叶子 节点。
步骤 213 : 将包含该字符的节点的节点类型设置为中间节点, 之后重 复执行步骤 205及其后续步骤。
例如, 包含 "c" 字符的节点的节点类型为中间节点, 之后再从 ": " 开始上述流程。
以本实施例 中采用 的两个对象名 , 即 c:\photo\image.jpg 和 c:\photo\201107\page.html, 为例, 经过上述的处理流程, 可以得到如图 3 所示的字典树的示意图, 参见图 3 , 对于共同前缀 "c:\photoV, , 本实施例 中只需用存储一次, 不同于现有技术中的存储两次。
图 4为本发明实施例中在字典树上删除对象名的流程示意图, 包括: 步骤 401 : OBS接收要删除的对象名, 并将要删除的对象名进行字符 编码。
同样, 为了避免客户端和 OBS采用不同的编码方式, OBS可以对客 户端上传的对象名进行字符编码。
步骤 402: OBS提取要删除的对象名内的第一个字符。
其中,假设在图 3所示的字典树上要删除的是对象 c:\photo\image.jpg, 则要删除的对象名的第一个字符为 "c" 。
步骤 403 : 从字典树的根节点开始查找。
步骤 404: 判断已经建立的路径上是否存在包含该字符的节点, 若是, 执行步骤 405 , 否则执行步骤 411。
步骤 405: 将包含该字符的节点添加到删除列表。
例如, 由于已经建立的路径上存在包含 "c" 的节点, 则将包含 "c" 的节点添加到删除列表中。
步骤 406: 判断提取的字符是否为要删除的对象名的最后一个字符, 若是, 执行步骤 408 , 否则执行步骤 407。
步骤 407:提取要删除的对象名的下一个字符。之后重复执行步骤 404 及其后续步骤。
步骤 408: 逆序遍历删除列表, 即从删除列表的包含最后一个字符的 节点处依次提取节点。 例如, 经过上述处理后, 得到的删除列表是依次包含如下字符 c:\photo\image.jpg的节点列表, 那么从包含最后一个 "g" 的节点处开始处 理。
步骤 409: 判断当前节点是否有兄弟节点, 若是, 执行步骤 410, 否 则重复执行步骤 408及其后续步骤。
例如, 提取的当前节点是最后一个 "g" , 参照图 3 所示的字典树, 该当前节点是没有兄弟节点的, 则之后再处理包含 "jpg" 中的 "p" 的节 点, 当然, 按照图 3所示的字典树依然不存在兄弟节点, 依次处理后, 当 提取的当前节点为包含 "i" 的节点后, 由于 "i" 有左兄弟节点, 则执行 下一步骤。
步骤 410: 根据当前节点的兄弟节点的情况进行指针修改。
具体的, 如果当前节点有左兄弟节点和右兄弟节点, 则修改当前节点 的左兄弟节点的右兄弟指针指向当前节点的右兄弟节点; 如果当前节点只 有左兄弟节点, 则修改左兄弟节点的右兄弟指针为空; 如果当前节点只有 右兄弟节点, 则修改当前节点的父节点的儿子指针指向右兄弟节点。
例如, 参见图 3所示的字典树, 如果要删除的是 c:\photo\image.jpg, 由于包含 "i" 的节点仅存在左兄弟节点, 即包含 "2" 的节点, 则在删除 时, 将包含 "2" 的节点的右兄弟指针修改为空。
又 例 如 , 参见 图 3 所 示 的 字 典树 , 如 果要删 除 的 c:\photo\201107\page.html , 由于包含 "2" 的节点仅存在右兄弟节点, 即 包含 "i" 的节点, 则在删除时, 将包含 "\" 的节点的儿子指针指向包含 "i" 的节点。
又例如, 假设在图 3的基础上还存在一个 c:\photo\l l .doc分支, 如果 要删除 c:\photo\201107\page.html, 由于包含 "2" 的节点存在左右兄弟节 点, 即分别为包含 " 1" 的节点和包含 "i" 的节点, 则在删除时, 将包含 " 1 " 的节点的右兄弟指针指向包含 "i" 的节点。
步骤 411 : 结束。
上述分别描述了对象名加入字典树以及从字典树删除的流程, 在获取 字典树后, 为了实现持久化存储, 可以将字典树的信息加入数据库。 在存 储到数据库的过程中, 为了避免数据库读写造成瓶颈, 可以对字典树进行 分片存储。
图 5为本发明实施例中字典树存储示意图, 其中, 块 (block ) 代表字典 树的一个节点, 对于上传的对象名所对应的节点, 其数据结构为字符、 节 点类型、 右兄弟指针、 儿子指针。 从根节点通过儿子指针到达叶子节点的 字符连接就是一个对象名, 兄弟指针指向共享前缀字符串对象名一个分叉 路径, 左兄弟节点在字典序上总是小于右兄弟节点。
片 ( RECORD )代表字典树的一个数据片 (默认 1M大小, 可配置 ) , 当节点空间超过一个数据片的容量, 则分配新的数据片给字典树使用, 每 个数据片作为数据库的一列进行存储。 从数据库读写字典树都是以数据片 为单位进行。
例如, blockO为默认的根节点, 其内的字符默认为 "OxFF" , 与对象 名对应的节点不同, 根节点的数据结构定义中不包含右兄弟指针, 其对应 位置可以采用默认值 (如 OxFFFFFFFF ) , 也就是对于根节点的右兄弟指 针无效(根节点特殊) , 儿子指针指向的是编号为 0x1的 block对应的节 点, 由于 0x1的 block内保存的字符为 "c" , 则根节点的儿子指针指向包 含 "c" 的节点。
对于其他节点, 其他节点是对象名对应的节点, 其数据结构分别为字 符、 节点类型、 右兄弟指针、 儿子指针。 图 5 中用节点类型用 "0" 表示 中间节点, " 1"表示叶子节点, " OxFFFFFFFF"表示右兄弟为空。 例如, 块 104858对应的节点内的字符为 "g" , 节点类型为中间节点, 右兄弟为 编号为 0xl9999F的块对应的节点, 儿子节点为编号为 0xl999B的块对应 的节点。 进一步地, 为减少字典树持久化过程中与数据库的交互次数, 可 以以数据片为单位与数据库进行交互。 在存储时, 当整个字典树对应的数 组的一个数据片内的节点分配完后, 将会增加新的数据片。 在将每个数据 片的数据存储到数据库前, 先压缩以减少数据库存储容量; 在读取时, 从 数据库内读取一个数据片的数据后, 先将其在内存上解压后再使用。
通过上述的分片存储, 可以使得前缀查询只访问节点所分布的数据片 来保证容器内对象规模增长不影响前缀查询的响应时间。
进一步地, 由于用户上传到 OBS 的对象名是随机乱序的, 因此对象 名加入字典树的顺序也是随机的, 因此会导致具有相同前缀的对象名对应 的节点会分散到不同的数据片上, 为了使得相同前缀的对象名集中分布在 相同或相邻的数据片内, 可以定期重建字典树, 从而减少一次前缀查询从 数据库中读入的数据片的片数, 前缀查询的性能不出现劣化。
图 6为本发明实施例中重建字典树的流程示意图, 包括:
步骤 601 : 从数据库中将字典树的第一个数据片读入内存;
步骤 602: 在第一个数据片得到的字典树的根节点;
步骤 603 : 根据根节点的儿子指针得到下一个节点作为当前节点; 其中, 对于根节点, 根据儿子指针得到的下一个节点为包含第一个字 符的节点。
步骤 604: 判断当前节点是否在已经读入内存的数据片内, 若是执行 步骤 606, 否则执行步骤 605。
步骤 605: 从数据库内将包含当前节点的数据片读入内存。
步骤 606: 判断当前节点是否为叶子节点, 若是执行步骤 608 , 否则 执行步骤 607。
步骤 607: 确定新的当前节点。之后重复执行步骤 604及其后续步骤。 其中, 可以根据原来的当前节点的儿子指针得到原来的当前节点的下 一个节点作为新的当前节点。 或者, 也可以根据原来的当前节点的右兄弟 指针将原来的当前节点的右兄弟节点确定为新的当前节点。
步骤 608:将整个路径上的节点包含的字符拼接组成一个完整对象名。 步骤 609: 将完整对象名插入另外一个新的字典树上。
步骤 610: 判断原有字典树遍历是否完成, 若是, 执行步骤 611 , 否 则执行步骤 612。
步骤 611 : 结束。 之后可以将新的字典树存储到数据库中。
步骤 612: 继续遍历字典树。 例如, 选取原有字典树上没有被遍历的 新的节点作为当前节点, 之后从步骤 604开始重复执行。
本实施例中, 以字典树记录容器内所有对象名, 通过前缀节点共享来 节省存储容量及内存, 利用字典树的深度优先遍历提升 OBS 的前缀查询 的响应时间。 对整颗字典树进行分片, 使得前缀查询只访问节点所分布的 数据片来保证容器内对象规模增长不影响前缀查询的响应时间。 通过定期 重建字典树来保证相同前缀的对象名尽可能分布在相同或者相邻的片内, 使得前缀查询的响应时间不出现劣化。
图 7为本发明文件目录检索方法一实施例的流程示意图, 包括: 步骤 701 : OBS接收用户发送的查询信息, 并对查询信息中的目录名 称的前缀、 目录分隔符和标记进行字符编码。
如存储流程所示, 由于客户端和 OBS可能采用不同的编码方式, OBS 需要首先对客户端发送的字符串进行字符编码。
步骤 702: OBS从数据库内将用户需要访问的容器对应的字典树的第 一个数据片读入内存。
步骤 703 : 从第一个数据片的字典树的根节点开始查找目录名称的前 缀。
步骤 704: 判断所述目录名称的前缀是否存在子树, 若是, 执行步骤 705 , 否则执行步骤 712。
本实施例以对图 3所示的字典树进行查询, 并且查询信息为: 目录名 称的前缀 ( refix ) = "c:\photoV, , 目录分隔符 ( delimiter ) = "\" , 标 i己 ( marker ) = ",, , 最大数目 (max-keys ) =1000为例。
此时, 当从根节点查找到包含第一个字符的节点直至包含前缀的最后 一个字符的节点时, 在字典树上以前缀最后一个字符节点为根节点的子树 则是前缀的子树。 例如, 要查询的前缀为 "c:\photoV, , 则参见图 3 , 在字 典树上遍历 "c" 的节点到包含最后一个 "\" 的节点, 则以包含 "\" 字符 的节点作为根节点的子树为目录名称的前缀的子树。
步骤 705: 从子树根节点继续深度遍历。 例如, 依次从子树根节点找 到下一个节点作为当前节点。
其中, 子树根节点是包含前缀的最后一个字符的节点, 例如, 包含 "c:\photoV, 中的最后一个 "\" 的节点是子树根节点。
步骤 706: 将当前节点包含的字符添加到字符串緩冲区。
步骤 707: 判断当前节点包含的字符是否等于目录分隔符, 若是, 执 行步骤 708 , 否则执行步骤 709。
步骤 708: 记录查询到子目录, 并将字符串緩冲区内的字符组成子目 录名。
步骤 709: 判断当前节点是否为叶子节点, 若是, 执行步骤 710, 否 则执行步骤 711。
步骤 710: 记录查询到文件, 并将字符串緩冲区内的字符组成文件名。 步骤 71 1 : 判断是否遍历完整个子树, 若是, 执行步骤 712, 否则执 行步骤 713。
步骤 712: 结束。
步骤 713 : 继续遍历子树。 例如选取一个没有遍历的节点作为新的当 前节点, 之后重复执行步骤 706及其后续步骤。
另外, 在上述查找过程中, marker可以用于表明返回的起始点, 如果 marker 为空, 则从查询到的第一个子目录名或文件名开始返回, 如果 marker不为空, 则从字典序大于 marker指示的子目录名或文件名开始返 回。 其中的对象名可能是子目录名或文件名。
例如, 本实施例中, 如果 marker为空, 则只要查找到的子目录名或文 件名达到最大值( 1000 )或子树遍历结束, 将获取的子目录名或文件名返 回给用户。 如果 marker不为空, 则将查找到的字典序大于 marker的值的 子目录名或文件名达到最大值( 1000 )或子树遍历结束, 将获取的字典序 大于 marker 的值且数量达到最大值或子树遍历结束时的子目录名或文件 名返回给用户。
另外, 查询过程中, 如果获取的为文件名, 还可以同时返回文件的元 数据信息, 例如创建时间、 权限等。
图 8为本发明文件目录存储设备一实施例的流程示意图, 包括接收模 块 81和记录模块 82; 接收模块 81用于接收用户的上传对象消息, 所述上 传对象消息中包括对象名和对象所在容器的信息; 记录模块 82用于将所 述对象名记录在所述对象所在容器对应的字典树上, 所述字典树由节点组 成, 每个节点存储所述对象名的一个字符, 且存储在同一个容器内的不同 可选的, 所述节点包括如下内容: 字符、 节点类型、 右兄弟指针和儿 子指针, 所述记录模块包括判断子模块、 创建子模块和设置子模块; 判断 子模块用于依次提取所述对象名的字符作为当前字符, 并判断字典树上是 否已经存在包含所述当前字符的节点, 若存在, 通知设置子模块设置包含 所述当前字符的节点的节点类型和指针, 并继续提取所述对象名的下一个 字符作为当前字符, 若不存在, 通知创建子模块增加包含所述当前字符的 节点; 创建子模块用于增加包含所述当前字符的节点, 并通知所述设置子 模块设置包含所述当前字符的节点的节点类型和指针; 设置子模块用于设 置包含所述当前字符的节点的节点类型和指针。
可选的, 所述设置子模块具体用于:
判断包含当前字符的节点是否存在左兄弟节点和 /或右兄弟节点; 当存在左兄弟节点时, 将所述左兄弟节点的右兄弟指针指向包含当前 字符的节点, 并将包含当前字符的节点的右兄弟指针置为空;
当存在右兄弟节点时, 将所述右兄弟节点的父节点的儿子指针指向包 含当前字符的节点, 并将包含当前字符的节点的右兄弟指针指向右兄弟节 点;
当存在左兄弟节点和右兄弟节点时, 将左兄弟节点的右兄弟指针指向 包含当前字符的节点, 将包含当前字符的节点的右兄弟指针指向右兄弟节 点;
在所述当前字符为所述对象名的最后一个字符时, 将包含该当前字符 的节点的节点类型设置为叶子节点, 在所述当前字符不是所述对象名的最 后一个字符时, 将包含该当前字符的节点的节点类型设置为中间节点。
可选的, 删除模块, 用于依次提取要删除的对象名的字符作为当前字 符; 从字典树的根节点开始查找, 判断字典树上是否存在包含当前字符的 节点, 并在存在时, 将包含当前字符的节点添加到删除列表; 在将所有包 含要删除的对象名的字符的节点添加到删除列表后, 逆序遍历删除列表获 取当前节点, 并在当前节点存在左兄弟节点和右兄弟节点时, 将左兄弟节 点的右兄弟指针指向右兄弟节点, 在当前节点只存在左兄弟节点时, 修改 左兄弟节点的右兄弟指针为空, 在当前节点只存在右兄弟节点时, 修改父 节点的儿子指针指向右兄弟节点。
可选的, 还包括: 存储模块, 用于以数据片为单位将字典树的信息保 存到数据库。
可选的, 还包括: 重建模块, 用于从数据库内将第一个数据片读入内 存; 从第一个数据片内获取根节点, 并从根节点开始依次选取节点作为当 前节点; 判断当前节点是否在已经读入内存的数据片, 并在不在时, 从数 据库内将包含当前节点的数据片读入内存; 判断当前节点是否为叶子节 点, 在不是叶子节点时再次选取新的当前节点直至当前节点为叶子节点 后, 将整个路径上的节点包含的字符组成对象名后插入另外一个新的字典 树上并存储到数据库。 时减少占用的存储空间, 在查询时降低内存消耗、 降低磁盘 10消耗并提 高响应速度。
图 9为本发明文件目录检索设备一实施例的结构示意图, 包括接收模 块 91和查找模块 92; 接收模块 91用于接收用户发送的查询信息, 所述查 询信息包括目录名称的前缀、 目录分隔符和标记; 查找模块 92用于依次 遍历已经建立的字典树的节点,找到所述目录名称的前缀所在子树;以及, 从子树根开始继续遍历, 将查找到的每个字符添加到字符串緩冲区, 并在 查找到所述目录分隔符后, 将字符串緩冲区内的所述目录分隔符前的字符 串组成子目录名返回给用户, 或者, 在查找到叶子节点后, 将字符串緩冲 区内的叶子节点前的字符串组成文件名返回给用户。
可选的, 还包括: 建立模块, 用于采用如上述的文件目录存储方法建 立字典树。
本实施例通过将文件目录以字典树的形式进行保存, 可以在保存时减 少占用的存储空间, 在查询时降低内存消耗、 降低磁盘 10消耗并提高响 应速度。 本领域普通技术人员可以理解: 实现上述方法实施例的全部或部 分步骤可以通过程序指令相关的硬件来完成, 前述的程序可以存储于一计 算机可读取存储介质中, 该程序在执行时, 执行包括上述方法实施例的步 骤; 而前述的存储介质包括: ROM、 RAM, 磁碟或者光盘等各种可以存 储程序代码的介质。
最后应说明的是: 以上实施例仅用以说明本发明的技术方案, 而非对 其限制; 尽管参照前述实施例对本发明进行了详细的说明, 本领域的普通 技术人员应当理解: 其依然可以对前述各实施例所记载的技术方案进行修 改, 或者对其中部分技术特征进行等同替换; 而这些修改或者替换, 并不 使相应技术方案的本质脱离本发明各实施例技术方案的范围。

Claims

权利要求书
1、 一种文件目录存储方法, 其特征在于, 包括:
接收用户的上传对象消息, 所述上传对象消息中包括对象名和对象所在 容器的信息;
将所述对象名记录在所述对象所在容器对应的字典树上, 所述字典树由 节点组成, 每个节点存储所述对象名的一个字符, 且存储在同一个容器内的 不同的对象名中的相同的字符共用所述字典树上的相同的节点。
2、 根据权利要求 1所述的方法, 其特征在于, 所述节点包括如下内容: 字符、 节点类型、 右兄弟指针和儿子指针, 所述将所述对象名记录在所述对 象所在容器对应的字典树上, 包括:
依次提取所述对象名的字符作为当前字符, 并判断字典树上是否已经存 在包含所述当前字符的节点, 若存在, 设置包含所述当前字符的节点的节点 类型和指针, 并继续提取所述对象名的下一个字符作为当前字符, 若不存在, 增加包含所述当前字符的节点, 并设置包含所述当前字符的节点的节点类型 和指针。
3、 根据权利要求 2所述的方法, 其特征在于, 所述设置包含所述当前字 符的节点的节点类型和指针包括:
判断包含所述当前字符的节点是否存在左兄弟节点和 /或右兄弟节点; 当存在左兄弟节点时, 将所述左兄弟节点的右兄弟指针指向包含当前字 符的节点, 并将包含当前字符的节点的右兄弟指针置为空;
当存在右兄弟节点时, 将所述右兄弟节点的父节点的儿子指针指向包含 当前字符的节点, 并将包含当前字符的节点的右兄弟指针指向右兄弟节点; 当存在左兄弟节点和右兄弟节点时, 将左兄弟节点的右兄弟指针指向包 含当前字符的节点, 将包含当前字符的节点的右兄弟指针指向右兄弟节点; 在所述当前字符为所述对象名的最后一个字符时, 将包含该当前字符的 节点的节点类型设置为叶子节点, 在所述当前字符不是所述对象名的最后一 个字符时, 将包含该当前字符的节点的节点类型设置为中间节点。
4、 根据权利要求 1-3任一项所述的方法, 其特征在于, 还包括, 在字典 树上删除要删除的对象名, 所述删除要删除的对象名, 包括:
依次提取要删除的对象名的字符作为当前字符; 从所述字典树的根节点开始遍历, 判断所述字典树上是否存在包含当前 字符的节点, 并在存在时, 将包含当前字符的节点添加到删除列表;
在将所有包含要删除的对象名的字符的节点添加到删除列表后, 逆序遍 历删除列表获取当前节点, 并在当前节点存在左兄弟节点和右兄弟节点时, 将左兄弟节点的右兄弟指针指向右兄弟节点, 在当前节点只存在左兄弟节点 时, 修改左兄弟节点的右兄弟指针为空, 在当前节点只存在右兄弟节点时, 修改父节点的儿子指针指向右兄弟节点。
5、 根据权利要求 1-4任一项所述的方法, 其特征在于, 还包括: 以数据片为单位将字典树的信息保存到数据库。
6、 根据权利要求 5所述的方法, 其特征在于, 还包括, 重建字典树, 所 述重建字典树包括:
从数据库内将第一个数据片读入内存;
从第一个数据片内获取根节点, 并从根节点开始依次选取节点作为当前 节点;
判断当前节点是否在已经读入内存的数据片, 并在不在时, 从数据库内 将包含当前节点的数据片读入内存;
判断当前节点是否为叶子节点, 在不是叶子节点时再次选取新的当前节 点直至当前节点为叶子节点后, 将整个路径上的节点包含的字符组成对象名 后插入另外一个新的字典树上并存储到数据库。
7、 一种文件目录的检索方法, 其特征在于, 包括:
接收用户发送的查询信息, 所述查询信息包括目录名称的前缀、 目录分 隔符和标记;
根据所述目录名称的前缀在所在容器对应的字典树上查找到需要遍历的 子树; 从子树根开始遍历, 将查找到的每个字符添加到字符串緩冲区, 并在 查找到所述目录分隔符后, 将字符串緩冲区内的所述目录分隔符前的字符串 组成子目录名返回给用户, 或者, 在查找到叶子节点后, 将字符串緩冲区内 的所述目录叶子节点前的字符串组成文件名返回给用户。
8、 根据权利要求 7所述的方法, 其特征在于, 还包括:
根据权利要求 1-6任一项所述的方法建立字典树。
9、 一种文件目录存储设备, 其特征在于, 包括: 接收模块, 用于接收用户的上传对象消息, 所述上传对象消息中包括对 象名和对象所在容器的信息;
记录模块,用于将所述对象名记录在所述对象所在容器对应的字典树上, 所述字典树由节点组成, 每个节点存储所述对象名的一个字符, 且存储在同 一个容器内的不同的对象名中的相同的字符共用所述字典树上的相同的节 点。
10、 根据权利要求 9所述的设备, 其特征在于, 所述节点包括如下内容: 字符、 节点类型、 右兄弟指针和儿子指针, 所述记录模块包括:
判断子模块, 用于依次提取所述对象名的字符作为当前字符, 并判断字 典树上是否已经存在包含所述当前字符的节点, 若存在, 通知设置子模块设 置包含所述当前字符的节点的节点类型和指针, 并继续提取所述对象名的下 一个字符作为当前字符, 若不存在, 通知创建子模块增加包含所述当前字符 的节点;
创建子模块, 用于增加包含所述当前字符的节点, 并通知所述设置子模 块设置包含所述当前字符的节点的节点类型和指针;
设置子模块, 用于设置包含所述当前字符的节点的节点类型和指针。
11、 根据权利要求 10所述的设备, 其特征在于, 所述设置子模块具体用 于:
判断包含当前字符的节点是否存在左兄弟节点和 /或右兄弟节点; 当存在左兄弟节点时, 将所述左兄弟节点的右兄弟指针指向包含当前字 符的节点, 并将包含当前字符的节点的右兄弟指针置为空;
当存在右兄弟节点时, 将所述右兄弟节点的父节点的儿子指针指向包含 当前字符的节点, 并将包含当前字符的节点的右兄弟指针指向右兄弟节点; 当存在左兄弟节点和右兄弟节点时, 将左兄弟节点的右兄弟指针指向包 含当前字符的节点, 将包含当前字符的节点的右兄弟指针指向右兄弟指针; 在所述当前字符为所述对象名的最后一个字符时, 将包含该当前字符的 节点的节点类型设置为叶子节点, 在所述当前字符不是所述对象名的最后一 个字符时, 将包含该当前字符的节点的节点类型设置为中间节点。
12、 根据权利要求 9-11任一项所述的设备, 其特征在于, 还包括: 删除模块, 用于依次提取要删除的对象名的字符作为当前字符; 从字典 树的根节点开始遍历, 判断字典树上是否存在包含当前字符的节点, 并在存 在时, 将包含当前字符的节点添加到删除列表; 在将所有包含要删除的对象 名的字符的节点添加到删除列表后, 逆序遍历删除列表获取当前节点, 并在 当前节点存在左兄弟节点和右兄弟节点时, 将左兄弟节点的右兄弟指针指向 右兄弟节点, 在当前节点只存在左兄弟节点时, 修改左兄弟节点的右兄弟指 针为空, 在当前节点只存在右兄弟节点时, 修改父节点的儿子指针指向右兄 弟节点。
13、 根据权利要求 9-12任一项所述的设备, 其特征在于, 还包括: 存储模块, 用于以数据片为单位将字典树的信息保存到数据库。
14、 根据权利要求 13所述的设备, 其特征在于, 还包括:
重建模块, 用于从数据库内将第一个数据片读入内存; 从第一个数据片 内获取根节点, 并从根节点开始依次选取节点作为当前节点; 判断当前节点 是否在已经读入内存的数据片, 并在不在时, 从数据库内将包含当前节点的 数据片读入内存; 判断当前节点是否为叶子节点, 在不是叶子节点时再次选 取新的当前节点直至当前节点为叶子节点后, 将整个路径上的节点包含的字 符组成对象名后插入另外一个新的字典树上并存储到数据库。
15、 一种文件目录的检索设备, 其特征在于, 包括:
接收模块, 用于接收用户发送的查询信息, 所述查询信息包括目录名称 的前缀、 目录分隔符和标记;
查找模块, 用于根据所述目录名称的前缀在所在容器对应的字典树上查 找到需要遍历的子树; 以及, 从子树根开始继续遍历, 将查找到的每个字符 添加到字符串緩冲区, 并在查找到所述目录分隔符后, 将字符串緩冲区内的 所述目录分隔符前的字符串组成子目录名返回给用户, 或者, 在查找到叶子 节点后, 将字符串緩冲区内的叶子节点前的字符串组成文件名返回给用户。
16、 根据权利要求 15所述的设备, 其特征在于, 还包括:
建立模块, 用于采用如权利要求 1-6任一项所述的方法建立字典树。
PCT/CN2011/084820 2011-12-28 2011-12-28 文件目录存储方法、检索方法和设备 WO2013097115A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2011/084820 WO2013097115A1 (zh) 2011-12-28 2011-12-28 文件目录存储方法、检索方法和设备
CN2011800036614A CN103299297A (zh) 2011-12-28 2011-12-28 文件目录存储方法、检索方法和设备

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2011/084820 WO2013097115A1 (zh) 2011-12-28 2011-12-28 文件目录存储方法、检索方法和设备

Publications (1)

Publication Number Publication Date
WO2013097115A1 true WO2013097115A1 (zh) 2013-07-04

Family

ID=48696202

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/084820 WO2013097115A1 (zh) 2011-12-28 2011-12-28 文件目录存储方法、检索方法和设备

Country Status (2)

Country Link
CN (1) CN103299297A (zh)
WO (1) WO2013097115A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105278877A (zh) * 2015-09-30 2016-01-27 成都华为技术有限公司 一种对象存储方法和装置
CN107066506A (zh) * 2017-01-11 2017-08-18 中国科学院空间应用工程与技术中心 一种提高空间科学与应用数据检索效率的方法及装置
CN108563685A (zh) * 2018-03-13 2018-09-21 阿里巴巴集团控股有限公司 一种银行标识代码的查询方法、装置及设备
CN111813771A (zh) * 2019-04-12 2020-10-23 深圳顺丰泰森控股(集团)有限公司 一种运单状态映射方法、装置、设备及存储介质

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108549679B (zh) * 2018-04-03 2022-03-25 国家计算机网络与信息安全管理中心 用于url分析系统的文件扩展名快速匹配方法和装置
CN110543575B (zh) * 2019-08-28 2021-11-19 浙江鸿泉车联网有限公司 车载外置存储设备的媒体文件检索方法及装置
CN113239307A (zh) * 2021-05-17 2021-08-10 北京百度网讯科技有限公司 用于存储消息主题的方法及装置

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5276874A (en) * 1989-08-11 1994-01-04 Digital Equipment Corporation Method for creating a directory tree in main memory using an index file in secondary memory
CN1786944A (zh) * 2004-12-11 2006-06-14 鸿富锦精密工业(深圳)有限公司 重建树状文件目录结构的系统及方法
CN100468402C (zh) * 2005-10-26 2009-03-11 腾讯科技(深圳)有限公司 一种数据存储及查询方法
US7720869B2 (en) * 2007-05-09 2010-05-18 Illinois Institute Of Technology Hierarchical structured abstract file system
CN102024019A (zh) * 2010-11-04 2011-04-20 曙光信息产业(北京)有限公司 一种分布式文件系统中基于后缀树的目录组织方法
CN102243660A (zh) * 2011-07-18 2011-11-16 中兴通讯股份有限公司 一种数据访问方法及设备

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5276874A (en) * 1989-08-11 1994-01-04 Digital Equipment Corporation Method for creating a directory tree in main memory using an index file in secondary memory
CN1786944A (zh) * 2004-12-11 2006-06-14 鸿富锦精密工业(深圳)有限公司 重建树状文件目录结构的系统及方法
CN100468402C (zh) * 2005-10-26 2009-03-11 腾讯科技(深圳)有限公司 一种数据存储及查询方法
US7720869B2 (en) * 2007-05-09 2010-05-18 Illinois Institute Of Technology Hierarchical structured abstract file system
CN102024019A (zh) * 2010-11-04 2011-04-20 曙光信息产业(北京)有限公司 一种分布式文件系统中基于后缀树的目录组织方法
CN102243660A (zh) * 2011-07-18 2011-11-16 中兴通讯股份有限公司 一种数据访问方法及设备

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
GONG, GAOSHENG: "The Research and Improvement for General Distributed File System", ELECTRONIC TECHNOLOGY & INFORMATION SCIENCE, CHINA MASTER'S THESES FULL-TEXT DATABASE, 15 March 2011 (2011-03-15) *
WU, HAIHUI ET AL.: "An Efficient Optimized Trie-Tree Based on Ordered Binary Tree", MICROCOMPUTER DEVELOPMENT, vol. 14, no. 4, April 2004 (2004-04-01), pages 18 - 19 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105278877A (zh) * 2015-09-30 2016-01-27 成都华为技术有限公司 一种对象存储方法和装置
CN107066506A (zh) * 2017-01-11 2017-08-18 中国科学院空间应用工程与技术中心 一种提高空间科学与应用数据检索效率的方法及装置
CN107066506B (zh) * 2017-01-11 2020-12-08 中国科学院空间应用工程与技术中心 一种提高空间科学与应用数据检索效率的方法及装置
CN108563685A (zh) * 2018-03-13 2018-09-21 阿里巴巴集团控股有限公司 一种银行标识代码的查询方法、装置及设备
CN111813771A (zh) * 2019-04-12 2020-10-23 深圳顺丰泰森控股(集团)有限公司 一种运单状态映射方法、装置、设备及存储介质

Also Published As

Publication number Publication date
CN103299297A (zh) 2013-09-11

Similar Documents

Publication Publication Date Title
KR102462781B1 (ko) Kvs 트리 데이터베이스
TWI682274B (zh) 鍵值儲存樹
WO2013097115A1 (zh) 文件目录存储方法、检索方法和设备
US11899641B2 (en) Trie-based indices for databases
US20190065545A1 (en) Materialization for data edge platform
US9805079B2 (en) Executing constant time relational queries against structured and semi-structured data
US8402071B2 (en) Catalog that stores file system metadata in an optimized manner
US8738572B2 (en) System and method for storing data streams in a distributed environment
US20150347553A1 (en) Object Storage System with Local Transaction Logs, a Distributed Namespace, and Optimized Support for User Directories
JP6550448B2 (ja) データ管理装置、データ管理方法、およびプログラム
WO2012149884A1 (zh) 文件系统和检索、写入、修改或删除文件的方法与装置
CN103678491A (zh) 一种基于Hadoop中小文件优化和倒排索引的方法
WO2013091244A1 (zh) 文件系统中数据的存储方法、访问方法及装置
JP2019029011A (ja) 最適なソートキーの圧縮およびインデックスの再構築
US11468031B1 (en) Methods and apparatus for efficiently scaling real-time indexing
WO2023179787A1 (zh) 分布式文件系统的元数据管理方法和装置
TW202147787A (zh) 利用主要資料的局部性來有效率檢索已使用主要資料篩而被無損地縮減的資料
US8392433B2 (en) Self-indexer and self indexing system
US11657051B2 (en) Methods and apparatus for efficiently scaling result caching
KR102127785B1 (ko) 효율적인 인덱싱을 제공하기 위한 방법, 장치 및 컴퓨터-판독가능 매체에 포함된 컴퓨터 프로그램
US20210286793A1 (en) Indexing stored data objects using probabilistic filters
CN114398324B (zh) 一种适用于分布式存储系统的文件名编码方法
US11797485B2 (en) Frameworks for data source representation and compression
JP6480495B2 (ja) データ管理装置、データ管理方法、およびプログラム
CN117493284A (zh) 文件存储方法、文件读取方法、文件存储和读取系统

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11879128

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11879128

Country of ref document: EP

Kind code of ref document: A1