A method and device for distributing multi-process files
Through the use of atomic locks and file link set locks, the problem of data inconsistency caused by concurrent file access in a multi-process environment is solved, system stability and concurrency performance are improved, and the security and consistency of file operations are ensured.
Patent Information
- Application Number
- CN202411008524.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-07-26
AI Technical Summary
In a multi-process and multi-instruction set environment, data inconsistency or overwriting problems are prone to occur during file delivery, resulting in compromised system stability and security.
By using atomic locks and file link set locks, we control the concurrent access of multiple task processes to the same file, ensuring that only one task process can modify the shared file at any time, avoiding errors and system crashes caused by concurrent modifications.
It improves the stability and concurrency performance of the system, ensures that access to shared resources in a multi-tasking process environment is safe, orderly and efficient, and reduces the risk of errors and system crashes caused by concurrent modifications.
Smart Images

Figure CN118550890B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and in particular relates to a method and device for distributing multi-process files. Background Art
[0002] In the related art, the current configuration distribution system has been transformed from the initial single instruction issuance to a multi-instruction set batch issuance mode, which greatly improves the distribution efficiency. However, for each multiple file issuance in an instruction set in each agent node, in order to ensure the security, consistency, historical record traceability and atomicity of the file issuance, it is necessary to back up the files of each file issuance type in each instruction set in advance. If any instruction set fails to execute, the previously modified files need to be rolled back (including file content and file belonging to user group). In this case, in the process of issuing the same file in multiple processes and multiple instruction sets, there will be situations where the file is incorrectly modified or overwritten, and different processes will perform different operations on the same file, resulting in data inconsistency. Therefore, how to better implement file issuance has become a problem to be solved. Summary of the invention
[0003] In view of the above-mentioned deficiencies in the prior art, the purpose of the invention is to provide a method and device for multi-process file distribution. This method effectively controls the concurrent access of multiple task processes to the same file through the use of atomic locks and file link set locks, thereby avoiding data inconsistency or damage caused by simultaneous reading and writing of the same file.
[0004] According to a first aspect of the present invention, a method for multi-process file distribution is proposed, comprising: S1, obtaining multiple instruction sets received by multiple task processes; S2, when the same file exists in the multiple instruction sets, determining a target instruction set having the same file, wherein the target instruction set includes multiple instruction sets, and each instruction set corresponds to a task process; S3, parsing the file path of any instruction set in the target instruction set to obtain a file set, and when the atomic lock of the file set is successfully obtained, obtaining a file link set lock of the file set and other task processes do not perform locking operations on the file set; S4, when it is determined that the file link set lock of the file set is successfully obtained, releasing the atomic lock of the file set and executing the tasks in the file set, and when all tasks in the file set are completed, releasing the file link set lock of the file set; S5, when the file link set lock of the file set is released, operating other instruction sets in the target instruction set.
[0005] Furthermore, the file path of any instruction set in the target instruction set is parsed to obtain a file set, including: parsing the file path of any instruction set in the target instruction set, encrypting each of the parsed file paths to obtain the file set.
[0006] Furthermore, the method also includes: when the file set is obtained, locking the file set to obtain a unique identifier of the file set; wherein, successfully obtaining the atomic lock of the file set includes: unlocking the file set according to the unique identifier; when the unlocking is successful, determining that the atomic lock of the file set is successfully obtained.
[0007] Furthermore, the method also includes: in case of failure to obtain the atomic lock of the file set, re-obtaining the atomic lock of the file set within a preset time; if the atomic lock of the file set is not successfully obtained after the preset time, determining that the task execution has failed.
[0008] Furthermore, when the atomic lock of the file collection is successfully obtained, a file link set lock of the file collection is obtained, including: when the atomic lock of the file collection is successfully obtained, detecting whether the files in the file collection are not locked by other task processes; when it is determined that there are locked files in the file collection, waiting for other task processes to release the locks of the locked files within a preset time; when the locks of the locked files are released, the current task process locks the unlocked files to obtain the file link set lock of the file collection.
[0009] Further, determining whether the file link set lock of the file set is successfully acquired includes: judging whether the locks of all files in the file set are successfully acquired; and determining whether the file link set lock of the file set is successfully acquired if the locks of all files in the file set are successfully acquired.
[0010] Furthermore, when all tasks in the file collection are completed, the file link collection lock of the file collection is released, including: determining the tasks in the file collection that are successfully executed or failed to execute; based on the tasks that are successfully executed or failed to execute, releasing the file link collection locks of the file collection in sequence.
[0011] According to a second aspect of the present invention, a device for distributing files in multiple processes is proposed, comprising: an acquisition module for acquiring multiple instruction sets received by multiple task processes; a determination module for determining a target instruction set having the same file when the same file exists in the multiple instruction sets, wherein the target instruction set includes multiple instruction sets, each of which corresponds to a task process; an acquisition module for parsing the file path of any instruction set in the target instruction set to obtain a file set, and when the atomic lock of the file set is successfully acquired, a file link set lock of the file set is acquired, and other task processes do not perform locking operations on the file set; an execution module for releasing the atomic lock of the file set and executing the tasks in the file set when it is determined that the file link set lock of the file set is successfully acquired, and releasing the file link set lock of the file set when all tasks in the file set are executed; an operation module for operating other instruction sets in the target instruction set when the file link set lock of the file set is released.
[0012] According to a third aspect of the present invention, an electronic device is proposed, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any of the methods described in the first aspect of the present invention.
[0013] According to a fourth aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any one of the methods according to the first aspect of the present invention.
[0014] The beneficial effects of the present invention are as follows:
[0015] The method and device for multi-process file distribution described in the present invention obtain multiple instruction sets received by multiple task processes; when the same file exists in multiple instruction sets, determine the target instruction set with the same file, wherein the target instruction set includes multiple, and each instruction set corresponds to a task process; parse the file path of any instruction set in the target instruction set to obtain a file set, and when the atomic lock of the file set is successfully obtained, obtain the file link set lock of the file set and other task processes do not perform locking operations on the file set; when it is determined that the file link set lock of the file set is successfully obtained, release the atomic lock of the file set, and execute the tasks in the file set, and when all tasks in the file set are executed, release the file link set lock of the file set; when the file link set lock of the file set is released, operate on other instruction sets in the target instruction set. This method effectively controls the concurrent access of multiple task processes to the same file through the use of atomic locks and file link collection locks, avoiding data inconsistency or damage caused by reading and writing the same file at the same time. The locking mechanism ensures that only one task process can modify the shared file at any time, which reduces the risk of errors and system crashes caused by concurrent modifications, improves the stability of the system, and ensures that access to shared resources in a multi-tasking process environment is safe, orderly and efficient, thereby improving the concurrency performance and stability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0017] Figure 1 is a flowchart of a method for multi-process file distribution according to an embodiment of the present invention;
[0018] Figure 2 is a flow chart of a method for multi-process file distribution according to a specific embodiment of the present invention;
[0019] Figure 3 is a structural block diagram of a device for multi-process file distribution according to an embodiment of the present invention;
[0020] Figure 4 It is a structural block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0022] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0023] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0024] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0025] With the continuous development of CDN systems, the access of customers, and the continuous growth of user needs, the amount of configuration tasks issued is growing exponentially. For the configuration task issuance of the configuration system and other access business platforms to 3000+ nodes across the country, the current configuration distribution system has been transformed from the initial single instruction issuance to a multi-instruction set batch issuance mode, which greatly improves the distribution efficiency. However, for each multiple file issuance in each instruction set in each agent node, in order to ensure the security, consistency, historical traceability and atomicity of the file issuance, it is necessary to back up the files of each file issuance type in each instruction set in advance. If any instruction set fails to execute, the previously modified files need to be rolled back (including file content and file belonging to user group). In this case, problems will arise when multiple processes and multiple instruction sets are involved in issuing the same file (for example, instruction sets S1 and S2 both include the issuance of file f0, and processes P1 and P2 issue instruction sets S1 and S2 respectively at the same time. Before issuing instruction set P1, it backs up file f0.bak and modifies the file to f1. At this time, S2 starts to issue file f0 and backs up file f1.bak. Process P1 fails to execute and rolls back the file to f0, and then process 2 fails to execute and rolls back the file to f1 (that is, both processes fail to execute, and the file should remain unchanged in the end, but the result is the intermediate file executed by S1)). Therefore, using a single process to solve this problem will result in too low issuance efficiency, and multiple processes locking individual files in the command set will cause mutual waiting between locks, resulting in deadlock. Therefore, using multiple processes to efficiently distribute file command sets without affecting each other's execution has become an urgent problem to be solved.
[0026] To this end, the present invention proposes a method, apparatus and related equipment for multi-process file distribution. Specifically, the method, apparatus and related equipment for multi-process file distribution according to an embodiment of the present invention are described below with reference to the accompanying drawings.
[0027] Figure 1 1 is a flowchart of a method for distributing files in multiple processes according to an embodiment of the present invention. It should be noted that the method for distributing files in multiple processes according to an embodiment of the present invention can be applied to the device for distributing files in multiple processes according to an embodiment of the present invention. The device for distributing files in multiple processes can be configured on an electronic device or in a server. This embodiment of the present application does not limit this.
[0028] like Figure 1 As shown, the method for distributing files in multiple processes is characterized by comprising:
[0029] S110, obtaining multiple instruction sets received by multiple task processes.
[0030] In an embodiment of the present invention, a task process may receive an instruction set, and then may obtain multiple instruction sets received by multiple task processes.
[0031] S120, when the same file exists in multiple instruction sets, determine a target instruction set having the same file, wherein the target instruction set includes multiple instruction sets, and each instruction set corresponds to a task process.
[0032] In an embodiment of the present invention, when multiple instruction sets are obtained, it can be determined whether there are the same files in the multiple instruction sets. If there are the same files, a target instruction set with the same files can be determined from the multiple instruction sets, wherein the target instruction set includes multiple. For example, the target instruction set includes at least two instruction sets.
[0033] S130, parsing the file path of any instruction set in the target instruction set to obtain a file set, and when the atomic lock of the file set is successfully obtained, obtaining the file link set lock of the file set and other task processes do not perform locking operations on the file set.
[0034] In an embodiment of the present invention, when a target instruction set with the same file is determined from multiple instruction sets, the file path in any instruction set in the target instruction set can be parsed first to obtain a file set, and when the atomic lock of the file set is successfully obtained, the file link set lock of the file set is obtained and other task processes do not perform locking operations on the file set. The specific implementation method can be referred to the subsequent embodiments.
[0035] S140, when it is determined that the file link set lock of the file set is successfully obtained, the atomic lock of the file set is released, and the tasks in the file set are executed. When all the tasks in the file set are completed, the file link set lock of the file set is released.
[0036] In an embodiment of the present invention, when it is determined that the file link set lock of a file collection is successfully acquired, the atomic lock of the file collection is released, and the tasks in the file collection are executed to determine whether the tasks in the file collection are executed successfully or failed; based on the tasks that are executed successfully or failed, the file link set locks of the file collection are released in sequence.
[0037] S150, when the file link set lock of the file set is released, operate other instruction sets in the target instruction set.
[0038] In an embodiment of the present invention, when the file link set lock of the file set is released, other instruction sets in the target instruction set are operated, wherein the implementation method of operating other instruction sets in the target instruction set can refer to the above-mentioned operation on the instruction set. For example, the target instruction set includes a first instruction set and a second instruction set, and when the operation on the first instruction set is completed, the second instruction set is operated. The specific implementation method can refer to the subsequent embodiments.
[0039] According to the multi-process file distribution method of an embodiment of the present invention, multiple instruction sets received by multiple task processes are obtained; when the same file exists in multiple instruction sets, a target instruction set with the same file is determined, wherein the target instruction set includes multiple, and each instruction set corresponds to a task process; the file path of any instruction set in the target instruction set is parsed to obtain a file set, and when the atomic lock of the file set is successfully obtained, the file link set lock of the file set is obtained and other task processes do not perform locking operations on the file set; when it is determined that the file link set lock of the file set is successfully obtained, the atomic lock of the file set is released, and the tasks in the file set are executed, and when all tasks in the file set are executed, the file link set lock of the file set is released; when the file link set lock of the file set is released, operations are performed on other instruction sets in the target instruction set. This method effectively controls the concurrent access of multiple task processes to the same file by using atomic locks and file link set locks, avoiding data inconsistency or damage caused by reading and writing the same file at the same time. The locking mechanism ensures that only one task process can modify the shared file at any time, which reduces the risk of errors and system crashes caused by concurrent modifications, improves the stability of the system, and ensures that access to shared resources is safe, orderly and efficient in a multi-task process environment, thereby improving the concurrent performance and stability of the system. This method also solves the data inconsistency and conflict problems that may be caused by concurrent access and modification of the same file in multi-task processes.
[0040] In order to make it easier for those skilled in the art to understand the present invention, Figure 2 A method for distributing files in multiple processes according to a specific embodiment of the present invention is as follows. Figure 2 As shown, the multi-process file distribution method includes:
[0041] S210, obtaining multiple instruction sets received by multiple task processes.
[0042] In an embodiment of the present invention, a task process may receive an instruction set, and then may obtain multiple instruction sets received by multiple task processes.
[0043] The instruction set includes a computer instruction set and / or a file configuration instruction.
[0044] S220, when the same file exists in multiple instruction sets, determine a target instruction set having the same file, wherein the target instruction set includes multiple instruction sets, and each instruction set corresponds to a task process.
[0045] In an embodiment of the present invention, when multiple instruction sets are obtained, it can be determined whether there are the same files in the multiple instruction sets. If there are the same files, a target instruction set with the same files can be determined from the multiple instruction sets, wherein the target instruction set includes multiple. For example, the target instruction set includes at least two instruction sets.
[0046] S230, parsing the file path of any instruction set in the target instruction set to obtain a file set.
[0047] In an embodiment of the present invention, a file path of any instruction set in a target instruction set is parsed, and each parsed file path is encrypted to obtain a file set.
[0048] For example, when the target instruction set includes a first instruction set and a second instruction set, the file path in the first instruction set can be parsed first, and each parsed file path can be encrypted, for example, the MD5 value of each file path is calculated to obtain each encrypted file path, that is, a file set.
[0049] S240, determining whether the atomic lock of the file set is successfully acquired.
[0050] In one embodiment of the present invention, when a file set is obtained, the file set is locked to obtain a unique identifier of the file set, and then the file set is unlocked according to the unique identifier; when the unlocking is successful, it is determined that the atomic lock of the file set is successfully obtained.
[0051] S250: When the acquisition of the atomic lock of the file set fails, determine that the task execution fails.
[0052] In an embodiment of the present invention, if the atomic lock of a file set fails to be obtained, the atomic lock of the file set is re-obtained within a preset time; if the atomic lock of the file set is not successfully obtained after the preset time, it is determined that the task execution has failed.
[0053] In one embodiment of the present invention, when it is determined that a task has failed to execute, the task for which the atomic lock of a file collection has timed out is re-added to the task queue, and the task process being executed gives priority to other non-conflicting tasks, without affecting the execution of the overall task in a high-concurrency scenario.
[0054] S260: When the atomic lock of the file set is successfully obtained, a file link set lock of the file set is obtained.
[0055] In an embodiment of the present invention, when the atomic lock of a file collection is successfully obtained, it is detected whether the files in the file collection are not locked by other task processes; when it is determined that there are locked files in the file collection, within a preset time, wait for other task processes to release the locks of the locked files; when the locks of the locked files are released, the current task process locks the unlocked files to obtain the file link set lock of the file collection.
[0056] For example, there are file 1, file 2, and file 3 in a file collection, that is, 3 files. It can be determined whether file 1, file 2, and file 3 are not locked by other task processes. When it is determined that file 1 and file 2 are not locked by other task processes, and file 3 is locked by other task processes, within 10 seconds, wait for other task processes to release the lock of file 3. When the lock of file 3 is released, the current task process (that is, the task process corresponding to the current instruction set) locks file 1, file 2, and file 3 to obtain the file link set lock of the file collection.
[0057] S270: When it is determined that the file link set lock of the file set is successfully acquired, the atomic lock of the file set is released, and the task in the file set is executed.
[0058] In an embodiment of the present invention, it is determined whether the locks of all files in the file set are successfully acquired; if the locks of all files in the file set are successfully acquired, it is determined that the file link set lock of the file set is successfully acquired.
[0059] For example, traverse each file in the file collection. For each file, check whether each file has been locked by the current task process, obtain the file lock corresponding to each file, and when all file locks are successfully obtained, it can be determined that the file link set lock of the file collection is successfully obtained. For example, a Boolean variable (such as isAllLocked) can be used to record whether the locks of all files in the file collection are successfully obtained. Initially, isAllLocked is set to true. Then traverse each file in the file collection. For each file, if it is found that it is not locked by the current task process, isAllLocked is set to false. After the traversal is completed, if isAllLocked is still true, it means that the locks of all files in the file collection have been successfully obtained; otherwise, it means that the locks of all files in the file collection have not been successfully obtained.
[0060] S280: When all tasks in the file set are completed, the file link set lock of the file set is released.
[0061] In an embodiment of the present invention, tasks in a file set that are executed successfully or failed to be executed are determined; based on the tasks that are executed successfully or failed to be executed, the file link set locks of the file set are released in sequence.
[0062] That is to say, whether the task is executed successfully or failed, the file link set lock in the file set needs to be released once.
[0063] It can be seen that the atomic lock of a file set is a file link set lock that acts on the file set, and the file link set lock of a file set acts on a task.
[0064] S290, when the file link set lock in the file set is released, operate other instruction sets in the target instruction set.
[0065] That is to say, the instruction set of the current process can operate on the instruction sets of other task processes when the file link set lock of the file set is released.
[0066] For example, the target instruction set includes a first instruction set and a second instruction set, wherein the first instruction set corresponds to a first process, and the second instruction set corresponds to a second process.
[0067] Among them, the file path of the first instruction set is parsed to obtain a file set. When the atomic lock of the file set is successfully obtained, the file link set lock of the file set is obtained and other task processes do not perform locking operations on the file set. When it is determined that the file link set lock of the file set is successfully obtained, the atomic lock of the file set is released, and the tasks in the file set are executed. When all tasks in the file set are completed, the file link set lock of the file set is released.
[0068] When the file link set lock of the file collection is released, the file path of the second instruction set is parsed to obtain the file collection. When the atomic lock of the file collection is successfully acquired, the file link set lock of the file collection is acquired and other task processes do not perform locking operations on the file collection. When it is determined that the file link set lock of the file collection is successfully acquired, the atomic lock of the file collection is released, and the tasks in the file collection are executed. When all tasks in the file collection are completed, the file link set lock of the file collection is released.
[0069] In a specific embodiment of the present invention, the service node 192.xxx.xx.xxx starts multiple task processes to receive the instruction set issued by the center, wherein task process 1 receives instruction set A, and task process 2 receives instruction set B, and the two processes are executed in parallel. When it is detected that the / etc / server1.conf file and the / etc / server2.conf file exist in both instruction set A and instruction set B, task process 1 and task process 2 cannot operate on the files at the same time, therefore, task process 1 operates on the files first, and when task process 1 completes the file operation, task process 2 operates on the files.
[0070] Among them, the implementation method of task process 1 to operate the file first is: instruction set A includes: / etc / server1.conf file and / etc / server2.conf file. The file path in instruction set A is parsed, and each parsed file path is encrypted to obtain a file set, and then the file set is locked to obtain a unique identifier of the file set, that is, the first key, and the file set is unlocked according to the first key. If the unlocking is successful, it can be determined that the atomic lock of the file set is successfully obtained.
[0071] When the atomic lock of the file collection is successfully obtained, check whether the files in the file collection are not locked by other task processes; when it is determined that there are locked files in the file collection, wait for other task processes to release the locks of the locked files within a preset time; when the locks of the locked files are released, the current task process locks the unlocked files to obtain the file link set lock of the file collection.
[0072] When it is determined that the file link set lock of the file set is successfully obtained, the atomic lock of the file set is released, and the tasks in the file set are executed. When all the tasks in the file set are completed, the file link set lock of the file set is released.
[0073] Among them, when the file link set lock of the file set is released, task process 2 operates on the file. The implementation method of task process 2 operating on the file is: instruction set B includes: / etc / server1.conf file and / etc / server2.conf file. The file path in instruction set B is parsed, each parsed file path is encrypted to obtain a file set, and then the file set is locked to obtain a unique identifier of the file set, that is, the second key, and the file set is unlocked according to the second key. If the unlocking is successful, it can be determined that the atomic lock of the file set is successfully obtained.
[0074] When the atomic lock of the file collection is successfully obtained, check whether the files in the file collection are not locked by other task processes; when it is determined that there are locked files in the file collection, wait for other task processes to release the locks of the locked files within a preset time; when the locks of the locked files are released, the current task process locks the unlocked files to obtain the file link set lock of the file collection.
[0075] When it is determined that the file link set lock of the file set is successfully obtained, the atomic lock of the file set is released, and the tasks in the file set are executed. When all the tasks in the file set are completed, the file link set lock of the file set is released.
[0076] According to the multi-process file distribution method of the embodiment of the present invention, the concurrent access of multiple task processes to the same file is effectively controlled by using atomic locks and file link set locks, thereby avoiding data inconsistency or damage caused by reading and writing the same file at the same time; the locking mechanism ensures that only one task process can modify the shared file at any time, which reduces the risk of errors and system crashes caused by concurrent modifications and improves the stability of the system; based on the locking mechanism, by ensuring the atomicity and consistency of file operations, the additional overhead caused by error handling and recovery operations can be reduced, thereby improving the overall execution efficiency; and the locking mechanism can localize error handling and simplify the error recovery process; the locking mechanism can ensure that even if there are multiple tasks, The task processes involve the same files and can be executed in a predetermined order to maintain data integrity and consistency; by reasonably managing the acquisition and release of locks, system resources can be used more effectively and resource waste caused by waiting for locks can be reduced; by ensuring that tasks are executed only after the necessary locks are acquired, it is guaranteed that tasks can be executed in a safe environment, and whether they succeed or fail, the locks can be released correctly to avoid deadlock and resource leakage; the design of the lock mechanism of the present invention allows the system to support more task processes and more complex operations without sacrificing data consistency, thereby improving the scalability of the system, and through the lock mechanism, various problems caused by resource competition, such as data loss, erroneous results, etc., can be avoided, ensuring the accuracy of data processing.
[0077] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0078] According to one aspect of an embodiment of the present invention, a device for distributing files in multiple processes is also provided. Figure 3 is a structural block diagram of a device for multi-process file distribution according to an embodiment of the present invention; Figure 3 As shown, including:
[0079] An acquisition module 310 is used to acquire multiple instruction sets received by multiple task processes;
[0080] A determination module 320 is configured to determine a target instruction set having the same file when the same file exists in the plurality of instruction sets, wherein the target instruction set includes a plurality of instruction sets, each of which corresponds to a task process;
[0081] Obtaining module 330, for parsing the file path of any instruction set in the target instruction set to obtain a file set, and in the case of successfully obtaining the atomic lock of the file set, obtaining the file link set lock of the file set and other task processes do not perform a locking operation on the file set;
[0082] The execution module 340 is used to release the atomic lock of the file set and execute the tasks in the file set when it is determined that the file link set lock of the file set is successfully acquired, and release the file link set lock of the file set when all the tasks in the file set are executed.
[0083] The operation module 350 is used to operate other instruction sets in the target instruction set when the file link set lock of the file set is released.
[0084] According to the multi-process file distribution device of the embodiment of the present invention, multiple instruction sets received by multiple task processes are obtained; when the same file exists in multiple instruction sets, a target instruction set with the same file is determined, wherein the target instruction set includes multiple, and each instruction set corresponds to a task process; the file path of any instruction set in the target instruction set is parsed to obtain a file set, and when the atomic lock of the file set is successfully obtained, the file link set lock of the file set is obtained and other task processes do not perform locking operations on the file set; when it is determined that the file link set lock of the file set is successfully obtained, the atomic lock of the file set is released, and the tasks in the file set are executed, and when all tasks in the file set are executed, the file link set lock of the file set is released; when the file link set lock of the file set is released, operations are performed on other instruction sets in the target instruction set. Thus, through the use of atomic locks and file link set locks, the concurrent access of multiple task processes to the same file is effectively controlled, avoiding data inconsistency or damage caused by reading and writing the same file at the same time. The locking mechanism ensures that only one task process can modify the shared file at any time, which reduces the risk of errors and system crashes caused by concurrent modifications, improves the stability of the system, and ensures that access to shared resources is safe, orderly and efficient in a multi-task process environment, thereby improving the concurrent performance and stability of the system. And this method solves the data inconsistency and conflict problems that may be caused by concurrent access and modification of the same file in multi-task processes.
[0085] Optionally, a module 330 is obtained, which is specifically used to parse the file path of any instruction set in the target instruction set, encrypt each of the parsed file paths, and obtain the file set.
[0086] Optionally, a locking module is also included, which is used to lock the file set when the file set is obtained, and obtain the unique identifier of the file set; wherein the obtaining module 330 is specifically used to unlock the file set according to the unique identifier; when the unlocking is successful, it is determined that the atomic lock of the file set is successfully obtained.
[0087] Optionally, it also includes a module for determining task execution failure, and the module for determining task execution failure is used to reacquire the atomic lock of the file collection within a preset time when the atomic lock of the file collection fails to be acquired; if the atomic lock of the file collection is not successfully acquired within the preset time, determine that the task execution has failed.
[0088] Optionally, a module 330 is obtained, which is specifically used to detect whether the files in the file collection are not locked by other task processes when the atomic lock of the file collection is successfully obtained; when it is determined that there are locked files in the file collection, wait for other task processes to release the locks of the locked files within a preset time; when the locks of the locked files are released, the current task process locks the unlocked files to obtain the file link set lock of the file collection.
[0089] Optionally, the execution module 340 is specifically configured to determine whether the locks of all files in the file set are successfully acquired; if the locks of all files in the file set are successfully acquired, determine that the file link set lock of the file set is successfully acquired.
[0090] Optionally, the execution module 340 is specifically configured to determine the tasks in the file set that are executed successfully or failed to be executed; and based on the tasks that are executed successfully or failed to be executed, release the file link set locks of the file set in sequence.
[0091] According to one aspect of an embodiment of the present invention, an electronic device is provided.
[0092] Figure 4 Schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Figure 4 As shown, the electronic device may include one or more ( Figure 4 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a microprocessor (Microprocessor Unit, referred to as MPU) or a programmable logic device (Programmable logic device, referred to as PLD)) and a memory 104 for storing data. In an exemplary embodiment, the electronic device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only and does not limit the structure of the above terminal device. Figure 4 More or fewer components as shown, or with Figure 4 Equivalent functions or comparisons shown Figure 4 A different configuration with more features is shown.
[0093] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for multi-process file distribution in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0094] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the switching device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0095] The present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute a multi-process file distribution method.
[0096] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation schemes of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, but not to limit the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.
[0097] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0098] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present invention have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present invention. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present invention.
[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.
Claims
1. A method for distributing files in multiple processes, characterized in that: include: S1, obtaining multiple instruction sets received by multiple task processes; S2, when the same file exists in the multiple instruction sets, determining a target instruction set having the same file, wherein the target instruction set includes multiple instruction sets, each instruction set corresponding to a task process; S3, parsing the file path of any instruction set in the target instruction set to obtain a file set, and if the atomic lock of the file set is successfully obtained, obtaining the file link set lock of the file set and other task processes do not perform a locking operation on the file set; S4, when it is determined that the file link set lock of the file set is successfully acquired, the atomic lock of the file set is released, and the tasks in the file set are executed. When all the tasks in the file set are completed, the file link set lock of the file set is released; S5, when the file link set lock of the file set is released, operate other instruction sets in the target instruction set.
2. The method for distributing multi-process files according to claim 1, characterized in that: Parse the file path of any instruction set in the target instruction set to obtain a file set, including: Parse the file path of any instruction set in the target instruction set, Each of the parsed file paths is encrypted to obtain the file set.
3. The method for distributing multi-process files according to claim 1, characterized in that: The method further comprises: When the file set is obtained, the file set is locked to obtain a unique identifier of the file set; The process of successfully acquiring the atomic lock of the file set includes: Unlocking the file set according to the unique identifier; When the unlocking is successful, it is determined that the atomic lock of the file set is acquired successfully.
4. The method for distributing multi-process files according to claim 3, characterized in that: The method further comprises: In case of failure to obtain the atomic lock of the file set, re-obtaining the atomic lock of the file set within a preset time; If the atomic lock of the file set is not successfully acquired within the preset time, it is determined that the task execution has failed.
5. The method for distributing multi-process files according to claim 1, characterized in that: In the case where the atomic lock of the file set is successfully obtained, obtaining the file link set lock of the file set includes: In the case where the atomic lock of the file set is successfully obtained, detecting whether all files in the file set are not locked by other task processes; When it is determined that there is a locked file in the file set, waiting for other task processes to release the lock of the locked file within a preset time; When the lock of the locked file is released, the current task process locks the unlocked file to obtain the file link set lock of the file set.
6. The method for distributing multi-process files according to claim 1, characterized in that: Determining that the file link set lock of the file set is successfully acquired includes: Determine whether locks of all files in the file set are acquired successfully; In the case that the locks of all files in the file set are acquired successfully, it is determined that the file link set locks of the file set are acquired successfully.
7. The method for distributing multi-process files according to claim 1, characterized in that: When all tasks in the file set are completed, the file link set lock of the file set is released, including: Determine the tasks in the file set that are executed successfully or failed; Based on the tasks that are successfully executed or failed to execute, the file link set locks of the file set are released in sequence.
8. A device for distributing files in multiple processes, characterized in that: include: An acquisition module, used for acquiring multiple instruction sets received by multiple task processes; A determination module, configured to determine a target instruction set having the same file when the same file exists in the plurality of instruction sets, wherein the target instruction set includes a plurality of instruction sets, each instruction set corresponding to a task process; A obtaining module, used for parsing the file path of any instruction set in the target instruction set to obtain a file set, and when the atomic lock of the file set is successfully obtained, obtaining the file link set lock of the file set and other task processes do not perform a locking operation on the file set; An execution module, configured to release the atomic lock of the file set and execute the tasks in the file set when it is determined that the file link set lock of the file set is successfully acquired, and release the file link set lock of the file set when all the tasks in the file set are executed; The operation module is used to operate other instruction sets in the target instruction set when the file link set lock of the file set is released.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 7.
