File creation method and apparatus, electronic device, and computer-readable storage medium
By determining the target file structure in offline mode and creating directories layer by layer starting from the last level, the problem of low efficiency in creating files and directories in distributed file systems is solved, achieving more efficient directory and file creation.
Patent Information
- Application Number
- CN202211079457.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-05
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2042-09-05
AI Technical Summary
Existing technologies are inefficient when creating files and directories in distributed file systems because the parent directory needs to be updated every time a subdirectory or file is created, resulting in more updates the deeper the directory hierarchy.
In offline mode, the target file structure is determined by receiving file creation requests, and directories are created layer by layer from the last level directory upwards. Files are created first and then the upper-level directories are created. The target sequence number of each directory is determined by the initial file sequence number, reducing the number of directory updates.
It improves the efficiency of file and directory creation, reduces creation time, and solves the problem of low creation efficiency in existing technologies.
Smart Images

Figure CN115422137B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of file processing and the field of distributed file system testing, in particular, to a file creation method and device, an electronic device and a computer readable storage medium. BACKGROUND
[0002] In order to verify the reliability of a distributed file system, sometimes it is necessary to perform system performance and stability testing on the basis of a large number of files, and therefore it is inevitable to fill a large number of files according to a certain directory structure. At present, the common practice is to create directories and files in a distributed file system in an online mode by using a tool developed on the basis of the semantics of the distributed file system.
[0003] However, the existing technology follows the principle of creating a parent directory first, then creating a child directory, and finally creating a file when creating a directory and a file. This creation method needs to update the parent directory at the upper level once every time a child directory or a file is created. The deeper the directory level, the more parent directories that need to be updated. Therefore, due to repeated multiple updates of the parent directory at the upper level, the creation efficiency of the directory and the file is low.
[0004] At present, no effective solution has been proposed for the above problems. SUMMARY
[0005] The embodiments of the present application provide a file creation method and device, an electronic device and a computer readable storage medium, to at least solve the technical problem of low creation efficiency in the prior art when creating files and directories in a distributed file system.
[0006] According to an aspect of an embodiment of the present application, a file creation method is provided, comprising: receiving a file creation request through a distributed file system, wherein the file creation request is used to create a preset number of files and a directory containing the files in the distributed file system, the file creation request at least contains a directory depth, a directory width and an initial file serial number, the directory depth is used to represent a number of levels of the directory to be created, the directory width is used to represent a number of next-level directories contained in each directory, and the initial file serial number is used to number the directories and the files; when the distributed file system is in an offline mode, determining a target file structure according to the directory depth, the directory width and the preset number, wherein the target file structure is used to represent a topological relationship between the multi-level directories to be created and a target number of the files to be created, and the target number is greater than or equal to the preset number; creating the target number of files in a database in the distributed file system according to the target file structure, and creating the directories of each level in a manner of layer by layer from the last level of the directories to the top, wherein the target number of files are located in the last level of the directories, and in the process of creating each directory, a target serial number of each directory is determined according to the initial file serial number.
[0007] Further, the file creation method further comprises: determining a number of directory levels constituting the target file structure and a number of directories corresponding to each level of the directories according to the directory depth and the directory width; determining that a number of directories corresponding to the last level of the directories in the target file structure is a first number; determining the target number of the files to be created according to a size relationship between the first number and the preset number, wherein a number of files corresponding to each directory in the last level of the directories is the same; and determining the target file structure according to the number of directories corresponding to each level of the directories, the number of directory levels and the target number.
[0008] Further, the file creation method further comprises: when the first number is greater than or equal to the preset number, determining that the first number is the target number; when the first number is less than the preset number, calculating a ratio of the preset number to the first number; when the ratio is an integer, calculating a product of the ratio and the first number to obtain the target number; and when the ratio is a non-integer, calculating a product of a target integer and the first number to obtain the target number, wherein the target integer is a smallest integer greater than the ratio.
[0009] Further, the file creation method further comprises: determining a level of each directory and a position sequence of each directory in the level; determining a serial number of each directory according to the level and the position sequence; and determining a target serial number of each directory according to the serial number and the initial file serial number.
[0010] Further, the file creation method further comprises: when the directory width is greater than 1, determining the serial number of each directory according to the directory width, the position sequence and the located level, wherein the directory width, the position sequence and the located level are in numerical form; when the directory width is equal to 1, determining the serial number of each directory according to the position sequence and the located level.
[0011] Further, the file creation method further comprises: determining any one directory as a target directory; when the located level of the target directory is the first level, determining that the target serial number of the parent directory of the target directory is 1; when the located level of the target directory is the last level, determining the target serial number of the parent directory of the target directory according to the located level of the target directory, the position sequence of the target directory in the located level and the first file quantity, wherein the first file quantity is the quantity of files to be created under each directory in the last level; when the located level of the target directory is the intermediate level, determining the target serial number of the parent directory of the target directory according to the directory width, the located level of the target directory and the position sequence of the target directory in the located level.
[0012] Further, the file creation method further comprises: after determining any one directory as a target directory, determining a first value according to the located level of the target directory and the directory depth, wherein the first value is used to determine the total quantity of subdirectories, and the total quantity of subdirectories is the quantity of all subdirectories of the target directory; when the directory width is greater than 1, determining the total quantity of subdirectories according to the first value and the directory width; when the directory width is 1, determining that the first value is the value of the total quantity of subdirectories.
[0013] Further, the file creation method further comprises: after determining the first value according to the located level of the target directory and the directory depth, determining the total quantity of files contained in the target directory according to the first value, the directory depth and the first file quantity; obtaining a unit logical space, wherein the unit logical space is used to represent the virtual space capacity occupied by one file in the distributed file system; and determining the total logical space occupied by the target directory in the distributed file system according to the unit logical space and the total quantity of files.
[0014] Further, the file creation method further comprises: when creating the target quantity of files and the directories of each level, detecting whether the distributed file system restarts; when the distributed file system restarts and the restart is successful, covering the files and directories that have been created and continuing to write new files and directories.
[0015] According to a further aspect of the embodiments of the present application, a file creation apparatus is also provided, which comprises: a receiving module configured to receive a file creation request through a distributed file system, wherein the file creation request is used to create a preset number of files and a directory containing the files in the distributed file system, and the file creation request at least contains a directory depth, a directory width and an initial file serial number, the directory depth is used to represent a number of levels of the directory to be created, the directory width is used to represent a number of next-level directories contained in each directory, and the initial file serial number is used to number the directories and the files; a determining module configured to determine a target file structure according to the directory depth, the directory width and the preset number when the distributed file system is in an offline mode, wherein the target file structure is used to represent a topological relationship between the multi-level directories to be created and a target number of the files to be created, and the target number is greater than or equal to the preset number; and a creating module configured to create the target number of files in a database in the distributed file system according to the target file structure, and create the directories of each level in a manner of starting from a last-level directory and layer by layer upwards, wherein the target number of files are located in the last-level directory, and in the process of creating each directory, a target serial number of each directory is determined according to the initial file serial number.
[0016] According to a further aspect of the embodiments of the present application, a computer readable storage medium is also provided, which stores a computer program, wherein the computer program is configured to execute the file creation method when running.
[0017] According to a further aspect of the embodiments of the present application, an electronic device is also provided, which comprises one or more processors and a memory, the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the file creation method.
[0018] In the present application, a file is first created, and then a directory of each layer is created layer by layer from the last layer of the directory. First, a file creation request is received through the distributed file system, wherein the file creation request is used to create a preset number of files and directories containing the files in the distributed file system. The file creation request at least contains a directory depth, a directory width and an initial file serial number. The directory depth is used to represent the number of levels of the directory to be created. The directory width is used to represent the number of next level directories contained in each directory. The initial file serial number is used to number the directories and the files. Then, when the distributed file system is in an offline mode, a target file structure is determined according to the directory depth, the directory width and the preset number, wherein the target file structure is used to represent the topological relationship between the multiple directories to be created and the target number of files to be created, and the target number is greater than or equal to the preset number. Finally, the target number of files are created in the database in the distributed file system according to the target file structure, and each layer of the directory is created layer by layer from the last layer of the directory. The target number of files are located in the last layer of the directory. In the process of creating each directory, the target serial number of each directory is determined according to the initial file serial number.
[0019] From the above, when the distributed file system is in an offline mode, the present application first determines a target file structure according to the directory depth, the directory width and the preset number, and then creates files based on the directory file structure, and creates the parent directory of the upper layer layer by layer from the last layer of the directory. In the file and directory creation process of the present application, each directory only needs to be updated once, without repeated updating, thereby solving the problem of repeated updating of the upper parent directory in the prior art when creating files and directories, and further reducing the file and directory creation time and improving the file and directory creation efficiency.
[0020] Therefore, through the technical scheme of the present application, the directory update frequency is reduced, the directory and file creation efficiency is improved, and the technical problem of low creation efficiency in the prior art when creating files and directories in the distributed file system is solved. BRIEF DESCRIPTION OF DRAWINGS
[0021] The drawings described herein are used to provide further understanding of the present application, and form a part of the present application. The schematic embodiments of the present application and the description thereof are used to explain the present application, and do not constitute an improper limitation on the present application. In the drawings:
[0022] Figure 1 A flow chart of an optional file creation method according to an embodiment of the present application;
[0023] Figure 2 A schematic diagram of an optional target file structure according to an embodiment of the present application;
[0024] Figure 3 An optional flow chart for determining the serial number of each directory according to an embodiment of the present application;
[0025] Figure 4 An optional flow chart for determining the target serial number of the parent directory according to an embodiment of the present application;
[0026] Figure 5 An optional schematic diagram of a file creation device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to make the personnel in the technical field better understand the present application scheme, the technical scheme in the present application embodiment will be described clearly and completely below in combination with the drawings in the present application embodiment. Obviously, the described embodiments are only a part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by the person skilled in the art without creative labor should belong to the scope of protection of the present application.
[0028] It should be noted that the terms "first", "second" and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Embodiment 1
[0030] According to an embodiment of the present application, an embodiment of a file creation method is provided. It should be noted that the steps shown in the flowchart of the drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that herein.
[0031] In addition, in order to facilitate better understanding of the technical scheme of the present application, some terms used in the present application are explained as follows:
[0032] Distributed file system: a storage system that stores data on multiple storage servers and constructs a virtual storage device from these scattered storage resources to provide file interface semantics to the outside;
[0033] mds: meta data system, a daemon process for managing, storing, and distributing distributed file system metadata information;
[0034] Online mode: a working mode of a distributed file system, in which the distributed file system mounts the metadata disk and operates normally according to the file system semantics;
[0035] Offline mode: another working mode of a distributed file system, corresponding to the online mode, in which the distributed file system does not mount the metadata disk and directly writes data to the backend storage or database;
[0036] Directory structure: a way of organizing files for a distributed file system, usually a tree structure.
[0037] Figure 1 According to an optional file creation method according to an embodiment of the application, a flowchart as shown in Figure 1 The method comprises the following steps:
[0038] Step S101, receiving a file creation request through a distributed file system.
[0039] In step S101, the file creation request is used to create a preset number of files and directories containing the files in the distributed file system. The file creation request at least contains the directory depth, the directory width and the initial file serial number. The directory depth is used to represent the number of levels of the directory to be created. The directory width is used to represent the number of next-level directories contained in each directory. The initial file serial number is used to number the directories and files. One of the above files is a database kv key-value pair.
[0040] Specifically, a data filling tool can be the execution subject of the file creation method in the embodiment of the application. The data filling tool can be a component set in the distributed file system, which is used to create directories and files in the distributed file system.
[0041] In an alternative embodiment, in order to test the stability of the distributed file system, the tester creates a certain number of directories and files in the distributed file system, and then performs relevant tests according to the created directories and files. Specifically, the tester can send a file creation request to the distributed file system through a terminal device, and the file creation request includes at least the number of files (i.e., the preset number) that the tester needs to create, the directory depth, the directory width, and the initial file serial number. The directory depth represents the number of directory layers that the tester needs to create, the directory width represents the number of subdirectories included in each directory, and the initial file serial number represents the starting assignable serial number in this directory and file creation process.
[0042] For convenience of description, the following uses depth to represent the directory depth, width to represent the directory width, and start_fileid to represent the initial file serial number. For example, depth = 3 represents that the directory to be created has 3 layers, i.e., the generated directory structure is a 3-layer directory structure, and width = 2 represents that each directory contains two subdirectories. In addition, it should be noted that the initial file serial number is related to the existing directories and files in the distributed file system. For example, if 100 directories and files have been created in the distributed file system, and the serial numbers of these 100 directories and files are 001-100, in order to avoid serial number duplication, the initial file serial number in this file creation request can be any value greater than 100, such as 101, 102, 103, etc.
[0043] Step S102, when the distributed file system is in an offline mode, determining a target file structure according to the directory depth, the directory width, and the preset number.
[0044] In step S102, the target file structure is used to represent the topological relationship between the multiple layers of directories to be created and the target number of files to be created, and the target number is greater than or equal to the preset number.
[0045] Specifically, the above-mentioned target file structure is a directory structure determined according to the directory depth, the directory depth, and the preset number, and the directory file structure is used to describe the organization structure between the files and directories to be created, which is usually a tree structure.
[0046] It should be noted that in the present application, all the created files are in the last layer of the directory, and each directory in the last layer has the same number of files, so that the purpose of uniformly distributing the files is to improve the test efficiency and facilitate the test personnel to better and faster count the test results. On this basis, in order to ensure the uniform distribution of files in the last layer of the directory, the final number of created files (i.e. the target number) may be greater than the preset number in the file creation request. For example, if the last layer of the directory has a total of 1024, and the preset number of files to be created in the file creation request is 1024, then 1 file can be created under each directory in the last layer. However, if the last layer of the directory has 1024, and the preset number of files to be created in the file creation request is 1025, then in order to ensure that each directory in the last layer has the same number of files, 2 files can be created under each directory in the last layer, i.e. a total of 1024*2=2048 files will be generated. In order to ensure that the test requirements of the test personnel can be met, the target number can only be greater than the preset number, and cannot be less than the preset number.
[0047] In an alternative embodiment, Figure 2 A schematic diagram of a target file structure is shown, wherein in Figure 2 , the directory depth depth=3, the directory width width=2, and the preset number fcount=8. As Figure 2 indicated, depth=3 indicates that the target file structure has a 3-layer directory structure, width=2 indicates that each directory contains two subdirectories, and fcount=8 indicates that the number of files to be created is 8, and can only be created in the last level directory. If the situation cannot be evenly allocated, then round up, ensure that the number of files created in each last level directory is the same and the total number of files is not less than fcount. In Figure 2 , the name prefix dir is a directory, the name prefix file is a file, and root is the root directory.
[0048] In step S103, the target number of files are created in the database in the distributed file system according to the target file structure, and the directories of each layer are created in a manner of starting from the last layer of the directory and going up layer by layer.
[0049] In step S103, the target number of files are located in the last layer of the directory, and in the process of creating each directory, the target serial number of each directory is determined according to the initial file serial number.
[0050] Specifically, unlike existing technologies, this application, after determining the target file structure, first creates the target number of files in a distributed file system, then creates the last-level directory to hold the files, and after the last-level directory is created, it begins to create the upper-level directories one by one. In other words, this application creates subdirectories first and then creates the parent directories.
[0051] In addition, during the creation of directories and files, the data population tool also determines the target sequence number of each directory and each file based on the initial file sequence number. The target sequence number of each directory represents the order in which the directory was created in the distributed file system. A directory's target sequence number consists of the initial file sequence number and the directory's sequence number. For ease of description, a directory's target sequence number can be represented by `file id`, and the sequence number can be represented by `index`. The initial file sequence number can be represented by `start_fileid`. Therefore, the target sequence number of the directory, `file id`, is calculated as `index + start_fileid`.
[0052] Furthermore, in this application, a file is a database key-value pair, represented by a data structure called an inode. The naming convention for the key is parent directory file ID (occupying 8 bytes) + the name of the directory or file. For example, in... Figure 2 In the database, the key for directory dir_0_0 is the file ID (a fixed value, 1) of its parent directory root plus the directory name dir_0_0. The value is a specific encoding of the inode data structure, primarily containing information such as the file ID assigned to the directory or file, the timestamp when the file or directory was created, the logical space per unit of the file, the total amount of data contained in each directory, and the total logical space occupied by the directory in the distributed file system. The total amount of data is the sum of the quantities of various data types within the directory, including but not limited to subdirectories and files. The resulting directory and file system forms a tree-like structure that grows downwards from the root directory.
[0053] In addition, when creating files and directories, this application first switches the distributed file system to offline mode, and then creates files and directories in offline mode. During the creation of files and directories, each directory and file is named by calculation. At the same time, when creating each directory, the number of all subdirectories, the number of files, and the total logical space occupied in the distributed system under each directory are calculated by calculation.
[0054] It should be noted that in the online mode, the prior art needs to update the statistical information of the parent directory in real time every time a directory or file is created in the distributed file system, including the number of subdirectories and files owned by the parent directory and the total logical space occupied. The deeper the directory level, the more parent directories that need to be modified, which seriously affects the filling efficiency.
[0055] In the technology of the present application, the number of subdirectories and the total number of files contained in a certain directory, and the total logical space occupied are accurately known by calculation in offline mode. Then, the directories and files can be created in a way from the last layer to the upper layer, and the number of subdirectories, the total number of files and the total logical space occupied under each directory can be obtained by calculation when creating a directory. Thus, the directory will only be updated once, thereby improving the filling efficiency. In the present application, the root directory is the last updated directory.
[0056] In addition, the reason for choosing to create text and directories in offline mode is that in online mode, there is a master-slave relationship between multiple mds of the distributed file system. The master mds is responsible for receiving and processing file system semantic requests sent by the client, then performing a series of checks and finally forming sub op and distributing it to each slave mds. Each slave mds needs to strictly follow the order of sub op sent by the master mds (since the network does not guarantee the order of sub op, a global version is needed to sort the sub op) to persist these sub op, and reply to the master mds after completing the local persistence to confirm the completion of the sub op.
[0057] In offline mode, the data filling tool can perform local disk (database) write operations on multiple mds of the distributed file system at the same time, thereby persisting the files (database kv key-value pairs) to be written to the local disk (database). In other words, in offline mode, there is no need for communication between mds for sub op distribution, processing and confirmation in master-slave mode, and the global version is not needed to ensure that the files (database kv key-value pairs) written by the master and slave mds are strictly consistent, because the write to the local disk (database) does not go through the network layer transmission, so it will not be out of order. In addition, in the prior art, only single file writing is allowed when writing files in online mode, which has low writing efficiency. The present application supports batch writing of files in offline mode, thereby improving the writing efficiency of files and further improving the test efficiency of the distributed file system.
[0058] As can be known from the above steps S101 to S103, in the present application, a manner of first creating a file and then creating a directory of each layer from a last layer directory upwards is adopted, a file creation request is first received by the distributed file system, the file creation request is used to create a preset number of files and directories containing the files in the distributed file system, the file creation request at least contains a directory depth, a directory width and an initial file serial number, the directory depth is used to represent a number of levels of the directory to be created, the directory width is used to represent a number of next level directories contained by each directory, and the initial file serial number is used to number the directories and the files. Then, when the distributed file system is in an offline mode, a target file structure is determined according to the directory depth, the directory width and the preset number, the target file structure is used to represent a topological relationship between the multiple directories to be created and a target number of the files to be created, and the target number is greater than or equal to the preset number. Finally, the target number of files are created in a database in the distributed file system according to the target file structure, and each layer of the directory is created from the last layer directory upwards, wherein the target number of files are located in the last layer directory, and in the process of creating each directory, a target serial number of each directory is determined according to the initial file serial number.
[0059] As can be known from the above content, in the present application, when the distributed file system is in the offline mode, the target file structure is first determined according to the directory depth, the directory width and the preset number, and then the files are created based on the directory file structure, and the parent directories of the upper layer are created from the last layer directory upwards. In the process of creating the files and the directories in the present application, each directory only needs to be updated once, and does not need to be repeatedly updated, thereby solving the problem of repeatedly updating the parent directories of the upper layer in the prior art when creating the files and the directories, and further reducing the creation time of the files and the directories and improving the creation efficiency of the files and the directories.
[0060] As can be seen, through the technical scheme of the present application, the purpose of reducing the number of directory updates is achieved, thereby realizing the effect of improving the creation efficiency of the directories and the files, and further solving the technical problem of low creation efficiency in the prior art when creating the files and the directories in the distributed file system.
[0061] In an optional embodiment, the data filling tool first determines a number of directory layers constituting the target file structure and a number of directories corresponding to each layer according to the directory depth and the directory width, and determines that a number of directories corresponding to the last layer directory in the target file structure is a first number, then the data filling tool determines a target number of the files to be created according to a size relationship between the first number and the preset number, and determines the target file structure according to the number of directories corresponding to each layer, the number of directory layers and the target number. Wherein, the number of files corresponding to each directory in the last layer directory is the same.
[0062] Optionally, as shown in Figure 2 the target file structure, the catalog depth and the catalog width define the number of catalogs in the target file structure, the number of layers of the catalogs, and the number of sub-catalogs under each specific catalog, and the number of catalogs in each layer. In addition, the target number of files to be created in a catalog file structure may be different from the preset number in the file creation request. The target number of files to be created is related to the number of catalogs in the last layer of catalogs (i.e., the first number), and in order to achieve uniform distribution of files, if uniform distribution is not possible, the number of files created in each last layer of catalogs is the same and the total number of files is not less than the preset number.
[0063] Specifically, when the first number is greater than or equal to the preset number, the data filling tool determines the first number as the target number; when the first number is less than the preset number, the data filling tool calculates the ratio of the preset number to the first number, and when the ratio is an integer, the data filling tool calculates the product of the ratio and the first number to obtain the target number; when the ratio is not an integer, the data filling tool calculates the product of the target integer and the first number to obtain the target number, wherein the target integer is the smallest integer greater than the ratio.
[0064] For example, assuming that the number of catalogs in the last layer is 1024, i.e., the first number is 1024. If the preset number is also 1024, the data filling tool determines that 1024 files need to be created, and each catalog in the last layer has one file; if the preset number is 1000, which is less than the first number, the data filling tool determines that 1024 files still need to be created, and each catalog in the last layer has one file; if the preset number is 2048, which is exactly twice the first number, the data filling tool determines that 1024*2=2048 files need to be created, and each catalog in the last layer has two files; if the preset number is 1025, the ratio of the preset number to the first number is 1025 / 1024, which is not an integer, and the ratio needs to be rounded up to obtain the target integer 2, and the final target number is 1024*2=2048, i.e., the data filling tool determines that 1024*2=2048 files need to be created, and each catalog in the last layer has two files.
[0065] It should be noted that the purpose of uniform distribution of files is to improve test efficiency and facilitate testers to better and faster count test results.
[0066] In an alternative embodiment, in the process of creating each directory, the data population system also determines the level of each directory and the position order of each directory in the level, and determines the serial number of each directory according to the level and the position order, and then determines the target serial number of each directory according to the serial number and the initial file serial number.
[0067] Optionally, the name of a directory is composed of a preset directory prefix, the level of the directory, and the serial number corresponding to the directory. For example, in Figure 2 , the "dir" in the directory "dir_1_3" is the preset directory prefix, "1" indicates that the directory is in the first "1" level (the actual number of levels is the second level), and "3" is the serial number corresponding to the directory. In Figure 2 , the number of directory levels is three, i.e., the first "0" level, the first "1" level, and the first "2" level.
[0068] In addition, the application determines the serial number of each directory by calculation. Specifically, the following cases are considered, as shown in Figure 3
[0069] Step S301: When the directory width is greater than 1, the data population tool determines the serial number of each directory according to the directory width, the position order, and the level.
[0070] In step S301, the directory width, the position order, and the level are in numerical form.
[0071] Optionally, for convenience of description, the following uses current_depth to represent the level of a directory or a file (coded from 0), current_width to represent the left-to-right position order of a directory or a file in the level (coded from 0), and fcount_avg to represent the number of files to be created under each directory in the last level.
[0072] If the directory width width>1, the serial number index of the directory is calculated by the formula index=(width^(current_depth+1)-1) / (width-1)-1+current_width, for example, taking the directory "dir_1_3" in Figure 2 as an example, the level current_depth of the directory is 1, the position order current_width is 1, and the directory width is 2, so the serial number index of the directory is index=(2^(1+1)-1) / (2-1)-1+1=3. In addition, taking the directory "dir_1_3" in Figure 2 For example, the directory "dir_1_2" in the directory tree, the directory's current_depth is 1, the directory's current_width is 0, and the directory's width is 2. Thus, the directory's index = (2^(1+1)-1) / (2-1)-1+0 = 2.
[0073] In step S302, when the directory's width is equal to 1, the data filling tool determines the index of each directory according to the current_depth and the current_width.
[0074] In step S302, when the directory's width is equal to 1, the data filling tool determines the index of each directory according to the current_depth and the current_width.
[0075] In addition, when the directory's width is equal to 0, the data filling tool determines the target value as the index of each file, where the target value represents the current_width. Specifically, when the directory's width is equal to 0, the data filling tool determines the index of each file according to the formula index = current_width.
[0076] It should be noted that after the index of a directory is determined, the target index of the directory can be determined according to the formula file id = index + start_fileid, where file id is the target index, and start_fileid is the initial file index.
[0077] In an optional embodiment, since the key of a directory in the database is the target index of the parent directory of the directory + the target name of the directory itself, when a directory is created, the target index of the parent directory of the directory also needs to be obtained. Specifically, as shown in Figure 4
[0078] In step S401, the data filling tool determines an arbitrary directory as a target directory.
[0079] In step S402, when the current_depth of the target directory is the first layer, the data filling tool determines that the target index of the parent directory of the target directory is 1.
[0080] Optionally, when the current_depth of the target directory is the 0th layer, i.e., the first layer in the target file structure, it indicates that the parent directory of the target directory is the root directory, and the target index of the parent directory of the target directory is parent_file_id = 1. In order to facilitate representation, the target index of the parent directory is represented by parent_file_id.
[0081] Step S403, when the target directory is in the last layer, determining the target serial number of the parent directory of the target directory according to the layer of the target directory, the position sequence of the target directory in the layer, and the first file quantity,
[0082] In step S403, the first file quantity is the quantity of files to be created under each directory in the last layer. For convenience, the first file quantity is denoted as fcount_avg.
[0083] If the layer of the target directory current_depth is the last layer, i.e., current_depth = depth, it means that the data filling tool is creating files at this time, and the directory serial number of the parent directory of the target directory can be calculated by the formula parent_file_id = calculate_fileid(current_depth-1, current_width / fcount_avg), wherein calculate_fileid represents a calculation formula in which "current_depth-1" is taken as "current_depth" in the formula for calculating the target serial number of each directory, "current_width / fcount_avg" is taken as "current_width" in the formula for calculating the directory serial number of each directory, and then the calculation formula is calculated according to the formula for calculating the directory serial number of each directory. For example, when calculating the parent directory of a target directory, if the directory width width>1, the target serial number of the parent directory of the target directory is calculated by the formula index = (width^(current_depth-1+1)-1) / (width-1)-1+current_width / fcount_avg.
[0084] Step S404, when the target directory is in the middle layer, determining the target serial number of the parent directory of the target directory according to the directory width, the layer of the target directory, and the position sequence of the target directory in the layer.
[0085] If the target directory is in a level current_depth < depth, it means that the data filling tool is creating a directory at this time, and the directory sequence number of the parent directory of the target directory can be calculated by the formula parent_file_id = calculate_fileid(current_depth - 1, current_width / width), where calculate_fileid represents a calculation formula in which "current_depth - 1" is used as "current_depth" in the formula for calculating the target sequence number of each directory, "current_width / width" is used as "current_width" in the formula for calculating the directory sequence number of each directory, and then the calculation formula is calculated according to the formula for calculating the directory sequence number of each directory. For example, when solving the parent directory of a target directory, if the directory width width > 1, the target sequence number of the parent directory of the target directory is calculated by the formula index = (width^(current_depth - 1 + 1) - 1) / (width - 1) - 1 + current_width / width.
[0086] As can be seen from the above, the target sequence number of each directory and the target sequence number of the parent directory of each directory can be determined by calculation, so that the key value corresponding to each directory can be ensured to be generated.
[0087] It should be noted that in the present application, the directory is prefixed with the string "dir_", the file is prefixed with the string "file_", and the rest is the level of the directory or file + the sequence number of the directory or file. The sequence number determination process of the file is the same as that of the directory, which is based on the above calculation formula, and therefore the sequence number determination process of the file will not be described in detail.
[0088] In addition, it should be noted that in the prior art, there is a master-slave relationship between multiple mds in online mode, and the master mds needs to assign the directory sequence number of the directory in a protected scenario, i.e., when holding a certain specific resource lock, in order to avoid a directory sequence number being assigned to multiple files (except for hard link files), which may cause serious lock competition when the client creates a directory or a file in the master mds, thereby affecting the filling efficiency.
[0089] In the present application, in offline mode, the target sequence number is assigned to the newly created directory and file starting from the initial file sequence number, without the need for lock protection, so as to avoid the problem of low file and directory creation efficiency caused by the influence of lock competition.
[0090] In an optional embodiment, after determining any one directory as the target directory, the data filling tool further determines a first value according to the level at which the target directory is located and the directory depth, wherein the first value is used to determine the total number of subdirectories, which is the number of all subdirectories of the target directory. When the directory width is greater than 1, the data filling tool determines the total number of subdirectories according to the first value and the directory width; when the directory width is 1, the data filling tool determines the first value as the value of the total number of subdirectories.
[0091] Optionally, since the value corresponding to the directory also records the total amount of data contained in the directory and the total logical space occupied by the directory in the distributed file system, etc., wherein the total amount of data is the sum of the number of various types of data in the directory, various types of data including but not limited to subdirectories and files. Therefore, in order to obtain the total amount of data, the data filling tool needs to count the number of all subdirectories under each directory. Specifically, when the level at which the target directory is located current_depth < depth, it means that the data filling tool is creating a directory at this time, and the data filling tool calculates the first value steps according to the formula steps = depth - current_depth - 1. If the directory width width > 1, then the total number of subdirectories of the target directory dirs = (width^(steps+1)-1) / (width-1)-1. For example, still taking Figure 2For example, the directory "dir_1_3" has a width of 2 and a depth of 3, and the "current_depth" of the directory "dir_1_3" is 1. Thus, the first value steps = depth - current_depth - 1 = 3 - 1 - 1 = 1, and the total number of subdirectories dirs = (width^(steps+1) - 1) / (width - 1) - 1 = (2^(1+1) - 1) / (2 - 1) - 1 = 2. Therefore, the directory "dir_1_3" contains a total of 2 subdirectories, which are "dir_2_8" and "dir_2_9". In addition, the directory "dir_0_0" has a "current_depth" of 0. Thus, the first value steps = depth - current_depth - 1 = 3 - 0 - 1 = 2, and the total number of subdirectories dirs = (width^(steps+1) - 1) / (width - 1) - 1 = (2^(2+1) - 1) / (2 - 1) - 1 = 6. Therefore, the directory "dir_0_0" contains a total of 6 subdirectories, which are "dir_1_2", "dir_1_3", "dir_2_6", "dir_2_7", "dir_2_8", and "dir_2_9". Similarly, the directory "dir_0_1" also contains 6 subdirectories, which are "dir_1_4", "dir_1_5", "dir_2_10", "dir_2_11", "dir_2_12", and "dir_2_13".
[0092] In addition, if the width of the directory is 1, the total number of subdirectories of the target directory is equal to the first value steps.
[0093] In an alternative embodiment, after determining the first value according to the level of the target directory and the depth of the directory, the data filling tool determines the total number of files contained in the target directory according to the first value, the depth of the directory, and the first number of files, and obtains a unit logical space, wherein the unit logical space is used to represent the virtual space capacity occupied by one file in the distributed file system. Finally, the data filling tool determines the total logical space occupied by the target directory in the distributed file system according to the unit logical space and the total number of files.
[0094] Optionally, in order to obtain the total amount of data and the total logical space and other information, the data filling tool also needs to count the number of all files under each directory and the total logical space occupied by the directory in the distributed file system. The logical space corresponds to the physical space. For example, the physical space occupied by a file in the disk represents the actual space capacity occupied by the file in the disk, such as 1 byte, but the unit logical space does not actually exist, but is a virtual space capacity. For example, the virtual space capacity occupied by a file in the distributed file system can be defined as 1G or 2G. The unit logical space can facilitate the management personnel to manage the files in the distributed file system.
[0095] In combination with the above-mentioned first file number fcount_avg, the data filling tool can calculate the total number of files contained in a target directory according to the formula files = (width^steps)*fcount_avg, so as to obtain the total number of files contained in the target directory. Figure 2 For example, the directory "dir_0_0" in the above formula, width = 2, steps = 2, fcount_avg = 1, then files = (width^steps)*fcount_avg = files = (2^2)*1 = 4, that is, the directory "dir_0_0" contains 4 files, which are "file_3_14", "file_3_15", "file_3_16", and "file_3_17". Similarly, the directory "dir_0_1" also contains 4 files, which are "file_3_18", "file_3_19", "file_3_20", and "file_3_21".
[0096] Further, the unit logical space can be represented by file_size. After obtaining the total number of files contained in a target directory, the total logical space total_amount_space occupied by the target directory in the distributed file system can be calculated by the formula total_amount_space = files*file_size. It is easy to understand that the directory itself does not occupy logical space, only the file occupies logical space.
[0097] It should be noted that in the online mode, the prior art needs to update the statistical information of the parent directory in real time every time a directory or file is created in the distributed file system, including the number of subdirectories and files owned by the parent directory and the total logical space occupied. The deeper the directory level, the more parent directories that need to be modified, which seriously affects the filling efficiency.
[0098] In the technology of the present application, in the offline mode, the number of subdirectories and the total number of files contained in a certain directory and the total logical space occupied can be accurately known through calculation, and then the directories and files can be created in a way of layer by layer from the last layer to the upper layer, and the number of subdirectories, the total number of files and the total logical space occupied under each directory can be obtained through calculation when the directory is created, so that the directory will be updated only once, thereby improving the filling efficiency.
[0099] In an optional embodiment, when the target number of files and directories of each layer are created, the data filling tool further detects whether the distributed file system restarts, and when the distributed file system restarts and restarts successfully, the data filling tool covers the files and directories that have been created and continues to write new files and directories.
[0100] Optionally, the data filling tool in the present application has a reentrant filling function. If the online creation method of the prior art is used, when the creation of a file or a directory is interrupted and restarted, it is necessary to rejudge which file or directory should be created, and the judgment process will consume a large amount of resources and reduce the creation efficiency.
[0101] In the present application, when an mds performs offline filling, if the machine crashes, the mds can re-execute the file creation command after the machine restarts, and the mds will directly cover the files and directories that have been created, so that there will be no old directories, files or redundant directories and files in the distributed file system.
[0102] In addition, it should be noted that in the online mode, there is a master-slave relationship between multiple mds, and the master mds is responsible for receiving and processing the file system semantics request of the client. When creating a directory or a file, the prior art first needs to check whether the parent directory of the to-be-created directory and file has the permission to create the directory and file; then it checks whether there is a directory or file with the same name. The judgment logic is to check whether there is a same name directory item in the memory cache. If the memory cache does not hit, it needs to be read from the disk (database), and if the disk (database) hits, it is inserted into the memory cache. If it does not hit, it means that there is no directory or file under the directory, and the creation can be performed.
[0103] From the above, it can be seen that in order to create a directory and a file, the prior art needs to perform permission checking and disk (database) reading operation, which will seriously affect the efficiency of filling files.
[0104] In the present application, in the offline mode, the to-be-filled directory and file do not exist (in the reentry scenario, all existing files are completely overwritten, and thus can be regarded as not existing). Therefore, according to the technical solution of the present application, it is not necessary to perform the permission check and the check of whether the same-named directory and file exist, and the data filling tool can directly create the file and the directory in the database, thereby further improving the creation efficiency of the file and the directory.
[0105] In an optional embodiment, the data filling tool can support the file creation without directory, that is, depth = 0, and the file is directly created in the root directory. Meanwhile, the data filling tool also supports the working mode of creating only the directory but not the file. When the directory and the file are created, the data filling tool writes the directory and the file in the disk (database) in batches, thereby improving the filling efficiency. In addition, when a large number of directories and files are created, the data filling tool can calculate and display the creation progress information, and when the creation is completed, the total number of created directories and the total number of created files are given.
[0106] In addition, the data filling tool also records the total number of completed files and directories at each time of completing the batch writing, and the total number of to-be-filled directories and files is calculable, and the rule is as follows:
[0107] If depth = 0, it indicates that there is no directory structure, and thus the total number of directories is 0; if depth > 0 and width > 1, the total number of directories = (width^(depth+1)-1) / (width-1)-1; if depth > 0 and width = 1, the total number of directories = depth.
[0108] Further, if depth = 0, it indicates that there is no directory structure, and thus the total number of files is fcount; if depth > 0, the total number of files = (width^depth)*fcount_avg.
[0109] Therefore, by calculating and displaying the creation progress information of the directory and the file, the tester can know the creation process at any time, and thus the test efficiency of the distributed file system is improved.
[0110] Embodiment 2
[0111] According to the embodiment of the present application, a file creation device embodiment is also provided, wherein, Figure 5 is a schematic diagram of an optional file creation device according to the embodiment of the present application, as shown in Figure 5As shown, the apparatus comprises: a receiving module 501, configured to receive a file creation request through a distributed file system, wherein the file creation request is used to create a preset number of files and a directory containing the files in the distributed file system, the file creation request at least contains a directory depth, a directory width and an initial file serial number, the directory depth is used to represent the number of levels of the directory to be created, the directory width is used to represent the number of next level directories contained in each directory, and the initial file serial number is used to number the directories and the files; a determining module 502, configured to determine a target file structure according to the directory depth, the directory width and the preset number when the distributed file system is in an offline mode, wherein the target file structure is used to represent the topological relationship between the multi-level directories to be created and the target number of files to be created, and the target number is greater than or equal to the preset number; and a creating module 503, configured to create the target number of files in a database in the distributed file system according to the target file structure, and create the directories of each level in a way of starting from the last level of directory and layer by layer upwards, wherein the target number of files are located in the last level of directory, and in the process of creating each directory, the target serial number of each directory is determined according to the initial file serial number.
[0112] It should be noted that the receiving module 501, the determining module 502 and the creating module 503 correspond to steps S101-S103 in the above embodiment 1, and the three modules have the same examples and application scenarios as the corresponding steps, but are not limited to the contents disclosed in the above embodiment 1.
[0113] Optionally, the determining module further comprises a first determining unit, a second determining unit, a third determining unit and a fourth determining unit. The first determining unit is configured to determine the number of directory layers constituting the target file structure and the number of directories corresponding to each layer according to the directory depth and the directory width; the second determining unit is configured to determine that the number of directories corresponding to the last layer of directory in the target file structure is a first number; the third determining unit is configured to determine the target number of files to be created according to the size relationship between the first number and the preset number, wherein the number of files corresponding to each directory in the last layer of directory is the same; and the fourth determining unit is configured to determine the target file structure according to the number of directories corresponding to each layer, the number of directory layers and the target number.
[0114] Optionally, the third determining unit further comprises a first determining sub-unit, a first calculating sub-unit, a second calculating sub-unit and a third calculating sub-unit. The first determining sub-unit is configured to determine the first number as the target number when the first number is greater than or equal to the preset number; the first calculating sub-unit is configured to calculate a ratio of the preset number to the first number when the first number is less than the preset number; the second calculating sub-unit is configured to calculate a product of the ratio and the first number to obtain the target number when the ratio is an integer; and the third calculating sub-unit is configured to calculate a product of a target integer and the first number to obtain the target number when the ratio is a non-integer, wherein the target integer is the smallest integer greater than the ratio.
[0115] Optionally, the creating module further comprises a fifth determining unit, a sixth determining unit, a seventh determining unit and an eighth determining unit. The fifth determining unit is configured to determine a level of each directory and a position sequence of each directory in the level; the sixth determining unit is configured to determine a serial number of each directory according to the level and the position sequence; and the seventh determining unit is configured to determine a target serial number of each directory according to the serial number and an initial file serial number.
[0116] Optionally, the sixth determining unit further comprises a second determining sub-unit, a third determining sub-unit and a fourth determining sub-unit. The second determining sub-unit is configured to determine the serial number of each directory according to a directory width, the position sequence and the level when the directory width is greater than 1, wherein the directory width, the position sequence and the level are in numerical form; and the third determining sub-unit is configured to determine the serial number of each directory according to the position sequence and the level when the directory width is equal to 1.
[0117] Optionally, the file creating device further comprises a first determining module, a second determining module, a third determining module and a fourth determining module. The first determining module is configured to determine any one directory as a target directory; the second determining module is configured to determine a target serial number of a parent directory of the target directory as 1 when a level of the target directory is a first layer; the third determining module is configured to determine the target serial number of the parent directory of the target directory according to the level of the target directory, a position sequence of the target directory in the level and a first file number when the level of the target directory is a last layer, wherein the first file number is a number of files needed to be created under each directory in the last layer; and the fourth determining module is configured to determine the target serial number of the parent directory of the target directory according to a directory width, the level of the target directory and the position sequence of the target directory in the level when the level of the target directory is an intermediate layer.
[0118] Optionally, the file creation apparatus further comprises a fifth determination module, a sixth determination module and a seventh determination module. The fifth determination module is configured to determine a first value according to the level of the target directory and the directory depth, wherein the first value is used to determine the total number of subdirectories, and the total number of subdirectories is the number of all subdirectories of the target directory. The sixth determination module is configured to determine the total number of subdirectories according to the first value and the directory width when the directory width is greater than 1. The seventh determination module is configured to determine the first value as the value of the total number of subdirectories when the directory width is 1.
[0119] Optionally, the file creation apparatus further comprises an eighth determination module, an acquisition module and a ninth determination module. The eighth determination module is configured to determine the total number of files contained in the target directory according to the first value, the directory depth and the first file number. The acquisition module is configured to acquire a unit logical space, wherein the unit logical space is used to represent the virtual space capacity occupied by one file in the distributed file system. The ninth determination module is configured to determine the total logical space occupied by the target directory in the distributed file system according to the unit logical space and the total number of files.
[0120] Optionally, the file creation apparatus further comprises a detection module and an overwrite writing module. The detection module is configured to detect whether the distributed file system restarts when the target number of files and the directories of each level are created. The overwrite writing module is configured to overwrite the files and directories that have been created when the distributed file system restarts and the restart is successful, and continue to write new files and directories.
[0121] Embodiment 3
[0122] According to the embodiments of the present application, a computer readable storage medium is further provided, and the computer readable storage medium stores a computer program. The computer program is configured to execute the file creation method in the above-mentioned embodiment 1 when running.
[0123] Embodiment 4
[0124] According to the embodiments of the present application, an electronic device is further provided. The electronic device comprises one or more processors and a memory. The memory is configured to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the file creation method in the above-mentioned embodiment 1.
[0125] The above-mentioned serial numbers of the embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0126] In the above-mentioned embodiments of the present application, the descriptions of various embodiments have different focuses. The parts not described in detail in a certain embodiment can be referred to the related descriptions of other embodiments.
[0127] In several embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. Among them, the above-mentioned device embodiments are only illustrative, for example, the division of units can be a logical function division, and actual implementation can have another division mode, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or modules shown or discussed can be indirect coupling or communication connection between the units or modules through some interfaces, and can be electrical or other forms.
[0128] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or they can be distributed to multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0129] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0130] If the integrated unit is realized in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned storage medium includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0131] The above is only the preferred embodiment of the present application, and it should be pointed out that for ordinary skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, and these improvements and refinements should be considered as the protection scope of the present application.
Claims
1. A file creating method characterized by comprising: The application comprises: receiving a file creation request through a distributed file system, wherein the file creation request is used to create a preset number of files and a directory containing the files in the distributed file system, the file creation request at least contains a directory depth, a directory width and an initial file serial number, the directory depth is used to represent the number of levels of the directory to be created, the directory width is used to represent the number of next-level directories contained in each directory, and the initial file serial number is used to number the directories and files; when the distributed file system is in an offline mode, determining a target file structure according to the directory depth, the directory width and the preset number, wherein the target file structure is used to represent the topological relationship between the multi-level directories to be created and the target number of files to be created, and the target number is greater than or equal to the preset number; creating the target number of files in a database in the distributed file system according to the target file structure, and creating the directories of each level in a way of layer by layer from the last level of directory to the upper level, wherein the target number of files are located in the last level of directory, and in the process of creating each directory, the target serial number of each directory is determined according to the initial file serial number.
2. The method of claim 1, wherein, Determining a target file structure according to the directory depth, the directory width and the preset number comprises: determining the number of directory levels constituting the target file structure and the number of directories corresponding to each level according to the directory depth and the directory width; determining the number of directories corresponding to the last level of directory in the target file structure as a first number; determining the target number of files to be created according to the size relationship between the first number and the preset number, wherein the number of files corresponding to each directory in the last level of directory is the same; determining the target file structure according to the number of directories corresponding to each level, the number of directory levels and the target number.
3. The method of claim 2, wherein, Determining the target number of files to be created according to the size relationship between the first number and the preset number comprises: when the first number is greater than or equal to the preset number, determining the first number as the target number; when the first number is less than the preset number, calculating the ratio of the preset number to the first number; when the ratio is an integer, calculating the product of the ratio and the first number to obtain the target number; when the ratio is not an integer, calculating the product of a target integer and the first number to obtain the target number, wherein the target integer is the smallest integer greater than the ratio.
4. The method of claim 1, wherein, In the process of creating each directory, determining the target serial number of each directory according to the initial file serial number comprises: determining the level of each directory and the position sequence of each directory in the level; determining the serial number of each directory according to the level and the position sequence; determining the target serial number of each directory according to the serial number and the initial file serial number.
5. The method of claim 4, wherein, Determining the serial number of each directory according to the level and the position sequence comprises: When the directory width is greater than 1, determining the serial number of each directory according to the directory width, the position sequence and the current level, wherein the directory width, the position sequence and the current level are in numerical form; When the directory width is equal to 1, determining the serial number of each directory according to the position sequence and the current level.
6. The method of claim 5, wherein, The method further comprises: determining any one directory as a target directory; when the current level of the target directory is the first level, determining that the target serial number of the parent directory of the target directory is 1; when the current level of the target directory is the last level, determining the target serial number of the parent directory of the target directory according to the current level of the target directory, the position sequence of the target directory in the current level and the first file quantity, wherein the first file quantity is the number of files to be created under each directory in the last level; when the current level of the target directory is the intermediate level, determining the target serial number of the parent directory of the target directory according to the directory width, the current level of the target directory and the position sequence of the target directory in the current level.
7. The method of claim 6, wherein, After determining any one directory as a target directory, the method further comprises: determining a first value according to the current level of the target directory and the directory depth, wherein the first value is used to determine the total number of subdirectories, and the total number of subdirectories is the number of all subdirectories of the target directory; when the directory width is greater than 1, determining the total number of subdirectories according to the first value and the directory width; when the directory width is 1, determining that the first value is the value of the total number of subdirectories.
8. The method of claim 7, wherein, After determining a first value according to the current level of the target directory and the directory depth, the method further comprises: determining the total number of files contained in the target directory according to the first value, the directory depth and the first file quantity; obtaining a unit logical space, wherein the unit logical space is used to represent the virtual space capacity occupied by one file in the distributed file system; determining the total logical space occupied by the target directory in the distributed file system according to the unit logical space and the total number of files.
9. The method of claim 1, wherein, The method further comprises: when creating the target number of files and the directories of each level, detecting whether the distributed file system restarts; when the distributed file system restarts and restarts successfully, covering the files and directories that have been created, and continuing to write new files and directories.
10. A file creating apparatus characterized by comprising: comprises: a receiving module, configured to receive a file creation request through a distributed file system, wherein the file creation request is used to create a preset number of files and directories containing the files in the distributed file system, and the file creation request at least contains a directory depth, a directory width and an initial file serial number, the directory depth is used to represent the level number of directories to be created, the directory width is used to represent the number of next level directories contained in each directory, and the initial file serial number is used to number the directories and files; determining a target file structure according to the directory depth, the directory width, and the preset number when the distributed file system is in an offline mode, wherein the target file structure is used to represent a topology relationship between a plurality of directories to be created and a target number of files to be created, and the target number is greater than or equal to the preset number; creating the target number of files in a database in the distributed file system according to the target file structure, and creating each directory in a layer-by-layer manner from a last layer of directories to an upper layer, wherein the target number of files are located in the last layer of directories, and a target serial number of each directory is determined according to the initial file serial number in a process of creating each directory.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is configured to execute the file creation method in any one of claims 1 to 9 when running.
12. An electronic device, comprising: The one or more processors and the memory are used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the file creation method in any one of claims 1 to 9.
Citation Information
Patent Citations
Metadata management method and system and medium
CN109933570A
Snapshot and restoration of distributed file system
US20220019555A1