Database synchronization method and device, electronic equipment and storage medium

By introducing the database lock list and multi -collection server competition lock in the business system, the problem of waste, low efficiency and omissions in the existing technology, and achieve efficient and accurate data synchronization.

CN119357285APending Publication Date: 2025-01-24厦门天锐科技股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411360741.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

Existing business systems have problems such as waste of performance, low efficiency and omission of incremental synchronization when performing data synchronization, especially in the case of multiple acquisition servers and multiple databases.

Method used

By introducing the mechanism of the database lock watch and the multi -collection server competition lock to ensure the consistency of the same business type of the same business at the same time. The collection server is based on the database lock table in accordance with the preset rules, and the database database is updated in accordance with the preset rules, and the version number maintenance table and synchronous business data are updated after occupying the database.

Benefits of technology

Avoid the waste of performance during database synchronization, improve the synchronization efficiency, ensure the accuracy of data synchronization, and reduce the probability of incremental synchronization omissions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357285A_ABST
    Figure CN119357285A_ABST
Patent Text Reader

Abstract

The invention provides a database synchronization method and device, electronic equipment and a storage medium, and relates to the technical field of databases. The method comprises the steps of competing for a target database according to a preset rule based on a database lock table; each database corresponds to a version number maintenance table; after the target database is occupied, if newly-added business data reported by the terminal exists in the target database during the occupation period, querying the current version number of the newly-added business data from the version number maintenance table of the target database and automatically increasing, and updating the version number maintenance table of the target database, and synchronizing the newly added business data to a headquarters database through a headquarters engine server. Compared with the prior art, only one acquisition server is ensured to access the same service type of the same database at the same time through the database table locking, so that the performance waste in the database synchronization process is avoided, the synchronization efficiency is improved, and the data synchronization accuracy is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a database synchronization method, device, electronic device and storage medium. Background Art

[0002] like Figure 1 As shown in the figure, the business system includes modules such as console, engine server, collection server, database, and terminal. The console and engine server are only deployed in the headquarters, while the collection server, database, and terminal can be deployed in the headquarters and branches respectively. For data security reasons, the databases of the headquarters and branches cannot open port mapping, but the engine server of the headquarters can open port mapping, that is, the business data of the branch terminal collected by the collection server of the branch can only be written to the database of the branch. The collection server of the branch can connect to the engine server of the headquarters, so the collection server of the branch can synchronize the business data of the branch database to the headquarters database through the engine server of the headquarters, so that the console of the headquarters can view the business data of the branch terminal through the database of the headquarters.

[0003] As the running time of the branch terminal increases, the business data will continue to increase, and the number of terminals connected to the branch will also continue to increase. Therefore, the business data of the branch database is synchronized to the headquarters database incrementally using the version number. Each database has a version number maintenance table. When the branch's acquisition server receives the business data reported by the branch terminal, the version number of each business data is first written as 0. The branch acquisition server starts another thread to regularly query the version number of the current business data in the branch database and increments the memory. The business data with version number 0 is updated to the self-incremented version number, and the version number maintenance table is also updated. When the headquarters engine server initiates data synchronization to the branch acquisition server, the branch acquisition server finds the incremental business data from the branch database according to the version number of the last synchronization of the headquarters engine server, and then sends the incremental business data to the engine server. After receiving the business data, the engine server writes it to the headquarters database, and finally enables the headquarters console to view and backup the business data of the branch terminal.

[0004] The existing business system has the following defects when performing data synchronization:

[0005] 1. When there is only one branch database, there is only one branch collection server that performs incremental synchronization, which is randomly specified by the engine server. The engine server cannot guarantee that the randomly specified branch collection server can access the branch database normally. In order to recover from the situation where the branch collection server is offline, multiple branch collection servers must connect to the engine server at the same time, which will cause performance waste.

[0006] 2. When there are multiple branch databases, there is only one branch collection server that performs incremental synchronization, which is randomly specified by the engine server. The engine server cannot guarantee that the randomly specified branch collection server can access the branch database normally. One branch collection server performs incremental synchronization of business data of multiple databases, and the execution efficiency is relatively low.

[0007] 3. There may be threads of multiple acquisition servers in a branch that concurrently query the current version number of a certain business type in the version maintenance table of the same branch database, and update the business data table and the version maintenance table after the version number is incremented. There is a certain probability that the version number of the business data table will be updated inconsistently, resulting in omissions in the synchronization of incremental data. Figure 1 As shown, for example, at a certain concurrent moment, acquisition server 1001 obtains the current business data version number 1 from the version number maintenance table of database 9001, and acquisition server 1002 obtains the current business data version number 1 from the version number maintenance table of database 9001. After the acquisition server 1001 version number is incremented to 2 and the business data table and the version number maintenance table are updated, the following two situations may occur:

[0008] One is that when the acquisition server 1002 obtains version number 1 and increments it to version number 2, but there is no time to update the version number of the business data, synchronization has already occurred. In this case, the next incremental synchronization will start incremental query from the business data with a version number greater than 2, causing the business data with version number 2 stored in the acquisition server 1002 to be missed.

[0009] The other is that when the acquisition server 1002 obtains the version number 1 and increments it to 2, but has no time to update the version number of the business data, the acquisition server 1003 has already obtained the current version number of the business data from the version number maintenance table of database 9001, which is 2, and incremented it to 3, and then updated the business data table and synchronized. Then the next incremental synchronization will start the incremental query from the business data with a version number greater than 3, causing the business data with version number 2 stored in the acquisition server 1002 to be missed.

[0010] In summary, when multiple collection servers are running, there is a certain probability that inconsistent updates of business data version numbers will occur. The more collection servers are running, the greater the probability of incremental synchronization omissions. Summary of the invention

[0011] The purpose of the present application is to provide a database synchronization method, device, electronic device and storage medium.

[0012] In a first aspect, an embodiment of the present application provides a database synchronization method applied to a collection server of a branch in a business system, wherein the business system also includes an engine server and a headquarters database of a headquarters, including:

[0013] Based on the database lock table, compete for the target database according to the preset rules; the database lock table includes: database number, business number, acquisition server number of the occupied lock, heartbeat timestamp of the occupied lock, acquisition server number of the competing lock, and heartbeat timestamp of the competing lock; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database;

[0014] After occupying the target database, during the occupation period, if the target database contains new business data reported by the terminal, the current version number of the new business data is queried from the version number maintenance table of the target database and incremented automatically, the version number maintenance table of the target database is updated, and the new business data is synchronized to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database.

[0015] In a possible implementation, the preset rule includes:

[0016] First query the records of the database lock table. If the database lock is not occupied by other collection servers, the collection server itself occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0017] If the database lock has been occupied by other acquisition servers, the heartbeat timestamp of the occupied lock is checked. When the difference between the heartbeat time of the occupied lock and the current time exceeds the first time threshold, the current acquisition server occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0018] In a possible implementation, the preset rule further includes:

[0019] The calculation formula for the maximum number of locks occupied by each acquisition server is: a = (b / c) + 1;

[0020] Among them, a represents the maximum number of locks occupied by the acquisition server, b represents the number of branch databases in the business system, and c represents the number of branch acquisition servers in the business system.

[0021] In a possible implementation, the preset rule further includes:

[0022] If there is no other collection server competing for the database lock, or the difference between the heartbeat time of the competing lock and the current time exceeds the second time threshold, and the number of occupied locks of this collection server plus the number of competing locks does not exceed the maximum number of occupied locks of this collection server, then this collection server is allowed to mark the competing lock and update the heartbeat timestamp of the competing lock. The same collection server cannot mark occupied locks and competing locks at the same time.

[0023] In a possible implementation, the preset rule further includes:

[0024] If the number of occupied locks of this acquisition server plus the number of competing locks exceeds the maximum number of occupied locks of this acquisition server, the excess occupied locks or competing locks are released so that other acquisition servers can re-mark the occupied locks or competing locks;

[0025] If the number of locks occupied by this acquisition server exceeds the maximum number of locks occupied by this acquisition server, and there is no other acquisition server competing for the lock, then this acquisition server will keep occupying the lock;

[0026] If the number of occupied locks of this collection server exceeds the maximum number of occupied locks of this collection server, and other collection servers have marked competing locks, this collection server will release the excess occupied locks so that the collection servers marked competing locks can occupy the released database locks first, and clear the competing lock marks after successfully occupying the locks.

[0027] In a second aspect, an embodiment of the present application provides a database synchronization device, which is applied to a collection server of a branch in a business system, wherein the business system also includes an engine server and a headquarters database of the headquarters, including:

[0028] A competition module is used to compete for a target database according to preset rules based on a database lock table; the database lock table includes: database number, business number, acquisition server number of the occupied lock, heartbeat timestamp of the occupied lock, acquisition server number of the competing lock, and heartbeat timestamp of the competing lock; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database;

[0029] The synchronization module is used to query the current version number of the new business data from the version number maintenance table of the target database and increment it automatically after occupying the target database during the occupation period, if the target database contains new business data reported by the terminal, update the version number maintenance table of the target database, and synchronize the new business data to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database.

[0030] In a possible implementation, the preset rule includes:

[0031] First query the records of the database lock table. If the database lock is not occupied by other collection servers, the collection server itself occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0032] If the database lock has been occupied by other acquisition servers, the heartbeat timestamp of the occupied lock is checked. When the difference between the heartbeat time of the occupied lock and the current time exceeds the first time threshold, the current acquisition server occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0033] In a possible implementation, the preset rule further includes:

[0034] The calculation formula for the maximum number of locks occupied by each acquisition server is: a = (b / c) + 1;

[0035] Among them, a represents the maximum number of locks occupied by the acquisition server, b represents the number of branch databases in the business system, and c represents the number of branch acquisition servers in the business system.

[0036] In a possible implementation, the preset rule further includes:

[0037] If there is no other collection server competing for the database lock, or the difference between the heartbeat time of the competing lock and the current time exceeds the second time threshold, and the number of occupied locks of this collection server plus the number of competing locks does not exceed the maximum number of occupied locks of this collection server, then this collection server is allowed to mark the competing lock and update the heartbeat timestamp of the competing lock. The same collection server cannot mark occupied locks and competing locks at the same time.

[0038] In a possible implementation, the preset rule further includes:

[0039] If the number of occupied locks of this acquisition server plus the number of competing locks exceeds the maximum number of occupied locks of this acquisition server, the excess occupied locks or competing locks are released so that other acquisition servers can re-mark the occupied locks or competing locks;

[0040] If the number of locks occupied by this acquisition server exceeds the maximum number of locks occupied by this acquisition server, and there is no other acquisition server competing for the lock, then this acquisition server will keep occupying the lock;

[0041] If the number of occupied locks of this collection server exceeds the maximum number of occupied locks of this collection server, and other collection servers have marked competing locks, this collection server will release the excess occupied locks so that the collection servers marked competing locks can occupy the released database locks first, and clear the competing lock marks after successfully occupying the locks.

[0042] In a third aspect, the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect.

[0043] In a fourth aspect, the present application provides a computer-readable storage medium having computer-readable instructions stored thereon, wherein the computer-readable instructions can be executed by a processor to implement the method described in the first aspect.

[0044] In the database synchronization method provided by the present application, based on the database lock table, the target database is competed according to the preset rules; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database; after occupying the target database, during the occupation period, if the target database has new business data reported by the terminal, the current version number of the new business data is queried from the version number maintenance table of the target database and incremented, the version number maintenance table of the target database is updated, and the new business data is synchronized to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database. Compared with the prior art, the present application ensures that only one acquisition server accesses the same business type of the same database at the same time through the database lock table, and different acquisition servers can access multiple databases or different business types of the same database in parallel, avoiding performance waste in the database synchronization process, improving synchronization efficiency, and ensuring accurate data synchronization. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0046] Figure 1 A schematic diagram of the structure of a business system is shown;

[0047] Figure 2 A flowchart of a database synchronization method provided in an embodiment of the present application is shown;

[0048] Figure 3 The interactive flow chart of business data synchronization in the business system provided by the embodiment of the present application is shown;

[0049] Figure 4 A schematic diagram showing the structure of a database synchronization device provided in an embodiment of the present application is shown;

[0050] Figure 5 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0051] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0052] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in this application should have the common meanings understood by technicians in the field to which this application belongs.

[0053] In addition, the terms "first" and "second" etc. are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.

[0054] Figure 2 is a flowchart of a database synchronization method provided in an embodiment of the present application, the method is applied to a collection server of a business system, such as Figure 1 As shown in the figure, the business system mainly includes modules such as console, engine server, collection server, database, terminal, etc. The console and engine server can only be deployed in the headquarters, while the collection server, database, and terminal can be installed and deployed in the headquarters and branches.

[0055] For data security reasons, neither the headquarters nor the branch databases can open port mapping, but the headquarters engine server can open port mapping, that is, the branch terminal business data collected by the branch collection server can only be written to the branch database. The branch collection server can connect to the headquarters engine server, and the branch collection server can synchronize the business data of the branch database to the headquarters database through the headquarters engine server, ultimately enabling the headquarters console to view the business data of the branch terminal through the headquarters database.

[0056] Please refer to Figure 2 The database synchronization method provided by the present application includes the following steps:

[0057] S101, based on the database lock table, compete for the target database according to the preset rules;

[0058] Specifically, the database lock table is a distributed lock table based on a database, and the fields included in the database lock table are: database number, business number, acquisition server number of occupied lock, heartbeat timestamp of occupied lock, acquisition server number of contended lock, heartbeat timestamp of contended lock; wherein each business number corresponds to a business type; occupied lock refers to occupied database lock; contended lock refers to being in competition for database lock, i.e., waiting in line for database lock to be released before occupying. Occupied locks and contended locks need to be marked in the database lock table, i.e., recorded.

[0059] As the running time of the branch terminal increases, the business data will continue to increase, and the number of terminals connected to the branch will also continue to increase. Therefore, the business data of the branch database is synchronized to the headquarters database incrementally using the version number. Each database in the business system corresponds to a version number maintenance table, which records the current version number of the business data corresponding to each business type in the database. When the branch's collection server receives the business data reported by the branch terminal, the version number of each business data can be written as 0 first, and then the collection server thread that occupies the database lock will periodically query the version number of the current business data in the branch database and increment it. The business data with version number 0 is updated to the self-incremented version number, and the version number maintenance table is also updated at the same time.

[0060] S102. After occupying the target database, during the occupation period, if the target database contains new business data reported by the terminal, the current version number of the new business data is queried from the version number maintenance table of the target database and incremented, the version number maintenance table of the target database is updated, and the new business data is synchronized to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database.

[0061] Specifically, the preset rules include:

[0062] First query the records of the database lock table. If the database lock is not occupied by other collection servers, the collection server itself occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0063] If the database lock has been occupied by other acquisition servers, the heartbeat timestamp of the occupied lock is checked. When the difference between the heartbeat time of the occupied lock and the current time exceeds the first time threshold, the current acquisition server occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0064] In actual applications, when the acquisition server of a branch is started, the business data monitoring thread, database lock management thread, and business data synchronization thread will be started. The database management thread will periodically check and maintain the database lock table. First, query the records of the database lock table. If it is found that the database lock table is not occupied by other acquisition servers, the acquisition server itself can occupy the database lock and update the heartbeat timestamp of the occupied lock; if it is found that the database lock has been occupied by other acquisition servers, check the heartbeat timestamp of the occupied lock. When it is found that the difference between the heartbeat time and the current time exceeds the threshold, it means that the acquisition server occupying the lock has been offline. At this time, the current acquisition server can occupy the lock and update the heartbeat timestamp of the occupied lock; if it is found that the database lock has been occupied by the acquisition server itself, update the heartbeat timestamp of the occupied lock to maintain the occupation.

[0065] Specifically, the preset rules also include:

[0066] The calculation formula for the maximum number of locks occupied by each acquisition server is: a = (b / c) + 1;

[0067] Among them, a represents the maximum number of locks occupied by the acquisition server, b represents the number of branch databases in the business system, and c represents the number of branch acquisition servers in the business system.

[0068] Specifically, the preset rules also include:

[0069] If there is no other collection server competing for the database lock, or the difference between the heartbeat time of the competing lock and the current time exceeds the second time threshold, and the number of occupied locks of this collection server plus the number of competing locks does not exceed the maximum number of occupied locks of this collection server, then this collection server is allowed to mark the competing lock and update the heartbeat timestamp of the competing lock. The same collection server cannot mark occupied locks and competing locks at the same time.

[0070] Specifically, the preset rules also include:

[0071] If the number of occupied locks of this acquisition server plus the number of competing locks exceeds the maximum number of occupied locks of this acquisition server, the excess occupied locks or competing locks are released so that other acquisition servers can re-mark the occupied locks or competing locks;

[0072] If the number of locks occupied by this acquisition server exceeds the maximum number of locks occupied by this acquisition server, and there is no other acquisition server competing for the lock, then this acquisition server will keep occupying the lock;

[0073] If the number of occupied locks of this collection server exceeds the maximum number of occupied locks of this collection server, and other collection servers have marked competing locks, this collection server will release the excess occupied locks so that the collection servers marked competing locks can occupy the released database locks first, and clear the competing lock marks after successfully occupying the locks.

[0074] Only the acquisition server that occupies the database lock can connect to the headquarters engine server for incremental synchronization of business data. Only the acquisition server that occupies the database lock can query the version number of the current business data in the branch database in the thread periodically and increment the memory, update the business data with version number 0 to the self-incremented version number, and also update the version number maintenance table. When the headquarters engine server initiates data synchronization to the branch acquisition server that occupies the lock, the branch acquisition server retrieves the incremental business data from the branch database according to the version number of the last synchronization of the headquarters engine server, and then sends the incremental business data to the engine server. After receiving the incremental business data, the engine server writes it to the headquarters database, and finally enables the headquarters console to view and backup the business data of the branch terminal.

[0075] For ease of understanding, this application also provides Figure 3 The interactive flow chart of business data synchronization in the business system shown in the figure. The terminal reports business data, and the collection server synchronizes the business data to the engine server based on the database lock increment.

[0076] It can be seen that the present application introduces a database lock table to ensure the read-write consistency of the same business type in the same database at the same time. Only the branch collection server that competes for the database lock will connect to the headquarters engine server, avoiding performance waste; if there are multiple branch collection servers and multiple branch databases, different branch databases can be accessed concurrently by different branch collection servers for incremental synchronization, avoiding the problem of low efficiency; only the branch collection server that competes for the database lock can obtain the version number from the version number maintenance table of the database and automatically update it to the business data table and the version number maintenance table, ensuring the read-write consistency of the same business type in the same database at the same time, and avoiding the problem of incremental synchronization omissions caused by inconsistent business data version numbers.

[0077] In the database synchronization method provided by the present application, based on the database lock table, the target database is competed according to the preset rules; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database; after occupying the target database, during the occupation period, if the target database has new business data reported by the terminal, the current version number of the new business data is queried from the version number maintenance table of the target database and incremented, the version number maintenance table of the target database is updated, and the new business data is synchronized to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database. Compared with the prior art, the present application ensures the read-write consistency of the same business type of the same database at the same time by introducing a mechanism of database lock table and multi-collection server competition lock, that is, only one collection server occupies the lock and accesses the same business type of the same database at the same time, ensuring data accuracy, and the concurrent work of multiple collection servers can improve efficiency.

[0078] In the above-mentioned embodiment, a method for synchronizing a database is provided, and correspondingly, the present application also provides a device for synchronizing a database. The device for synchronizing a database provided in the embodiment of the present application can implement the above-mentioned method for synchronizing a database, and the device for synchronizing a database can be implemented by software, hardware, or a combination of software and hardware. For example, the device for synchronizing a database can include integrated or separate functional modules or units to execute the corresponding steps in the above-mentioned methods.

[0079] Please refer to Figure 4 As shown, the database synchronization device 10 provided by the present application is applied to a collection server, and includes:

[0080] The competition module 101 is used to compete for the target database according to preset rules based on the database lock table; the database lock table includes: database number, business number, acquisition server number of the occupied lock, heartbeat timestamp of the occupied lock, acquisition server number of the competing lock, and heartbeat timestamp of the competing lock; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database;

[0081] The synchronization module 102 is used to, after occupying the target database, during the occupation period, if the target database contains new business data reported by the terminal, query the current version number of the new business data from the version number maintenance table of the target database and increment it automatically, update the version number maintenance table of the target database, and synchronize the new business data to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database.

[0082] In a possible implementation, the preset rule includes:

[0083] First query the records of the database lock table. If the database lock is not occupied by other collection servers, the collection server itself occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0084] If the database lock has been occupied by other acquisition servers, the heartbeat timestamp of the occupied lock is checked. When the difference between the heartbeat time of the occupied lock and the current time exceeds the first time threshold, the current acquisition server occupies the database lock and updates the heartbeat timestamp of the occupied lock.

[0085] In a possible implementation, the preset rule further includes:

[0086] The calculation formula for the maximum number of locks occupied by each acquisition server is: a = (b / c) + 1;

[0087] Among them, a represents the maximum number of locks occupied by the acquisition server, b represents the number of branch databases in the business system, and c represents the number of branch acquisition servers in the business system.

[0088] In a possible implementation, the preset rule further includes:

[0089] If there is no other collection server competing for the database lock, or the difference between the heartbeat time of the competing lock and the current time exceeds the second time threshold, and the number of occupied locks of this collection server plus the number of competing locks does not exceed the maximum number of occupied locks of this collection server, then this collection server is allowed to mark the competing lock and update the heartbeat timestamp of the competing lock. The same collection server cannot mark occupied locks and competing locks at the same time.

[0090] In a possible implementation, the preset rule further includes:

[0091] If the number of occupied locks of this acquisition server plus the number of competing locks exceeds the maximum number of occupied locks of this acquisition server, the excess occupied locks or competing locks are released so that other acquisition servers can re-mark the occupied locks or competing locks;

[0092] If the number of locks occupied by this acquisition server exceeds the maximum number of locks occupied by this acquisition server, and there is no other acquisition server competing for the lock, then this acquisition server will keep occupying the lock;

[0093] If the number of occupied locks of this collection server exceeds the maximum number of occupied locks of this collection server, and other collection servers have marked competing locks, this collection server will release the excess occupied locks so that the collection servers marked competing locks can occupy the released database locks first, and clear the competing lock marks after successfully occupying the locks.

[0094] The database synchronization device provided in the embodiment of the present application and the database synchronization method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented therein.

[0095] The embodiment of the present application also provides an electronic device corresponding to the method provided in the aforementioned embodiment, and the electronic device can be a mobile phone, a laptop computer, a tablet computer, a desktop computer, etc., to execute the above-mentioned database synchronization method.

[0096] Please refer to Figure 5 , which shows a schematic diagram of an electronic device provided by some embodiments of the present application. Figure 5 As shown, the electronic device 20 includes: a processor 200, a memory 201, a bus 202 and a communication interface 203, and the processor 200, the communication interface 203 and the memory 201 are connected via the bus 202; the memory 201 stores a computer program that can be run on the processor 200, and when the processor 200 runs the computer program, it executes the database synchronization method provided in any of the aforementioned embodiments of the present application.

[0097] The memory 201 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 203 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0098] The bus 202 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 201 is used to store programs, and the processor 200 executes the programs after receiving the execution instruction. The database synchronization method disclosed in any implementation of the embodiment of the present application may be applied to the processor 200, or implemented by the processor 200.

[0099] The processor 200 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 200. The above processor 200 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a readily available programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 201, and the processor 200 reads the information in the memory 201 and completes the steps of the above method in combination with its hardware.

[0100] The electronic device provided in the embodiment of the present application and the database synchronization method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented therein.

[0101] An embodiment of the present application also provides a computer-readable storage medium corresponding to the database synchronization method provided in the aforementioned embodiment, on which a computer program (i.e., a program product) is stored. When the computer program is executed by a processor, it will execute the database synchronization method provided in any of the aforementioned embodiments.

[0102] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.

[0103] The computer-readable storage medium provided in the above-mentioned embodiments of the present application and the database synchronization method provided in the embodiments of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.

[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application, and they should all be included in the scope of the claims and specification of the present application.

Claims

1. A database synchronization method, applied to a collection server of a branch in a business system, wherein the business system also includes an engine server and a database of a headquarters, characterized in that: include: Based on database lock table, compete for the target database according to preset rules; The database lock table includes: database number, business number, acquisition server number of occupied lock, heartbeat timestamp of occupied lock, acquisition server number of competing lock, heartbeat timestamp of competing lock; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database; After occupying the target database, during the occupation period, if the target database contains new business data reported by the terminal, the current version number of the new business data is queried from the version number maintenance table of the target database and incremented automatically, the version number maintenance table of the target database is updated, and the new business data is synchronized to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database.

2. The method according to claim 1, characterized in that The preset rules include: First query the records of the database lock table. If the database lock is not occupied by other collection servers, the collection server itself occupies the database lock and updates the heartbeat timestamp of the occupied lock. If the database lock has been occupied by other acquisition servers, the heartbeat timestamp of the occupied lock is checked. When the difference between the heartbeat time of the occupied lock and the current time exceeds the first time threshold, the current acquisition server occupies the database lock and updates the heartbeat timestamp of the occupied lock.

3. The method according to claim 2, characterized in that The preset rules also include: The calculation formula for the maximum number of locks occupied by each acquisition server is: a = (b / c) + 1; Among them, a represents the maximum number of locks occupied by the acquisition server, b represents the number of branch databases in the business system, and c represents the number of branch acquisition servers in the business system.

4. The method according to claim 3, characterized in that The preset rules also include: If there is no other collection server competing for the database lock, or the difference between the heartbeat time of the competing lock and the current time exceeds the second time threshold, and the number of occupied locks of this collection server plus the number of competing locks does not exceed the maximum number of occupied locks of this collection server, then this collection server is allowed to mark the competing lock and update the heartbeat timestamp of the competing lock. The same collection server cannot mark occupied locks and competing locks at the same time.

5. The method according to claim 3, characterized in that: The preset rules also include: If the number of occupied locks of this acquisition server plus the number of competing locks exceeds the maximum number of occupied locks of this acquisition server, the excess occupied locks or competing locks are released so that other acquisition servers can re-mark the occupied locks or competing locks; If the number of locks occupied by this acquisition server exceeds the maximum number of locks occupied by this acquisition server, and there is no other acquisition server competing for the lock, then this acquisition server will keep occupying the lock; If the number of occupied locks of this collection server exceeds the maximum number of occupied locks of this collection server, and other collection servers have marked competing locks, this collection server will release the excess occupied locks so that the collection servers marked competing locks can occupy the released database locks first, and clear the competing lock marks after successfully occupying the locks.

6. A database synchronization device, applied to a branch acquisition server, characterized in that: include: The competition module is used to compete for the target database according to preset rules based on the database lock table; The database lock table includes: database number, business number, acquisition server number of occupied lock, heartbeat timestamp of occupied lock, acquisition server number of competing lock, heartbeat timestamp of competing lock; each database corresponds to a version number maintenance table, and the version number maintenance table records the current version number of the business data corresponding to each business type in the database; The synchronization module is used to query the current version number of the new business data from the version number maintenance table of the target database and increment it automatically after occupying the target database during the occupation period, if the target database contains new business data reported by the terminal, update the version number maintenance table of the target database, and synchronize the new business data to the engine server of the headquarters, so that the engine server of the headquarters is synchronized to the headquarters database.

7. The device according to claim 6, characterized in that The preset rules include: First query the records of the database lock table. If the database lock is not occupied by other collection servers, the collection server itself occupies the database lock and updates the heartbeat timestamp of the occupied lock. If the database lock has been occupied by other acquisition servers, the heartbeat timestamp of the occupied lock is checked. When the difference between the heartbeat time of the occupied lock and the current time exceeds the first time threshold, the current acquisition server occupies the database lock and updates the heartbeat timestamp of the occupied lock.

8. The device according to claim 7, characterized in that The preset rules also include: The calculation formula for the maximum number of locks occupied by each acquisition server is: a = (b / c) + 1; Among them, a represents the maximum number of locks occupied by the acquisition server, b represents the number of branch databases in the business system, and c represents the number of branch acquisition servers in the business system.

9. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 5 when executing the computer program.

10. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and the computer-readable instructions can be executed by a processor to implement the method according to any one of claims 1 to 5.