Disclosure of Invention
The invention aims to provide a method, a device, equipment and a storage medium for creating files in batch, which can improve the file creating performance and further improve the performance of a distributed file system.
In order to achieve the above purpose, the invention provides the following technical scheme:
a method of creating files in batches, comprising:
receiving an authorization request sent by a target client, and determining a directory corresponding to the authorization request as an appointed directory; the target client is any client needing to create batch files;
judging whether the specified directory is authorized to other clients except the target client, if so, waiting until the batch creation of all files corresponding to the client with the authority to the specified directory is completed, releasing the specified directory, and authorizing the specified directory to the target client, and if not, authorizing the specified directory to the target client; wherein the specified directory only allows access to clients having rights to the specified directory;
receiving a plurality of creation requests sent by the target client, realizing the simultaneous creation of a plurality of corresponding files based on the received creation requests, storing the metadata of each file obtained by the creation, and releasing the specified directory after completing the batch creation of all the files corresponding to the target client.
Preferably, before receiving the authorization request sent by the destination client, the method further includes:
receiving a connection request sent by the target client, responding to the connection request to establish connection with the target client, and applying for a file number in a preset range for the target client in advance;
after the simultaneous creation of the plurality of files is realized based on the received creation request, the method further comprises:
respectively allocating file numbers belonging to the preset range to each file obtained by creation; wherein the metadata of the file includes a file number of the file.
Preferably, after the simultaneous creation of the plurality of files is realized based on the received creation request, the method further includes:
setting corresponding file names for each created file respectively, and establishing association between the file name of each created file and a file number; wherein the metadata of the file includes the file name and the file number having an association.
Preferably, the method further comprises the following steps:
when the batch creation of all files corresponding to the target client is not completed, receiving authorization requests sent by other clients except the target client, indicating the target client to forcibly refresh all creation requests cached by the target client so as to obtain all creation requests refreshed by the target client, and executing the step of realizing the simultaneous creation of a plurality of corresponding files based on the received creation requests.
Preferably, the method further comprises the following steps:
if a fault occurs in the process of realizing batch creation of all files corresponding to the target client, receiving each creation request of the target client record, which is retransmitted by the target client, after the fault is repaired; and the client records a creation request corresponding to each file to be created.
Preferably, after the target client is implemented to create all files in batch, the method further includes:
and returning confirmation information of successful batch creation of all the files corresponding to the target client to indicate the creation request of deleting the record of the target client.
Preferably, after the target client is implemented to create all files in batch, the method further includes:
and sending a marking instruction to the target client to indicate the target client to record a mark of successful creation of the batch files in a log of file creation.
An apparatus for creating files in batches, comprising:
a determination module to: receiving an authorization request sent by a target client, and determining a directory corresponding to the authorization request as an appointed directory; the target client is any client needing to create batch files;
a determination module configured to: judging whether the specified directory is authorized to other clients except the target client, if so, waiting until the batch creation of all files corresponding to the client with the authority to the specified directory is completed, releasing the specified directory, and authorizing the specified directory to the target client, and if not, authorizing the specified directory to the target client; wherein the specified directory only allows access to clients having rights to the specified directory;
a creation module to: receiving a plurality of creation requests sent by the target client, realizing simultaneous creation of a plurality of corresponding files based on the received creation requests, storing metadata of each file obtained by creation, and releasing the specified directory after completing batch creation of all files corresponding to the target client.
An apparatus for creating files in batches, comprising:
a memory for storing a computer program;
a processor for implementing the steps of the method for batch creation of files as described in any one of the above when executing the computer program.
A computer-readable storage medium having stored thereon a computer program which, when executed by a processor, carries out the steps of the method of bulk creating files as claimed in any one of the preceding claims.
The invention provides a method, a device, equipment and a storage medium for creating files in batches, wherein the method comprises the following steps: receiving an authorization request sent by a target client, and determining a directory corresponding to the authorization request as an appointed directory; the target client is any client needing to create batch files; judging whether the specified directory is authorized to other clients except the target client, if so, waiting until the batch creation of all files corresponding to the client with the authority to the specified directory is completed, releasing the specified directory, and authorizing the specified directory to the target client, and if not, authorizing the specified directory to the target client; wherein the specified directory only allows access to clients having rights to the specified directory; receiving a plurality of creation requests sent by the target client, realizing the simultaneous creation of a plurality of corresponding files based on the received creation requests, storing the metadata of each file obtained by the creation, and releasing the specified directory after completing the batch creation of all the files corresponding to the target client. According to the technical scheme, when the client needs to create the files in batch, the authority of the appointed directory can be obtained through application, if the appointed directory is not authorized to other clients currently, the authority of the appointed directory can be obtained, and then the files are created in batch under the appointed directory, otherwise, the authority of the appointed directory is obtained after the access authority of other clients to the appointed directory is removed, and then the files are created in batch under the appointed directory. Therefore, the files required to be created can be created in batches under the instruction of the client, the file creation performance is improved, and the performance of the distributed file system is further improved; in addition, by setting the exclusive right for the specified directory, the situation that the names of created files are the same and further file creation fails when multiple clients simultaneously achieve file creation under the specified directory can be avoided, effective implementation of batch creation of the files is guaranteed, the situation that when one client achieves file creation under the specified directory, other clients cannot access the information such as the valid files when accessing the specified directory can be avoided, and the effectiveness of the clients in obtaining the information is guaranteed.
Detailed Description
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 only a part of the embodiments of the present invention, and not all of the embodiments. 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, a flowchart of a method for creating files in batch according to an embodiment of the present invention is shown, where the method may include:
s11: receiving an authorization request sent by a target client, and determining a directory corresponding to the authorization request as an appointed directory; the target client is any client which needs to create the batch files.
The execution subject of the method for creating files in batches provided by the embodiment of the present invention may be a corresponding device, and the device may be disposed in a client, so that the execution subject of the method may be a server, and the following detailed description will be given by taking the execution subject of the method as a server.
When any client needs to create files in batch, the client needing to create the files in batch can be called as a target client, so that the file batch creation of any client is realized. When a target client needs to create files in batch, an authorization request can be sent to a server, after the server receives the authorization request sent by the target client, a directory corresponding to the authorization request, that is, a directory identifier carried in the authorization request can be determined, and the directory for which the target client needs to create files in batch, which can be called as an appointed directory. In addition, in this embodiment, creating a file in batch, that is, creating multiple files simultaneously, and a Server can provide an MDS (Meta Data Server) metadata service, the method for creating a file in batch implemented in this embodiment of the present application is implemented based on the MDS.
S12: judging whether the appointed directory is authorized to other clients except the target client, if so, waiting until the batch creation of all files corresponding to the client with the authority to the appointed directory is completed, releasing the appointed directory, authorizing the appointed directory to the target client, and if not, authorizing the appointed directory to the target client; wherein the specified directory allows access only to clients having rights to the specified directory.
It should be noted that, in this embodiment, a Cap (Capability, metadata operation authority) that monopolizes a directory is introduced, and when a certain client holds the Cap of a certain directory, other clients cannot operate the directory to perform operations such as reading and writing, file creation, and the like; specifically, when a certain directory is an appointed directory, the appointed directory can only be authorized to one client at the same time, the client authorized by the appointed directory is a client having access right to the appointed directory, namely, the client can realize operations such as information reading and writing, file creation and the like under the appointed directory, and other clients not authorized cannot access the appointed directory; because if a plurality of clients create files under a specified directory at the same time, the situation that the names of the files created by different clients are the same may occur, but the situation that the names of the files are the same is actually not allowed, the situation that the names of the created files are the same and further the file creation fails when the plurality of clients simultaneously achieve the file creation under the same directory can be avoided through the setting of the authority of the directory; moreover, if a certain client creates a file or reads and writes under a directory, other clients accessing the directory at the moment cannot access the latest data information, that is, cannot access valid data information, so that through the setting of the permission to the directory, the situation that when one client achieves file creation under a directory, other clients cannot access valid data information such as files and the like under the directory can be avoided. Therefore, in this embodiment, after determining the designated directory, the server may determine whether the designated directory is currently authorized to other clients except the destination client, that is, whether other clients except the destination client have the right to the designated directory, if so, the designated directory cannot be authorized to the destination client, so that the designated directory is released after the batch creation of all files that the client having the right to the designated directory needs to implement is completed, that is, after the right to the designated directory is released, the designated directory does not have the client having the right to the designated directory, and at this time, the designated directory may be authorized to the destination client; if not, the designated directory may be directly authorized to the destination client.
In addition, if the specified directory is authorized to other clients except the destination client, the destination client may wait until the specified directory has the authority of the specified directory after being released, or may implement the sequential creation of the files in a conventional manner, and may specifically perform setting according to actual needs, all of which are within the protection scope of the present invention.
S13: receiving a plurality of creation requests sent by a target client, realizing simultaneous creation of a plurality of corresponding files based on the received creation requests, storing metadata of each file obtained by creation, and releasing a specified directory after batch creation of all files corresponding to the target client is completed.
After the target client side applies for obtaining the authority of the specified directory, the creation requests in a certain time (or certain items) can be packaged simultaneously, and the packaged result is sent to the server, so that the server analyzes the creation requests contained in the packaged result, the batch creation, namely simultaneous creation, of the corresponding files is further realized, the metadata of each file obtained by the creation is stored, and the specified directory is released after all files required to be created by the target client side are created and is available for other client sides to obtain. In addition, in this embodiment, the certain time may be total time required for instructing the server to implement batch creation of the files, and the certain entry may be total number of the files required for instructing the server to implement batch creation of the files, so as to implement batch creation of the files according to the requirement of the target client.
According to the technical scheme, when the client needs to create the files in batch, the authority of the appointed directory can be obtained through application, if the appointed directory is not authorized to other clients currently, the authority of the appointed directory can be obtained, and then the files are created in batch under the appointed directory, otherwise, the authority of the appointed directory is obtained after the access authority of other clients to the appointed directory is removed, and then the files are created in batch under the appointed directory. Therefore, the files required to be created can be created in batches under the instruction of the client, the file creation performance is improved, and the performance of the distributed file system is further improved; in addition, by setting the exclusive right for the specified directory, the situation that the names of created files are the same and further file creation fails when multiple clients simultaneously achieve file creation under the specified directory can be avoided, effective implementation of batch creation of the files is guaranteed, the situation that when one client achieves file creation under the specified directory, other clients cannot access the information such as the valid files when accessing the specified directory can be avoided, and the effectiveness of the clients in obtaining the information is guaranteed.
The method for creating files in batch provided by the embodiment of the invention can further include, before receiving an authorization request sent by a destination client:
receiving a connection request sent by a target client, responding to the connection request to establish connection with the target client, and pre-applying a file number in a preset range for the target client;
after the simultaneous creation of the plurality of files is realized based on the received creation request, the method further comprises:
respectively allocating file numbers belonging to a preset range to each file obtained by creation; wherein the metadata of the file includes a file number of the file.
It should be noted that, in this embodiment, in order to achieve simultaneous creation of multiple corresponding files, a file number of each file may be quickly obtained, and then the file creation rate is increased, so in this embodiment, after receiving a connection request sent by a destination client, a connection with the destination client may be established, and a file number (Inode, a file number that is included in a node) in a certain range (a preset range and may be set according to actual needs) is applied for the destination client from a metadata pool, and then allocation of the file number may be directly achieved when creating the file, and it is not necessary to obtain the file number from the metadata pool, and thus the file creation rate is greatly increased. After the server applies for a certain range of file numbers for the target client in advance, the server can inform the target client of all the file numbers distributed for the target client, so that the target client can know the file numbers of the files which are determined to be created based on the file numbers. In addition, if the target client needs to create files in batch and the file numbers allocated to the target client are used up, a certain range of file numbers can be allocated to the target client from the metadata pool, and so on, so as to ensure that the target client has sufficient file numbers to create the files.
The method for creating files in batch provided by the embodiment of the present invention may further include, after the simultaneous creation of a plurality of corresponding files is realized based on the received creation request:
setting corresponding file names for each created file respectively, and establishing association between the file name of each created file and a file number; the metadata of the file includes a file name and a file number having an association.
The creation request sent by the destination client may carry a file name (i.e., a name of a file) set by the client for the corresponding file, so that the name of the file obtained by creation is set as the file name carried in the corresponding creation request, and the file name and the file number of each file are associated and stored as metadata, thereby facilitating searching for the file and the like. In addition, the information having the association may specifically be a CInode (metadata Inode information, which mainly includes file attributes) and a CDentry (metadata directory entry, which mainly includes file names), where the CInode includes a file number, and the CDentry includes a file name, so that the associated CInode and CDentry include an associated file name and file number, and further include the associated CInode and CDentry in the metadata for storage, for example, in a metadata pool.
The method for creating files in batch provided by the embodiment of the invention can further comprise the following steps:
when the batch creation of all files corresponding to the target client is not completed, receiving authorization requests sent by other clients except the target client, indicating the target client to forcibly refresh all creation requests cached by the target client so as to obtain all creation requests refreshed by the target client, and executing the step of realizing the simultaneous creation of a plurality of corresponding files based on the received creation requests.
It should be noted that, the target client in this embodiment may package and send the creation requests corresponding to all files that the target client needs to create to the server, or may package and send the creation requests included in each batch to the server after dividing all files that the target client needs to create into multiple batches, which may be specifically determined according to actual situations; correspondingly, the application of the destination client for having the authority for the specified directory may include a time period in which the authority for the specified directory needs to be provided and the total number of all files that need to be created under the specified directory, while the incomplete destination client corresponds to the batch creation of all files, and specifically, the application of the destination client for having the authority for the specified directory may not have the time period in which the authority for the specified directory has the authority for the specified directory, and/or the number of the files created under the specified directory does not have the total number of all files that the destination client needs to create. In addition, the destination client can cache the creation request which needs to be sent and is not sent yet locally; if the target client side does not finish the batch creation of all files corresponding to the target client side, authorization requests sent by other client sides are received, whether the target client side has creation requests which are not sent to the server or not can be judged, if yes, the target client side can be informed to forcibly refresh the cached creation requests to the server, so that the server can realize corresponding file batch creation, file metadata storage and the like, if not, the server can finish the file batch creation, the file metadata storage and the like corresponding to the creation requests which are sent to the server by the target client side, and then the authority of the specified directory is released after the batch creation and the corresponding metadata storage of all files which need to be created by the target client side are realized, so that the use of the specified directory by other client sides can be facilitated.
The method for creating files in batch provided by the embodiment of the invention can further comprise the following steps:
if a fault occurs in the process of realizing batch creation of all files corresponding to the target client, receiving each creation request recorded by the target client and retransmitted by the target client after the fault is repaired; the client records a creation request corresponding to each file to be created.
The client can locally record the creation request to be sent before sending the creation request to the server, and further if the server fails during processing the batch creation request, the server needs to repair the failure, and after the server is repaired and can normally work, the client needs to resend the recorded creation request to the server, and the server realizes batch file creation again after receiving the creation request resent by the client, so that the effective realization of batch file creation by the client is ensured.
The method for creating files in batch provided by the embodiment of the invention can further include the following steps after the target client side is created in batch corresponding to all the files:
and returning confirmation information of successful batch creation of all the files corresponding to the target client to indicate the creation request of deleting the record of the target client.
After the server completes batch creation of all files corresponding to the target client, confirmation information can be returned to the target client, so that the target client can know the created information of all files to be created, and further delete the recorded creation request, thereby avoiding waste of storage space in the target client.
Moreover, after the target client is implemented to perform batch creation of all files, the method may further include:
and sending a marking instruction to the target client to indicate the target client to record the mark of successful creation of the batch file in the log of file creation.
By sending the marking instruction to the target client, the target client can be instructed to record the mark of successful creation of the batch file in the log after receiving the marking instruction, so as to be queried at a later stage.
In a specific implementation scenario, a method for creating files in batch provided in an embodiment of the present application may include:
(1) inode pre-allocation:
when the server is connected with the client, the server applies for Inode in a certain range from the metadata pool and informs the client;
(2) the Cap application:
when a client creates a file under a certain directory, applying for exclusive Cap of the directory to a server, and if no other client uses the directory, the server agrees to grant the exclusive Cap of the directory to the client; and if other clients are using the directory, the server refuses to authorize the exclusive Cap, and after all files of other clients are created, the server agrees to authorize the exclusive Cap of the directory to the client.
(3) Sending in batches:
after applying for exclusive Cap of the directory, the client packs the creation request within a certain time (or a certain request entry) and sends the request to the server, and the client records the sent request (for fault processing); if a certain time or an item period is not reached, other clients apply for the exclusive Cap of the directory to the server, and the server informs the client of forcibly refreshing the creation request in the cache and then releases the exclusive Cap;
(4) the server processes the batch requests:
after receiving the batch creation request of the client, the server analyzes the batch creation request, creates a corresponding file, associates the CInode and the CDentry of the file, drops all created metadata into a metadata pool, and then responds (can comprise confirmation information and a marking instruction) to the client to complete the request;
(5) and a finishing stage:
after receiving the server response, the client clears the sent request recorded in the client, and marks that the batch creation service is completed;
(6) and (3) fault repair:
if the server fails during processing of the batch creation request, the client needs to resend the batch creation request to the server for processing again in the server recovery phase.
The method for creating the files in batch in the distributed file system can greatly improve the file creating performance and the metadata creating performance, particularly the creating performance of small file scenes, and further improve the creating performance of the distributed file system.
An embodiment of the present invention further provides a device for creating files in batch, and as shown in fig. 2, the device specifically includes:
a determining module 11, configured to: receiving an authorization request sent by a target client, and determining a directory corresponding to the authorization request as an appointed directory; the target client is any client needing to create the batch files;
a judging module 12, configured to: judging whether the appointed directory is authorized to other clients except the target client, if so, waiting until the batch creation of all files corresponding to the client with the authority to the appointed directory is completed, releasing the appointed directory, authorizing the appointed directory to the target client, and if not, authorizing the appointed directory to the target client; wherein, the appointed directory only allows the client with the authority to access the appointed directory;
a creation module 13 for: receiving a plurality of creation requests sent by a target client, realizing simultaneous creation of a plurality of corresponding files based on the received creation requests, storing metadata of each file obtained by creation, and releasing a specified directory after batch creation of all files corresponding to the target client is completed.
The apparatus for creating files in batch provided by the embodiment of the present invention may further include:
a connection module for: before receiving an authorization request sent by a target client, receiving a connection request sent by the target client, responding to the connection request to establish connection with the target client, and pre-applying a file number in a preset range for the target client;
an assignment module to: after the simultaneous creation of a plurality of corresponding files is realized based on the received creation request, file numbers belonging to a preset range are respectively distributed to each file obtained by the creation; wherein the metadata of the file includes a file number of the file.
The apparatus for creating files in batch provided by the embodiment of the present invention may further include:
a setup module to: after the simultaneous creation of a plurality of corresponding files is realized based on the received creation request, respectively setting corresponding file names for each file obtained by creation, and establishing association between the file name of each file obtained by creation and a file number; the metadata of the file includes a file name and a file number having an association.
The apparatus for creating files in batch provided by the embodiment of the present invention may further include:
an indication module to: when the batch creation of all files corresponding to the target client is not completed, receiving authorization requests sent by other clients except the target client, indicating the target client to forcibly refresh all creation requests cached by the target client so as to obtain all creation requests refreshed by the target client, and executing the step of realizing the simultaneous creation of a plurality of corresponding files based on the received creation requests.
The apparatus for creating files in batch provided by the embodiment of the present invention may further include:
a reconstruction module to: if a fault occurs in the process of realizing batch creation of all files corresponding to the target client, receiving each creation request recorded by the target client and retransmitted by the target client after the fault is repaired; the client records a creation request corresponding to each file to be created.
The apparatus for creating files in batch provided by the embodiment of the present invention may further include:
a return module to: and after the batch creation of all files corresponding to the target client is realized, returning confirmation information of successful batch creation of all files corresponding to the target client to indicate the creation request of deleting the record of the target client.
The apparatus for creating files in batch provided by the embodiment of the present invention may further include:
a sending module configured to: after the target client side is established in batch corresponding to all the files, a marking instruction is sent to the target client side so as to indicate the target client side to record a mark of successful establishment of the batch files in a log of file establishment.
An embodiment of the present invention further provides a device for creating files in batch, where the device may include:
a memory for storing a computer program;
a processor for implementing the steps of the method for batch creation of files as described in any one of the above when executing a computer program.
The embodiment of the invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for creating the files in batches as described above can be implemented.
It should be noted that for the description of the relevant parts in the apparatus, the device, and the storage medium for creating files in batches provided in the embodiment of the present invention, reference is made to the detailed description of the corresponding parts in the method for creating files in batches provided in the embodiment of the present invention, and details are not repeated here. In addition, parts of the above technical solutions provided in the embodiments of the present invention that are consistent with the implementation principles of the corresponding technical solutions in the prior art are not described in detail, so as to avoid redundant description.
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.