A method, apparatus, device, and storage medium for modifying the content of a shared file

By pre-locking and backing up files, threads exclusively operate the files and generate patch files, solving the problem of low file resource utilization, realizing rapid file modification and unlocking, and improving operational efficiency.

CN114138728BActive Publication Date: 2025-07-11JINAN INSPUR DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111265647.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-28
Publication Date
2025-07-11
Estimated Expiration
2041-10-28

AI Technical Summary

Technical Problem

In multi-user and multi-task operating systems, when a thread exclusively entrusts a file to write, the file enters a temporary state, and other threads need to wait when trying to read, resulting in low file resource utilization.

Method used

By pre-locking the target file and generating multiple backup files, the thread exclusively occupies one file to operate, generates patch files and updates the backup files, and achieves rapid modification and unlocking of files.

Benefits of technology

It improves the utilization rate of file resources, reduces thread waiting time, and improves the efficiency of file operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138728B_ABST
    Figure CN114138728B_ABST
Patent Text Reader

Abstract

The present invention provides a method, apparatus, device, and storage medium for modifying the content of a shared file, which includes the following steps: receiving a file access request sent by a client; wherein the access request includes a target file name and a file locking command; pre-locking the target file according to the access request, and backing up the pre-locked target file; wherein the number of backup files is the maximum value N of the number of threads arriving at the first time and the number of threads arriving at the second time plus 1; running threads lock the pre-locked target file and N backup files, and each thread operates on an exclusive file to obtain its respective processed file; finding differences in the obtained processed files to generate a patch file; updating the (N + 1)-th backup file according to the generated patch file to generate a modified shared file. After the file is locked, other threads can still access the file, increasing the utilization rate of file resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of shared file modification, and particularly relates to a method, device, equipment, and storage medium for modifying the content of a shared file. Background Art

[0002] File locking is a very important part in a multi-user and multi-task operating system. Programs often need to share data, which is usually achieved through files. When a program is performing a write operation on a file, the file enters a temporary state. In this state, if another program attempts to read the file, it will automatically stop and wait for the end of this state.

[0003] Linux programs create lock files in an atomic operation manner. When creating a lock, the system will not allow any other method to occur, which provides a way for the program to ensure that the file it creates is unique and cannot be created by other programs at the same time.

[0004] Suppose there are two threads modifying (writing) a shared file A. According to the existing content, the first-arriving thread a locks the file A and exclusively occupies the write permission of the file. The second thread b is waiting. After the first thread a finishes occupying the file and unlocks it to release the resources, the second thread b locks the shared file A and then exclusively occupies the write permission of the file. After the second thread b finishes occupying the file and unlocks it to release the resources, the task is completed. Suppose the first thread takes 5 seconds to complete the task, and the second thread b also takes 5 seconds to complete the task. It takes about 10 seconds to complete the tasks of the two threads. The utilization rate of file resources is low. Summary of the Invention

[0005] Aiming at the problem that when a thread is performing a write operation on a file, the file enters a temporary state. In this state, if another process attempts to read the file, it needs to wait for the end of this state, resulting in low utilization rate of file resources. The present invention provides a method, device, equipment, and storage medium for modifying the content of a shared file to solve the problem that after a thread exclusively occupies and locks a file, it can still be locked and used by other threads.

[0006] The technical solution of the present invention is as follows:

[0007] In a first aspect, the technical solution of the present invention provides a method for modifying the content of a shared file. Define the first arrival as the first time of arrival, and the arrival after the first-arriving thread starts running as the second time of arrival; the method includes the following steps:

[0008] Receive a file access request sent by a client; the access request includes a target file name and a file locking command;

[0009] Pre-lock the target file according to the access request, and back up the pre-locked target file; where the number of backup files is the maximum value N of the number of threads arriving at the first time and the number of threads arriving at the second time plus 1;

[0010] The running threads lock the pre-locked target file and N backup files. Each thread operates on an exclusive file to obtain its own processed file;

[0011] Find the differences in the obtained processed files to generate a patch file;

[0012] Update the (N + 1)-th backup file according to the generated patch file to generate a modified shared file.

[0013] Set an area under a certain path in the file system to store the backup files of the shared file.

[0014] Preferably, after the step of updating the (N + 1)-th backup file according to the generated patch file to generate a modified shared file, it further includes:

[0015] Delete the N + 1 backup files.

[0016] Due to security reasons, this application copies the backup of the shared file into the memory. Set an area in the memory to store the backup of the shared file. After generating the modified shared file, the memory resources occupied by the backup file need to be released.

[0017] Preferably, in the step of pre-locking the target file according to the access request and backing up the pre-locked target file, during the running of thread a, thread b arrives or threads a and b arrive simultaneously. Thread a pre-locks the target file, and the generated backup files are file I and file II;

[0018] The method includes:

[0019] Run thread a to lock the pre-locked target file, exclusively modify the target file to generate a processed file a;

[0020] Run thread b to lock backup file I, exclusively modify backup file I to generate a processed file b;

[0021] Find the differences between processed file a and processed file b to generate a patch file;

[0022] Update file II according to the patch file to generate a modified shared file.

[0023] After the thread exclusively modifies the file and finishes the operation, unlock it and release the resources.

[0024] Preferably, defining the patch file generated according to the differences between the processing file a and the processing file b to update the file II to generate the modified shared file as the first modified file; the method further includes:

[0025] During the running of thread b, thread c arrives. Cache thread c through a waiting queue.

[0026] After threads a and b finish running, run thread c to lock the first modified file exclusively and perform a modification operation on the first modified file to generate the modified shared file.

[0027] Preferably, defining the patch file generated according to the differences between the processing file a and the processing file b to update the file II to generate the modified shared file as the first modified file; the method further includes:

[0028] During the running of thread b, threads c and d arrive successively or simultaneously. Cache threads c and d through a waiting queue.

[0029] After threads a and b finish running, threads c and d process the first modified file in the same way as threads a and b process the target file, and so on for subsequent threads. The specific steps include:

[0030] Thread c pre-locks the first modified file and generates the first modified backup file I and the first modified backup file II by backing up the pre-locked first modified file.

[0031] Run thread c to lock the pre-locked first modified file exclusively and perform a modification operation on the first modified file to generate the processing file c.

[0032] Run thread d to lock the first modified backup file I exclusively and perform a modification operation on the first modified backup file I to generate the processing file d.

[0033] Find the differences between the processing file c and the processing file d to generate a patch file.

[0034] Update the first modified backup file II according to the patch file to generate the modified shared file.

[0035] Preferably, thread a pre-locks the target file and generates the backup files as file I and file II; the method further includes:

[0036] Run thread a to lock the pre-locked target file exclusively and perform a modification operation on the target file to generate the processing file a.

[0037] During the running of thread a, threads b and c arrive simultaneously. Thread b pre-locks file I, and thread c pre-locks file II and generates file III by backing up the pre-locked file I.

[0038] The running thread b locks the pre-locked file I, exclusively modifies file I, and generates the processed file Ia;

[0039] The running thread c locks the pre-locked file II, exclusively modifies file II, and generates the processed file Ic;

[0040] Find the differences between the processed file a and the processed file Ia to generate a patch file; update file III according to the patch file to generate the modified shared file I;

[0041] Find the differences between the processed file a and the processed file Ic to generate a patch file; update file III according to the patch file to generate the modified shared file II;

[0042] Find the differences between the shared file I and the shared file II to generate a patch file; update file III according to the patch file to generate the modified shared file.

[0043] In a second aspect, the technical solution of the present invention provides a device for modifying the content of a shared file. It is defined that the first arrival is the first time of arrival, and the arrival after the first-arriving thread starts running is the second time of arrival; the device includes a receiving module, a file backup module, an execution processing module, a difference processing module, and an update module;

[0044] The receiving module is used to receive the file access request sent by the client; the access request includes the target file name and the file locking command;

[0045] The file backup module is used to pre-lock the target file according to the access request and back up the pre-locked target file; the number of backup files is the maximum value N of the number of first-arriving threads and the number of second-arriving threads plus 1;

[0046] The execution processing module is used to run threads to lock the pre-locked target file and N backup files, and each thread exclusively operates on one file to obtain its respective processed file;

[0047] The difference processing module is used to find the differences between the obtained processed files to generate a patch file;

[0048] The update module is used to update the (N + 1)-th backup file according to the generated patch file to generate the modified shared file.

[0049] Preferably, the device further includes a deletion module, which is used to delete the N + 1 backup files after the update module finishes processing.

[0050] In a third aspect, the technical solution of the present invention further provides a computer device, including a processor and a memory. The processor and the memory communicate with each other through a bus. The memory stores program instructions executable by the processor, and the processor can execute the method for modifying the content of a shared file as described in the first aspect by invoking the program instructions.

[0051] In a fourth aspect, the technical solution of the present invention further provides a non-transitory computer-readable storage medium. The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions cause the computer to execute the method for modifying the content of a shared file as described in the first aspect.

[0052] As can be seen from the above technical solutions, the present invention has the following advantages: Locking the file restricts the file from being used by other threads, increasing the copy of the file, enabling the copied file to be locked and used by other threads, and updating the source file by finding different sources according to different criteria. After the file is locked, other threads can still access the file, increasing the utilization rate of file resources.

[0053] In addition, the design principle of the present invention is reliable, the structure is simple, and it has a very broad application prospect.

[0054] Thus, compared with the prior art, the present invention has prominent substantive features and significant progress, and the beneficial effects of its implementation are also obvious. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.

[0056] Figure 1 is a schematic flowchart of the method according to an embodiment of the present invention.

[0057] Figure 2 is a schematic block diagram of the device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0058] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0059] As Figure 1 shown, Embodiment 1 of the present invention provides a method for modifying the content of a shared file. It is defined that the first arrival is the first time to arrive, and the arrival after the thread that arrives at the first time starts running is the second time to arrive. The method includes the following steps:

[0060] Step 1: Receive a file access request sent by a client; the access request includes a target file name and a file locking command;

[0061] Step 2: Pre-lock the target file according to the access request, and back up the pre-locked target file; the number of backup files is the maximum value N of the number of threads that arrive at the first time and the number of threads that arrive at the second time plus 1;

[0062] Step 3: Run threads to lock the pre-locked target file and N backup files. Each thread operates on an exclusive file to obtain its own processed file;

[0063] Step 4: Search for differences in the obtained processed files to generate a patch file;

[0064] Step 5: Update the (N + 1)-th backup file according to the generated patch file to generate a modified shared file.

[0065] In some embodiments, after the step of updating the (N + 1)-th backup file according to the generated patch file to generate a modified shared file in Step 5, the method further includes:

[0066] Step 6: Delete the N + 1 backup files. Set an area at a certain path in the file system to store the backup files of the shared file.

[0067] Due to security reasons, this application copies the backup of the shared file into the memory. Set an area in the memory to store the backup of the shared file. After generating the modified shared file, the memory resources occupied by the backup files need to be released.

[0068] Embodiment 2 of the present invention provides a method for modifying the content of a shared file. During the running of thread a, thread b arrives or thread a and thread b arrive simultaneously. Thread a pre-locks the target file, and the generated backup files are File I and File II. The differences between this method and Embodiment 1 include:

[0069] Run thread a to lock the pre-locked target file and modify it exclusively to generate a processed file a;

[0070] Run thread b to lock backup file I and modify it exclusively to generate a processed file b;

[0071] Search for differences between processed file a and processed file b to generate a patch file;

[0072] Update File II according to the patch file to generate the modified shared file.

[0073] Set an area under a certain path in the file system to store the shared file, which is defined here as two backup files I and File II of the target file A; among them, File I is the file occupied by the second thread, and File II is used to save the original file. Before the thread executes the task, copy A to the specified file area. The first-arrived thread a locks file A and exclusively occupies the write permission of the file. The second-arrived thread b finds that A is already locked and immediately locks the backup file I of A and exclusively occupies the write permission of the file. The lock added by thread b to the backup file I of A is called a reservation lock. Assume that within 5 seconds when thread a is running, thread b is also modifying the file. After thread a finishes running, it unlocks and releases the resources, and then waits for thread b to finish executing. After thread b finishes writing, it unlocks and releases the resources. Now there are two processed files, Processed File a and Processed File b. In this embodiment, to find the differences between the files, use the command diff ab>diff.log. The differential file generated by diff.log is also called the patch file here. Now only need to correctly process the differences of the files to obtain the modified File A+.

[0074] If neither thread a nor thread b has made modifications, it is not in the content of diff.log; the original file shall prevail.

[0075] If thread a makes modifications and thread b does not, it is in the content of diff.log. At this time, the original file marked with a + sign shall prevail. That is, a + sign means that the latter of the compared files has one more line than the former, and a - sign means that the latter of the compared files has one less line than the former.

[0076] If thread a does not make modifications and thread b makes modifications, it is in the content of diff.log. At this time, the file marked with a - sign shall prevail.

[0077] If thread a makes modifications and thread b makes modifications, it is in the content of diff.log. At this time, the file marked with a - sign shall prevail. That is, the processed file of the later-executed thread shall prevail.

[0078] Combined with the above four judgments and the original file, the modified shared file can be obtained. In summary, the tasks of the two threads are completed in less than 10 seconds.

[0079] After the thread exclusively occupies the file and finishes the modification operation, it unlocks and releases the resources.

[0080] Embodiment 3 of the present invention provides a method for modifying the content of a shared file, defining the shared file generated by generating a modified file by updating the patch file II according to the difference between the processed file a and the processed file b in embodiment 2 as a first modified file; the method further includes:

[0081] When thread c arrives while thread b is running, it is cached in a waiting queue.

[0082] After threads a and b are finished running, thread c locks the first modified file and exclusively uses it to perform a modification operation on the first modified file to generate a shared file after the modification is completed.

[0083] Three threads quickly modify the target file. Assume that the threads are thread a, thread b, and thread c. The first ones to arrive are thread a and thread b, and the last one to arrive is thread c (thread c is waiting). At this time, the processing method is that thread a and thread b first process to obtain the first modified file, and then based on the first modified file, thread c locks the first modified file, monopolizes the write permission of the file, and obtains the modified shared file.

[0084] Embodiment 4 of the present invention provides a method for modifying the content of a shared file, defining the shared file generated by generating a modified file by updating the patch file II according to the difference between the processed file a and the processed file b in embodiment 2 as a first modified file; the method further includes:

[0085] During the running of thread b, thread c and thread d arrive successively or simultaneously, and thread c and thread d are cached in a waiting queue;

[0086] After threads a and b finish running, threads c and d process the first modified file in the same way as threads a and b process the target file, and the processing methods of subsequent threads are similar. The specific steps include:

[0087] Thread c pre-locks the first modified file, and backs up the pre-locked first modified file to generate first modified backup file I and first modified backup file II;

[0088] The running thread c locks the pre-locked first modified file and exclusively performs a modification operation on the first modified file to generate a processed file c;

[0089] Running thread d locks the first modified backup file I and exclusively performs a modification operation on the first modified backup file I to generate a processed file d;

[0090] Find the different generated patch files for processing file c and processing file d;

[0091] The first modified backup file II is updated according to the patch file to generate a modified shared file.

[0092] Four threads quickly modify a shared file. Assume the threads are thread a, thread b, thread c, and thread d. The first arrivals are thread a and thread b, and the later arrivals are thread c and thread d. At this time, the processing method is that after thread a and thread b finish processing, a first modified backup file is obtained. Then, based on the first modified backup file, thread c and thread d lock the first modified backup file of the file, and obtain the modified completed shared file in the same way as thread a and thread b process the target file to obtain the first modified backup file. And so on.

[0093] Embodiment 5 of the present invention provides a method for modifying the content of a shared file. Thread a pre-locks the target file, and the generated backup files are file I and file II; the method further includes:

[0094] Run thread a to lock the pre-locked target file exclusively and perform a modification operation on the target file to generate a processed file a;

[0095] During the running of thread a, thread b and thread c arrive simultaneously. Thread b pre-locks file I, and thread c pre-locks file II, and backs up the pre-locked file I to generate file III;

[0096] Run thread b to lock the pre-locked file I exclusively and perform a modification operation on file I to generate a processed file Ia;

[0097] Run thread c to lock the pre-locked file II exclusively and perform a modification operation on file II to generate a processed file Ic;

[0098] Find the differences between processed file a and processed file Ia to generate a patch file; update file III according to the patch file to generate the modified completed shared file I;

[0099] Find the differences between processed file a and processed file Ic to generate a patch file; update file III according to the patch file to generate the modified completed shared file II;

[0100] Find the differences between shared file I and shared file II to generate a patch file; update file III according to the patch file to generate the modified completed shared file.

[0101] In this embodiment, there are more than three threads and some threads arrive simultaneously. For example, thread a arrives first, and thread b and thread c arrive simultaneously. At this time, the number of copies of the target file needs to be increased.

[0102] As Figure 2 shown, the technical solution of the present invention provides a device for modifying the content of a shared file. It is defined that the first arrival is the first-time arrival, and the arrivals after the first-time arrival thread starts running are the second-time arrivals; the device includes a receiving module, a file backup module, an execution processing module, a difference processing module, and an update module;

[0103] A receiving module, configured to receive a file access request sent by a client; wherein the access request includes a target file name and a file locking command;

[0104] A file backup module, configured to pre-lock the target file according to the access request and back up the pre-locked target file; wherein the number of backup files is the maximum value N of the number of threads arriving at the first time and the number of threads arriving at the second time plus 1;

[0105] An execution processing module, configured to run threads to lock the pre-locked target file and N backup files, and each thread exclusively operates on one file to obtain its respective processed file;

[0106] A difference processing module, configured to find differences in the obtained processed files to generate a patch file;

[0107] An update module, configured to update the (N + 1)-th backup file according to the generated patch file to generate a modified shared file.

[0108] The device further includes a deletion module, configured to delete the N + 1 backup files after the update module finishes processing.

[0109] A computer device provided by an embodiment of the present invention may include: a processor, a communication interface, a memory, and a bus. Among them, the processor, the communication interface, and the memory communicate with each other through the bus. The bus may be used for information transmission between the electronic device and the sensor. The processor may call logic instructions in the memory to execute the following method: Step 1: Receive a file access request sent by a client; wherein the access request includes a target file name and a file locking command; Step 2: Pre-lock the target file according to the access request and back up the pre-locked target file; wherein the number of backup files is the maximum value N of the number of threads arriving at the first time and the number of threads arriving at the second time plus 1; Step 3: Run threads to lock the pre-locked target file and N backup files, and each thread exclusively operates on one file to obtain its respective processed file; Step 4: Find differences in the obtained processed files to generate a patch file; Step 5: Update the (N + 1)-th backup file according to the generated patch file to generate a modified shared file.

[0110] In addition, when the logical instructions in the above-mentioned memory can be implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, external hard drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.

[0111] An embodiment of the present invention provides a non-transitory computer-readable storage medium that stores computer instructions, and the computer instructions cause the computer to execute the method provided in the above method embodiment. For example, it includes: Step 1: Receive a file access request sent by a client; where the access request includes a target file name and a file locking command; Step 2: Pre-lock the target file according to the access request and back up the pre-locked target file; where the number of backup files is the maximum value N of the number of threads arriving at the first time and the number of threads arriving at the second time plus 1; Step 3: Run threads to lock the pre-locked target file and N backup files, and each thread exclusively operates on one file to obtain its respective processed file; Step 4: Search for differences in the obtained processed files to generate patch files; Step 5: Update the (N + 1)-th backup file according to the generated patch files to generate a modified shared file; Step 6: Delete the N + 1 backup files that have been backed up.

[0112] In some specific embodiments, the program instructions executed by the processor in the readable storage medium can specifically implement the following steps: When thread c arrives during the running of thread b, cache thread c through a waiting queue; after threads a and b finish running, run thread c to lock the first modified file and exclusively modify the first modified file to generate a modified shared file.

[0113] In some specific embodiments, the program instructions executed by the processor in the readable storage medium can specifically implement the following steps: Run thread a to lock the pre-locked target file, exclusively modify the target file, and generate processed file a; During the running of thread a, threads b and c arrive simultaneously. Thread b pre-locks file I, and thread c pre-locks file II, and generates file III by backing up the pre-locked file I; Run thread b to lock the pre-locked file I, exclusively modify file I, and generate processed file Ia; Run thread c to lock the pre-locked file II, exclusively modify file II, and generate processed file Ic; Find the differences between processed file a and processed file Ia to generate a patch file; Update file III according to the patch file to generate the modified shared file I; Find the differences between processed file a and processed file Ic to generate a patch file; Update file III according to the patch file to generate the modified shared file II; Find the differences between shared file I and shared file II to generate a patch file; Update file III according to the patch file to generate the modified shared file.

[0114] Although the present invention has been described in detail by referring to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, those of ordinary skill in the art can make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions should all be within the scope of the present invention. / Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. A method for modifying the content of a shared file, characterized in that Define the first arrival as the arrival at the first time, and the arrival after the thread that arrives at the first time starts running as the arrival at the second time; the method includes the following steps: Receive a file access request sent by a client; the access request includes a target file name and a file locking command; Pre-lock the target file according to the access request, and back up the pre-locked target file; The number of backup files is the maximum value N of the number of threads that arrive at the first time and the number of threads that arrive at the second time plus 1; The running threads lock the pre-locked target file and N backup files, and each thread operates on a file exclusively to obtain its own processed file; Find the differences in the obtained processed files to generate a patch file; Update the (N + 1)-th backup file according to the generated patch file to generate a modified shared file; In the step of pre-locking the target file according to the access request and backing up the pre-locked target file, during the running of thread a, thread b arrives or threads a and b arrive simultaneously. Thread a pre-locks the target file, and the generated backup files are file I and file II; The method includes: Run thread a to lock the pre-locked target file and modify the target file exclusively to generate a processed file a; Run thread b to lock backup file I and modify backup file I exclusively to generate a processed file b; Find the differences between processed file a and processed file b to generate a patch file; Update file II according to the patch file to generate a modified shared file.

2. The method for modifying the content of a shared file according to claim 1, wherein After the step of updating the (N + 1)-th backup file according to the generated patch file to generate a modified shared file, it further includes: Delete the N + 1 backed-up files.

3. The method for modifying the content of a shared file according to claim 1, wherein Define updating file II according to the differences between processed file a and processed file b to generate a modified shared file as the first modified file; the method further includes: During the running of thread b, thread c arrives, and cache thread c through a waiting queue; After threads a and b finish running, run thread c to lock the first modified file and modify the first modified file exclusively to generate a modified shared file.

4. The method for modifying the content of a shared file according to claim 1, wherein Define updating file II according to the differences between processed file a and processed file b to generate a modified shared file as the first modified file; the method further includes: During the running of thread b, threads c and d arrive successively or simultaneously, and cache threads c and d through a waiting queue; After threads a and b finish running, thread c pre-locks the first modified file, and back up the pre-locked first modified file to generate the first modified backup file I and the first modified backup file II; Run thread c to lock the pre-locked first modified file and modify the first modified file exclusively to generate a processed file c; Run thread d to lock the first modified backup file I and modify the first modified backup file I exclusively to generate a processed file d; Find the differences between processed file c and processed file d to generate a patch file; Update the first modified backup file II according to the patch file to generate a modified shared file.

5. The method for modifying the content of a shared file according to claim 1, wherein Thread a pre-locks the target file, and the generated backup files are file I and file II; the method further includes: The running thread a locks the pre-locked target file, exclusively modifies the target file, and generates the processed file a; During the running of thread a, threads b and c arrive simultaneously. Thread b pre-locks file I, thread c pre-locks file II, and backs up the pre-locked file I to generate file III; The running thread b locks the pre-locked file I, exclusively modifies file I, and generates the processed file Ia; The running thread c locks the pre-locked file II, exclusively modifies file II, and generates the processed file Ic; Find the differences between the processed file a and the processed file Ia to generate a patch file; update file III according to the patch file to generate the modified shared file I; Find the differences between the processed file a and the processed file Ic to generate a patch file; update file III according to the patch file to generate the modified shared file II; Find the differences between the shared file I and the shared file II to generate a patch file; update file III according to the patch file to generate the modified shared file.

6. A device for modifying the content of a shared file, characterized in that Define the first arrival as the first time of arrival, and the arrival after the first-arriving thread starts running as the second time of arrival; The device includes a receiving module, a file backup module, an execution processing module, a difference processing module, and an update module; The receiving module is used to receive the file access request sent by the client; Wherein the access request includes the target file name and the file locking command; The file backup module is used to pre-lock the target file according to the access request and back up the pre-locked target file; Wherein the number of backup files is the maximum value N of the number of first-arriving threads and the number of second-arriving threads plus 1; The execution processing module is used to run the thread to lock the pre-locked target file and N backup files, and each thread exclusively operates on one file to obtain its respective processed file; The difference processing module is used to find the differences between the obtained processed files to generate a patch file; The update module is used to update the (N + 1)th backup file according to the generated patch file to generate the modified shared file.

7. The device for modifying the content of a shared file according to claim 6, wherein The device further includes a deletion module, which is used to delete the N + 1 backup files after the update module finishes processing.

8. A computer device, characterized in that, It includes a processor and a memory. The processor and the memory communicate with each other through a bus; The memory stores program instructions executable by the processor, and the processor can execute the method for modifying the content of the shared file as described in any one of claims 1 to 5 by calling the program instructions.

9. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions cause the computer to execute the method for modifying the content of the shared file as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Multi-process file reading and writing method

    CN110825708A

  • Database access method and system based on locking limitation, terminal and storage medium

    CN113010533A