CN117666926A - Data storage method and device and electronic equipment - Google Patents
Data storage method and device and electronic equipment Download PDFInfo
- Publication number
- CN117666926A CN117666926A CN202211043529.2A CN202211043529A CN117666926A CN 117666926 A CN117666926 A CN 117666926A CN 202211043529 A CN202211043529 A CN 202211043529A CN 117666926 A CN117666926 A CN 117666926A
- Authority
- CN
- China
- Prior art keywords
- time period
- duty ratio
- space
- duty cycle
- storage space
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000013500 data storage Methods 0.000 title claims abstract description 61
- 238000000034 method Methods 0.000 title claims abstract description 51
- 238000004590 computer program Methods 0.000 claims description 11
- 238000004904 shortening Methods 0.000 claims description 10
- 239000002699 waste material Substances 0.000 abstract description 9
- 238000010586 diagram Methods 0.000 description 7
- 238000004891 communication Methods 0.000 description 5
- 238000004364 calculation method Methods 0.000 description 4
- 230000003190 augmentative effect Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000003247 decreasing effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000007689 inspection Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000005192 partition Methods 0.000 description 1
- 230000002035 prolonged effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides a data storage method, a data storage device and electronic equipment, comprising the following steps: space use information of a storage space is acquired every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block; determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer; and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio. The invention can dynamically adjust the size of the index node and avoid the waste of storage space.
Description
Technical Field
The present invention relates to the field of data storage technologies, and in particular, to a data storage method, a data storage device, and an electronic device.
Background
After disk formatting, it is split into two parts, a data block (block) and an inode (inode). Block is the minimum unit of file access to store the actual data content; inodes are used to store meta-information of files, i.e., some attributes of data, such as file size, rights information, owner information, etc. Where the duty cycle of the inodes is given at disk formatting, each inode is typically 256 bytes or 512 bytes. Each file has an inode, each inode has a unique number, and the operating system operates different files according to the number of the inode. When an operating system is to read a certain file, the code number corresponding to the file name is found, then information in the code is acquired, a corresponding block is acquired according to the code information, and data is read from the block.
Because each file is provided with one inode, when the file is small and the inode duty ratio is also small, the condition that the inode of a disk is used up but the whole disk space is not fully stored can occur, so that the disk space is wasted.
Disclosure of Invention
The invention provides a data storage method, a data storage device and electronic equipment, which are used for solving the problem of disk space waste in the prior art.
The invention provides a data storage method, which comprises the following steps: space use information of a storage space is acquired every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block; determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer; and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
According to one embodiment of the present invention, the adjusting the initial duty ratio of the index node in the (i+1) th time period according to the desired duty ratio includes: acquiring the initial duty ratio of the index node in the ith time period; and when the expected duty ratio is greater than or less than the initial duty ratio of the ith time period, determining the expected duty ratio as the initial duty ratio of the index node in the (i+1) th time period.
According to one embodiment of the present invention, the determining the desired duty ratio as the initial duty ratio of the index node in the i+1th period when the desired duty ratio is greater than or less than the initial duty ratio of the i-th period includes: determining a first duty cycle of the data block during the ith time period when the desired duty cycle is greater than an initial duty cycle of the ith time period; determining the desired duty cycle as an initial duty cycle of the i+1th time period when the first duty cycle of the data block matches the desired duty cycle of the inode; determining a second duty cycle of the index node in the ith time period when the expected duty cycle is less than the initial duty cycle of the ith time period; and when the second duty ratio is less than or equal to the expected duty ratio, determining the expected duty ratio as an initial duty ratio in the (i+1) th time period.
According to an embodiment of the present invention, the data storage method further includes: determining a difference between an initial duty cycle of the i-th time period and an initial duty cycle of the i+1-th time period; when the difference exceeds a first threshold, the (i+2) th time period is shortened.
According to an embodiment of the present invention, the data storage method further includes: determining a difference between the initial duty cycles of adjacent time periods prior to the ith time period; and increasing an ith time period when the difference between the initial duty ratios of the adjacent time periods does not exceed the first threshold.
According to an embodiment of the present invention, the data storage method further includes: determining the space utilization rate of the storage space according to the space utilization information of the ith time period; and shortening the target time period when the space utilization exceeds a second threshold.
According to one embodiment of the present invention, the determining the expected duty cycle of the index node in the storage space when the storage space is not available includes: determining the average size of data stored in the ith time period according to the space use information in the ith time period; a desired duty cycle of the inode is determined based on the average size.
The present invention also provides a data storage device comprising: the data acquisition module is used for acquiring space use information of a storage space every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block; the space determining module is used for determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer; and the space allocation module is used for adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
According to an embodiment of the present invention, the space allocation module may specifically include: a first obtaining module, configured to obtain an initial duty ratio of the index node in the ith time period; a first determining module, configured to determine the desired duty ratio as an initial duty ratio of the index node in the i+1th time period when the desired duty ratio is greater than or less than the initial duty ratio of the i time period.
According to one embodiment of the present invention, the first determining module specifically includes: a second determining module, configured to determine, when the expected duty ratio is greater than an initial duty ratio of the ith period, a first duty ratio of the data block in the ith period; a third determining module, configured to determine, when a first duty cycle of the data block matches the expected duty cycle of the inode, the expected duty cycle as an initial duty cycle of the i+1th time period; a fourth determining module, configured to determine a second duty cycle of the inode in the ith time period when the expected duty cycle is less than an initial duty cycle of the ith time period; and a fifth determining module, configured to determine the desired duty ratio as an initial duty ratio in the i+1th time period when the second duty ratio is less than or equal to the desired duty ratio.
According to one embodiment of the present invention, the data storage device further includes: a difference determining module for determining a difference between an initial duty cycle of the i-th time period and an initial duty cycle of the i+1th time period; a time shortening module, configured to shorten the (i+2) th time period when the difference exceeds a first threshold.
According to one embodiment of the present invention, the data storage device further includes: a difference calculation module for determining a difference between the initial duty ratios of the adjacent time periods before the ith time period; a time increasing module, configured to increase an ith time period when the difference between the initial duty ratios of the adjacent time periods does not exceed the first threshold.
According to one embodiment of the present invention, the data storage device further includes: the utilization rate determining module is used for determining the space utilization rate of the storage space according to the space utilization information of the ith time period; and the time period adjusting module is used for shortening the target time period when the space utilization rate exceeds a second threshold value.
According to one embodiment of the present invention, the space determination module specifically includes: the first average module is used for determining the average size of the stored data in the ith time period according to the space use information in the ith time period; and the duty ratio calculation module is used for determining the expected duty ratio of the index node based on the average size.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing a data storage method as described in any of the above when executing the program.
The invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a data storage method as described in any of the above.
The invention also provides a computer program product comprising a computer program which when executed by a processor implements a data storage method as described in any one of the above.
According to the data storage method, the data storage device and the electronic equipment, the space use information of the storage space is acquired at intervals, so that the duty ratio of index nodes (inodes) in the next time period can be adjusted according to the space use information in the previous time period, the sizes of the index nodes are dynamically changed, the actual storage requirement is better met, the waste of the storage space is avoided, and the utilization rate of the storage space is improved.
Drawings
In order to more clearly illustrate the invention or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a data storage method according to the present invention;
FIG. 2 is a schematic diagram of a storage space of a data storage method according to the present invention;
FIG. 3 is a second flow chart of the data storage method according to the present invention;
FIG. 4 is a third flow chart of the data storage method according to the present invention;
FIG. 5 is a schematic diagram of a data storage device according to the present invention;
fig. 6 is a schematic structural diagram of an electronic device provided by the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The block diagrams depicted in the figures are merely functional entities and do not necessarily correspond to physically separate entities. That is, the functional entities may be implemented in software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
The flow diagrams depicted in the figures are exemplary only, and do not necessarily include all of the elements and operations/steps, nor must they be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the order of actual execution may be changed according to actual situations.
In the present specification, the terms "first", "second", "third", and the like are used as labels only, and are not intended to limit the number or order of their objects.
The data storage method, apparatus and electronic device of the present invention are described below with reference to the accompanying drawings.
The embodiment of the invention firstly provides a data storage method. The data storage method may be applied to a mobile phone, a tablet computer, a palm computer, an augmented reality (augmented reality, AR)/Virtual Reality (VR) device, a robot, a wearable device, and various electronic devices such as a server, a personal computer (personal computer, PC), etc., which is not particularly limited in the present invention.
Fig. 1 shows a flowchart of a data storage method in this embodiment. Referring to fig. 1, the data storage method may include the steps of:
Step 10: and acquiring space use information of a storage space every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block.
Storage space refers to a storage medium, such as a disk, that can be used for storage. The method comprises the steps that before the disk in the electronic equipment is used, the disk is required to be formatted, when the disk is formatted, the electronic equipment partitions the disk, the disk is divided into data blocks (blocks) for storing data, namely files, and index nodes (inodes) for storing meta-information, the duty ratio of the index nodes or the data blocks is set, and the sum of the duty ratio of the index nodes and a database is 1, namely the whole disk.
The space usage information refers to space information occupied by currently stored data, and may specifically include the number of stored files, the size or duty ratio of occupied blocks, and the size or duty ratio of occupied inodes. After the storage space formatting is completed, the initial space use information of the storage space can be acquired, and the space use information of the storage space is counted once every target time period.
For example, as shown in fig. 2, the disk (storage space) 20 may be formatted by the electronic device dividing the disk 20 into two areas, an area 201 and an area 202. Region 201 is the region where the index node is located, and region 202 is the region where the data block is located. Assuming that the total size of the disk 20 is a, the index node that the electronic device defaults to when formatting is C (%). After formatting is complete, the initial space usage information of the disk 20 may be as follows in Table 1:
TABLE 1
Time | Initial time of day |
Size of occupation (B) | 0 |
Number of files | 0 |
inode duty cycle | C |
The initial time refers to the time when the disk formatting is completed, and the time when the disk formatting is completed can be determined by acquiring the time of the clock of the electronic device, so that the time is recorded. At this initial time, the occupied size of the disk is empty, i.e., no file is written.
When storing a file, the system will first allocate an inode in area 201 for the file to be stored. The size B of the inode is specified by the system, typically 256 bytes or 512 bytes. The file to be stored is then written into the data block of the region 202 pointed to by the inode.
The space usage information may be acquired every target period from the initial time, thereby acquiring the space usage information at a plurality of different times. The target period of time may be set according to actual requirements, for example, 5 minutes, 500 seconds, 10 minutes, etc., which is not particularly limited in this embodiment. For example, when the target period is 3 minutes and the initial time is 0, the space usage information at the initial time may be acquired as in table 1, and then the space usage information at 3 minutes (1 st period), the space usage information at 6 minutes (2 nd target period), and the like are acquired.
The space usage information for each time period may be recorded in a table, and the structure of the table may be the same as table 1. Alternatively, one table records only space usage information for a specific period of time, which is greater than the target period of time. For example, the space usage information is recorded every 5 minutes, and the space usage information within one day is stored in a table. To reduce the occupation of storage resources, records may be deleted at intervals, such as a table of space usage information of records, etc. every other week.
Step 20: and determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information in the ith time period, wherein i is a positive integer.
i is a time node for starting to adjust the index node duty ratio, and can be determined according to the actual adjustment requirement. i may take on a value from 1, and when i is 1, the first time period is a target time period from the initial time. When the clock of the electronic equipment reaches the first time period, the number of files currently stored in the storage space and the occupied size of the storage space can be queried through the query instruction, so that the space use information of the 1 st time period is obtained. Illustratively, the query instruction "df-h" may be employed to query the size of the occupied storage space; when the number of files is queried, the query instruction "df-i" may be used to query, and the embodiment is not limited thereto.
For example, when the target time period is n minutes, the first time period is n minutes from the initial time, the second time period is n minutes from the n+ initial time, and so on, and when the space usage information of the i-th time period is obtained, the final duty ratio, that is, the expected duty ratio, of the index node when the storage space is not available can be estimated according to the space usage information. When an inode or block in the storage space runs out, the storage space cannot be re-written with data, i.e., is not available.
When the estimated storage space is not available, the method for estimating the expected duty ratio of the index node is as follows: the average size of the stored data by the i-th time period and the number of stored data, i.e., the number of files, are first calculated. The expected duty cycle of the inode is then predicted based on the average size of the stored data and the number of files.
Specifically, taking the first time period as an example, when the time reaches the first time period, space usage information of the storage space in the first time period is obtained, and at this time, the space usage information is as follows in table 2:
TABLE 2
The 1 st time is the time when the 1 st time period is cut off, namely the 1 st time period is from the initial time to the 1 st time; e is the occupied size of the storage space at the 1 st moment, and D is the number of files stored in the storage space at the 1 st moment.
Based on the current space usage information of the 1 st time period, it can be estimated that when the storage space is not available, the average size of the storage data is: (E-BD)/D.
When the block is used up and the inode is used up, the storage space is not available without wasting the storage space. In this case, assuming that the total number of files to be finally written is X and the desired duty ratio of the inode is Y, there are:
from the above relation (1), x=ad/E can be determined; y=bd/E, resulting in the values of X and Y, i.e. the total number of files finally written and the desired duty ratio occupied by the final inode.
Step 30: and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
After the initial duty ratio of the (i+1) th time period is adjusted, the electronic device allocates index nodes and data blocks for the file to be written according to the adjusted initial duty ratio, so that the file is stored. After the duty ratio of the index node of the (i+1) th time period is adjusted, the space usage information of the (i+1) th time period when the (i+1) th time period is cut off can be counted, the steps in the figure 1 are executed, the duty ratio of the index node of the (i+2) th time period is adjusted, and the like until the index node in the storage space is used up or the data block is used up. In this embodiment, the index node may be dynamically adjusted according to the use condition of the actual storage space, so that the use rates of the index node and the data block are near to the optimal use rate at the same time, and when the storage space is used up, the index node and the data block reach the maximum use rate at the same time, so that the space waste caused by more residual space of one of the index node and the data block when the other one is used up is avoided.
If the index node duty cycle is dynamically adjusted from i, then it can be determined whether there is currently waste of storage space based on the desired duty cycle at the i-th time period. The current initial duty ratio of the index node, that is, the initial duty ratio in the ith time period is obtained, and if the estimated expected duty ratio is the same as the initial duty ratio, it is indicated that the utilization rate of the storage space is higher under the condition of the initial duty ratio, and waste is not caused. If the desired duty cycle is greater than the initial duty cycle of the ith time period, this indicates that the initial duty cycle may result in insufficient space for the final inode, thereby wasting storage space. Therefore, when the expected duty ratio is greater than the initial duty ratio in the ith time period, the calculated expected duty ratio is determined to be the initial duty ratio of the index node in the (i+1) th time period, so that the problem that the space of the index node is insufficient and the waste of storage space is caused can be avoided. If the desired duty cycle is less than the initial duty cycle of the ith time period, the specification may result in that when the data block is already used up, the space of the index node remains, thereby wasting storage space. Therefore, when the expected duty ratio is smaller than the initial duty ratio in the i-th period, the calculated expected duty ratio is also taken as the initial duty ratio of the index node in the i+1th period.
In combination with table 2 above, the initial duty cycle of the 1 st time period index node is C, and the calculated desired duty cycle is Y. Then, when C is greater or less than Y, Y is taken as the initial duty cycle of the inode for the subsequent time (i.e., the 2 nd time period). If C is equal to Y, the electronic equipment still allocates space according to the current initial duty ratio without adjusting the current initial duty ratio, and stores data.
The duty ratio of the index node is adjusted, the duty ratio of the data block is synchronously changed, and the data block and the index node are combined into the whole storage space. Therefore, in order to ensure the accuracy of adjusting the duty cycle of the inode, the space that the data block has currently used needs to be considered. Specifically, when the estimated expected duty ratio is greater than the initial duty ratio in the ith time period, determining a first duty ratio of the data block in the ith time period; when the first duty cycle of the data block matches the desired duty cycle of the inode, the desired duty cycle is determined to be the initial duty cycle during the i+1th time period.
Wherein the first duty ratio is a proportion of the data block calculated according to the space usage information of the ith time period, which is actually occupied in the storage space. For example, table 2 above, the first duty cycle is: (E-BD)/A. Thereafter, a determination is made as to whether the first duty cycle matches the desired duty cycle of the inode. If the first duty cycle plus the desired duty cycle is 1 or less, the first duty cycle matches the desired duty cycle. That is, it is calculated whether the value of (E-BD)/A is less than or equal to 1-Y. If the first duty cycle matches the desired duty cycle, the initial duty cycle of the i+1th time period is adjusted to the desired duty cycle.
If the result of the addition of the first duty cycle to the desired duty cycle is greater than 1, then the initial duty cycle of the inode of the storage space cannot be adjusted to the desired duty cycle. In this case, the electronic device may display a prompt to prompt the user that the index node's duty cycle cannot be adjusted.
When the desired duty cycle is less than the initial duty cycle in the ith time period, a second duty cycle of the data block in the ith time period is determined. The second duty ratio is the actual proportion of the index node in the ith time period, and can be calculated through the space use information of the ith time period. Also taking the data shown in table 2 as an example, the second duty cycle is: DB/A. If the second duty cycle is greater than the desired duty cycle, that is, the actual proportion of the index node of the current (i.e., i-th time period) storage space is already greater than the desired duty cycle, then adjusting the initial duty cycle of the index node of the i+1th time period to the desired duty cycle may result in the electronic device failing to reassign the index node, resulting in a storage failure. Therefore, when the second duty ratio is less than or equal to the desired duty ratio, the desired duty ratio is determined as the initial duty ratio in the i+1th period, and it is possible to avoid a situation in which the space allocation is erroneous.
After the initial duty ratio of the (i+1) th time period is adjusted according to the expected duty ratio, the electronic device can allocate an index node for the data to be stored based on the adjusted initial duty ratio for storage. In this embodiment, the space usage information of the storage space is dynamically monitored to dynamically configure the duty ratio of the index node, so that the usage rates of the index node and the data block can be simultaneously optimized, thereby avoiding the waste of the storage capacity and improving the usage rate of the storage space.
In order to ensure timely and effective adjustment, the corresponding time period of each adjustment can be dynamically adjusted. Illustratively, a difference between the initial duty ratio of the i-th period and the initial duty ratio of the i+1th period is determined, and when the difference exceeds a set threshold value, the next period, i.e., the i+2th period, is shortened. This set threshold value is referred to as a first threshold value. The first threshold may be determined according to practical circumstances, e.g. 0.5, 0.3, etc. If the difference between the initial duty ratio of the i+1th time period and the i+1th time period is large, it may be determined that the size and speed of the file written in the i+1th time period are different from those of the i time period, the variation of the duty ratio of the index node is large, and in order to accurately control the duty ratio of the index node, the time period for subsequently adjusting the duty ratio of the index node, i.e., the i+2th time period, may be shortened. The degree of each shortening may be determined according to practical situations, for example, when the target period is n minutes, the i+2th period may be shortened to n/3 minutes, n/2 minutes, or the like, which is not particularly limited in this embodiment. For example, if the time periods before the i+2th time period are each 5 minutes, the i+2th time period may be shortened to 3 minutes.
Illustratively, the i+2th period is resized, and the subsequent period may be the same as the i+2th period, that is, all periods after the i+1th period are shortened. Alternatively, only the i+2th time period is adjusted, and the following time period still adopts the target time period, i.e., the i+3rd time period as the target time period.
Similarly, when the difference between the initial duty ratios of the adjacent time periods does not exceed the first threshold, it can be determined that the consumption speed of the index node is relatively stable, the duty ratio change is relatively small, and in order to reduce the adjustment times, the consumption of the CPU is reduced. Specifically, the difference between the initial duty ratios of adjacent time periods in M (M is more than or equal to 2) time periods before the ith time period is determined, and the ith time period is increased when the difference between the initial duty ratios of the adjacent time periods does not exceed a first threshold value. Alternatively, the i-th period and the subsequent periods are increased uniformly.
For example, if M is 3, the difference of the initial duty ratio between the first time period and the second time period and the difference of the initial duty ratio between the second time period and the third time period are calculated, and if the difference of both the two calculated time periods is less than or equal to the first threshold value, the fourth time period may be increased. By way of example, 1/2, 1/3, etc. may be increased each time on the basis of the target period, and the embodiment is not limited thereto.
After increasing or decreasing the jth (j is equal to or greater than i) time period, the initial duty ratio of the jth time period may be continuously determined, and then it may be determined whether to continuously increase or decrease the jth+1 time period based on the difference between the initial duty ratio of the jth time period and the time period preceding it.
The greater the space usage, the less storage space remains and the higher the timeliness requirement for adjustment. Therefore, the space usage rate of the i-th period can also be determined from the space usage information of the i-th period; when the space usage exceeds the second threshold, the target period is shortened. That is, the initial duty ratio of the index node is adjusted by the shortened target period after the i-th period.
The space utilization rate is the ratio of the occupied size of the current time period to the total size of the storage space. For example, referring to Table 2 above, at time 1, the space usage is E/A. The second threshold may be various values of 0.9, 0.8, 0.7, etc. For example, when the second threshold is 0.8 and the space usage of the storage space reaches 0.8, the target period n is shortened to n/2, and the initial duty ratio of the subsequent period is adjusted according to n/2.
In this embodiment, the duty ratio of the index node in each time period is dynamically adjusted, so that the duty ratio of the index node better meets the requirement of actual data storage, and the sum of the duty ratio of the index node and the duty ratio of the database can be more close to 1 when the storage space is used up, thereby realizing the maximization of the storage space utilization rate.
The data storage method of the present invention may also be implemented by a module, or process, in an electronic device, for example, the module performing the data storage method may be referred to as: a space patrol module (Space Inspection Module, hereinafter abbreviated as SIM). Fig. 3 shows a flow chart of a method of data storage performed by the SIM in this embodiment. Referring to fig. 3, the data storage method may further include the steps of:
step 301, after the disc formatting is completed, the SIM records the initial duty ratio C of the disc inode, the number of files written, the occupied size of the current space, and the current time into the database table. The disk is a storage space, and the database table may have a table structure of table 1 or table 2. Step 302: it is determined whether the space usage reaches 10%, and if so, step 303 is executed. In the case of small space usage, such as less than 10%, fewer files are written, and the calculated desired duty cycle may be inaccurate. In this embodiment, after the space usage reaches 10%, adjustment of the index node duty ratio is started. In step 303, the SIM counts the occupied space of the number of files currently written, determines the expected duty ratio Y of the current time period, and records the expected duty ratio Y in the database table. In step 304, the SIM determines whether the desired duty cycle Y is greater than the initial duty cycle C, and if yes, step 305 is executed; if not, go to step 306. In step 305, the SIM determines whether the utilization of the block reaches (1-Y), and if the utilization of the block reaches 1-Y, step 307 is executed: and (3) returning prompt information to prompt the user that the inode duty ratio cannot be adjusted, and the situation that capacity is wasted possibly exists. If the block utilization does not reach 1-Y, then step 308 is performed: the inode duty cycle of the next time period is adjusted to the desired duty cycle Y.
In step 306, it is determined whether the desired duty ratio Y is equal to the initial duty ratio C, if so, the inode duty ratio of the next time period is not adjusted, i.e., the inode duty ratio of the next time period is still the initial duty ratio. If the desired duty cycle Y is not equal to the initial duty cycle C in step 306, the desired duty cycle Y is less than the initial duty cycle C, step 309 is performed: calculating whether the utilization rate of the inode reaches Y, if so, executing step 307; if not, then step 308 is performed.
In step 310, the SIM module counts time and determines if n minutes have been reached. Wherein n minutes is a preset target time period. If n minutes is reached, i.e. the next time period is reached, execution continues with step 303, where the adjustment of the duty cycle of the next time period inode is performed.
The SIM may also dynamically adjust the size of each time period while adjusting the inode duty cycle of each time period. Fig. 4 shows a flow chart for adjusting the size of a time period, and as shown in fig. 4, the process of adjusting the time period is as follows:
step 401: the SIM module counts time and judges whether n minutes are reached. If n minutes are reached, step 402 is performed: judging whether the space utilization rate exceeds 90%. If n minutes are not reached, the timer is continued. In step 402, if the space usage rate does not exceed 90%, step 403 is executed: comparing whether the difference between the inode duty ratio of the current time period and the previous time period exceeds a first threshold, if yes, executing step 404: shortening n. For example, n is originally 5 minutes, and is shortened to 4 minutes. If the space usage exceeds 90% in step 402, n is shortened to n/2 and then the timer is started with n/2 continuing to return to step 401. If in step 403, the difference between the inode duty ratio of the current time period and the previous time period does not exceed the first threshold, step 405 is executed: judging whether the difference values do not exceed the first threshold value for three consecutive times, if yes, executing step 406: and prolonging n and clearing the times of which the first threshold value is not exceeded. For example, n is originally 5 minutes, and the time period is prolonged to 6 minutes. If in step 405, none of the three consecutive differences exceeds the first threshold, for example, when the last determined difference does not exceed the first threshold, then the number of times that exceeds the first threshold does not reach three consecutive times, in which case step 407 is performed: the number of times that the first threshold is not exceeded is added to 1, which is initially 0.
Then, in step 408, it is determined whether n reaches a maximum value, if so, step 409 is performed to set n to the maximum value. The maximum value of n can be determined in advance, and if n does not reach the maximum value, the timing according to n is continued.
In step 410, it is determined whether n is less than or equal to the minimum value, if yes, step 401 is executed, and the timing is continued according to the shortened n; if not, go to step 411: n is set to a minimum value. And (3) presetting a minimum value of the target time period, if n exceeds the minimum value after shortening, not shortening n, and continuing to time according to the minimum value.
The size of the time period is controlled according to the steps in fig. 4, so that space usage information is counted according to different time periods, and the duty ratio of the index node is adjusted, so that the size of the index node is dynamically changed, and the method is more suitable for the requirement of actually storing data.
Furthermore, the invention also provides a data storage device which can execute the data storage method. The data storage device provided by the invention is described below, and the data storage device described below and the data storage method described above can be referred to correspondingly.
Fig. 5 shows a schematic diagram of the structure of the data storage device. Referring to fig. 5, the data storage device 50 may include: a data obtaining module 51, configured to obtain space usage information of a storage space every a target period, where the storage space includes a data block storing data and an index node corresponding to the data block; a space determining module 52, configured to determine, according to space usage information in an ith time period, an expected duty ratio of the index node in the storage space when the storage space is unavailable, where i is a positive integer; and the space allocation module 53 is configured to adjust an initial duty ratio of the index node in the (i+1) th time period according to the desired duty ratio, and store data in the storage space based on the initial duty ratio.
According to the data storage device provided by the embodiment, the space use information of the storage space is acquired at intervals, so that the duty ratio of index nodes (inodes) in the next time period can be adjusted according to the space use information in the previous time period, the sizes of the index nodes are dynamically changed, the actual storage requirement is better met, the waste of the storage space is avoided, and the utilization rate of the storage space is improved.
According to an embodiment of the present invention, the space allocation module 53 may specifically include: a first obtaining module, configured to obtain an initial duty ratio of the index node in the ith time period; a first determining module, configured to determine the desired duty ratio as an initial duty ratio of the index node in the i+1th time period when the desired duty ratio is greater than or less than the initial duty ratio of the i time period.
According to one embodiment of the present invention, the first determining module specifically includes: a second determining module, configured to determine, when the expected duty ratio is greater than an initial duty ratio of the ith period, a first duty ratio of the data block in the ith period; a third determining module, configured to determine, when a first duty cycle of the data block matches the expected duty cycle of the inode, the expected duty cycle as an initial duty cycle of the i+1th time period; a fourth determining module, configured to determine a second duty cycle of the inode in the ith time period when the expected duty cycle is less than an initial duty cycle of the ith time period; and a fifth determining module, configured to determine the desired duty ratio as an initial duty ratio in the i+1th time period when the second duty ratio is less than or equal to the desired duty ratio.
According to one embodiment of the present invention, the data storage device 50 further includes: a difference determining module for determining a difference between an initial duty cycle of the i-th time period and an initial duty cycle of the i+1th time period; a time shortening module, configured to shorten the (i+2) th time period when the difference exceeds a first threshold.
According to one embodiment of the present invention, the data storage device 50 further includes: a difference calculation module for determining a difference between the initial duty ratios of the adjacent time periods before the ith time period; a time increasing module, configured to increase an ith time period when the difference between the initial duty ratios of the adjacent time periods does not exceed the first threshold.
According to one embodiment of the present invention, the data storage device 50 further includes: the utilization rate determining module is used for determining the space utilization rate of the storage space according to the space utilization information of the ith time period; and the time period adjusting module is used for shortening the target time period when the space utilization rate exceeds a second threshold value.
According to one embodiment of the present invention, the space determination module specifically includes: the first average module is used for determining the average size of the stored data in the ith time period according to the space use information in the ith time period; and the duty ratio calculation module is used for determining the expected duty ratio of the index node based on the average size.
Fig. 6 illustrates a physical schematic diagram of an electronic device, as shown in fig. 6, which may include: processor 610, communication interface (Communications Interface) 620, memory 630, and communication bus 640, wherein processor 610, communication interface 620, and memory 630 communicate with each other via communication bus 640. The processor 610 may invoke logic instructions in the memory 630 to perform a data storage method comprising: space use information of a storage space is acquired every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block; determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer; and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
Further, the logic instructions in the memory 630 may be implemented in the form of software functional units and stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product comprising a computer program storable on a non-transitory computer readable storage medium, the computer program, when executed by a processor, is capable of performing the data storage method provided by the methods described above, the method comprising: space use information of a storage space is acquired every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block; determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer; and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
In yet another aspect, the present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform a data storage method provided by the above methods, the method comprising: space use information of a storage space is acquired every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block; determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer; and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims (10)
1. A method of data storage, comprising:
space use information of a storage space is acquired every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block;
determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer;
and adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
2. The data storage method of claim 1, wherein said adjusting the initial duty cycle of the inode for the i+1th time period according to the desired duty cycle comprises:
Acquiring the initial duty ratio of the index node in the ith time period;
and when the expected duty ratio is greater than or less than the initial duty ratio of the ith time period, determining the expected duty ratio as the initial duty ratio of the index node in the (i+1) th time period.
3. The data storage method of claim 2, wherein the determining the desired duty cycle as the initial duty cycle of the inode for the i+1th period of time when the desired duty cycle is greater than or less than the initial duty cycle of the i-th period of time comprises:
determining a first duty cycle of the data block during the ith time period when the desired duty cycle is greater than an initial duty cycle of the ith time period;
determining the desired duty cycle as an initial duty cycle of the i+1th time period when the first duty cycle of the data block matches the desired duty cycle of the inode;
determining a second duty cycle of the index node in the ith time period when the expected duty cycle is less than the initial duty cycle of the ith time period;
and when the second duty ratio is less than or equal to the expected duty ratio, determining the expected duty ratio as an initial duty ratio in the (i+1) th time period.
4. The data storage method of claim 1, further comprising:
determining a difference between an initial duty cycle of the i-th time period and an initial duty cycle of the i+1-th time period;
when the difference exceeds a first threshold, the (i+2) th time period is shortened.
5. The data storage method of claim 4, further comprising:
determining a difference between the initial duty cycles of adjacent time periods prior to the ith time period;
and increasing an ith time period when the difference between the initial duty ratios of the adjacent time periods does not exceed the first threshold.
6. The data storage method of claim 1, further comprising:
determining the space utilization rate of the storage space according to the space utilization information of the ith time period;
and shortening the target time period when the space utilization exceeds a second threshold.
7. The data storage method of claim 1, wherein the determining the desired duty cycle of the inode in the storage space when the storage space is not available comprises:
determining the average size of data stored in the ith time period according to the space use information in the ith time period;
A desired duty cycle of the inode is determined based on the average size.
8. A data storage device, comprising:
the data acquisition module is used for acquiring space use information of a storage space every other target time period, wherein the storage space comprises a data block for storing data and an index node corresponding to the data block;
the space determining module is used for determining the expected duty ratio of the index node in the storage space when the storage space is unavailable according to the space use information of the ith time period, wherein i is a positive integer;
and the space allocation module is used for adjusting the initial duty ratio of the index node in the (i+1) th time period according to the expected duty ratio, and storing data in the storage space based on the initial duty ratio.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the data storage method of any one of claims 1 to 7 when the program is executed by the processor.
10. A non-transitory computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when executed by a processor, implements the data storage method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211043529.2A CN117666926A (en) | 2022-08-29 | 2022-08-29 | Data storage method and device and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211043529.2A CN117666926A (en) | 2022-08-29 | 2022-08-29 | Data storage method and device and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117666926A true CN117666926A (en) | 2024-03-08 |
Family
ID=90071906
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211043529.2A Pending CN117666926A (en) | 2022-08-29 | 2022-08-29 | Data storage method and device and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117666926A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117971889A (en) * | 2024-03-29 | 2024-05-03 | 天津南大通用数据技术股份有限公司 | SQL performance optimization method based on distributed database |
-
2022
- 2022-08-29 CN CN202211043529.2A patent/CN117666926A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117971889A (en) * | 2024-03-29 | 2024-05-03 | 天津南大通用数据技术股份有限公司 | SQL performance optimization method based on distributed database |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2020253111A1 (en) | Automatic expansion method and apparatus for blockchain node, and operation and maintenance terminal and storage medium | |
CN110289994B (en) | Cluster capacity adjusting method and device | |
CN111522636A (en) | Application container adjusting method, application container adjusting system, computer readable medium and terminal device | |
CN108540568B (en) | Computing capacity sharing method and intelligent equipment | |
CN107656807A (en) | The automatic elastic telescopic method and device of a kind of virtual resource | |
CN106407191B (en) | Data processing method and server | |
CN112367384B (en) | Kafka cluster-based dynamic speed limiting method and device and computer equipment | |
CN117666926A (en) | Data storage method and device and electronic equipment | |
CN114490078A (en) | Dynamic capacity reduction and expansion method, device and equipment for micro-service | |
CN112527746A (en) | Log storage method, device, equipment and storage medium | |
CN114866563A (en) | Capacity expansion method, device, system and storage medium | |
CN111008181A (en) | Method, system, terminal and storage medium for switching storage strategies of distributed file system | |
CN113568891B (en) | Distributed ID generation method, device, server and readable storage medium | |
CN116204311A (en) | Pod cluster capacity expansion and contraction method and device, computer equipment and storage medium | |
CN102904946B (en) | Method and device for managing nodes in cluster | |
CN112436962A (en) | Block chain consensus network dynamic expansion method, electronic device, system and medium | |
CN110061933B (en) | Data processing method and device, equipment and storage medium | |
CN111913913A (en) | Access request processing method and device | |
CN112286623A (en) | Information processing method and device and storage medium | |
CN111506254A (en) | Distributed storage system and management method and device thereof | |
CN114157717A (en) | Micro-service dynamic current limiting system and method | |
CN116166410A (en) | Cloud database processing method and device, electronic equipment and storage medium | |
CN111104381A (en) | Log management method, device and equipment and computer readable storage medium | |
CN114185896B (en) | Data processing method, device, electronic equipment and storage medium | |
CN117194020B (en) | Cloud computing original big data processing method, system and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |