Database rollback resource processing method and apparatus, computer device, and medium
By determining the actual and target number of pages in the rollback segment in the database, identifying and scheduling redundant data pages, the problem of space expansion and excessive I/O overhead of undo resources is solved, and resource utilization and database performance are improved.
Patent Information
- Application Number
- PCT/CN2023/093173
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-26
- Filing Date
- 2023-05-10
- Publication Date
- 2024-10-31
AI Technical Summary
The space expansion and excessive I/O overhead of undo resources in the database lead to performance degradation, especially in high concurrency scenarios, resource imbalance leads to table space expansion and low utilization.
By determining the actual number of pages and the target number of pages in each rollback segment, identify redundant data pages, perform balanced scheduling, and recycle redundant data pages to the preset table space to ensure that the number of data pages on each rollback segment is consistent with Actual consumption matching reduces redundant data pages and improves resource utilization.
It effectively reduces the space expansion caused by redundant rollback segments in the database, improves resource utilization, reduces I/O overhead, ensures that data pages are recycled in memory, and improves database performance.
Smart Images

Figure CN2023093173_31102024_PF_FP_ABST
Abstract
Description
Database rollback resource processing method, device, computer equipment and medium Technical Field
[0001] The present application relates to the field of computers, and in particular to a method, apparatus, computer equipment, and medium for processing database rollback resources. Background Art
[0002] In a database, undo is often referred to as undoing data or rolling back data. It is a logging mechanism for a database to save historical versions of data. Undo is used for transaction MVCC (multi-version concurrency control) management and transaction rollback, and stores multiple versions of old data.
[0003] In database applications, undo resources are limited, scarce, and require a large amount of access. Especially in performance-sensitive scenarios, the efficiency of undo data page allocation, access, and other related operations will have a significant impact on performance. On the one hand, the problem of undo space expansion is a problem faced by all database vendors in database use; on the other hand, uneven distribution of undo resources will lead to I / O
[0004] Excessive (input / output) problems and resource imbalance have a significant impact on database performance.
[0005] Summary of the Invention
[0006] In view of the above problems, the present application is proposed to provide a database rollback resource processing method, apparatus, computer device, and medium that overcome the above problems or at least partially solve the above problems, including:
[0007] A method for processing database rollback resources, wherein the database is used to set a corresponding rollback segment for a data service when the data service is running, the rollback segment being composed of data pages, the method comprising:
[0008] Determine the target rollback segment;
[0009] Determine the actual number of pages of the target rollback segment;
[0010] Calculate the target number of pages of the target rollback segment based on the actual number of pages;
[0011] When the actual number of pages is greater than the target number of pages, determining redundant data pages in the target rollback segment;
[0012] Balanced scheduling is performed on the redundant data pages.
[0013] Furthermore, performing balanced scheduling on the redundant data pages includes:
[0014] The redundant data pages are recycled to a preset table space.
[0015] Furthermore, the method further includes: when the actual number of pages is greater than the target number of pages, returning to the step of determining the actual number of pages of the target rollback segment after determining the redundant data pages in the target rollback segment;
[0016] When the actual number of pages is not greater than the target number of pages, the process returns to the step of determining the target rollback segment.
[0017] Furthermore, the calculating the target number of pages of the target rollback segment based on the actual number of pages includes:
[0018] Read the commit time, current time, and preset retention time corresponding to the chain head data page of the target rollback segment;
[0019] Calculate the target number of pages N2 based on the actual number of pages N1, the submission time T1, the current time T2, and the retention time T3;
[0020] Among them, N2=N1*T3 / (T2-T1).
[0021] Furthermore, the step of determining the target rollback segment includes:
[0022] Reading polling information; the polling information is used to record the rollback segment corresponding to the data service;
[0023] The rollback segments in the polling information are sequentially determined as target rollback segments.
[0024] Furthermore, the method further includes: in response to the resource request, determining a rollback segment to be allocated corresponding to the resource request;
[0025] The performing balanced scheduling on the redundant data page includes: transferring the redundant data page to the rollback segment to be allocated.
[0026] Furthermore, the resource request is generated in the following manner:
[0027] Detect the resource shortage type and resource shortage frequency of each rollback segment;
[0028] Calculating a resource strain statistic according to the resource strain type and the resource strain frequency;
[0029] A resource request is generated for the rollback segment whose resource shortage statistic reaches a preset threshold.
[0030] A database rollback resource processing device, wherein the database is used to set a corresponding rollback segment for a data service when the data service is running, and the rollback segment is composed of data pages. The device includes:
[0031] A target rollback segment determination module is used to determine the target rollback segment;
[0032] An actual page number determination module, configured to determine the actual page number of the target rollback segment;
[0033] A target page number calculation module, configured to calculate a target page number of the target rollback segment based on the actual page number;
[0034] a redundant data page determination module, configured to determine redundant data pages in the target rollback segment when the actual number of pages is greater than the target number of pages;
[0035] The balancing module is used to perform balanced scheduling on the redundant data pages.
[0036] A computer device includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the steps of the above-mentioned database rollback resource processing method are implemented.
[0037] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the above-mentioned method for processing database rollback resources.
[0038] This application has the following advantages:
[0039] In an embodiment of the present application, in response to the problems of undo space expansion and excessive I / O overhead in the prior art, the present application provides a solution for determining the actual number of pages and the target number of pages of each rollback segment, thereby determining the redundant data pages in each rollback segment, and performing balanced scheduling on the redundant data pages. Specifically, the database is used to set a corresponding rollback segment for the data business when running the data business, and the rollback segment is composed of data pages, by determining the target rollback segment; determining the actual number of pages of the target rollback segment; calculating the target number of pages of the target rollback segment based on the actual number of pages; when the actual number of pages is greater than the target number of pages, determining the redundant data pages in the target rollback segment; and performing balanced scheduling on the redundant data pages. By identifying redundant data pages in the rollback segment and performing balanced scheduling for the redundant data pages, the problems of undo space expansion and excessive I / O overhead are solved, and the redundant data pages in the rollback segment corresponding to each data business are reduced to even no redundant data pages, avoiding the problem of space expansion due to the existence of a large number of redundant rollback segments. At the same time, by balanced scheduling of redundant data pages, the redundant data pages in each data business are promptly recovered, and other data businesses can use the redundant data pages in a timely manner, reducing I / O overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for the description of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0041] FIG1 is a flowchart of a method for processing database rollback resources provided by an embodiment of the present application;
[0042] FIG2 is a flowchart of a database rollback resource processing method provided by an embodiment of the present application;
[0043] FIG3 is a functional block diagram of a database provided by an embodiment of the present application;
[0044] FIG4 is a flowchart of another method for processing database rollback resources provided by an embodiment of the present application;
[0045] FIG5 is a flowchart of another database rollback resource processing method provided by an embodiment of the present application;
[0046] FIG6 is a functional block diagram of another database provided in an embodiment of the present application;
[0047] 7 is a structural block diagram of a database rollback resource processing device provided by an embodiment of the present application;
[0048] FIG8 is a schematic structural diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] To make the objectives, features, and advantages of this application more readily apparent, the present application is further described below in conjunction with the accompanying drawings and specific embodiments. It is apparent that the embodiments described are only a portion of the embodiments of this application, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments in this application without inventive effort are also within the scope of protection of this application.
[0050] Undo, often referred to as undo data or rollback data, is a database logging mechanism that stores historical versions of data. A database can typically have several undo tablespaces (a tablespace is a logical concept in the database, organizing several files to store data pages that require persistence within the database), but only one can be used at a time. Undo data pages managed within an undo tablespace serve as the most basic storage unit, preserving historical data for data services running in the database. When data services need to access historical versions of data or when rolling back ongoing transactions, undo data must be accessed. Therefore, accessing and reading and writing undo data pages significantly impacts database performance.
[0051] In general, to enable concurrent use of undo resources, many databases adopt the logical concept of rollback segments. Each transaction can be bound to a rollback segment (a rollback segment is a logical unit used to manage data page allocation in the database's undo tablespace). This rollback segment is used to allocate the transaction's use of undo resources. To achieve concurrent processing, the database strives to bind different rollback segments to different transactions. Each rollback segment manages a portion of undo data pages, ensuring that the undo data pages used by different transactions are not affected by each other. After these transactions are committed or rolled back, the data page chain consisting of the undo data pages used during the transaction is returned to the bound logical undo rollback segment. Each rollback segment then manages these data pages for redistribution.
[0052] However, undo resources are limited, and the historical data generated by database data services cannot be retained permanently. Therefore, the database generally provides a configurable parameter as the time period that the user wishes to retain undo. When allocating an undo data page, the database will check the time interval from the moment the transaction data recorded on the undo data page was submitted to the present. If the time interval after submission has exceeded the user's desired undo retention time, it is considered that the historical data recorded on the undo data page has expired and there is no need to retain it. The data page can be released for use by other transactions, and the old data can be overwritten. If the time interval does not exceed the retention time, it is considered that the undo data page still needs to be retained. The database will try to retain the old data on these data pages and try to allocate other expired data pages or apply for new data pages from the undo tablespace.
[0053] By analyzing the prior art, the inventors discovered that in high-concurrency scenarios, some long transactions occupy a large number of undo data pages. When the transaction ends, the rollback segment bound to such a transaction will manage a large number of undo data pages. When other transactions are subsequently bound to the rollback segment, they will be allocated from the data page chain managed by the rollback segment. At this time, the number of data pages managed by the rollback segment bound to other short transactions is extremely small, and the undo resources will be extremely unbalanced across different rollback segments. When other rollback segments are short of resources and cannot allocate data pages, they will first request new data pages from the tablespace, causing the tablespace to continue to expand. However, the actual free data pages are hung on other free rollback segments, greatly reducing the utilization of undo. At the same time, the size of database memory is also limited. When a large number of free undo data page chains exist, because data pages at the back of the chain will not be accessed for a long time, they become cold pages in memory and will be eliminated from memory and written to disk before use. The next time these undo data pages are used, they must be read from disk, incurring a large amount of IO overhead.
[0054] Ideally, if the number of allocatable undo data pages held on each rollback segment can be as close as possible to the actual consumption of the running transactions, it can be ensured that the number of data pages managed on each rollback segment roughly meets the needs of data business operation, and there will be no problem of surplus resources in some parts and tight resources in other parts between different transactions; on the other hand, if the number of data pages matches the actual consumption, it can be ensured that they are hot pages in memory most of the time, constantly recycled back and forth, and will not be eliminated by memory, so that most of the access to these data pages is in memory, without the need for disk reading and writing, saving a lot of I / O reading and writing.
[0055] It should be noted that in any embodiment of the present invention, there is no limitation on the type of database. As long as the database can run one or more data services and can bind a rollback segment composed of data pages to the data service, those skilled in the art can apply the present invention to different types of databases.
[0056] 1 , a database rollback resource processing method provided by an embodiment of the present application is shown, wherein the database is used to set a corresponding rollback segment for a data service when running the data service, and the rollback segment is composed of data pages;
[0057] The method comprises:
[0058] S101, determining a target rollback segment;
[0059] S102, determining the actual number of pages of the target rollback segment;
[0060] S103, calculating the target number of pages of the target rollback segment based on the actual number of pages;
[0061] S104. When the actual number of pages is greater than the target number of pages, determine redundant data pages in the target rollback segment;
[0062] S105: Perform balanced scheduling on the redundant data pages.
[0063] In an embodiment of the present application, in response to the problems of undo space expansion and excessive I / O overhead in the prior art, the present application provides a solution for determining the actual number of pages and the target number of pages of each rollback segment, thereby determining the redundant data pages in each rollback segment, and performing balanced scheduling on the redundant data pages. Specifically, the database is used to set a corresponding rollback segment for the data business when running the data business, and the rollback segment is composed of data pages, by determining the target rollback segment; determining the actual number of pages of the target rollback segment; calculating the target number of pages of the target rollback segment based on the actual number of pages; when the actual number of pages is greater than the target number of pages, determining the redundant data pages in the target rollback segment; and performing balanced scheduling on the redundant data pages. By identifying redundant data pages in the rollback segment and performing balanced scheduling for the redundant data pages, the problems of undo space expansion and excessive I / O overhead are solved, and the redundant data pages in the rollback segment corresponding to each data business are reduced to even no redundant data pages, avoiding the problem of space expansion due to the existence of a large number of redundant rollback segments. At the same time, by balanced scheduling of redundant data pages, the redundant data pages in each data business are promptly recovered, and other data businesses can use the redundant data pages in a timely manner, reducing I / O overhead.
[0064] Next, a database rollback resource processing method in this exemplary embodiment will be further described.
[0065] As described in step S101 , a target rollback segment is determined.
[0066] In an embodiment of the present invention, the specific process of "determining the target rollback segment" in step S101 may be further explained in conjunction with the following description.
[0067] Several data services can run in the database. The database can bind a rollback segment to each data service, that is, each data service corresponds to a rollback segment. Since the data services processed by different rollback segments require different storage resources, that is, the number of data pages, it is necessary to determine whether there are redundant data pages for different rollback segments.
[0068] In practical applications, the rollback segments bound to each data service in the database can be determined in sequence as target rollback segments, or several rollback segments can be determined and redundant data pages of each target rollback segment can be calculated synchronously.
[0069] For example, if data services A, B, and C are running in a database, and rollback segment a is bound to data service A, containing 33 data pages; rollback segment b is bound to data service B, containing 15 data pages; and rollback segment c is bound to data service A, containing 21 data pages, then step S110 can sequentially select one of rollback segments a, b, and c as the target rollback segment and execute subsequent steps S102-S105. Alternatively, at least two of rollback segments a, b, and c can be selected as the target rollback segments, and subsequent steps S102-S105 can be executed for each target rollback segment, and the process returns to the step of determining the target rollback segment until the calculation of redundant data pages for all rollback segments is complete.
[0070] In an embodiment of the present invention, the specific process of "determining the target rollback segment" in step S101 may be further explained in conjunction with the following description.
[0071] As described in the following steps, polling information is read; the polling information is used to record the rollback segment corresponding to the data service; and the rollback segment in the polling information is sequentially determined as the target rollback segment.
[0072] Polling information for rollback segments can be pre-generated. For example, the polling order for each rollback segment can be determined based on the earliest commit time in the rollback segment, and the polling information can be generated based on the polling order. Alternatively, rollback segment identifiers can be set for each rollback segment, and polling information can be generated based on the rollback segment identifier sorting. Alternatively, data service identifiers can be set for each data service, and polling information can be generated based on the data service identifier sorting. In actual applications, the polling information can also be obtained based on other sorting methods, which are not limited in the embodiments of the present invention.
[0073] In S101, the target rollback segment is determined in sequence by reading the polling information, and redundant data pages are determined for the current target rollback segment. In actual applications, the database can scan the rollback segments recorded in the polling information at a certain frequency to regularly determine the redundant data pages of each rollback segment, thereby achieving automatic balancing of the redundant data pages of the rollback segments.
[0074] In an embodiment of the present invention, the specific process of "calculating the target number of pages of the target rollback segment based on the actual number of pages" in step S103 can be further explained in combination with the following description.
[0075] As described in the following steps, the commit time, current time and preset retention time corresponding to the chain head data page of the target rollback segment are read; based on the actual number of pages N1, the commit time T1, the current time T2 and the retention time T3, the target number of pages N2 is calculated; wherein, N2 = N1*T3 / (T2-T1).
[0076] The rollback segment includes several data pages composed of a chain structure. The commit time of the first data in the chain structure is the earliest commit time of each data page in the current target rollback segment. Therefore, by reading the commit time corresponding to the head data page of the target rollback segment, the earliest commit time of the data page of the target rollback segment can be determined.
[0077] After determining the actual number of pages N1, the commit time T1, the current time T2, and the retention time T3, the target number of pages N2 is calculated according to the formula N2=N1*T3 / (T2-T1). The actual number of pages is the number of data pages currently actually contained in the target rollback segment, and the target number of pages is the number of data pages that the target rollback segment needs to retain to meet its data business requirements. When the actual number of pages is greater than the target number of pages, it is determined that unnecessary data pages are occupied, that is, there are redundant data pages in the target rollback segment.
[0078] In actual applications, the target number of pages is constantly updated and changed during the operation of data services. During scanning, it is constantly recalculated based on the actual consumption of data services and serves as the self-balancing retention number of data pages on the rollback segment. When it is found that the number of data pages actually held on the rollback segment exceeds the self-balancing retention number during this period, the database executes step S105 to reclaim the redundant data pages on the rollback segment, and these data pages will be transferred to the undo tablespace. During the recycling process, recycling starts with the data page with the earliest transaction commit time, which can ensure that the data pages with the longest expiration time are recycled first, and the possibility of them being accessed again by data services is minimized.
[0079] In an embodiment of the present invention, the specific process of “performing balanced scheduling for the redundant data pages” in step S105 may be further explained in conjunction with the following description.
[0080] As described in the following steps, the redundant data pages are recycled to the preset table space.
[0081] After determining the redundant data pages, they are recycled to the designated undo tablespace, so that other data businesses can apply for data pages from this tablespace when they need more data pages, thereby improving the smoothness of data business operation.
[0082] In actual applications, a queue can be built in advance. After the redundant data pages for the same target rollback segment are determined, the redundant data pages are cached in the queue. When all the redundant data pages of the same target rollback segment are cached in the queue or there is no free space in the queue, the next target rollback segment is polled and the redundant data pages in the queue are stored in the preset table space.
[0083] In one embodiment of the present invention, the method further includes: when the actual number of pages is greater than the target number of pages, returning to step S102 after determining the redundant data pages in the target rollback segment; and when the actual number of pages is not greater than the target number of pages, returning to step S101.
[0084] In the actual process, when the actual number of pages is greater than the target number of pages, the data page with the earliest commit time is determined to be a redundant data page, and after the redundant data page is removed from the current target rollback segment, the data pages included in the rollback segment have actually changed, then it is necessary to return to step S102 and re-execute steps S102-S105 until the actual number of pages is not greater than the target number of pages, indicating that the number of data pages required for the target rollback segment matches the actual number of data pages included, and there are no redundant data pages, then return to step S101, and re-determine another rollback segment as the new target rollback segment, and poll and scan each rollback segment in the above manner. After each round of scanning, the number of data pages remaining on all rollback segments will be maintained as close as possible to the number consumed by its own data business operation, and each will match the data business usage.
[0085] By using the above method to determine the redundant data pages of each rollback segment and to evenly schedule them, the number of data pages on the chain is reasonable when using the rollback segment, which can meet the needs of data business operations and is greatly reduced. Once there is a change in data business, these rollback segments can quickly apply for new data pages in the undo tablespace, and the data pages that have been returned to the undo tablespace can be used directly. There is no need to continuously expand the unused portion of the tablespace, nor does it require tablespace file expansion, thus avoiding the problem of tablespace file expansion when there are still many free undo data pages. At the same time, the number of data pages held by each rollback segment is greatly reduced, and continuous use can ensure that these few data pages are mostly accessed in memory and rarely eliminated by memory, which greatly reduces the IO reading and writing of undo data pages.
[0086] Furthermore, compared with the rollback resource processing solution of the prior art, which causes the undo tablespace file to expand, the file size far exceeds the actual usage size. The embodiment of the present invention can keep the file size as close to the actual usage size as possible, thus avoiding the problem of excessive expansion.
[0087] Furthermore, when file expansion occurs, unlike other existing solutions, which require the database to be offline and services to be suspended, old undo tablespace files are directly discarded. Furthermore, once the database is restarted, the original old version of the data is no longer accessible. This embodiment of the present invention does not require stopping database processes or rebuilding tablespaces, ensuring that old versions of data are retained as much as possible during this period, extending the time during which old versions of data can be read.
[0088] Furthermore, compared to existing approaches to addressing file bloat, which rely on a series of manual operations and can lead to various problems if errors are made, the present invention solves the file bloat problem in the background, recycling data pages within a reasonable range without the user noticing or requiring any special operations.
[0089] 2 , a flowchart of a database rollback resource processing method according to an embodiment of the present application is shown, specifically including:
[0090] S201. The background thread periodically performs undo space optimization tasks.
[0091] S202: Scan the undo segment, and scan each rollback segment in turn.
[0092] S203. Calculate and update the number of self-balancing reserved pages (target number of pages) for the undo segment. Obtain the commit time of the transaction containing the head data page of the rollback segment chain, obtain the number of data pages on the chain, and calculate the average data page consumption rate of the undo page based on the running data business during this period.
[0093] S203: Calculate and update the number of self-balancing reserved pages of the undo segment. Calculate the number of self-balancing data pages reserved on the rollback segment that meets the consumption of the running data business.
[0094] S204: Check whether the number of records exceeds the upper limit of single processing. If not, execute S205; if yes, execute S207.
[0095] S205: Determine whether the actual number of held data pages is greater than the number of self-balancing data pages reserved. If not, execute step S206; if so, execute step S207.
[0096] S206: Remove a data page from the chain head and record it in the processing queue. The number of self-balancing reserved pages is recalculated and refreshed. If the actual number of held data pages is equal to the self-balancing number, or the processing queue has reached its upper limit, or the commit time of the transaction containing the chain head data page in the rollback segment has not yet expired, the process is exited.
[0097] S207: Return the data pages in the processing queue to the table space.
[0098] S208: Replace the next undo segment. Replace the next rollback segment and rescan, and process according to the above process.
[0099] The following further illustrates an embodiment of the present invention with reference to FIG3 , which shows a functional block diagram of a database provided by an embodiment of the present application.
[0100] Example 1
[0101] The database is running data services with X concurrent threads performing data services. Each connection is bound to a different undo segment, namely undo segment 1, undo segment 2, and undo segment 3, up to undo segment X. Assume that a long transaction runs on undo segment X, consuming 10,000 undo data pages. The transaction has been committed at t1, and the user-set expected undo retention time is UNDO_RETENTION.
[0102] The background thread periodically polls and scans all undo segments. When it reaches undo segment X, it discovers that it now contains only 10,000 data pages, all of which have expired. At this point, the transaction commit time for the oldest data page in the chain is t1. Assuming the current time is t and it has already expired, T > T1 + UNDO_RETENTION . The average undo consumption rate for data services during this period is Rate = 10,000 / (t – t1). At this point, the number of self-balanced data pages in undo segment X is 10,000 * UNDO_RETENTION / (t – t1). The number of excess data pages is 10,000 - 10,000 * UNDO_RETENTION / (t – t1). At this point, data page 1 is removed from the head of the chain in undo segment X and added to the processing queue.
[0103] After the undo segment X is removed, the time is t2, the data has changed, and the latest number of self-balancing data pages is dynamically updated: 9999–9999*UNDO_RETENTION / (t2–t1). This process continues until there are no more excess data pages in the undo segment X, or the processing queue is full, or the transaction commit time of the next data page to be removed has not expired.
[0104] When the collection is terminated, the background will return the data pages in the processing queue to the table space one by one.
[0105] At this time, due to insufficient resources, undo segment 1 does not need to expand the file when applying for data pages from the tablespace. Instead, it can directly use the free data pages in the existing file that have just been transferred by undo segment X.
[0106] 4 , another database rollback resource processing method provided by an embodiment of the present application is shown, wherein the database is used to set a corresponding rollback segment for the data service when the data service is running, and the rollback segment is composed of data pages;
[0107] The method comprises:
[0108] S401: In response to a resource request, determine a rollback segment to be allocated corresponding to the resource request;
[0109] S402: Determine the target rollback segment.
[0110] S403, determining the actual number of pages of the target rollback segment;
[0111] S404, calculating the target number of pages of the target rollback segment based on the actual number of pages;
[0112] S405. When the actual number of pages is greater than the target number of pages, determine redundant data pages in the target rollback segment.
[0113] S406 : Perform balanced scheduling on the redundant data pages, specifically including: transferring the redundant data pages to the rollback segment to be allocated.
[0114] In an embodiment of the present application, by responding to resource requests, redundant data pages on each rollback segment are determined, and the redundant data pages are transferred to the rollback segment to be allocated corresponding to the resource request, thereby avoiding the process in the prior art of first transferring the free data pages to the table space and then applying for data page resources from the table space for the rollback segment to be allocated, thereby improving the scheduling of redundant data page resources and improving the data business operation efficiency in the database.
[0115] Furthermore, compared to the prior art approach of reading new data pages from an expanded file, which necessarily involves disk I / O, the present invention recycles data pages and ensures that each undo segment maintains a self-balancing number of data pages. This ensures that most data pages are hot pages in memory and are less likely to be evicted. Consequently, these data pages can be accessed in memory without requiring disk I / O, significantly improving performance.
[0116] Next, another database rollback resource processing method in this exemplary embodiment will be further described.
[0117] In one embodiment of the present invention, the specific generation process of the “resource request” in step S410 may be further explained in conjunction with the following description.
[0118] As described in the following steps, the resource strain type and resource strain frequency of each rollback segment are detected; a resource strain statistic is calculated based on the resource strain type and the resource strain frequency; and a resource request is generated for the rollback segment whose resource strain statistic reaches a preset threshold.
[0119] When a rollback segment is applying for a data page and finds that there is no data page available in the data page chain, or the commit time of the data page at the head of the chain has not yet exceeded the retention time of the data page, it is determined that the rollback segment has experienced resource shortage. According to different types of application situations, the weight of each resource-scarce data page application is different. A resource shortage statistic is maintained on the rollback segment and the statistic is accumulated. When the statistic accumulates to a preset threshold, a resource request is generated for the rollback segment, and then the resource request is responded to through step S401.
[0120] Steps S402-S405 are similar to steps S101-S104 and will not be described in detail. For similarities, please refer to the corresponding contents of steps S101-S104.
[0121] In an embodiment of the present invention, the generation process of "transferring the redundant data page to the rollback segment to be allocated" in step S406 may be further explained in combination with the following description.
[0122] As an example, the number of redundant data pages of each rollback segment may be polled, and for the rollback segment with the most redundant data pages, the redundant data pages may be transferred to the rollback segment to be allocated according to the resource request.
[0123] As another example, the redundant data pages of each rollback segment can be polled. When any rollback segment has a redundant data page, the redundant data page is transferred to the rollback segment to be allocated, and then the next rollback segment is polled until the transferred redundant data page meets the resource request, and polling of other rollback segments is stopped.
[0124] As another example, the redundant data pages of each rollback segment may be polled. When the number of redundant data pages on a certain rollback segment satisfies the resource request, the redundant resources of the rollback segment are transferred to the rollback segment to be allocated, and polling of other rollback segments is stopped.
[0125] In the embodiment of the present application, when resources are scarce on a certain rollback segment for multiple times, a request for source shortage will be issued to the background thread. After the background thread receives a signal that a certain rollback segment is short of resources, it will start to scan all rollback segments, calculate the number of self-balancing data pages of all rollback segments, and compare it with the number of real data pages currently held by the corresponding rollback segment, and select the rollback segment that holds the most redundant data pages on the basis of keeping the rollback data page resources required by the data business smoothly available. After selecting the rollback segment with the most redundant resources, a section is directly intercepted from the chain resource of the rollback segment and transferred to the rollback segment that issued the resource request due to resource shortage. The free resources on other rollback segments are quickly transferred to the rollback segment with scarce resources. During the high-concurrency operation of the database, this mechanism provides a mechanism for rapid resource transfer between rollback segments, saving the process of returning idle resources to the table space first, and then the scarce rollback segment applying for resources from the table space. Resources are so scarce that the rollback segment that issues the request is inefficient, whether it is directly applying for resources from the tablespace or requiring automatic tablespace expansion. When faced with the immediate need to use data pages, directly using the idle resources of other rollback segments is the most efficient, fastest, and least expensive option. In addition, the pages used are likely to be hot pages in memory, which also reduces I / O overhead.
[0126] From the perspective of rollback segments providing idle resources, these resources can be directly intercepted for use by other rollback segments facing resource constraints. For their data services, these are calculated idle resources. When scheduled recycling occurs, these data pages are likely to be recycled. Directly transferring these idle data pages to other rollback segments reduces recycling overhead and ensures that the number of data pages used in rotation on their own rollback segments is more aligned with the data services. This prevents most data pages from being eliminated from memory, improving access efficiency and reducing I / O overhead.
[0127] 5 , there is shown another database rollback resource processing flow chart provided by an embodiment of the present application, specifically including:
[0128] S501. The background thread periodically responds to the undo resource transfer request and executes step S502.
[0129] S502: Wait for a resource request. After receiving the resource request, execute steps S503-S505, wherein the resource request is generated through the following S511-S515.
[0130] S511: An undo segment no longer holds expired data pages. When requesting a data page, the undo segment finds that no data page is available in the data page chain, or the commit time of the data page at the head of the chain has not yet exceeded the undo retention time.
[0131] S512: Apply for data pages or expired data pages using other methods. The undo segment can continue to apply for resources using other methods, such as applying for new data pages from the tablespace or extending the undo file.
[0132] S513: Resource shortage time statistics: The situation in step S501 will be defined as a resource shortage. According to different application situations, the weight of each resource shortage data page application is different. A resource shortage statistic is maintained on the undo segment and accumulated.
[0133] S514: Determine whether the resource shortage statistics exceed a threshold, and if so, proceed to step S505.
[0134] S515: Initiate a resource request. When the resource shortage statistic accumulates to a threshold, a resource request is initiated to the background thread, and the background thread responds to the resource shortage request of the undo segment.
[0135] S503: Initiate a polling scan for all other undo segments. The background thread initiates a polling scan for all other undo segments.
[0136] S504. Find the undo segment with the most redundant data pages. For each undo segment, calculate the number of self-balancing data pages in the segment to obtain the actual number of redundant data pages. Whenever an undo segment with a larger number of redundant data pages is found, refresh the target record. After the polling is completed, the undo segment with the most redundant data pages is determined.
[0137] S505: Initiate resource conversion to transfer a segment of excess data pages to the undo segment that initiated the request. For the undo segment with the largest number of excess data pages, remove a portion of its data page chain. This removed portion of the data page chain is attached to the head of the undo segment that initiated the request, and its resource shortage statistics are cleared. The next time the resource-constrained undo chain initiates a data page request, it will begin with the segment of data pages just obtained from another undo segment, alleviating resource shortages.
[0138] The following further illustrates an embodiment of the present invention with reference to FIG6 , which shows another database function block diagram provided by an embodiment of the present application.
[0139] Example 2
[0140] The database is running data services, with X concurrent threads performing data services simultaneously. Each connection is bound to a different undo segment, namely undo segment 1, undo segment 2, undo segment 3, and so on, up to undo segment X.
[0141] The resources on the remaining undo segments are insufficient, and all existing files in the undo tablespace have been used. Assume that the undo file size is 1GB, and that all undo data pages held by undo segment 1 have not expired at time T. At this time, the data business in undo segment 1 needs to continue to apply for undo data pages.
[0142] When undo segment 1 requests data pages, resources are insufficient and the statistical value reaches the threshold, triggering a resource shortage request signal. The database backend receives the signal from undo segment 1 and begins processing. The backend traverses all undo segments, dynamically calculating the number of self-balanced data pages within each segment and thus the number of excess data pages. Whenever the number of excess data pages exceeds the maximum number in the current record, the record is updated and the undo segment is marked as the undo segment with the most free data pages.
[0143] After all scans are complete, undo segment X has the most redundant data pages in the current record. Therefore, a batch of data pages is removed from undo segment X. Assume that 16 data pages are removed this time and transferred to undo segment 1. At this time, undo segment 1 has 16 data pages. When undo segment 1 requests data pages again, it does not need to apply for them from the tablespace but can directly request 16 data pages from itself, thus solving the urgent resource problem.
[0144] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0145] 7 , a database rollback resource processing device provided by an embodiment of the present application is shown. The database is used to set a corresponding rollback segment for a data service when running the data service. The rollback segment is composed of data pages and specifically includes:
[0146] A target rollback segment determination module 701 is used to determine a target rollback segment;
[0147] An actual page number determination module 702 is used to determine the actual page number of the target rollback segment;
[0148] A target page number calculation module 703 is configured to calculate a target page number of the target rollback segment based on the actual page number;
[0149] A redundant data page determination module 704 is configured to determine redundant data pages in the target rollback segment when the actual number of pages is greater than the target number of pages;
[0150] The balancing module 705 is configured to perform balanced scheduling on the redundant data pages.
[0151] In one embodiment of the present invention, the balancing module 705 includes:
[0152] The recycling submodule is used to recycle the redundant data pages to a preset table space.
[0153] In one embodiment of the present invention, the method includes:
[0154] A first calling module, configured to call the actual page number determining module 702 after determining the redundant data pages in the target rollback segment when the actual page number is greater than the target page number;
[0155] The second calling module is configured to call the target rollback segment determining module 701 when the actual number of pages is not greater than the target number of pages.
[0156] In one embodiment of the present invention, the target page number calculation module 703 includes:
[0157] A data page information reading submodule is used to read the commit time, current time, and preset retention time corresponding to the chain head data page of the target rollback segment;
[0158] A target page number calculation submodule is used to calculate the target page number N2 based on the actual page number N1, the submission time T1, the current time T2 and the retention time T3;
[0159] Among them, N2=N1*T3 / (T2-T1).
[0160] In one embodiment of the present invention, the target rollback segment determination module 701 includes:
[0161] A polling information reading submodule, configured to read polling information; the polling information is used to record the rollback segment corresponding to the data service;
[0162] The target rollback segment determination submodule is used to sequentially determine the rollback segments in the polling information as target rollback segments.
[0163] In one embodiment of the present invention, the apparatus further comprises:
[0164] A response module, configured to determine, in response to a resource request, a rollback segment to be allocated corresponding to the resource request;
[0165] The balancing module 705 includes: a transfer submodule, configured to transfer the redundant data page to the rollback segment to be allocated.
[0166] In one embodiment of the present invention, the resource request is generated by the following modules:
[0167] Resource shortage detection module, used to detect the resource shortage type and resource shortage frequency of each rollback segment;
[0168] A statistics calculation module, configured to calculate a resource strain statistic based on the resource strain type and the resource strain frequency;
[0169] The request generation module is used to generate a resource request for the rollback segment whose resource shortage statistic reaches a preset threshold.
[0170] 8 , a computer device of a database rollback resource processing method according to the present invention is shown, which may specifically include the following:
[0171] The computer device 12 is a general-purpose computing device. The components of the computer device 12 may include but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0172] The bus 18 represents one or more of several types of bus 18 structures, including a memory bus 18 or memory controller, a peripheral bus 18, an accelerated graphics port, a processor, or a local bus 18 that utilizes any of a variety of bus 18 architectures. Examples of such architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus 18, a Micro Channel Architecture (MAC) bus 18, an Enhanced ISA bus 18, an Audio Video Electronics Standards Association (VESA) local bus 18, and a Peripheral Component Interconnect (PCI) bus 18.
[0173] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0174] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be configured to read and write to non-removable, non-volatile magnetic media (commonly referred to as a "hard drive"). Although not shown in FIG8 , a magnetic disk drive may be provided for reading and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), as well as an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media). In these cases, each drive may be connected to bus 18 via one or more data media interfaces. The memory may include at least one program product having a set (e.g., at least one) of program modules 42 configured to perform the functions of various embodiments of the present invention.
[0175] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in a memory. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules 42, and program data, each of which, or some combination thereof, may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0176] The computer device 12 can also communicate with one or more external devices 14 (e.g., a keyboard, pointing device, display 24, camera, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication can occur via an input / output (I / O) interface 22. Furthermore, the computer device 12 can communicate with one or more networks (e.g., a local area network (LAN)), a wide area network (WAN), and / or a public network (e.g., the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with the other modules of the computer device 12 via a bus 18. It should be understood that, although not shown in FIG. 8 , other hardware and / or software modules can be used in conjunction with the computer device 12, including but not limited to microcode, device drivers, redundant processing units 16, external disk drive arrays, RAID systems, tape drives, and data backup storage systems 34.
[0177] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing a database rollback resource processing method provided by an embodiment of the present invention.
[0178] That is, when the processing unit 16 executes the program, it implements the following: determining a target rollback segment; determining the actual number of pages of the target rollback segment; calculating the target number of pages of the target rollback segment based on the actual number of pages; determining redundant data pages in the target rollback segment when the actual number of pages is greater than the target number of pages; and performing balanced scheduling for the redundant data pages.
[0179] In an embodiment of the present invention, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a database rollback resource processing method as provided in all embodiments of the present application:
[0180] That is, when the program is executed by the processor, it implements the following: determining a target rollback segment; determining the actual number of pages of the target rollback segment; calculating the target number of pages of the target rollback segment based on the actual number of pages; when the actual number of pages is greater than the target number of pages, determining redundant data pages in the target rollback segment; and performing balanced scheduling for the redundant data pages.
[0181] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0182] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0183] The computer program code for performing the operations of the present invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other.
[0184] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0185] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.
[0186] The above is a detailed introduction to the database rollback resource processing method, device, computer equipment and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for processing database rollback resources, wherein the database is used to set a corresponding rollback segment for a data service when running the data service, and the rollback segment is composed of data pages, characterized in that: The method comprises: Determine the target rollback segment; Determine the actual number of pages of the target rollback segment; Calculate the target number of pages of the target rollback segment based on the actual number of pages; When the actual number of pages is greater than the target number of pages, determining redundant data pages in the target rollback segment; Balanced scheduling is performed on the redundant data pages.
2. The method according to claim 1, characterized in that The performing balanced scheduling for the redundant data pages comprises: The redundant data pages are recycled to a preset table space.
3. The method according to claim 1, characterized in that Also includes: When the actual number of pages is greater than the target number of pages, after determining the redundant data pages in the target rollback segment, returning to the step of determining the actual number of pages of the target rollback segment; When the actual number of pages is not greater than the target number of pages, the process returns to the step of determining the target rollback segment.
4. The method according to claim 1, characterized in that: Calculating the target number of pages of the target rollback segment based on the actual number of pages includes: Read the commit time, current time, and preset retention time corresponding to the chain head data page of the target rollback segment; Calculate the target number of pages N2 according to the actual number of pages N1, the submission time T1, the current time T2 and the retention time T3; Among them, N2=N1*T3 / (T2-T1).
5. The method according to claim 1, characterized in that The step of determining the target rollback segment comprises: Reading polling information; the polling information is used to record the rollback segment corresponding to the data service; The rollback segments in the polling information are sequentially determined as target rollback segments.
6. The method according to claim 1, characterized in that The method further comprises: in response to the resource request, determining a rollback segment to be allocated corresponding to the resource request; The balanced scheduling for the redundant data page includes: transferring the redundant data page to the rollback segment to be allocated.
7. The method according to claim 6, characterized in that The resource request is generated in the following way: Detect the resource shortage type and resource shortage frequency of each rollback segment; Calculating resource strain statistics according to the resource strain type and the resource strain frequency; A resource request is generated for the rollback segment whose resource shortage statistic reaches a preset threshold.
8. A database rollback resource processing device, wherein the database is used to set a corresponding rollback segment for a data service when the data service is running, and the rollback segment is composed of data pages, characterized in that: The device comprises: A target rollback segment determination module, used to determine the target rollback segment; An actual page number determination module, used to determine the actual page number of the target rollback segment; A target page number calculation module, used to calculate the target page number of the target rollback segment based on the actual page number; A redundant data page determination module, used for determining redundant data pages in the target rollback segment when the actual number of pages is greater than the target number of pages; The balancing module is used to perform balanced scheduling on the redundant data pages.
9. A computer device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and system for recycling database resources
CN103593449A
Method and device for quickly reclaiming rollback space in MySQL
CN104881418A
Large-field data release method and device, electronic equipment and storage medium
CN114328565A
Rollback counters for step records of a database
US20140250085A1
Cited By
Transaction rollback method and device, equipment, storage medium and program product
CN120670412A
Cache pool load optimization method and device, electronic equipment and storage medium
CN120849389A
