Tablespace defragmentation method, apparatus, electronic device, and storage medium

By migrating data pages to the end of the tablespace in physical order in the InnoDB database to create free pages and then releasing them, the problem of low efficiency in tablespace fragmentation management is solved, disk space reclamation without the creation of new tables is achieved, and disk pressure is reduced.

CN110597797BActive Publication Date: 2026-06-16BEIJING BAIDU NETCOM SCI & TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING BAIDU NETCOM SCI & TECH CO LTD
Filing Date
2019-09-16
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

In the InnoDB database engine, tablespace fragmentation management is inefficient, leading to wasted disk space. Existing methods for reclaiming fragmented data require building new tables, increasing disk space pressure.

Method used

By migrating data in data pages forward in physical order, free data pages are constructed at the end of the tablespace, and these free data pages are released without creating new tables. This merges space fragments in data pages to reduce intra-page fragmentation.

🎯Benefits of technology

It effectively reduces tablespace fragmentation, avoids increasing disk space usage, improves disk space utilization, and reduces the impact on business operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110597797B_ABST
    Figure CN110597797B_ABST
Patent Text Reader

Abstract

The application discloses a table space fragment recovery method and device, electronic equipment and a storage medium, and relates to the technical field of database management systems. The specific implementation scheme is as follows: data in a data page is migrated forward according to a physical order to construct an idle data page at the end of a table space; the table space is a data space formed by a plurality of data pages according to the physical order; and the idle data page at the end of the table space is released. The application can recover the table space fragments without bringing additional pressure to the disk space.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to a data field, and more particularly to the field of database management system technology. Background Technology

[0002] MySQL is a relational database management system, and InnoDB is one of its database engines. In the InnoDB engine, data pages are organized and managed using a B+ tree, with pointers determining the logical order of the data pages. A B+ tree is a tree-like data structure; the data space formed by the physical order of data pages is called a tablespace. The physical order of the same data page in the tablespace is independent of its logical order in the B+ tree.

[0003] InnoDB tablespace fragmentation (hereinafter referred to as "tablespace fragmentation") refers to the unusable free space generated in the tablespace as the InnoDB engine continues to run. Due to the shortcomings of the InnoDB engine in managing tablespace fragmentation, it cannot efficiently utilize these fragmented spaces, leading to a gradual increase in tablespace fragmentation and a progressively worsening waste of disk space.

[0004] Current tablespace fragmentation reclamation technologies generally require building new tables and inserting data from the original tables into the new tables, resulting in a large amount of disk space being occupied and putting significant pressure on disk space. Summary of the Invention

[0005] In a first aspect, embodiments of this application propose a method for reclaiming tablespace fragmentation, including:

[0006] Data in the data pages is migrated forward in physical order to create a free data page at the end of the tablespace; the tablespace is a data space composed of multiple data pages in the physical order.

[0007] Release the free data pages at the end of the tablespace.

[0008] This embodiment first migrates the data in the data pages forward according to their physical order, thereby constructing free data pages at the end of the tablespace, and then releases these free data pages. Since this embodiment does not create new tables during tablespace fragmentation reclamation, the total disk space occupied does not increase, thus avoiding new pressure on disk space.

[0009] In one implementation, before migrating the data in the data page forward in physical order, the method further includes:

[0010] Spatial fragments from different data pages are merged to construct free data pages in a tree-like data structure; the tree-like data structure is a data space composed of multiple data pages in logical order.

[0011] Release the free data pages in the tree data structure.

[0012] In the above embodiments, merging space fragments in data pages before data migration can reduce fragmented space within pages and free up idle data pages for data migration.

[0013] In one implementation, merging spatial fragments in different data pages includes: migrating data in the data pages forward according to the logical order.

[0014] Since data pages are organized and managed in a logical order in a tree data structure, the embodiments of this application can migrate data forward in a logical order when merging space fragments in data pages, thereby reducing fragmented space within pages.

[0015] In one implementation, the step of migrating data in the data page forward in physical order includes:

[0016] Set the data page at the end of the tablespace as the current data page, so as to concentrate the space fragments in the different data pages to the end of the logical order;

[0017] If data exists in the current data page, find the first free data page in the tablespace. If the first free data page is located before the current data page, migrate the data in the current data page to the first free data page in the tablespace.

[0018] Set the previous data page of the current data page as the new current data page, and return to the step of finding the first free data page in the tablespace if a data page exists in the current data page.

[0019] The embodiments of this application adopt a traversal method, migrating data from the last data page to the previous free data page, thereby creating a free data page at the end of the tablespace so as to release the free data page from the end. Therefore, it avoids creating a new table and avoids putting additional pressure on disk space.

[0020] In one implementation, releasing the free data pages at the end of the tablespace includes:

[0021] When consecutive free data pages at the end of the tablespace constitute a free data region, a mutex lock is added to the tablespace.

[0022] Release the free data area and remove the mutex lock.

[0023] In releasing free data pages, this embodiment of the application releases data in units of data regions, and uses mutex locks during the release process to avoid damage to data files during the release of space.

[0024] Secondly, embodiments of this application propose a surface space debris recycling device, comprising:

[0025] The data migration module migrates data in the data pages forward according to their physical order to create a free data page at the end of the tablespace; the tablespace is a data space composed of multiple data pages arranged in the physical order.

[0026] The space reclamation module is used to release free data pages at the end of the tablespace.

[0027] In one implementation, it further includes:

[0028] The defragmentation module is used to merge space fragments in different data pages to construct free data pages in a tree data structure; the tree data structure is a data space composed of multiple data pages in logical order; and to release the free data pages in the tree data structure.

[0029] In one implementation, the fragmentation module is used to migrate data in the data page forward according to the logical order, so that the spatial fragments in the different data pages are concentrated at the end of the logical order.

[0030] In one embodiment, the data migration module includes:

[0031] The setting submodule is used to set the data page at the end of the tablespace as the current data page;

[0032] The migration submodule is used to find the first free data page in the tablespace when data exists in the current data page, and to migrate the data in the current data page to the first free data page in the tablespace if the first free data page is located before the current data page.

[0033] The reset submodule is used to set the previous data page of the current data page as the new current data page, and instruct the migration submodule to perform data migration for the new current data page.

[0034] In one implementation, the defragmentation module is used to add a mutex lock to the tablespace when consecutive free data pages at the end of the tablespace constitute a free data region; release the free data region and remove the mutex lock.

[0035] Thirdly, embodiments of this application provide an electronic device, including:

[0036] At least one processor; and

[0037] A memory communicatively connected to the at least one processor; wherein,

[0038] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in any one of the first aspects.

[0039] Fourthly, embodiments of this application provide a non-transitory computer-readable storage medium storing computer instructions for causing the computer to perform the method described in any one of the first aspects.

[0040] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the method described above.

[0041] One embodiment of the above application has the following advantages or beneficial effects: This embodiment first migrates the data in the data pages forward according to their physical order, thereby constructing free data pages at the end of the tablespace, and then releases these free data pages. Since this embodiment does not create new tables during tablespace fragmentation reclamation, the total disk space occupied does not increase, thus avoiding new pressure on disk space.

[0042] Other effects of the above-mentioned alternative methods will be described below in conjunction with specific embodiments. Attached Figure Description

[0043] The accompanying drawings are provided for a better understanding of this solution and do not constitute a limitation of this application. Wherein:

[0044] Figure 1 The implementation flow of a tablespace fragmentation reclamation method according to an embodiment of this application is as follows. Figure 1 ;

[0045] Figure 2 The implementation flow of a tablespace fragmentation reclamation method according to an embodiment of this application is as follows. Figure 2 ;

[0046] Figure 3 This is a flowchart illustrating the implementation of a tablespace fragmentation reclamation method according to an embodiment of this application, which involves migrating data in a data page forward in physical order.

[0047] Figure 4 This is a flowchart illustrating the implementation of a tablespace fragmentation reclamation method according to an embodiment of this application, specifically the release of free data pages at the end of a tablespace.

[0048] Figure 5A This is a schematic diagram of a data page layout structure applied to an embodiment of this application;

[0049] Figure 5B This is a diagram illustrating the logical order of data pages and the order of data migration.

[0050] Figure 5C This is a schematic diagram of the data page layout structure after fragmentation and defragmentation.

[0051] Figure 5D This is a diagram illustrating data migration.

[0052] Figure 5E This is a schematic diagram of the data page layout after data migration;

[0053] Figure 5F This is a diagram illustrating the free data pages after data migration.

[0054] Figure 5G This is a schematic diagram of the tablespace layout after space reclamation;

[0055] Figure 6 The implementation flow of a tablespace fragmentation reclamation method according to an embodiment of this application is as follows. Figure 3 ;

[0056] Figure 7 This is a schematic diagram of a surface space debris recycling device according to an embodiment of this application. Figure 1 ;

[0057] Figure 8 This is a schematic diagram of a surface space debris recycling device according to an embodiment of this application. Figure 2 ;

[0058] Figure 9 This is a block diagram of an electronic device used to implement the tablespace fragmentation recycling method of the present application embodiments. Detailed Implementation

[0059] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0060] This application proposes a method for reclaiming tablespace fragments. Figure 1 The implementation flow of a tablespace fragmentation reclamation method according to an embodiment of this application is as follows. Figure 1 ,include:

[0061] Step S101: Move the data in the data page forward in physical order to create a free data page at the end of the tablespace; the tablespace is a data space composed of multiple data pages in physical order.

[0062] Step S102: Release the free data pages at the end of the tablespace.

[0063] This application also proposes another method for tablespace fragmentation recycling. Figure 2 The implementation flow of a tablespace fragmentation reclamation method according to an embodiment of this application is as follows. Figure 2 .like Figure 2 As shown, this embodiment further includes the following before step S101 in the above embodiment:

[0064] S201: Merge space fragments in different data pages to construct free data pages in a tree data structure; the tree data structure is a data space composed of multiple data pages in logical order;

[0065] Step S202: Release free data pages in the tree data structure.

[0066] In one possible implementation, the tree data structure can be the B+ tree described above, and releasing free data pages can refer to returning the storage space of free data pages to the operating system.

[0067] In one possible implementation, the method for merging spatial fragments in the data page in step S201 can be: migrating the data in the data page forward in logical order so that the spatial fragments in the different data pages are concentrated at the end of the logical order.

[0068] The tablespace fragmentation recovery technology in the above embodiments can be summarized into three stages:

[0069] Phase 1: Fragmentation: Following the logical order of the B+ tree nodes, migrate the data forward, releasing empty data pages after migration. The goal is to reduce fragmented space within data pages and free up idle data pages for use in the data migration steps. This phase includes steps S201 and S202 mentioned above.

[0070] Phase Two: Data Migration: Data at the end of the tablespace is migrated forward according to the physical order of the tablespace, thereby creating free data pages at the end of the tablespace. These free data pages can be contiguous. This phase includes step S101 mentioned above.

[0071] Phase 3: Space Reclamation: This phase releases free data pages at the end of the tablespace, returning the free space to the operating system and significantly reducing the disk space occupied by the tablespace. This phase includes step S102 described above. In one implementation, the operating system's Truncate interface can be called to completely remove consecutive free data pages from the end of the tablespace and return them to the operating system, thereby achieving the goal of reclaiming tablespace fragmentation.

[0072] In the second stage of data migration, the last data page of the tablespace can be obtained through the tablespace file metadata, and the data in that data page can be migrated to the first free data page in the tablespace. Then, the data pages of the tablespace are traversed from back to front, and the data migration operation is performed one by one.

[0073] Figure 3 The flowchart illustrates the implementation of a tablespace fragmentation reclamation method according to an embodiment of this application, which involves migrating data in a data page forward in physical order, including:

[0074] Step S301: Set the data page at the end of the tablespace as the current data page;

[0075] Step S302: If data exists in the current data page, find the first free data page in the tablespace. If the first free data page is located before the current data page, migrate the data in the current data page to the first free data page in the tablespace;

[0076] Step S303: Set the previous data page of the current data page as the new current data page, and return to step S302.

[0077] In the above process, if there is no data in the current data page, it means that the traversal of the tablespace has been completed, and the execution flow ends. Alternatively, if the first free data page is not before the current data page, it means that there are no free data pages available for data migration, and the current flow ends.

[0078] The data migration process is considered complete when there is no data left in the current data page (i.e., the current data page is an idle data page), and the above traversal process ends.

[0079] In one possible implementation, an Extent can be removed from the list only when consecutive free data pages at the end of the tablespace constitute a free data region (Extent), and the corresponding free space is released using the Truncate interface. However, if tablespace expansion or other changes occur at the end of the data file while the Truncate interface is being called to release free space, the state and metadata of the tablespace file before and after the Truncate operation will be inconsistent, leading to data file corruption. Therefore, this embodiment can acquire a table lock (e.g., a mutex lock) before the Truncate operation to stop all writes to the tablespace file, ensuring the atomicity of the Truncate operation. The table lock is then removed after the Truncate operation.

[0080] Figure 4 The flowchart below illustrates the implementation of a tablespace fragmentation reclamation method according to an embodiment of this application, which involves releasing free data pages at the end of a tablespace. The method includes:

[0081] Step S401: If consecutive free data pages at the end of the tablespace constitute a free data region, add a mutex lock to the tablespace;

[0082] Step S402: Release the free data area and remove the mutex lock.

[0083] The following is for reference Figures 5A to 5G Taking a specific tablespace layout as an example, this paper introduces the fragmentation reclamation process for that tablespace layout.

[0084] Figure 5A This is a schematic diagram of a data page layout structure applied to an embodiment of this application. Figure 5A In the initial state, the root page (page 3) of the B+ tree connects to six other data pages: page 9, page 8, page 7, page 6, page 5, and page 4. The physical order of these seven data pages in the tablespace is: page 3 → page 4 → page 5 → page 6 → page 7 → page 8 → page 9. After the InnoDB engine has been running for a period of time, the data in page 7 and page 6 is completely deleted, becoming free data pages, and are removed from the B+ tree. Figure 5A , 5C In 5D and 5E, gray data pages represent free data pages.

[0085] like Figure 5A As shown, after page7 and page6 are removed, the logical order of the data pages in the B+ tree is: page9 → page8 → page4 → page5.

[0086] Fragmentation will migrate data from back to front according to the logical order of the data pages. Figure 5B This diagram illustrates the logical order of data pages and the order of data migration. Figures 5A to 5G In this context, PK stands for Primary Key, and PK:n represents data with primary key n. For example... Figure 5B As shown, following the logical order from back to front, the data with PK 2 in page 8 is migrated to a free position within page 9; the data with PK 8 in page 4 is migrated to a free position within page 8; this process continues until the data with PK 10 in page 5 is migrated to a free position within page 4; finally, page 5 becomes a free data page. After the defragmentation step, the free data page page 5 is released.

[0087] Figure 5C This is a schematic diagram of the data page layout structure after defragmentation. Figure 5C In this context, page 5 becomes a free data page and is released.

[0088] Afterwards, based on Figure 5C The displayed data page layout moves data from the end of the tablespace forward according to the physical order of the data pages. Figure 5D This is a diagram illustrating data migration. (For example...) Figure 5D As shown, the data in the last data page (page9) of the tablespace is moved to the free data page (page5); traversing forward, the data in the previous data page (page8) is moved to the free data page (page6).

[0089] Data migration adds idle data pages to the B+ tree, adjusts the logical order of the data pages, and releases the original data pages. The data page layout after migration is as follows: Figure 5E As shown.

[0090] After the above data migration process, the data in page 9 is migrated to page 5, and the data in page 8 is migrated to data page 6, thus creating three consecutive free data pages (page 7, page 8, and page 9) at the end of the tablespace, as follows. Figure 5F As shown.

[0091] In the space reclamation step, this embodiment locates the header of consecutive free data pages, calls the Truncate interface, deletes the consecutive free data pages, and returns them to the operating system. Figure 5G This is a schematic diagram of the tablespace layout after space reclamation, such as... Figure 5G As shown, after space reclamation, the number of data pages in the tablespace is reduced, releasing three consecutive free data pages at the end of the tablespace: page7, page8, and page9.

[0092] Figure 6 The implementation flow of a tablespace fragmentation reclamation method according to an embodiment of this application is as follows. Figure 3 ,include:

[0093] Step S601: Obtain the tablespaces that need to be reclaimed for tablespace fragmentation.

[0094] Step S602: Perform defragmentation to eliminate fragmentation within data pages in the tablespace.

[0095] Step S603: Obtain the identifier of the last data page in the tablespace and mark it as the identifier of the current data page (which can be represented by cur_page_no).

[0096] Step S604: Obtain the information of the current data page (which can be represented by cur_page) based on cur_page_no.

[0097] Step S605: Determine if there is data in cur_page. If there is, proceed to step S606; otherwise, proceed to step S612.

[0098] Step S606: Obtain the identifier of the smallest free data page (which can be represented by free_page_no) from the free data page list. The identifier of the smallest free data page is the identifier of the first free data page in the tablespace.

[0099] Step S607: Determine if free_page_no is less than cur_page_no; if so, continue to step S608; otherwise, it means that there are no free data pages available for data migration before cur_page, so terminate the space fragmentation reclamation of the current table and end the process.

[0100] Step S608: Obtain the new data page in the tablespace based on free_page_no (new_page can be used).

[0101] Step S609: Insert new_page into the B+ tree.

[0102] Step S610: Migrate the data in cur_page to new_page.

[0103] Step S611: Release cur_page.

[0104] Step S612: Determine if cur_page is the first data page of the Extent. If it is, proceed to step S613; otherwise, add a flag indicating successful data migration and continue to step S619.

[0105] Step S613: Add a write lock (e.g., a mutex lock) to the tablespace.

[0106] Step S614: Determine if the Extent is idle. If it is idle, continue to step S615; otherwise, remove the write lock, add a flag indicating data migration failure, and continue to step S619.

[0107] In this step, if it is determined that the Extent is not free, it may be because during this fragmentation reclamation process, free data pages that had previously had data removed were rewritten with new data, thus turning those free data pages into non-free data pages again. In this case, the data migration is considered to have failed, and the data migration process restarts from the end of the tablespace.

[0108] Step S615: Remove the Extent from the free list (such as FREE_LIST).

[0109] Step S616: Call the Truncate interface to release the idle Extent.

[0110] Step S617: Remove the write lock mentioned above.

[0111] Step S618: Determine whether the tablespace file traversal is complete; if yes, terminate the space fragmentation reclamation of the current table and end the process; otherwise, add a flag indicating successful data migration and continue to step S619.

[0112] Step S619: Based on the previously added markers, determine whether the data migration was successful. If yes, proceed to step S620; otherwise, proceed to step S621.

[0113] Step S620: Subtract 1 from the value of cur_page_no, and return to step S604. This step processes the next data page from the end to the beginning.

[0114] Step S621: Reset cur_page_no to the identifier of the data page at the end of the tablespace, and return to step S604.

[0115] The above embodiments describe the overall process of defragmentation, data migration, and space reclamation. This application embodiment can be used with InnoDB tablespaces as well as other types of tablespaces. This application embodiment does not create new tables during defragmentation reclamation, and the total disk space occupied does not increase, thus avoiding new pressure on disk space. This application embodiment can reclaim free space in tablespace files and return it to the operating system, thereby truly reducing the disk space occupied by tablespace files and achieving the ultimate goal of freeing up disk space. Furthermore, this application embodiment does not require locking the table throughout the entire process, but only needs to lock a small number of data pages being operated on during data migration; while table locking is required during space reclamation to prevent changes to the tablespace file, the lock holding time is short, resulting in a low impact on business operations.

[0116] This application also proposes a surface space debris recycling device. Figure 7 This is a schematic diagram of the structure of a surface space debris recycling device according to an embodiment of this application. Figure 1 .like Figure 7 As shown, the surface space debris recycling device 700 includes:

[0117] The data migration module 710 migrates data in the data pages forward according to the physical order to construct a free data page at the end of the tablespace; the tablespace is a data space composed of multiple data pages in the physical order.

[0118] The space reclamation module 720 is used to release free data pages at the end of the tablespace.

[0119] This application also proposes another surface space debris recycling device. Figure 8 This is a schematic diagram of the structure of a surface space debris recycling device according to an embodiment of this application. Figure 2 .like Figure 8 As shown, the surface space debris recycling device 800 includes:

[0120] The system includes a data migration module 710, a space reclamation module 720, and a defragmentation module 830. The data migration module 710 and the space reclamation module 720 have the same functions as the corresponding modules in the above embodiments, and will not be described again.

[0121] The defragmentation module 830 is used to merge space fragments in different data pages to construct free data pages in a tree data structure; the tree data structure is a data space composed of multiple data pages in logical order; and to release the free data pages in the tree data structure.

[0122] In one possible implementation, the fragmentation module 830 is used to migrate data in the data page forward according to the logical order, so that the spatial fragments in the different data pages are concentrated at the end of the logical order.

[0123] In one possible implementation, such as Figure 8 As shown, the data migration module 710 includes:

[0124] Setting submodule 711 is used to set the data page at the end of the tablespace as the current data page;

[0125] The migration submodule 712 is used to find the first free data page in the tablespace when data exists in the current data page, and to migrate the data in the current data page to the first free data page in the tablespace when the first free data page is located before the current data page.

[0126] The reset submodule 713 is used to set the previous data page of the current data page as the new current data page, and instruct the migration submodule 712 to perform data migration for the new current data page.

[0127] In one possible implementation, the defragmentation module 830 is used to add a mutex lock to the tablespace when consecutive free data pages at the end of the tablespace constitute a free data region; release the free data region; and remove the mutex lock.

[0128] The functions of each module in the devices of this application embodiment can be found in the corresponding descriptions in the above methods, and will not be repeated here.

[0129] According to embodiments of this application, this application also provides an electronic device, a readable storage medium, and a computer program product.

[0130] like Figure 9 The diagram shown is a block diagram of an electronic device for a tablespace fragmentation recycling method according to an embodiment of this application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of migration devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present application described and / or claimed herein.

[0131] like Figure 9As shown, the electronic device includes one or more processors 901, a memory 902, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components are interconnected via different buses and can be mounted on a common motherboard or otherwise as required. The processors can process instructions executed within the electronic device, including instructions stored in or on memory to display graphical information of a graphical user interface (GUI) on an external input / output device (such as a display device coupled to the interface). In other embodiments, multiple processors and / or multiple buses can be used with multiple memories and multiple storage devices, if desired. Similarly, multiple electronic devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 9 Take the 901 processor as an example.

[0132] The memory 902 is the non-transitory computer-readable storage medium provided in this application. The memory stores instructions executable by at least one processor to cause the at least one processor to perform the tablespace fragmentation reclamation method provided in this application. The non-transitory computer-readable storage medium of this application stores computer instructions for causing a computer to perform the tablespace fragmentation reclamation method provided in this application.

[0133] Memory 902, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions / modules corresponding to the methods in the embodiments of this application (e.g., appendix). Figure 7 (The data migration module 710 and space reclamation module 720 are shown). The processor 901 executes various server functions and data processing by running non-transient software programs, instructions, and modules stored in the memory 902, thereby implementing the tablespace fragmentation reclamation method in the above method embodiments.

[0134] Memory 902 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device during tablespace fragmentation reclaiming. Furthermore, memory 902 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory 902 may optionally include memory remotely located relative to processor 901, which can be connected to the electronic device during tablespace fragmentation reclaiming via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, migration communication networks, and combinations thereof.

[0135] The electronic device for the surface space fragmentation recycling method may further include an input device 903 and an output device 904. The processor 901, memory 902, input device 903, and output device 904 can be connected via a bus or other means. Figure 9 Taking the example of a connection between China and Israel via a bus.

[0136] Input device 903 can receive input digital or character information, as well as key signal input related to user settings and function control of electronic equipment for surface space debris recycling, such as touch screens, keypads, mice, trackpads, touchpads, joysticks, one or more mouse buttons, trackballs, joysticks, etc. Output device 904 may include display devices, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration motors). The display device may include, but is not limited to, liquid crystal displays (LCDs), light-emitting diode (LED) displays, and plasma displays. In some embodiments, the display device may be a touch screen.

[0137] Various implementations of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, application-specific integrated circuits (ASICs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.

[0138] These computational programs (also referred to as programs, software, software applications, or code) include machine instructions for a programmable processor and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device (PLD)) used to provide machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal used to provide machine instructions and / or data to a programmable processor.

[0139] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (Cathode Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0140] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0141] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.

[0142] According to the technical solution of this application embodiment, data in data pages is migrated forward in physical order, thereby constructing free data pages at the end of the tablespace, and then these free data pages are released. Before migration, this application embodiment can first merge space fragments in different data pages to reduce fragmented space within pages, while releasing free data pages for data migration. Since this application embodiment does not create new tables during tablespace fragmentation reclamation, the total disk space occupied does not increase, thus not putting new pressure on disk space.

[0143] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.

[0144] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for recovering surface space fragments, characterized in that, include: Data in a data page is migrated forward in logical order so that space fragments in different data pages are concentrated at the end of the logical order, thereby constructing a free data page in a tree data structure; the tree data structure is a data space composed of multiple data pages in the logical order. Release the free data pages in the tree data structure; The process of migrating data in a data page forward in physical order to create a free data page at the end of the tablespace includes: setting the data page at the end of the tablespace as the current data page; if data exists in the current data page, searching for the first free data page in the tablespace; if the first free data page is located before the current data page, migrating the data in the current data page to the first free data page in the tablespace; setting the data page preceding the current data page as the new current data page, and returning to the step of searching for the first free data page in the tablespace if data exists in the current data page; wherein the tablespace is a data space composed of multiple data pages in the physical order. When consecutive free data pages at the end of the tablespace constitute a free data region, a mutex lock is added to the tablespace. Release the free data area and remove the mutex lock.

2. A surface space debris recycling device, characterized in that, include: The fragmentation module is used to migrate data in a data page forward according to a logical order, so that the space fragments in different data pages are concentrated at the end of the logical order, so as to construct a free data page in the tree data structure; the tree data structure is a data space composed of multiple data pages in the logical order. Release the free data pages in the tree data structure; The data migration module migrates data in the data pages forward according to their physical order to create a free data page at the end of the tablespace; the tablespace is a data space composed of multiple data pages arranged in the physical order. The space reclamation module is used to add a mutex lock to the tablespace when consecutive free data pages at the end of the tablespace constitute a free data area. Release the free data area and remove the mutex lock; The data migration module includes: The setting submodule is used to set the data page at the end of the tablespace as the current data page; The migration submodule is used to find the first free data page in the tablespace when data exists in the current data page, and to migrate the data in the current data page to the first free data page in the tablespace if the first free data page is located before the current data page. The reset submodule is used to set the previous data page of the current data page as the new current data page, and instruct the migration submodule to perform data migration for the new current data page.

3. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of claim 1.

4. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method of claim 1.

5. A computer program product comprising a computer program that, when executed by a processor, implements the method of claim 1.