CN114968963A - File overwriting method and device and electronic equipment - Google Patents

File overwriting method and device and electronic equipment Download PDF

Info

Publication number
CN114968963A
CN114968963A CN202110194994.5A CN202110194994A CN114968963A CN 114968963 A CN114968963 A CN 114968963A CN 202110194994 A CN202110194994 A CN 202110194994A CN 114968963 A CN114968963 A CN 114968963A
Authority
CN
China
Prior art keywords
overwriting
file
overwrite
content
target file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110194994.5A
Other languages
Chinese (zh)
Inventor
黎海兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202110194994.5A priority Critical patent/CN114968963A/en
Publication of CN114968963A publication Critical patent/CN114968963A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/162Delete operations

Abstract

The invention provides a method and a device for overwriting a file and electronic equipment, wherein the method comprises the following steps: acquiring an overwriting instruction; the overwrite write instruction includes at least: the method comprises the steps that a file identifier of a target file needing to be overwritten, a storage position identifier of overwriting content and an overwriting position are obtained; and according to the overwriting instruction, writing the overwriting content into the overwriting position in the target file. According to the method, based on the data contained in the overwriting instruction, the overwriting content is written into the target file at the storage position of the target file to be overwritten, and the target file does not need to be overwritten after being read out from the storage position, so that the data volume of reading and writing data is reduced, and the overwriting performance is improved.

Description

File overwriting method and device and electronic equipment
Technical Field
The invention relates to the technical field of file storage, in particular to a method and a device for overwriting a file and electronic equipment.
Background
In the related art, the writing mode of the distributed file system to the file usually only supports the additional writing and does not support the overwriting. In order to overwrite files in the distributed file system, a user is generally required to read files to be overwritten from the distributed file system through terminal equipment, merge the files to be overwritten with preset overwriting contents in the terminal equipment, write the merged files into the distributed file system, and delete original files corresponding to the files to be overwritten in the distributed file system, so as to complete overwriting of the files to be overwritten. However, when the method overwrites a file, the file in the distributed file system needs to be read to the local terminal device for file merging, and the local merged file needs to be written into the distributed file system again, which causes large data volume of both read data and write data and affects the overwrite performance.
Disclosure of Invention
The invention aims to provide a method and a device for overwriting a file and electronic equipment, so as to reduce the data volume of reading data and writing data when overwriting the file and improve the overwriting performance.
In a first aspect, an embodiment of the present invention provides a file overwriting method, where the method includes: acquiring an overwriting instruction; wherein the overwrite command comprises at least: the method comprises the steps that a file identifier of a target file needing to be overwritten, a storage position identifier of overwriting content and an overwriting position are obtained; and according to the overwriting instruction, writing the overwriting content into the overwriting position in the target file.
In an alternative embodiment, the overwrite location comprises: an overwrite start address and an overwrite length; wherein the overwrite length is the same as the overwrite length; the step of writing the overwrite content to the overwrite location in the target file according to the overwrite command includes: determining the target file and the overwriting content according to the file identifier of the target file and the storage position identifier of the overwriting content; and replacing the content of the overwriting length in the target file with the overwriting content from the overwriting starting address in the target file.
In an alternative embodiment, the overwrite command is stored in a designated database; the step of obtaining the overwrite command includes: judging whether an overwriting instruction exists in the specified database; if so, the overwrite write instruction is fetched.
In an optional embodiment, the target file to be overwritten is stored in a preset distributed file system; the overwrite command in the specified database is obtained by: if an overwriting request sent by a user is received, extracting overwriting content, an overwriting position and a file identifier of a target file needing to be overwritten from the overwriting request; writing the overlay writing content into a distributed file system to obtain a storage position identifier of the overlay writing content; splicing the file identification of the target file, the storage position identification of the overwriting content and the overwriting position to obtain an overwriting instruction of the target file; the overwrite write instruction is saved to a specified database.
In an optional implementation manner, after the step of writing the overwrite content to the overwrite location in the target file according to the overwrite command, the method further includes: and deleting the overwriting instruction, and identifying the overwriting content in the corresponding file by the storage position.
In an optional embodiment, the method further comprises: receiving a reading request of a target file sent by a user; judging whether an overwriting instruction of a target file exists in a specified database or not; if the target file exists, according to the overwriting instruction of the target file, the overwriting content and the target file corresponding to the overwriting instruction are read from the distributed file system, the overwriting content and the target file are combined, and the combined target file is returned to the user; and if the target file does not exist, reading the target file from the distributed file system, and returning the read target file to the user.
In an optional embodiment, the distributed file system stores an overwrite version number of the target file; after the step of writing the overwriting content into the distributed file system to obtain the storage location identifier of the overwriting content, the method further includes: receiving an overwrite version number of a target file returned by the distributed file system; writing the overwrite version number into an overwrite command; after the step of writing the overwrite content to the overwrite location in the target file according to the overwrite command, the method further includes: and updating the overwrite version number in the distributed file system into the sum of the overwrite version number in the overwrite instruction and one.
In an alternative embodiment, the target file includes a plurality of copy files; according to the overwriting instruction, the step of writing the overwriting content into the overwriting position in the target file comprises the following steps: and aiming at each copy file of the target file, writing the overwriting content into the overwriting position in the current copy file according to the overwriting instruction.
In an optional embodiment, the method further comprises: judging whether the overwriting content is successfully written into an overwriting position in the current copy file or not aiming at each copy file of the target file; and if the writing is not successful, automatically repairing the current copy file, and rewriting the overwriting content into the current copy file until the current copy file is successfully overwritten.
In a second aspect, an embodiment of the present invention provides a file overwriting apparatus, where the apparatus includes: the instruction acquisition module is used for acquiring an overwriting instruction; wherein the overwrite command comprises at least: the method comprises the steps that a file identifier of a target file needing to be overwritten, a storage position identifier of overwriting content and an overwriting position are obtained; and the overwriting module is used for writing the overwriting content into the overwriting position in the target file according to the overwriting instruction.
In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory, where the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the file overwriting writing method described in any one of the foregoing implementation manners.
In a fourth aspect, embodiments of the invention provide a machine-readable storage medium storing machine-executable instructions that, when invoked and executed by a processor, cause the processor to implement a file overwrite method as described in any one of the preceding embodiments.
The embodiment of the invention has the following beneficial effects:
the invention provides a method, a device and electronic equipment for overwriting a file, which are characterized in that firstly, an overwriting instruction is obtained; the overwriting instruction at least comprises a file identifier of a target file to be overwritten, a storage position identifier of overwriting content and an overwriting position; and then writing the overwriting content into the overwriting position in the target file according to the overwriting instruction. According to the method, based on the data contained in the overwriting instruction, the overwriting content is written into the target file at the storage position of the target file to be overwritten, and the target file does not need to be overwritten after being read out from the storage position, so that the data volume of reading and writing data is reduced, and the overwriting performance is improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the invention as set forth above.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
FIG. 1 is a flowchart of a file overwriting method according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method for overwriting a file according to an embodiment of the present invention;
FIG. 3 is a flowchart of another method for overwriting a file according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a file overwrite provided by an embodiment of the present invention;
FIG. 5 is a schematic structural diagram of a document overwriting apparatus according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Distributed File System (DFS) generally means that physical storage resources managed by a File System are not necessarily directly connected to a local node, but are connected to a node (which may be simply understood as a computer) through a computer network; or a complete hierarchical file system formed by combining several different logical disk partitions or volume labels. For example, a Distributed file system HDFS (Hadoop Distributed file system) with a directory tree, where files on the HDFS are horizontally cut into data blocks of a fixed length for storage; the distributed file system can store files uploaded by users, and can also provide corresponding file system operations for the users, such as volume operations, directory operations, file operations (file creation, file content uploading, file reading, file deletion, and the like), and the like.
The current writing mode of the distributed file system to the file usually only supports additional writing and does not support overwriting. In order to overwrite files in the distributed file system, it is usually necessary to read a file to be overwritten from the distributed file system through a terminal device, merge the file to be overwritten with preset overwrite content in the terminal device (which is equivalent to local), write the merged file into the distributed file system, and delete an original file corresponding to the file to be overwritten in the distributed file system. Because the method needs to perform multiple read/write operations on the file from the distributed file system, the data volume of reading data and writing data is large, and the overwrite performance is influenced.
For example, an original file in the distributed file system is 1GB, the overwriting content is 1MB, when the original file is overwritten, the original file of 1GB needs to be read from the distributed file system, the overwriting content of 1MB is overwritten on the terminal device at a corresponding position in the original file of 1GB, then the combined 1GB file is written into the distributed file system, and the original file of 1GB in the distributed file system is deleted.
Based on the above problems, embodiments of the present invention provide a method and an apparatus for overwriting a file, and an electronic device. In order to facilitate understanding of the embodiment of the present invention, a detailed description is first made of a file overwriting method disclosed in the embodiment of the present invention, as shown in fig. 1, the method includes the following steps:
step S102, acquiring an overwriting instruction; the overwrite write instruction includes at least: the file identification of the target file needing to be overwritten, the storage location identification of the overwriting content and the overwriting location.
The overwriting instruction can be data stored in a preset database or a storage system, and the data generally has instruction attributes; the overwriting instruction may also be an instruction sent by a user through a terminal device, where the terminal device may be a mobile terminal (e.g., a mobile phone, a tablet computer, etc.), or may be a computer. The overwriting instruction may include a file identifier of a target file that needs to be overwritten, a storage location identifier of the overwriting content, and an overwriting location, and may also include other contents, which are not listed herein one by one.
In a specific implementation, the target file to be overwritten is usually stored in a distributed file system, and the file identifier of the target file may be a file name of the target file or another code for uniquely identifying the file; the overwriting content may be content that a user wants to overwrite, where the overwriting content may be a content that the user uploads to the distributed file system in advance, and the storage location identifier of the overwriting content is also a file identifier corresponding to a storage location of the overwriting content in the distributed file system, for example, the user uploads the overwriting content, and the server receives the overwriting content and then automatically writes the overwriting content as a temporary file into the distributed file system, where the storage location identifier of the overwriting content is a file identifier of the temporary file. The overwrite location may also be understood as a location where the user wants to write the overwrite content in the target file, and the overwrite location may be a certain location in the target file, a certain segment range, or the like.
And step S104, writing the overwriting content into the overwriting position in the target file according to the overwriting instruction.
The target file and the overwrite content can be determined according to the file representation of the target file and the storage location identification of the overwrite content included in the overwrite command, for example, when the target file and the overwrite content are stored in the distributed file system, the target file and the overwrite content are determined from the distributed file system according to the file identification of the target file and the storage location identification of the overwrite content. When the target file is subjected to overwriting, firstly, an overwriting position is inquired in the target file, and then overwriting contents are written in the inquired overwriting position.
In a specific implementation, after the overwriting operation indicated by the overwriting instruction is completed, the overwriting instruction and the overwriting content at the storage location identifier in the overwriting instruction may be deleted, thereby completing the overwriting on the target file.
The embodiment of the invention provides a file overwriting method, which comprises the steps of firstly obtaining an overwriting instruction; the overwriting instruction at least comprises a file identifier of a target file to be overwritten, a storage position identifier of overwriting content and an overwriting position; and then writing the overwriting content into the overwriting position in the target file according to the overwriting instruction. According to the method, based on the data contained in the overwriting instruction, the overwriting content is written into the target file at the storage position of the target file to be overwritten, and the target file does not need to be overwritten after being read out from the storage position, so that the data volume of reading and writing data is reduced, and the overwriting performance is improved.
The embodiment of the invention also provides another file overwriting method, which is realized on the basis of the method of the embodiment; the method mainly describes a specific process of writing the overwriting content into an overwriting position in a target file according to an overwriting instruction (which is realized by the following steps S204-S206); as shown in fig. 2, the method comprises the steps of:
step S202, acquiring an overwriting instruction; the overwrite write instruction includes at least: the method comprises the steps that a file identifier of a target file needing to be overwritten, a storage position identifier of overwriting content and an overwriting position are obtained; wherein the overwrite location comprises: an overwrite write start address and an overwrite write length.
The overwrite start address may be an address in the target file entered by the user. Since a file in a distributed file system is usually stored by being horizontally divided into a plurality of data blocks of fixed length, the overwrite starting address may be a certain position on a certain data block corresponding to the target file. The length of the overwriting can be a length value input by a user, and the length value is the same as the length of the overwriting content written by the user; or a length value calculated according to the length of the overwriting content input by the user. In a specific implementation, when the user uploads the overwrite content, the system stores the overwrite content in a specified location (corresponding to the storage location) in the distributed file system, so as to be used for overwriting the target file in the distributed file system.
And step S204, determining the target file and the overwriting content according to the file identifier of the target file and the storage position identifier of the overwriting content.
In a specific implementation, since the overwriting content is stored in the storage location of the distributed file system in advance, the target file and the overwriting content can be determined from the distributed file system according to the file identifier of the target file and the storage location identifier of the overwriting content in the overwriting instruction.
In step S206, the content of the overwrite length in the target file is replaced with the overwrite content, starting from the overwrite starting address in the target file.
According to the overwriting starting address contained in the overwriting instruction, the position corresponding to the overwriting starting address is determined from the target file, the overwriting content is written into the target file from the position, the writing length of the overwriting content in the target file is the same as the overwriting length indicated in the overwriting instruction, therefore, the target file can be overwritten in the distributed file system according to the user requirement, and the problems of reading the target file and amplifying the reading data and the writing data of overwriting in local are avoided.
And step S208, deleting the overwriting instruction and the overwriting content in the file corresponding to the storage position identification so as to complete the overwriting of the target file.
And when the content of the overwriting length in the target file is replaced by the overwriting content, deleting the overwriting instruction executed this time, and deleting the overwriting content in the file corresponding to the storage position identifier, thereby completing the overwriting of the target file indicated by the overwriting instruction this time.
According to the file overwriting method, an overwriting instruction is obtained firstly, and then a target file and the overwriting content are determined according to a file identifier of the target file and a storage position identifier of the overwriting content indicated in the overwriting instruction; then, from the overwriting start address in the target file, replacing the content of the overwriting length in the target file with the overwriting content; and deleting the overwriting command and the overwriting content in the file corresponding to the storage position identifier so as to complete overwriting of the target file. According to the method, the overwriting content is overwritten into the target file at the storage position of the target file needing overwriting according to the overwriting instruction, the target file is not required to be read completely, and the overwriting content is merged with the overwriting content locally and then written back to the storage position of the target file, so that the overwriting performance is greatly improved, and the overwriting efficiency is also improved.
The embodiment of the invention also provides another file overwriting method which is realized on the basis of the method of the embodiment; the method mainly describes a specific process of acquiring the overwriting instruction when the overwriting instruction is stored in a specified database and a target file which needs to be overwritten is stored in a preset distributed file system (realized by the following steps S310-S312); as shown in fig. 3, the method comprises the steps of:
step S302, if an overwriting request sent by a user is received, overwriting contents, an overwriting position and a file identification of a target file needing to be overwritten are extracted from the overwriting request.
In specific implementation, if a user wants to overwrite a certain file stored in the distributed file system, the user may send an overwrite request through the terminal device, where the overwrite request usually carries overwrite content, overwrite location, and a file identifier (or a file name) of a target file that needs to be overwritten, which are input by the user.
And step S304, writing the overwriting content into a distributed file system to obtain a storage position identifier of the overwriting content.
When the overwriting content is extracted, writing the overwriting content into the distributed file system in the form of a temporary file to obtain a storage location identifier of the overwriting content, wherein the storage location identifier is also a file identifier of the temporary file storing the overwriting content in the distributed file system, and the file identifier can be a file name.
In some embodiments, the distributed file system stores an overwrite version number of the target file; writing the overwriting content into the distributed file system, and returning the overwriting version of the stored target file by the distributed file system after obtaining the storage position identification of the overwriting content; and then the system receives the overwrite version number of the target file returned by the distributed file system and writes the overwrite version number into an overwrite instruction.
And S306, splicing the file identifier of the target file, the storage position identifier of the overwriting content and the overwriting position to obtain an overwriting instruction of the target file.
And splicing the file identifier of the target file, the storage position identifier of the overwriting content and the overwriting position to generate an overwriting instruction of the target file, wherein the overwriting instruction can also be called an overwriting record. In some embodiments, if the overwrite version number of the target file returned by the distributed file system is received, the file identifier of the target file, the storage location identifier of the overwrite content, the overwrite location, and the overwrite version number of the target file may be spliced to generate an overwrite command.
Step S308, the overwriting instruction is saved in a designated database.
Each overlay write request sent by the user can correspond to an overlay write instruction. In a specific implementation, multiple overwriting requests sent by multiple users may be received, that is, multiple overwriting instructions are obtained, for sequentially processing the overwriting instructions in the following, the overwriting instructions may be stored in a specified database according to a preset rule, where the preset rule may be according to a generation order of the overwriting instructions, a receiving order of the received overwriting requests, and the like.
Step S310, whether an overwriting instruction exists in the designated database or not is monitored in real time.
Through the preset service, the data in the designated database can be continuously scanned so as to achieve the purpose of monitoring the data in the designated database in real time, and therefore when the designated database contains the covering and writing instructions, the covering and writing instructions in the designated database can be processed one by one.
Step S312; if so, the overwrite command is fetched.
In step S314, the overwrite content is written in the overwrite location in the target file according to the overwrite command.
If the overwriting instruction exists in the designated database, the overwriting instruction is read one by one, and step S314 is executed for each overwriting instruction, that is, the following processing is performed for each overwriting instruction: reading the overwriting content from the distributed file system according to the storage position identifier of the overwriting content contained in the overwriting instruction, calling a preset interface of the distributed file system, overwriting the overwriting content to the overwriting position of the target file, and deleting the overwriting content at the storage position corresponding to the current overwriting instruction and the storage position identifier (which can also be understood as deleting a temporary file for storing the overwriting content).
In specific implementation, if the overwrite command includes an overwrite version number of the target file, after the overwrite content is written into an overwrite position in the target file according to the overwrite command, the overwrite version number in the distributed file system is updated to be the sum of the overwrite version number in the overwrite command and one. The method can also be understood as that after the overwrite content is written into the target file, the overwrite version number of the target file stored in the distributed target file is increased by one, so that any overwrite of the same file can be identified by the unique and strictly increasing overwrite version number, and meanwhile, the overwrite times of the target file can be determined according to the overwrite version number, so that subsequent use and query of a user are facilitated.
In a specific implementation, since files in the distributed file system are stored in multiple copies (e.g., 3 copies), the target file includes multiple copy files, that is, multiple copy files in the distributed file system that store the target file; when the target file is overwritten, the overwriting content needs to be written into the overwriting position in the current copy file according to the overwriting instruction for each copy file of the target file; the method can also be understood as overwriting the overwriting content in all the copy files corresponding to the target file, thereby ensuring the consistency of data between copies.
In order to ensure that each duplicate file of the target file is completely overwritten, during specific implementation, whether the overwriting content is successfully written into the overwriting position in the current duplicate file needs to be judged for each duplicate file of the target file; and if the writing is not successful, automatically repairing the current copy file, and rewriting the overwriting content into the current copy file until the current copy file is successfully overwritten.
For example, the distributed file system includes 3 copy files of the target file, and when the target file is overwritten, the 3 copy files are overwritten concurrently, so that all the copy files are overwritten successfully. If a copy file fails to be overwritten due to the failure and damage of a disk or a machine, the system monitors the situation, automatically removes the disk or the machine from the cluster, automatically restores a 3 rd copy file according to the rest 2 copy files, and then continuously overwrites the overwrite content to the restored copy file until the overwrite of all the 3 copy files is successful.
To facilitate understanding of embodiments of the present invention, fig. 4 is a schematic diagram of a file overwrite; the storage gateway in fig. 4 is used to receive an overwrite request sent by a user, and the storage gateway is based on a distributed file service on a distributed file system, and may exist in a form of a Hyper Text Transfer Protocol (HTTP) interface, and may provide a file storage service for multiple users, and may also provide functions such as multi-user data isolation and permission verification; after receiving an overwrite request sent by a user, a storage gateway extracts overwrite content in the overwrite request, a file identifier and an overwrite position of a target file to be overwritten, writes the overwrite content into a distributed file system as a temporary file, returns an overwrite version number to the storage gateway after the distributed file system receives the temporary file, and then the storage gateway can splice the file identifier, the overwrite position, the storage position identifier and the overwrite version number of the overwrite content of the target file to obtain an overwrite instruction, and stores the overwrite instruction into a specified database.
The instruction reading service in fig. 4 may continuously scan the overwriting writing instructions in the designated database, and read the overwriting writing instructions in the designated database one by one, and perform the following operations for each overwriting writing instruction: and reading the overwriting content in the temporary file indicated by the overwriting instruction, calling a preset interface of the distributed file system, overwriting the overwriting content in a plurality of duplicate files of the target file, if the overwriting of a certain duplicate file fails, retrying the overwriting until all the duplicate files succeed in overwriting in the distributed file system, and then deleting the temporary file and the overwriting instruction.
In specific implementation, a user can read a file from the distributed file system according to own requirements, and the reading operation of the file can be realized through the following steps 10-13:
step 10, receiving a reading request of a target file sent by a user. The user can send a read request for any file in the distributed file system through the terminal device.
Step 11, judging whether an overwriting instruction of a target file exists in a designated database; if yes, go to step 12; if not, step 13 is performed.
And step 12, reading the overlay writing content and the target file corresponding to the overlay writing instruction from the distributed file system according to the overlay writing instruction of the target file, merging the overlay writing content and the target file, and returning the merged target file to the user.
And step 13, reading the target file from the distributed file system, and returning the read target file to the user.
The reading mode of the target file can ensure that a user can read the target file combined with the overlay writing content, thereby ensuring that the user can read the latest file and avoiding the loss of data.
According to the file overwriting method, if an overwriting request sent by a user is received, overwriting contents, an overwriting position and a file identifier of a target file needing to be overwritten are extracted from the overwriting request; writing the overwriting content into the distributed file system to obtain a storage position identifier of the overwriting content; then, the file identification of the target file, the storage position identification of the overwriting content and the overwriting position are spliced to obtain an overwriting instruction of the target file, and the overwriting instruction is stored in a designated database; and monitoring and acquiring an overwriting instruction in the designated database in real time, and writing the overwriting content into an overwriting position in the target file according to the overwriting instruction. Compared with the method of reading the original file, locally combining the coverage contents, then uploading the whole file and deleting the original file, the method has the advantages of no reading and writing amplification problem, reduction of the data volume of reading and writing data and further improvement of the performance of the file coverage and writing.
Corresponding to the foregoing method embodiment, an embodiment of the present invention provides a file overwriting apparatus, and as shown in fig. 5, the apparatus includes:
an instruction obtaining module 50, configured to obtain an overwrite instruction; wherein the overwrite command comprises at least: the file identification of the target file needing to be overwritten, the storage location identification of the overwriting content and the overwriting location.
And an overwrite module 51, configured to write the overwrite content to the overwrite location in the target file according to the overwrite command.
The file overwriting device firstly acquires an overwriting instruction; the overwriting instruction at least comprises a file identifier of a target file to be overwritten, a storage position identifier of overwriting content and an overwriting position; and then writing the overwriting content into the overwriting position in the target file according to the overwriting instruction. According to the method, based on the data contained in the overwriting instruction, the overwriting content is written into the target file at the storage position of the target file to be overwritten, and the target file does not need to be overwritten after being read out from the storage position, so that the data volume of reading and writing data is reduced, and the overwriting performance is improved.
Specifically, the overwrite location includes: an overwrite start address and an overwrite length; wherein the overwrite length is the same as the length of the overwrite content; the overwrite module 51 is configured to: determining the target file and the overwriting content according to the file identifier of the target file and the storage position identifier of the overwriting content; and replacing the content of the overwriting length in the target file with the overwriting content from the overwriting starting address in the target file.
Further, the overwriting instruction is stored in a designated database; the instruction obtaining module 50 is configured to: judging whether an overwriting instruction exists in the designated database; if so, the overwrite write instruction is fetched.
Further, the target file which needs to be overwritten is stored in a preset distributed file system; the device further comprises an overwriting instruction storage module, which is used for: if an overwriting request sent by a user is received, extracting overwriting content, an overwriting position and a file identifier of a target file needing to be overwritten from the overwriting request; writing the overlay writing content into a distributed file system to obtain a storage position identifier of the overlay writing content; splicing the file identification of the target file, the storage position identification of the overwriting content and the overwriting position to obtain an overwriting instruction of the target file; the overwrite write instruction is saved to a specified database.
Further, the apparatus further includes an information deleting module, configured to: and deleting the overwriting instruction, and identifying the overwriting content in the corresponding file by the storage position.
In a specific implementation, the apparatus further includes a file reading module, configured to: receiving a reading request of a target file sent by a user; judging whether an overwriting instruction of a target file exists in a specified database or not; if the target file exists, according to the overwriting instruction of the target file, the overwriting content and the target file corresponding to the overwriting instruction are read from the distributed file system, the overwriting content and the target file are combined, and the combined target file is returned to the user; and if the target file does not exist, reading the target file from the distributed file system, and returning the read target file to the user.
Further, the distributed file system stores an overwrite version number of the target file; the overwrite instruction saving module is further configured to: writing the overwriting content into the distributed file system, and receiving an overwriting version number of a target file returned by the distributed file system after obtaining a storage position identifier of the overwriting content; the overwrite write version number is written to the overwrite command.
Specifically, the apparatus further includes a version number updating module, configured to: and updating the overwrite version number in the distributed file system to be the sum of the overwrite version number in the overwrite instruction and one.
In a specific implementation, the target file comprises a plurality of copy files; the overwrite module 51 is configured to: and aiming at each copy file of the target file, writing the overwriting content into the overwriting position in the current copy file according to the overwriting instruction.
Further, the apparatus further includes an overwrite monitoring module configured to: judging whether the overwriting content is successfully written into an overwriting position in the current copy file or not aiming at each copy file of the target file; and if the writing is not successful, automatically repairing the current copy file, and rewriting the overwriting content into the current copy file until the current copy file is successfully overwritten.
The implementation principle and the generated technical effect of the document overwriting device provided by the embodiment of the invention are the same as those of the method embodiment, and for the sake of brief description, no part of the embodiment of the device is mentioned, and reference may be made to the corresponding contents in the method embodiment.
An embodiment of the present invention further provides an electronic device, which is shown in fig. 6 and includes a processor 101 and a memory 100, where the memory 100 stores machine executable instructions capable of being executed by the processor 101, and the processor 101 executes the machine executable instructions to implement the above-mentioned file overwriting method.
Further, the electronic device shown in fig. 6 further includes a bus 102 and a communication interface 103, and the processor 101, the communication interface 103, and the memory 100 are connected through the bus 102.
The memory 100 may include a high-speed Random Access Memory (RAM) and may further include a non-volatile memory (non-volatile memory), such as at least one disk memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like may be used. The bus 102 may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 6, but that does not indicate only one bus or one type of bus.
The processor 101 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 101. The processor 101 may be a general-purpose processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100, and completes the steps of the method of the foregoing embodiment in combination with the hardware thereof.
An embodiment of the present invention further provides a machine-readable storage medium, where the machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the above-mentioned file overwriting method, and specific implementation may refer to method embodiments, which are not described herein again.
The method, the apparatus, and the computer program product for writing a file in an overwriting manner provided in the embodiments of the present invention include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method described in the foregoing method embodiments, and specific implementation may refer to the method embodiments, and will not be described herein again.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention or a part thereof which substantially contributes to the prior art may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (12)

1. A method of overwriting a file, the method comprising:
acquiring an overwriting instruction; wherein the overwrite instruction comprises at least: the method comprises the steps that a file identifier of a target file needing to be overwritten, a storage position identifier of overwriting content and an overwriting position are obtained;
and writing the overwriting content into the overwriting position in the target file according to the overwriting instruction.
2. The method of claim 1, wherein overwriting the write location comprises: an overwrite start address and an overwrite length; wherein the overwrite length is the same as the overwrite length;
the step of writing the overwrite content to the overwrite location in the target file according to the overwrite command includes:
determining the target file and the overwriting content according to the file identifier of the target file and the storage position identifier of the overwriting content;
and replacing the content of the overwriting length in the target file with the overwriting content from the overwriting starting address in the target file.
3. The method of claim 1, wherein the overwrite instruction is saved in a specified database; the step of acquiring an overwrite command comprises:
judging whether the designated database has the overwriting instruction or not;
if so, the overwrite write instruction is fetched.
4. The method according to claim 3, wherein the target file to be overwritten is stored in a preset distributed file system; the overwrite instruction in the specified database is obtained by:
if an overwriting request sent by a user is received, extracting overwriting content, an overwriting position and a file identifier of a target file needing to be overwritten from the overwriting request;
writing the overlay writing content into the distributed file system to obtain a storage position identifier of the overlay writing content;
splicing the file identification of the target file, the storage position identification of the overwriting content and the overwriting position to obtain an overwriting instruction of the target file;
and saving the overwriting instruction to the specified database.
5. The method of claim 1, wherein after the step of writing the overwrite content to the overwrite location in the target file in accordance with the overwrite command, the method further comprises:
and deleting the overwriting instruction and the overwriting content in the file corresponding to the storage position identification.
6. The method of claim 4, further comprising:
receiving a reading request of a target file sent by a user;
judging whether an overwriting instruction of the target file exists in the specified database;
if the target file exists, according to the overwriting instruction of the target file, the overwriting content and the target file corresponding to the overwriting instruction are read from the distributed file system, the overwriting content and the target file are merged, and the merged target file is returned to the user;
and if the target file does not exist, reading the target file from the distributed file system, and returning the read target file to the user.
7. The method of claim 4, wherein the distributed file system has stored therein an overwrite version number of the target file;
after the step of writing the overwriting content into the distributed file system to obtain the storage location identifier of the overwriting content, the method further includes:
receiving an overwriting version number of the target file returned by the distributed file system;
writing the overwrite write version number into the overwrite write instruction;
after the step of writing the overwrite content to the overwrite location in the target file according to the overwrite command, the method further comprises:
and updating the overwrite version number in the distributed file system to be the sum of the overwrite version number in the overwrite instruction and one.
8. The method of claim 1, wherein the target file comprises a plurality of replica files;
according to the overwriting instruction, the step of writing the overwriting content into the overwriting position in the target file comprises the following steps:
and for each copy file of the target file, writing the overwriting content into the overwriting position in the current copy file according to the overwriting instruction.
9. The method of claim 8, further comprising:
for each copy file of the target file, judging whether the overwriting content is successfully written into the overwriting position in the current copy file;
and if the current copy file is not successfully written, automatically repairing the current copy file, and rewriting the overwriting content into the current copy file until the current copy file is successfully overwritten.
10. An apparatus for overwriting a file, the apparatus comprising:
the instruction acquisition module is used for acquiring an overwriting instruction; wherein the overwrite instruction comprises at least: the method comprises the steps that a file identifier of a target file needing to be overwritten, a storage position identifier of overwriting content and an overwriting position are obtained;
and the overwriting module is used for writing the overwriting content into the overwriting position in the target file according to the overwriting instruction.
11. An electronic device comprising a processor and a memory, the memory storing machine executable instructions executable by the processor, the processor executing the machine executable instructions to implement the file overwrite method of any one of claims 1 to 9.
12. A machine-readable storage medium having stored thereon machine-executable instructions which, when invoked and executed by a processor, cause the processor to implement the file overwrite method of any one of claims 1 to 9.
CN202110194994.5A 2021-02-19 2021-02-19 File overwriting method and device and electronic equipment Pending CN114968963A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110194994.5A CN114968963A (en) 2021-02-19 2021-02-19 File overwriting method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110194994.5A CN114968963A (en) 2021-02-19 2021-02-19 File overwriting method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN114968963A true CN114968963A (en) 2022-08-30

Family

ID=82954205

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110194994.5A Pending CN114968963A (en) 2021-02-19 2021-02-19 File overwriting method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN114968963A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069685A (en) * 2023-03-07 2023-05-05 浪潮电子信息产业股份有限公司 Storage system write control method, device, equipment and readable storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069685A (en) * 2023-03-07 2023-05-05 浪潮电子信息产业股份有限公司 Storage system write control method, device, equipment and readable storage medium

Similar Documents

Publication Publication Date Title
CN110058873B (en) Application page updating method, device, equipment and storage medium
CN109391673B (en) Method, system and terminal equipment for managing update file
US9864736B2 (en) Information processing apparatus, control method, and recording medium
US20050071839A1 (en) Communication terminal and communication network for partially updating software, software update method, and software creation device and method therefor
US20220004334A1 (en) Data Storage Method, Apparatus and System, and Server, Control Node and Medium
CN112714359B (en) Video recommendation method and device, computer equipment and storage medium
CN104182294A (en) Method and device for backing up and recovering file
CN112182010B (en) Dirty page refreshing method and device, storage medium and electronic equipment
CN111240892A (en) Data backup method and device
CN112925759A (en) Data file processing method and device, storage medium and electronic device
CN111198885A (en) Data processing method and device
CN114968963A (en) File overwriting method and device and electronic equipment
CN114489762A (en) Method and system for realizing multi-version application and electronic equipment
CN110807000B (en) File repair method and device, electronic equipment and storage medium
CN112000850A (en) Method, device, system and equipment for data processing
CN115454933A (en) File processing method, device, equipment, storage medium and program product
CN114675776A (en) Resource storage method and device, storage medium and electronic equipment
CN113419901A (en) Data disaster recovery method and device and server
JP2008250864A (en) Data storing method, data storing system and information processor
CN110083509B (en) Method and device for arranging log data
CN113535470A (en) Configuration backup method and device, electronic equipment and storage medium
CN107967366B (en) File management method, U disk and computer readable storage medium
CN106407320B (en) File processing method, device and system
JPWO2020065778A1 (en) Information processing equipment, control methods, and programs
CN113626245B (en) Method for preventing ios application program from crashing

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination