Locking of directory tree

By pre-allocating read and write lock objects to each layer of the directory tree and performing lock operations according to operation requests, the problem of large-grained locking and concurrent operations of the directory tree is solved, and efficient directory tree operation performance and concurrent access are achieved.

WO2025149825A1PCT designated stage expired Publication Date: 2025-07-17CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/IB2024/063195
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-01-09
Filing Date
2024-12-27
Publication Date
2025-07-17

AI Technical Summary

Technical Problem

The locking method of directory trees in the prior art has the problem of large locking granularity and the inability to realize high concurrent directory operations.

Method used

Each layer node of the directory tree is pre-allocated with a preset number of read and write lock objects. Through the operation type, application node identification and target node identification, the locking operation is performed, which solves the problem that the read lock in the layer lock is blocked by an unrelated write lock, releases the performance of read operations, and releases the performance of read operations and concurrent write operations while the memory usage is controllable.

Benefits of technology

It realizes small locking granularity, reduces resource consumption, avoids deadlock situations, and improves the concurrent access performance and processing throughput of directory tree operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IB2024063195_17072025_PF_FP_ABST
    Figure IB2024063195_17072025_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to a locking method for a directory tree, and a related device. The method comprises: acquiring a locking operation request for a directory tree, wherein the operation request comprises an operation type and an application node identifier, each layer in the directory tree corresponds to a sequence lock table, each sequence lock table comprises a preset number of read-write lock objects, and each read-write lock object comprises a read-write lock used for recording a writer owner and a corresponding target node identifier used for recording a node protected by the writer; and on the basis of the operation type, the application node identifier and the target node identifier, executing a locking operation on the read-write lock objects corresponding to each layer of nodes in an operation path.
Need to check novelty before this filing date? Find Prior Art

Description

Locking Technology of Directory Tree

[0001] This application relates to the field of computer technology, and particularly to locking of directory trees. Background Art

[0002] This section aims to provide background or context for the embodiments of the present application described in the claims. It should not be admitted as prior art based on the description included in this section.

[0003] In a large-scale distributed file system, the concurrent access performance of the directory tree in the metadata server is of great significance for meeting the high-concurrency and low-latency access requirements of upper-layer applications. The directory tree is a tree-like organization of file system metadata and can contain hundreds of millions of files and directories. The distributed file system supports operations such as finding, listing, creating, deleting, and renaming the directory tree by users. Upper-layer applications will initiate various directory tree operations with high concurrency. On the one hand, the distributed file system needs to reasonably lock the data structure of the directory tree to ensure data consistency and concurrent correctness. On the other hand, it needs to ensure that operations are completed with low latency and high concurrency to meet performance requirements.

[0004] Directory tree locking methods generally include the global lock method that uses a single read-write lock to lock and protect the entire directory tree structure and the layer lock method that locks and protects a certain layer structure of the directory tree through read-write locks. However, both of the above methods have problems such as large locking granularity and inability to achieve high-concurrency directory operations. Summary of the Invention

[0005] A directory tree locking method and related devices provided by embodiments of the present application at least solve the problems of large locking granularity and inability to achieve high-concurrency directory operations in related technologies.

[0006] The above object of the present application is achieved by the following technical solutions.

[0007] In a first aspect, an embodiment of the present application provides a directory tree locking method, including: obtaining a locking operation request for the directory tree, where the operation request includes an operation type and an application node identifier, and each layer in the directory tree corresponds to a sequential lock table, the sequential lock table includes a preset number of read-write lock objects, and the read-write lock object includes a read-write lock for recording the owner of the writer and a target node identifier corresponding to the node protected by the writer; based on the operation type, the application node identifier, and the target node identifier, performing a locking operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path.

[0008] In a second aspect, an embodiment of the present application provides a directory tree locking device, including: an obtaining module for obtaining For the lock operation request for the directory tree, the operation request includes an operation type and an application node identifier. Each node in the directory tree corresponds to a read-write lock object, and the read-write lock object includes a read-write lock for recording the owner of the writer and a target node identifier corresponding to the node protected by the writer. The locking module is configured to perform a locking operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path based on the operation type, the application node identifier, and the target node identifier.

[0009] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor, and a memory storing a program, where the program includes instructions that, when executed by the processor, cause the processor to execute the method according to the first aspect.

[0010] In a fourth aspect, an embodiment of the present application provides a non-transitory machine-readable medium storing computer instructions, where the computer instructions are used to cause the computer to execute the method according to the first aspect.

[0011] The beneficial effects of the embodiments of the present application: The locking method for the directory tree provided by the embodiments of the present application can solve the problems of large locking granularity and inability to achieve high-concurrency directory operations in related technologies. In practical applications, for each layer of nodes in the directory tree, a preset number of read-write lock objects are pre-allocated and placed in a sequential lock table. In this way, by customizing the number of read-write lock objects, the memory usage can be controlled and the resource consumption can be reduced. Then, based on the operation type, the application node identifier, and the target node identifier corresponding to the node protected by the writer in the operation request of the target tree obtained, a locking operation is performed on the read-write lock objects corresponding to each node in the operation path. Based on the method of adding the target node identifier corresponding to the node protected by the writer of the read-write lock in this method, the problem that the read lock in the layer lock is blocked by an irrelevant write lock is solved, and the performance of the read operation is released for the scenario where there are more reads and fewer writes in the directory tree operation. At the same time, the performance of the read operation and the concurrent write operation can be released under the condition that the memory usage is controllable.

[0012] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more comprehensible. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application, and those of ordinary skill in the art can obtain other embodiments based on these drawings without creative efforts.

[0014] FIG. 1 is a flowchart of a method for locking a directory tree provided by an exemplary embodiment of the present application.

[0015] FIG. 2 is a flowchart of a method for locking a directory tree when an operation type is a read lock type provided by an exemplary embodiment of the present application of the directory tree.

[0016] FIG. 3 is a flowchart of a method for locking a directory tree when an operation type is a write lock type provided by an exemplary embodiment of the present application.

[0017] FIG. 4 is a schematic diagram of a lock representation of a target directory tree provided by an exemplary embodiment of the present application.

[0018] FIG. 5 is a schematic structural diagram of a directory tree locking device provided by an exemplary embodiment of the present application.

[0019] FIG. 6 is a schematic structural diagram of an electronic device provided by an exemplary embodiment of the present application. Detailed embodiments

[0020] Embodiments of the present embodiment will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present embodiment are shown in the drawings, it should be understood that the present embodiment can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present embodiment. It should be understood that the drawings and embodiments of the present embodiment are only for exemplary purposes and are not used to limit the protection scope of the present embodiment.

[0021] A directory tree is a data structure in a computer file system used to organize and manage files and folders. It is usually a tree-like structure where the root node represents the entire file system, and each child node represents a folder or a file. Each node can have multiple child nodes but only one parent node. Through the directory tree, users can conveniently browse and manage files and folders in the file system. In an operating system, common directory trees include the root directory tree in Unix / Linux systems and the file system tree in Windows systems.

[0022] Taking the file system tree in the Windows system as an example, the file system tree takes the root directory of each disk as the root node, and each disk has a file system tree. Common child nodes include "C:\Windows", "C:\Program Files", Such as “D:\Data”. Among them, “C:\Windows” stores system files, "C:\Program Files” stores installed software, and “D:\Data” stores user data, etc.

[0023] A read-write lock is a multi-thread synchronization mechanism used to control access to shared resources. It allows multiple threads to read the shared resources simultaneously, but only allows one thread to write to the shared resources.

[0024] A read-write lock usually includes two types of locks: a read lock and a write lock. When a thread acquires a read lock, other threads can also acquire the read lock, but cannot acquire the write lock. When a thread acquires a write lock, other threads cannot acquire the read lock or the write lock. The advantage of a read-write lock is that it can improve concurrency performance, especially when read operations are more frequent than write operations. It can avoid data inconsistency problems caused by multiple threads writing to shared resources simultaneously. The disadvantage is that the implementation of a read-write lock is relatively complex and prone to problems such as deadlocks.

[0025] For the method of locking the entire directory tree system in the related art, only one request can operate on the directory tree, resulting in poor performance; while the layer lock method that locks a certain layer structure of the directory tree through a read-write lock is prone to blocking the read lock by an unrelated write lock, affecting the performance of the metadata service.

[0026] In order to reduce the locking granularity of the directory tree and improve concurrent directory operations, the embodiments of the present application provide a method for locking a directory tree. In this embodiment, for each layer of nodes in the directory tree, a preset number of read-write lock objects are pre-allocated and placed in the sequential lock table. Then, according to the operation type, application node identifier in the operation request for the target tree, and the target node identifier corresponding to the node protected by the writer in the read-write lock, a locking operation is performed on the read-write lock objects corresponding to each node in the operation path.

[0027] The following will describe in detail the technical solutions provided by the embodiments of the present application with reference to the accompanying drawings.

[0028] FIG. 1 is a flowchart of a method for locking a directory tree provided by an exemplary embodiment of the present application. Referring to FIG. 1, the method includes the following steps.

[0029] Step S101: Obtain a locking operation request for the directory tree. The operation request includes an operation type and an application node identifier. Each layer in the directory tree corresponds to a sequential lock table, and the sequential lock table includes a preset number of read-write lock objects. The read-write lock object includes a read-write lock for recording the owner of the writer and a target node identifier corresponding to the node protected by the writer.

[0030] Step S102: Based on the operation type, the application node identifier, and the target node identifier, perform a locking operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path.

[0031] The directory tree locking method provided by the embodiments of the present application can be applied to any device that needs to manage the file system, including storage devices such as hard disks, solid-state drives, USB flash drives, and SD cards, and can also include terminal devices, server devices, etc. For example, terminal devices can include mobile phones, computers, etc., and server devices can include servers for file system management, and the servers can include physical servers or virtual servers (virtual machines) in the cloud. In the above devices, the organization methods of files and directories are all based on the directory tree structure, and the directory tree locking method of the embodiments of the present application can effectively protect the security of files and directories. In addition, the above directory tree locking method can also be applied to network file systems to protect files and directories in the network file system from being illegally accessed.

[0032] To achieve controllable memory usage and reduce resource consumption problems, each node in the directory tree corresponds to an ordered lock table, and the ordered lock table includes a preset number of read-write lock objects.

[0033] In this embodiment, read-write lock objects corresponding to each layer of nodes in the directory tree can be pre-allocated. Specifically, for each layer of nodes in the directory tree, a preset number of read-write lock objects are pre-allocated and placed in the ordered lock table. The preset number of read-write lock objects for each layer of nodes in the directory tree can be specifically set according to specific implementation requirements. In practical applications, the preset number of read-write lock objects for each layer of nodes in the directory tree can be the same. For example, the preset number of read-write lock objects for each layer of nodes in the directory tree is 1024. Or, the preset number of read-write lock objects for each layer in the directory tree increases sequentially according to the number of layers of the directory tree. Taking the directory tree including three layers as an example, the preset number of read-write lock objects pre-allocated to the first layer nodes of the directory tree is 120, the preset number of read-write lock objects pre-allocated to the second layer nodes of the directory tree is 200, and the preset number of read-write lock objects pre-allocated to the third layer nodes of the directory tree is 300.

[0034] In the embodiments of the present application, the target node identifier can be used as the identifier of the node currently holding the write lock, and the conflict domain of the lock can be determined based on this identifier, thereby greatly reducing the probability that the lock-acquiring node still needs to wait for the lock-releasing event of the lock-holding node when the lock-acquiring node has nothing to do with the lock-holding node. The node identifier (Key Tag) can be a non-zero integer of 32 bits. In practical applications, the node identifier can be calculated based on the attribute information of the protected node. Among them, the attribute information of the protected node can include the directory entry identifier (Dentry Id) of the protected node, the storage location, and so on.

[0035] In this embodiment, the application node identifier can include the node identifier applied for in the operation request, which is used to identify the node that needs to perform an operation. In the above embodiment, the application node identifier is used to specify the node that needs to perform a lock-acquiring operation. The target node identifier refers to the identifier of the node protected by the read-write lock to be operated in the operation request. In the above embodiment, the target node identifier is used to specify the node that is currently holding the write lock. If there is no write lock, the target node identifier is zero. Through the application node identifier, the node to be operated can be uniquely determined; through the target node identifier, the node holding the write lock of the read-write lock can be uniquely determined, and then corresponding operations can be performed according to the scenario.

[0036] After obtaining the operation request, a lock-acquiring operation can be performed on the read-write lock objects corresponding to the nodes in the operation path based on the operation type, the application node identifier, and the target node identifier in the operation request.

[0037] Specifically, it can be determined whether there is a conflict domain between the currently applied read-lock operation and the existing write-lock operation according to whether the application node identifier and the target node identifier are the same. If there is no conflict domain, the corresponding lock-acquiring operation can be performed according to the operation type and the application node identifier; if there is a conflict domain, the current operation request needs to be placed in the waiting queue, and after the write lock is released, the lock-acquiring task corresponding to the operation request is awakened, and then the corresponding lock-acquiring operation is performed.

[0038] In this embodiment, when performing the lock-acquiring operation corresponding to the operation request, first, the path to be operated is parsed layer by layer. For each directory or file in the path, the node in the directory tree is the application node, and the unique identifier of this node in the file system is the application node identifier. Then, the corresponding lock-acquiring operation can be performed on the read-write lock object corresponding to the application node according to the operation type.

[0039] In an embodiment of the present application, by increasing the target node identifier for protecting writers of the read-write lock, the problem that the read lock in the layer lock is blocked by an irrelevant write lock is solved, and for the scenario where there are more read operations than write operations in the directory tree operation, the performance of the read operation is released; meanwhile, when the memory usage is controllable, the performance of the read operation and the concurrent write operation can be released.

[0040] It should be noted that in the directory tree locking method provided in the embodiment of the present application, the nodes in the directory tree are identified by a memory data structure, and the memory data structure includes information such as the name of the current node of the directory tree, the number of child nodes, and the pointer list of the child nodes. To ensure that the memory data structure is not modified by multiple directory tree operations simultaneously or read while being modified, a read-write lock is used to protect the concurrent access to the nodes. In the directory tree operation, the read lock or write lock of the corresponding node must be obtained first to access the content of the memory data structure corresponding to the corresponding node. The embodiment of the present application can avoid the memory management overhead of dynamically creating and recycling read-write lock objects by pre-allocating read-write lock objects corresponding to each layer of nodes in the directory tree, thereby reducing the memory management overhead to improve the operation performance of the directory tree. According to the directory tree operation, the read lock or write lock is added to the read-write lock objects corresponding to each node in the operation path to ensure that there is no deadlock situation when the directory tree operation is accessed concurrently with a small locking granularity for the operation path, and then the latency of the directory tree concurrent operation is reduced by reducing the lock conflict, and the throughput of processing the directory tree operation is improved.

[0041] In an alternative embodiment, the operation type includes a read-lock addition type. FIG. 2 is a flowchart of a directory tree locking method when an operation type is a read-lock addition type provided by an exemplary embodiment of the present application. The method includes the following steps.

[0042] Step S201: Obtain the application node identifier corresponding to the operation request for the directory tree.

[0043] Step S202: Verify the application node identifier through the target node identifier and output the verification result.

[0044] If the verification result indicates that the application node identifier is different from the target node identifier, then step S203 is executed; if the verification result indicates that the application node identifier is the same as the target node identifier, then step S204 is executed.

[0045] In this embodiment, verifying the application node identifier through the target node identifier means verifying whether the application node identifier is the same as the target node identifier.

[0046] Step S203: Perform a read lock addition operation corresponding to the read lock type on the read-write lock object corresponding to the current node in the operation path.

[0047] In this embodiment, if the verification result indicates that the applied node identifier is different from the target node identifier, it means that the current applied read lock addition operation does not conflict with the existing write lock addition operation. In this case, a read lock addition operation corresponding to the read lock type can be performed on the read-write lock object corresponding to the current node in the operation path.

[0048] Step S204: Add the operation request to the read lock waiting for write lock release queue, so as to perform a read lock addition operation corresponding to the read lock type on the read-write lock object corresponding to the current node in the operation path according to the order of the operation request in the read lock waiting for write lock release queue.

[0049] In this embodiment, if the verification result indicates that the applied node identifier is the same as the target node identifier, it means that the current applied read lock addition operation conflicts with the existing write lock addition operation. In this case, the read lock task corresponding to the current read lock addition operation request needs to be temporarily placed in the read lock waiting for write lock release queue, wait for the write lock to be released and then wake up the read lock task, and perform a read lock addition operation corresponding to the read lock type on the read-write lock object corresponding to the current node in the operation path according to the order of the read lock task in the read lock waiting for write lock release queue.

[0050] In the embodiment of the present application, when performing a read lock addition operation on the read-write lock object, the current read lock count corresponding to the read-write lock object can be updated based on an atomic operation, and the update result is output. In practical applications, updating the current read lock count corresponding to the read-write lock object based on an atomic operation means adding one to the current read lock count. Optionally, in this embodiment, the atomic operation may include a compare and swap (CAS) operation, etc.

[0051] In the above embodiment, if the update result indicates that the update of the current read lock count corresponding to the read-write lock object based on the atomic operation fails, the spin lock inside the lock can be obtained, and it is judged inside the lock whether the applied node identifier is the same as the target node identifier. Correspondingly, when the update result indicates that the current read lock count is successfully updated, it means that the read lock addition is successful, and then the write lock version number obtained by the atomic operation can be output. It should be noted that in this embodiment, after the atomic operation is executed, the spin lock inside the lock needs to be released.

[0052] The following uses specific embodiments to illustrate a directory tree lock addition method when the operation type in the embodiment of the present application is the read lock type.

[0053] Assume that the current read lock operation needs to add a read lock to a certain file in the directory tree. After obtaining the application node identifier corresponding to the read lock request for the file, it is determined whether the target node identifier recorded in the read-write lock object is the same as the application node identifier.

[0054] If the application node identifier is different from the target node identifier, then the 64-bit integer CAS operation supported by the hardware can be used to increase the current read lock count, that is, increment the current read lock count by one. If the increase in the current read lock count is successful, it means that the addition of the read lock is successful, and then the write lock version number returned by the atomic operation can be returned.

[0055] If the application node identifier is the same as the target node identifier, then the spin lock inside the lock can be obtained, and it is judged inside the lock whether the verified application node identifier is the same as the target node identifier. If the application node identifier is different from the target node identifier, then the current read lock count is increased through a CAS operation, the spin lock is released, and the write lock version number returned by the atomic operation is returned. If the application node identifier is the same as the target node identifier, then the current read lock request is placed in the read lock waiting for the write lock release queue, and the spin lock is released. When the write lock is released, the above steps are repeated.

[0056] In an optional embodiment, when releasing the read lock, the incoming write lock version number can be compared with the write lock version number of the current lock.

[0057] If the incoming write lock version number is the same as the write lock version number of the current lock, it means that no attempt has been made to add a write lock operation during the read lock operation. At this time, the current read lock count can be decreased through a CAS operation, that is, decrement the current read lock count by one.

[0058] If the incoming write lock version number is different from the write lock version number of the current lock, it means that there is a current write lock operation waiting for the release of the current read lock. Moreover, the write lock in the waiting queue has transferred the reference count of the current read lock from the current read lock count to the historical read lock count. At this time, the spin lock inside the lock needs to be obtained first, and the read lock release is completed by decreasing the historical read lock count. If the historical read lock count is 0, it means that all the read locks blocking the write lock operation have been released. At this time, the spin lock can be released to wake up the write lock task waiting for the read lock in the queue.

[0059] In an optional embodiment, the operation type includes the write lock type. FIG. 3 is a flowchart of a method for locking a directory tree when an operation type is the write lock type provided by an exemplary embodiment of the present application. The method includes the following steps.

[0060] Step S301: Determine whether the value of the target node identifier exists to obtain a first judgment result.

[0061] If the first judgment result indicates that the value of the target node identifier does not exist, then step S302 is executed.

[0062] In this embodiment, first, the spin lock within the lock is acquired, and then it is determined whether the value of the target node identifier exists, that is, whether the value of the target node identifier is 0. If the first judgment result indicates that the value of the target node identifier does not exist, it means that the value of the target node identifier is 0. Correspondingly, if the first judgment result indicates that the value of the target node identifier exists, it means that the value of the target node identifier is not 0.

[0063] Step S302: Determine whether the value of the current read lock count corresponding to the read-write lock object meets a preset condition to obtain a second judgment result.

[0064] If the second judgment result indicates that the current read lock count meets the preset condition, then the following step S303 is executed. In this embodiment, the first judgment result indicates that the value of the target node identifier does not exist, that is, the value of the target node identifier is 0, indicating that the current write lock operation is the first write lock operation. Then, the application node identifier can be updated to the target node identifier corresponding to the read-write lock object, the write lock version number can be incremented, and the current read lock count can be obtained and cleared through a CAS operation.

[0065] The preset condition may include that the current read lock count is 0 as described above. In other words, if the current read lock count is 0, it means that the current read lock count meets the preset condition; if the current read lock count is not 0, it means that the current read lock count does not meet the preset condition.

[0066] Step S3O3: Perform a write lock operation corresponding to the write lock type on the read-write lock object of the application node corresponding to the application node identifier in the operation path.

[0067] If the obtained current read lock count is 0, that is, the current read lock count meets the preset condition, indicating that there are no conflicting read locks, the spin lock within the lock is released, and the lock acquisition is successful; conversely, if the obtained current read lock count is non-0, that is, the current read lock count does not meet the preset condition, the obtained current read lock count is transferred to the historical read lock count to identify that these read locks are previous-generation read locks, which may conflict with the current write lock and need to wait for all these read locks to be released before returning that the write lock acquisition is successful. Then, the operation request is added to the write lock waiting read lock release queue, the spin lock within the lock is released, and it waits to be awakened after all read lock tasks are completed. Once awakened, the lock acquisition is successful. Through this operation, subsequent conflicting read lock operations and previous-generation read lock release operations are forced into the spin lock within the lock, and then under the protection of the spin lock, the corresponding lock acquisition and release operations are completed. After the lock acquisition is successful, the incremented write lock version number obtained by the atomic operation is output.

[0068] In an alternative embodiment, if the first judgment result indicates that the value of the target node identifier exists, the operation request is added to the write lock waiting for the write lock release queue, so as to perform a write lock addition operation corresponding to the write lock type on the read-write lock object corresponding to the current node in the operation path according to the order of the operation request in the write lock waiting for the write lock release queue.

[0069] In this embodiment, the first judgment result indicates that the value of the target node identifier exists, that is, the value of the target node identifier is not 0, indicating that there is an ongoing write lock addition operation. At this time, the current operation request can be added to the write lock waiting for the write lock release queue, and the spin lock is released, and the above operation is repeated after the current operation request is awakened, so as to perform a lock addition operation on the read-write lock object corresponding to the current node in the operation path O

[0070] The following describes a lock addition method for a directory tree when the operation type in the embodiment of the present application is a read lock addition type in conjunction with FIG. 4 and specific embodiments.

[0071] «The current write lock addition operation needs to add a write lock to file A in the target directory tree shown in FIG. 4. After obtaining the application node identifier corresponding to the write lock request, the spin lock in the lock is added, and it is judged whether the target node identifier recorded in the read-write lock object is 0.

[0072] If the target node identifier recorded in the read-write lock object is not 0, the current operation request is added to the write lock waiting for the write lock release queue, and the spin lock is released, and the above operation is repeated after the current operation request is awakened to complete the write lock addition operation on file A.

[0073] If the target node identifier recorded in the read-write lock object is 0, the application node identifier is updated to the target node identifier corresponding to the read-write lock object through a CAS operation, the write lock version number is incremented, and the current read lock count is obtained and cleared. If the obtained current read lock count is 0, it means there is no conflicting read lock, the spin lock in the lock is released, and the lock addition is successful; otherwise, if the obtained current read lock count is non-0, the obtained current read lock count is transferred to the historical read lock count, indicating that these read locks are previous generation read locks, which may conflict with the current write lock and need to wait for all these read locks to be released before returning that the write lock addition is successful. Then the operation request is added to the write lock waiting for the read lock release queue, the spin lock in the lock is released, and it waits to be awakened after all read lock tasks are completed. Once awakened, the lock addition is successful. After the lock addition is successful, the incremented write lock version number is output. After the lock addition is successful, the incremented write lock version number is output.

[0074] In an optional embodiment, when releasing a write lock, a spin lock within the lock can be acquired, and the attributes of the write lock writer owner and the target node identifier of the read-write lock object can be cleared. Thereafter, if there are waiting operation requests or tasks in the write lock waiting for write lock release queue or the read lock waiting for write lock release queue, the above operation requests or tasks are executed, and the spin lock is released.

[0075] Based on the above directory tree locking method provided by the embodiments of the present application, the embodiments of the present application further provide a directory tree locking device. As shown in FIG. 5, the directory tree locking device includes an acquisition module 501 and a locking module 502.

[0076] The acquisition module 501 is configured to acquire a locking operation request for the directory tree. The operation request includes an operation type and an application node identifier. Each layer in the directory tree corresponds to a sequential lock table, and the sequential lock table includes a preset number of read-write lock objects. The read-write lock object includes a read-write lock for recording the writer owner and a target node identifier for recording the writer protection in the read-write lock.

[0077] The locking module 502 is configured to perform a locking operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path based on the operation type, the application node identifier, and the target node identifier.

[0078] Optionally, the operation type includes a read lock addition type.

[0079] Correspondingly, the locking module 502 is specifically configured to verify the application node identifier through the target node identifier, and output a verification result; if the verification result indicates that the application node identifier is different from the target node identifier, a read lock operation is performed on the read-write lock object corresponding to the current node in the operation path.

[0080] Optionally, the locking module 502 is further configured to, if the verification result indicates that the application node identifier is the same as the target node identifier, add the operation request to the read lock waiting for write lock release queue, so as to perform a read lock addition operation corresponding to the read lock addition type on the read-write lock objects corresponding to each node in the operation path according to the order of the operation request in the read lock waiting for write lock release queue.

[0081] Optionally, the locking module 502 is further configured to update the current read lock count corresponding to the read-write lock object corresponding to the current node based on an atomic operation to obtain an update result; and output the write lock version number obtained by the atomic operation when the update result indicates that the current read lock count is successfully updated.

[0082] Optionally, the operation type includes a write lock addition type.

[0083] Accordingly, the locking module 502 is specifically configured to determine whether the value of the target node identifier exists, and obtain a first determination result; if the first determination result indicates that the value of the target node identifier does not exist, then determine whether the current read lock count value corresponding to the read-write lock object meets a preset condition, and obtain a second determination result; if the second determination result meets the preset condition, then perform a write lock operation on the read-write lock object of the application node corresponding to the application node identifier in the operation path.

[0084] Optionally, the locking module 502 is further configured to, if the first determination result indicates that the value of the target node identifier exists, then add the operation request to the write lock waiting write lock release queue, so as to perform a locking operation on the read-write lock object corresponding to the current node in the operation path according to the order of the operation request in the write lock waiting write queue.

[0085] Optionally, the locking module 502 is further configured to, if the second determination result does not meet the preset condition, then add the operation request to the write lock waiting read lock release queue, so as to perform a write lock operation corresponding to the write lock type on the read-write lock objects corresponding to each node in the operation path according to the order of the operation request in the write lock waiting read lock release queue.

[0086] Optionally, the locking module 502 also updates the application node identifier to the target node identifier that identifies the writer protection in the read-write lock object based on an atomic operation; and outputs the write lock version number obtained by the atomic operation.

[0087] An embodiment of the present application further provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The above-mentioned memory stores a computer program that can be executed by the at least one processor, and the above-mentioned computer program, when executed by the at least one processor, is used to cause the electronic device to execute the method of the embodiment of the present application.

[0088] An embodiment of the present application further provides a non-transitory machine-readable medium storing a computer program, wherein the above-mentioned computer program, when executed by a processor of a computer, is used to cause the above-mentioned computer to execute the method of the embodiment of the present application.

[0089] An embodiment of the present application further provides a computer program product, including a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to execute the method of the embodiment of the present application.

[0090] Referring to FIG. 6, the structural block diagram of an electronic device that can be a server or a client according to an embodiment of the present application will now be described. It is an example of a hardware device that can be applied to various aspects of the present application. The electronic device is intended to represent various forms of digital electronic computer devices, such as, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, personal digital processors, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.

[0091] As shown in FIG. 6, the electronic device includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0092] Multiple components in the electronic device are connected to the I / O interface 605, including: an input unit 606, an output unit 607, a storage unit 608, and a communication unit 609. The input unit 606 can be any type of device that can input information into the electronic device. The input unit 606 can receive input digital or character information and generate key signal inputs related to the user settings and / or function controls of the electronic device. The output unit 607 can be any type of device that can present information and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 608 can include, but is not limited to, magnetic disks and optical disks. The communication unit 609 allows the electronic device to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks and can include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0093] ​The computing unit 601 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, CPU, graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 executes the various methods and processes described above. For example, in some embodiments, the method embodiments of the present application can be implemented as a computer program, which is tangibly contained in a machine-readable medium, such as the storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device via the ROM 602 and / or the communication unit 609. In some embodiments, the computing unit 601 can be configured to execute the above methods in any other suitable manner (e.g., by means of firmware).

[0094] The computer programs for implementing the methods of the embodiments of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to the processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing devices, such that when the computer programs are executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer programs can be executed entirely on the machine, partially on the machine, as an independent software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0095] In the context of the embodiments of the present application, the machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. The machine-readable signal medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the above. More specific examples of the machine-readable storage medium would include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.

[0096] It should be noted that the term "including" and its variants used in the embodiments of the present application are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The modifications of "one" and "multiple" mentioned in the embodiments of the present application are illustrative rather than restrictive. Those skilled in the art should understand that unless clearly specified otherwise in the context, it should be understood as "one or more".

[0097] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the embodiments of the present application are all information and data authorized by the user or fully authorized by all parties. And the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation entrances are provided for users to choose to authorize or reject.

[0098] The various steps described in the method embodiments provided by the embodiments of the present application can be executed in different orders and / or executed in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The protection scope of the present application is not limited in this regard.

[0099] The term "embodiment" in this specification means that the specific features, structures, or characteristics described in connection with the embodiment may be included in at least one embodiment of the present application. The phrase appears in various positions in the specification does not necessarily mean the same embodiment, nor does it mean being independent or alternative to other embodiments and mutually exclusive. The various embodiments in this specification are described in a related manner, and the same or similar parts among the embodiments are referred to each other. In particular, for device, equipment, and system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and the relevant parts refer to the partial description of the method embodiments.

[0100] The above-described embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of patent protection. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

Claims 1. A method for locking a directory tree, comprising: Obtain a lock operation request for the directory tree, where the operation request includes an operation type and an application node identifier. Each layer in the directory tree corresponds to a sequential lock table, and the sequential lock table includes a preset number of read-write lock objects. The read-write lock object includes a read-write lock for recording the owner of the writer and a target node identifier corresponding to the node protected by the writer. Based on the operation type, the application node identifier, and the target node identifier, perform a lock operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path.

2. The method according to claim 1, wherein The operation type includes a read lock addition type; based on the operation type, the application node identifier, and the target node identifier, performing a lock operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path includes: verifying the application node identifier through the target node identifier and outputting a verification result; if the verification result indicates that the application node identifier is different from the target node identifier, perform a read lock addition operation on the read-write lock object corresponding to the current node in the operation path.

3. The method according to claim 2, wherein It further includes: if the verification result indicates that the application node identifier is the same as the target node identifier, add the operation request to the read lock waiting for write lock release queue, and perform the read lock addition operation corresponding to the read lock addition type on the read-write lock object corresponding to the current node in the operation path according to the order of the operation request in the read lock waiting for write lock release queue.

4. The method according to any one of claims 2 and 3, wherein, Performing a read lock addition operation on the read-write lock object corresponding to the current node in the operation path includes: updating the current read lock count corresponding to the read-write lock object corresponding to the current node based on an atomic operation to obtain an update result; in the case where the update result indicates that the current read lock count is successfully updated, output the read lock version number obtained by the atomic operation.

5. The method according to claim 1, wherein The operation type includes a write lock addition type; based on the operation type, the application node identifier, and the target node identifier, performing a lock operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path includes: determining whether the value of the target node identifier exists to obtain a first determination result; if the first determination result indicates that the value of the target node identifier does not exist, then determine whether the value of the current read lock count corresponding to the read-write lock object meets a preset condition to obtain a second determination result. If the second determination result indicates that the current read lock count meets the preset condition, perform a write lock addition operation on the read-write lock object of the application node corresponding to the application node identifier in the operation path.

6. The method according to claim 5, wherein It further includes: if the first determination result indicates that the value of the target node identifier exists, add the operation request to the write lock waiting for write lock release queue, and perform the lock operation on the read-write lock object corresponding to the current node in the operation path according to the order of the operation request in the write lock waiting for write lock release queue.

7. The method according to claim 5, wherein Further included is: if the second judgment result does not meet the preset condition, adding the operation request to a write-lock waiting-for-read-lock release queue, so as to perform a write-lock addition operation corresponding to the write-lock addition type on the read-write lock object corresponding to the current node in the operation path according to the order of the operation request in the write-lock waiting-for-read-lock release queue.

8. The method according to any one of claims 5 to 7, wherein Performing the write-lock addition operation corresponding to the write-lock addition type on the read-write lock objects corresponding to the nodes in the operation path includes: updating the application node identifier to the target node identifier that identifies the writer protection in the read-write lock object based on an atomic operation; and outputting the write-lock version number obtained by the atomic operation.

9. A locking device for a directory tree, comprising: An acquisition module, configured to acquire a lock addition operation request for the directory tree, where the operation request includes an operation type and an application node identifier, each layer in the directory tree corresponds to an order lock table, and the order lock table includes a preset number of read-write lock objects, and the read-write lock objects include a read-write lock for recording the writer owner and a target node identifier corresponding to the node protected by the writer. A lock addition module, configured to perform a lock addition operation on the read-write lock objects corresponding to at least one layer of nodes in the operation path based on the operation type, the application node identifier, and the target node identifier.

10. - An electronic device, comprising: A processor and a memory storing a program, where the program includes instructions that, when executed by the processor, cause the processor to execute the method according to any one of claims 1 to 8.

11. A non-transitory machine-readable medium storing computer instructions, wherein, The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device for operating file system

    CN103942269A

  • Locking method and device of directory tree

    CN107783988A

  • Tree-shaped data locking and unlocking method

    CN111597193A

  • Directory tree operation method, file system, electronic equipment and storage medium

    CN116483778A

  • Write operations in a tree-based distributed file system

    US20160034508A1