Data storage method and device based on snapshot technology
By adopting directory-level fine-grained snapshot technology in the file system, using version address tables and chain management structures, the problems of low backup efficiency and waste of storage resources in the existing technology are solved, and efficient and reliable data protection and storage are achieved. manage.
Patent Information
- Application Number
- CN202411133261.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-06
AI Technical Summary
The existing snapshot technology has shortcomings in backup efficiency, especially when retaining versions of some directories or files, it cannot meet user needs and consumes storage resources, resulting in inconvenience in management.
Using directory-level fine-grained snapshot technology, the file system disk layout is divided, metadata area and main area are created, and the inode node is stored using version address tables and chain management structures, and the creation timestamps and reference times of directory snapshots are recorded. , realizes directory snapshot management and recycling of different versions.
It realizes efficient and reliable data protection, reduces storage fragmentation, saves storage resources, improves data access speed and system operation efficiency, while maintaining data reliability and timeliness.
Smart Images

Figure CN119088780A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to a data storage method and device based on snapshot technology. Background Art
[0002] Flash-friendly file system (F2FS) is the mainstream flash file system. Based on the characteristics of log-structured file system and copy-on-write (COW) technology, F2FS can give full play to the storage read and write performance and maintain the integrity of files, but the backup efficiency needs to be improved.
[0003] Snapshot technology is essentially a lightweight data fast backup technology that retains the historical images of directories and files in the system by copying the file system metadata. However, existing snapshots all use coarse-grained version generation and management strategies, and will generate an image of the entire file system when executing a snapshot operation. This consumes a lot of storage resources and cannot meet the user's needs to retain versions of only some directories or files, which is not conducive to management. Summary of the invention
[0004] In order to solve the above technical problems, the present invention is proposed. The embodiments of the present invention provide a data storage method and device based on snapshot technology, which can provide data storage and backup based on directory-level fine-grained snapshot technology.
[0005] According to one aspect of the present invention, a data storage method based on snapshot technology is provided, comprising: dividing the file system disk layout to obtain a metadata area and a main area; wherein the metadata area includes a version address table, and the main area includes a storage index node segment area, a data segment area and a version segment area; when creating a directory snapshot in response to a snapshot request instruction, creating a new entry in the version address table, recording the directory snapshot name and the current system time as an index node; wherein the index node is used to record the directory index node number and the sub-directory index node position at the time of sub-snapshot creation; storing the index nodes based on a chain management structure to store directory snapshots of different versions; wherein each index node of the chain management structure includes necessary information when creating the directory snapshot, a timestamp of the directory snapshot, a pointer to a data block, and a pointer to the address of the next directory snapshot.
[0006] In one embodiment, the data storage method based on snapshot technology also includes: recording the number of times different data blocks are referenced by directory snapshots; when a directory snapshot is created, using a counter to increase the number of references of the data block by one; when the directory snapshot is deleted, using a counter to decrease the number of references of the data block by one; when the number of references recorded by the counter of the data block is less than or equal to a preset number and there is no ongoing write operation, marking the data block as invalid for recycling.
[0007] In one embodiment, a data storage method based on snapshot technology includes: when a data block with a reference count greater than a preset number of times is migrated, a pointer is added to the data block to point to the parent node corresponding to the data block, and the first version of the parent directory containing the file is found by indexing upward, and then other related versions are found by tracking the directory snapshot, and the corresponding address is addressed for updating.
[0008] In one embodiment, the data storage method based on snapshot technology also includes: adding a snapshot time field of 32-bit int type in the data structure; wherein the snapshot time field is used to distinguish whether it is a snapshot node; for non-snapshot nodes, the snapshot time field is set to a default value; for snapshot nodes, it is set to the time when the index node is created; wherein, for the same directory, the snapshot time field is a monotonically increasing value and is consistent with the system time, so as to determine the directory snapshot version to which the index stage belongs.
[0009] In one embodiment, the data storage method based on snapshot technology also includes: after creating a directory snapshot, when the index node of the sub-directory tree under the directory snapshot is modified, backing up the historical index node information; wherein the historical index node information points to the original data; after creating a directory snapshot, when updating the data, saving the index node pointing to the original data corresponding to the updated data, and generating a new index node at the same time; wherein the updated index node is not recursively backed up and updated; adding an entry under the corresponding index to record the location of the new metadata, and saving it in the version segment area; storing the new index node number and actual address in the version address table to form the modified directory index node number and sub-directory index node position.
[0010] In one embodiment, the data storage method based on snapshot technology also includes: before creating a directory snapshot, if the directory snapshot saves the state of the file when it is normally closed in the future, the specified directory is not modified; before creating a directory snapshot, if the directory snapshot saves the current state of the file, then when the file is opened and each time the file is updated, a mutual exclusion is added when reading and writing the directory in the version address table to check whether the parent directory has already created a directory snapshot; wherein, when a directory snapshot is created in response to a snapshot request instruction, a new entry is created in the version address table, and the directory snapshot name and the current system time are recorded as an index node, including: when a directory snapshot has not been created for the parent directory, when a directory snapshot is created in response to a snapshot request instruction, a new entry is created in the version address table, and the directory snapshot name and the current system time are recorded as an index node.
[0011] In one embodiment, index nodes are stored based on a chain management structure to store different versions of directory snapshots, including: using the index node of the original directory as the head node of the snapshot chain to address the snapshot chain; the linked list uses a page replacement algorithm, and when the file system creates a new directory snapshot, a new child node is added to the node at the head of the linked list, and the version address table stores the mapping of the directory to the index node address of the most recent directory snapshot to confirm different historical versions by accessing the snapshot chain; wherein, the pointer of the new child node to the data block is initially shared with the parent node until the data block is modified.
[0012] In one embodiment, a data storage method based on snapshot technology includes: when updating the node at the head of a linked list, if the update time of the node saved before the update is later than the directory snapshot creation time, replace the node at the head of the linked list; if the update time of the node saved before the update is earlier than the directory snapshot creation time or a preset time, add a new index node and point to the existing index node, and add the index information of the new index node in the version address table.
[0013] In one embodiment, a data storage method based on snapshot technology includes: when accessing a directory snapshot, based on the path information, if the directory snapshot or the parent directory corresponding to the directory snapshot is in the version address table, then based on retrieving the original index node information, checking whether there is new metadata in the version address table; if the node at the head of the linked list is updated after the directory snapshot is created, the updated metadata recorded in the version address table is used.
[0014] According to another aspect of the present invention, a data storage device based on snapshot technology is provided, comprising: a partitioning module, used to partition the file system disk layout to obtain a metadata area and a main area; wherein the metadata area includes a version address table, and the main area includes a storage index node segment area, a data segment area and a version segment area; a creation module, used to create a new entry in the version address table when creating a directory snapshot in response to a snapshot request instruction, and record the directory snapshot name and the current system time as an index node; wherein the index node is used to record the directory index node number and the sub-directory index node position at the time of sub-snapshot creation; a storage module, used to store index nodes based on a chain management structure to store directory snapshots of different versions; wherein each index node of the chain management structure includes necessary information when creating a directory snapshot, a timestamp of the directory snapshot, a pointer to a data block, and a pointer to the address of the next directory snapshot.
[0015] The data storage method and device based on snapshot technology provided by the present invention support fine-grained and lightweight snapshots at the directory level, and provide an efficient and reliable data protection mechanism. It enables users to perform directory snapshot storage for key data, reduce storage fragmentation, save storage resources, improve data access speed and overall system operation efficiency, and maintain the reliability and timeliness of data protection. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above and other purposes, features and advantages of the present invention will become more apparent by describing the embodiments of the present invention in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings, the same reference numerals generally represent the same components or steps.
[0017] Figure 1 It is a flowchart of a data storage method based on snapshot technology provided by an exemplary embodiment of the present invention.
[0018] Figure 2 A schematic diagram of the field contents of a version address table provided by an exemplary embodiment of the present invention.
[0019] Figure 3 It is a schematic diagram of a flow chart of modifying a data block provided by an exemplary embodiment of the present invention.
[0020] Figure 4 It is a schematic diagram of the principle of batch updating directory trees provided by an exemplary embodiment of the present invention.
[0021] Figure 5 The figure is a schematic diagram of the principle of querying and managing multi-version snapshots provided by an exemplary embodiment of the present invention.
[0022] Figure 6 It is a schematic diagram of the structure of a data storage device based on snapshot technology provided by an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0023] Below, the exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described here.
[0024] Figure 1 FIG. 1 is a flow chart of a data storage method based on snapshot technology provided by an exemplary embodiment of the present invention. Figure 1 As shown, the data storage method based on snapshot technology includes:
[0025] S100: Divide the file system disk layout to obtain a metadata area and a main area.
[0026] The metadata area includes a version address table, and the main area includes a storage index node segment area, a data segment area, and a version segment area.
[0027] The present invention is implemented based on a flash-friendly file system (F2FS). First, the file system disk layout of F2FS is divided into two parts. The first part includes a file system metadata area, such as a super block, a checkpoint, a segment information table, a node address table, a segment summary area, and a version address table (VAT). The second part is a main area, which is used to store data, such as an inode (index node) segment, a data segment, and a version segment. A version address table (VAT) is added to the metadata area, and the modification of the metadata includes the recording of directory snapshots and snapshot timestamps, and the address change of subdirectories / files pointing to data blocks. Each snapshot entry in the VAT records the timestamp of its latest snapshot creation as an index, which is used to determine the order of data versions when restoring and managing snapshots, and saves pointers to record the positions of the latest inodes of all subdirectories at the time of snapshot creation, records the current data status, and quickly locates when the snapshot is restored. A version segment area is added to the main area, and the version segment contains metadata for creating a snapshot, mainly saves inodes updated after creating a snapshot, and ensures the integrity and consistency of the snapshot.
[0028] S200: When creating a directory snapshot in response to a snapshot request instruction, create a new entry in the version address table, record the directory snapshot name and the current system time as an index node.
[0029] The index node is used to record the directory index node number and the sub-directory index node position at the time when the sub-snapshot is created.
[0030] F2FS uses an off-site update method. The modification of the data block corresponds to the writing of the new address. The snapshot node created before the modification points to the original data block address. Directory snapshots are used to back up directories. Snapshots are created for important directories so that they can be quickly restored when data is lost or damaged. When the snapshot request command indicates the first creation of a directory snapshot, a new entry is created in the VAT to record the directory name and the current system time as an index node. In the VAT, the index information consists of the recorded directory name and the current system time. The subdirectory inode number and position are recorded under the index. In particular, when the directory is updated after the snapshot is created, a new inode is generated. The updated inode is not recursively backed up and updated. An entry is added to the corresponding index to record the location of the latest metadata stored in the version segment area, and the latest inode node number and actual address are stored in the VAT table. This information is crucial for subsequent data recovery from the snapshot. Through the above method, the impact on active data is minimized and the efficiency of snapshot creation is improved.
[0031] Figure 2 A schematic diagram of the field contents of a version address table provided by an exemplary embodiment of the present invention is shown in FIG. Figure 2 As shown in the figure, the version address table contains the directory snapshot name and the current system time. For example, dir in / dir1, time1 is the abbreviation of "directory", which means "directory", and time1 is the current system time. In addition, the subdirectory inode number and subdirectory inode position at time1 are also recorded, such as subdirectory 1 inode number, position, ..., subdirectory ninode number, position. Later, / dir2, time2, ..., / dirn, timen can be recorded. Each index node can contain subdirectory 1 inode number, position, ..., subdirectory ninode number, position.
[0032] S300: Store index nodes based on a chain management structure to store directory snapshots of different versions.
[0033] Each index node of the chain management structure includes necessary information when creating a directory snapshot, a timestamp of the directory snapshot, a pointer to a data block, and a pointer to the address of the next directory snapshot.
[0034] Inode (index node) is a file system data structure used to store file metadata in Unix and Unix-like systems (such as Linux). Metadata refers to data about a file, not the file name and file content itself. The inode contains information such as the file type (such as regular file, directory, character device, etc.), size, creation and modification time, number of links (how many file names point to this node), data block location, etc., but does not include the file name.
[0035] A chain management method is introduced in the file system to efficiently maintain and operate multiple versions of snapshots. The original directory inode is used as the head node of the snapshot chain for snapshot chain addressing. The linked list adopts the LRU (Least Recently Used, page replacement algorithm) form. The newly created snapshot node is inserted into the head of the linked list. The VAT saves the mapping from the directory to the inode address of the latest snapshot point. The confirmation of different historical versions is achieved by accessing the snapshot chain. Each node is an independent entity in the chain structure, containing the necessary information when creating the snapshot, the timestamp of the snapshot, the pointer to the data block, and the pointer to the next snapshot address. When the file system creates a new snapshot, a new child node is added to the node at the head of the linked list. In the metadata of the new node, the pointer to the data block is initially shared with its parent node until the data block is modified. The write-time copy technology is used to separate the data block to ensure the integrity of the snapshot. Users browse historical snapshots by traversing the linked list. Since each node contains complete snapshot information, it is possible to quickly locate any historical state and restore data from it. The chain management method optimizes the use of storage space, simplifies snapshot creation and browsing, and supports fast data recovery.
[0036] In one embodiment, the data storage method based on snapshot technology may also include: recording the number of times different data blocks are referenced by directory snapshots; when a directory snapshot is created, using a counter to increase the number of references to the data block by one; when the directory snapshot is deleted, using a counter to decrease the number of references to the data block by one; when the number of references recorded by the counter of the data block is less than or equal to a preset number and there is no ongoing write operation, marking the data block as invalid for recycling.
[0037] The I / O overhead caused by snapshot operations requires the modification of the garbage collection mechanism to automatically identify and recycle snapshot data that is no longer needed. For example, a data structure is created in memory to record the number of times different data blocks are referenced by snapshots. The reference count is incremented by one each time a snapshot is created; when a snapshot is deleted, the counter is decremented by one. Periodically or when the system load is low, analyze which data blocks are part of the current system working set and which data blocks are only referenced by old snapshots. A data block with a counter of 0 indicates that the current block has no directory snapshot reference. If there is no ongoing write operation, it is marked as invalid and can be safely recycled. This data structure is obtained by traversing the directory tree and written to the flash disk asynchronously at regular intervals. After the system is started, the data structure is verified when the load is low. The marking of invalid blocks is not only based on the off-site updates made for data modification, but also needs to consider the number of data block references. A reference greater than 1 means that at least one snapshot references the current data block and cannot be marked invalid.
[0038] In one embodiment, a data storage method based on snapshot technology may include: when a data block with a reference count greater than a preset number of times is migrated, a pointer is added to the data block to point to the parent node corresponding to the data block, and the first version of the parent directory containing the file is found by indexing upward, and then other related versions are found by tracking directory snapshots, and the corresponding address is addressed for updating.
[0039] In order to reduce the overhead of data migration, a pointer is added to the data block to point to its parent node. By indexing upward, the first version of the parent directory containing the file is found, and then other related versions are found by tracking the directory snapshot chain. The corresponding addresses are addressed and updated, thereby balancing the performance impact of snapshot creation and daily file operations, improving the I / O performance of the file system under the snapshot function, and improving the garbage collection mechanism, thereby reducing the I / O overhead caused by frequent snapshot creation.
[0040] In one embodiment, the data storage method based on snapshot technology may also include: adding a snapshot time field of 32-bit int type in the data structure; wherein the snapshot time field is used to distinguish whether it is a snapshot node; for non-snapshot nodes, the snapshot time field is set to a default value; for snapshot nodes, it is set to the time when the index node is created; wherein, for the same directory, the snapshot time field is a monotonically increasing value and is consistent with the system time, so as to determine the snapshot version to which the index stage belongs.
[0041] The version segment contains metadata for creating a directory snapshot, and mainly stores the inode updated after creating the directory snapshot. F2FS manages node differentiation, and the key data structure for distinguishing which type of node it is is node_footer. In order to implement snapshot version management, it is necessary to add a 32-bit int type snap_time field (snapshot time field) to the node_footer data structure to distinguish whether it is a snapshot node. For non-snapshot nodes, it is set to the default value of 0, and for snapshot nodes, it is set to the time when the inode was created. For the same directory, snap_time is a monotonically increasing value and is consistent with the system time. It can be used to determine which version of the snapshot the inode belongs to. Add the snapshot chain pointer field snap_point to manage multiple versions of snapshots for the same directory. The original inode of the directory is used as the head node of the snapshot chain, and its snap_point points to the node saved by the previous version until it points to the node with the longest history.
[0042] In one embodiment, the data storage method based on snapshot technology may also include: after creating a directory snapshot, when the index node of the sub-directory tree under the directory snapshot is modified, backing up the historical index node information; wherein the historical index node information points to the original data; after creating a directory snapshot, when updating the data, saving the index node pointing to the original data corresponding to the updated data, and generating a new index node at the same time; wherein the updated index node is not recursively backed up and updated; adding an entry under the corresponding index to record the location of the new metadata, and saving it in the version segment area; storing the new index node number and actual address in the version address table to form the modified directory index node number and sub-directory index node position.
[0043] Figure 3 FIG. 1 is a flow chart of modifying a data block provided by an exemplary embodiment of the present invention. Figure 3 As shown, the original inode points to four data blocks A, B, C, and D. A snapshot, namely, snapshot inode, is generated at a certain moment. At this time, the data blocks are not modified, so the data blocks pointed to by the index node and the snapshot are the same. At a certain moment after the snapshot is generated, data block C needs to be modified. Modifying data block C does not mean overwriting data block C, but rewriting data block C' at a new address. After the modification, the index node (inode) points to the latest data blocks, namely A, B, C' and D. However, since the snapshot is generated before the data blocks are modified, the snapshot node (snapshot inode) still points to the four data blocks A, B, C and D.
[0044] In addition, when the update content accumulates to a certain amount after the snapshot is created, the version segment data is updated to the old directory tree in batches, which can improve the efficiency of directory tree access and save VAT space. Figure 4 FIG. 1 is a schematic diagram showing the principle of batch updating a directory tree provided by an exemplary embodiment of the present invention. Figure 4 As shown, the VAT stores the snapshot directory, snapshot creation time, subdirectory 1 inode number, location, and subdirectory 2 inode number and location. When subdirectory 1 and subdirectory 2 are updated, new inode 1 and new inode 2 are generated to replace the old inode in the old directory tree and form a new directory tree.
[0045] In one embodiment, the data storage method based on snapshot technology may also include: before creating a directory snapshot, if the directory snapshot saves the state of the file when it is normally closed in the future, the specified directory will not be modified; before creating a directory snapshot, if the directory snapshot saves the current state of the file, then when the file is opened and each time the file is updated, a mutual exclusion is added when reading and writing the directory in the version address table to check whether the parent directory has created a directory snapshot; wherein, S200 may include: when the parent directory has not been created with a directory snapshot, when creating a directory snapshot in response to a snapshot request instruction, a new entry is created in the version address table to record the directory snapshot name and the current system time as an index node.
[0046] It is possible to allow the creation of directory snapshots when there are files opened in the directory. For example, if the snapshot saves the state of the file when it is normally closed in the future, no additional modification is required. If the snapshot saves the current state of the file, then when the file is opened and each time the file is updated, add mutual exclusion when reading and writing the directory in the VAT table to check whether its parent directory has been snapshotted. If the parent directory has not been snapshotted, execute the command to create a directory snapshot. If the parent directory has been snapshotted, no subdirectory snapshot will be created.
[0047] In addition, when files are updated, they need to be updated in snapshot mode. When creating a snapshot, if there is an open file, the corresponding handle is marked in the memory. During the writing process, the file handle mark is checked to determine the writing mode at a low cost.
[0048] In one embodiment, S300 may include: using the index node of the original directory as the head node of the snapshot chain to perform snapshot chain addressing; the linked list adopts a page replacement algorithm, and when the file system creates a new directory snapshot, a new child node is added to the node at the head of the linked list, and the version address table saves the mapping of the directory to the index node address of the most recent directory snapshot to confirm different historical versions by accessing the snapshot chain; wherein, the pointer of the new child node to the data block is initially shared with the parent node until the data block is modified.
[0049] The snapshot chain is a management method for index nodes. A chain snapshot storage structure is designed. The index node of the original directory is used as the head node of the snapshot chain for snapshot chain addressing. The linked list adopts the LRU (Least Recently Used, page replacement algorithm) form. The newly created snapshot node is inserted into the head of the linked list. The VAT saves the mapping from the directory to the inode address of the most recent snapshot node. The confirmation of different historical versions is achieved by accessing the snapshot chain. Each index node is an independent entity in the chain structure, which contains the necessary information when creating a directory snapshot, the timestamp of the directory snapshot, the pointer to the data block, and the pointer to the address of the next directory snapshot. When the file system creates a new snapshot, a new child node is added to the node at the head of the linked list. In the metadata of the new node, the pointer to the data block is initially shared with its parent node until the data block is modified. The copy-on-write technology is used to separate the data block to ensure the integrity of the snapshot. Users browse historical snapshots by traversing the linked list. Since each node contains complete snapshot information, it is possible to quickly locate any historical state and restore data from it. The chain management method optimizes the use of storage space, simplifies snapshot creation and browsing, and supports fast data recovery.
[0050] In one embodiment, a data storage method based on snapshot technology may include: when updating a node at the head of a linked list, if the update time of the node saved before the update is later than the directory snapshot creation time, replace the node at the head of the linked list; if the update time of the node saved before the update is earlier than the directory snapshot creation time or a preset time, add a new index node and point to the existing index node, and add the index information of the new index node to the version address table.
[0051] When updating the head node of the linked list, if the update time of the latest node saved before the update is later than the snapshot creation time, it means that the latest inode is updated after the snapshot is created and needs to be overwritten, that is, the head node is replaced. If the creation time of the latest inode is earlier than the snapshot creation time or is 0, a new inode is added and points to the existing inode. At the same time, the index information of the new inode is added to the VAT table.
[0052] Figure 5 FIG. 1 is a schematic diagram showing the principle of querying and managing multi-version snapshots provided by an exemplary embodiment of the present invention. Figure 5As shown in the figure, ①T1 is the original state of the data. At T1, the user applies to create a snapshot. At this time, a snapshot metadata node is first generated, that is, the snap1(t1) node at T2. Then the system records the directory snapshot name and creation time in the VAT. At this time, there is no backup operation of the directory file inode. In the figure, except for the last row of data blocks A and B, the blocks above represent index nodes. ②T2 is the time to modify the file that creates the snapshot directory, then the directory inode and the corresponding data block B are modified. At this time, a new inode is created to form a new data block B`, which records the inode creation time and the pointer to the original inode. However, due to the existence of the snapshot, the original block is retained, and the snap1(t1) node is created before the data block B` is modified, so the snap1(t1) node still points to the original data block A and the original data block B address. ③ At T3, a snapshot is created again, similar to the snapshot creation process at T1. The snap2(t3) node is generated and inserted into the head of the linked list. Since the snap2(t3) node is generated after the data block B is modified, the snap2(t3) node and inode point to the modified data blocks A and B` at the same time. ④ At T4, the snapshot directory is modified again, which is the same as the corresponding operation at T2. A new inode is created, pointing to data blocks A and B`. Since the snap1(t1) node and snap2(t3) node are both created before the data block B` is modified, the snap1(t1) node still points to the original data blocks A and B, and the snap2(t3) node still points to the original data blocks A and B`.
[0053] In one embodiment, a data storage method based on snapshot technology may include: when accessing a directory snapshot, based on the path information, if the directory snapshot or the parent directory corresponding to the directory snapshot is in the version address table, then based on retrieving the original index node information, checking whether there is new metadata in the version address table; if the node at the head of the linked list is updated after the directory snapshot is created, the updated metadata recorded in the version address table is used.
[0054] When the operating system accesses a directory, based on the path information, if the directory or its parent directory is in the VAT table, it will check whether there is new metadata in the VAT table based on the original inode information. If there is an update after the snapshot is created, the latest metadata information recorded in the VAT table is used. For reading the latest version of data, the latest inode and data can be obtained by combining the VAT table and the directory tree structure. For example, Figure 5As shown in the figure, if you need to obtain the snapshot content created at time T2, according to the latest inode information, if the creation time is later than the snapshot time, you need to obtain the previous inode and corresponding data according to the linked list. On the inode linked list, the inode with a creation time of 0 (original state) or earlier than T2 is the state when the snapshot was created at time T2.
[0055] Figure 6 is a schematic diagram of a data storage device based on snapshot technology provided by an exemplary embodiment of the present invention. Figure 6 As shown, the data storage device 6 based on snapshot technology includes: a partitioning module 61, which is used to partition the file system disk layout to obtain a metadata area and a main area; wherein the metadata area includes a version address table, and the main area includes a storage index node segment area, a data segment area and a version segment area; a creation module 62, which is used to create a new entry in the version address table when creating a directory snapshot in response to a snapshot request instruction, and record the directory snapshot name and the current system time as an index node; wherein the index node is used to record the directory index node number and the sub-directory index node position at the time of sub-snapshot creation; a storage module 63, which is used to store index nodes based on a chain management structure to store directory snapshots of different versions; wherein each index node of the chain management structure includes necessary information when creating a directory snapshot, a timestamp of the directory snapshot, a pointer to a data block, and a pointer to the address of the next directory snapshot.
[0056] The data storage device based on snapshot technology provided by the present invention supports fine-grained and lightweight snapshots at the directory level, and provides an efficient and reliable data protection mechanism. It enables users to perform directory snapshot storage for key data, reduce storage fragmentation, save storage resources, improve data access speed and overall system operation efficiency, and maintain the reliability and timeliness of data protection.
[0057] In one embodiment, the data storage device 6 based on snapshot technology can be configured to: record the number of times different data blocks are referenced by directory snapshots; when a directory snapshot is created, a counter is used to increase the number of references of the data block by one; when the directory snapshot is deleted, a counter is used to reduce the number of references of the data block by one; when the number of references recorded by the counter of the data block is less than or equal to a preset number and there is no ongoing write operation, the data block is marked as invalid for recycling.
[0058] In one embodiment, the data storage device 6 based on snapshot technology can be configured as follows: when a data block with a reference count greater than a preset number of times is migrated, a pointer is added to the data block to point to the parent node corresponding to the data block, and the first version of the parent directory containing the file is found by indexing upward, and then other related versions are found by tracking directory snapshots, and the corresponding address is addressed for updating.
[0059] In one embodiment, the data storage device 6 based on snapshot technology can be configured as follows: adding a 32-bit int type snapshot time field in the data structure; wherein the snapshot time field is used to distinguish whether it is a snapshot node; for non-snapshot nodes, the snapshot time field is set to a default value; for snapshot nodes, it is set to the time when the index node is created; wherein, for the same directory, the snapshot time field is a monotonically increasing value and is consistent with the system time, so as to determine the snapshot version to which the index stage belongs.
[0060] In one embodiment, the data storage device 6 based on snapshot technology can be configured as follows: after creating a directory snapshot, when the index node of the sub-directory tree under the directory snapshot is modified, the historical index node information is backed up; wherein the historical index node information points to the original data; after creating a directory snapshot, when the data is updated, the index node pointing to the original data corresponding to the updated data is saved, and a new index node is generated at the same time; wherein the updated index node is not recursively backed up and updated; an entry is added under the corresponding index to record the location of the new metadata, and is saved in the version segment area; the new index node number and actual address are stored in the version address table to form the modified directory index node number and sub-directory index node position.
[0061] In one embodiment, the data storage device 6 based on snapshot technology can be configured as follows: before creating a directory snapshot, if the directory snapshot saves the state of the file when it is normally closed in the future, the specified directory will not be modified; before creating a directory snapshot, if the directory snapshot saves the current state of the file, then when the file is opened and each time the file is updated, a mutual exclusion is added when reading and writing the directory in the version address table to check whether the parent directory has already created a directory snapshot; wherein the creation module 62 can be correspondingly configured as follows: when the parent directory has not been created with a directory snapshot, when creating a directory snapshot in response to a snapshot request instruction, a new entry is created in the version address table to record the directory snapshot name and the current system time as an index node.
[0062] In one embodiment, the storage module 63 can be configured as follows: using the index node of the original directory as the head node of the snapshot chain for snapshot chain addressing; the linked list uses a page replacement algorithm, and when the file system creates a new directory snapshot, a new child node is added to the node at the head of the linked list, and the version address table saves the mapping of the directory to the index node address of the most recent directory snapshot to confirm different historical versions by accessing the snapshot chain; wherein, the pointer of the new child node to the data block is initially shared with the parent node until the data block is modified.
[0063] In one embodiment, the data storage device 6 based on snapshot technology can be configured as follows: when updating the node at the head of the linked list, if the update time of the node saved before the update is later than the directory snapshot creation time, the node at the head of the linked list is replaced; if the update time of the node saved before the update is earlier than the directory snapshot creation time or the preset time, a new index node is added and points to the existing index node, and the index information of the new index node is added to the version address table.
[0064] In one embodiment, the data storage device 6 based on snapshot technology can be configured as follows: when accessing a directory snapshot, based on the path information, if the directory snapshot or the parent directory corresponding to the directory snapshot is in the version address table, then on the basis of retrieving the original index node information, check whether there is new metadata in the version address table; if the node at the head of the linked list is updated after the directory snapshot is created, the updated metadata recorded in the version address table is used.
[0065] The embodiment of the present invention provides a data storage device based on snapshot technology. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. From the hardware level, in addition to the CPU, memory, network interface, and non-volatile memory, the device in the embodiment where the device is located can generally include other hardware, such as a forwarding chip responsible for processing messages, etc. Taking software implementation as an example, as a device in a logical sense, it is formed by the CPU of the device where it is located reading the corresponding computer program instructions in the non-volatile memory into the memory for execution.
[0066] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and the computer program is used to execute the data storage method based on snapshot technology in any of the above embodiments.
[0067] In addition to the above-mentioned methods and devices, an embodiment of the present invention may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the data storage method based on snapshot technology according to various embodiments of the present invention described in the above "Exemplary Method" section of this specification.
[0068] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: a processor; a memory for storing instructions executable by the processor; and the processor for executing the data storage method based on snapshot technology of any of the above embodiments.
[0069] In addition, an embodiment of the present invention may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the steps of the data storage method based on snapshot technology according to various embodiments of the present invention described in the above "Exemplary Method" section of this specification.
[0070] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A data storage method based on snapshot technology, characterized in that: include: Divide the file system disk layout to obtain a metadata area and a main area; wherein the metadata area includes a version address table, and the main area includes a storage index node segment area, a data segment area, and a version segment area; When creating a directory snapshot in response to a snapshot request instruction, a new entry is created in the version address table, recording the directory snapshot name and the current system time as an index node; wherein the index node is used to record the directory index node number and the sub-directory index node position at the time of sub-snapshot creation; Index nodes are stored based on a chain management structure to store directory snapshots of different versions; wherein each index node of the chain management structure includes necessary information when creating a directory snapshot, a timestamp of the directory snapshot, a pointer to a data block, and a pointer to the address of the next directory snapshot.
2. The data storage method based on snapshot technology according to claim 1, characterized in that: Data storage methods based on snapshot technology also include: Record the number of times different data blocks are referenced by directory snapshots; When creating a directory snapshot, a counter is used to increase the number of references to the data block by one; When a directory snapshot is deleted, a counter is used to reduce the number of references to the data block by one; When the number of references recorded by the counter of a data block is less than or equal to the preset number and there is no ongoing write operation, the data block is marked as invalid for recycling.
3. The data storage method based on snapshot technology according to claim 2, characterized in that: Data storage methods based on snapshot technology include: When a data block with a reference count greater than a preset number is migrated, a pointer is added to the data block to point to the parent node corresponding to the data block. By indexing upward, the first version of the parent directory containing the file is found, and then other related versions are found by tracking directory snapshots, and the corresponding addresses are addressed for updating.
4. The data storage method based on snapshot technology according to claim 1, characterized in that: Data storage methods based on snapshot technology also include: Add a 32-bit int type snapshot time field to the data structure; wherein the snapshot time field is used to distinguish whether it is a snapshot node; For non-snapshot nodes, set the snapshot time field to the default value; For snapshot nodes, it is set to the time when the index node was created; For the same directory, the snapshot time domain is a monotonically increasing value and is consistent with the system time to determine the directory snapshot version to which the indexing phase belongs.
5. The data storage method based on snapshot technology according to claim 1, characterized in that: Data storage methods based on snapshot technology also include: After creating a directory snapshot, when the index node of the subdirectory tree under the directory snapshot is modified, the historical index node information is backed up; wherein the historical index node information points to the original data; After creating a directory snapshot, when data is updated, the index node pointing to the original data corresponding to the updated data is saved, and a new index node is generated at the same time; wherein, the updated index node is not recursively backed up and updated; Add an entry under the corresponding index to record the location of the new metadata and save it in the version segment area; The new index node number and actual address are stored in the version address table to form the modified directory index node number and subdirectory index node position.
6. The data storage method based on snapshot technology according to claim 1, characterized in that: Data storage methods based on snapshot technology also include: Before creating a directory snapshot, if the directory snapshot saves the state of the file when it is normally closed in the future, the specified directory will not be modified; Before creating a directory snapshot, if the directory snapshot saves the current file status, then when the file is opened and each time the file is updated, add a mutual exclusion when reading and writing the directory in the version address table to check whether the parent directory has created a directory snapshot; When a directory snapshot is created in response to a snapshot request instruction, a new entry is created in the version address table to record the directory snapshot name and the current system time as an index node, including: When a directory snapshot has not been created for the parent directory, when a directory snapshot is created in response to a snapshot request instruction, a new entry is created in the version address table to record the directory snapshot name and the current system time as an index node.
7. The data storage method based on snapshot technology according to claim 1, characterized in that: Store index nodes based on a chain management structure to store different versions of directory snapshots, including: Use the index node of the original directory as the head node of the snapshot chain to perform snapshot chain addressing; The linked list uses a page replacement algorithm. When the file system creates a new directory snapshot, a new child node is added to the node at the head of the linked list. The version address table stores the mapping of the directory to the index node address of the most recent directory snapshot to confirm different historical versions by accessing the snapshot chain. Among them, the pointer of the new child node to the data block is initially shared with the parent node until the data block is modified.
8. The data storage method based on snapshot technology according to claim 7, characterized in that: Data storage methods based on snapshot technology include: When updating the node at the head of the linked list, if the update time of the node saved before the update is later than the directory snapshot creation time, the node at the head of the linked list is replaced; If the update time of the node saved before the update is earlier than the directory snapshot creation time or the preset time, a new index node is added and points to the existing index node, and the index information of the new index node is added to the version address table.
9. The data storage method based on snapshot technology according to claim 1, characterized in that: Data storage methods based on snapshot technology include: When accessing a directory snapshot, based on the path information, if the directory snapshot or the parent directory corresponding to the directory snapshot is in the version address table, then based on retrieving the original index node information, check whether there is new metadata in the version address table; If the node at the head of the linked list is updated after the directory snapshot is created, the updated metadata recorded in the version address table is used.
10. A data storage device based on snapshot technology, characterized in that: include: A partitioning module, used to partition the file system disk layout to obtain a metadata area and a main area; wherein the metadata area includes a version address table, and the main area includes a storage index node segment area, a data segment area, and a version segment area; A creation module, for creating a new entry in a version address table when creating a directory snapshot in response to a snapshot request instruction, recording the directory snapshot name and the current system time as an index node; wherein the index node is used to record the directory index node number and the sub-directory index node position at the time of sub-snapshot creation; A storage module is used to store index nodes based on a chain management structure to store directory snapshots of different versions; wherein each index node of the chain management structure includes necessary information when creating a directory snapshot, a timestamp of the directory snapshot, a pointer to a data block, and a pointer to the address of the next directory snapshot.
Citation Information
Cited By
Metadata snapshot increment management method and device of distributed file system
CN122412371A
