Data storage method and device
By dynamically allocating data blocks from the general data block UBS of the target disk, the problem of low storage space utilization in the prior art is solved, and more efficient storage space utilization is achieved.
Patent Information
- Application Number
- CN202311061417.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-21
- Publication Date
- 2025-02-21
AI Technical Summary
In the prior art, the storage space needs to be divided in advance when storing video surveillance data, resulting in a low utilization rate of storage space.
By dynamically determining the required data block from the general data block UBS of the target disk, and combining the amount of data to be stored, the target data block is dynamically allocated for storing video surveillance data.
It effectively avoids waste of storage space caused by pre-reserving partitions and improves the utilization of storage space.
Smart Images

Figure CN119493521A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a data storage method and device. Background Art
[0002] In the field of video surveillance, video surveillance data is generally stored through block storage. Universal block storage (UBS) is a storage format based on block devices. It is necessary to pre-divide space from the storage space in the disk and format it into UBS to store video surveillance data through UBS.
[0003] In the related prior art, when the storage space in the disk is divided, the storage space is divided into two partitions, wherein the first partition is a reserved partition and is only used to store other business data, such as file data, etc.; the second partition is formatted as UBS and is only used to store video surveillance data.
[0004] However, using the above data storage method will result in low utilization of storage space. Summary of the invention
[0005] The embodiments of the present application provide a data storage method and device for solving the problem of low storage space utilization in the prior art, thereby effectively improving the storage space utilization.
[0006] The present application provides a data storage method, which may include:
[0007] Based on the amount of data to be stored, determining a first number of data blocks required to store the data to be stored;
[0008] Determine the first number of target data blocks from a universal data block UBS of the target disk, wherein the target data blocks include free data blocks in the UBS and / or used data blocks in the UBS;
[0009] The data to be stored is stored based on the target data block.
[0010] According to a data storage method provided by an embodiment of the present application, determining the first number of target data blocks from a universal data block UBS of a target disk includes:
[0011] Determining a second number of all free data blocks in the UBS;
[0012] In a case where the second number is greater than or equal to the first number, determining the first number of candidate free data blocks from all the free data blocks;
[0013] The candidate idle data block is determined as the target data block.
[0014] According to a data storage method provided in an embodiment of the present application, the method further includes:
[0015] In the case where the second number is less than the first number, determining a third number of candidate used data blocks from all used data blocks based on the data storage moments of all used data blocks in the UBS, where the third number is equal to the difference between the first number and the second number;
[0016] All the free data blocks and the candidate used data blocks are determined as the target data blocks.
[0017] According to a data storage method provided by an embodiment of the present application, the step of determining a third number of candidate used data blocks from all used data blocks based on the data storage moments of all used data blocks in the UBS includes:
[0018] According to the order of data storage time of all the used data blocks from earliest to latest, the first third number of data blocks among all the used data blocks are determined as the candidate used data blocks.
[0019] According to a data storage method provided by an embodiment of the present application, the data blocks in the UBS are used to store data output by each channel of the monitoring device, and the first third number of data blocks in the used data blocks are determined as the candidate used data blocks in the order of data storage time of all the used data blocks from earliest to latest, including:
[0020] Determine the first third number of first data blocks corresponding to the first channel in order of data storage times of the used data blocks corresponding to the first channel from earliest to latest;
[0021] Traverse other channels except the first channel, and determine the candidate used data blocks based on the second data block with the earliest data storage time among the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks.
[0022] According to a data storage method provided by an embodiment of the present application, the method of determining the candidate used data blocks based on the second data block with the earliest data storage time of the used data blocks corresponding to other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks, includes:
[0023] When the data storage time of the second data block is earlier than the data storage time of the third data block, the second data block is used to replace the third data block to obtain a new first data block; the fourth data block with the second earliest data storage time among the used data blocks corresponding to the other channels currently traversed is determined as the new second data block, and the data block with the latest data storage time among the new first data blocks is used as the new third data block, and this step is repeated until there is a data storage time that is later than the data storage time of the third data block among the used data blocks corresponding to the other channels currently traversed, and the finally determined new first data block is determined as the candidate used data block.
[0024] According to a data storage method provided by an embodiment of the present application, replacing the third data block with the second data block to obtain a new first data block includes:
[0025] The third data block is replaced by the second data block, and based on the data storage time of the second data block and the data storage time of each of the other first data blocks except the third data block in the first third number of first data blocks, the second data block is inserted into the other first data blocks to obtain the new first data block;
[0026] The data storage times of the new first data blocks are arranged in order from earliest to latest.
[0027] According to a data storage method provided by an embodiment of the present application, the number of the target data blocks is multiple, and storing the data to be stored based on the target data blocks includes:
[0028] Determine the offset of each target data block based on the offset position sorting of each target data block in the target disk, and map the storage space of each target data block to a target logical address space based on the offset of each target data block;
[0029] Creating a target block device based on the target logical address space;
[0030] The data to be stored is stored in the target block device.
[0031] The present application also provides a data storage device, which may include:
[0032] a determining unit, configured to determine, based on the amount of data to be stored, a first number of data blocks required to store the data to be stored;
[0033] A processing unit, configured to determine the first number of target data blocks from a universal data block UBS of a target disk, wherein the target data blocks include free data blocks in the UBS and / or used data blocks in the UBS;
[0034] A storage unit is used to store the data to be stored based on the target data block.
[0035] According to a data storage device provided in an embodiment of the present application, the processing unit is specifically used for:
[0036] Determine a second number of all free data blocks in the UBS; if the second number is greater than or equal to the first number, determine the first number of candidate free data blocks from all the free data blocks; and determine the candidate free data blocks as the target data blocks.
[0037] According to a data storage device provided by an embodiment of the present application, the processing unit is further used for:
[0038] In the case that the second number is smaller than the first number, based on the data storage time of all used data blocks in the UBS, a third number of candidate used data blocks is determined from all the used data blocks, and the third number is equal to the difference between the first number and the second number; all the free data blocks and the candidate used data blocks are determined as the target data blocks.
[0039] According to a data storage device provided in an embodiment of the present application, the processing unit is specifically used for:
[0040] According to the order of data storage time of all the used data blocks from earliest to latest, the first third number of data blocks among all the used data blocks are determined as the candidate used data blocks.
[0041] According to a data storage device provided by an embodiment of the present application, the data block in the UBS is used to store data output by each channel of the monitoring device, and the processing unit is specifically used to:
[0042] Determine the first third number of first data blocks corresponding to the first channel in order of data storage times of the used data blocks corresponding to the first channel from earliest to latest;
[0043] Traverse other channels except the first channel, and determine the candidate used data blocks based on the second data block with the earliest data storage time among the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks.
[0044] According to a data storage device provided in an embodiment of the present application, the processing unit is specifically used for:
[0045] When the data storage time of the second data block is earlier than the data storage time of the third data block, the second data block is used to replace the third data block to obtain a new first data block; the fourth data block with the second earliest data storage time among the used data blocks corresponding to the other channels currently traversed is determined as the new second data block, and the data block with the latest data storage time among the new first data blocks is used as the new third data block, and this step is repeated until there is a data storage time that is later than the data storage time of the third data block among the used data blocks corresponding to the other channels currently traversed, and the finally determined new first data block is determined as the candidate used data block.
[0046] According to a data storage device provided in an embodiment of the present application, the processing unit is specifically used for:
[0047] The third data block is replaced by the second data block, and based on the data storage time of the second data block and the data storage time of each of the other first data blocks except the third data block in the first third number of first data blocks, the second data block is inserted into the other first data blocks to obtain the new first data block; wherein the data storage time of the new first data block is arranged in order from early to late.
[0048] According to a data storage device provided by an embodiment of the present application, the number of the target data blocks is multiple, and the device further includes:
[0049] A mapping unit, configured to determine the offset of each target data block based on the offset position sorting of each target data block in the target disk, and map the storage space of each target data block to a target logical address space based on the offset of each target data block;
[0050] A creating unit, configured to create a target block device based on the target logical address space;
[0051] The storage unit is specifically configured to store the data to be stored in the target block device.
[0052] The present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the data storage methods described above is implemented.
[0053] The present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which implements any of the data storage methods described above when executed by a processor.
[0054] The present application also provides a computer program product, including a computer program, which implements any of the data storage methods described above when executed by a processor.
[0055] The data storage method and device provided in the embodiment of the present application determine the first number of data blocks required to store the data to be stored based on the amount of data to be stored; determine the first number of target data blocks from the universal data block UBS of the target disk, the target data blocks include free data blocks in the UBS, and / or used data blocks in the UBS; store the data to be stored based on the target data blocks. In this way, there is no need to reserve partitions from the disk in advance, but when there is a storage demand, the required target data blocks are dynamically allocated from the UBS for the data to be stored in combination with the amount of data to be stored, which can effectively avoid the problem of storage space waste caused by reserving partitions in advance, thereby effectively improving the utilization rate of storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0057] Figure 1 A schematic diagram of a UBS data structure provided in an embodiment of the present application;
[0058] Figure 2 A schematic diagram of the structure of summary information provided in an embodiment of the present application;
[0059] Figure 3 A schematic diagram of the structure of a flag bit information provided in an embodiment of the present application;
[0060] Figure 4 A schematic diagram of a data storage method provided in an embodiment of the present application;
[0061] Figure 5 A schematic diagram of the structure of a channel link table information provided in an embodiment of the present application;
[0062] Figure 6 A flowchart of a method for determining a third number of candidate used data blocks according to the order of data storage times of all used data blocks from earliest to latest provided by an embodiment of the present application;
[0063] Figure 7 A schematic diagram of na first data blocks corresponding to a first channel provided in an embodiment of the present application;
[0064] Figure 8 A schematic diagram of na first data blocks after updating provided in an embodiment of the present application;
[0065] Fig. 9 A schematic diagram of na candidate used data blocks finally determined according to an embodiment of the present application;
[0066] Fig.10 A schematic diagram of a process for creating a block device provided in an embodiment of the present application;
[0067] Fig.11 A schematic diagram of another process of creating a block device provided in an embodiment of the present application;
[0068] Fig.12 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application;
[0069] Fig.13 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0071] In the embodiments of the present application, "at least one" means one or more, and "more" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In the text description of the present application, the character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0072] The technical solution provided by the embodiment of the present application can be applied to data storage scenarios, especially video surveillance data storage scenarios. In the field of video surveillance, video surveillance data is generally stored through block storage. UBS is a storage format based on block devices. It is necessary to divide the storage space in the disk in advance and format it into UBS to store video surveillance data through UBS.
[0073] In the related prior art, when the storage space in the disk is divided, the storage space is divided into two partitions, wherein the first partition is a reserved partition and is only used to store other business data, such as file data, etc.; the second partition is formatted as UBS and is only used to store video surveillance data.
[0074] For example, see Figure 1 As shown, Figure 1 A schematic diagram of a UBS data structure provided in an embodiment of the present application shows that the UBS data structure includes a super block, a summary area, a data area, and a reserved area. The super block is mainly used to record the number and size of the data blocks included in the data area, and the summary area is mainly used to record the relevant information of the video surveillance data stored in each data block, such as the channel from which the video surveillance data is obtained, the start time and end time of the video surveillance data, and other relevant information; the data area includes multiple data blocks for storing video surveillance data; the reserved area is mainly used to back up the super block.
[0075] Combination Figure 1 As shown, under normal circumstances, the total storage space of the super block and the summary area is 256MB, ensuring that the data area starts with 256MB alignment. The summary area occupies 4KB of storage space with 31 summaries as a group, and each summary corresponds to a data block in the data block in sequence. The data area includes n data blocks and the remaining data slice area that is less than 256MB. The n data blocks include data block 1, data block 2, ..., data block n. The storage space of each data block is 256MB, and the storage space of the reserved area is 1GB, which is used to back up the super block.
[0076] It should be noted that, generally, the summary area includes summary information of the corresponding data block and some flag information, which are used together to record the relevant information of the video surveillance data stored in each data block. Figure 2 and Figure 3 As shown, Figure 2 A schematic diagram of the structure of summary information provided in an embodiment of the present application, Figure 3 A schematic diagram of a structure of a flag information provided in an embodiment of the present application, combined with Figure 2 As shown, the summary information may include block type, flag information, recording information, channel identification (Identity, ID), start time, end time, data size and reserved area.
[0077] Among them, the block type is used to characterize the type of data block, etc.; the flag information is used to characterize the type of video surveillance data, such as common type, alarm type, etc.; the channel ID is used to characterize the channel from which the video surveillance data is obtained; the start time characterizes the start time of the video surveillance data; the end time characterizes the end time of the video surveillance data; the data size is used to characterize the size of the space actually used for storage of the data block; the reserved area is unused storage space to facilitate subsequent expansion.
[0078] Combination Figure 3 As shown, the flag information may include multiple fields, such as UD (Used), LK (Lock), CT (Continuous), SG (Segment), MK, RS (Reserve) and other fields.
[0079] Among them, field UD is used to indicate whether the data block has been used; LK is used to indicate that the video surveillance data is locked and is not allowed to be overwritten; field CT indicates whether the video surveillance data in the data block is continuous; field SG is used to indicate whether the video surveillance data is segmented; field MK indicates the supplementary video surveillance data block; field RS is a reserved field, used to indicate that the data block can be used separately.
[0080] However, using the above-mentioned method of reserving partitions in advance, once the storage space in the disk is divided into a first partition and a second partition, the first partition can only be used as a reserved partition for storing other business data; the second partition can only be formatted as UBS for storing video surveillance data. This will result in a waste of storage space, especially when there is no need to store other business data, the reserved partition divided in advance will always be idle, resulting in low utilization of the storage space.
[0081] In order to effectively solve the problem of storage space waste caused by pre-set partitions, thereby improving the utilization of storage space, it is possible to consider dynamically determining the target data block from the universal data block UBS of the target disk when there is a data storage demand, combined with the amount of data to be stored, so as to store the data to be stored through the target data block. This can effectively avoid the problem of storage space waste caused by pre-reserved partitions, thereby effectively improving the utilization of storage space.
[0082] The data storage method provided by the present application will be described in detail below through the following specific embodiments. It is understandable that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0083] Embodiment 1
[0084] Figure 4A flowchart of a data storage method provided in an embodiment of the present application is provided. The data storage method can be executed by software and / or hardware devices, such as a data storage device.
[0085] For example, see Figure 4 As shown, the data storage method may include:
[0086] S401. Determine a first number of data blocks required to store the data based on the amount of the data to be stored.
[0087] For example, the data to be stored may be other data besides the video surveillance data, such as other business data such as file data and audio data.
[0088] For example, when determining the first number of data blocks required to store the data to be stored based on the amount of the data to be stored, the first number may be determined based on a ratio of the amount of data to the storage space of the data blocks.
[0089] For example, if the amount of data to be stored is 512MB and the storage space of the data block is 256MB, the first number of data blocks required is 2; if the amount of data to be stored is 600MB and the storage space of the data block is 256MB, the first number of data blocks required is 3.
[0090] By executing the above S401, the first number of data blocks required to store the data to be stored can be determined according to the storage data volume of the data to be stored; in order to ensure the normal storage of the data to be stored, it is necessary to filter out the first number of data blocks from the UBS of the target disk, so as to realize the storage of the data to be stored through the filtered first number of data blocks, that is, execute the following S402.
[0091] S402: Determine a first number of target data blocks from the universal data blocks UBS of the target disk, where the target data blocks include free data blocks in the UBS and / or used data blocks in the UBS.
[0092] The target disk can be understood as a disk used to store data to be stored. For example, in the embodiment of the present application, the number of the target disk can be one or more, which can be set according to actual needs.
[0093] When the number of target disks is one, when selecting a target disk, the disk corresponding to the UBS with the largest number of free data blocks among multiple disks can be determined as the target disk; of course, the disk corresponding to the UBS with the second largest number of free data blocks among multiple disks can also be determined as the target disk. The specific setting can be made according to actual needs.
[0094] When there are multiple target disks, when selecting multiple target disks, you can start from the free data block ranked first and determine the disks corresponding to the first multiple UBSs with a larger number of free data blocks as the target disks in the order of the free data blocks in the UBS from most to least; you can also start from the free data block ranked second and determine the disks corresponding to the first multiple UBSs with a larger number of free data blocks as the target disk. The specific setting can be made according to actual needs.
[0095] It is understandable that when there are multiple target disks, each target disk may evenly share the storage space required for the amount of data to be stored, or may not evenly share the storage space required for the amount of data to be stored, which can be specifically set according to actual needs.
[0096] When selecting a target disk from multiple disks, it is considered that under normal circumstances, when each disk is online, the data storage device will read the summary area in the disk and establish a bitmap table in the memory of the data storage device to record whether each data block in the UBS of the disk is used. If a data block has been used, the bitmap table can record the bitmap corresponding to the data block as 1; if a data block is not used, that is, it is a free data block, the bitmap table can record the bitmap corresponding to the data block as 0. The specific setting can be made according to actual needs. Therefore, the number of free data blocks in the UBS of each disk can be found based on the established bitmap table, so as to determine the target disk from multiple disks and the number of all free data blocks in the UBS of the target disk.
[0097] For example, in an embodiment of the present application, when determining the target data block from the UBS of the target disk according to the first number of data blocks required for the data to be stored, the following three possible implementations may be included:
[0098] In one possible way, the second number of all free data blocks in the UBS can be determined first; when the second number is greater than or equal to the first number, it means that the free data blocks in the UBS of the target disk are sufficient to store the data to be stored, and then a first number of candidate free data blocks can be determined from all free data blocks, and the candidate free data blocks can be determined as target data blocks. In this way, there is no need to reserve partitions from the disk in advance, but when there is a storage demand, the required target data blocks can be dynamically allocated from the free data blocks in the UBS for the data to be stored, which can effectively avoid the problem of storage space waste caused by reserving partitions in advance, thereby effectively improving the utilization rate of storage space.
[0099] In another possible implementation, when the second number is less than the first number, it means that the free data blocks in the UBS of the target disk are insufficient to store the data to be stored, then based on the data storage time of all used data blocks in the UBS, a third number of candidate used data blocks are determined from all used data blocks, and the third number is equal to the difference between the first number and the second number; and all free data blocks and candidate used data blocks are jointly determined as target data blocks. In this way, there is no need to reserve partitions from the disk in advance, but the required target data blocks are dynamically allocated from the free data blocks in the UBS for the data to be stored when there is a storage demand, which can effectively avoid the problem of storage space waste caused by reserving partitions in advance, thereby effectively improving the utilization rate of storage space.
[0100] It can be understood that in this possible implementation method, all free data blocks and candidate used data blocks are jointly determined as target data blocks, that is, all free data blocks are preferentially selected, and then the selected candidate used data blocks are superimposed as target data blocks; of course, a part of free data blocks can also be selected from all free data blocks, and then the selected candidate used data blocks are superimposed as target data blocks. The specific settings can be made according to actual needs. Here, the embodiment of the present application is only explained by taking the example of preferentially selecting all free data blocks and then superimposing the selected candidate used data blocks as target data blocks, but it does not mean that the embodiment of the present application is limited to this.
[0101] For example, assuming that the first number of data blocks required to store the data to be stored is n, and the second number of all free data blocks in the UBS of the target disk is a, the difference between the first number and the second number can be recorded as na, and the third number of candidate used data blocks is na.
[0102] By way of example, in an embodiment of the present application, when determining a third number of candidate used data blocks from all used data blocks based on the data storage time of all used data blocks in the UBS, it is considered that the earlier the video surveillance data is stored, the smaller the impact on the current video surveillance service. Therefore, in order to reduce the impact on the current video surveillance service, the data blocks that store data earlier can be determined as candidate used data blocks for storing the data to be stored based on the data storage time of all used data blocks in the UBS.
[0103] For example, based on the data storage time of all used data blocks in the UBS, when determining the data blocks that store data earlier as candidate used data blocks, the first third number of data blocks among all used data blocks can be determined as candidate used data blocks in the order of the data storage time of all used data blocks from early to late. Alternatively, the last third number of data blocks among all used data blocks can be determined as candidate used data blocks in the order of the data storage time of all used data blocks from late to early. The specific setting can be made according to actual needs.
[0104] For example, the data storage time of all used data blocks is in the order from early to late: data block 1, data block 3, data block 2, data block 6, data block 9, and data block 8. The third number is 4, then the first 4 data blocks, namely data block 1, data block 3, data block 2 and data block 6, can be determined as candidate used data blocks.
[0105] Of course, if the video surveillance data stored in data block 9 has little impact on the current video surveillance service, data block 3, data block 2, data block 6 and data block 9 can also be determined as candidate used data blocks, which can be set according to actual needs. It should be noted that if the impact on the current video surveillance service is not considered, 4 data blocks can also be randomly selected from all used data blocks to be determined as candidate used data blocks, which can be set according to actual needs.
[0106] In another possible implementation, the number of all used data blocks in the UBS can be determined first; when the number of used data blocks is greater than or equal to the first number, a first number of used data blocks can be determined from all used data blocks as target data blocks. In this way, there is no need to reserve partitions from the disk in advance. Instead, when there is a storage demand, the required target data blocks are dynamically allocated from the used data blocks in the UBS for the data to be stored. This can effectively avoid the problem of storage space waste caused by reserving partitions in advance, thereby effectively improving the utilization rate of the storage space.
[0107] It should be noted that when determining the first number of target data blocks from the UBS of the target disk according to the first number of data blocks required for the data to be stored, the embodiments of the present application only use the above three possible implementation methods as examples for illustration, but it does not mean that the embodiments of the present application are limited to this.
[0108] In combination with the above S402, after the target data block is determined from the UBS of the target disk, the data to be stored can be stored based on the target data block, that is, the following S403 is executed.
[0109] S403: Store the data to be stored based on the target data block.
[0110] It can be seen that in the embodiment of the present application, based on the amount of data to be stored, the first number of data blocks required to store the data to be stored is determined; a first number of target data blocks are determined from the universal data block UBS of the target disk, the target data blocks include free data blocks in the UBS, and / or, used data blocks in the UBS; the data to be stored is stored based on the target data blocks. In this way, there is no need to reserve partitions from the disk in advance, but when there is a storage demand, combined with the amount of data to be stored, the required target data blocks are dynamically allocated from the UBS for the data to be stored, which can effectively avoid the problem of storage space waste caused by reserving partitions in advance, thereby effectively improving the utilization rate of storage space.
[0111] Normally, when a disk is online, the data storage device reads the summary area in the disk and creates a bitmap table in the memory of the data storage device, so that the target disk and the second number of all free data blocks in the UBS of the target disk can be determined from multiple disks through the bitmap table. For example, in an embodiment of the present application, when a disk is online, in addition to reading the summary area in the disk and creating a bitmap table in the memory of the data storage device, the data storage device can also create channel link list information.
[0112] For example, see Figure 5 As shown, Figure 5 A structural schematic diagram of a channel linked list information provided for an embodiment of the present application, wherein the channel linked list information includes a channel linked list, a day linked list and a block linked list. Through the channel linked list information, the association relationship between each channel of the monitoring device, the data storage time and the corresponding data block can be obtained.
[0113] Combination Figure 5 As shown, Figure 5 The channel list in can be understood as a list formed by the order of the channels of the monitoring devices. The channels of the monitoring devices refer to their output channels. Among them, chl1 represents the first channel of the monitoring device, which can be recorded as channel 1, chl2 represents the second channel of the monitoring device, which can be recorded as channel 2, chl3 represents the third channel of the monitoring device, which can be recorded as channel 3, and chl4 represents the fourth channel of the monitoring device, which can be recorded as channel 4. The day list can be understood as a list formed by the data storage time. The video monitoring data is stored in units of days. day1 means that the data storage time is the first day, day2 means that the data storage time is the second day, and day3 means that the data storage time is the third day. The block connection table can be understood as a list formed by data blocks. blk1 represents data block 1, blk2 represents data block 2, and blk3 represents data block 3. Figure 5 The arrow directions shown can be understood as the video monitoring data of channel 1 of the monitoring device on the first day being stored in data blocks 1, data block 2, data block 3, and so on.
[0114] Considering that the channel linked list information can be used to know the association relationship between each channel of the monitoring device, the data storage time and the corresponding data block, for example, in the embodiment of the present application, when determining the candidate used data blocks according to the data storage time of all used data blocks from early to late, the candidate used data blocks can be determined based on the channel linked list information according to the data storage time of the used data blocks from early to late. For details, please refer to the following Figure 6 The second embodiment is shown.
[0115] Embodiment 2
[0116] Figure 6 A flowchart of a method for determining a third number of candidate used data blocks according to the data storage time of all used data blocks in order from earliest to latest is provided in an embodiment of the present application. The method can also be executed by software and / or hardware devices. For example, see Figure 6 As shown, the method may include:
[0117] S601 . Determine the first third number of first data blocks corresponding to the first channel in order of data storage times of used data blocks corresponding to the first channel from earliest to latest.
[0118] For example, assuming that the first number of data blocks required to store the data to be stored is n, the second number of all free data blocks in the UBS of the target disk is a, a third number na used data blocks need to be determined as candidate used free blocks.
[0119] For example, when determining candidate used data blocks according to the order of data storage time of all used data blocks from earliest to latest, the first channel can be used as the starting channel, and the first na used data blocks can be determined as the na first data blocks corresponding to the first channel according to the order of data storage time of the used data blocks corresponding to the first channel from earliest to latest. Figure 7 As shown, Figure 7 A schematic diagram of na first data blocks corresponding to a first channel provided in an embodiment of the present application assumes that the na first data blocks corresponding to the first channel are, in order from early to late, data block chl1-1, data block chl1-2, data block chl1-3, ..., and data block chl1-(na), thereby determining the na first data blocks corresponding to the first channel.
[0120] After determining the na first data blocks corresponding to the first channel, considering that the na first data blocks may not be the data blocks with the earliest data storage time among all the used data blocks, it is necessary to traverse other channels except the first channel in turn, and compare the data storage time of the na first data blocks with the data storage time of the used data blocks corresponding to other channels, so as to determine na candidate used data blocks.
[0121] When comparing the data storage time of the used data blocks corresponding to other channels, its specific implementation can refer to the following S602:
[0122] S602, traverse other channels except the first channel, and determine candidate used data blocks based on the second data block with the earliest data storage time among the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks.
[0123] For example, in an embodiment of the present application, based on the second data block with the earliest data storage time, the third data block with the latest data storage time, and the first third number of first data blocks of the used data blocks corresponding to the other channels currently traversed, when determining the candidate used data blocks, the data storage time of the second data block with the earliest data storage time corresponding to the other channels currently traversed can be compared with the third data block with the latest data storage time. If the data storage time of the second data block is later than the data storage time of the third data block, it means that the data storage times of all the used data blocks corresponding to the other channels currently traversed are later than the data storage time of the third data block. Then, the candidate used data blocks are directly determined according to the channel order. sequence, switch to the next other channel to continue traversing; on the contrary, if the data storage time of the second data block is earlier than the data storage time of the third data block, the second data block can be used to replace the third data block to obtain a new first data block; then the fourth data block with the second earliest data storage time of the used data blocks corresponding to the other channels currently traversed is determined as the new second data block, and the data block with the latest data storage time in the new first data block is used as the new third data block, and this step is repeated until there is a data storage time later than the data storage time of the third data block in the used data blocks corresponding to the other channels currently traversed, and the finally determined new first data block is determined as the candidate used data block. In this way, by traversing other channels, data blocks with earlier data storage time can be accurately determined, and these data blocks with earlier data storage time can be used as candidate used data blocks, which can not only effectively avoid the problem of storage space waste caused by pre-reserved partitions and improve the utilization rate of storage space, but also effectively reduce the impact on the current video surveillance business.
[0124] For example, when the second data block is used to replace the third data block to obtain a new first data block, the second data block can be used to replace the third data block, and based on the data storage time of the second data block and the data storage time of each of the other first data blocks except the third data block in the first third number of first data blocks, the second data block is inserted into the other first data blocks to obtain a new first data block; wherein the data storage time of the new first data block is arranged in order from early to late.
[0125] For example, combined with Figure 7As shown, assuming that the na first data blocks corresponding to the first channel determined by the above S601 are in order from earliest to latest, respectively: data block chl1-1, data block chl1-2, data block chl1-3, ..., and data block chl1-(na); first traverse the second channel to determine whether the data storage time of the second data block with the earliest data storage time of the used data blocks corresponding to the second channel is earlier than the data storage time of the data block chl1-(na); if the data storage time of the second data block with the earliest data storage time corresponding to the second channel is later than the data storage time of the data block chl1-(na), it means that the data storage time of all the used data blocks corresponding to the second channel is later than the data storage time of the data block chl1-(na), then directly switch to the third channel to start traversal; on the contrary, if the data storage time of the second data block with the earliest data storage time corresponding to the second channel is earlier than the data storage time of the data block chl1-(na), then the second data block can be used to replace the data block chl1-(na) to obtain a new first data block; and determine the data storage time of the fourth data block with the second earliest data storage time corresponding to the second channel Whether the time is earlier than the data storage time of the data block chl1-(na); if the data storage time of the fourth data block with the second earliest data storage time corresponding to the second channel is later than the data storage time of the data block chl1-(na), it means that the data storage time of other uncompared used data blocks corresponding to the second channel are also later than the data storage time of the data block chl1-(na), then directly switch to the third channel to start traversal; on the contrary, if the data storage time of the fourth data block with the second earliest data storage time corresponding to the second channel is earlier than the data storage time of the data block chl1-(na), then the fourth data block can be used to replace the data block with the latest data storage time in the new first data block to obtain a new first data block; then the fourth data block with the third earliest data storage time of the used data blocks corresponding to the other channels currently traversed is determined as the new second data block, and the data block with the latest data storage time in the new first data block is used as the new third data block, and this step is repeated until there is a data storage time later than the data storage time of the third data block in the used data blocks corresponding to the other channels currently traversed, and the finally determined new first data block is determined as the na candidate used data blocks.
[0126] By way of example, in an embodiment of the present application, assuming that the second data block with the earliest data storage time corresponding to the second channel is data block chl2-1, and the data storage time of data block chl2-1 is earlier than the data storage time of data block chl1-(na), then data block chl2-1 can be used to replace data block chl1-(na), that is, data block chl1-(na) is deleted to obtain na data blocks with earlier data storage times; by way of example, the data storage time of data block chl2-1 can also be compared with the data storage times of data blocks chl1-1, data block chl1-2, data block chl1-3, ..., and data block chl1-(na-1) corresponding to the first channel. Assuming that the data storage time of data block chl2-1 is between the data storage time of data block chl1-1 and the data storage time of data block chl1-2, then data block chl2-1 can be inserted between data block chl1-1 and data block chl1-2. By way of example, see Figure 8 As shown, Figure 8 A schematic diagram of an updated n first data blocks provided in an embodiment of the present application is provided. The above traversal operation is repeatedly performed until n candidate used data blocks are finally determined. Assume that the n candidate used data blocks finally determined are, in order from earliest to latest, data block chl1-1, data block chl2-2, data block chl1-2, data block chl3-1, ..., and data block chln-2. For example, see Fig. 9 As shown, Fig. 9 A schematic diagram of the na candidate used data blocks that are finally determined is provided in an embodiment of the present application. By traversing other channels, data blocks with earlier data storage times can be accurately determined, and these data blocks with earlier data storage times can be used as candidate used data blocks. This can not only effectively avoid the problem of storage space waste caused by pre-reserved partitions and improve the utilization of storage space, but also effectively reduce the impact on current video surveillance services.
[0127] It should be noted that, in the embodiment of the present application, when the selected target data blocks are used to store the data to be stored, these target data blocks can be deleted from the channel linked list information and the usage flags in their summary areas can be set.
[0128] It can be seen that in the embodiment of the present application, when determining the candidate used data blocks according to the data storage time of all used data blocks from early to late, the first third number of first data blocks corresponding to the first channel can be determined according to the data storage time of the used data blocks corresponding to the first channel from early to late; then traverse other channels except the first channel, and jointly determine the candidate used data blocks based on the second data block with the earliest data storage time of the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks. In this way, by traversing other channels, data blocks with earlier data storage time can be accurately determined, and these data blocks with earlier data storage time can be used as target data blocks, which can not only effectively avoid the problem of storage space waste caused by pre-reserved partitions and improve the utilization rate of storage space, but also effectively reduce the impact on the current video surveillance business.
[0129] Based on any of the above embodiments, after the target data block is determined, the data to be stored can be stored based on the target data block to implement storage of the data to be stored.
[0130] For example, in one scenario, assuming that there are multiple target data blocks, and the multiple target data blocks are data blocks in a target disk, when storing the data to be stored based on the target data blocks, refer to Fig.10 As shown, Fig.10 A flow chart of creating a block device provided in an embodiment of the present application, considering that multiple target data blocks are usually non-continuous storage spaces, therefore, each target data block can be sorted based on its offset position in the target disk, the offset of each target data block can be determined, and based on the offset of each target data block, the storage space of each target data block can be mapped to a target logical address space, the target logical address space is a continuous storage space, and a target block device is created based on the target logical address space; then the data to be stored is stored in the created target block device, thereby realizing the storage of the data to be stored.
[0131] For example, in another scenario, assuming that there are multiple target data blocks, and the multiple target data blocks are data blocks in multiple target disks, when storing the data to be stored based on the target data blocks, unlike the data blocks in the above-mentioned one target disk, when sorting based on the offset position of each target data block in the target disk, determining the offset of each target data block, and mapping the storage space of each target data block to the target logical address space based on the offset of each target data block, for each target disk, determine the data block corresponding to the target disk from the multiple target data blocks, and map the storage space of the data block corresponding to the target disk to the logical address space corresponding to the target disk, that is, first map the logical address space corresponding to each target disk with the target disk as a unit; considering that in the video surveillance scenario, the stored video surveillance data has been redundantly protected and does not need to be superimposed with data redundancy, therefore, the logical address space corresponding to each target disk can be further processed for data redundancy to obtain the target logical address space.
[0132] Generally, the offset position of a data block on a disk refers to the offset of the physical storage position of the data in the data block on the disk relative to the starting point of the disk. The offset position is usually expressed in bytes. For most disks, the offset position starts from the starting point of the disk and increases in bytes. For example, an offset position of 0 means that the data is located at the starting position of the disk, and an offset position of 100 means that the data is located at the 100th byte on the disk.
[0133] It should be noted that when there are multiple target disks, each target disk can evenly share the storage space required for the amount of data to be stored, so that the target logical address space corresponding to each target disk is ultimately a target logical address space of equal size, and then data redundancy processing is performed on the logical address space corresponding to each target disk to obtain the target logical address space.
[0134] For example, see Fig.11 As shown, Fig.11A schematic diagram of another process of creating a block device provided in an embodiment of the present application, assuming that the number of target disks is three, and the three target disks are target disk A, target disk B and target disk C respectively. After determining the target data blocks for storing the data to be stored from target disk A, target disk B and target disk C, for target disk A, the storage space of the data blocks corresponding to target disk A is mapped to the logical address space A corresponding to target disk A; for target disk B, the storage space of the data blocks corresponding to target disk B is mapped to the logical address space B corresponding to target disk B; for target disk C, the storage space of the data blocks corresponding to target disk C is mapped to the logical address space C corresponding to target disk C, and then data redundancy processing is performed on the logical address spaces corresponding to target disk A, target disk B and disk target C respectively to obtain a target logical address space, which is a continuous storage space, and a target block device is created based on the target logical address space; then the data to be stored is stored in the created target block device, thereby realizing the storage of the data to be stored.
[0135] The data storage device provided in the present application is described below. The data storage device described below and the data storage method described above can be referenced to each other.
[0136] Fig.12 A schematic diagram of a data storage device provided in an embodiment of the present application is provided. For example, see Fig.12 As shown, the data storage device 120 may include:
[0137] The determining unit 1201 is configured to determine a first number of data blocks required to store the data to be stored based on the amount of the data to be stored.
[0138] The processing unit 1202 is configured to determine the first number of target data blocks from a universal data block UBS of a target disk, wherein the target data blocks include free data blocks in the UBS and / or used data blocks in the UBS.
[0139] The storage unit 1203 is configured to store the data to be stored based on the target data block.
[0140] Optionally, the processing unit 1202 is specifically configured to:
[0141] Determine a second number of all free data blocks in the UBS; when the second number is greater than or equal to the first number, determine the first number of candidate free data blocks from all the free data blocks; and determine the candidate free data blocks as the target data blocks.
[0142] Optionally, the processing unit 1202 is further configured to:
[0143] In the case that the second number is smaller than the first number, based on the data storage time of all used data blocks in the UBS, a third number of candidate used data blocks is determined from all the used data blocks, and the third number is equal to the difference between the first number and the second number; all the free data blocks and the candidate used data blocks are determined as the target data blocks.
[0144] Optionally, the processing unit 1202 is specifically configured to:
[0145] According to the order of data storage time of all the used data blocks from earliest to latest, the first third number of data blocks among all the used data blocks are determined as the candidate used data blocks.
[0146] Optionally, the data block in the UBS is used to store data output by each channel of the monitoring device, and the processing unit 1202 is specifically used to:
[0147] Determine the first third number of first data blocks corresponding to the first channel in order of data storage times of the used data blocks corresponding to the first channel from earliest to latest;
[0148] Traverse other channels except the first channel, and determine the candidate used data blocks based on the second data block with the earliest data storage time among the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks.
[0149] Optionally, the processing unit 1202 is specifically configured to:
[0150] When the data storage time of the second data block is earlier than the data storage time of the third data block, the second data block is used to replace the third data block to obtain a new first data block; the fourth data block with the second earliest data storage time among the used data blocks corresponding to the other channels currently traversed is determined as the new second data block, and the data block with the latest data storage time among the new first data blocks is used as the new third data block, and this step is repeated until there is a data storage time that is later than the data storage time of the third data block among the used data blocks corresponding to the other channels currently traversed, and the finally determined new first data block is determined as the candidate used data block.
[0151] Optionally, the processing unit 1202 is specifically configured to:
[0152] The third data block is replaced by the second data block, and based on the data storage time of the second data block and the data storage time of each of the other first data blocks except the third data block in the first third number of first data blocks, the second data block is inserted into the other first data blocks to obtain the new first data block; wherein the data storage time of the new first data block is arranged in order from early to late.
[0153] Optionally, the number of the target data blocks is multiple, and the device 120 further includes:
[0154] A mapping unit, configured to determine the offset of each target data block based on the offset position sorting of each target data block in the target disk, and map the storage space of each target data block to a target logical address space based on the offset of each target data block;
[0155] A creating unit, configured to create a target block device based on the target logical address space;
[0156] The storage unit 1203 is specifically configured to store the data to be stored in the target block device.
[0157] The data storage device 120 provided in the embodiment of the present application can execute the technical solution of the data storage method in any of the above-mentioned embodiments. Its implementation principle and beneficial effects are similar to the implementation principle and beneficial effects of the data storage method. Please refer to the implementation principle and beneficial effects of the data storage method, and no further details will be given here.
[0158] Fig.13 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Fig.13 As shown, the electronic device may include: a processor 1310, a communication interface 1320, a memory 1330 and a communication bus 1340, wherein the processor 1310, the communication interface 1320 and the memory 1330 communicate with each other through the communication bus 1340. The processor 1310 may call the logic instructions in the memory 1330 to execute the data storage method, which includes: determining a first number of data blocks required to store the data to be stored based on the amount of data to be stored; determining a first number of target data blocks from the universal data blocks UBS of the target disk, the target data blocks including free data blocks in the UBS and / or used data blocks in the UBS; storing the data to be stored based on the target data blocks.
[0159] In addition, the logic instructions in the above-mentioned memory 1330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
[0160] On the other hand, the present application also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the data storage method provided by the above-mentioned methods, which includes: based on the amount of data to be stored, determining a first number of data blocks required to store the data to be stored; determining a first number of target data blocks from the universal data blocks UBS of the target disk, the target data blocks including free data blocks in the UBS, and / or used data blocks in the UBS; storing the data to be stored based on the target data blocks.
[0161] On the other hand, the present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the data storage method provided by the above-mentioned methods, the method comprising: determining a first number of data blocks required to store the data to be stored based on the amount of data to be stored; determining a first number of target data blocks from the universal data blocks UBS of the target disk, the target data blocks including free data blocks in the UBS, and / or used data blocks in the UBS; and storing the data to be stored based on the target data blocks.
[0162] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0163] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0164] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data storage method, characterized in that: include: Based on the amount of data to be stored, determining a first number of data blocks required to store the data to be stored; Determine the first number of target data blocks from a universal data block UBS of the target disk, wherein the target data blocks include free data blocks in the UBS and / or used data blocks in the UBS; The data to be stored is stored based on the target data block.
2. The data storage method according to claim 1, characterized in that: The determining the first number of target data blocks from the universal data block UBS of the target disk includes: Determining a second number of all free data blocks in the UBS; In a case where the second number is greater than or equal to the first number, determining the first number of candidate free data blocks from all the free data blocks; The candidate idle data block is determined as the target data block.
3. The data storage method according to claim 2, characterized in that: The method further comprises: In the case where the second number is less than the first number, determining a third number of candidate used data blocks from all used data blocks based on the data storage moments of all used data blocks in the UBS, where the third number is equal to the difference between the first number and the second number; All the free data blocks and the candidate used data blocks are determined as the target data blocks.
4. The data storage method according to claim 3, characterized in that: The step of determining a third number of candidate used data blocks from all used data blocks based on the data storage moments of all used data blocks in the UBS comprises: According to the order of data storage time of all the used data blocks from earliest to latest, the first third number of data blocks among all the used data blocks are determined as the candidate used data blocks.
5. The data storage method according to claim 4, characterized in that: The data blocks in the UBS are used to store data output by each channel of the monitoring device, and the first third number of data blocks in the used data blocks are determined as the candidate used data blocks in the order of data storage time from earliest to latest, including: Determine the first third number of first data blocks corresponding to the first channel in order of data storage times of the used data blocks corresponding to the first channel from earliest to latest; Traverse other channels except the first channel, and determine the candidate used data blocks based on the second data block with the earliest data storage time among the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks.
6. The data storage method according to claim 5, characterized in that: The determining of the candidate used data blocks based on the second data block with the earliest data storage time among the used data blocks corresponding to the other channels currently traversed, the third data block with the latest data storage time among the first third number of first data blocks, and the first third number of first data blocks comprises: When the data storage time of the second data block is earlier than the data storage time of the third data block, the second data block is used to replace the third data block to obtain a new first data block; the fourth data block with the second earliest data storage time among the used data blocks corresponding to the other channels currently traversed is determined as the new second data block, and the data block with the latest data storage time among the new first data blocks is used as the new third data block, and this step is repeated until there is a data storage time that is later than the data storage time of the third data block among the used data blocks corresponding to the other channels currently traversed, and the finally determined new first data block is determined as the candidate used data block.
7. The data storage method according to claim 6, characterized in that: The step of replacing the third data block with the second data block to obtain a new first data block includes: The third data block is replaced by the second data block, and based on the data storage time of the second data block and the data storage time of each of the other first data blocks except the third data block in the first third number of first data blocks, the second data block is inserted into the other first data blocks to obtain the new first data block; The data storage times of the new first data blocks are arranged in order from earliest to latest.
8. The data storage method according to any one of claims 1 to 7, characterized in that: The number of the target data blocks is multiple, and storing the data to be stored based on the target data blocks includes: Determine the offset of each target data block based on the offset position sorting of each target data block in the target disk, and map the storage space of each target data block to a target logical address space based on the offset of each target data block; Creating a target block device based on the target logical address space; The data to be stored is stored in the target block device.
9. A data storage device, characterized in that: include: a determining unit, configured to determine, based on the amount of data to be stored, a first number of data blocks required to store the data to be stored; A processing unit, configured to determine the first number of target data blocks from a universal data block UBS of a target disk, wherein the target data blocks include free data blocks in the UBS and / or used data blocks in the UBS; A storage unit is used to store the data to be stored based on the target data block.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the data storage method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Video file processing method and device
CN110531940A
Storage method and device, storage medium and terminal equipment
CN112199050A
Data processing method and device
CN112513804A
Storage device control method, storage device and computer readable storage medium
CN116126212A
Block storage device, data storage method, electronic device and storage medium
CN116301565A