Snapshot optimization method and device, electronic equipment and storage medium
By setting a judgment flag value and bitmap for the snapshot, the snapshot deletion process is optimized, solving the problem of slow snapshot deletion in ROW snapshots and achieving faster snapshot deletion and higher storage performance.
Patent Information
- Application Number
- CN202511668855.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-01-06
AI Technical Summary
In existing technologies, ROW snapshots suffer from slow deletion speeds and impact system performance due to the interdependence between multiple snapshots and the intertwining of data and business data.
By setting a judgment flag value and bitmap for the snapshot, it can be determined whether the snapshot can be deleted directly, and the data changes can be quickly verified by comparing the bitmap, thus optimizing the snapshot deletion process.
It accelerates snapshot deletion, improves storage performance, and avoids wasting time due to snapshot dependency analysis.
Smart Images

Figure CN121277751A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage, and in particular to snapshot optimization methods, apparatus, electronic devices, and storage media. Background Technology
[0002] In the context of big data, the amount of data is increasing daily, and the importance of data protection is becoming increasingly prominent.
[0003] Snapshot technology is widely used due to its ability to efficiently handle "soft disasters" (such as program bugs, virus attacks, data logic errors caused by operational mistakes, or data inaccessibility). By creating multiple snapshots for a Logical Unit Number (LUN), with each snapshot corresponding to the data of that LUN at a specific point in time, data can be recovered by restoring to a snapshot at an undamaged point in time when a soft disaster occurs, thereby achieving data protection.
[0004] However, as the number of snapshots continues to accumulate, some snapshots need to be deleted periodically to free up storage space. Snapshot deletion speed becomes a key performance indicator affecting system performance and business operations. Current snapshot implementation schemes mostly use Redirect-On-Write (ROW) snapshots. In ROW snapshots, multiple snapshots are interdependent, and snapshot data and business data are intertwined, which leads to the problem of slow snapshot deletion. Summary of the Invention
[0005] In view of this, embodiments of this application provide a snapshot optimization method, apparatus, electronic device, and storage medium to improve snapshot deletion speed and optimize storage performance.
[0006] This application provides a snapshot optimization method, which is applied to a storage device, and the method includes: When creating a snapshot for any logical unit number (LUN), if the first snapshot created is the first snapshot of that LUN, the judgment flag value of the first snapshot is set to the first value; if the first snapshot is not the first snapshot of that LUN, the judgment flag value of the first snapshot is set to the second value. Wherein, when the judgment flag value of the first snapshot is the first value, it indicates that the snapshot can be deleted directly; when the judgment flag value of the first snapshot is the second value, it indicates that the snapshot cannot be deleted directly. A bitmap for the first snapshot is created, and the initial value of each bit in the bitmap is set to the fourth value. There is a one-to-one correspondence between the bits in the bitmap and the data blocks represented by the logical block addresses (LBAs) in the LUN. When it is determined to add an operation record to the first snapshot, the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record is changed from the fourth value to the third value. Specifically, if the value of any bit in the bitmap of any snapshot is the third value, it indicates that the data block represented by the LBA corresponding to that bit has undergone data changes within the snapshot time period corresponding to that snapshot. If the value of any bit in the bitmap of any snapshot is the fourth value, it indicates that the data block represented by the LBA corresponding to that bit has not undergone data changes within the snapshot time period corresponding to that snapshot. If the first snapshot is not the first or second snapshot of the LUN, the bitmaps of the second and third snapshots are compared to redetermine the judgment value of the second snapshot; the second snapshot is the snapshot preceding the first snapshot among all snapshots of the LUN, and the third snapshot is the snapshot preceding the second snapshot among all snapshots of the LUN. For a target snapshot to be deleted, the target snapshot is deleted based on its judgment identifier value and its bitmap.
[0007] This application embodiment also provides a snapshot optimization apparatus, the method being applied to a storage device, the apparatus comprising: The snapshot creation module is used to, when creating a snapshot for any logical unit number LUN, set the judgment flag value of the first snapshot to a first value if the first snapshot created is the first snapshot of the LUN; if the first snapshot is not the first snapshot of the LUN, set the judgment flag value of the first snapshot to a second value; wherein, when the judgment flag value of the first snapshot is the first value, it indicates that the snapshot can be directly deleted, and when the judgment flag value of the first snapshot is the second value, it indicates that the snapshot cannot be directly deleted. The bitmap creation module creates a bitmap for the first snapshot and sets the initial value of each bit in the bitmap to the fourth value. There is a one-to-one correspondence between the bits in the bitmap and the data blocks represented by the logical block addresses (LBAs) in the LUN. When it is determined to add an operation record to the first snapshot, the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record is changed from the fourth value to the third value. Specifically, if the value of any bit in the bitmap of any snapshot is the third value, it indicates that the data block represented by the LBA corresponding to that bit has undergone data changes within the snapshot time period corresponding to that snapshot. If the value of any bit in the bitmap of any snapshot is the fourth value, it indicates that the data block represented by the LBA corresponding to that bit has not undergone data changes within the snapshot time period corresponding to that snapshot. The identifier determination module, when the first snapshot is not the first or second snapshot of the LUN, compares the bitmaps of the second and third snapshots to redetermine the judgment identifier value of the second snapshot; the second snapshot is the snapshot preceding the first snapshot among all snapshots of the LUN, and the third snapshot is the snapshot preceding the second snapshot among all snapshots of the LUN; The deletion module is used to delete a target snapshot based on its identification value and bitmap.
[0008] This application also provides an electronic device, including: a processor and a memory for storing computer program instructions, which, when executed by the processor, cause the processor to perform the steps of the method described above.
[0009] This application also provides a machine-readable storage medium storing computer program instructions that, when executed, enable the implementation of the steps described above.
[0010] As can be seen from the above technical solution, firstly, when creating a snapshot for any logical unit number (LUN), if it is determined that the currently created snapshot (i.e., the first snapshot) is the first snapshot of that LUN, then the judgment flag value of that snapshot is set to the first value; if it is determined that the snapshot is not the first snapshot of that LUN, then the judgment flag value of that snapshot is set to the second value. Then, when it is determined that the first snapshot is not the first or second snapshot of that LUN, the operation flag value of the second snapshot is re-determined by comparing the bitmaps of the previous snapshot (i.e., the second snapshot) and the snapshot before that previous snapshot (i.e., the third snapshot) among all snapshots of that LUN. In this way, each snapshot has a judgment flag value indicating whether the snapshot can be directly deleted. This allows subsequent deletion of the target snapshot; if the judgment flag value of the target snapshot is the first value, then the snapshot is directly deleted without needing to spend time analyzing snapshot dependencies, thus accelerating snapshot deletion.
[0011] Furthermore, a bitmap is created simultaneously with the establishment of the first snapshot. Each bit in this bitmap corresponds one-to-one with the data block represented by the logical block address (LBA) in the LUN. The initial value of each bit in the bitmap is set to the fourth value. When adding an operation record to the first snapshot, the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record is changed from the fourth value to the third value. In this way, the value of each bit in the bitmap of each snapshot indicates whether the data block represented by the LBA corresponding to that bit has changed within the snapshot time period. This allows for rapid data verification by comparing the bitmap of the target snapshot when deleting it, even if the target snapshot's judgment flag value is the second value. Compared to checking operation records one by one in related technologies, this significantly speeds up snapshot deletion. Attached Figure Description
[0012] Figure 1 A schematic diagram illustrating the creation of a ROW snapshot for LUNA as provided in the embodiments of this application; Figure 2 A schematic flowchart illustrating the snapshot optimization method provided in this application embodiment; Figure 3 A schematic diagram illustrating the process of deleting a target snapshot provided in an embodiment of this application; Figure 4 A schematic diagram of the sorting and merging process provided for embodiments of this application; Figure 5 This is a schematic diagram of the device provided in the embodiments of this application; Figure 6 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0013] To enable those skilled in the art to better understand the technical solutions provided in the embodiments of this application, and to make the above-mentioned objectives, features and advantages of the embodiments of this application more apparent and understandable, the technical solutions in the embodiments of this application will be further described in detail below with reference to the accompanying drawings.
[0014] Before introducing the method provided in the embodiments of this application, let's first combine... Figure 1 The process of creating a ROW snapshot is shown, and the technical issues involved are explained: Before introducing the method provided in the embodiments of this application, let's first combine... Figure 1 The process of creating a ROW snapshot is shown, and the technical issues involved are explained: See Figure 1 , Figure 1 This is a schematic diagram illustrating the creation of a ROW snapshot for LUNA provided in the embodiments of this application.
[0015] LUNA initiates a ROW snapshot, and the specific process for generating a snapshot includes the following steps.
[0016] 1. See Figure 1 As shown in (a), a snapshot S1 is created for LUNA at time T1, and the initial content of snapshot S1 is empty.
[0017] The mapping table between Logical Block Addressing (LBA) and Physical Block Addressing (PBA) in LUNA is as follows: LBA1 points to PBA1 (LBA1→PBA1), LBA2 points to PBA2 (LBA2→PBA2).
[0018] At this time, the data at time T1 in LBA1 is A, and the data at time T1 in LBA2 is B.
[0019] 2. See Figure 1 As shown in (b), for LUNA, new data A1 is written to LBA1.
[0020] Write the new data A1 to the idle PBAn, then modify the LUNA mapping table so that LBA1 points to PBAn. The new LUNA mapping table is as follows: LBA1→PBAn; LBA2→PBA2.
[0021] At this point, the data in LBA1 is A1.
[0022] An operation record pointing from LBA1 to PBA1 (LBA1→PBA1) will be added to snapshot S1. If data recovery is subsequently performed using the snapshot, the data A at time T1 can be found through the operation record LBA1→PBA1. The operation record in snapshot S1 is: LBA1→PBA1.
[0023] 3. See Figure 1 As shown in (c), when new data A2 needs to be written to LBA1 for LUNA, since snapshot S1 has already recorded the data at time T1, A2 can be directly written to PBAn.
[0024] The mapping table in LUNA and the records in snapshot S1 remain unchanged.
[0025] 4. See Figure 1 As shown in (d), a snapshot S2 is created for LUNA at time T2, and the initial content of snapshot S2 is empty.
[0026] 5. See Figure 1As shown in (e), for LUNA, LBA1 needs to be written to A3 and LBA2 needs to be written to B1.
[0027] At this point, write the new data A3 to the idle PBAR, then modify the LUNA mapping table so that LBA1 points to PBAR. Write the new data B1 to the idle PBAT, then modify the LUNA mapping table so that LBA2 points to PBAT. The new LUNA mapping table is as follows: LBA1→PBAr; LBA2→PBAt.
[0028] At this point, the data in LBA1 is A3, and the data in LBA2 is B1.
[0029] Afterwards, operation records for LBA1→PBAn and LBA2→PBA2 will be added to snapshot S2.
[0030] The operation records in snapshot S2 are as follows: LBA1→PBAn; LBA2→PBA2; This process continues, creating more ROW snapshots.
[0031] As described above, in a ROW snapshot, once the snapshot is created, when a data block needs to be modified for the first time, it is not directly overwritten in the original location. Instead, the new data is written to a completely new location, and the metadata pointer is redirected to point to this new location. The original LBA and PBA mapping relationship before redirection is stored in the snapshot as an operation record for subsequent data recovery.
[0032] ROW snapshots are incremental snapshots. The operation records in each snapshot record the data changes between that snapshot and the next snapshot (the changes are reflected by recording the mapping relationship from LBA to PBA before the data changes). For example, the operation records in snapshot S1 created at time T1 record the data changes from time T1 to time T2, and the operation records in snapshot S2 created at time T2 record the data changes from time T2 to the current time.
[0033] Therefore, older snapshots depend on newer snapshots, and multiple snapshots in a ROW snapshot are interdependent, with snapshot data and business data intertwined. This complex dependency and interweaving makes it impossible to easily distinguish between snapshots, thus preventing direct deletion of snapshots that need to be deleted. For example, the mapping relationship LBA2→PBA2 before the data change from B to B1 on PBA2 is only recorded in snapshot S2. If snapshot S2 is to be deleted, the information that LBA2→PBA2 indicates the data B on PBA2 at time T2 will be lost. This will affect snapshot-based rollback, leading to data recovery failure. Therefore, snapshots cannot be deleted quickly.
[0034] Based on this, embodiments of this application provide a snapshot optimization method, apparatus, electronic device, and storage medium to improve snapshot deletion speed.
[0035] The method provided in the embodiments of this application is described in detail below: See Figure 2 , Figure 2 This is a flowchart illustrating the snapshot optimization method provided in an embodiment of this application. As one embodiment, the execution subject of this method can be a storage device.
[0036] like Figure 2 As shown, the process may include the following steps: S201, when creating a snapshot for any logical unit number LUN, if the first snapshot created is the first snapshot of the LUN, then the judgment flag value of the first snapshot is set to the first value; if the first snapshot is not the first snapshot of the LUN, then the judgment flag value of the first snapshot is set to the second value.
[0037] In this embodiment, when the judgment flag of the first snapshot is a first value, it indicates that the first snapshot can be deleted directly; when the judgment flag of the first snapshot is a second value, it indicates that the first snapshot cannot be deleted directly.
[0038] Specifically, after configuring a snapshot for any LUN, a new snapshot is created for that LUN at regular intervals. When creating any snapshot, in addition to the standard configuration in related technologies, a judgment flag value needs to be set for that snapshot (i.e., the snapshot carries a judgment flag value). If the snapshot is the first snapshot of the LUN, the judgment flag value is set to a first value, such as 1; if the snapshot is not the first snapshot of the LUN, the judgment flag value is set to a second value, such as 0. Here, the first value is different from the second value.
[0039] Considering that data recovery using snapshot rollback proceeds by gradually rolling back the first snapshot from the last snapshot, and the first snapshot in a LUN is the last snapshot to be rolled back during rollback, it doesn't need to be the basis for other snapshots. Therefore, directly deleting the first snapshot will not affect other snapshots created later in that LUN. Thus, if the currently created first snapshot is the first snapshot of that LUN, the judgment flag value is set to the first value, such as 1. However, snapshots other than the first snapshot in that LUN need to be used as the basis for other snapshots during rollback. Therefore, directly deleting a snapshot other than the first snapshot will affect the snapshots associated with it in that LUN. Therefore, if the currently created first snapshot is not the first snapshot of that LUN, the judgment flag value is set to the second value, such as 0. In this way, by setting the judgment flag value, it directly indicates whether the currently created snapshot can be directly deleted, providing a basis for accelerating snapshot deletion in the future.
[0040] S202, establish a bitmap for the first snapshot, and set the initial value of each bit in the bitmap to the fourth value; there is a one-to-one correspondence between the bits in the bitmap and the data blocks represented by the logical block addresses (LBA) in the LUN; when it is determined to add an operation record to the first snapshot, change the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record from the fourth value to the third value.
[0041] In this embodiment, when the value of any bit in the bitmap of any snapshot is a third value, such as 1, it indicates that the data block represented by the LBA corresponding to that bit has undergone data changes during the snapshot time period corresponding to that snapshot; when the value of any bit in the bitmap of any snapshot is a fourth value, such as 0, it indicates that the data block represented by the LBA corresponding to that bit has not undergone data changes during the snapshot time period corresponding to that snapshot. Optionally, the third value can be equal to the first value, such as both being 1, and the fourth value can be equal to the second value, such as both being 0.
[0042] It should be noted that the snapshot time period corresponding to any snapshot refers to the following: when the snapshot is not the latest snapshot in the LUN to which it belongs, the snapshot time period is the time period between the snapshot creation time and the creation time of the next snapshot of the LUN among all snapshots of that snapshot. When the snapshot is the latest snapshot in the LUN to which it belongs, the snapshot time period is the time period between the snapshot creation time and the latest time.
[0043] Specifically, a bitmap is created simultaneously with the first snapshot. The bits in this bitmap have a one-to-one correspondence with the data blocks represented by the LBAs in the LUN. Each logical block address represents a fixed-size storage block (the storage block size is the same as the block size processed in the snapshot), such as 8KB. The first bit in this bitmap represents the first 8KB space of the LUN, the second bit represents the second 8KB space of the LUN, and so on.
[0044] When the bitmap of the first snapshot is initially created, the value of each bit in the bitmap is the fourth value, such as 0. After the first snapshot is created, before the next snapshot of the LUN is created, when the data of any LBA-represented data block of the LUN changes for the first time, an operation record corresponding to the data block represented by that LBA is added to the first snapshot. The added operation record is the mapping relationship between the LBA and PBA of the data block represented by that LBA before the data modification, as described in related technologies. In this embodiment, when determining to add the operation record of the data block represented by that LBA to the snapshot, the value of the data block represented by that LBA in the bitmap of the first snapshot is changed from the fourth value to the third value (for example, from 0 to 1). In this way, the value of each bit in the bitmap of each snapshot indicates whether the data block represented by the LBA corresponding to that bit has changed during the snapshot time period, thereby providing a basis for accelerating snapshot deletion in the future.
[0045] As described above, operation records are added to the first snapshot only when the data block represented by each LBA undergoes its first data change after the first snapshot is established. Therefore, when a write operation is received, it is necessary to determine whether to add an operation record to the first snapshot. The specific implementation of determining whether to add an operation record to the first snapshot can be a conventional method. For example, after the first snapshot is established, when a write operation is received for that LUN, it is determined whether the data block represented by the LBA involved in the write operation exists in the operation record list of the first snapshot.
[0046] It can also be combined with the value of bits in the bitmap for judgment. For example, after the first snapshot is established, when a write operation is received for the LUN, for each data block represented by an LBA involved in the write operation, the current value of the bit corresponding to the data block represented by that LBA in the bitmap of the first snapshot is obtained. If the current value is the fourth value, it indicates that no operation record has been generated for the data block represented by that LBA in the first snapshot. Therefore, it is determined to add the operation record of the data block represented by that LBA to the first snapshot. If the current value is the third value, it indicates that an operation record has been generated for the data block represented by that LBA in the first snapshot. Therefore, it is determined not to add the operation record of the data block represented by that LBA to the first snapshot.
[0047] S203, if the first snapshot is not the first or second snapshot of the LUN, compare the bitmaps of the second and third snapshots to redetermine the judgment flag value of the second snapshot; the second snapshot is the snapshot preceding the first snapshot among all snapshots of the LUN, and the third snapshot is the snapshot preceding the second snapshot among all snapshots of the LUN.
[0048] In this embodiment, when the currently established first snapshot is not the first or second snapshot of the LUN, upon completion of the first snapshot, it is assumed that the operation records in the previous snapshot (second snapshot) and the snapshot before that (third snapshot) have been solidified (i.e., no new operation records will be added to the second and third snapshots). At this time, the bitmaps of the second and third snapshots have also been solidified. Combining the bitmaps of the second and third snapshots allows us to represent the data changes within their respective time periods. Therefore, by comparing the bitmaps of the second and third snapshots, we can analyze the dependency relationship between the second and third snapshots, re-determine whether the second snapshot can be directly deleted, and characterize this result through a judgment flag value. This allows subsequent deletion of target snapshots where, if the judgment flag value of the target snapshot is the first value, the snapshot is directly deleted without needing to spend time analyzing snapshot dependencies to determine whether the target snapshot can be deleted, thus accelerating snapshot deletion.
[0049] The following example illustrates how the determination flag value for the second snapshot is redefined by comparing the bitmaps of the second and third snapshots: As an example, if the value of each bit in the bitmap of the second snapshot and the bitmap of the third snapshot are the same, then the judgment flag value of the second snapshot is modified to the first value.
[0050] For a data block represented by an LBA that undergoes data changes during the snapshot period of the third snapshot (i.e., from the creation time of the third snapshot to the creation time of the second snapshot), and this same data block also undergoes data changes during the snapshot period of the second snapshot (i.e., from the creation time of the second snapshot to the creation time of the first snapshot), not only does the second snapshot record the mapping relationship between the LBA and PBA of the data block before the data change, but the third snapshot also records this mapping relationship. Deleting the operation record corresponding to the data block represented by the LBA in the second snapshot will not cause data loss on the data block represented by the LBA in the third snapshot, and will not affect subsequent data recovery based on snapshot rollback. Therefore, when the value of each bit in the bitmap of the second snapshot and the bitmap of the third snapshot are the same, it indicates that the data blocks represented by LBAs that undergo data changes during the snapshot period of the third snapshot and the snapshot period of the second snapshot are the same. Directly deleting the second snapshot will not affect subsequent data recovery based on snapshot rollback, thus modifying the judgment flag value of the second snapshot to the first value.
[0051] The above provides a detailed explanation of the criteria for re-determining the second snapshot.
[0052] S204, when determining to delete a target snapshot, the target snapshot is deleted based on the judgment identifier value of the target snapshot and the bitmap in the target snapshot.
[0053] In this embodiment, the target snapshot is any specified snapshot within any specified LUN in this device. The timing for triggering the deletion of the target snapshot follows conventional procedures in related technologies and will not be elaborated here.
[0054] The specific implementation method for deleting the target snapshot in this embodiment will be described in detail later with specific embodiments, and will not be repeated here.
[0055] This concludes the process. Figure 2 The process is shown below.
[0056] pass Figure 2As shown in the process described in this embodiment, firstly, when creating a snapshot for any logical unit number (LUN), if it is determined that the currently created snapshot (i.e., the first snapshot) is the first snapshot of that LUN, then the judgment flag value of that snapshot is set to a first value; if it is determined that the snapshot is not the first snapshot of that LUN, then the judgment flag value of that snapshot is set to a second value. Then, if it is determined that the first snapshot is not the first or second snapshot of that LUN, the operation flag value of the second snapshot is re-determined by comparing the bitmaps of the previous snapshot (i.e., the second snapshot) and the snapshot before that previous snapshot (i.e., the third snapshot) among all snapshots of that LUN. In this way, each snapshot has a judgment flag value indicating whether the snapshot can be directly deleted. This allows subsequent deletion of a target snapshot; if the judgment flag value of the target snapshot is the first value, the snapshot is directly deleted without needing to spend time analyzing snapshot dependencies, thereby accelerating snapshot deletion.
[0057] Furthermore, a bitmap is created simultaneously with the establishment of the first snapshot. Each bit in this bitmap corresponds one-to-one with the data block represented by the logical block address (LBA) in the LUN. The initial value of each bit in the bitmap is set to the fourth value. When adding an operation record to the first snapshot, the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record is changed from the fourth value to the third value. In this way, the value of each bit in the bitmap of each snapshot indicates whether the data block represented by the LBA corresponding to that bit has changed within the snapshot time period. This allows for rapid data verification by comparing the bitmap of the target snapshot when deleting it, even if the target snapshot's judgment flag value is the second value. Compared to checking operation records one by one in related technologies, this significantly speeds up snapshot deletion.
[0058] The following section details the specific implementation of deleting a target snapshot: See Figure 3 , Figure 3 This is a schematic diagram illustrating the process of deleting a target snapshot as provided in an embodiment of this application.
[0059] like Figure 3 As shown, the process may include the following steps: S301, determine whether the target snapshot is the first snapshot of the LUN to which the target snapshot belongs.
[0060] If the execution result of S301 is yes, then execute step S302 below. If the execution result of S301 is yes, then execute step S303 below.
[0061] S302, delete the target snapshot, and modify the judgment flag value of the next snapshot of the target snapshot in all snapshots of the LUN to which the target snapshot belongs to the first value.
[0062] Specifically, if the target snapshot is the first snapshot of its LUN, then the identification value of the first snapshot will definitely be the first value, so the target snapshot can be deleted directly. If the target snapshot is not the first snapshot of its LUN, then the identification value of the target snapshot is needed for determination.
[0063] S303, obtain the judgment flag value of the target snapshot.
[0064] S304. If the judgment flag value of the target snapshot is the first value, the target snapshot is deleted directly.
[0065] S305, when the determination flag value of the target snapshot is the second value, compare the bitmaps of the target snapshot and the fourth snapshot to obtain the target bit located at the same position in the bitmaps of the target snapshot and the fourth snapshot, and the value of both is the third value; release the physical space corresponding to the operation record of the data block represented by the target LBA in the target snapshot, and delete the operation record of the data block represented by the target LBA; and modify the value of the target bit in the bitmap of the target snapshot from the third value to the fourth value; the fourth snapshot is the previous snapshot of the target snapshot among all snapshots of the LUN to which the target snapshot belongs.
[0066] In this embodiment, the bits located at the same position in the bitmap of the target snapshot and the bitmap of the fourth snapshot correspond to the data blocks represented by the same LBA of the LUN. When the values of the corresponding bits for the same LBA in both the bitmap of the target snapshot and the bitmap of the fourth snapshot are the third value, it indicates that the data blocks represented by the LBA have undergone data changes within the time from the establishment time of the fourth snapshot to the establishment time of the target snapshot (the snapshot time period of the target snapshot) and from the establishment time of the target snapshot to the establishment time of the next snapshot of the target snapshot (the snapshot time period of the target snapshot). At this time, not only does the target snapshot record the mapping relationship between the LBA and PBA before the data change on the LBA, but the fourth snapshot also records the mapping relationship between the LBA and PBA before the data change on the data blocks represented by the LBA. Deleting the operation record corresponding to the data blocks represented by the LBA in the target snapshot will not cause data loss on the data blocks represented by the LBA in the fourth snapshot, and will not affect subsequent data recovery based on snapshot rollback. Therefore, the physical space represented by the physical block address PBA corresponding to the data blocks represented by the LBA is released, and the operation record of the data blocks represented by the LBA is deleted. After deleting the operation record, the value of the bit corresponding to the data block represented by the LBA in the bitmap of the target snapshot will be changed from the third value to the fourth value.
[0067] In this embodiment, the physical space release adopts a common method in related technologies, which will not be described in detail here.
[0068] S306, merge the remaining operation records of the target snapshot and the operation records of the fourth snapshot to update the operation records of the fourth snapshot, and sort and merge the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot; then delete the target snapshot.
[0069] In this embodiment, the remaining operation records of the target snapshot and the operation records of the fourth snapshot are merged using a merging method based on relevant technologies, which will not be elaborated here.
[0070] The following section elaborates on the step S306 above, which involves merging the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot: See Figure 4 , Figure 4 This is a schematic diagram of the bitmap sorting and merging process provided in the embodiments of this application.
[0071] like Figure 4 As shown, the process may include the following steps: S401, for each bit in the bitmap of the target snapshot, determine whether the value of the bit is the fourth value.
[0072] If the result of S401 is yes, then proceed to step S402. If the result of S401 is no (that is, the value of the bit is the third value), then proceed directly to step S403.
[0073] In this embodiment, if the bit in the target snapshot has a fourth value, it indicates that the data block represented by the LBA corresponding to the bit has not changed during the snapshot time period of the target snapshot. Therefore, the value of the bit in the bitmap of the fourth snapshot that is at the same position as the bit remains unchanged. That is, if the value of the bit in the bitmap of the fourth snapshot that is at the same position as the bit has a third value, it remains at the third value; if the value of the bit in the bitmap of the fourth snapshot that is at the same position as the bit has a fourth value, it remains at the fourth value.
[0074] If the bit in the target snapshot has a third value, it indicates that the data block represented by the LBA corresponding to this bit has changed during the snapshot time period of the target snapshot. Therefore, the value of the bit in the bitmap of the fourth snapshot that is at the same position as this bit is changed from the fourth value to the third value, or it remains at the third value. That is, if the value of the bit in the bitmap of the fourth snapshot that is at the same position as this bit is the third value, it remains at the third value; if the value of the bit in the bitmap of the fourth snapshot that is at the same position as this bit is the fourth value, it is changed from the fourth value to the third value.
[0075] S402, keep the value of the bit in the same position as the bit in the bitmap of the fourth snapshot unchanged.
[0076] S403, change the value of the bit in the bitmap of the fourth snapshot that is at the same position as the bit to the third value, or keep it at the third value.
[0077] The above provides a detailed explanation of how to organize and merge the bitmaps of the target snapshot and the fourth snapshot to update the bitmap of the fourth snapshot.
[0078] This concludes the description of the method provided in this embodiment. The apparatus provided in this application embodiment will now be described: See Figure 5 , Figure 5 This is a schematic diagram of the device provided in an embodiment of this application. Figure 5 As shown, the device is applied to a storage device, and the device 500 includes: a snapshot creation module 501, a bitmap creation module 502, an identifier determination module 503, and a deletion module 504.
[0079] The snapshot creation module 501 is used to, when creating a snapshot for any logical unit number LUN, set the judgment flag value of the first snapshot to a first value if the first snapshot created is the first snapshot of the LUN; and set the judgment flag value of the first snapshot to a second value if the first snapshot is not the first snapshot of the LUN. Wherein, when the judgment flag value of the first snapshot is the first value, it indicates that the snapshot can be directly deleted; when the judgment flag value of the first snapshot is the second value, it indicates that the snapshot cannot be directly deleted. Bitmap creation module 502 creates a bitmap for the first snapshot and sets the initial value of each bit in the bitmap to the fourth value. There is a one-to-one correspondence between the bits in the bitmap and the data blocks represented by the logical block addresses (LBAs) in the LUN. When it is determined to add an operation record to the first snapshot, the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record is changed from the fourth value to the third value. Specifically, if the value of any bit in the bitmap of any snapshot is the third value, it indicates that the data block represented by the LBA corresponding to that bit has undergone data changes within the snapshot time period corresponding to that snapshot. If the value of any bit in the bitmap of any snapshot is the fourth value, it indicates that the data block represented by the LBA corresponding to that bit has not undergone data changes within the snapshot time period corresponding to that snapshot. The identifier determination module 503, when the first snapshot is not the first or second snapshot of the LUN, compares the bitmaps of the second and third snapshots to redetermine the judgment identifier value of the second snapshot; the second snapshot is the snapshot preceding the first snapshot among all snapshots of the LUN, and the third snapshot is the snapshot preceding the second snapshot among all snapshots of the LUN; The deletion module 504 is used to delete the target snapshot based on the judgment identifier value of the target snapshot and the bitmap of the target snapshot.
[0080] As one embodiment, when the deletion module 504 performs deletion on the target snapshot based on the judgment identifier value and the bitmap of the target snapshot, it is further configured to: If the target snapshot is the first snapshot of the LUN to which the target snapshot belongs, then delete the target snapshot and modify the identification value of the next snapshot of the target snapshot among all snapshots of the LUN to which the target snapshot belongs to the first value. If the target snapshot is not the first snapshot of the LUN to which it belongs, then: If the judgment flag value of the target snapshot is the first value, the target snapshot is deleted directly; When the judgment flag value of the target snapshot is the second value, the bitmaps of the target snapshot and the fourth snapshot are compared to obtain the target bit located at the same position in the bitmaps of the target snapshot and the fourth snapshot, and the value of both is the third value; the physical space corresponding to the operation record of the data block represented by the target LBA in the target snapshot is released, and the operation record of the data block represented by the target LBA is deleted; and the value of the target bit in the bitmap of the target snapshot is changed from the third value to the fourth value; the fourth snapshot is the previous snapshot of the target snapshot among all snapshots of the LUN to which the target snapshot belongs; The remaining operation records of the target snapshot and the operation records of the fourth snapshot are merged to update the operation records of the fourth snapshot. The bitmap of the target snapshot and the bitmap of the fourth snapshot are then sorted and merged to update the bitmap of the fourth snapshot. Finally, the target snapshot is deleted.
[0081] As an example, the deletion module 504, when performing the process of merging and combining the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot, is further configured to: For each bit in the bitmap of the target snapshot, if the value of the bit is the fourth value, then the values of the bits in the bitmap of the fourth snapshot that are at the same position as the bit remain unchanged. If the value of this bit is the third value, then the value of the bit in the same position as this bit in the bitmap of the fourth snapshot will be changed from the fourth value to the third value, or it will remain at the third value.
[0082] As one embodiment, the identifier determination module 503, when performing a comparison of the bitmaps of the second snapshot and the third snapshot to re-determine the identifier value of the second snapshot, is further configured to: If the value of each bit in the bitmap of the second snapshot is the same as that in the bitmap of the third snapshot, then the judgment flag value of the second snapshot is modified to the first value.
[0083] As an example, the bitmap creation module 502, when determining whether to add an operation record to the first snapshot, specifically includes the following steps: After the first snapshot is established, when a write operation is received for the LUN, for each data block represented by the LBA involved in the write operation, the current value of the bit corresponding to the data block represented by the LBA in the bitmap of the first snapshot is obtained; If the current value is the fourth value, then it is determined that an operation record for the data block represented by the LBA will be added to the first snapshot; If the current value is the third value, then it is determined that no operation record of the data block represented by the LBA will be added to the first snapshot.
[0084] This concludes the process. Figure 5 Structural description of the device shown.
[0085] Please see Figure 6 , Figure 6 This is a structural diagram of an electronic device provided in an embodiment of this application. Figure 6 As shown, the hardware structure may include: a processor and a machine-readable storage medium, the machine-readable storage medium storing machine-executable instructions that can be executed by the processor; the processor is used to execute the machine-executable instructions to implement the method disclosed in the above example of this application.
[0086] Based on the same application concept as the above method, this application embodiment also provides a machine-readable storage medium storing a plurality of computer instructions, which, when executed by a processor, can implement the method disclosed in the above examples of this application.
[0087] For example, the aforementioned machine-readable storage medium can be any electronic, magnetic, optical, or other physical storage device that can contain or store information such as executable instructions, data, etc. For instance, machine-readable storage media can be: RAM (Random Access Memory), volatile memory, non-volatile memory, flash memory, storage drives (such as hard disk drives), solid-state drives, any type of storage disk (such as optical discs, DVDs, etc.), or similar storage media, or combinations thereof.
[0088] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A snapshot optimization method, characterized by, The method is applied to a storage device, and the method comprises: When a snapshot is established for any logical unit number (LUN), if a first snapshot currently established is a first snapshot of the LUN, a judgment identifier value of the first snapshot is set to a first value; if the first snapshot is not the first snapshot of the LUN, the judgment identifier value of the first snapshot is set to a second value; wherein when the judgment identifier value of the first snapshot is the first value, it is indicated that the snapshot is allowed to be directly deleted, and when the judgment identifier value of the first snapshot is the second value, it is indicated that the snapshot is prohibited to be directly deleted; a bitmap of the first snapshot is established, and an initial value of a value of each bit in the bitmap is set to a fourth value; the bit in the bitmap and a data block represented by a logical block address (LBA) in the LUN have a one-to-one correspondence; when an operation record is determined to be added to the first snapshot, the value of the bit in the bitmap corresponding to the data block represented by the LBA of the operation record is changed from the fourth value to a third value; wherein when a value of any bit in a bitmap of any snapshot is the third value, it is indicated that the data block represented by the LBA corresponding to the bit has data change in a snapshot time period corresponding to the snapshot; and when a value of any bit in a bitmap of any snapshot is the fourth value, it is indicated that the data block represented by the LBA corresponding to the bit has no data change in a snapshot time period corresponding to the snapshot; when the first snapshot is not the first snapshot or a second snapshot of the LUN, a judgment identifier value of the second snapshot is re-determined by comparing bitmaps of the second snapshot and a third snapshot; the second snapshot is a snapshot preceding the first snapshot among all snapshots of the LUN, and the third snapshot is a snapshot preceding the second snapshot among all snapshots of the LUN; for a target snapshot to be deleted, the target snapshot is deleted based on a judgment identifier value of the target snapshot and a bitmap of the target snapshot.
2. The method of claim 1, wherein, The method for deleting the target snapshot based on the judgment identifier value of the target snapshot and the bitmap of the target snapshot comprises: if the target snapshot is a first snapshot of a LUN to which the target snapshot belongs, the target snapshot is deleted, and a judgment identifier value of a snapshot next to the target snapshot among all snapshots of the LUN to which the target snapshot belongs is modified to the first value; if the target snapshot is not the first snapshot of the LUN to which the target snapshot belongs, the target snapshot is deleted based on the judgment identifier value of the target snapshot and the bitmap of the target snapshot: when the judgment identifier value of the target snapshot is the first value, the target snapshot is directly deleted; when the judgment identifier value of the target snapshot is the second value, a target bit located at the same position and having a value of the third value in the bitmap of the target snapshot and a bitmap of a fourth snapshot is obtained by comparing the bitmap of the target snapshot and the bitmap of the fourth snapshot; a physical space corresponding to an operation record of a target LBA represented by the target bit in the target snapshot is released, the operation record of the target LBA represented by the target bit is deleted, and the value of the target bit in the bitmap of the target snapshot is modified from the third value to the fourth value; the fourth snapshot is a snapshot preceding the target snapshot among all snapshots of the LUN to which the target snapshot belongs; and Merging the operation record of the target snapshot and the operation record of the fourth snapshot to update the operation record of the fourth snapshot, and merging the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot, and then deleting the target snapshot.
3. The method of claim 2, wherein, The merging the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot comprises: If the value of the bit in the bitmap of the target snapshot is the fourth value, the value of the bit in the bitmap of the fourth snapshot in the same position is maintained unchanged; If the value of the bit in the bitmap of the target snapshot is the third value, the value of the bit in the bitmap of the fourth snapshot in the same position is modified from the fourth value to the third value, or maintained at the third value.
4. The method of claim 1, wherein, The re-determining the judgment identification value of the second snapshot by comparing the bitmap of the second snapshot and the bitmap of the third snapshot comprises: If the value of each bit in the bitmap of the second snapshot and the bitmap of the third snapshot is the same, the judgment identification value of the second snapshot is modified to the first value.
5. The method of claim 1, wherein, The determining whether to add the operation record to the first snapshot comprises the following steps: After the first snapshot is established, when a write operation about the LUN is received, for each data block represented by an LBA involved in the write operation, the current value of the bit corresponding to the data block represented by the LBA in the bitmap of the first snapshot is obtained; If the current value is the fourth value, it is determined to add the operation record of the data block represented by the LBA to the first snapshot; If the current value is the third value, it is determined not to add the operation record of the data block represented by the LBA to the first snapshot.
6. The method of claim 1, wherein, The snapshot time period corresponding to any snapshot is determined by the following steps: When the snapshot is not the latest snapshot in the LUN to which the snapshot belongs, the snapshot time period corresponding to the snapshot is the time period between the establishment time of the snapshot and the establishment time of the next snapshot of the snapshot among all snapshots of the LUN; When the snapshot is the latest snapshot in the LUN to which the snapshot belongs, the snapshot time period is the time period between the establishment time of the snapshot and the latest time.
7. A snapshot optimization apparatus, characterized by comprising: The method is applied to a storage device, and the device comprises: A snapshot establishment module is configured to, when a snapshot is established for any logical unit number (LUN), if a first snapshot currently established is the first snapshot of the LUN, set the judgment identification value of the first snapshot to a first value; if the first snapshot is not the first snapshot of the LUN, set the judgment identification value of the first snapshot to a second value; wherein when the judgment identification value of the first snapshot is the first value, it indicates that the snapshot is allowed to be directly deleted, and when the judgment identification value of the first snapshot is the second value, it indicates that the snapshot is prohibited to be directly deleted. The bitmap establishing module establishes a bitmap of the first snapshot, and sets an initial value of a value of each bit in the bitmap to a fourth value. The bits in the bitmap have a one-to-one correspondence with data blocks represented by logical block addresses (LBAs) in the LUN. When it is determined to add an operation record to the first snapshot, the value of a bit in the bitmap corresponding to a data block represented by an LBA of the operation record is changed from the fourth value to a third value. When a value of any bit in a bitmap of any snapshot is the third value, it indicates that a data block represented by the LBA corresponding to the bit has data changes in a snapshot time period corresponding to the snapshot. When a value of any bit in a bitmap of any snapshot is the fourth value, it indicates that a data block represented by the LBA corresponding to the bit has no data changes in a snapshot time period corresponding to the snapshot. The identification determining module re-determines the judgment identification value of the second snapshot by comparing the bitmaps of the second snapshot and a third snapshot when the first snapshot is not the first snapshot or the second snapshot of the LUN. The second snapshot is a snapshot preceding the first snapshot among all snapshots of the LUN, and the third snapshot is a snapshot preceding the second snapshot among all snapshots of the LUN. The deleting module is configured to delete the target snapshot based on the judgment identification value of the target snapshot and the bitmap of the target snapshot.
8. The apparatus of claim 7, wherein, When the deleting module deletes the target snapshot based on the judgment identification value of the target snapshot and the bitmap of the target snapshot, the deleting module is further configured to: if the target snapshot is the first snapshot of the LUN to which the target snapshot belongs, delete the target snapshot, and modify the judgment identification value of a snapshot succeeding the target snapshot among all snapshots of the LUN to which the target snapshot belongs to the first value; if the target snapshot is not the first snapshot of the LUN to which the target snapshot belongs, then: if the judgment identification value of the target snapshot is the first value, directly delete the target snapshot; if the judgment identification value of the target snapshot is the second value, compare the bitmaps of the target snapshot and a fourth snapshot to obtain a target bit having the same position and the third value in the bitmap of the target snapshot and the bitmap of the fourth snapshot, release a physical space corresponding to an operation record of a target LBA represented by the target bit in the target snapshot, delete the operation record of the target LBA represented by the target bit, and modify the value of the target bit in the bitmap of the target snapshot from the third value to the fourth value. The fourth snapshot is a snapshot preceding the target snapshot among all snapshots of the LUN to which the target snapshot belongs. merge the remaining operation records of the target snapshot and the operation records of the fourth snapshot to update the operation records of the fourth snapshot, and arrange and merge the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot; and then delete the target snapshot.
9. The apparatus of claim 8, wherein, When the deleting module arranges and merges the bitmap of the target snapshot and the bitmap of the fourth snapshot to update the bitmap of the fourth snapshot, the deleting module is further configured to: For each bit in the bitmap of the target snapshot, if the value of the bit is the fourth value, the value of the bit in the bitmap of the fourth snapshot at the same position is maintained; If the value of the bit is the third value, the value of the bit in the bitmap of the fourth snapshot at the same position is modified from the fourth value to the third value, or maintained at the third value.
10. The apparatus of claim 7, wherein, The identification determination module, when performing the comparison between the bitmaps of the second snapshot and the third snapshot to redetermine the judgment identification value of the second snapshot, is further configured to: If the values of all bits in the bitmap of the second snapshot and the bitmap of the third snapshot are the same, the judgment identification value of the second snapshot is modified to the first value.
11. The apparatus of claim 7, wherein, The bitmap establishment module, when performing the determination of whether to add the operation record to the first snapshot, specifically includes the following steps: After the first snapshot is established, when a write operation related to the LUN is received, for each data block represented by an LBA involved in the write operation, the current value of the bit corresponding to the data block represented by the LBA in the bitmap of the first snapshot is obtained; If the current value is the fourth value, it is determined to add the operation record of the data block represented by the LBA to the first snapshot; If the current value is the third value, it is determined not to add the operation record of the data block represented by the LBA to the first snapshot.
12. The apparatus of claim 7, wherein, The snapshot time period corresponding to any snapshot is determined by the following steps: When the snapshot is not the latest snapshot in the LUN to which the snapshot belongs, the snapshot time period corresponding to the snapshot is the time period between the establishment time of the snapshot and the establishment time of the next snapshot of the snapshot among all snapshots of the LUN; When the snapshot is the latest snapshot in the LUN to which the snapshot belongs, the snapshot time period is the time period between the establishment time of the snapshot and the latest time.
13. An electronic device, comprising: The electronic device includes: a processor; and a computer readable storage medium having stored therein computer program instructions, which, when executed by the processor, cause the processor to perform the steps of the method of any one of claims 1 to 6.
14. A computer-readable storage medium, characterized in that, The computer readable storage medium has stored thereon computer program instructions, which, when executed by a processor, cause the processor to perform the steps of the method of any one of claims 1 to 6.