CN113986855B - Method, system, equipment and medium for locking files by network file system - Google Patents
Method, system, equipment and medium for locking files by network file system Download PDFInfo
- Publication number
- CN113986855B CN113986855B CN202111090435.6A CN202111090435A CN113986855B CN 113986855 B CN113986855 B CN 113986855B CN 202111090435 A CN202111090435 A CN 202111090435A CN 113986855 B CN113986855 B CN 113986855B
- Authority
- CN
- China
- Prior art keywords
- file
- locking
- lock
- record
- list
- Prior art date
- Legal status (The legal status 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 status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 117
- 230000008569 process Effects 0.000 claims abstract description 45
- 238000011084 recovery Methods 0.000 claims abstract description 14
- 238000004590 computer program Methods 0.000 claims description 15
- 230000026676 system process Effects 0.000 claims description 8
- 230000001360 synchronised effect Effects 0.000 description 18
- 230000005291 magnetic effect Effects 0.000 description 6
- 230000004048 modification Effects 0.000 description 5
- 238000012986 modification Methods 0.000 description 5
- 238000012545 processing Methods 0.000 description 5
- 230000007547 defect Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 230000003068 static effect Effects 0.000 description 4
- 230000009471 action Effects 0.000 description 3
- 230000000903 blocking effect Effects 0.000 description 3
- 238000004891 communication Methods 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 238000010586 diagram Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 230000002159 abnormal effect Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005294 ferromagnetic effect Effects 0.000 description 1
- 230000002085 persistent effect Effects 0.000 description 1
- 230000008439 repair process Effects 0.000 description 1
- 238000012552 review Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/176—Support for shared access to files; File sharing support
- G06F16/1767—Concurrency control, e.g. optimistic or pessimistic approaches
- G06F16/1774—Locking methods, e.g. locking methods for file systems allowing shared and concurrent access to files
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/178—Techniques for file synchronisation in file systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/18—File system types
- G06F16/182—Distributed file systems
- G06F16/1824—Distributed file systems implemented using Network-attached Storage [NAS] architecture
- G06F16/183—Provision of network file services by network file servers, e.g. by using NFS, CIFS
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a method, a system, equipment and a medium for locking a file by a network file system. The method comprises the steps of receiving a file locking request and generating a locking record; if the original file lock list is queried according to the locking records, the locking records with the same range are not available, and no conflict lock is available; adding the locking record into the original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking. The method comprises the steps of unlocking the file, repairing the file and sharing the file. Based on the method, a system, equipment and medium for locking the file by the network file system are also provided. According to the lock state before the recovery of the data recorded in the database, the continuity of the lock state is maintained, the use experience of the NFS network file system is improved, the NFS process can realize fault recovery on all file lock requests, and the stability and reliability of the NFS are improved.
Description
Technical Field
The application belongs to the technical field of file storage, and particularly relates to a method, a system, equipment and a medium for locking a file by a network file system.
Background
NFS (Network File System), the network file system, is one of the file systems supported by FreeBSD, which allows resources to be shared between computers in the network. In NFS applications, a client application of local NFS can transparently read and write files located on a remote NFS server just as if accessing local files. NFS sharing services are service processes in NAS clustered storage systems that provide file sharing, and the nature of storage requires that such processes must run stably for long periods of time, especially for dual-control storage systems.
After the NFS-server process fails and is restarted or the storage node fails, the lock state information of the file added by the client through the NFS network file system is lost, so that the storage node and the client are in an actual lock state, and the NFS application of the client is problematic.
Disclosure of Invention
In order to solve the technical problems, the application provides a method, a system, equipment and a medium for locking files by a network file system. The method and the device realize the locking of the file and overcome the defect of the locking of the file, so that the network file system process can realize fault recovery for all file locking requests, and the stability and the reliability of the network file system are improved.
In order to achieve the above purpose, the present application adopts the following technical scheme:
a method for locking files by a network file system, comprising the steps of:
receiving a file locking request and generating a locking record;
if the original file lock list is queried according to the locking records, the locking records with the same range are not available, and no conflict lock is available; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking.
Further, the method further comprises unlocking the file; the file unlocking process comprises the following steps:
receiving a file unlocking request; generating an unlocking record;
and deleting the unlocking record from the first file lock list to obtain a second file lock list, executing file unlocking, and synchronizing the second file lock list into the database.
Further, the method further comprises:
traversing a second file lock list; judging whether the file needs to be locked continuously or not; if the second file lock list is not empty, acquiring a locking record from the head of the second file lock list, and executing file locking.
Further, the method further comprises:
restarting the network file system process after locking the file, and firstly enabling the network file system to enter a silent state;
under the silent state, if the file needs to be restored to the locking state, the first file lock list is read from the database, and the file structure is initialized according to the locking record;
traversing all the locked records, and recovering the records which are locked once;
and after the recovery is finished, exiting the silence state.
Further, the method further comprises:
if the current node fails, switching the shared resource of the network file system of the current node to a standby node;
judging whether the file needs to be restored to the locking state after switching to the standby node, if so, enabling the network file system to enter the silent state, then reading the file lock record corresponding to the current node from the database, restoring according to the file structure which needs to be restored, and exiting the silent state after restoring.
Further, the method for querying the original file lock list, that is, the locked records not having the same scope, includes:
inquiring that the original file lock list has the same locking records according to the locking records, and if the original file lock list has the same locking records, directly returning to the original file lock list without locking;
and inquiring whether the original file lock list has the file lock covering the range according to the file lock range in the locking record, and if so, directly returning to not lock.
Further, the conflict lock includes:
an exclusive lock exists for the same file lock range as in the locking record;
there are shared locks that have the same file lock range as in the locking record, and what is currently needed to be locked is an exclusive lock.
The application also provides a system for locking the files by the network file system, which comprises a receiving module and a locking module;
the receiving module is used for receiving a file locking request and generating a locking record;
the locking module is used for inquiring whether the original file lock list has the same locking records with the same range or not according to the locking records; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking.
The application also proposes a device comprising:
a memory for storing a computer program;
and a processor for implementing the method steps when executing the computer program.
The application also proposes a readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method steps.
The effects provided in the summary of the application are merely effects of embodiments, not all effects of the application, and one of the above technical solutions has the following advantages or beneficial effects:
the application provides a method, a system, equipment and a medium for locking a file by a network file system. The method comprises the steps of receiving a file locking request and generating a locking record; if the original file lock list is queried according to the locking records, the locking records with the same range are not available, and no conflict lock is available; adding the locking record into the original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking. The method includes unlocking a file; the file unlocking process comprises the following steps: receiving a file unlocking request; generating an unlocking record; deleting the unlocking record from the first file lock list to obtain a second file lock list, executing file unlocking, and synchronizing the second file lock list into the database. A method for locking files based on a network file system, and a system, equipment and medium for locking files by the network file system are also provided. According to the application, the file lock list is written into the database, and the database is a Ctdb database, namely a distributed database, so that not only can data be saved, but also the data synchronization among a plurality of nodes can be realized. Therefore, the information of the file locks is ensured to be synchronous after the current node is restarted or the network file system sharing is switched to other nodes due to the failure, the file locks added before the failure are valid after the failure or after the node switching, and the problem that file access occurs to the client application of the network file system due to inconsistent states of the file locks is avoided. The method and the system enable all outstanding lock operations on the file to be recorded in a persistent mode, so that after the NFS-server process is restarted due to faults or the node where the process is located is switched to other nodes due to fault sharing resources, the continuity of the lock state can be maintained according to the lock state before the data recorded in the database ctdb is recovered, and the use experience of the NFS network file system is improved.
Drawings
FIG. 1 is a flowchart of a method for locking files by a network file system according to an embodiment 1 of the present application;
FIG. 2 is a flowchart of a method for unlocking a file by a network file system according to embodiment 1 of the present application;
FIG. 3 is a flowchart illustrating a method for repairing a network file system according to embodiment 1 of the present application;
FIG. 4 is a flow chart of a method for network file system failover in accordance with embodiment 1 of the present application;
fig. 5 is a schematic diagram of a system for locking files by a network file system according to embodiment 2 of the present application.
Detailed Description
In order to clearly illustrate the technical features of the present solution, the present application will be described in detail below with reference to the following detailed description and the accompanying drawings. The following disclosure provides many different embodiments, or examples, for implementing different structures of the application. In order to simplify the present disclosure, components and arrangements of specific examples are described below. Furthermore, the present application may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed. It should be noted that the components illustrated in the figures are not necessarily drawn to scale. Descriptions of well-known components and processing techniques and processes are omitted so as to not unnecessarily obscure the present application.
Example 1
The embodiment 1 of the application provides a method for locking a file by a network file system, and the application provides the receiving and processing of the file lock request of the network file system and the recovery of the file lock of the network file system under the abnormal condition.
FIG. 1 is a flowchart showing a method for locking files by a network file system according to embodiment 1 of the present application
In step S101, a file locking request is received, and a locking record is generated;
the NFS-server receives a locking request and generates a lock record, wherein the lock record comprises a client identifier, a file handle, a starting position of a file lock, a range of the file lock, a type of the file lock and a file lock state. The initial file lock state is an unlock state.
In step S102, if the original file lock list is queried according to the locking records, that is, the locking records with the same range are not available, and no conflict lock is available; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking.
Firstly, inquiring whether the same lock record exists in a lock list according to the lock record, and if the same lock record indicates that the repeated lock directly returns;
and inquiring whether the lock list has latches which can cover the range according to the range of the file lock in the lock record, and if so, directly returning.
And comparing whether the file locks have conflict one by one according to the lock records in the lock list. There are two conflicting situations, one is that there is already a file lock that has an exclusive lock added to the same range, and the file lock that is currently being processed, whether it is a shared lock or an exclusive lock, conflicts with this lock that already exists. Secondly, a shared lock is added to a file lock within the same range, and if the file lock to be processed is an exclusive lock, the two locks collide. If a conflict exists, the state of the current file lock record needs to be modified into a block state, wherein the block state is a blocking state. If no conflict exists, the current lock record state of the file needs to be changed into a locking state, and the locking of the file is executed.
The current lock record is inserted into the lock list of the file structure (file_entry). Synchronous writing of lock list of file into ctdb database
After the completion of the locking of the file, the embodiment 1 of the application also provides a method for unlocking the file. Fig. 2 is a flowchart of a method for unlocking a file by a network file system according to embodiment 1 of the present application.
In step S201, a file unlock request is received; generating an unlocking record;
and the NFS-server receives the unlocking request and finds a lock record according to the parameters transmitted by the NFS-client.
In step S202, the unlocking record is deleted from the first file lock list to obtain a second file lock list, file unlocking is performed, and the second file lock list is synchronized into the database.
And deleting the lock record from the lock list of the file, performing an unlock operation on the file, and synchronizing the lock list into the ctdb database.
Traversing the lock list of the file, and judging whether the file needs to be continuously locked or not. If the lock list is not empty, a lock record is fetched from the head of the lock list, the state of the lock record is modified to be a locking state, the actual locking operation is carried out on the file, and the lock is synchronized into the ctdb database.
FIG. 3 is a flowchart of a method for repairing a network file system according to embodiment 1 of the present application;
in step S301, after the file is locked, the network file system process is restarted, and the network file system is first brought into a silent state;
the NFS-server process starts, the NFS-server processes are initialized to enter a silent state, and the process does not accept the requests of locking and unlocking and file modification in the silent state, so that inconsistency is avoided.
In step S302, in the silent state, if the file needs to be restored to the locked state, the first file lock list is read from the database, and the file structure is initialized according to the locked record.
And determining whether a lock state needs to be restored according to the configuration of the NFS-server. Since it is not necessary in all application environments to restore the lock state after a failure, such as the failure time is long, it is not meaningful to restore the lock state, and the NFS-server process exits the mute state.
The lock list is read from ctdb database, and since the process is just started and there is no file_entry (file structure) of all files in the process, it is necessary to initialize the file_entry (file structure) according to the need of the lock record.
In step S303, all the locked records are traversed, and the records once locked are recovered; traversing all lock records, recovering the record with the lock state, namely locking the corresponding file according to the content in the lock record
In step S304, the silent state is exited after the recovery is completed.
And traversing all lock records, and recovering the record with the locking state, namely locking the corresponding file according to the content in the lock records. Fig. 4 is a flowchart of a method for sharing a network file system in embodiment 1 of the present application.
In step S401, if the current node fails, switching the network file system shared resource of the current node to a standby node;
after a node failure, the file system and NFS shared resources switch to other nodes, such as node2. The file system is a single node instead of a distributed file system, that is, a file system is mounted on only one node at the same time. The cluster on Node2 informs the NFS-server process on the Node that Node switching has occurred.
In step S402, after the switch to the standby node is determined, it is determined whether the file needs to be restored to the locked state, if the locked state needs to be restored, the network file system is brought into the silent state, then the file lock record corresponding to the current node is read from the database, and the file is restored according to the file structure that needs to be restored, and the silent state is exited after the restoration is completed.
Determining whether a lock state needs to be restored according to the configuration of the NFS-server;
if the lock state needs to be restored, the NFS-server process enters a partial silence state, namely all the received requests need to be judged to correspond to which file system, and if the received requests correspond to the file system which is just switched, the requests are directly discarded;
the NFS-server process reads lock data corresponding to the node with the fault from the ctdb database, restores a file structure (file_entry) according to the requirement, and restores a lock state according to the lock record;
after the Lock state is restored, the NFS-server process exits the partially silent state.
The application designs an improved method for realizing the locking of the file by the NFS aiming at the defect that the file is locked by the NFS service in a storage system, so that the NFS process can realize fault recovery and sharing on all file locking requests, and the stability and the reliability of the NFS are improved.
Example 2
Based on the method for locking the file by the network file system provided by the embodiment 1 of the application, a system for locking the file by the network file system is also provided. Fig. 5 is a schematic diagram of a system for locking files by a network file system according to embodiment 2 of the present application. The system comprises a receiving module and a locking module;
the receiving module is used for receiving a file locking request and generating a locking record;
the locking module is used for inquiring whether the original file lock list has the locking records with the same range or not according to the locking records or not, and also has no conflict lock; adding the locking record into the original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking.
The method for inquiring the locking records in the original file lock list, namely the locking records not having the same scope comprises the following steps: inquiring that the original file lock list has the same locking records according to the locking records, and if the original file lock list has the same locking records, directly returning to the original file lock list without locking; and inquiring whether the original file lock list has the file lock covering the range according to the file lock range in the locking record, and if so, directly returning to not lock.
Wherein the conflicting lock comprises an exclusive lock having the same file lock range as in the locking record; there are shared locks that have the same file lock range as in the locking record, and what is currently needed to be locked is an exclusive lock.
The system also comprises an unlocking module, a repairing module and a sharing module;
the unlocking module is used for receiving a file unlocking request; generating an unlocking record; and deleting the unlocking record from the first file lock list to obtain a second file lock list, executing file unlocking, and synchronizing the second file lock list into the database.
The repair module is used for restarting the network file system process after the files are locked, and firstly enabling the network file system to enter a silent state; under the silent state, if the file needs to be restored to the locking state, the first file lock list is read from the database, and the file structure is initialized according to the locking record; traversing all the locked records, and recovering the records which are locked once; and after the recovery is finished, exiting the silence state.
The sharing module is used for switching the shared resource of the network file system of the current node to the standby node if the current node fails; judging whether the file needs to be restored to the locking state after switching to the standby node, if so, enabling the network file system to enter the silent state, then reading the file lock record corresponding to the current node from the database, restoring according to the file structure which needs to be restored, and exiting the silent state after restoring.
Example 3
The application also proposes a device comprising:
a memory for storing a computer program;
the processor is used for realizing the following steps when executing the computer program:
FIG. 1 is a flowchart showing a method for locking files by a network file system according to embodiment 1 of the present application
In step S101, a file locking request is received, and a locking record is generated;
the NFS-server receives a locking request and generates a lock record, wherein the lock record comprises a client identifier, a file handle, a starting position of a file lock, a range of the file lock, a type of the file lock and a file lock state. The initial file lock state is an unlock state.
In step S102, if the original file lock list is queried according to the locking records, that is, the locking records with the same range are not available, and no conflict lock is available; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking.
Firstly, inquiring whether the same lock record exists in a lock list according to the lock record, and if the same lock record indicates that the repeated lock directly returns;
and inquiring whether the lock list has latches which can cover the range according to the range of the file lock in the lock record, and if so, directly returning.
And comparing whether the file locks have conflict one by one according to the lock records in the lock list. There are two conflicting situations, one is that there is already a file lock that has an exclusive lock added to the same range, and the file lock that is currently being processed, whether it is a shared lock or an exclusive lock, conflicts with this lock that already exists. Secondly, a shared lock is added to a file lock within the same range, and if the file lock to be processed is an exclusive lock, the two locks collide. If a conflict exists, the state of the current file lock record needs to be modified into a block state, wherein the block state is a blocking state. If no conflict exists, the current lock record state of the file needs to be changed into a locking state, and the locking of the file is executed.
The current lock record is inserted into the lock list of the file structure (file_entry). Synchronous writing of lock list of file into ctdb database
After the completion of the locking of the file, the embodiment 1 of the application also provides a method for unlocking the file. Fig. 2 is a flowchart of a method for unlocking a file by a network file system according to embodiment 1 of the present application.
In step S201, a file unlock request is received; generating an unlocking record;
and the NFS-server receives the unlocking request and finds a lock record according to the parameters transmitted by the NFS-client.
In step S202, the unlocking record is deleted from the first file lock list to obtain a second file lock list, file unlocking is performed, and the second file lock list is synchronized into the database.
And deleting the lock record from the lock list of the file, performing an unlock operation on the file, and synchronizing the lock list into the ctdb database.
Traversing the lock list of the file, and judging whether the file needs to be continuously locked or not. If the lock list is not empty, a lock record is fetched from the head of the lock list, the state of the lock record is modified to be a locking state, the actual locking operation is carried out on the file, and the lock is synchronized into the ctdb database.
FIG. 3 is a flowchart of a method for repairing a network file system according to embodiment 1 of the present application;
in step S301, after the file is locked, the network file system process is restarted, and the network file system is first brought into a silent state;
the NFS-server process starts, the NFS-server processes are initialized to enter a silent state, and the process does not accept the requests of locking and unlocking and file modification in the silent state, so that inconsistency is avoided.
In step S302, in the silent state, if the file needs to be restored to the locked state, the first file lock list is read from the database, and the file structure is initialized according to the locked record.
And determining whether a lock state needs to be restored according to the configuration of the NFS-server. Since it is not necessary in all application environments to restore the lock state after a failure, such as the failure time is long, it is not meaningful to restore the lock state, and the NFS-server process exits the mute state.
The lock list is read from ctdb database, and since the process is just started and there is no file_entry (file structure) of all files in the process, it is necessary to initialize the file_entry (file structure) according to the need of the lock record.
In step S303, all the locked records are traversed, and the records once locked are recovered; traversing all lock records, recovering the record with the lock state, namely locking the corresponding file according to the content in the lock record
In step S304, the silent state is exited after the recovery is completed.
And traversing all lock records, and recovering the record with the locking state, namely locking the corresponding file according to the content in the lock records. Fig. 4 is a flowchart of a method for sharing a network file system in embodiment 1 of the present application.
In step S401, if the current node fails, switching the network file system shared resource of the current node to a standby node;
after a node failure, the file system and NFS shared resources switch to other nodes, such as node2. The file system is a single node instead of a distributed file system, that is, a file system is mounted on only one node at the same time. The cluster on Node2 informs the NFS-server process on the Node that Node switching has occurred.
In step S402, after the switch to the standby node is determined, it is determined whether the file needs to be restored to the locked state, if the locked state needs to be restored, the network file system is brought into the silent state, then the file lock record corresponding to the current node is read from the database, and the file is restored according to the file structure that needs to be restored, and the silent state is exited after the restoration is completed.
Determining whether a lock state needs to be restored according to the configuration of the NFS-server;
if the lock state needs to be restored, the NFS-server process enters a partial silence state, namely all the received requests need to be judged to correspond to which file system, and if the received requests correspond to the file system which is just switched, the requests are directly discarded;
the NFS-server process reads lock data corresponding to the node with the fault from the ctdb database, restores a file structure (file_entry) according to the requirement, and restores a lock state according to the lock record;
after the Lock state is restored, the NFS-server process exits the partially silent state.
The application designs an improved method for realizing the locking of the file by the NFS aiming at the defect that the file is locked by the NFS service in a storage system, so that the NFS process can realize fault recovery and sharing on all file locking requests, and the stability and the reliability of the NFS are improved.
It is necessary to explain that: the technical scheme of the application also provides electronic equipment, which comprises: a communication interface capable of information interaction with other devices such as a network device and the like; and the processor is connected with the communication interface to realize information interaction with other devices, and is used for executing the method for locking the files by the network file system provided by one or more of the technical schemes when running the computer program, and the computer program is stored in the memory. Of course, in practice, the various components in the electronic device are coupled together by a bus system. It will be appreciated that a bus system is used to enable connected communications between these components. The bus system includes a power bus, a control bus, and a status signal bus in addition to the data bus. The memory in the embodiments of the present application is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program for operating on an electronic device. It will be appreciated that the memory can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. Wherein the nonvolatile Memory may be Read Only Memory (ROM), programmable Read Only Memory (PROM, programmable Read-Only Memory), erasable programmable Read Only Memory (EPROM, erasable Programmable Read-Only Memory), electrically erasable programmable Read Only Memory (EEPROM, electrically Erasable Programmable Read-Only Memory), magnetic random access Memory (FRAM, ferromagnetic random access Memory), flash Memory (Flash Memory), magnetic surface Memory, optical disk, or compact disk Read Only Memory (CD-ROM, compact Disc Read-Only Memory); the magnetic surface memory may be a disk memory or a tape memory. The volatile memory may be random access memory (RAM, random AccessMemory), which acts as external cache memory. By way of example, and not limitation, many forms of RAM are available, such as static random access memory (SRAM, static Random Access Memory), synchronous static random access memory (SSRAM, synchronous Static Random Access Memory), dynamic random access memory (DRAM, dynamic Random Access Memory), synchronous dynamic random access memory (SDRAM, synchronousDynamic Random Access Memory), double data rate synchronous dynamic random access memory (ddr sdram, double Data Rate Synchronous Dynamic Random Access Memory), enhanced synchronous dynamic random access memory (ESDRAM, enhanced Synchronous Dynamic Random Access Memory), synchronous link dynamic random access memory (SLDRAM, syncLink Dynamic Random Access Memory), direct memory bus random access memory (DRRAM, direct Rambus Random Access Memory). The memory described by embodiments of the present application is intended to comprise, without being limited to, these and any other suitable types of memory. The method disclosed by the embodiment of the application can be applied to a processor or realized by the processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or by instructions in the form of software. The processor may be a general purpose processor, a DSP (Digital Signal Processing, meaning a chip capable of implementing digital signal processing techniques), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiment of the application can be directly embodied in the hardware of the decoding processor or can be implemented by combining hardware and software modules in the decoding processor. The software modules may be located in a storage medium having a memory, and the processor reads the program in the memory and performs the steps of the method in combination with its hardware. The corresponding flow in each method of the embodiments of the present application is implemented when the processor executes the program, and for brevity, will not be described in detail herein.
Example 4
The application also provides a readable storage medium, the readable storage medium stores a computer program, and the computer program when executed by a processor realizes the following steps:
FIG. 1 is a flowchart showing a method for locking files by a network file system according to embodiment 1 of the present application
In step S101, a file locking request is received, and a locking record is generated;
the NFS-server receives a locking request and generates a lock record, wherein the lock record comprises a client identifier, a file handle, a starting position of a file lock, a range of the file lock, a type of the file lock and a file lock state. The initial file lock state is an unlock state.
In step S102, if the original file lock list is queried according to the locking records, that is, the locking records with the same range are not available, and no conflict lock is available; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then perform file locking.
Firstly, inquiring whether the same lock record exists in a lock list according to the lock record, and if the same lock record indicates that the repeated lock directly returns;
and inquiring whether the lock list has latches which can cover the range according to the range of the file lock in the lock record, and if so, directly returning.
And comparing whether the file locks have conflict one by one according to the lock records in the lock list. There are two conflicting situations, one is that there is already a file lock that has an exclusive lock added to the same range, and the file lock that is currently being processed, whether it is a shared lock or an exclusive lock, conflicts with this lock that already exists. Secondly, a shared lock is added to a file lock within the same range, and if the file lock to be processed is an exclusive lock, the two locks collide. If a conflict exists, the state of the current file lock record needs to be modified into a block state, wherein the block state is a blocking state. If no conflict exists, the current lock record state of the file needs to be changed into a locking state, and the locking of the file is executed.
The current lock record is inserted into the lock list of the file structure (file_entry). Synchronous writing of lock list of file into ctdb database
After the completion of the locking of the file, the embodiment 1 of the application also provides a method for unlocking the file. Fig. 2 is a flowchart of a method for unlocking a file by a network file system according to embodiment 1 of the present application.
In step S201, a file unlock request is received; generating an unlocking record;
and the NFS-server receives the unlocking request and finds a lock record according to the parameters transmitted by the NFS-client.
In step S202, the unlocking record is deleted from the first file lock list to obtain a second file lock list, file unlocking is performed, and the second file lock list is synchronized into the database.
And deleting the lock record from the lock list of the file, performing an unlock operation on the file, and synchronizing the lock list into the ctdb database.
Traversing the lock list of the file, and judging whether the file needs to be continuously locked or not. If the lock list is not empty, a lock record is fetched from the head of the lock list, the state of the lock record is modified to be a locking state, the actual locking operation is carried out on the file, and the lock is synchronized into the ctdb database.
FIG. 3 is a flowchart of a method for repairing a network file system according to embodiment 1 of the present application;
in step S301, after the file is locked, the network file system process is restarted, and the network file system is first brought into a silent state;
the NFS-server process starts, the NFS-server processes are initialized to enter a silent state, and the process does not accept the requests of locking and unlocking and file modification in the silent state, so that inconsistency is avoided.
In step S302, in the silent state, if the file needs to be restored to the locked state, the first file lock list is read from the database, and the file structure is initialized according to the locked record.
And determining whether a lock state needs to be restored according to the configuration of the NFS-server. Since it is not necessary in all application environments to restore the lock state after a failure, such as the failure time is long, it is not meaningful to restore the lock state, and the NFS-server process exits the mute state.
The lock list is read from ctdb database, and since the process is just started and there is no file_entry (file structure) of all files in the process, it is necessary to initialize the file_entry (file structure) according to the need of the lock record.
In step S303, all the locked records are traversed, and the records once locked are recovered; traversing all lock records, recovering the record with the lock state, namely locking the corresponding file according to the content in the lock record
In step S304, the silent state is exited after the recovery is completed.
And traversing all lock records, and recovering the record with the locking state, namely locking the corresponding file according to the content in the lock records. Fig. 4 is a flowchart of a method for sharing a network file system in embodiment 1 of the present application.
In step S401, if the current node fails, switching the network file system shared resource of the current node to a standby node;
after a node failure, the file system and NFS shared resources switch to other nodes, such as node2. The file system is a single node instead of a distributed file system, that is, a file system is mounted on only one node at the same time. The cluster on Node2 informs the NFS-server process on the Node that Node switching has occurred.
In step S402, after the switch to the standby node is determined, it is determined whether the file needs to be restored to the locked state, if the locked state needs to be restored, the network file system is brought into the silent state, then the file lock record corresponding to the current node is read from the database, and the file is restored according to the file structure that needs to be restored, and the silent state is exited after the restoration is completed.
Determining whether a lock state needs to be restored according to the configuration of the NFS-server;
if the lock state needs to be restored, the NFS-server process enters a partial silence state, namely all the received requests need to be judged to correspond to which file system, and if the received requests correspond to the file system which is just switched, the requests are directly discarded;
the NFS-server process reads lock data corresponding to the node with the fault from the ctdb database, restores a file structure (file_entry) according to the requirement, and restores a lock state according to the lock record;
after the Lock state is restored, the NFS-server process exits the partially silent state.
The application designs an improved method for realizing the locking of the file by the NFS aiming at the defect that the file is locked by the NFS service in a storage system, so that the NFS process can realize fault recovery and sharing on all file locking requests, and the stability and the reliability of the NFS are improved.
The embodiment of the application also provides a storage medium, namely a computer storage medium, particularly a computer readable storage medium, for example, comprising a memory for storing a computer program, wherein the computer program can be executed by a processor to complete the steps of the method. The computer readable storage medium may be FRAM, ROM, PROM, EPROM, EEPROM, flash Memory, magnetic surface Memory, optical disk, or CD-ROM.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the above method embodiments may be implemented by hardware associated with program instructions, where the foregoing program may be stored in a computer readable storage medium, and when executed, the program performs steps including the above method embodiments; and the aforementioned storage medium includes: a removable storage device, ROM, RAM, magnetic or optical disk, or other medium capable of storing program code. Alternatively, the above-described integrated units of the present application may be stored in a computer-readable storage medium if implemented in the form of software functional modules and sold or used as separate products. Based on such understanding, the technical solutions of the embodiments of the present application may be embodied in essence or a part contributing to the prior art in the form of a software product stored in a storage medium, including several instructions for causing an electronic device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a removable storage device, ROM, RAM, magnetic or optical disk, or other medium capable of storing program code.
The description of the relevant parts in the device and the storage medium for locking the file by the network file system provided in the embodiment of the present application can refer to the detailed description of the corresponding parts in the method for locking the file by the network file system provided in embodiment 1 of the present application, which is not repeated here.
It is noted that 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. Moreover, 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 is inherent to. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element. In addition, the parts of the above technical solutions provided in the embodiments of the present application, which are consistent with the implementation principles of the corresponding technical solutions in the prior art, are not described in detail, so that redundant descriptions are avoided.
While the specific embodiments of the present application have been described above with reference to the drawings, the scope of the present application is not limited thereto. Other modifications and variations to the present application will be apparent to those of skill in the art upon review of the foregoing description. It is not necessary here nor is it exhaustive of all embodiments. On the basis of the technical scheme of the application, various modifications or variations which can be made by the person skilled in the art without the need of creative efforts are still within the protection scope of the application.
Claims (8)
1. A method for locking files by a network file system, comprising the steps of:
receiving a file locking request and generating a locking record;
if the original file lock list is queried according to the locking records, the original file lock list has no locking records with the same range or conflict locks; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then executing file locking;
the method further comprises the steps of: restarting the network file system process after locking the file, and firstly enabling the network file system to enter a silent state; under the silent state, if the file needs to be restored to the locking state, the first file lock list is read from the database, and the file structure is initialized according to the locking record; traversing all the locked records, and recovering the records which are locked once; after the recovery is completed, the silent state is exited;
if the current node fails, switching the shared resource of the network file system of the current node to a standby node; judging whether the file needs to be restored to the locking state after switching to the standby node, if so, enabling the network file system to enter the silent state, then reading the file lock record corresponding to the current node from the database, restoring according to the file structure which needs to be restored, and exiting the silent state after restoring.
2. The method for locking a file by a network file system of claim 1, further comprising unlocking the file; the file unlocking process comprises the following steps:
receiving a file unlocking request; generating an unlocking record;
and deleting the unlocking record from the first file lock list to obtain a second file lock list, executing file unlocking, and synchronizing the second file lock list into the database.
3. A method of locking a file by a network file system as recited in claim 2, further comprising:
traversing a second file lock list; judging whether the file needs to be locked continuously or not; if the second file lock list is not empty, acquiring a locking record from the head of the second file lock list, and executing file locking.
4. The method for locking files by a network file system according to claim 1, wherein said method for querying the original file lock list for locking records that do not have the same and the same scope comprises:
inquiring that the original file lock list has the same locking records according to the locking records, and if the original file lock list has the same locking records, directly returning to the original file lock list without locking;
and inquiring whether the original file lock list has the file lock covering the range according to the file lock range in the locking record, and if so, directly returning to not lock.
5. The method for locking a file by a network file system of claim 4, wherein said conflicting lock comprises:
an exclusive lock exists for the same file lock range as in the locking record;
there are shared locks that have the same file lock range as in the locking record, and what is currently needed to be locked is an exclusive lock.
6. A system for locking files by a network file system, which is characterized by comprising a receiving module and a locking module;
the receiving module is used for receiving a file locking request and generating a locking record;
the locking module is used for inquiring whether the original file lock list has the locking records with the same range or conflict locks according to the locking records; adding the locking record to an original file lock list to obtain a first file lock list, and writing the first file lock list into a database; then executing file locking;
restarting the network file system process after locking the file, and firstly enabling the network file system to enter a silent state; under the silent state, if the file needs to be restored to the locking state, the first file lock list is read from the database, and the file structure is initialized according to the locking record; traversing all the locked records, and recovering the records which are locked once; after the recovery is completed, the silent state is exited;
if the current node fails, switching the shared resource of the network file system of the current node to a standby node; judging whether the file needs to be restored to the locking state after switching to the standby node, if so, enabling the network file system to enter the silent state, then reading the file lock record corresponding to the current node from the database, restoring according to the file structure which needs to be restored, and exiting the silent state after restoring.
7. An apparatus for locking files by a network file system, comprising:
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1 to 5 when executing said computer program.
8. A readable storage medium, characterized in that it has stored thereon a computer program which, when executed by a processor, implements the method steps of any of claims 1 to 5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111090435.6A CN113986855B (en) | 2021-09-17 | 2021-09-17 | Method, system, equipment and medium for locking files by network file system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111090435.6A CN113986855B (en) | 2021-09-17 | 2021-09-17 | Method, system, equipment and medium for locking files by network file system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113986855A CN113986855A (en) | 2022-01-28 |
CN113986855B true CN113986855B (en) | 2023-11-14 |
Family
ID=79735966
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111090435.6A Active CN113986855B (en) | 2021-09-17 | 2021-09-17 | Method, system, equipment and medium for locking files by network file system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113986855B (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6389420B1 (en) * | 1999-09-30 | 2002-05-14 | Emc Corporation | File manager providing distributed locking and metadata management for shared data access by clients relinquishing locks after time period expiration |
CN101567805A (en) * | 2009-05-22 | 2009-10-28 | 清华大学 | Method for recovering failed parallel file system |
CN102651006A (en) * | 2011-02-25 | 2012-08-29 | 上海网环信息科技有限公司 | Database table record locking method and device |
CN111708744A (en) * | 2020-05-15 | 2020-09-25 | 苏州浪潮智能科技有限公司 | Method, system, device and medium for maintaining file lock based on stateless protocol |
CN112069519A (en) * | 2020-09-08 | 2020-12-11 | 陕西上讯信息技术有限公司 | Method and equipment for outputting encrypted record of information file |
-
2021
- 2021-09-17 CN CN202111090435.6A patent/CN113986855B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6389420B1 (en) * | 1999-09-30 | 2002-05-14 | Emc Corporation | File manager providing distributed locking and metadata management for shared data access by clients relinquishing locks after time period expiration |
CN101567805A (en) * | 2009-05-22 | 2009-10-28 | 清华大学 | Method for recovering failed parallel file system |
CN102651006A (en) * | 2011-02-25 | 2012-08-29 | 上海网环信息科技有限公司 | Database table record locking method and device |
CN111708744A (en) * | 2020-05-15 | 2020-09-25 | 苏州浪潮智能科技有限公司 | Method, system, device and medium for maintaining file lock based on stateless protocol |
CN112069519A (en) * | 2020-09-08 | 2020-12-11 | 陕西上讯信息技术有限公司 | Method and equipment for outputting encrypted record of information file |
Also Published As
Publication number | Publication date |
---|---|
CN113986855A (en) | 2022-01-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR100471567B1 (en) | Transaction Management Method For Data Synchronous In Dual System Environment | |
US9778998B2 (en) | Data restoration method and system | |
US6785789B1 (en) | Method and apparatus for creating a virtual data copy | |
US6823474B2 (en) | Method and system for providing cluster replicated checkpoint services | |
CN106776130B (en) | Log recovery method, storage device and storage node | |
CN106844014B (en) | Method and device for realizing suspension prevention of distributed transactions | |
CN107426265A (en) | The synchronous method and apparatus of data consistency | |
US20040078658A1 (en) | Journaling and recovery method of shared disk file system | |
CN110515557B (en) | Cluster management method, device and equipment and readable storage medium | |
CN111078667B (en) | Data migration method and related device | |
US20090132534A1 (en) | Remote replication synchronizing/accessing system and method thereof | |
WO2020033323A1 (en) | Ordinary write in distributed system maintaining data storage integrity | |
US20210072903A1 (en) | Future write in distributed system maintaining data storage integrity | |
US20120278429A1 (en) | Cluster system, synchronization controlling method, server, and synchronization controlling program | |
CN110737716B (en) | Data writing method and device | |
US9330153B2 (en) | System, method, and computer readable medium that coordinates between devices using exchange of log files | |
CN113986855B (en) | Method, system, equipment and medium for locking files by network file system | |
CN107528703B (en) | Method and equipment for managing node equipment in distributed system | |
CN115495286A (en) | Test method, system, equipment and storage medium for timed backup of configuration file | |
CN115587099A (en) | Distributed meter lock application method and device, storage medium and electronic equipment | |
CN113806309B (en) | Metadata deleting method, system, terminal and storage medium based on distributed lock | |
CN114064717A (en) | Data processing method, device, equipment and storage medium | |
WO2021141696A1 (en) | Processing delete requests based on change feed of updates | |
CN111198783B (en) | Data access method, device, system, equipment and storage medium | |
US7543017B1 (en) | Cluster file system node failure file recovery by reconstructing file state |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |