Background
For a distributed file system, in order to facilitate access of a client, an export directory is shared through an NAS (Network Attached Storage) protocol, and then the client is mounted on the file system through the NAS protocol to access and operate the file system. The file lock is a common mode used for ensuring concurrent access of multiple clients, the file lock is divided into a blocking lock and a non-blocking lock, for the non-blocking lock, when the NAS client side initiates a request of the non-blocking lock, if the NAS server side judges that the authorized lock is mutually exclusive with the lock, failure is returned to the client side, otherwise, success is returned to the NAS client side. For a blocking lock, if the NAS server finds that an already granted lock is mutually exclusive with the lock, the thread that processes the lock request is blocked, and the thread is blocked until the mutually exclusive lock is released. If a plurality of blocking lock requests initiated by the NAS client are mutually exclusive, a plurality of threads are blocked, and since the threads used by the NAS server to process the lock requests are fixed in the prior art, blocking of multiple threads affects the processing efficiency of other requests, thereby affecting the stability of the system.
Therefore, how to provide a method, an apparatus, a device and a computer readable storage medium for processing a file lock in a distributed file system to solve the above technical problems becomes a problem to be solved by those skilled in the art at present.
Disclosure of Invention
Embodiments of the present invention provide a method, an apparatus, a device, and a computer readable storage medium for processing a file lock in a distributed file system, which avoid a problem that an original thread in an NSA server is occupied when multiple blocking lock requests are mutually exclusive in a using process, thereby increasing processing speeds of the lock requests and other requests, and improving stability of the system.
In order to solve the above technical problem, an embodiment of the present invention provides a method for processing a file lock in a distributed file system, including:
receiving a lock request sent by an NAS client;
judging whether the type of the lock request is a blocking lock request, if so, adding the blocking lock request into a lock request queue;
and judging whether the lock request queue is empty or not through a pre-established lock processing thread group, if not, acquiring a corresponding blocking lock request from the lock queue according to a preset sequence by using the lock processing thread group, and sending the acquired blocking lock request to a file system.
Optionally, the method further includes:
and receiving response information returned by the file system, and returning the response information to the NAS client.
Optionally, the method further includes:
and updating the state information of the corresponding lock in the file lock list according to the response information.
Optionally, after the adding the blocking lock request to the lock request queue, the method further includes:
and returning a blocking state code corresponding to the blocking lock request to the NAS client.
The embodiment of the invention correspondingly provides a processing device of a file lock in a distributed file system, which comprises:
the receiving module is used for receiving a lock request sent by the NAS client;
the first judgment module is used for judging whether the type of the lock request is a blocking lock request or not, and if so, the adding module is triggered;
the adding module is used for adding the blocking lock request into a lock request queue;
the second judgment module is used for judging whether the lock request queue is empty or not through a pre-established lock processing thread group, and if not, the sending module is triggered;
and the sending module is used for acquiring corresponding blocking lock requests from the lock queue according to a preset sequence by using the lock processing thread group and sending the acquired blocking lock requests to the file system.
Optionally, the NAS client further includes a returning module, configured to receive response information returned by the file system, and return the response information to the NAS client.
Optionally, the system further includes an updating module, configured to update state information of a corresponding lock in the file lock list according to the response information.
An embodiment of the present invention provides a device for processing a file lock in a distributed file system, including:
a memory for storing a computer program;
and the processor is used for realizing the steps of the file lock processing method in the distributed file system when executing the computer program.
An embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program implements the steps of the method for processing a file lock in a distributed file system as described above.
The embodiment of the invention provides a method, a device and equipment for processing a file lock in a distributed file system and a computer readable storage medium, wherein the method comprises the steps of receiving a lock request sent by an NAS client; judging whether the type of the lock request is a blocking lock request, if so, adding the blocking lock request into a lock request queue; and judging whether the lock request queue is empty or not through a pre-established lock processing thread group, if not, acquiring a corresponding blocking lock request from the lock queue according to a preset sequence by using the lock processing thread group, and sending the acquired blocking lock request to the file system.
The NSA server side specially processes the blocking lock request through a preset lock processing thread group and a lock request queue, when the lock request sent by the NAS client side is the blocking lock request, the blocking lock request is added into the lock request queue, and when the lock request queue is not empty, the lock processing thread group obtains corresponding blocking lock requests from the lock request queue according to a preset sequence and sends the corresponding blocking lock requests to the file system. In the use process of the embodiment of the invention, the problem that the original thread in the NSA server side is occupied when a plurality of blocking lock requests have mutual exclusion is solved, thereby improving the processing speed of the lock requests and other requests and improving the stability of the system.
Detailed Description
Embodiments of the present invention provide a method, an apparatus, a device, and a computer-readable storage medium for processing a file lock in a distributed file system, which avoid a problem that an original thread in an NSA server is occupied when multiple blocking lock requests are mutually exclusive in a using process, thereby improving processing speeds of the lock requests and other requests, and improving stability of the system.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a processing method of a file lock in a distributed file system according to an embodiment of the present invention.
The method comprises the following steps:
s11: receiving a lock request sent by an NAS client;
s12: judging whether the type of the lock request is a blocking lock request, if so, entering S13;
s13: adding a blocking lock request to a lock request queue;
s14: judging whether the lock request queue is empty or not through a pre-established lock processing thread group, and if not, entering S15;
s15: and acquiring corresponding blocking lock requests from the lock queue according to a preset sequence by using the lock processing thread group, and sending the acquired blocking lock requests to the file system.
It should be noted that, a lock processing thread group and a lock request queue are pre-established in addition to the native threads of the NAS server, and the lock processing thread group may have a preset number of lock processing threads. After receiving a lock request sent by a NAS client, a NAS server judges whether the type of the lock request is a blocking lock request, and when the lock request is the blocking lock request, the NAS server adds the lock request into a pre-established lock request queue, and when the type of the lock request is a non-blocking lock request, the NAS server processes according to a normal flow.
The pre-established lock processing thread group can detect the lock request queue once every preset time interval, judge whether the lock request queue is empty or not, when the lock request queue is not empty, it indicates that the to-be-processed blocking lock requests are added to the lock request queue, at this time, the lock processing thread group can process each blocking lock request from the lock request queue according to the sequence, specifically, the lock processing thread group can obtain the blocking lock request which is added to the lock request queue first from the lock request queue according to the sequence, and sends the blocking lock request to the file system waiting for a response through the idle lock handling thread, then obtaining the next block lock request, and sending the next block lock request to the file system to wait for response through the idle lock processing thread, and processing the blocking lock requests in the lock request queue one by one until the blocking lock requests in the lock request queue are processed.
It should be further noted that, in the embodiment of the present invention, the execution of S12 and S14 has no sequence, and the lock processing thread group in S14 may detect the lock request queue in real time, or may detect the lock request queue periodically, which is not limited specifically.
Further, the method further comprises:
and receiving response information returned by the file system, and returning the response information to the NAS client.
It should be noted that, for multiple NAS clients, the response message is returned to the corresponding NAS client.
Specifically, the acquired blocking lock request is sent to a file system in the lock processing thread group to request and call a corresponding locking interface, the file system determines the corresponding locking interface according to request information of the blocking lock request, such as a file name, a file length and a lock type, when the locking interface is idle, locking can be performed through the locking interface, the file system returns response information of locking to the lock processing thread group sending the blocking lock request, and the lock processing thread group returns the response information to the NAS client after receiving the response information.
It should be noted that there may be a plurality of NAS clients, and when there are a plurality of NAS clients, the lock processing thread group returns a response message to the corresponding NAS client.
Still further, the method further comprises:
and updating the state information of the corresponding lock in the file lock list according to the response information.
It should be further noted that, after the lock processing thread group receives the response information returned by the file system, the state corresponding to the corresponding file lock in the file list is updated according to the response information, for example, the state is updated to be information that the file is locked.
Optionally, after the adding the blocking lock request to the lock request queue, the method further includes:
and returning the blocking state code corresponding to the blocking lock request to the NAS client.
Specifically, after adding the received blocking lock request to the lock request stream, the NAS server may also return a blocking status code of the lock request to the NAS client, so that the NAS client knows the status of the corresponding blocking lock request.
The embodiment of the invention provides a method for processing a file lock in a distributed file system, which comprises the steps of receiving a lock request sent by an NAS client; judging whether the type of the lock request is a blocking lock request, if so, adding the blocking lock request into a lock request queue; and judging whether the lock request queue is empty or not through a pre-established lock processing thread group, if not, acquiring a corresponding blocking lock request from the lock queue according to a preset sequence by using the lock processing thread group, and sending the acquired blocking lock request to the file system.
The NSA server side specially processes the blocking lock request through a preset lock processing thread group and a lock request queue, when the lock request sent by the NAS client side is the blocking lock request, the blocking lock request is added into the lock request queue, and when the lock request queue is not empty, the lock processing thread group obtains corresponding blocking lock requests from the lock request queue according to a preset sequence and sends the corresponding blocking lock requests to the file system. In the use process of the embodiment of the invention, the problem that the original thread in the NSA server side is occupied when a plurality of blocking lock requests have mutual exclusion is solved, thereby improving the processing speed of the lock requests and other requests and improving the stability of the system.
Correspondingly, an embodiment of the present invention further discloses a processing apparatus for a file lock in a distributed file system, and specifically, referring to fig. 2, fig. 2 is a schematic structural diagram of a processing apparatus for a file lock in a distributed file system according to an embodiment of the present invention. On the basis of the above-described embodiment:
the device includes:
the receiving module 1 is used for receiving a lock request sent by the NAS client;
the first judging module 2 is used for judging whether the type of the lock request is a blocking lock request, and if so, the adding module 3 is triggered;
an adding module 3, configured to add the blocking lock request to a lock request queue;
the second judgment module 4 is used for judging whether the lock request queue is empty through a pre-established lock processing thread group, and if not, the sending module 5 is triggered;
and the sending module 5 is configured to obtain, by using the lock processing thread group, a corresponding blocking lock request from the lock queue according to a preset order, and send the obtained blocking lock request to the file system.
Optionally, the NAS client further includes a returning module, configured to receive response information returned by the file system, and return the response information to the NAS client.
Optionally, the file lock management system further includes an updating module, configured to update state information of a corresponding lock in the file lock list according to the response information.
The NSA server side specially processes the blocking lock request through a preset lock processing thread group and a lock request queue, when the lock request sent by the NAS client side is the blocking lock request, the blocking lock request is added into the lock request queue, and when the lock request queue is not empty, the lock processing thread group obtains corresponding blocking lock requests from the lock request queue according to a preset sequence and sends the corresponding blocking lock requests to the file system. In the use process of the embodiment of the invention, the problem that the original thread in the NSA server side is occupied when a plurality of blocking lock requests have mutual exclusion is solved, thereby improving the processing speed of the lock requests and other requests and improving the stability of the system.
In addition, for a specific description of the processing method for the file lock in the distributed file system according to the embodiment of the present invention, please refer to the above method embodiment, which is not described herein again.
An embodiment of the present invention provides a device for processing a file lock in a distributed file system, including:
a memory for storing a computer program;
and the processor is used for realizing the steps of the file lock processing method in the distributed file system when executing the computer program.
The embodiment of the invention provides a computer-readable storage medium, on which a computer program is stored, and when being executed by a processor, the computer program implements the steps of the processing method for the file lock in the distributed file system.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
It is further noted that, in the present specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.