A database synchronization method and apparatus, an electronic device, and a storage medium
By determining the synchronization method based on the number of events in the archived logs, frequent disk flushing operations are avoided, thus solving the problem of low synchronization efficiency between primary and standby databases and achieving more efficient data synchronization.
Patent Information
- Application Number
- CN202311094664.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-29
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2043-08-29
AI Technical Summary
The existing primary/standby database synchronization method results in low synchronization efficiency, and timeout waiting affects the database processing capacity.
The synchronization method is determined based on the number of events in the archived logs, avoiding frequent disk flushing and I/O operations, and improving synchronization efficiency by strategically grouping transaction data.
While ensuring stable database processing performance, it improves the synchronization efficiency between the primary and backup machines, avoids performance fluctuations, and enhances overall performance.
Smart Images

Figure CN117112695B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a database synchronization method, apparatus, electronic device, and storage medium. Background Technology
[0002] Data is the core of a database, and preventing data loss and ensuring data security are prerequisites for high availability. Using a primary server with multiple backup servers (multiple replicas) is the industry standard for achieving high availability. Mainstream centralized and distributed databases typically use archived logs for data synchronization, and the primary server waits for responses from the backup servers to ensure strong consistency between the primary and backup data.
[0003] Currently, in primary-standby synchronization operations of various databases, when the primary machine executes a transaction with write statements, the changes to the related write operations are recorded in the archive log. When the transaction begins or completes its commit, the archive log information is incrementally sent to the standby machine, and the primary machine synchronously waits for a response from the standby machine. The transaction execution result is only returned to the client after receiving a response from the standby machine or after a timeout period. However, this approach reduces the synchronization efficiency between the primary and standby machines, and the timeout also impacts the database's processing capacity. Summary of the Invention
[0004] This application provides a database synchronization method, apparatus, electronic device, and storage medium to improve the synchronization efficiency between the primary and backup databases while ensuring the overall performance of the database.
[0005] According to a first aspect of this application, a database synchronization method is provided, applied to a database standby machine, the method comprising:
[0006] Obtain the archived log of the target transaction sent by the database host; wherein the archived log consists of at least one event;
[0007] The backup machine synchronization method is determined based on the number of events in the archived logs;
[0008] According to the standby machine synchronization method, the data of the database host is synchronized to the database standby machine, and a synchronization response is sent back to the database host.
[0009] According to a second aspect of this application, a database synchronization method is provided, applied to a database host, the method comprising:
[0010] Get the log volume of the archived logs corresponding to the target transaction;
[0011] Based on the log volume, the number of target transactions, and preset impact parameters, determine the theoretical response time of the target transaction, and send the archived logs to the database standby machine;
[0012] Based on the actual response time and the theoretical response time provided by the database standby machine, determine whether the database standby machine has experienced a transaction synchronization timeout, and issue a timeout alarm.
[0013] According to a third aspect of this application, a database synchronization device is provided for use on a database standby machine, the device comprising:
[0014] The archive log acquisition module is used to acquire the archive log of the target transaction sent by the database host; wherein the archive log consists of at least one event;
[0015] The synchronization method determination module is used to determine the standby machine synchronization method based on the number of events in the archived logs;
[0016] The standby data synchronization module is used to synchronize the data of the database host to the database standby machine according to the standby synchronization method, and to send a synchronization response back to the database host.
[0017] According to a fourth aspect of this application, a database synchronization apparatus is provided, applied to a database host, the apparatus comprising:
[0018] The log volume acquisition module is used to obtain the log volume of the archived logs corresponding to the target transaction;
[0019] The response time determination module is used to determine the theoretical response time of the target transaction based on the log volume, the number of target transactions, and preset impact parameters, and send the archived logs to the database standby machine.
[0020] The synchronization timeout determination module is used to determine whether the database standby machine has experienced a transaction synchronization timeout based on the actual response time and the theoretical response time provided by the database standby machine, so as to issue a timeout alarm.
[0021] According to a fifth aspect of this application, an electronic device is provided, the electronic device comprising:
[0022] At least one processor; and
[0023] A memory communicatively connected to the at least one processor; wherein,
[0024] 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 database synchronization method described in the first aspect of the present application; and / or, to perform the database synchronization method described in the second aspect of the present application.
[0025] According to a sixth aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions, the computer instructions being configured to cause a processor to execute and implement the database synchronization method described in the first aspect embodiment of this application; and / or, implement the database synchronization method described in the second aspect embodiment of this application.
[0026] The technical solution of this application embodiment determines the synchronization method based on the number of events in the archived log, so as to synchronize the data in the database master to the database standby. This can ensure the stability of database processing performance while avoiding performance jitter caused by frequent disk flushing and I / O operations, thereby improving the synchronization efficiency between the database master and standby.
[0027] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments of this application, 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 this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 This is a flowchart of a database synchronization method provided according to Embodiment 1 of this application;
[0030] Figure 2 This is a flowchart of a database synchronization method according to Embodiment 2 of this application;
[0031] Figure 3A This is a schematic diagram of a standby machine strategic disk flashing synchronization process provided in Embodiment 3 of this application;
[0032] Figure 3B This is a schematic diagram of a process for a host machine to check a standby machine response timeout according to Embodiment 3 of this application;
[0033] Figure 4 This is a schematic diagram of a database synchronization device according to Embodiment 4 of this application;
[0034] Figure 5 This is a schematic diagram of a database synchronization device according to Embodiment 5 of this application;
[0035] Figure 6 This is a schematic diagram of the structure of an electronic device that implements the database synchronization method of the embodiments of this application. Detailed Implementation
[0036] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0037] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application 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 this application 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 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.
[0038] Example 1
[0039] Figure 1 This application provides a flowchart of a database synchronization method according to Embodiment 1. This embodiment is applicable to data synchronization between a primary and backup database. The method is applied to the backup database and can be executed by a database synchronization device. This database synchronization device can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:
[0040] S110. Obtain the archive log of the target transaction sent by the database host; wherein the archive log consists of at least one event.
[0041] The database can be of any type, including but not limited to centralized and distributed databases. Correspondingly, the database host can be the primary device for any database, while the database standby device can be a redundant device of the database host. To ensure data security, multiple database standby devices can be configured to synchronize data in the database host. Of course, the embodiments in this application only describe the interaction between one database host and one database standby device and should not be construed as a limitation on the number of database standby devices. The target transaction can be the set of data that needs to be synchronized between the primary and standby devices. The archived log can be used to record information about transactions archived in the database host. Events are records of operations such as queries and calls performed on data in the database during the operation of the database host; multiple events can be recorded in the archived log. It should be noted that after updating the archived log, the database host generally pushes it directly to each database standby device so that the database standby devices can synchronize data based on these archived logs.
[0042] S120. Determine the standby machine synchronization method based on the number of events in the archived logs.
[0043] The number of events can refer to the number of events in the archived logs. It's understood that existing technologies use incremental updates for updating archived logs and synchronizing data. That is, after a new archived log is generated, the database host sends the corresponding incremental log to the database standby, and the standby synchronizes and backs up the data based on the continuously sent incremental logs. However, this approach easily leads to frequent disk flushing operations on the standby, thus wasting database resources. This application uses the number of events as the basis for synchronization on the database standby. The database standby can synchronize and respond to the database host only after receiving all archived logs for a complete transaction. Since a transaction may contain multiple events, different synchronization methods can be used based on the number of events. Strategic disk flushing can maximize synchronization quality and efficiency while reducing the resource consumption of the database standby. Optionally, if the number of events in a single transaction is small, each transaction can be processed directly; if the number of events in a single transaction is large, these event data can be grouped for processing.
[0044] In one optional implementation, determining the standby machine synchronization method based on the number of events in the archived log may include: if the number of events is greater than a preset number threshold, grouping the events according to the number threshold to obtain at least one event group to be synchronized; and using each event group to be synchronized as a granularity for synchronization.
[0045] The quantity threshold can be a processing limit set for the corresponding number of events, that is, the maximum number of events that the database standby machine can process at one time from the archived logs. Of course, the quantity threshold can be set by relevant technical personnel based on extensive experimentation or human experience; this embodiment does not limit this. If the number of events in a transaction exceeds the quantity threshold, all events in the archived logs can be grouped according to the quantity threshold to obtain event groups to be synchronized. Each event group to be synchronized is treated as a separate granularity for subsequent synchronization processing.
[0046] For example, assuming the set threshold is N, if the number of events in the archived log exceeds N, then every N events are grouped into a single synchronization event group as a granularity for synchronization. For instance, if the threshold is set to 10, and the total number of events in the archived log is 50, then they can be divided into 5 different synchronization event groups. It's understandable that dividing the events in the archived log according to their quantity effectively avoids the drawback of the database standby machine frequently flushing disks for data synchronization, thus affecting the database's processing performance. This helps improve the efficiency of database synchronization and enhances the database's data processing performance.
[0047] In another optional implementation, determining the standby synchronization method based on the number of events in the archived log may include: if the number of events is not greater than the number threshold, then the target transaction is used as a unit of synchronization.
[0048] Understandably, if the number of events in the archived logs is less than the set threshold, it means that the database standby server is capable of handling the data synchronization corresponding to these events with good performance. Therefore, target transactions with fewer than the threshold of events can be processed as a single unit, and subsequent synchronization can be performed directly on that target transaction.
[0049] S130. According to the standby machine synchronization method, synchronize the data of the database host to the database standby machine, and send a synchronization response back to the database host.
[0050] According to the synchronization method determined in the aforementioned implementation methods, the data that needs to be synchronized by the database host is flushed (written to the cache) and synced (cleared the cache and written to the physical disk) on the database standby. Then, the message that the target transaction synchronization is complete is fed back to the database host, that is, a synchronization response is sent.
[0051] The technical solution of this application embodiment determines the synchronization method based on the number of events in the archived log, so as to synchronize the data in the database master to the database standby. This can ensure the stability of database processing performance while avoiding performance jitter caused by frequent disk flushing and I / O operations, thereby improving the synchronization efficiency between the database master and standby.
[0052] Example 2
[0053] Figure 2 This is a flowchart of a database synchronization method provided in Embodiment 2 of this application. This embodiment is applicable to data synchronization between a primary and backup database. The method is applied to the primary database side and can be executed by a database synchronization device. This database synchronization device can be implemented in hardware and / or software and can be configured in an electronic device. Figure 2 As shown, the method includes:
[0054] S210. Obtain the log volume of the archived log corresponding to the target transaction.
[0055] The target transaction can be a set of data that needs to be synchronized between the primary and standby databases. The archived log can be information used to record transactions archived on the database host. The log volume can be the amount of data containing the records of various transactions or events in the archived log. Since the archived log is directly generated on the database host, the database host can directly retrieve the log volume. It should be noted that the log volume of the archived log synchronized for each transaction between the primary and standby databases varies in practice; therefore, the synchronization strategy of the database host can be adjusted accordingly for different standby databases.
[0056] S220. Based on the log volume, the number of target transactions, and preset impact parameters, determine the theoretical response time of the target transaction, and send the archived logs to the database standby machine.
[0057] The number of target transactions can be the number of transactions requiring data synchronization, and the influencing parameters can be auxiliary parameters used to calculate the theoretical response time. In one optional embodiment, the preset influencing parameters may include: a proportional coefficient, an adjustment amount, and a lower limit of the timeout threshold. The proportional coefficient can reflect the database processing capacity and is used to proportionally amplify or reduce the processing time corresponding to the log volume according to the database's processing capacity; the adjustment amount is the adaptively supplemented time after proportional adjustment; the lower limit of the timeout threshold is the limit of standby timeout that the database master can accept. If no response is received from the standby machine after this time, it indicates that the standby machine has timed out during the synchronization process. Of course, the proportional coefficient, adjustment amount, and lower limit of the timeout threshold can all be determined by relevant technical personnel through extensive experiments or actual conditions, and this application embodiment does not limit this.
[0058] The theoretical response time of the target transaction is obtained by calculating the log volume and the number of target transactions using preset impact parameters. This theoretical response time can be understood as the longest time theoretically possible for the database standby server to send a response back to the database master server after synchronization. It's important to note that the target transactions (including the amount of events in the archived logs) that need to be backed up differ between different database standby servers. Therefore, the theoretical response time for each standby server can be calculated separately based on its corresponding log volume.
[0059] Furthermore, determining the theoretical response time of the target transaction based on the log volume, the number of target transactions, and preset impact parameters may include: determining the calculated response time based on the log volume, the proportional coefficient, and the adjustment amount; and taking the larger of the calculated response time and the lower limit of the timeout threshold as the theoretical response time.
[0060] The calculation of theoretical response time requires analysis of different scenarios. For archived logs of a single transaction, the response time is calculated by multiplying the log volume and the proportional coefficient of the archived logs by the sum of the adjustment amount. Then, the calculated response time is compared with the lower limit of the timeout threshold, and the larger one is taken as the theoretical response time.
[0061] Understandably, the response time is calculated based on the varying log volume required for synchronization on different database standby servers. However, this response time may be short. If the primary database server continuously waits for a short period without receiving a response from the standby server and immediately judges the standby server as timed out, it can easily lead to misjudgments and affect synchronization efficiency. Therefore, a lower timeout threshold is set. If the calculated response time exceeds this lower threshold, the calculated response time is selected as the theoretical response time; similarly, if the calculated response time is less than or equal to the lower timeout threshold, the lower timeout threshold is selected as the theoretical response time.
[0062] Furthermore, for archived logs across multiple transactions, the database host needs to enable group commit mode. Each synchronization process generates archived logs for a group of transactions. Therefore, the log volumes from all transactions within a group must first be summed to obtain the total log volume. Then, the product of the total log volume and the scaling factor, plus the sum of the adjustment amount, is used to calculate the response time. Similarly, the calculated response time is compared to the lower limit of the timeout threshold; the larger of the two is used as the theoretical response time. If the calculated response time is greater than the lower limit of the timeout threshold, the calculated response time is selected as the theoretical response time; conversely, if the calculated response time is less than or equal to the lower limit of the timeout threshold, the lower limit of the timeout threshold is selected as the theoretical response time.
[0063] S230. Based on the actual response time and the theoretical response time provided by the database standby machine, determine whether the database standby machine has experienced a transaction synchronization timeout, and issue a timeout alarm.
[0064] The actual response time is the actual time taken for the database standby machine to synchronize based on the archived logs of the target transaction. When the actual response time exceeds the theoretical response time, it can be determined that the database standby machine has timed out during the synchronization process, and a timeout alarm will be issued. Of course, the alarm method can be any alarm method in the relevant technology, such as audible and visual alarms, etc. This application embodiment does not limit this.
[0065] The technical solution of this application embodiment calculates the theoretically permissible response time of each database standby machine during the synchronization process based on the amount of logs that need to be synchronized for different database standby machines, and then determines which database standby machines have experienced synchronization timeouts and issues an alarm. This allows for control over the different synchronization situations of different database standby machines, further improving the adaptability and efficiency of data synchronization.
[0066] Example 3
[0067] Embodiment 3 of this application is a preferred embodiment provided based on the foregoing embodiments. Figure 3A This is a schematic diagram of a standby machine strategic disk flashing synchronization process provided in an embodiment of this application, such as... Figure 3A As shown:
[0068] The database standby server will only respond to the database master server after receiving the complete archive log of a full transaction. A complete transaction's archive log consists of multiple events. The standby server will respond when the number of events in the transaction's archive log received is less than a threshold N. events In such cases, flush and sync operations are performed at the transaction level to avoid frequent disk flushing impacting the performance of the database standby server; for databases containing more than N events...events Large transactions, each time N is received events For each event, a flush and sync operation is performed (equivalent to a threshold N). events Event grouping is implemented to ensure performance while avoiding performance jitter caused by concentrated I / O operations.
[0069] Figure 3B This is a schematic diagram of a process for a host machine to check a standby machine's response timeout, provided in an embodiment of this application. Figure 3B As shown:
[0070] Because the amount of archived logs synchronized for each transaction between the primary and backup servers varies, the response processing thread retrieves the log size S of the transaction to be synchronized from the archived log cache before waking up the worker thread to synchronize the archived logs. log The proportionality coefficient for waiting for a response timeout is R. timeout The adjustment amount is Δ, and the lower limit of the timeout threshold for waiting for a synchronization response is L. timeout The timeout for each log synchronization is:
[0071] T timeout =max{R timeout *S log +Δ,L timeout};
[0072] Among them, the proportionality coefficient R timeout Adjustment amount Δ and lower limit of waiting response timeout threshold L timeout These are all configuration items that can be dynamically adjusted and can be flexibly configured according to different production environments.
[0073] When the database is in group commit mode, each synchronization synchronizes the archived logs generated by a group of transactions. If the number of transactions synchronized together is n, then...
[0074]
[0075] Accordingly, the timeout for each log synchronization is:
[0076]
[0077] When the primary machine's dump thread (synchronization thread) prepares to synchronize archived logs to the standby machine, the response processing thread will use the response timeout T calculated by the above formula. timeout Set a response timeout for the corresponding transaction and poll it every second. If no response is received from the standby machine by the timeout period, the transaction will be marked as a timed-out transaction, and the standby machine's response timeout information will be recorded. The host will then send all information about the timeout to the alarm monitoring platform via the alarm module and adjust the cluster's primary and standby status information accordingly.
[0078] The solution in this application not only adapts to the different log volumes of the host and standby machines by varying their characteristics, effectively avoiding the problems of a single processing mode and susceptibility to abnormal host-standby status due to different business requirements in existing master-standby architectures, thus significantly enhancing the availability of the database cluster; it also performs strategic flushing of logs on the standby machine, effectively reducing master-standby latency and improving overall performance and stability while ensuring data consistency and reliability between the master and standby machines. Synchronization is performed at the transaction size granularity, ensuring master-standby consistency while avoiding frequent network interactions.
[0079] Example 4
[0080] Figure 4 This is a schematic diagram of a database synchronization device provided in Embodiment 4 of this application. Figure 4 As shown, the device 400 includes:
[0081] The archive log acquisition module 410 is used to acquire the archive log of the target transaction sent by the database host; wherein the archive log consists of at least one event;
[0082] The synchronization mode determination module 420 is used to determine the standby machine synchronization mode based on the number of events in the archived logs;
[0083] The standby data synchronization module 430 is used to synchronize the data of the database host to the database standby machine according to the standby synchronization method, and to send a synchronization response back to the database host.
[0084] The technical solution of this application embodiment determines the synchronization method based on the number of events in the archived log, so as to synchronize the data in the database master to the database standby. This can ensure the stability of database processing performance while avoiding performance jitter caused by frequent disk flushing and I / O operations, thereby improving the synchronization efficiency between the database master and standby.
[0085] In one alternative implementation, the synchronization mode determination module 420 may include:
[0086] An event group determination unit is used to group the events according to the number threshold if the number of events is greater than a preset number threshold, so as to obtain at least one event group to be synchronized.
[0087] The granularity determination unit is used to use each of the event groups to be synchronized as a granularity for synchronization.
[0088] In another alternative embodiment, the synchronization mode determination module 420 can be specifically used for:
[0089] If the number of events is not greater than the number threshold, then the target transaction is used as a unit of synchronization.
[0090] The database synchronization device provided in this application can execute the database synchronization method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects for executing each database synchronization method.
[0091] Example 5
[0092] Figure 5 This is a schematic diagram of a database synchronization device provided in Embodiment 5 of this application. Figure 5 As shown, the device 500 includes:
[0093] The log volume acquisition module 510 is used to acquire the log volume of the archived logs corresponding to the target transaction;
[0094] The response duration determination module 520 is used to determine the theoretical response duration of the target transaction based on the log volume, the number of target transactions, and preset impact parameters, and send the archived logs to the database standby machine.
[0095] The synchronization timeout judgment module 530 is used to determine whether the database standby machine has experienced a transaction synchronization timeout based on the actual response time and the theoretical response time of the feedback synchronization response provided by the database standby machine, so as to issue a timeout alarm.
[0096] The technical solution of this application embodiment calculates the theoretically permissible response time of each database standby machine during the synchronization process based on the amount of logs that need to be synchronized for different database standby machines, and then determines which database standby machines have experienced synchronization timeouts and issues an alarm. This allows for control over the different synchronization situations of different database standby machines, further improving the adaptability and efficiency of data synchronization.
[0097] In one optional implementation, the preset influence parameters include: a proportional coefficient, an adjustment amount, and a lower limit of the timeout threshold.
[0098] Furthermore, the response duration determination module 520 may include:
[0099] The duration calculation unit is used to determine the response duration based on the log volume, the proportional coefficient, and the adjustment amount.
[0100] The theoretical duration determination unit is used to take the larger of the calculated response duration and the lower limit of the timeout threshold as the theoretical response duration.
[0101] The database synchronization device provided in this application can execute the database synchronization method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects for executing each database synchronization method.
[0102] Example 6
[0103] Figure 6 A schematic diagram of an electronic device 10, which can be used to implement embodiments of this application, is shown. 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 (such as 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 application described and / or claimed herein.
[0104] like Figure 6 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may 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.
[0105] 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.
[0106] 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, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as database synchronization methods.
[0107] In some embodiments, the database synchronization method may 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 may 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 database synchronization method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the database synchronization method by any other suitable means (e.g., by means of firmware).
[0108] 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 products (ASSPs), systems-on-a-chip (SoCs), payload-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.
[0109] Computer programs used to implement the methods of this application 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.
[0110] In the context of this application, a computer-readable storage medium can 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. A computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can 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 fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0111] 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).
[0112] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include 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.
[0113] 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.
[0114] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this application can be achieved, and this is not limited herein.
[0115] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A database synchronization method, characterized by, The method applied to a database standby machine comprises: acquiring an archive log of a target transaction sent by a database host; wherein the archive log is composed of at least one event; determining a standby machine synchronization mode according to the number of events in the archive log, comprising: if the number of events is greater than a preset number threshold, grouping each of the events according to the number threshold to obtain at least one to-be-synchronized event group; using each of the to-be-synchronized event groups as granularity for synchronization respectively; synchronizing data of the database host to the database standby machine according to the standby machine synchronization mode, and feeding back a synchronization response to the database host.
2. The method of claim 1, wherein, The method of determining the standby machine synchronization mode according to the number of events in the archive log comprises: if the number of events is not greater than the number threshold, using the target transaction as a granularity for synchronization.
3. A database synchronization method, characterized by, The method applied to a database host comprises: acquiring a log quantity of an archive log corresponding to a target transaction; determining a theoretical response time length of the target transaction according to the log quantity, the number of the target transaction and a preset influence parameter, and sending the archive log to a database standby machine, wherein the preset influence parameter comprises a proportionality coefficient, an adjustment quantity and a lower limit of a timeout threshold; determining whether transaction synchronization timeout of the database standby machine occurs according to an actual response time length of the database standby machine providing a feedback synchronization response and the theoretical response time length, to perform timeout alarm; The method of determining the theoretical response time length of the target transaction according to the log quantity, the number of the target transaction and the preset influence parameter comprises: determining a calculation response time length according to the log quantity, the proportionality coefficient and the adjustment quantity; using the greater one of the calculation response time length and the lower limit of the timeout threshold as the theoretical response time length.
4. A database synchronization apparatus, characterized by comprising: The device applied to a database standby machine comprises: an archive log acquiring module, configured to acquire an archive log of a target transaction sent by a database host; wherein the archive log is composed of at least one event; a synchronization mode determining module, configured to determine a standby machine synchronization mode according to the number of events in the archive log; The synchronization mode determining module comprises: an event group determining unit, configured to, if the number of events is greater than a preset number threshold, group each of the events according to the number threshold to obtain at least one to-be-synchronized event group; a granularity determining unit, configured to use each of the to-be-synchronized event groups as granularity for synchronization respectively; a standby machine data synchronizing module, configured to synchronize data of the database host to the database standby machine according to the standby machine synchronization mode, and feed back a synchronization response to the database host.
5. A database synchronization apparatus, characterized by comprising: The device applied to a database host comprises: a log quantity acquiring module, configured to acquire a log quantity of an archive log corresponding to a target transaction; a response time length determining module, configured to determine a theoretical response time length of the target transaction according to the log quantity, the number of the target transaction and a preset influence parameter, and send the archive log to a database standby machine; wherein the preset influence parameter comprises a proportionality coefficient, an adjustment quantity and a lower limit of a timeout threshold; The response time length determining module further comprises: The time length calculation unit is configured to determine a calculation response time length according to the log amount, the proportion coefficient and the adjustment amount. The theoretical time length determination unit is configured to determine the larger one of the calculation response time length and the lower limit of the timeout threshold as the theoretical response time length. The synchronous timeout judgment module is configured to determine whether the database standby machine has transaction synchronization timeout according to the actual response time length of the database standby machine providing feedback synchronization response and the theoretical response time length, so as to perform timeout alarm.
6. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected with the at least one processor in communication; wherein, the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the database synchronization method in any one of claims 1-2; and / or execute the database synchronization method in claim 3.
7. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to implement the database synchronization method in any one of claims 1-2; and / or implement the database synchronization method in claim 3 when executed.
Citation Information
Patent Citations
Data synchronization method, device and system, apparatus, storage medium and program product
CN113434476A
Data synchronization method and system between databases, electronic equipment and storage medium
CN115329007A