File management method, device and equipment
By dividing files into data blocks and generating identifiers, and updating file mapping relationships, the availability and consistency issues of file management systems during write operations are resolved, achieving efficient file management and access.
Patent Information
- Application Number
- CN202511793471.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-01
- Publication Date
- 2026-03-03
AI Technical Summary
Traditional file management methods lock files until synchronization is complete, leading to decreased availability of the file management system and hindering efficient retrieval and fast access.
The file to be managed is divided into multiple data blocks, and an identifier is assigned to each data block according to preset rules. An initial version identifier is generated, and an initial file mapping relationship is created. In response to write operations, a new data block is generated, and the file mapping relationship is updated to ensure high availability and consistency of read operations.
During write operations, the system can still respond to read operations based on the original version, ensuring the high availability of the file management system. It also ensures the consistency of read operations by maintaining the latest version of the file mapping relationship, avoiding data inconsistency or read errors.
Smart Images

Figure CN121597639A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of document management technology, and in particular to a document management method, apparatus and device. Background Technology
[0002] With the rapid increase in information volume, the number and types of files have exploded, making traditional manual management methods insufficient to support information processing needs. Scientific file management methods can not only achieve standardized storage and orderly organization of files, ensuring clear data structures and reasonable hierarchical relationships, but also enable efficient retrieval and rapid access to files through intelligent indexing and classification mechanisms, significantly improving information utilization efficiency.
[0003] However, in current file management methods, files are usually locked before synchronization is complete, and upper-layer applications cannot access the files before synchronization is complete, resulting in a decrease in the availability of the file management system. Summary of the Invention
[0004] This application provides a document management method, apparatus, and device to improve the usability of a document management system.
[0005] The first aspect of this application provides a file management method, the method comprising:
[0006] Divide the files to be managed into multiple data blocks;
[0007] Identifiers are assigned to each data block according to preset rules, and an initial version identifier is assigned to the file to be managed based on the identifiers of all data blocks;
[0008] An initial file mapping relationship for the file to be managed is created based on the file identifier and the initial version identifier, and the initial file mapping relationship is used as the read mapping relationship in response to read operations;
[0009] In response to a write operation, if it is determined that there is a target data block affected by the write operation, a new data block is generated to replace the target data block according to the write operation; and if it is determined that there is no target data block affected by the write operation, an additional new data block is generated according to the write operation.
[0010] An identifier is assigned to each new data block according to the preset rules, and an update version identifier is assigned to the file to be managed based on the identifiers of the other data blocks (excluding the target data block) and the identifier of the new data block.
[0011] An update file mapping relationship for the file to be managed is created based on the file identifier and the update version identifier, and the read mapping relationship is updated to the update file mapping relationship so as to respond to read operations through the update file mapping relationship.
[0012] A second aspect of this application provides a file management device, which includes a processing module, a creation module, and a response module;
[0013] The processing module is used to divide the file to be managed into multiple data blocks;
[0014] The processing module is also used to assign an identifier to each data block according to a preset rule, and to assign an initial version identifier to the file to be managed based on the identifiers of all data blocks;
[0015] The creation module is used to create an initial file mapping relationship for the file to be managed based on the file identifier and the initial version identifier, and to use the initial file mapping relationship as a read mapping relationship in response to read operations;
[0016] The response module is configured to respond to a write operation by generating a new data block to replace the target data block according to the write operation when it is determined that there is a target data block affected by the write operation, and by generating an additional new data block according to the write operation when it is determined that there is no target data block affected by the write operation.
[0017] The processing module is further configured to assign an identifier to each new data block according to the preset rules, and to assign an update version identifier to the file to be managed based on the identifiers of the other data blocks (excluding the target data block) and the identifier of the new data block.
[0018] The creation module is further configured to create an update file mapping relationship for the file to be managed based on the file identifier and the update version identifier, and update the read mapping relationship to the update file mapping relationship so as to respond to read operations through the update file mapping relationship.
[0019] A third aspect of this application provides a file management device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the file management method described in any one of the first aspects of this application.
[0020] A fourth aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the file management method described in any of the first aspects of this application.
[0021] The file management method, apparatus, and device provided in this application divide the file to be managed into multiple data blocks, assign an identifier to each data block according to a preset rule, assign an initial version identifier to the file to be managed based on the identifiers of all data blocks, and create an initial file mapping relationship for the file to be managed based on the file identifier and the initial version identifier. This initial file mapping relationship is then used as a read mapping relationship in response to a read operation. Furthermore, in response to a write operation, when it is determined that a target data block is affected by the write operation, a new data block is generated to replace the target data block based on the write operation. Conversely, when it is determined that no target data block is affected by the write operation, a new data block is generated based on the write operation. An identifier is assigned to each new data block according to a preset rule, and an update version identifier is assigned to the file to be managed based on the identifiers of the other data blocks (excluding the target data block) and the identifier of the new data block. This creates an updated file mapping relationship for the file to be managed based on the file identifier and the update version identifier, and updates the read mapping relationship to the updated file mapping relationship. In this way, before the write operation is completed, the read mapping relationship is the initial file mapping relationship, which can be used to respond to read operations. After the write operation is completed, the read mapping relationship is updated to the updated file mapping relationship, which can be used to respond to read operations. In this way, during the write operation, the original version can still be used to respond to read operations, thereby ensuring the high availability of the file management system during the write process. In addition, by maintaining the read mapping relationship as a variable, the latest version of the file mapping relationship can be accessed at any time, ensuring the consistency of read operations and avoiding data inconsistency or read errors caused by write operations.
[0022] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description
[0023] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0024] Figure 1 A flowchart of an embodiment of the document management method provided in this application;
[0025] Figure 2 A schematic diagram illustrating the implementation principle of a write operation as shown in an exemplary embodiment of this application;
[0026] Figure 3 A flowchart of Embodiment 2 of the document management method provided in this application;
[0027] Figure 4A flowchart of Embodiment 3 of the document management method provided in this application;
[0028] Figure 5 A hardware structure diagram of a file management device, which is a file management apparatus, shown as an exemplary embodiment of this application;
[0029] Figure 6 This is a schematic diagram of the structure of a document management device according to an embodiment of this application. Detailed Implementation
[0030] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application.
[0031] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0032] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0033] The following specific embodiments are given to illustrate the technical solution of this application in detail.
[0034] Figure 1 A flowchart illustrating an embodiment of the document management method provided in this application. Please refer to... Figure 1 The file management method provided in this embodiment may include:
[0035] S101. Divide the file to be managed into multiple data blocks.
[0036] It should be noted that the file management method provided in this embodiment is applied to a file management device, which can be a local computer or a local server, etc., and is not limited thereto in this embodiment.
[0037] Specifically, the file to be managed can be any collection of data that can be serialized into a byte stream, including structured data files, unstructured data files, and semi-structured data files. Furthermore, the file to be managed can be divided into multiple data blocks of the same size or multiple data blocks of different sizes; this embodiment does not limit this. For example, in one possible implementation, the file to be managed is divided into multiple data blocks of fixed size, and each data block is stored in memory.
[0038] It should be noted that when dividing the file to be managed into multiple data blocks of fixed size according to a preset block size, the specific value of the preset block size is set according to actual needs, and is not limited in this embodiment. For example, in one possible implementation, the preset block size can be 4KB, 8KB, etc.
[0039] S102. Assign an identifier to each data block according to a preset rule, and assign an initial version identifier to the file to be managed based on the identifiers of all data blocks.
[0040] Specifically, the identifier is used to uniquely identify a data block. In this embodiment, an identifier is assigned to each data block according to a preset rule. The specific content of the preset rule is set according to actual needs, and this embodiment does not limit its specific content. For example, in one possible implementation, the preset rule is used to instruct that an identifier be assigned to each database according to the content of each data block. Specifically, in one embodiment, the preset rule is to determine the hash value of each data block as its identifier. In this case, a hash operation can be performed on each data block to obtain its hash value, and then the hash value of each data block can be determined as its identifier.
[0041] It should be noted that hash operations can be SHA-256, MD5, BLAKE3, etc., and this embodiment does not limit them.
[0042] It is understood that in this embodiment, if H(x) = H(y), then x = y, meaning that data blocks with the same content written repeatedly will not be stored repeatedly.
[0043] It should be noted that the version identifier of the file to be managed is used to uniquely identify the set of all data blocks of the file to be managed in its current state. In this embodiment, for ease of explanation, the initial version identifier is referred to as the initial version identifier. Based on the above description, when the preset rule is to determine the hash value of each data block as its identifier, the process of determining the version identifier of the file to be managed may include: determining the root hash value of all identifiers of all data blocks currently included in the file to be managed, and determining the root hash value as the version identifier of the file to be managed.
[0044] Based on the above description, for example, in one embodiment, the content of data block i is denoted as BlockData(i), and the identifier of this data block is denoted as I. i Let i range from 1 to N, where N represents the total number of data blocks. i =H(BlockData(i)), at this time, R old =H(I1, I2, ..., I N ), R old This is the initial version identifier of the file to be managed.
[0045] Optionally, in one possible implementation, the identifier of the data block can be generated based on the logical sequence number of the data block and the timestamp when the data block was created. Furthermore, the identifiers of all data blocks are aggregated to obtain the version identifier.
[0046] S103. Create an initial file mapping relationship for the file to be managed based on the file identifier and the initial version identifier, and use the initial file mapping relationship as the read mapping relationship in response to the read operation.
[0047] Specifically, a file mapping relationship describes the correspondence between files to be managed and actual data blocks. In practice, the file identifier (FileID) and the initial version identifier (Rold) of the files to be managed can be bound together to form the following initial file mapping relationship (FileID, Rold). old ).
[0048] It should be noted that the file management method provided in this embodiment maintains a read mapping relationship for responding to read operations. That is, the read mapping relationship is used to point to the latest file mapping relationship used when performing a read operation. Specifically, when a read operation is received, the read mapping relationship corresponding to the file identifier to be read is found according to the read operation indication. Then, the version identifier recorded in the read mapping relationship is obtained, and all data blocks indicated by the version identifier are read.
[0049] For example, in one embodiment, the read mapping relationship is denoted as ReadMap, and then we have ReadMap: (FileID, R old That is, at this point, when a read operation exists, it will be based on R. old Read the corresponding data block.
[0050] S104. In response to a write operation, if it is determined that there is a target data block affected by the write operation, a new data block is generated to replace the target data block according to the write operation; and if it is determined that there is no target data block affected by the write operation, a new data block is generated according to the write operation.
[0051] In practice, in response to a write operation, the system first determines whether there is a target data block affected by the write operation. Specifically, a write operation can be denoted as WRITE(offset, buf), which carries the write offset and the buffer buf. The write offset is represented by a byte offset and is used to indicate the starting position of the data to be written. The buffer is represented by a continuous sequence of bytes and is used to indicate the data buffer to be written.
[0052] In this step, the write interval can be determined first based on the write offset and the buffer. Referring to the example above, for instance, the write interval is determined to be [offset, offset + |buf|]. Further, for the i-th data block in the file to be managed, the byte range covered by that data block is determined. For example, when all data blocks are of a fixed size s, the byte range covered by the i-th data block is determined to be... Finally, after determining the write interval and the byte interval covered by each data block, it can be determined whether there is an intersection between the write interval and the byte interval covered by each data block. If there is an intersection between the write interval and the byte interval covered by a certain data block, the data block is determined to be the affected data block. If there is no intersection between the write interval and the byte intervals covered by all data blocks, it is determined that there is no target data block affected by the write operation.
[0053] It is understandable that write operations can include modification, deletion, and addition operations. When the write operation is a modification or deletion operation, it is determined that there is a target data block affected by the write operation; when the write operation is an addition operation, it is determined that there is no target data block affected by the write operation.
[0054] In this step, in response to a write operation, if it is determined that there is a target data block affected by the write operation, a new data block is generated to replace the target data block according to the write operation; if it is determined that there is no target data block affected by the write operation, an additional new data block is generated according to the write operation.
[0055] For example, in one embodiment, when the write operation is a deletion operation used to indicate the deletion of the 5th data block, a new data block is directly generated for the affected 5th data block, and no content is written in the data block. The new data block replaces the 5th data block, and the new data block and the original data blocks other than the 5th data block constitute the latest version of the file to be managed.
[0056] For example, in another possible implementation, when the write operation is a new operation, it is determined that there is no affected target data block. The new data block is generated directly based on the write operation. The new data block and all the original data blocks constitute the latest version of the file to be managed.
[0057] For example, in another possible implementation, when the write operation is a modification operation, it is determined that there is an affected target data block. For example, if the affected target data block is the 7th data block, a new data block can be generated to replace the 7th data block based on a partial overwrite method. This new data block and the original data blocks other than the 7th data block constitute the latest version of the file to be managed.
[0058] Optionally, in one possible implementation, when the write operation is a modification operation, generating a new data block to replace the target data block based on the write operation includes:
[0059] For each target data block, a first portion of the target data block affected by the write operation and a second portion unaffected by the write operation are identified; a replacement portion of the first portion is determined based on the write operation; the replacement portion and the second portion are combined to form a new data block to replace the target data block.
[0060] In practice, based on the write interval and the byte range covered by the target data block, the first part affected by the write operation and the second part unaffected by the write operation can be further determined. The first part is the intersection of the write interval and the byte range covered by the target data block, and the second part is the remaining portion of the target data block. Furthermore, after determining the first and second parts, a replacement portion for the first part can be directly found in the buffer; this replacement portion is the part in the buffer corresponding to the aforementioned intersection. Finally, combining the replacement portion and the second part yields the new data block.
[0061] It should be noted that the method provided in this embodiment directly generates new data blocks in response to write operations. This not only avoids rewriting the entire file, significantly improving the efficiency of file writing and updating, but also preserves unaffected data blocks, avoiding duplicate storage, reducing storage overhead, and improving storage utilization. Furthermore, it can generate new versions of the file to be managed without damaging older versions, achieving version traceability and snapshot protection.
[0062] S105. Assign an identifier to each new data block according to the preset rules, and assign an update version identifier to the file to be managed based on the identifiers of the other data blocks besides the target data block and the identifier of the new data block.
[0063] Referring to the preceding description, in one possible implementation, in this step, for a new data block, its hash value can be calculated and used as the allocation identifier for that new data block. Furthermore, the identifiers of the other data blocks besides the target data, as well as the root hash value of the identifier of the new data block, can be determined, and this root hash value can then be used as the updated version identifier for the file to be managed.
[0064] Based on the preceding description, for example, when the write operation is a new operation, there is no target data block at this time. In this step, an update version identifier is assigned to the file to be managed based on the existing multiple data blocks and the new data block.
[0065] For example, in one embodiment, two new data blocks are added, denoted as the (N+1)th data block and the (N+2)th data block, respectively, and the identifier of the (N+1)th data block is I. N+1 = H(BlockData(N+1)), where the identifier for the (N+2)th data block is I. N+2 =H(BlockData(N+2)). At this time, R new =H(I1, I2, ..., I N I N+1 I N+2 ), R new This is the update version identifier for the file to be managed.
[0066] Figure 2 This is a schematic diagram illustrating the implementation principle of a write operation as shown in an exemplary embodiment of this application. Please refer to... Figure 2 Based on the preceding description, for example, in one embodiment, when the write operation is a deletion or modification operation, the target data block is determined to be the 6th data block. In step S104, a new data block is generated to replace the 6th data block, denoted as the (N+1)th data block, and the identifier of the (N+1)th data block is I. N+1 = H(BlockData(N+1)), further, at this time, Rnew=H(I1,I2,I3,I4,I5,I7,I8,I9,...,I... N I N+1 ).
[0067] S106. Create an update file mapping relationship for the file to be managed based on the file identifier and the update version identifier, and update the read mapping relationship to the update file mapping relationship so as to respond to the read operation through the update file mapping relationship.
[0068] In this step, the file identifier FileID and the update version identifier R are... newThey are bound together to form the following file update mapping relationship: (FileID, R new Furthermore, the read mapping is updated to the following state: ReadMap: (FileID, R) new ).
[0069] It's important to note that by maintaining the read mapping as a variable, the file mapping corresponding to the latest version can be accessed at any time, ensuring the efficiency and consistency of read operations and avoiding data inconsistencies or read errors caused by write operations. Furthermore, since writing does not destroy the existing old version, reading can continue even during a write operation, improving availability.
[0070] The file management method provided in this embodiment divides the file to be managed into multiple data blocks, assigns an identifier to each data block according to a preset rule, assigns an initial version identifier to the file to be managed based on the identifiers of all data blocks, and creates an initial file mapping relationship for the file to be managed based on the file identifier and the initial version identifier. This initial file mapping relationship is then used as a read mapping relationship in response to read operations. Furthermore, in response to write operations, when it is determined that a target data block is affected by the write operation, a new data block is generated to replace the target data block based on the write operation. When it is determined that no target data block is affected by the write operation, a new data block is generated based on the write operation, and an identifier is assigned to each new data block according to a preset rule. An update version identifier is assigned to the file to be managed based on the identifiers of the other data blocks besides the target data block and the identifier of the new data block. Thus, an update file mapping relationship for the file to be managed is created based on the file identifier and the update version identifier, and the read mapping relationship is updated to the update file mapping relationship. In this way, before the write operation is completed, the read mapping relationship is the initial file mapping relationship, which can be used to respond to read operations. After the write operation is completed, the read mapping relationship is updated to the updated file mapping relationship, which can be used to respond to read operations. In this way, during the write operation, the original version can still be used to respond to read operations, thereby ensuring the high availability of the file management system during the write process. In addition, by maintaining the read mapping relationship as a variable, the latest version of the file mapping relationship can be accessed at any time, ensuring the consistency of read operations and avoiding data inconsistency or read errors caused by write operations.
[0071] Optionally, in one possible implementation, after creating the update file mapping relationship for the file to be managed, the method further includes:
[0072] Record the write operation log; the write operation log includes the write operation identifier, the initial version identifier, the updated version identifier, the new data block, and the identifier of the new data block.
[0073] In practice, the following operation logs can be recorded: in A set consisting of a new data block and its identifier.
[0074] The method provided in this embodiment, after creating the update file mapping relationship of the file to be managed, records the write operation log, and records information such as write operation identifier, initial version identifier, update version identifier, new data block and its identifier in the write operation log. This can be used to accurately describe the impact of each write operation on the file structure and version, and realize full-process tracking and traceable management of the file update process.
[0075] Therefore, on the one hand, in the event of file system anomalies or rollback operations, the system can be quickly restored to a specified version based on the write operation log, improving the system's fault tolerance and data security; on the other hand, through the version association recorded in the write operation log, the file version evolution process can be visualized and tracked for differences, further enhancing the consistency and maintainability of the file management system.
[0076] Optionally, in one possible implementation, the backup file of the file to be managed is stored on a cloud server; the method further includes:
[0077] The write operation log is notified to the cloud server, instructing the cloud server to update the backup file according to the write operation log upon receipt.
[0078] Specifically, to improve data security and reliability, the method provided in this embodiment, in addition to storing the files to be managed on the file management device, also stores backup files of the files to be managed on a cloud server. Thus, through cloud backup, even if the locally stored files to be managed are damaged or accidentally lost, they can be quickly restored based on the backup files stored on the cloud server, avoiding the permanent loss of critical data.
[0079] Furthermore, when backup files are stored on the cloud server, the write operation log can be sent to the cloud server. Furthermore, upon receiving the write operation log, the cloud server can update the backup files based on the write operation log.
[0080] In practice, the cloud server can first assign an identifier to each new data block according to preset rules, further verify the consistency between the assigned identifier and the identifier recorded in the write operation log, and when all data blocks are consistent, store the data block recorded in the write operation log locally.
[0081] The method provided in this embodiment stores backups of the files to be managed on a cloud server and notifies the cloud server of the write operation log in real time, thereby achieving dynamic updates of the backup files. In this way, firstly, the consistency between local files and cloud backup files can be guaranteed, avoiding data loss due to local data anomalies or device failures; secondly, the automatic updates of backup files by the cloud server based on the write operation log simplifies manual synchronization operations and improves the efficiency and accuracy of file management.
[0082] Figure 3 A flowchart illustrating Embodiment Two of the document management method provided in this application. Please refer to... Figure 3 Based on the above embodiments, the method further includes:
[0083] S301. In response to the rollback operation, obtain the target version identifier to which the rollback operation indicates.
[0084] As described above, it is understandable that different versions of the files to be managed correspond to different version identifiers, and the rollback operation essentially means that the user wants to restore the files to be managed to a certain historical version.
[0085] It should be noted that rollback operations can be user-initiated or automatically triggered by the file management device. For example, in one possible implementation, the user can trigger a rollback operation when they discover file content errors, accidental deletion, or the need to recover historical data. In another possible implementation, the file management device can automatically select the most recently available stable version for rollback when it detects abnormal modifications or synchronization failures.
[0086] Referring to the preceding description, it can be understood that the rollback operation carries a target version identifier, indicating the rollback to the version corresponding to that target version identifier. In this step, the target version identifier can be directly read from the rollback operation. For example, in one possible implementation, the initial version identifier of the file to be managed is R1. After one write operation, the updated version identifier of the file to be managed is R2. After another write operation, the updated version identifier of the file to be managed is R3. At this point, the read mapping relationship is ReadMap:(FileID, R3), meaning that the read operation will be responded to based on the latest version corresponding to R3.
[0087] Furthermore, combining the above example, for instance, if a user wants to roll back to the version after the first write operation, the target version identifier carried in the rollback operation is R2.
[0088] S302. Locate the target mapping relationship containing the target version identifier from the created file mapping relationships.
[0089] Based on the example above, the existing file mapping relationships include: (FileID, R1), (FileID, R2), and (FileID, R3). In this step, the target mapping relationship found is (FileID, R2).
[0090] S303. Update the read mapping relationship to the target mapping relationship so as to respond to the read operation through the target mapping relationship.
[0091] In this step, the read mapping relationship is updated to ReadMap:(FileID, R2), meaning that read operations will now be responded to based on the version corresponding to R2.
[0092] The method provided in this embodiment, in response to a rollback operation, obtains the target version identifier to which the rollback operation indicates to roll back, and searches for the target mapping relationship where the target version identifier is located from the created file mapping relationship, and then updates the read mapping relationship to the target mapping relationship. In this way, the files to be managed can be quickly rolled back to historical versions, effectively preventing information loss caused by accidental operation or abnormal modification, and improving the reliability of file management.
[0093] Figure 4 The flowchart for Embodiment 3 of the document management method provided in this application is shown below. Please refer to... Figure 4 In one possible implementation, based on the above embodiments, the method further includes:
[0094] S401. After each file mapping relationship is created, establish the association between the creation sequence number, file identifier, and version identifier based on the currently created file mapping relationship and the creation sequence number when the file mapping relationship was created, and obtain the association relationship corresponding to the file mapping relationship.
[0095] It should be noted that the creation sequence number is a unique identifier assigned to each file mapping operation, used to distinguish the order of different creation operations. The creation sequence number can be an incrementing integer or a timestamped number. The following explanation uses an incrementing integer creation sequence number as an example. In this case, for example, in one embodiment, the creation sequence number is 1 when the file mapping relationship is created for the first time, and the creation sequence number is 2 when the file mapping relationship is created for the second time.
[0096] In this step, after each file mapping relationship is created, the association between the creation number, file identifier, and version identifier is established based on the currently created file mapping relationship and the creation sequence number when the file mapping relationship was created. This association can be represented as (creation sequence number, file identifier, version identifier).
[0097] Based on the example in step S301, the established associations include: (1, FileID, R1), (2, FileID, R2), and (3, FileID, R3).
[0098] S402. Store the association relationship in the version database.
[0099] Specifically, a relationship can be inserted as an entry into the version database. The version database is used to centrally manage the version information and history of files, and can be used to perform functions such as quick search and version reversion.
[0100] The method provided in this embodiment establishes an association between the creation sequence number, file identifier, and version identifier after each file mapping relationship is created and stores it in a version database. First, the version database can completely record the version evolution history of files, providing reliable data support for file tracing and rollback. Second, by centrally managing the association relationships, the mapping relationship of a specific version can be quickly located, improving the efficiency of file reading and version switching. In addition, the version database enables version consistency verification and parallel management of multiple versions, enhancing the security, reliability, and controllability of the file management system, thereby effectively ensuring the integrity and maintainability of file data.
[0101] Corresponding to the aforementioned embodiment of a file management method, this application also provides an embodiment of a file management device.
[0102] An embodiment of a file management device disclosed in this application can be applied to a file management device. The device embodiment can be implemented through software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by the processor of the file management device loading the corresponding computer program instructions from non-volatile memory into memory for execution. From a hardware perspective, such as... Figure 5 As shown, Figure 5 This is a hardware structure diagram of a file management device, which is the file management apparatus shown in an exemplary embodiment of this application. (Except for...) Figure 5 In addition to the processor, memory, network interface, and non-volatile memory shown, the file management device in the embodiment may also include other hardware depending on the actual function of the file management device, which will not be described in detail here.
[0103] Figure 6 This is a schematic diagram of the structure of a document management device according to Embodiment 1 of this application. Please refer to... Figure 6 The file management device provided in this embodiment includes a processing module 610, a creation module 620, and a response module 630;
[0104] The processing module 610 is used to divide the file to be managed into multiple data blocks;
[0105] The processing module 610 is also used to assign an identifier to each data block according to a preset rule, and to assign an initial version identifier to the file to be managed based on the identifiers of all data blocks.
[0106] The creation module 620 is used to create an initial file mapping relationship for the file to be managed based on the file identifier and the initial version identifier, and to use the initial file mapping relationship as a read mapping relationship in response to read operations;
[0107] The response module 630 is configured to respond to a write operation by generating a new data block to replace the target data block according to the write operation when it is determined that there is a target data block affected by the write operation, and by generating an additional new data block according to the write operation when it is determined that there is no target data block affected by the write operation.
[0108] The processing module 610 is further configured to assign an identifier to each new data block according to the preset rules, and to assign an update version identifier to the file to be managed based on the identifiers of the other data blocks (excluding the target data block) and the identifier of the new data block.
[0109] The creation module 620 is further configured to create an update file mapping relationship for the file to be managed based on the file identifier and the update version identifier, and update the read mapping relationship to the update file mapping relationship so as to respond to read operations through the update file mapping relationship.
[0110] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0111] Optionally, in one possible implementation, the creation module 620 is further configured to record a write operation log after creating the update file mapping relationship of the file to be managed; the write operation log includes a write operation identifier, the initial version identifier, the update version identifier, the new data block, and the identifier of the new data block.
[0112] Optionally, in one possible implementation, the response module 630 is further configured to, in response to a rollback operation, obtain the target version identifier to which the rollback operation indicates a rollback;
[0113] The processing module 610 is also used to find the target mapping relationship where the target version identifier is located from the created file mapping relationship;
[0114] The processing module 610 is further configured to update the read mapping relationship to the target mapping relationship, so as to respond to the read operation through the target mapping relationship.
[0115] Optionally, in one possible implementation, the preset rule is to determine the hash value of each data block as the identifier of that data block; the process of determining the version identifier of the file to be managed includes:
[0116] Determine the root hash value of all identifiers for all data blocks currently included in the file to be managed;
[0117] The root hash value is determined as the version identifier of the file to be managed.
[0118] Optionally, in one possible implementation, the backup file of the file to be managed is stored on a cloud server; the processing module 610 is further configured to notify the cloud server of the write operation log, so as to instruct the cloud server to update the backup file according to the write operation log when it receives the write operation log.
[0119] Optionally, in one possible implementation, the creation module 620 is further configured to, after each creation of a file mapping relationship, establish an association between the creation sequence number, file identifier, and version identifier based on the currently created file mapping relationship and the creation sequence number when the file mapping relationship was created, so as to obtain the association relationship corresponding to the file mapping relationship;
[0120] The creation module 620 is also used to store the association relationship in the version database.
[0121] Optionally, in one possible implementation, the processing module 610 is specifically configured to, for each target data block, determine a first portion of the target data block affected by the write operation and a second portion unaffected by the write operation, and determine a replacement portion of the first portion based on the write operation;
[0122] The processing module 610 is further configured to combine the replacement portion and the second portion to form a new data block for replacing the target data block.
[0123] Please continue to refer to Figure 5 The file management device provided in this application includes a memory and a processor. The memory stores a computer program, and the processor is configured to run the computer program to perform the file management method described in any of the first aspects of this application.
[0124] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the file management method described in any of the first aspects of this application.
[0125] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0126] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A file management method, characterized in that, The method includes: Divide the files to be managed into multiple data blocks; Identifiers are assigned to each data block according to preset rules, and an initial version identifier is assigned to the file to be managed based on the identifiers of all data blocks; An initial file mapping relationship for the file to be managed is created based on the file identifier and the initial version identifier, and the initial file mapping relationship is used as the read mapping relationship in response to read operations; In response to a write operation, if it is determined that there is a target data block affected by the write operation, a new data block is generated to replace the target data block according to the write operation; and if it is determined that there is no target data block affected by the write operation, an additional new data block is generated according to the write operation. An identifier is assigned to each new data block according to the preset rules, and an update version identifier is assigned to the file to be managed based on the identifiers of the other data blocks (excluding the target data block) and the identifier of the new data block. An update file mapping relationship for the file to be managed is created based on the file identifier and the update version identifier, and the read mapping relationship is updated to the update file mapping relationship so as to respond to read operations through the update file mapping relationship.
2. The file management method according to claim 1, characterized in that, After creating the update file mapping relationship for the files to be managed, the method further includes: Record the write operation log; the write operation log includes the write operation identifier, the initial version identifier, the updated version identifier, the new data block, and the identifier of the new data block.
3. The file management method according to claim 1, characterized in that, The method further includes: In response to a rollback operation, obtain the target version identifier to which the rollback operation indicates; Locate the target mapping relationship containing the target version identifier from the existing file mapping relationships; Update the read mapping relationship to the target mapping relationship so that the read operation is responded to through the target mapping relationship.
4. The method according to claim 1, characterized in that, The preset rule is to determine the hash value of each data block as the identifier of that data block; The process of determining the version identifier of the file to be managed includes: Determine the root hash value of all identifiers for all data blocks currently included in the file to be managed; The root hash value is determined as the version identifier of the file to be managed.
5. The file management method according to claim 2, characterized in that, The backup files of the files to be managed are stored on a cloud server; the method further includes: The write operation log is notified to the cloud server, instructing the cloud server to update the backup file according to the write operation log upon receipt.
6. The method according to claim 1, characterized in that, The method further includes: After each file mapping relationship is created, the association between the creation sequence number, file identifier, and version identifier is established based on the currently created file mapping relationship and the creation sequence number when the file mapping relationship was created, so as to obtain the association relationship corresponding to the file mapping relationship. The relationships are stored in the version database.
7. The method according to claim 1, characterized in that, The step of generating a new data block to replace the target data block according to the write operation includes: For each target data block, determine a first portion of the target data block that is affected by the write operation and a second portion that is not affected by the write operation; The replacement portion of the first portion is determined based on the write operation; The replacement portion and the second portion are combined to form a new data block for replacing the target data block.
8. A document management device, characterized in that, The file management device includes a processing module, a creation module, and a response module; wherein, The processing module is used to divide the file to be managed into multiple data blocks; The processing module is also used to assign an identifier to each data block according to a preset rule, and to assign an initial version identifier to the file to be managed based on the identifiers of all data blocks; The creation module is used to create an initial file mapping relationship for the file to be managed based on the file identifier and the initial version identifier, and to use the initial file mapping relationship as a read mapping relationship in response to read operations; The response module is configured to respond to a write operation by generating a new data block to replace the target data block according to the write operation when it is determined that there is a target data block affected by the write operation, and by generating an additional new data block according to the write operation when it is determined that there is no target data block affected by the write operation. The processing module is further configured to assign an identifier to each new data block according to the preset rules, and to assign an update version identifier to the file to be managed based on the identifiers of the other data blocks (excluding the target data block) and the identifier of the new data block. The creation module is further configured to create an update file mapping relationship for the file to be managed based on the file identifier and the update version identifier, and update the read mapping relationship to the update file mapping relationship so as to respond to read operations through the update file mapping relationship.
9. A file management device, comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the file management method according to any one of claims 1 to 7.
10. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the file management method according to any one of claims 1 to 7.