Storage space management method and device, electronic equipment and storage medium
By counting and managing the tenant's storage space usage in a multi-tenant database environment in real time, the problem of resource competition among tenants is solved, and business stability and reliability and accuracy of storage space management are achieved.
Patent Information
- Application Number
- CN202411962535.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-25
AI Technical Summary
In a multi-tenant database environment, different tenants on the same database are affected by the competition for resources, and they cannot effectively manage and allocate storage space.
A storage space management method is proposed, by counting the tenant's storage space usage in real time in the database memory and persisting this information to a persistent storage device, periodically correcting the storage space statistics to ensure the accuracy and reliability of the data.
Real-time statistics and management of tenants' storage space are realized, and resource competition among different tenants is avoided, business operation is ensured, and the reliability and accuracy of storage space statistics are improved.
Smart Images

Figure CN119884048A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a storage space management method and device, an electronic device, and a storage medium. Background Art
[0002] With the exponential growth of data in the computer field and the development of database technology, databases are gradually moving towards multi-tenancy, that is, databases can be shared by multiple tenants. Databases can manage and use the data of multiple tenants, such as performing data queries based on the tenants' data.
[0003] However, in the related technologies, different tenants on the same database often encounter confusion due to competition for database resources, making it impossible to ensure stable business operation. Summary of the invention
[0004] In view of this, one or more embodiments of the present specification provide a storage space management method and device, an electronic device, and a storage medium.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a storage space management method is proposed, which is applied to a database. The method includes:
[0007] If any tenant of the database writes or deletes data into the database, the data is written to the persistent storage device of the database or deleted from the persistent storage device of the database, and the storage space statistics of the tenant are determined in the memory of the database according to the space required by the data;
[0008] Persisting the storage space statistics information of the tenant in the memory to the persistent storage device of the database;
[0009] The storage space statistics of the tenant on the persistent storage device are corrected periodically.
[0010] In one or more possible embodiments of the present specification, the storage space statistical information includes total storage space and used storage space, and the total storage space of each tenant is allocated by the database;
[0011] Writing the data into a persistent storage device of the database, and determining storage space statistics of the tenant in the memory of the database according to the space required by the data, includes:
[0012] If the remaining storage space of the tenant is not less than the space required by the data, after allocating space for the data in the memory of the database based on the space required by the data, the data is written to the persistent storage device of the data, wherein the remaining storage space is the difference between the total storage space and the used storage space;
[0013] If the data fails to be written on the persistent storage device, the space allocated for the data in the memory of the database is reclaimed.
[0014] In one or more possible embodiments of the present specification, deleting the data from the persistent storage device of the database and determining the storage space statistics of the tenant in the memory of the database according to the space required by the data includes:
[0015] After determining the space occupied by the data in the memory of the database, deleting the data from the persistent storage device of the database;
[0016] If the data is successfully deleted from the persistent storage device of the database, the space occupied by the data is reclaimed in the memory of the database.
[0017] In one or more possible embodiments of the present specification, persisting the storage space statistics information of the tenant in the memory to the storage device of the database includes:
[0018] The storage space statistics information of each tenant in the memory is periodically persisted to the storage device of the database at intervals of a first duration.
[0019] In one or more possible embodiments of the present specification, the periodically correcting the storage space statistics information of the tenant on the persistent storage device includes:
[0020] If the time between the current time and the last correction of the storage space statistics information of the tenant on the persistent storage device is the second time, the storage space statistics information of each tenant on the persistent storage device is corrected in the following manner:
[0021] Reading storage space statistics information of the tenant at the correction start time from the memory of the database;
[0022] Traversing all the data of the tenant on the persistent storage device, and counting the space required for data written before the correction start time in all the traversed data as the correction data amount;
[0023] Reading storage space statistics information of the tenant at the end of the traversal from the memory of the database;
[0024] The storage space statistics information of the tenant on the persistent storage device is corrected according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the corrected data amount.
[0025] In one or more possible embodiments of the present specification, the correcting the storage space statistical information of the tenant on the persistent storage device according to the storage space statistical information of the tenant at the correction start time, the storage space statistical information of the tenant at the traversal end time, and the corrected data amount includes:
[0026] Determine the quantity change amount according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the correction data amount;
[0027] Determine and save storage space statistics of the tenant on the persistent storage device according to the corrected data amount and the data change amount.
[0028] In one or more possible embodiments of this specification, the method further includes:
[0029] In the process of traversing all the tenant's data on the persistent storage device, if the tenant deletes the data in the database, a to-be-deleted mark is added to the data that the tenant needs to delete, and the data with the to-be-deleted mark is deleted after the correction of the tenant's storage space statistical information is completed.
[0030] In one or more possible embodiments of this specification, the method further includes:
[0031] If the database is restarted, the storage space statistics information of the tenant on the persistent storage device is loaded into the memory.
[0032] According to a second aspect of one or more embodiments of this specification, a storage space management device is provided, which is applied to a database, and the device includes:
[0033] a data operation module, configured to write the data into a persistent storage device of the database or delete the data from the persistent storage device of the database if any tenant of the database writes or deletes data into the database, and determine storage space statistics of the tenant in the memory of the database according to the space required by the data;
[0034] A persistence module, used to persist the storage space statistics information of the tenant in the memory to the persistent storage device of the database;
[0035] The correction module is used to periodically correct the storage space statistics information of the tenant on the persistent storage device.
[0036] According to a third aspect of one or more embodiments of this specification, a computer program product is provided, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.
[0037] According to a fourth aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0038] processor;
[0039] a memory for storing processor-executable instructions;
[0040] The processor implements the method as described in the first aspect by running the executable instructions.
[0041] According to a fifth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.
[0042] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0043] The storage space management method provided in the embodiments of the present specification is that when the database writes or deletes data for each tenant it contains, it is necessary not only to complete the data writing or data deletion on the persistent storage device, but also to update the tenant's storage space statistical information in the memory based on the written or deleted data, thereby realizing real-time statistics of the tenant's storage space, so that there can be a basis for allocating storage space to each tenant during business processing, avoiding confusion caused by competition for storage resources among different tenants, and ensuring stable business operation; and the tenant's storage space statistical information will be persisted from the memory to the persistent storage device and periodically corrected, so that the storage space statistical information of each tenant is more reliable (because it is stored on the persistent storage device) and more accurate (because it is periodically corrected), further improving the reliability of storage space management of tenants in the database and further improving business stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is a structural diagram of a data system provided by an exemplary embodiment.
[0045] Figure 2 It is a flowchart of a storage space management method provided by an exemplary embodiment.
[0046] Figure 3is a logic diagram of writing data provided by an exemplary embodiment.
[0047] Figure 4 It is a logical diagram of deleting data provided by an exemplary embodiment.
[0048] Figure 5 A logical diagram of correcting storage space statistics provided by an exemplary embodiment.
[0049] Figure 6 It is a structural schematic diagram of a device provided by an exemplary embodiment.
[0050] Figure 7 is a block diagram of a storage space management device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0051] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0052] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0053] First, some concepts involved in this specification are explained.
[0054] File system: The file system is a method used by the operating system to manage files or data on storage devices (commonly disks and solid-state drives), that is, to organize files on storage devices.
[0055] Space management: Disk space statistics and space verification for files written or deleted in the local file system.
[0056] Based on the technical problems mentioned in the background technology, at least one embodiment of the present specification provides a storage space management method, which can perform real-time statistics on the storage space occupied by multiple tenants in the database on the persistent storage device, and persist the statistical results on the persistent storage device, so as to provide a basis for allocating storage space to each tenant, avoiding confusion caused by competition for storage resources among different tenants, so that the space size can be effectively managed in the multi-tenant space management system, so that tenants can make full use of the allocated storage space and there will be no tenant storage space leakage (this is because the storage space between different tenants is isolated from each other).
[0057] The method can be applied to a database, which contains multiple tenants, that is, is responsible for data storage, management, query, etc. of multiple tenants, and these tenants share the storage space of the database's persistent storage device. The database has a persistent storage device and a memory, for example, the persistent storage device can be a disk; the memory is a non-persistent storage medium, but its read and write speed is fast. For example, the database can be a stand-alone database, or a database cluster.
[0058] Please refer to the attached Figure 1 , which exemplarily shows a database with a multi-tenant architecture, which may include a file system layer and multiple tenants communicating with it. The file system layer is used to manage the persistent storage device of the database, for example, to manage the storage space of each tenant on the persistent storage device, that is, to allocate storage space, reclaim storage space, etc.
[0059] Please refer to the attached Figure 2 , which exemplarily shows a flow chart of the method, including step S201 and step S203.
[0060] In step S201, if any tenant of the database writes or deletes data into the database, the data is written to the persistent storage device of the database or deleted from the persistent storage device of the database, and the storage space statistics of the tenant are determined in the memory of the database based on the space required for the data.
[0061] The database can allocate a total storage space to each tenant it contains. The total storage space of a tenant is the maximum space that the tenant is allowed to use on the persistent storage device, that is, the space occupied by the data stored by the tenant on the persistent storage device cannot exceed the total storage space of the tenant. The total storage space allocated by the database to each tenant can be the same or different.
[0062] Furthermore, the database may allocate a storage area on its persistent storage device for each tenant it contains, and the space of the storage area allocated to a tenant may be the total storage space of the tenant.
[0063] For example, the database uses object storage to store data. When a tenant writes data to a persistent storage device, it is written as an object, that is, it is written once in the form of a small file, without overwriting or appending. This makes it easy to count the space occupied by the data written and deleted by the tenant on the persistent storage device. In this example, the database can create a file directory on the persistent storage device for each tenant it contains. When each tenant writes data, it writes the data in the form of a small file under its directory. The file directory is used to divide the data stored by different tenants, and the total storage space is used to limit the space occupied by the data written under the tenant's directory.
[0064] By allocating total storage space, storage area, file directory and other restrictions and guidelines to each tenant, persistent storage devices can achieve data isolation between different tenants, avoiding competition for storage space among different tenants and affecting business stability.
[0065] The storage space statistics information of the tenant may include the above-mentioned total storage space, and may further include used storage space, where the used storage space refers to the space occupied by the data stored by the tenant on the persistent storage device of the database.
[0066] Optionally, this step writes the data into the persistent storage device of the database, and determines the storage space statistics of the tenant in the memory of the database according to the space required by the data, according to the attached Figure 3 Execute as shown:
[0067] First, if the tenant's remaining storage space is not less than the space required by the data, after allocating space for the data in the database's memory based on the space required by the data, the data is written to the data's persistent storage device, wherein the remaining storage space is the difference between the total storage space and the used storage space.
[0068] For example, the remaining storage space of the tenant is determined by the current storage space statistics of the tenant. If the database adopts object storage, when determining the space required for the data to be written, it can be regarded as an object or a small file for statistics to determine its size, that is, the required space. If the remaining storage space of the tenant is not less than the space required for the data to be written, space can be allocated for the data to be written, otherwise space cannot be allocated for the data to be written.
[0069] For example, the space required for the data is increased by the tenant's used storage space in the memory to allocate space for the data. If the allocation fails, the data writing ends with a write failure. If the allocation succeeds, the data to be written is written to the persistent storage device, for example, in the form of an object under the tenant's directory.
[0070] Next, if the data is successfully written on the persistent storage device, the data writing ends with a successful writing. If the data is failed to be written on the persistent storage device, the space allocated for the data in the database memory is reclaimed, and the data writing ends with a failed writing.
[0071] For example, the space required by the data is subtracted from the tenant's used storage space in memory to reclaim the space allocated for the data.
[0072] This optional example updates the tenant's storage space statistics in memory before writing data, and restores the tenant's storage space statistics to the state before the update after a write fails, ensuring that each data write can update the tenant's storage space statistics in real time and accurately.
[0073] Optionally, this step deletes the data from the persistent storage device of the database, and when determining the storage space statistics of the tenant in the memory of the database according to the space required by the data, the attached Figure 4 Execute as shown:
[0074] First, after determining the space occupied by the data in the memory of the database, the data is deleted from the persistent storage device of the database.
[0075] For example, if the database adopts an object storage method, statistics can be collected for the object of the data to be deleted to determine the space occupied by the object on the persistent storage device.
[0076] Next, if the data fails to be deleted from the persistent storage device of the database, the data deletion ends as a deletion failure. If the data is successfully deleted from the persistent storage device of the database, the space occupied by the data is reclaimed in the memory of the database.
[0077] For example, the space occupied by the data is subtracted from the tenant's used storage space in the memory to reclaim the space occupied by the data.
[0078] This optional example determines the space occupied by the deleted data in the memory before deleting the data, and updates the tenant's storage space statistics accordingly after the deletion is successful, ensuring that the tenant's storage space statistics can be updated in real time and accurately each time the data is deleted.
[0079] In summary, after the total storage space of the persistent storage device is allocated to the new tenant, the tenant's used storage space and total storage space are recorded in the memory. At the same time, a new directory is created on the disk for the new tenant to store the tenant's data. The tenant's data is written once in the form of small files. There is no overwrite or append of files, and all the tenant's files are spread out in the tenant directory. When the tenant writes a small file to the disk, the tenant's used storage space will increase by the corresponding file size, but it cannot exceed the tenant's total storage space; when a small file of the tenant is deleted from the disk, the tenant's used storage space will decrease by the corresponding file size.
[0080] In step S202, the storage space statistics information of the tenant in the memory is persisted to the persistent storage device of the database.
[0081] The storage space statistics of the tenants in the memory are persisted to the persistent storage device of the database because the data in the memory is non-persistently stored. In the event of a power outage or other unexpected situation, the database will crash and restart. In this case, the storage space statistics of the tenants in the memory will be lost, while the storage space statistics of the tenants stored on the persistent storage device can be directly obtained after the restart, avoiding re-counting.
[0082] In this step, after the storage space statistics information of a tenant in the memory is updated in step S201, the storage space statistics information of the tenant is synchronously and persistently stored in the persistent storage device.
[0083] Alternatively, this step may be performed in the following manner: periodically persisting the storage space statistics information of each tenant in the memory to the storage device of the database at intervals of the first time period. Periodically persisting the storage space statistics information of each tenant can avoid persisting the storage space statistics information too frequently.
[0084] Based on this step, the method may further include: if the database is restarted, the storage space statistics of the tenants on the persistent storage device are loaded into the memory. Thus, the storage space statistics of each tenant on the persistent storage device can be quickly obtained when the database is restarted, and services can be provided externally based on the information, thereby improving the efficiency of database restart and service performance.
[0085] In step S203, the storage space statistics information of the tenant on the persistent storage device is corrected periodically.
[0086] The storage space statistics information loaded from the persistent storage device to the memory after the database crashes and restarts is not an accurate value. In order to ensure that the storage space statistics information of the tenant is accurate, the storage space statistics information can be regularly corrected according to this step. Among them, this step can periodically correct the storage space statistics information of the tenant on the persistent storage device at intervals of a second time length. Preferably, the second time length is greater than the first time length.
[0087] For example, if the time between the current time and the last correction of the storage space statistics information of the tenant on the persistent storage device is the second time, the storage space statistics information of each tenant on the persistent storage device is corrected in the following manner:
[0088] First, the storage space statistics of the tenant at the correction start time are read from the memory of the database. For example, the correction start time is recorded as Time1, and the used storage space in the storage space statistics of the tenant at Time1 is recorded as alloc_size1. Because when correcting the storage space statistics of the tenant, only the used storage space needs to be corrected, and the total storage space does not need to be corrected. The total storage space is a fixed value allocated by the database.
[0089] Next, all the data of the tenant on the persistent storage device is traversed, and the space required for the data with a write time before the correction start time in all the traversed data is counted as the correction data amount. Continuing with the example, when traversing a certain data, the space and write time required can be determined by counting (statistics) the data. If the write time of the data is before Time1, it is regarded as data with a write time before the correction start time, and the space required is added to the current correction statistics; after traversing all the data, the current correction statistics are used as the correction data amount, that is, the sum of the space required for all data with a write time before Time1 is used as the correction statistics, which is recorded as alloc_size2.
[0090] Next, the storage space statistics information of the tenant at the end of the traversal is read from the memory of the database. For example, the used storage space in the storage space statistics information of the tenant at the end of the traversal is recorded as alloc_size3.
[0091] Finally, the storage space statistics of the tenant on the persistent storage device are corrected according to the storage space statistics of the tenant at the start time of the correction, the storage space statistics of the tenant at the end time of the traversal, and the corrected data volume. Preferably, the quantity change can be determined first according to the storage space statistics of the tenant at the start time of the correction, the storage space statistics of the tenant at the end time of the traversal, and the corrected data volume; then, the storage space statistics of the tenant on the persistent storage device are determined and saved according to the corrected data volume and the data change. The corrected storage space statistics of the tenant can be synchronously written to the memory and the persistent storage device. Continuing with the example, the used storage space in the corrected storage space statistics of the tenant is alloc_size2+alloc_size3-alloc_size1.
[0092] This example may also include: in the process of traversing all the data of the tenant on the persistent storage device, if the tenant deletes the data in the database, then the data to be deleted by the tenant is marked as to be deleted, and the data with the mark to be deleted is deleted after the correction of the storage space statistics of the tenant is completed. For example, in the process of traversing all the data of the tenant, the file name x of the data to be deleted is renamed to x.delete; after the correction of the storage space statistics of the tenant is completed, the data to which the file name with ".delete" belongs can be actually deleted. Of course, the storage space statistics of the tenant will be updated in the memory during this operation. In this way, the deletion of data during the traversal of data can be avoided from affecting the statistical results during the traversal process, thereby ensuring the accuracy of the storage space statistics during the correction; moreover, the rename operation of the file system is an atomic operation, and the operation is either completely successful or completely failed, and there will be no intermediate state, thus ensuring data consistency.
[0093] In summary, combining the above examples, we can get the following Figure 5 The process of storage space correction is shown below:
[0094] First, record the current time Time1 and the available storage space alloc_size1 of the tenant in memory.
[0095] Next, all the data of the tenant in the persistent storage device is traversed, and the space alloc_size2 occupied by all the data written before Time1 is counted. If the tenant deletes some data written before Time1 during the traversal, the data is re-added with the to-be-deleted mark .delete.
[0096] Next, at the end of the traversal, the available storage space alloc_size3 of the tenant in the memory is recorded.
[0097] Next, the available storage space of the tenant in the memory and persistent storage device is corrected to alloc_size2+alloc_size3-alloc_size1. If there is data with a to-be-deleted mark, the data with the to-be-deleted mark .delete needs to be deleted to release the occupied space.
[0098] The storage space management method provided in the embodiments of the present specification is that when the database writes or deletes data for each tenant it contains, it is necessary not only to complete the data writing or data deletion on the persistent storage device, but also to update the tenant's storage space statistical information in the memory based on the written or deleted data, thereby realizing real-time statistics of the tenant's storage space, so that there can be a basis for allocating storage space to each tenant during business processing, avoiding confusion caused by competition for storage resources among different tenants, and ensuring stable business operation; and the tenant's storage space statistical information will be persisted from the memory to the persistent storage device and periodically corrected, so that the storage space statistical information of each tenant is more reliable (because it is stored on the persistent storage device) and more accurate (because it is periodically corrected), further improving the reliability of storage space management of tenants in the database and further improving business stability.
[0099] Figure 6 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 6 At the hardware level, the device includes a processor 602, an internal bus 604, a network interface 606, a memory 608, and a non-volatile memory 610, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 602 reading the corresponding computer program from the non-volatile memory 610 into the memory 608 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0100] Please refer to Figure 7 , the storage space management device can be applied to Figure 6 The storage space management device may include:
[0101] The data operation module 701 is used for writing the data to the persistent storage device of the database or deleting the data from the persistent storage device of the database if any tenant of the database writes or deletes data into the database, and determining the storage space statistics of the tenant in the memory of the database according to the space required by the data;
[0102] A persistence module 702, used to persist the storage space statistics information of the tenant in the memory to the persistent storage device of the database;
[0103] The correction module 703 is used to periodically correct the storage space statistics information of the tenant on the persistent storage device.
[0104] In one or more possible embodiments of the present specification, the storage space statistical information includes total storage space and used storage space, and the total storage space of each tenant is allocated by the database;
[0105] The data operation module is used to write the data into the persistent storage device of the database, and when determining the storage space statistics of the tenant in the memory of the database according to the space required by the data, is used to:
[0106] If the remaining storage space of the tenant is not less than the space required by the data, after allocating space for the data in the memory of the database based on the space required by the data, the data is written to the persistent storage device of the data, wherein the remaining storage space is the difference between the total storage space and the used storage space;
[0107] If the data fails to be written on the persistent storage device, the space allocated for the data in the memory of the database is reclaimed.
[0108] In one or more possible embodiments of the present specification, the data operation module is used to delete the data from the persistent storage device of the database, and when determining the storage space statistics information of the tenant in the memory of the database according to the space required by the data, is used to:
[0109] After determining the space occupied by the data in the memory of the database, deleting the data from the persistent storage device of the database;
[0110] If the data is successfully deleted from the persistent storage device of the database, the space occupied by the data is reclaimed in the memory of the database.
[0111] In one or more possible embodiments of the present specification, the persistence module is used to:
[0112] The storage space statistics information of each tenant in the memory is periodically persisted to the storage device of the database at intervals of a first duration.
[0113] In one or more possible embodiments of the present specification, the correction module is used to:
[0114] If the time between the current time and the last correction of the storage space statistics information of the tenant on the persistent storage device is the second time, the storage space statistics information of each tenant on the persistent storage device is corrected in the following manner:
[0115] Reading storage space statistics information of the tenant at the correction start time from the memory of the database;
[0116] Traversing all the data of the tenant on the persistent storage device, and counting the space required for data written before the correction start time in all the traversed data as the correction data amount;
[0117] Reading storage space statistics information of the tenant at the end of the traversal from the memory of the database;
[0118] The storage space statistics information of the tenant on the persistent storage device is corrected according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the corrected data amount.
[0119] In one or more possible embodiments of the present specification, the correction module is used to correct the storage space statistical information of the tenant on the persistent storage device according to the storage space statistical information of the tenant at the correction start time, the storage space statistical information of the tenant at the traversal end time, and the correction data amount, and is used to:
[0120] Determine the quantity change amount according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the correction data amount;
[0121] Determine and save storage space statistics of the tenant on the persistent storage device according to the corrected data amount and the data change amount.
[0122] In one or more possible embodiments of the present specification, the device further includes a deletion module, configured to:
[0123] In the process of traversing all the tenant's data on the persistent storage device, if the tenant deletes the data in the database, a to-be-deleted mark is added to the data that the tenant needs to delete, and the data with the to-be-deleted mark is deleted after the correction of the tenant's storage space statistical information is completed.
[0124] In one or more possible embodiments of the present specification, the device further includes a restart module, configured to:
[0125] If the database is restarted, the storage space statistics information of the tenant on the persistent storage device is loaded into the memory.
[0126] The functions of each module in the above-mentioned device have been introduced in detail in the method embodiment of the first aspect, and will not be repeated here.
[0127] One or more embodiments of the present specification also propose a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the storage space management method provided in any of the above embodiments.
[0128] One or more embodiments of the present specification also provide a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the storage space management method provided in any of the above embodiments.
[0129] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0130] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0131] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0132] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0133] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0134] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0135] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0136] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0137] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0138] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A storage space management method, applied to a database, comprising: If any tenant of the database writes or deletes data into the database, the data is written to the persistent storage device of the database or deleted from the persistent storage device of the database, and the storage space statistics of the tenant are determined in the memory of the database according to the space required by the data; Persisting the storage space statistics information of the tenant in the memory to the persistent storage device of the database; The storage space statistics of the tenant on the persistent storage device are corrected periodically.
2. The storage space management method according to claim 1, wherein the storage space statistical information includes total storage space and used storage space, and the total storage space of each tenant is allocated by the database; Writing the data into a persistent storage device of the database, and determining storage space statistics of the tenant in the memory of the database according to the space required by the data, includes: If the remaining storage space of the tenant is not less than the space required by the data, after allocating space for the data in the memory of the database based on the space required by the data, the data is written to the persistent storage device of the data, wherein the remaining storage space is the difference between the total storage space and the used storage space; If the data fails to be written on the persistent storage device, the space allocated for the data in the memory of the database is reclaimed.
3. The storage space management method according to claim 1, wherein the data is deleted from the persistent storage device of the database, and storage space statistics of the tenant are determined in the memory of the database according to the space required by the data, comprising: After determining the space occupied by the data in the memory of the database, deleting the data from the persistent storage device of the database; If the data is successfully deleted from the persistent storage device of the database, the space occupied by the data is reclaimed in the memory of the database.
4. According to the storage space management method of claim 1, the step of persisting the storage space statistical information of the tenant in the memory to the storage device of the database comprises: The storage space statistics information of each tenant in the memory is periodically persisted to the storage device of the database at intervals of a first duration.
5. The storage space management method according to claim 1, wherein the periodically correcting the storage space statistics of the tenant on the persistent storage device comprises: If the time between the current time and the last correction of the storage space statistics information of the tenant on the persistent storage device is the second time, the storage space statistics information of each tenant on the persistent storage device is corrected in the following manner: Reading storage space statistics information of the tenant at the correction start time from the memory of the database; Traversing all the data of the tenant on the persistent storage device, and counting the space required for data written before the correction start time in all the traversed data as the correction data amount; Reading storage space statistics information of the tenant at the end of the traversal from the memory of the database; The storage space statistics information of the tenant on the persistent storage device is corrected according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the corrected data amount.
6. The storage space management method according to claim 5, wherein the storage space statistical information of the tenant on the persistent storage device is corrected according to the storage space statistical information of the tenant at the correction start time, the storage space statistical information of the tenant at the traversal end time, and the corrected data volume, comprising: Determine the quantity change amount according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the correction data amount; Determine and save storage space statistics of the tenant on the persistent storage device according to the corrected data amount and the data change amount.
7. The storage space management method according to claim 5, further comprising: In the process of traversing all the tenant's data on the persistent storage device, if the tenant deletes the data in the database, a to-be-deleted mark is added to the data that the tenant needs to delete, and the data with the to-be-deleted mark is deleted after the correction of the tenant's storage space statistical information is completed.
8. The storage space management method according to claim 1, further comprising: If the database is restarted, the storage space statistics information of the tenant on the persistent storage device is loaded into the memory.
9. A storage space management device, applied to a database, comprising: a data operation module, configured to write the data into a persistent storage device of the database or delete the data from the persistent storage device of the database if any tenant of the database writes or deletes data into the database, and determine storage space statistics of the tenant in the memory of the database according to the space required by the data; A persistence module, used to persist the storage space statistics information of the tenant in the memory to the persistent storage device of the database; The correction module is used to periodically correct the storage space statistics information of the tenant on the persistent storage device.
10. The storage space management device according to claim 9, wherein the storage space statistical information includes total storage space and used storage space, and the total storage space of each tenant is allocated by the database; The data operation module is used to write the data into the persistent storage device of the database, and when determining the storage space statistics of the tenant in the memory of the database according to the space required by the data, is used to: If the remaining storage space of the tenant is not less than the space required by the data, after allocating space for the data in the memory of the database based on the space required by the data, the data is written to the persistent storage device of the data, wherein: The remaining storage space is the difference between the total storage space and the used storage space; If the data fails to be written on the persistent storage device, the space allocated for the data in the memory of the database is reclaimed.
11. The storage space management device according to claim 9, wherein the data operation module is used to delete the data from the persistent storage device of the database, and when determining the storage space statistics information of the tenant in the memory of the database according to the space required by the data, is used to: After determining the space occupied by the data in the memory of the database, deleting the data from the persistent storage device of the database; If the data is successfully deleted from the persistent storage device of the database, the space occupied by the data is reclaimed in the memory of the database.
12. The storage space management device according to claim 9, wherein the persistence module is used for: The storage space statistics information of each tenant in the memory is periodically persisted to the storage device of the database at intervals of a first duration.
13. The storage space management device according to claim 9, wherein the correction module is used for: If the time between the current time and the last correction of the storage space statistics information of the tenant on the persistent storage device is the second time, the storage space statistics information of each tenant on the persistent storage device is corrected in the following manner: Reading storage space statistics information of the tenant at the correction start time from the memory of the database; Traversing all the data of the tenant on the persistent storage device, and counting the space required for data written before the correction start time in all the traversed data as the correction data amount; Reading storage space statistics information of the tenant at the end of the traversal from the memory of the database; The storage space statistics information of the tenant on the persistent storage device is corrected according to the storage space statistics information of the tenant at the correction start time, the storage space statistics information of the tenant at the traversal end time, and the corrected data amount.
14. The storage space management device according to claim 13, further comprising a deletion module, configured to: In the process of traversing all the tenant's data on the persistent storage device, if the tenant deletes the data in the database, a to-be-deleted mark is added to the data that the tenant needs to delete, and the data with the to-be-deleted mark is deleted after the correction of the tenant's storage space statistical information is completed.
15. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 8.
16. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 8 by running the executable instructions.
17. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 8.