Method, device, equipment, medium and product for generating flashback log in database

By generating flashback logs in the database, the time requirement for rapid database recovery to historical moments is addressed. Furthermore, by controlling transaction commits through hash table verification and global flags, the database's recovery efficiency and concurrency capabilities are optimized.

CN123178455APending Publication Date: 2026-11-27SHANGHAI DAMENG DATABASE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611357489.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-03
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies cannot meet the time requirements for quickly restoring databases to a small number of accidentally deleted data points in the past.

Method used

Under the physical transaction process, the data page log generation status is verified by a hash table. Flashback logs are generated only for data pages that are modified for the first time after the internal restore point is created. Random values ​​are generated using thread identifiers to dynamically allocate flashback log buffers. The original mirror page of the data page is copied and the page address is registered. Combined with global flags, the transaction commit sequence is controlled, and the restore point switching process is standardized.

Benefits of technology

It enables the database to quickly recover to a specified historical point without interrupting business operations, reduces the overhead of generating invalid logs, and optimizes concurrent processing performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178455A_ABST
    Figure CN123178455A_ABST
Patent Text Reader

Abstract

The application discloses a generation method and device of flash-back logs in a database, equipment, medium and products, relates to the technical field of databases, and comprises the following steps: starting a physical transaction; checking a hash table to determine whether a data page modified by a user thread has generated a flash-back log; if not, determining whether the current data page modification operation is the first modification of the data page after the corresponding internal restoration point is created; if yes, determining the identification information of the user thread; generating a random value corresponding to the identification information, and determining the buffer area of the flash-back log based on the random value; copying the data page into the flash-back log in the buffer area, and registering the address of the data page in the hash table to indicate that the data page has generated a flash-back log; modifying the data page, and determining whether to submit the physical transaction based on a global mark after all data page modifications of the physical transaction are completed. The technical problem that the prior art cannot meet the time requirement of rapid recovery is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to methods, apparatus, devices, media, and products for generating flashback logs in databases. Background Technology

[0002] During database operation, there may be scenarios such as accidental operation and data corruption. The database needs to have the ability to restore the data to a historical point in time to ensure data security and business reliability.

[0003] Currently, databases generally use a combination of backup set restoration to rebuild the original database and redo log playback to achieve recovery. That is, backup sets are periodically generated to save database copies. When data loss or corruption occurs, the backup set is used to restore a complete copy of the database, and then the redo logs for the corresponding time range are replayed to restore the database to the specified historical moment.

[0004] However, if a database needs to be quickly restored to a past point in time, such as rolling back a small amount of accidentally deleted data within minutes, existing technologies cannot meet the time requirements for rapid recovery. Summary of the Invention

[0005] This invention provides a method, apparatus, device, medium, and product for generating flashback logs in a database, solving the technical problem that existing technologies cannot meet the time requirements for rapid recovery.

[0006] According to one aspect of the present invention, a method for generating flashback logs in a database is provided, comprising: Initiate a physical transaction, which includes modification operations on data pages; Check the hash table to determine if the data page modified by the user thread has generated a flashback log. If not, determine whether this data page modification operation is the first modification to the data page after the corresponding internal restore point is created. If so, determine the identification information of the user thread. The internal restore point is used to represent a snapshot of the database at a certain moment. Generate a random value corresponding to the identification information, and determine the buffer of the flashback log based on the random value; The data page is copied to the flashback log in the buffer, and the address of the data page is registered in the hash table to indicate that the data page has generated the flashback log; After all data pages of the physical transaction have been modified, a global flag is used to determine whether to commit the physical transaction. The global flag is set in the internal restore point switching process.

[0007] According to another aspect of the present invention, an apparatus for generating flashback logs in a database is provided, comprising: A startup module is used to initiate physical transactions, which include modification operations on data pages; The inspection module is used to inspect the hash table to determine whether the data page modified by the user thread has generated a flashback log. The first determining module is used to determine whether the current data page modification operation is the first modification of the data page after the creation of the corresponding internal restore point if no; if yes, it determines the identification information of the user thread, wherein the internal restore point is used to represent a snapshot of the database at a certain moment. The second determining module is used to generate a random value corresponding to the identification information and determine the buffer of the flashback log based on the random value; The copying module is used to copy the data page to the flashback log in the buffer and register the address of the data page in the hash table to indicate that the data page has generated the flashback log; The modification module is used to modify the data pages. After all data pages of the physical transaction have been modified, it determines whether to commit the physical transaction based on a global flag, which is set in the internal restore point switching process.

[0008] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the method described in any embodiment of the present invention.

[0009] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the method described in any embodiment of the present invention.

[0010] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the method described in any embodiment of the present invention.

[0011] The technical solution of this invention performs data page modification operations under the physical transaction process, uses a hash table to verify the data page log generation status, and only generates flashback logs for data pages modified for the first time after the internal restore point is created, thus reducing the overhead of generating invalid logs. Simultaneously, it dynamically allocates the flashback log buffer based on a random value generated by the thread identifier, and retains the original data by copying the original mirror page of the data page and registering the page address, providing accurate data support for flashback recovery. Furthermore, it controls the transaction commit sequence through a global flag set in the restore point switching process, standardizing the execution sequence of physical transactions and restore point switching. This solves the technical problem that existing technologies cannot meet the time requirements for rapid database recovery.

[0012] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0013] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0014] Figure 1 This is a flowchart of a method for generating flashback logs in a database, provided by an embodiment of the present invention; Figure 2 This is a flowchart of another method for generating flashback logs in a database, provided by an embodiment of the present invention; Figure 3 This is a schematic diagram of an internal reduction point sub-period division provided by an embodiment of the present invention; Figure 4 This is a schematic diagram illustrating the generation of flashback logs for the same data page under different internal restore point cycles in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of a device for generating flashback logs in a database, provided in an embodiment of the present invention. Figure 6 This is a structural block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0015] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0016] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0017] To facilitate understanding of the embodiments of the present invention, some terms and related concepts appearing in the present invention will be explained below.

[0018] Redo logs record the modifications made to data pages by physical transactions. The write-ahead logging (WAL) mechanism ensures that the corresponding redo logs are flushed to disk before the data pages are flushed. When a failure causes data loss, the data pages can be recovered by replaying the redo logs to replay the modifications made to the data pages.

[0019] A Log Sequence Number (LSN) can be a continuously incrementing integer starting from zero, uniquely identifying a physical transaction and its generated redo logs. A log sequence number is assigned to a physical transaction when it is committed.

[0020] When a physical transaction is committed, the data page header is set simultaneously, and the physical transaction LSN that modifies the data page is recorded; this can be called the page LSN.

[0021] In a production environment, databases may become unavailable due to various reasons, such as damaged storage media, accidental data deletion, or malicious damage, leading to data corruption or loss. To address this, a data backup strategy is introduced to periodically back up the database, saving multiple copies of the database data, which can be a backup set, to restore the data when necessary.

[0022] When a database experiences data corruption or loss, the original database can be rebuilt by restoring data from the backup set and replaying the redo logs within a specified time range, thus restoring the database to any specified point in time.

[0023] Restoring data from a backup set requires restoring the entire database from the backup set and then replaying the redo logs within a specified time range. In production environments, database data volumes are typically in the GB or TB range or higher, resulting in large amounts of data to restore and redo log replays, which is time-consuming.

[0024] To support the need for rapid database recovery, this invention proposes a method for generating database flashback logs. Based on this method, the database can be restored to any point in time by applying flashback logs and replaying a small portion of redo logs. This invention introduces internal restore points, dividing the database runtime into continuous and independent sub-cycles by periodically switching restore points. It also introduces a flashback log generation strategy: before a physical transaction modifies a data page, it copies the mirror page to the flashback log according to the flashback log generation rules. Simultaneously, by controlling the restore point switching and physical transaction mirror page generation process, the independence of sub-cycles and the atomicity of physical transactions are ensured. Furthermore, parallel flashback logging further optimizes concurrent processing performance and reduces the performance overhead caused by flashback log generation.

[0025] In one embodiment, Figure 1 This is a flowchart illustrating a method for generating flashback logs in a database according to an embodiment of the present invention. This embodiment is applicable to situations where a database generates flashback logs for data page modification processes. This method can be executed by a flashback log generation device in the database, which can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes: S110, Initiate physical transaction.

[0026] The physical transactions include operations that modify data pages.

[0027] A physical transaction can be a set of operations that physically modify data pages in a database. A single physical transaction can carry out one or more data page modification operations.

[0028] A data page can be the smallest unit of input / output (IO) in a database. A data page can be uniquely identified by a combination of tablespace ID, file ID, and page number as its page address.

[0029] When a user thread performs any data page modification operation, a physical transaction is started. The modification operation can be any of the following: update, delete, or page release.

[0030] S120. Check the hash table to determine whether the data page modified by the user thread has generated a flashback log.

[0031] A hash table can be a record structure maintained in memory by a database, using the page address of a data page as the key. When a data page has generated a flashback log within the current internal restore point period, the page address of that data page is registered and stored in the hash table. By querying the hash table to see if the corresponding page address of the data page exists, it can be determined whether the data page has generated a flashback log within the current internal restore point period.

[0032] Flashback logs can be logs that store mirror pages of data pages before modification. Flashback logs include a log header and a mirror page storage area. The log header is used to store attribute information, and the mirror page storage area is used to store mirror pages copied before the data pages were modified.

[0033] Read the hash table, use the page address of the data page to be modified as the search key, and perform a search and match in the hash table.

[0034] If the page address corresponding to the data page is found in the hash table, it is determined that the data page has already generated a flashback log within the current internal restore point period. Therefore, flashback logs will not be generated again for the data page, and the process of modifying the data page and generating the corresponding redo log will be directly executed. If the page address corresponding to the data page is not found in the hash table, it is determined that the data page has not yet generated a flashback log within the current internal restore point period.

[0035] S130. If not, determine whether this data page modification operation is the first modification of the data page after the corresponding internal restore point is created. If so, determine the identifier information of the user thread.

[0036] The internal restore point is used to represent a snapshot of the database at a given moment.

[0037] When an internal restore point is generated, it records the corresponding timestamp and the database's current system maximum LSN, representing the database's time period and used to divide the continuous operation of the database into independent sub-cycles. Each restore point switch creates a new internal restore point. The database at the time of the internal restore point is always in a state of data integrity and consistency.

[0038] The identification information can be information that can uniquely distinguish different user threads, such as a thread ID.

[0039] After the internal restore point is created, check whether the data page has been modified, and then determine whether this modification is the first modification of the data page within the internal restore point period.

[0040] Retrieve the identifier information of the user thread currently performing a data page modification operation.

[0041] If this data page modification operation is not the first modification to the data page after the creation of the corresponding internal restore point, then the data page modification and corresponding redo log generation will be performed directly.

[0042] In one embodiment, the moment is represented by a timestamp created by the internal restore point and the maximum log sequence number of the database.

[0043] Timestamps provide an intuitive representation of physical time, making it easy for operations and maintenance personnel to identify and locate the real-world time corresponding to the restore point. In this embodiment, a timestamp and the maximum log sequence number of the database are used to jointly represent the database time corresponding to the internal restore point. The timestamp is used to record the real time corresponding to the restore point, which is convenient for identification and location. The maximum log sequence number is the logical time stamp of the database kernel. The two work together to facilitate manual identification of the time and ensure that the database can accurately locate the database consistency state corresponding to the internal restore point when performing flashback or restore recovery.

[0044] S140. Generate a random value corresponding to the identification information, and determine the buffer of the flashback log based on the random value.

[0045] The random value can be a value obtained by using the user thread's identifier information as a seed. This random value can be mapped to one of the flashback log buffers, allowing different threads to use different flashback log buffers. In this embodiment, the thread ID can be used as the seed for random number generation, fixing different user threads to different parallel flashback log buffers and avoiding conflicts caused by multi-threaded operations.

[0046] The operation is performed using the user thread's identifier information as a seed to obtain the output value.

[0047] By using this random value mapping index, the flashback log buffer to be used in this case is selected from multiple flashback log buffers, thereby distributing the flashback logs of different user threads to different buffers and reducing access conflicts to the same buffer under multi-threaded concurrency.

[0048] S150. Copy the data page to the flashback log in the buffer, and register the address of the data page in the hash table to indicate that the data page has generated the flashback log.

[0049] Before performing this modification operation on the data page, read the current complete page content of the data page in memory, generate a mirror page of the data page before modification, and copy the mirror page into the flashback log of the selected flashback log buffer.

[0050] Write the page address of the data page to be modified into a hash table in memory.

[0051] In one embodiment, the flashback log includes a log header and a mirror page storage area, wherein the log header is used to store attribute information; The process of copying the data page to the flashback log in the buffer includes: Before modifying the data page, copy the data page to obtain a mirror page of the data page; The mirror page is stored in the mirror page storage area of ​​the flashback log.

[0052] The attribute information can be used to describe the mirror page information, such as the page address of the data page corresponding to the mirror page, the page LSN of the mirror page, etc., which is used to locate and verify the mirror page when performing flashback recovery.

[0053] Before a data page is overwritten, the complete page content of that data page is read from memory and copied to create a mirror page. The copying operation occurs before the data page content is modified, ensuring that the mirror page contains the original page content before the modification.

[0054] The generated image page is written to the image page storage area inside the currently selected flashback log buffer, completing the writing and saving of the image page in the buffer, waiting for subsequent flushing of the buffer to persist it to disk.

[0055] In this embodiment, the flashback log is divided into a log header and a mirror page storage area. The mirror page is copied before the data page is rewritten and stored in the mirror page storage area to facilitate the location and verification of the mirror page during flashback recovery. It also ensures that the mirror page contains the original content before modification. The mirror page is temporarily stored in the buffer before being flushed to disk.

[0056] S160. Modify the data page. After all data pages of the physical transaction have been modified, determine whether to commit the physical transaction based on the global flag.

[0057] The global marker is set during the internal restore point switching process.

[0058] The global flag can be a global state flag for the database. Most runtime flags are in an unset state, and the global flag is only assigned a value when the internal restore point switching process is executed. In this embodiment, the global flag can be represented by SWITCH_FLAG.

[0059] After the flashback log mirror page copy is completed, the page content of the data page in memory is modified.

[0060] After all pending data pages of a physical transaction have been rewritten, the current state of the global flag is read to determine whether the physical transaction should be committed directly or enter a blocked waiting state.

[0061] The technical solution of this invention performs data page modification operations under the physical transaction process, uses a hash table to verify the data page log generation status, and only generates flashback logs for data pages modified for the first time after the internal restore point is created, thus reducing the overhead of generating invalid logs. Simultaneously, it dynamically allocates the flashback log buffer based on a random value generated by the thread identifier, and retains the original data by copying the original mirror page of the data page and registering the page address, providing accurate data support for flashback recovery. Furthermore, it manages the transaction commit sequence through a global flag set in the restore point switching process, standardizing the execution sequence of physical transactions and restore point switching. This solves the technical problem that existing technologies cannot meet the time requirements for rapid database recovery.

[0062] In one embodiment, Figure 2 This is a flowchart illustrating another method for generating flashback logs in a database, provided by an embodiment of the present invention. This embodiment is a further refinement of the above embodiments. Figure 2 As shown, the method includes: S210, Initiate physical transaction.

[0063] The physical transactions include operations that modify data pages.

[0064] S220. Check the hash table to determine whether the data page modified by the user thread has generated a flashback log.

[0065] S230. If not, determine whether this data page modification operation is the first modification of the data page after the corresponding internal restore point is created. If so, determine the identifier information of the user thread.

[0066] The internal restore point is used to represent a snapshot of the database at a given moment.

[0067] S240. Generate a random value corresponding to the identification information, and determine the buffer of the flashback log based on the random value.

[0068] S250. Copy the data page to the flashback log in the buffer, and register the address of the data page in the hash table to indicate that the data page has generated the flashback log.

[0069] S260. Modify the data page. After all data pages of the physical transaction have been modified, if the global flag is in a blocked state, execute S270; otherwise, execute S280.

[0070] The global flag can be SWITCH_FLAG, which is unset for most of the runtime. It can be in a ready or blocked state only during the execution of the internal restore point switching process.

[0071] In one embodiment, the global flag includes the blocked state and the ready state. In the blocked state, physical transactions initiated before the blocked state are allowed to execute and commit, while physical transactions initiated after the blocked state are allowed to execute but blocked from committing. In the prepared state, the physical transaction can be submitted.

[0072] The blocked state can be a state entered during the internal restore point switching process. This state is used to constrain the commit of physical transactions, waiting for all physical transactions started before the blocked state to complete their commits. In this embodiment, the blocked state can be represented by SUSPEND.

[0073] The ready state can be a state entered during the internal restore point switching process. This state is used to trigger the flushing of the flashback log and redo log buffers to disk. Physical transactions can be committed while in the ready state. In this embodiment, the ready state can be represented by PREPARE.

[0074] Internal restore point switching can be triggered when a set time interval is reached, and the global marker is set to the ready state and then the blocked state in sequence. After completing the log flushing and waiting for the existing physical transactions to be committed, the next internal restore point is generated and the global marker is cleaned up.

[0075] The set time interval can be a pre-configured time threshold for the database, used to trigger periodic internal restore point switching.

[0076] In this embodiment, the physical transaction commit is differentiated and controlled by the globally marked ready state and blocked state. During the internal restore point switching process, the flashback log and redo log are persisted to disk. The switch is completed only after all physical transactions started before the blocked state are committed. This ensures that the modification and execution of physical transactions on the business side are not stopped, and the consistency of the snapshot corresponding to the internal restore point is guaranteed.

[0077] S270. After the internal restore point switching is completed, submit the physical transaction.

[0078] The completion of the internal restore point switching includes the next internal restore point after the creation of the previous internal restore point.

[0079] If the global flag is in a blocked state, the commit action of the physical transaction will not be executed for the time being. The physical transaction will be committed after all the internal restore point switching processes are completed and the global flag constraint is removed.

[0080] S280, Submit the physical transaction.

[0081] If the global flag is set to ready or unset, commit the physical transaction directly.

[0082] In this embodiment, after initiating a physical transaction, the hash table is checked. When a data page is modified for the first time after the creation of the corresponding internal restore point, the flashback log buffer is determined based on the identification information, the data page is copied, and the page address is registered in the hash table. After all data pages of the physical transaction have been modified, the timing of the physical transaction commit is controlled differently based on the state of the global flag. Building upon the periodic triggering of internal restore point switching, the constraint rules for physical transaction commits by the global flag's ready and blocked states during the switching process are further refined. This also addresses the issue of repeated flashback log generation caused by multiple modifications to the same data page within the same internal restore point period. By leveraging different states of the global flag to impose differentiated constraints on physical transaction commits, the consistency of snapshots corresponding to internal restore points is ensured without interrupting business operations.

[0083] Based on the above embodiments, modified embodiments of the above embodiments are proposed. It should be noted that, in order to keep the description brief, only the differences from the above embodiments are described in the modified embodiments.

[0084] In one embodiment, the internal restore point switching process includes: After a set time interval has elapsed since the creation of the previous internal restore point, the global marker is set to the ready state; In the prepared state, the flashback log buffer is refreshed, and the process waits for all generated flashback logs to be written to disk; the redo logs are refreshed, and the process waits for all redo logs to be written to disk. Set the global flag to a blocked state. In the blocked state, check whether all target physical transactions started before the blocked state have been committed. If not, block and wait until all target physical transactions have been committed. Refresh the flashback log buffer and the redo log again; Perform a restore point switch; Clean up the global markers of the internal restore points.

[0085] The target physical transaction can be a physical transaction that started before entering the blocked state. This part of the physical transaction is allowed to continue to execute and complete the commit. The internal restore point switching process needs to wait for all of this part of the physical transaction to be processed before it can continue to execute.

[0086] Set the global flag to the ready state, refresh the flashback log buffer, output the data temporarily stored in the flashback log buffer to the disk, and complete the process of writing memory data to the external storage device.

[0087] The data temporarily stored in the redo log buffer is output to the disk, completing the process of writing the redo log memory data to disk.

[0088] Set the global flag to blocked state, identify the running progress of all target physical transactions started before the blocked state, and confirm whether all of these physical transactions have been committed.

[0089] If not all target physical transactions have been committed, the subsequent process is paused, and the current processing state is maintained until all target physical transactions have been committed before the subsequent internal restore point switching process continues.

[0090] After the previous round of log flushing is completed, the operation of outputting data from the log buffer to the disk is executed again; the flashback log buffer and redo log are flushed again to output the newly generated log data during the blocked state phase to the disk.

[0091] Generate a new internal restore point to complete the replacement of the internal restore point.

[0092] This restores the global flag to its unset state, removing the constraint on physical transaction commits.

[0093] In this embodiment, by periodically triggering the internal restore point switch, the global flag is changed to the ready state and the blocked state in sequence. In the ready state, the flashback log and redo log are written to disk. In the blocked state, it waits for all the target physical transactions that were started earlier to be committed. Then, the flashback log and redo log added in the blocked phase are refreshed and written to disk again to generate a new internal restore point and remove the flag constraint. This ensures that the internal restore point snapshot is complete and reliable while the business runs normally, providing a foundation for database flashback operations.

[0094] In one embodiment, Figure 3 This is a schematic diagram of an internal reduction point sub-period division provided by an embodiment of the present invention. For example... Figure 3 As shown, the database continuously creates new internal restore points at specific time intervals, dividing the database runtime into consecutive sub-cycles. The abbreviation RP (Restore Point) represents an internal restore point. Internal restore points RP0, RP1, RP2, RP3, etc., are generated sequentially at preset time intervals. Two adjacent internal restore points constitute one sub-cycle. The LSNs of the database corresponding to each internal restore point are 100, 200, 500, and 1000, respectively.

[0095] To ensure the correctness of data after application flashback log rollback, restore point switching requires that the segmented sub-periods be continuous and independent, that is: 1. Physical transactions started after the current internal restore point is created must be committed within the current sub-cycle; that is, physical transactions will not span sub-cycles divided by the restore point.

[0096] 2. The physical transaction LSN committed after the current internal restore point is created must be greater than the current restore point LSN.

[0097] 3. The physical transaction LSN committed before the creation of the next restore point must be less than or equal to the LSN of the next restore point.

[0098] The restore point switching also ensures the atomicity of physical transactions. That is, after applying the flashback log to roll back data, it must be ensured that a batch of data pages modified by the physical transaction are either all rolled back to the state of the database at the specified time, or none are rolled back.

[0099] The internal restore point switching process is as follows: 1. The database triggers restore point switching at specific time intervals to prepare for the creation of new internal restore points.

[0100] 2. The global flag is denoted as SWITCH_FLAG. First, set the global flag to PREPARE state (i.e., ready state). In this state, there is no impact on the database's concurrent worker threads.

[0101] 3. Perform time-consuming operations in PREPARE state to avoid blocking database concurrent threads during subsequent switchover processes: refresh the flashback log buffer and wait for all generated flashback logs to be written to disk; refresh the redo log and wait for all redo logs (i.e., redo logs) to be written to disk.

[0102] 4. When the global flag is set to SUSPEND, physical transactions started before this flag is set can execute and commit normally; physical transactions started after this flag is set can execute normally but must be blocked before committing, waiting for the restore point switchover process to complete. After the SUSPEND state (i.e., blocked state) is set, no physical transactions write flashback logs or redo logs to the buffer.

[0103] 5. In the SUSPEND state, check whether all physical transactions started before the SUSPEND state was set have been committed, block and wait until they are all committed, and satisfy the independence of the restore point segmentation sub-cycles mentioned above.

[0104] 6. Refresh the flashback log buffer again to ensure that all newly generated flashback logs after the PREPARE state are written to disk; refresh the redo log again to ensure that newly generated redo logs after the PREPARE state are written to disk.

[0105] 7. Perform a restore point switch, clean up resources such as the memory pool and hash table, create a new internal restore point and register the maximum LSN value of the system at this time.

[0106] 8. Clear the global SWITCH_FLAG flag to indicate that the restore point switch is complete. At this point, the physical transactions blocked in step 4 will be automatically resumed.

[0107] 9. After the physical transaction blocked in step 4 is woken up, it enters a new sub-cycle and executes the commit action normally.

[0108] In one embodiment, Figure 4 This is a schematic diagram illustrating the generation of flashback logs for the same data page under different internal restore point cycles in an embodiment of the present invention. The flashback log stores a copy of the data page before modification, i.e., a mirror page. Before modifying a data page, the data page is copied and written to the flashback log. The flashback log consists of a log header and a mirror page. The log header stores necessary attribute information. For a data page, no flashback log is generated when it is first created; when it is subsequently modified, a flashback log is generated according to the following rules: 1. After creating an internal restore point, the data page will only generate a flashback log when it is first modified (including when it is updated or released).

[0109] 2. After creating a new internal restore point at periodic intervals, regenerate the flashback log according to rule 1.

[0110] like Figure 4 The diagram illustrates how a flashback log is generated when a data page is modified. Here, Pn represents the physical transaction with LSN n that modifies the data page (after Pn modifies the data page, the page LSN of the data page will be set to n), and Mn represents the replication of the data page with LSN n to the flashback log.

[0111] 1. Before creating the internal restore point for the first time, assume that the page LSN of the data page is 10.

[0112] 2. When LSN is 100, an internal restore point switch is performed, and an internal restore point is created, denoted as RP0.

[0113] 3. Physical transaction P110 with LSN 110 modifies the data page. At this time, a flashback log needs to be generated. Before modification, the data page is copied to obtain a mirror page. The mirror page is written to the flashback log. The mirror page has LSN 10 and is denoted as M10.

[0114] 4. Physical transaction P210 with LSN 210 modifies this data page; flashback logs are not required in this case.

[0115] 5. When LSN is 300, an internal restore point switch is performed, and an internal restore point is created, denoted as RP1.

[0116] 6. Similar to 3, physical transaction P310 with LSN 310 modifies the data page and needs to generate a flashback log. Before modification, the data page is copied to obtain a mirror page, which is then written into the flashback log. The mirror page has LSN 210 and is denoted as M210.

[0117] 7. Similar to 4, physical transaction P410 with LSN 410 modifies this data page without generating a flashback log.

[0118] When data needs to be rolled back, such as rolling back a data page to the point where RP1 is located, you only need to parse the flashback log to obtain the mirror page M210, and then use M210 to overwrite the current data page.

[0119] In one embodiment, the database is a high-concurrency system where hundreds or thousands of concurrent threads modify data pages at the same time. To address this, flashback logs are generated concurrently to optimize concurrency performance.

[0120] Each concurrent thread is allocated an independent flashback log buffer. Concurrent threads generate a random value based on their thread ID and determine a log buffer accordingly. When a concurrent thread needs to generate a flashback log to modify data, a mirror page is copied to the designated flashback log buffer. There are no concurrency conflicts between threads, maximizing concurrency processing capabilities and minimizing the impact of flashback log generation on database performance.

[0121] In this embodiment, the flashback log generation process is as follows: 1. The user thread executes the data page modification operation and starts the physical transaction.

[0122] 2. Before modifying a data page, check the hash table to determine if a flashback log has been generated for that page. If so, proceed to step 4; otherwise, proceed to step 3.

[0123] 3. Use the thread ID (i.e. identification information) as a seed to generate a random value, use this value to determine a flashback log buffer, then copy the data page to the flashback log in the buffer, and at the same time register the page address in the hash table to indicate that the page has generated a flashback log.

[0124] 4. Modify the data pages and generate the corresponding redo logs. Repeat steps 2 to 4 until all data pages have been modified.

[0125] 5. Once the data modification is complete, prepare to commit the physical transaction. Check if the global flag SWITCH_FLAG is SUSPEND. If not, commit the physical transaction directly; otherwise, block and wait until the restore point switch is completed and the global flag SWITCH_FLAG is cleared.

[0126] In one embodiment, Figure 5This is a schematic diagram of the structure of a device for generating flashback logs in a database, provided in an embodiment of the present invention. Figure 5 As shown, the device includes: The startup module 510 is used to start a physical transaction, which includes modification operations on data pages; Inspection module 520 is used to inspect the hash table to determine whether the data page modified by the user thread has generated a flashback log. The first determining module 530 is used to determine whether the current data page modification operation is the first modification of the data page after the creation of the corresponding internal restore point if no, and to determine the identification information of the user thread if yes, wherein the internal restore point is used to represent a snapshot of the database at a certain moment. The second determining module 540 is used to generate a random value corresponding to the identification information and determine the buffer of the flashback log based on the random value; The copy module 550 is used to copy the data page to the flashback log in the buffer and register the address of the data page in the hash table to indicate that the data page has generated the flashback log; Modification module 560 is used to modify the data page. After all data pages of the physical transaction have been modified, it determines whether to commit the physical transaction based on a global flag, which is set in the internal restore point switching process.

[0127] In one embodiment, the modification module 560 is specifically used for: If the global flag is in a blocked state, the physical transaction is committed after the internal restore point switch is completed. The completion of the internal restore point switch includes the creation of the next internal restore point after the creation of the internal restore point. Otherwise, submit the physical transaction.

[0128] In one embodiment, the global flag includes the blocked state and the ready state. In the blocked state, physical transactions initiated before the blocked state are allowed to execute and commit, while physical transactions initiated after the blocked state are allowed to execute but blocked from committing. In the prepared state, the physical transaction can be submitted.

[0129] In one embodiment, the flashback log includes a log header and a mirror page storage area, wherein the log header is used to store attribute information; the replication module 550 is specifically used for: Before modifying the data page, copy the data page to obtain a mirror page of the data page; The mirror page is stored in the mirror page storage area of ​​the flashback log.

[0130] In one embodiment, the moment is represented by a timestamp created by the internal restore point and the maximum log sequence number of the database.

[0131] In one embodiment, the modification module 560 is specifically used for: After a set time interval has elapsed since the creation of the previous internal restore point, the global marker is set to the ready state; In the prepared state, the flashback log buffer is refreshed, and the process waits for all generated flashback logs to be written to disk; the redo logs are refreshed, and the process waits for all redo logs to be written to disk. Set the global flag to a blocked state. In the blocked state, check whether all target physical transactions started before the blocked state have been committed. If not, block and wait until all target physical transactions have been committed. Refresh the flashback log buffer and the redo log again; Perform a restore point switch; Clean up the global markers of the internal restore points.

[0132] The apparatus provided in the embodiments of the present invention can execute the methods provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the methods.

[0133] In one embodiment, Figure 6 This is a structural block diagram of an electronic device provided in an embodiment of the present invention, such as... Figure 6 The diagram illustrates a schematic representation of an electronic device 10 that can be used to implement embodiments of the present invention. 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 can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), 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 invention described and / or claimed herein.

[0134] like Figure 6As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor 11, and the computer program is executed by the at least one processor 11 to enable the at least one processor 11 to perform the method provided by the present invention.

[0135] The processor 11 can perform various appropriate actions and processes based on a computer program stored in the read-only memory (ROM) 12 or a computer program loaded from the storage unit 18 into the random access memory (RAM) 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0136] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0137] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the methods provided in this invention.

[0138] In some embodiments, the method provided by the present invention can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the method described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to execute the method by any other suitable means (e.g., by means of firmware).

[0139] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard parts (ASSPs), systems-on-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments 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 transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0140] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0141] In the context of this invention, a computer-readable storage medium stores computer instructions that are used to cause a processor to execute and implement the method provided by this invention.

[0142] The present invention also provides a computer program product comprising a computer program that, when executed by a processor, implements the method provided according to embodiments of the present invention. A computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, the computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0143] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. 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).

[0144] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users 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., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0145] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0146] This invention also provides a computer program product, including a computer program that, when executed by a processor, can implement the methods provided in any embodiment of this invention.

[0147] In implementing the computer program product, computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone 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 via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0148] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0149] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. 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 invention should be included within the scope of protection of this invention.

Claims

1. A method for generating flashback logs in a database, characterized in that, include: Initiate a physical transaction, which includes modification operations on data pages; Check the hash table to determine if the data page modified by the user thread has generated a flashback log. If not, determine whether this data page modification operation is the first modification to the data page after the corresponding internal restore point is created. If so, determine the identification information of the user thread. The internal restore point is used to represent a snapshot of the database at a certain moment. Generate a random value corresponding to the identification information, and determine the buffer of the flashback log based on the random value; The data page is copied to the flashback log in the buffer, and the address of the data page is registered in the hash table to indicate that the data page has generated the flashback log; After all data pages of the physical transaction have been modified, a global flag is used to determine whether to commit the physical transaction. The global flag is set in the internal restore point switching process.

2. The method according to claim 1, characterized in that, The process of determining whether to commit the physical transaction based on a global flag includes: If the global flag is in a blocked state, the physical transaction is committed after the internal restore point switch is completed. The completion of the internal restore point switch includes the creation of the next internal restore point after the creation of the internal restore point. Otherwise, submit the physical transaction.

3. The method according to claim 2, characterized in that, The global flag includes the blocked state and the ready state. In the blocked state, physical transactions initiated before the blocked state are allowed to execute and commit, while physical transactions initiated after the blocked state are allowed to execute but blocked from committing. In the prepared state, the physical transaction can be submitted.

4. The method according to claim 1, characterized in that, The flashback log includes a log header and a mirror page storage area, wherein the log header is used to store attribute information; The process of copying the data page to the flashback log in the buffer includes: Before modifying the data page, copy the data page to obtain a mirror page of the data page; The mirror page is stored in the mirror page storage area of ​​the flashback log.

5. The method according to claim 1, characterized in that, The time is represented by the timestamp created by the internal restore point and the maximum log sequence number of the database.

6. The method according to claim 1, characterized in that, The internal restore point switching process includes: After a set time interval has elapsed since the creation of the previous internal restore point, the global marker is set to the ready state; In the prepared state, the flashback log buffer is refreshed, and the process waits for all generated flashback logs to be written to disk; the redo logs are refreshed, and the process waits for all redo logs to be written to disk. Set the global flag to a blocked state. In the blocked state, check whether all target physical transactions started before the blocked state have been committed. If not, block and wait until all target physical transactions have been committed. Refresh the flashback log buffer and the redo log again; Perform a restore point switch; Clean up the global markers of the internal restore points.

7. A device for generating flashback logs in a database, characterized in that, include: A startup module is used to initiate physical transactions, which include modification operations on data pages; The inspection module is used to inspect the hash table to determine whether the data page modified by the user thread has generated a flashback log. The first determining module is used to determine whether the current data page modification operation is the first modification of the data page after the creation of the corresponding internal restore point if no; if yes, it determines the identification information of the user thread, wherein the internal restore point is used to represent a snapshot of the database at a certain moment. The second determining module is used to generate a random value corresponding to the identification information and determine the buffer of the flashback log based on the random value; The copying module is used to copy the data page to the flashback log in the buffer and register the address of the data page in the hash table to indicate that the data page has generated the flashback log; The modification module is used to modify the data pages. After all data pages of the physical transaction have been modified, it determines whether to commit the physical transaction based on a global flag, which is set in the internal restore point switching process.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the method of any one of claims 1-6.

10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method according to any one of claims 1-6.