WO2023029519A1 - 一种数据同步方法及装置、计算机设备、存储介质 - Google Patents

一种数据同步方法及装置、计算机设备、存储介质 Download PDF

Info

Publication number
WO2023029519A1
WO2023029519A1 PCT/CN2022/088533 CN2022088533W WO2023029519A1 WO 2023029519 A1 WO2023029519 A1 WO 2023029519A1 CN 2022088533 W CN2022088533 W CN 2022088533W WO 2023029519 A1 WO2023029519 A1 WO 2023029519A1
Authority
WO
WIPO (PCT)
Prior art keywords
server
data queue
database
configuration information
data
Prior art date
Application number
PCT/CN2022/088533
Other languages
English (en)
French (fr)
Inventor
王俊
李明
叶正武
Original Assignee
康键信息技术(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 康键信息技术(深圳)有限公司 filed Critical 康键信息技术(深圳)有限公司
Publication of WO2023029519A1 publication Critical patent/WO2023029519A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5083Techniques for rebalancing the load in a distributed system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the technical field of data processing, and in particular to a data synchronization method and device, computer equipment, and storage media.
  • data synchronization tools can be used to synchronize the incremental data of the database to other storage applications to realize the subscription and consumption of incremental data.
  • the inventors found that in the existing method, it is necessary to manually configure the one-to-one connection relationship between each data synchronization tool and the database through a local configuration file. When the configuration of the data synchronization tool or the database is changed, the operation and maintenance is more difficult.
  • the present application provides a data synchronization method and device, computer equipment, and storage media, the main purpose of which is to reduce the difficulty of operation and maintenance of database data synchronization.
  • the embodiment of the present application provides a data synchronization method applied to a data synchronization system.
  • the data synchronization system includes a database, a first server, and a server.
  • the method includes: responding to changes in configuration information of the data synchronization system , to obtain the target configuration information of the data synchronization system; according to the target configuration information, determine the first data queue to be locked from at least one data queue running on the first server, and determine the first data queue to be locked from the data synchronization system Determine the first database to be locked among all the databases; generate a lock request, and send the lock request to the second server, wherein the lock request is used to instruct the second server to be in the first Create the first resource corresponding to the first data queue in the first resource pool corresponding to the database; obtain the resource information of the first resource pool from the second server; judge whether the locking is successful according to the resource information, if If the locking is successful, the first data queue is connected to the first database for data synchronization; if the locking fails, change monitoring is performed on the
  • the embodiment of the present application also proposes a data synchronization device, which is applied to a data synchronization system.
  • the data synchronization system includes a database, a first server, and a second server.
  • the device includes: an acquisition module for responding to Based on the change of the configuration information of the data synchronization system, the target configuration information of the data synchronization system is acquired; the determining module is configured to determine from at least one data queue running on the first server to be locked according to the target configuration information the first data queue, and determine the first database to be locked from all the databases in the data synchronization system; the generation module is used to generate a lock request, wherein the lock request is used to instruct the second server to The first resource corresponding to the first data queue is created in the first resource pool corresponding to the first database; the sending module is configured to send the lock request to the second server; the acquiring module also uses Obtaining the resource information of the first resource pool from the second server; a judging module, configured to judge whether the locking is successful according to the resource information;
  • the embodiment of the present application also proposes a computer device, the computer device includes a memory and a processor, the memory stores a program, and when the program is executed by the processor, the following steps are implemented: in response to changing the configuration information of the data synchronization system, acquiring target configuration information of the data synchronization system; determining the first data queue to be locked from at least one data queue running on the first server according to the target configuration information, And determine the first database to be locked from all the databases in the data synchronization system; generate a lock request, and send the lock request to the second server, wherein the lock request is used to indicate the first
  • the second server creates the first resource corresponding to the first data queue in the first resource pool corresponding to the first database; obtains the resource information of the first resource pool from the second server; according to the resource information Judging whether the locking is successful, if the locking is successful, connect the first data queue to the first database for data synchronization, and if the locking fails, monitor changes to the first resource pool.
  • the present application provides a storage medium for computer-readable storage, the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to Execute the following steps: in response to the change of the configuration information of the data synchronization system, obtain the target configuration information of the data synchronization system; according to the target configuration information, determine from at least one data queue running on the first server to be locked The first data queue of the data synchronization system, and determine the first database to be locked from all databases in the data synchronization system; generate a lock request, and send the lock request to the second server, wherein the lock request It is used to instruct the second server to create the first resource corresponding to the first data queue in the first resource pool corresponding to the first database; obtain resource information of the first resource pool from the second server ; Determine whether the locking is successful according to the resource information, if the locking is successful, connect the first data queue to the first database for data synchronization, and if the locking fails, change the first resource pool monitor.
  • the data synchronization method and device, computer equipment, and storage medium proposed in this application are suitable for a data synchronization system including a database, a first server, and a second server, and can monitor configuration changes of the entire data synchronization system to achieve distributed deployment. It is convenient for horizontal expansion and contraction, and reduces the difficulty of operation and maintenance of the data synchronization system.
  • Fig. 1 is a structural block diagram of a kind of data synchronization system applied in the embodiment of the present application;
  • Fig. 2 is a structural block diagram of a server applied in the embodiment of the present application
  • FIG. 3 is a schematic diagram of data synchronization between a database and a canal instance in the prior art
  • FIG. 4 is a schematic diagram of data synchronization between the database and the first server in the embodiment of the present application.
  • FIG. 5 is a flowchart of a data synchronization method provided in Embodiment 1 of the present application.
  • FIG. 6 is a flowchart of a data synchronization method provided in Embodiment 2 of the present application.
  • FIG. 7 is a structural block diagram of a data synchronization device applied in the embodiment of the present application.
  • the application can be used in numerous general purpose or special purpose computer system environments or configurations. Examples: personal computers, server computers, handheld or portable devices, tablet-type devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer servers, network PCs, minicomputers, mainframe computers, including the above A distributed computing environment for any system or device, and more.
  • This application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer.
  • program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types.
  • the application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network.
  • program modules may be located in both local and remote computer storage media including storage devices.
  • FIG. 1 is a structural block diagram of a data synchronization system applied in the embodiment of the present application.
  • the data synchronization system includes a first server 10 , a database 20 and a second server 30 .
  • the number of the first server 10 and the number of the database 20 may be at least one, which is not specifically limited.
  • the database 20 may be a relational database such as MySQL, Oracle database or Sybase, or a non-relational database such as MongoDB or Hbase, which is not specifically limited.
  • database 20 can adopt binary log (binary log) to record and store information such as the change history of database 20, database incremental backup, recovery and replication (master-slave database replication), thereby being applicable to data synchronization (such as online, offline) Data synchronization between databases), data consumption (such as incremental search based on database table changes) or data desensitization (such as importing online dynamic data to other applications to achieve data desensitization) and other application scenarios.
  • binary log binary log
  • database 20 can adopt binary log (binary log) to record and store information such as the change history of database 20, database incremental backup, recovery and replication (master-slave database replication), thereby being applicable to data synchronization (such as online, offline) Data synchronization between databases), data consumption (such as incremental search based on database table changes) or data desensitization (such as importing online dynamic data to
  • FIG. 2 is a structural block diagram of a server applied in the embodiment of the present application.
  • the server can be an independent server, or it can provide cloud service, cloud database, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, content distribution Network (Content Delivery Network, CDN), and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms.
  • cloud service cloud database, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, content distribution Network (Content Delivery Network, CDN), and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms.
  • the server includes: a memory 11 , a processor 12 , a network interface 13 and a data bus 14 .
  • the memory 11 includes at least one type of readable storage medium, and the at least one type of readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, or a card-type memory.
  • the readable storage medium may be an internal storage unit of the server, such as a hard disk of the server.
  • the readable storage medium can also be an external memory of the server, such as a plug-in hard disk equipped on the server, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, Flash card (Flash Card), etc.
  • the readable storage medium of the memory 11 is generally used to store programs installed in the server and the like.
  • the memory 11 can also be used to temporarily store data that has been output or will be output.
  • Processor 12 can be a central processing unit (Central Processing Unit, CPU) in some embodiments, microprocessor or other data processing chip, is used for running the program code stored in memory 11 or processing data, such as execution program etc., In order to realize the technical solutions provided by the embodiments of the present application.
  • CPU Central Processing Unit
  • the network interface 13 may optionally include standard wired interfaces and wireless interfaces (such as WI-FI interfaces), which are generally used to establish communication connections between the server and other electronic devices.
  • WI-FI interfaces such as WI-FI interfaces
  • the data bus 14 is used to realize connection communication between these components.
  • FIG. 1 only shows a server with components 11-14, but it should be understood that implementation of all of the illustrated components is not required and that more or fewer components may instead be implemented. It can also be understood that the servers shown in FIG. 2 above are applicable to the first server 10 and the second server 30 .
  • the first server 10 and the database 20 in this embodiment may adopt a canal architecture, and then the first server 10 may be a canal server.
  • a backup command (such as a dump command) can be sent to the database 20 through the master-slave replication interaction protocol of the database 20, and then the database 20 pushes the binary log to the first server 10 in response to the backup command, Make the first server 10 obtain and parse the binary log to realize data synchronization.
  • At least one data queue (that is, canal instance) can run on the first server 10, and each data queue can establish connections with different databases. Among them, the data queue can realize: data source access and analysis of the interaction protocol with the database 20; data filtering, distribution, merging and processing; data storage; and incremental subscription and consumption information management.
  • FIG. 3 is a schematic diagram of data synchronization between a database and a canal instance in the prior art.
  • most canal-based active-standby architecture modules are adopted, that is, two canal instances will form an active-standby service group, such as instance A of the active server and instance A of the standby server.
  • a primary and backup service group is only connected to a designated database (or database instance), for example, the primary and secondary service group corresponding to instance A above is only connected to database instance A.
  • the instance of the primary server is serving, the instance of the standby server is only used to report the heartbeat and monitor whether the primary server is abnormal, and does not participate in other services.
  • FIG. 4 is a schematic diagram of data synchronization between the database 20 and the first server 10 in the embodiment of the present application. Compared with the prior art, this application does not use a backup server, and there are no idle nodes. Each instance on the first server 10 can preempt each database 20 to try to establish a connection, thus greatly reducing machine costs and waste of resources.
  • the first server 10 and the database 20 can establish a long connection, and then the newly added database 20 will not affect the established connection relationship between the first server 10 and the database 20, nor will it involve the master and backup Additional connection disconnection and reconnection are generated during switching, which has high availability and avoids repeated consumption.
  • the first server 10, the database 20, and the second server 30 adopt a distributed architecture, such as service registration and discovery models based on transmission control protocol (transmission control protocol, TCP) long connections such as dubbo or kafka.
  • TCP transmission control protocol
  • the second server 30 can adopt a zookeeper server, and the number of the second server 30 can also be at least one, and is deployed in cluster form. That is to say, the first server 10 can be connected to any second server 30 in the cluster, and if the connection is disconnected abnormally, the first server 10 can connect to other second servers 30 in the cluster again.
  • the data synchronization system may also include a configuration center 40.
  • the configuration center 40 may be a service component that uniformly manages configuration information of system applications such as the database 20 and the first server 10 in the data synchronization system, and may be applied to servers, smartphones, etc. , tablet computers, portable computers, desktop computers and other terminal devices with computing functions.
  • the configuration center 40 stores state information, and then sends the configuration information to the first servers 10 in response to the requests of each first server 10, so there is no need to deliberately synchronize the information of each first server 10 , realize the stateless application of the first server 10, have high fault tolerance, and provide the ability of remote configuration management, and realize the manageability of the application configuration under the distributed system.
  • the data synchronization system may also include a subscriber 50.
  • the subscriber 50 and the first server 10 may use a distributed messaging system, such as Rocket MQ, to provide low-latency and highly reliable message publishing and subscription services.
  • the first server 10 can distribute the obtained incremental data to one or more message queues, and then push each message queue to the subscriber corresponding to the topic of the message queue based on the topic corresponding to each subscription task of the subscriber 50 50.
  • the data synchronization system may further include at least one client 60, and the client 60 may be a terminal device with computing functions such as a smart phone, a tablet computer, a portable computer, and a desktop computer.
  • the client 60 can establish a connection with any first server 10 to realize remote data interaction, so as to expand more diverse interactive functions.
  • a data synchronization method disclosed in the embodiment of the present application will be specifically described below. It can be understood that the above data synchronization system is applicable to the data synchronization method in the embodiment of the present application.
  • FIG. 5 is a flowchart of a data synchronization method provided in Embodiment 1 of the present application. As shown in Figure 5, the method includes the following steps:
  • Step S500 In response to the change of the configuration information of the data synchronization system, the first server acquires the target configuration information of the data synchronization system.
  • the configuration center may send a configuration update notification to each first server when the configuration information of the data synchronization system changes, so that the first server sends a configuration acquisition request to the configuration center according to the configuration update notification , the configuration center sends the target configuration information obtained after the configuration information is changed to the first server.
  • Changes to configuration information include but are not limited to: information addition, modification, and deletion.
  • the target configuration information may include database configuration information and first server configuration information.
  • the first server configuration information may include all first servers in the data synchronization system, server information of each first server, data queues running on each first server, and limit information of each data queue (such as database connection upper limit and transaction processing Upper limit value, etc.), database configuration information includes all databases in the data synchronization system, identification information of each database (such as number or name, etc.) and connection information (such as connection domain name, account number and password, etc.), all of which are not specifically limited.
  • the database configuration information can be divided into global configuration information and connection information.
  • the configuration center can store the global configuration information in the first storage path in a preset data format.
  • the global configuration information includes all databases in the database synchronization system and all databases of each database.
  • the preset data format may include but not limited to lists, tuples, or key-value pairs.
  • the connection information of each database is stored in a second storage path corresponding to each database, and the second storage path is related to the identification information of the database. That is to say, when the first server sends a configuration acquisition request, the configuration center may return to the first server the global configuration information read according to the first storage path.
  • the first server can send an information reading request for the identification information to the configuration center according to the identification information of the database to be connected, and then configure The center then determines the corresponding second storage path according to the identification information corresponding to the information read request, and reads the connection information according to the second storage path to return to the first server, and finally makes the first server connect to the database according to the returned connection information .
  • com.pajk.roma.db2.dbinfo ⁇ connect domain name: add two; account: user two; password: psd two ⁇ .
  • connection information ⁇ connection domain name: add one; account number: user one; password: psd one ⁇ .
  • Step S501 The first server determines the first data queue to be locked from at least one data queue running on the first server according to the target configuration information, and determines the first database to be locked from all databases in the data synchronization system .
  • the target configuration information includes the database connection upper limit of each data queue running on the first server, and the method for determining the first database may specifically be:
  • the lock quantity represents the number of databases connected to the data queue.
  • a first data queue to be locked is determined from at least one data queue, and the first data queue satisfies: the number of locks corresponding to the first data queue is less than the upper limit value of the database connection of the first data queue. It can be understood that whenever the data queue on the first server establishes a connection with the database, the corresponding lock quantity of the data queue is increased by one.
  • the target configuration information includes the transaction processing upper limit value of each data queue running on the first server, and the transaction processing upper limit value represents the maximum transaction processing volume of the data queue within a specified time, then
  • the method for determining the first database may specifically be:
  • the current transaction processing capacity corresponding to at least one data queue running on the first server is obtained, and the current transaction processing capacity indicates the current transaction processing volume of the data queue within a specified time, such as transaction processing volume per second (transaction per second, TPS).
  • TPS transaction per second
  • the first data queue to be locked is determined from at least one data queue, and the first data queue satisfies that: the current transaction processing capacity corresponding to the first data queue is smaller than the transaction processing upper limit of the first data queue.
  • the above-mentioned first data queue may also meet the following requirements: the number of locks corresponding to the first data queue is less than the upper limit of the database connection of the first data queue, and the current lock number corresponding to the first data queue The transaction processing capacity is less than the transaction processing upper limit of the first data queue.
  • the aforementioned preset parameters such as the upper limit of database connection, the upper limit of transaction processing, and the specified time can be manually set and adjusted. It can be seen that adding different resource threshold constraints to each data queue will help improve the stability and reliability of the system.
  • the first database to be locked may satisfy: the first data queue has not created resources in the first resource pool corresponding to the first database; or, the first database has not been successfully locked, and no Be specific.
  • Step S502 the first server generates a lock request, and sends the lock request to the second server.
  • the lock request is used to instruct the second server to create the first resource corresponding to the first data queue in the first resource pool corresponding to the first database.
  • the resource pools corresponding to each database are used to store the resources created by different data queues.
  • the first resource pool can be a queuing list
  • the first resource can be a node created by the first queuing list in the queuing list.
  • the nodes here It can be a temporary node, a permanent node, a numbered node, or a temporary numbered node, etc., without limitation.
  • the temporary node can be cleared when the first server and the second server are disconnected, the permanent node is a persistent node that is actively deleted by the first server, and the numbered node is a persistent node that automatically increases the sequence number.
  • a node is a temporary node with a temporary auto-increment number.
  • the step of the second server creating the first resource in the first resource pool may specifically be:
  • the second server first tries to call the first resource pool corresponding to the first database. If the first resource pool does not exist, the second server creates a first resource pool corresponding to the first database.
  • the second server uses the preset starting number (such as 000001) as the sorting number corresponding to the first data queue, and generates the resources of the first data queue according to the database code corresponding to the first database and the sorting number corresponding to the first data queue code, wherein the database code represents a storage path corresponding to the first database, and the resource code represents a resource path for locating the first resource.
  • the second server creates the first resource in the first resource pool according to the resource code of the first data queue. Taking the queuing list of a first database shown in Table 1 below as an example, node 1 may be the first resource corresponding to the first data queue.
  • the second server can determine the resource with the largest sort number from the first resource pool, and then according to the resource corresponding to the resource with the largest sort number A sorting number assigns a sorting number to the first data queue to obtain a second sorting number, so that the second sorting number is greater than the first sorting number. Combine the database code corresponding to the first database and the second sorting number to generate the resource code of the first data queue, and create the first resource in the first resource pool according to the resource code.
  • Step S503 the first server acquires resource information of the first resource pool from the second server.
  • the resource information of the first resource pool may include, but not limited to, all resources in the first resource pool and the sort numbers (or resource codes) corresponding to each resource.
  • Step S504 The first server judges whether the locking is successful according to the resource information, if yes, execute step S505, if not, execute step S506.
  • step S504 may specifically be: according to the resource information, determine the sequence number of each resource in the first resource pool, and the sequence number is generated according to the order in which the resources are created in the first resource pool. Judging whether the sorting number of the first resource has the smallest value among the sorting numbers of all resources in the first resource pool, if so, determine that the locking is successful, and if not, determine that the locking has failed.
  • Table 1 since the sorting number "000001" of the newly added node 1 has the smallest value among the sorting numbers of the existing resources in the first resource pool, the first server can determine that the first data queue is the first database at this time. Locking succeeded.
  • the first server determines that the first data queue is right for the first Failed to lock the database. It can be seen that the resources in the resource pool are sequentially numbered, so that each data queue seizes the resources in the resource pool in a certain order, and it can ensure that the database is always only connected to one data queue.
  • Step S505 the first server connects the first data queue to the first database for data synchronization.
  • step S505 may specifically be: the first server sends a backup command to the first database, so as to acquire incremental data returned by the first database in response to the backup command. After that, the first server sends the incremental data to the subscriber, and completes an incremental data synchronization after receiving the confirmation information returned by the subscriber.
  • Step S506 The first server monitors changes to the first resource pool.
  • the first server can use a monitoring mechanism (such as a zookeeper watch mechanism) to monitor changes to the first resource pool, and when the resources successfully locked in the first resource pool are released, the second server can send a notification To the first server, so that the first server obtains the resource information of the first resource pool from the second server again, so as to determine whether the locking is successful.
  • a monitoring mechanism such as a zookeeper watch mechanism
  • steps S501 to S506 may also be executed in a loop until there is no first data queue to be locked on the first server, or, for the first data queue, there is no lock-to-be corresponding to the first data queue.
  • the first database so the connection resources of each data queue and database can be utilized most efficiently.
  • FIG. 6 is a flowchart of the data synchronization method provided in Embodiment 2 of the present application. As shown in Figure 6, the method includes the following steps:
  • Step S600 In response to the change of the configuration information of the data synchronization system, the first server acquires the target configuration information of the data synchronization system.
  • Step S601 the first server acquires stored local configuration information.
  • the local configuration information is the configuration information obtained from the data synchronization system when the configuration information of the data synchronization system was changed last time.
  • the local configuration information refer to the target configuration information, and details will not be repeated.
  • Step S602 the first server compares the target configuration information with the local configuration information, and obtains a comparison result.
  • Step S603 When the comparison result includes a new database or any data queue is deleted, the first server determines the first data queue to be locked from at least one data queue running on the first server according to the target configuration information , and determine the first database to be locked from all the databases in the data synchronization system.
  • the first server can determine the target database connected to the deleted data queue, and send the deleted data queue pair to the release of the target database to the second server ask.
  • the second server deletes the resource corresponding to the deleted data queue from the resource pool of the target database according to the release request, and completes resource release.
  • step S603 the following steps may also be included:
  • the comparison result includes that the second database is deleted
  • a release request of the second data queue to the second database is sent to the second server, and the second data queue is sent to the second server.
  • the second server can delete the second resource created by the second data queue from the second resource pool corresponding to the second database according to the release request; queue, then send the third data queue to the second server a monitor cancel request for the second database, and the monitor cancel request is used to indicate that the second server can delete the first database created by the third data queue from the second resource pool according to the monitor cancel request.
  • the comparison result includes that the third database is modified, and the fourth data queue connected to the third database is running on the first server, then send the fourth data queue to the second server.
  • Re-lock request According to the relock request, the second server deletes the fourth resource created by the fourth data queue from the third resource pool corresponding to the third database, and then creates a new fourth resource for the fourth data queue in the third resource pool.
  • Step S604 The first server determines the identification information of the first database according to the configuration information of all databases in the data synchronization system.
  • the first server may obtain the code corresponding to the first database from the configuration information of each database.
  • Step S605 the first server acquires the set monitoring object and trigger event type.
  • both the listening object and the triggering event type can be manually set and adjusted, and the listening object can be: the first resource pool corresponding to the first database; or, the first data queue is created in the first resource pool or, resources that are successfully locked in the first resource pool; or, one or more resources in the first resource pool whose sequence number is before the resource created by the first data queue, which is not specifically limited.
  • the types of triggering events may include, but are not limited to: deletion of the listening object, content change of the listening object, and the like.
  • Step S606 The first server generates a lock request in combination with the identification information, the listening object, and the trigger event type, and sends the lock request to the second server.
  • the second server may determine the first resource pool corresponding to the first database according to the identification information corresponding to the lock request, thereby creating the first resource pool in the first resource pool.
  • the second server may also generate a listener according to the listening object corresponding to the lock request and the type of the triggering event to monitor the first resource pool for changes.
  • the second server uses the listener to listen to the trigger event that meets the trigger event type from the listener object in the first resource pool
  • the second server When the second server uses the listener to listen to the trigger event that meets the trigger event type from the listener object in the first resource pool, the second server generates a change notification and sends the change notification to the first server, realizing effective resource monitoring
  • the mechanism can reflect the connection change of the database through the change of the resource pool, and feed back the connection change of the database to the first server in time, so that the first server can dynamically preempt and lock the resource pool.
  • the change notification may include a notification status, a trigger event type, and a resource path corresponding to the trigger event, etc., and the notification status indicates the connection status between the first server and the second server (such as normal connection, connection disconnection, or session failure, etc.).
  • the first server when the first server generates the lock request, it may also establish a monitoring relationship between the first data queue and the corresponding monitoring object and trigger event type, and store the monitoring relationship. Based on this, each time the first server receives the change notification sent by the second server, it can match the change notification with the stored monitoring relationship, and then determine the data queue on the first server that responds to this change according to the matching monitoring relationship .
  • Step S607 the first server acquires resource information of the first resource pool from the second server.
  • Step S608 The first server judges whether the locking is successful according to the resource information, if yes, execute step S609, if not, execute steps S610 to S611.
  • Step S609 the first server connects the first data queue to the first database for data synchronization.
  • Step S610 the first server detects the change notification sent by the second server.
  • Step S611 If a change notification is received, continue to execute step S607.
  • steps S600, S603, S606 to S609 in this embodiment reference may also be made to the description of steps S500 to S506 in the first embodiment above, and details are not repeated here.
  • the first server may also receive a processing request (such as an HTTP request) sent by the client, and perform interactive processing according to the processing request to obtain a processing result, and then return the processing result to the client.
  • a processing request such as an HTTP request
  • the processing request may be a query request, and the first server may obtain the instance identification information (or first server identification information) specified by the query request.
  • the first server queries the database information connected to the target data queue according to the instance identification information (or the first server identification information) as a processing result.
  • the target data queue is a data queue matching the instance identification information
  • the instance identification information includes ip address or serial number, etc.
  • the database information includes but not limited to the number of databases and the name of the database.
  • the first server may query the data queue connected to the target database according to the database information specified in the query request as the processing result.
  • the target database is a database matching the specified database information.
  • the processing request may be an intervention request
  • the first server may obtain the fifth data queue and the fourth database specified by the intervention request according to the intervention request, and send the fifth data queue to the fourth database to the second server.
  • the second server deletes the resource created by the fifth data queue from the resource pool corresponding to the fourth database.
  • FIG. 7 is a structural block diagram of a data synchronization device applied in the embodiment of the present application.
  • the data synchronization device 700 includes:
  • An acquisition module 710 configured to acquire target configuration information of the data synchronization system in response to changes in the configuration information of the data synchronization system;
  • the determination module 720 is configured to determine the first data queue to be locked from at least one data queue running on the first server according to the target configuration information, and determine the first database to be locked from all databases in the data synchronization system ;
  • a generating module 730 configured to generate a lock request, where the lock request is used to instruct the second server to create the first resource corresponding to the first data queue in the first resource pool corresponding to the first database;
  • a sending module 740 configured to send a lock request to the second server
  • the obtaining module 710 is further configured to obtain resource information of the first resource pool from the second server;
  • a judging module 750 configured to judge whether the locking is successful according to the resource information
  • a synchronization module 760 configured to connect the first data queue to the first database to perform data synchronization when the locking is successful
  • the monitoring module 770 is configured to perform change monitoring on the first resource pool when locking fails.
  • the embodiment of the present application also provides a computer device, the computer device includes a memory and a processor, a program is stored in the memory, and the above data synchronization method is implemented when the program is executed by the processor.
  • the embodiment of the present application also provides a storage medium for computer-readable storage, the storage medium stores one or more programs, and one or more programs can be executed by one or more processors to implement the above data synchronization method .
  • the storage medium may be non-volatile or volatile, which is not specifically limited.
  • the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be composed of several physical components. Components cooperate to execute.
  • Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit .
  • a processor such as a central processing unit, digital signal processor, or microprocessor
  • Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media).
  • computer storage media includes both volatile and nonvolatile media implemented in any method or technology for storage of information, such as computer readable instructions, data structures, program modules, or other data. permanent, removable and non-removable media.
  • Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cartridges, tape, magnetic disk storage or other magnetic storage devices, or can Any other medium used to store desired information and which can be accessed by a computer.
  • communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种数据同步方法及装置、计算机设备、存储介质,应用于包括数据库、第一服务器和第二服务器的数据同步系统,该方法包括:响应于数据同步系统配置信息的变更,获取数据同步系统的目标配置信息。根据目标配置信息,从第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所有数据库中确定待加锁的第一数据库。向第二服务器发送加锁请求,使得第二服务器在第一数据库的第一资源池中创建第一数据队列对应的第一资源。从第二服务器获取第一资源池的资源信息以判断是否加锁成功,若加锁成功,将第一数据队列与第一数据库连接,否则,对第一资源池进行变更监听,从而动态调整第一服务器上数据队列与数据库的连接,降低系统运维难度。

Description

一种数据同步方法及装置、计算机设备、存储介质
本申请要求于2021年8月30日提交中国专利局、申请号为2021110076986,发明名称为“一种数据同步方法及装置、计算机设备、存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及数据处理技术领域,具体涉及一种数据同步方法及装置、计算机设备、存储介质。
背景技术
目前的数据库增量日志解析系统中,可以利用数据同步工具将数据库的增量数据同步到其他的存储应用,实现增量数据的订阅和消费。但是,发明人发现,现有方式下,需要通过本地配置文件人为配置各个数据同步工具与数据库的一一连接关系,当数据同步工具或数据库发生配置变更时,运维难度较大。
技术问题
本申请提供一种数据同步方法及装置、计算机设备、存储介质,其主要目的在于降低数据库数据同步的运维难度。
技术解决方案
第一方面,本申请实施例提供了一种数据同步方法,应用于数据同步系统,所述数据同步系统包括数据库、第一服务器和服务器,所述方法包括:响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;生成加锁请求,并向第二服务器发送所述加锁请求,其中,所述加锁请求用于指示所述第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;从所述第二服务器获取所述第一资源池的资源信息;根据所述资源信息判断是否加锁成功,若加锁成功,将所述第一数据队列与所述第一数据库连接以进行数据同步,若加锁失败,对所述第一资源池进行变更监听。
第二方面,本申请实施例还提出了一种数据同步装置,应用于数据同步系统,所述数据同步系统包括数据库、第一服务器和第二服务器,所述装置包括:获取模块,用于响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;确定模块,用于根据 所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;生成模块,用于生成加锁请求,其中,所述加锁请求用于指示第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;发送模块,用于向所述第二服务器发送所述加锁请求;所述获取模块,还用于从所述第二服务器获取所述第一资源池的资源信息;判断模块,用于根据所述资源信息判断是否加锁成功;同步模块,用于在加锁成功时,将所述第一数据队列与所述第一数据库连接以进行数据同步;监听模块,用于在加锁失败时,对所述第一资源池进行变更监听。
第三方面,本申请实施例还提出了一种计算机设备,所述计算机设备包括存储器和处理器,所述存储器上存储有程序,所述程序被所述处理器执行时实现如下步骤:响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;生成加锁请求,并向第二服务器发送所述加锁请求,其中,所述加锁请求用于指示所述第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;从所述第二服务器获取所述第一资源池的资源信息;根据所述资源信息判断是否加锁成功,若加锁成功,将所述第一数据队列与所述第一数据库连接以进行数据同步,若加锁失败,对所述第一资源池进行变更监听。
第四方面,本申请提供了一种存储介质,用于计算机可读存储,所述存储介质存储有一个或者多个程序,所述一个或者多个程序可被一个或者多个处理器执行,以执行以下步骤:响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;生成加锁请求,并向第二服务器发送所述加锁请求,其中,所述加锁请求用于指示所述第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;从所述第二服务器获取所述第一资源池的资源信息;根据所述资源信息判断是否加锁成功,若加锁成功,将所述第一数据队列与所述第一数据库连接以进行数据同步,若加锁失败,对所述第一资源池进行变更监听。
有益效果
本申请提出的数据同步方法及装置、计算机设备、存储介质,适用于包括数据库、第一服务器和第二服务器的数据同步系统,能够监听整个数据同步系统的配置变更,实现分布式部署的同时,便于水平扩缩容,降低了对数据同步系统的运维难度。
附图说明
图1是本申请实施例所应用的一种数据同步系统的结构框图;
图2是本申请实施例所应用的一种服务器的结构框图;
图3是现有技术中数据库与canal实例进行数据同步的示意图;
图4是本申请实施例中数据库与第一服务器进行数据同步的示意图;
图5是本申请实施例一提供的数据同步方法的流程图;
图6是本申请实施例二提供的数据同步方法的流程图;
图7是本申请实施例所应用的一种数据同步装置的结构框图。
本发明的实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
在后续的描述中,使用用于表示元件的诸如“模块”、“部件”或“单元”的后缀仅为了有利于本申请的说明,其本身没有特有的意义。因此,“模块”、“部件”或“单元”可以混合地使用。
本申请可用于众多通用或专用的计算机系统环境或配置中。例如:个人计算机、服务器计算机、手持设备或便携式设备、平板型设备、多处理器系统、基于微处理器的系统、置顶盒、可编程的消费服务器、网络PC、小型计算机、大型计算机、包括以上任何系统或设备的分布式计算环境等等。本申请可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本申请,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。
本申请提供一种数据同步方法,应用于一种数据同步系统。参照图1所示,图1是本申请实施例所应用的一种数据同步系统的结构框图。该数据同步系统包括第一服务器10、数据库20和第二服务器30。其中,第一服务器10和数据库20的数目均可以是至少一个,不做具体限定。
在本实施例中,数据库20可以是MySQL、Oracle数据库或Sybase等关系型数据库,也可以是MongoDB或Hbase等非关系型数据库,对此不做具体限定。具体的,数据库20可以采用二进制日志(binary log)记录并存储数据库20的变更历史、数据库增量备份、恢复和复制(主从数据库的复制)等信息,从而适用于数据同步(比如在线、离线数据库之间的数据同步操作)、数据消费(比如根据数据库表的变化实现增量搜索)或者数据脱敏(比如将线上动态数据导入到其他应用以实现数据脱敏)等多种应用场景。
参照图2所示,图2是本申请实施例所应用的一种服务器的结构框图。
在本实施例中,服务器可以是独立的服务器,也可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、内容分发网络(Content Delivery Network,CDN)、以及大数据和人工智能平台等基础云计算服务的云服务器。
该服务器包括:存储器11、处理器12、网络接口13及数据总线14。
存储器11包括至少一种类型的可读存储介质,至少一种类型的可读存储介质可为如闪存、硬盘、多媒体卡、卡型存储器等的非易失性存储介质。在一些实施例中,可读存储介质可以 是服务器的内部存储单元,例如该服务器的硬盘。在另一些实施例中,可读存储介质也可以是服务器的外部存储器,例如服务器上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。
在本实施例中,存储器11的可读存储介质通常用于存储安装于服务器中的程序等。存储器11还可以用于暂时地存储已经输出或者将要输出的数据。
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU),微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如执行程序等,以实现本申请实施例所提供的技术方案。
网络接口13可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该服务器与其他电子设备之间建立通信连接。
数据总线14用于实现这些组件之间的连接通信。
图1仅示出了具有组件11-14的服务器,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。还可以理解的是,上述图2所示的服务器可适用于第一服务器10和第二服务器30。
具体的,本实施例中的第一服务器10和数据库20可以采用canal架构,则第一服务器10可以是canal服务器。第一服务器10与数据库20建立连接时,可以通过数据库20的主从复制交互协议向数据库20发送备份指令(比如dump指令),则数据库20响应于备份指令将二进制日志推送给第一服务器10,使得第一服务器10获得并解析二进制日志以实现数据同步。第一服务器10上可以运行有至少一个数据队列(也即canal实例),而每个数据队列可与不同数据库建立连接。其中,数据队列可实现:数据源接入,并解析与数据库20的交互协议;数据过滤、分发、归并及加工;数据存储;以及,增量订阅与消费信息管理。
如图3所示,图3是现有技术中数据库与canal实例进行数据同步的示意图。现有技术中,大多采用基于canal的主备架构模块,即两个canal实例会组成一个主备服务组,比如主服务端的实例A和备服务端的实例A。并且,一个主备服务组只连接于指定的一个数据库(或数据库实例),比如上述实例A对应的主备服务组只与数据库实例A连接。当主服务端的实例服务时,备服务端的实例只用于上报心跳并监听主服务端是否异常,不参与其他服务,而当主服务端异常时,备服务端的实例才会接管,导致了一定的资源冗余。如图4所示,图4是本申请实施例中数据库20与第一服务器10进行数据同步的示意图。相比于现有技术,本申请不采用备服务端,没有闲置节点,第一服务器10上的每个实例均可抢占每个数据库20以尝试建立连接,因此大大减少了机器成本和资源浪费。更具体的,本申请中,第一服务器10与数据库20可以建立长连接,则新增数据库20不会影响已建立的第一服务器10和数据库20之间的连接关系,也不会涉及主备切换时产生额外的连接断开与重连,具备高可用性,避免重复消费。
具体的,第一服务器10、数据库20和第二服务器30采用分布式架构,比如dubbo或kafka等基于传输控制协议(transmission control protocol,TCP)长连接的服务注册及发现模型。其中,第二服务器30可以采用zookeeper服务器,第二服务器30的数目也可以是至少 一个,并以集群形式部署。也就是说,第一服务器10可以与集群中任一第二服务器30连接,如果连接异常断开,则第一服务器10可再次连接集群中其他第二服务器30。
可选的,该数据同步系统还可以包括配置中心40,配置中心40可以是统一管理数据同步系统中数据库20和第一服务器10等系统应用的配置信息的服务组件,可应用于服务器、智能手机、平板电脑、便携计算机、桌上型计算机等具有运算功能的终端设备。用户在配置中心40进行配置更新,则配置中心40存放有状态信息,再通过响应各个第一服务器10的请求向第一服务器10下发配置信息,故无需特意对各个第一服务器10进行信息同步,实现第一服务器10的无状态应用,容错性高,且提供了远程管理配置的能力,实现分布式系统下应用配置的可管理性。
可选的,该数据同步系统还可以包括订阅端50,订阅端50和第一服务器10可采用分布式消息系统,比如Rocket MQ,从而提供低延时和高可靠的消息发布与订阅服务。第一服务器10可以将获得的增量数据分发到一个或多个消息队列中,再基于订阅端50的各个订阅任务对应的主题,将各个消息队列推送到与消息队列的主题所对应的订阅端50。
可选的,该数据同步系统还可以包括至少一个客户端60,客户端60可以是智能手机、平板电脑、便携计算机、桌上型计算机等具有运算功能的终端设备。客户端60可以与任一第一服务器10建立连接以实现远程数据交互,便于拓展更加多样化的交互功能。
下面对本申请实施例公开的一种数据同步方法进行具体说明。可以理解的是,上述数据同步系统适用于本申请实施例中的数据同步方法。
实施例一
如图5所示,图5是本申请实施例一提供的数据同步方法的流程图。如图5所示,该方法包括如下步骤:
步骤S500:响应于数据同步系统配置信息的变更,第一服务器获取数据同步系统的目标配置信息。
在本申请实施例中,具体的,可以由配置中心在数据同步系统的配置信息发生变更时,向各个第一服务器发送配置更新通知,使得第一服务器根据配置更新通知向配置中心发送配置获取请求,则配置中心将配置信息变更后得到的目标配置信息下发给第一服务器。配置信息发生变更的情况包括但不限于:信息增加、修改和删减等。目标配置信息可以包括数据库配置信息和第一服务器配置信息。第一服务器配置信息可以包括数据同步系统中所有第一服务器、各个第一服务器的服务器信息、各个第一服务器上运行的数据队列以及各个数据队列的限制信息(比如数据库连接上限值和事务处理上限值等),数据库配置信息包括数据同步系统中所有数据库、各个数据库的识别信息(比如编号或名称等)及连接信息(比如连接域名、账号及密码等),均不做具体限定。
可选的,数据库配置信息可分为全局配置信息和连接信息,配置中心可以以预设数据格式将全局配置信息存储至第一存储路径,全局配置信息包括数据库同步系统中所有数据库以及各个数据库的识别信息,预设数据格式可以包括但不限于列表、元组或键值对等。以及,将各个数据库的连接信息存储至各个数据库对应的第二存储路径,第二存储路径与数据库的 识别信息相关。也就是说,当第一服务器发送配置获取请求,配置中心可以先向第一服务器返回按照第一存储路径读取到的全局配置信息。而当第一服务器确定与任一数据库建立连接(也即加锁成功),则第一服务器可以根据待连接的数据库的识别信息,向配置中心发送对该识别信息的信息读取请求,则配置中心再按照信息读取请求对应的识别信息确定相应的第二存储路径,并按照该第二存储路径读取连接信息以返回给第一服务器,最终使得第一服务器根据返回的连接信息进行数据库连接。
示例性的,配置中心存储的全局配置信息可以为数据库信息列表,即:com.pajk.roma.dbinfos=["db1","db2"]。易知存在两个数据库,这两个数据库的编号分别为“db1”和“db2”。假设根据两个数据库各自的编号,还可获得各个数据库的连接信息,即:
com.pajk.roma.db1.dbinfo={连接域名:add one;账号:user one;密码:psd one},
com.pajk.roma.db2.dbinfo={连接域名:add two;账号:user two;密码:psd two}。
以编号“db1”为例,当配置中心接收到对“db1”的信息读取请求,则可确定“db1”对应的第二存储路径“com.pajk.roma.db1.dbinfo”,再按照第二存储路径“com.pajk.roma.db1.dbinfo”,读取到连接信息:{连接域名:add one;账号:user one;密码:psd one}。
步骤S501:第一服务器根据目标配置信息,从第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从数据同步系统的所有数据库中确定待加锁的第一数据库。
在一种可选的实施方式中,目标配置信息包括第一服务器上运行的各个数据队列的数据库连接上限值,第一数据库的确定方式具体可以为:
获取第一服务器上运行的至少一个数据队列各自对应的加锁数量,加锁数量表示数据队列已连接的数据库数量。从至少一个数据队列中确定待加锁的第一数据队列,第一数据队列满足:第一数据队列对应的加锁数量小于第一数据队列的数据库连接上限值。可以理解,每当第一服务器上的数据队列与数据库建立连接,则该数据队列对应的加锁数量加一。
在另一种可选的实施方式中,目标配置信息包括第一服务器上运行的各个数据队列的事务处理上限值,事务处理上限值表示数据队列在指定时间内的最大事务处理量,则第一数据库的确定方式具体也可以为:
获取第一服务器上运行的至少一个数据队列各自对应的当前事务处理能力,当前事务处理能力表示数据队列当前在指定时间内的事务处理量,比如每秒事务处理量(transaction per second,TPS)。从至少一个数据队列中确定待加锁的第一数据队列,第一数据队列满足:第一数据队列对应的当前事务处理能力小于第一数据队列的事务处理上限值。
在又一种可选的实施方式中,上述第一数据队列也可同时满足:第一数据队列对应的加锁数量小于第一数据队列的数据库连接上限值,且第一数据队列对应的当前事务处理能力小于第一数据队列的事务处理上限值。
可以理解,上述数据库连接上限值、事务处理上限值和指定时间等预设参数均可由人为设定及调整。可见,对各个数据队列增设不同的资源阈值限制条件,有利于改善系统的稳定 性和可靠性。
在本申请实施例中,待加锁的第一数据库可以满足:第一数据队列未在第一数据库对应的第一资源池中创建资源;或者,第一数据库未被加锁成功,对此不做具体限定。
步骤S502:第一服务器生成加锁请求,并向第二服务器发送加锁请求。
在本申请实施例中,加锁请求用于指示第二服务器在第一数据库对应的第一资源池中创建第一数据队列对应的第一资源。各个数据库对应的资源池用于存放不同数据队列创建的资源,具体的,第一资源池可以是排队列表,而第一资源可以是第一排队列表在排队列表中创建的节点,此处的节点可以是临时节点、永久节点、有编号节点或临时有编号节点等,不做限定。其中,临时节点可在第一服务器和第二服务器断开连接时被清除,永久节点是由第一服务器主动删除的持久化节点,有编号节点是自动增加顺序编号的持久化节点,临时有编号节点是临时自动增加编号的临时节点。
一些可选的实施方式中,第二服务器在第一资源池创建第一资源的步骤具体可以为:
第二服务器先尝试调用第一数据库对应的第一资源池。若第一资源池不存在,则第二服务器新建第一数据库对应的第一资源池。第二服务器将预设的起始编号(比如000001)作为第一数据队列对应的排序编号,并根据第一数据库对应的数据库编码和第一数据队列对应的排序编号,生成第一数据队列的资源编码,其中,数据库编码表示第一数据库对应的存储路径,资源编码表示用于定位第一资源的资源路径。之后,第二服务器根据第一数据队列的资源编码在第一资源池中创建第一资源。以下表1所示的一种第一数据库的排队列表为例,节点1可以是第一数据队列对应的第一资源。
表1 第一数据库的排队列表一
Figure PCTCN2022088533-appb-000001
或者,调用第一数据库对应的第一资源池之后,若获得第一资源池,则第二服务器可以从第一资源池中确定排序编号最大的资源,再根据该排序编号最大的资源对应的第一排序编号为第一数据队列分配排序编号,得到第二排序编号,使得第二排序编号大于第一排序编号。结合第一数据库对应的数据库编码和第二排序编号,生成第一数据队列的资源编码,并根据资源编码在第一资源池中创建第一资源。以下表2所示的另一种第一数据库的排队列表为例,假设该排队列表已包含下表节点1、2和3,可知排序编号最大的节点为节点3,则第一排序编号为“000003”。假设第二排序编号为第一排序编号加一,则第二服务器在该排队列表中为第一数据队列创建下图中的节点4。
表2 第一数据库的排队列表二
Figure PCTCN2022088533-appb-000002
Figure PCTCN2022088533-appb-000003
步骤S503:第一服务器从第二服务器获取第一资源池的资源信息。
在本申请实施例中,第一资源池的资源信息可以包括但不限于第一资源池中的所有资源以及各个资源对应的排序编号(或资源编码)。
步骤S504:第一服务器根据资源信息判断是否加锁成功,若是,执行步骤S505,若否,执行步骤S506。
在一种可选的实施方式中,步骤S504具体可以为:根据资源信息,确定第一资源池内各个资源的排序编号,排序编号根据资源在第一资源池中的创建次序所生成。判断第一资源的排序编号是否在第一资源池内所有资源的排序编号中取值最小,若是,则判定加锁成功,若否,则判定加锁失败。以表1为例,由于新增的节点1的排序编号“000001”在第一资源池内已有资源的排序编号中取值最小,故第一服务器此时可判定第一数据队列对第一数据库加锁成功。而以表2为例,由于新增的节点4的排序编号“000004”在第一资源池内已有资源的排序编号中取值并非最小,故第一服务器此时判定第一数据队列对第一数据库加锁失败。可见,对资源池中的资源进行有序编号,使得各个数据队列按照一定先后次序抢占资源池中的资源,能够保证数据库始终只与一个数据队列建立连接。
步骤S505:第一服务器将第一数据队列与第一数据库连接以进行数据同步。
在本申请实施例中,步骤S505具体可以为:第一服务器向第一数据库发送备份指令,从而获取第一数据库响应于备份命令返回的增量数据。之后,第一服务器再将增量数据发送给订阅端,并在接收到订阅端返回的确认信息后,完成一次增量数据同步。
步骤S506:第一服务器对第一资源池进行变更监听。
在本申请实施例中,第一服务器可以采用监听机制(比如zookeeper watch机制)对第一资源池进行变更监听,当第一资源池中加锁成功的资源被释放,则第二服务器可以发送通知给第一服务器,使得第一服务器重新从第二服务器获取第一资源池的资源信息,以判断是否加锁成功。
可选的,还可以循环执行步骤S501至步骤S506,直到第一服务器上不存在待加锁的第一数据队列,或者,针对第一数据队列,不存在与第一数据队列对应且待加锁的第一数据库,故能够最高效化地利用各个数据队列和数据库的连接资源。
可见,实施上述方法实施例,能够监听整个数据同步系统的配置变更,并结合配置变更情况适应性地采取相应的负载分配方式,即动态调整各个第一服务器上数据队列与数据库的连接,无需人为配置,故各个数据队列可以灵活抢占各个数据库的资源池,并根据资源池的资源创建情况分析是否加锁成功,加锁成功即建立连接,加锁失败则继续对资源池进行变更 监听以等待下一次加锁机会,从而在实现分布式部署的同时,便于水平扩缩容,降低了对数据同步系统的运维难度。
实施例二
如图6所示,图6是本申请实施例二提供的数据同步方法的流程图。如图6所示,该方法包括如下步骤:
步骤S600:响应于数据同步系统配置信息的变更,第一服务器获取数据同步系统的目标配置信息。
步骤S601:第一服务器获取存储的本地配置信息。
在本申请实施例中,本地配置信息为上一次数据同步系统的配置信息发生变更时对数据同步系统获取到的配置信息,对本地配置信息的具体描述可参照目标配置信息,不做赘述。
步骤S602:第一服务器将目标配置信息与本地配置信息进行对比,得到对比结果。
步骤S603:在对比结果包括新增数据库或者任一数据队列被删除的情况下,第一服务器根据目标配置信息,从第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从数据同步系统的所有数据库中确定待加锁的第一数据库。
也就是说,当新增数据库或任一数据队列被删除时,数据同步系统中存在空闲的连接资源,故此时适合重新对各个仍具备加锁条件的数据队列进行动态分配。具体的,若第一服务器上运行有被删除的数据队列,则第一服务器可以确定与被删除的数据队列连接的目标数据库,并向第二服务器发送被删除的数据队列对与目标数据库的释放请求。第二服务器根据释放请求从目标数据库的资源池中删去上述被删除的数据队列所对应的资源,完成资源释放。
在一些可选的实施方式中,步骤S603之后,还可以包括以下步骤:
在对比结果包括第二数据库被删除的情况下,当第一服务器上运行有与第二数据库连接的第二数据队列,则向第二服务器发送第二数据队列对第二数据库的释放请求,第二服务器可以根据释放请求从第二数据库对应的第二资源池中删去第二数据队列创建的第二资源;或者,当第一服务器上运行有对第二资源池进行变更监听的第三数据队列,则向第二服务器发送第三数据队列对第二数据库的监听取消请求,监听取消请求用于指示第二服务器可以根据监听取消请求从第二资源池中删去第三数据队列创建的第三资源。
和/或,在对比结果包括第三数据库被修改的情况下,且第一服务器上运行有与第三数据库连接的第四数据队列,则向第二服务器发送第四数据队列对第三数据库的重加锁请求。第二服务器根据重加锁请求,从第三数据库对应的第三资源池中删除第四数据队列创建的第四资源,再在第三资源池中为第四数据队列创建新的第四资源。
可见,通过目标配置信息和本地配置信息的对比,实现对配置信息变化的具体分析,并结合多种配置变化适应性地调整数据队列与数据库的连接,具备更加灵活的负载均衡效果。
步骤S604:第一服务器根据数据同步系统中所有数据库的配置信息,确定第一数据库的识别信息。
比如,第一服务器可以从各个数据库的配置信息中获得第一数据库所对应的编码。
步骤S605:第一服务器获取设定的监听对象和触发事件类型。
在本申请实施例中,监听对象和触发事件类型均可以由人为设定及调整,监听对象可以是:第一数据库对应的第一资源池;或者,第一数据队列在第一资源池中创建的资源;或者,第一资源池中加锁成功的资源;或者,第一资源池中排序编号在第一数据队列所创建资源之前的一个或多个资源,不做具体限定。触发事件类型可以包括但不限于:监听对象被删除和监听对象发生内容变更等。
步骤S606:第一服务器结合识别信息、监听对象和触发事件类型,生成加锁请求,并向第二服务器发送加锁请求。
在本申请实施例中,具体的,第二服务器接收到加锁请求后,可以根据加锁请求对应的识别信息确定第一数据库对应的第一资源池,从而在第一资源池中创建第一数据队列对应的第一资源。第二服务器还可以根据加锁请求对应的监听对象和触发事件类型生成监听器以对第一资源池进行变更监听。当第二服务器利用监听器对第一资源池中的监听对象监听到满足触发事件类型的触发事件时,第二服务器生成变更通知,并将变更通知发送给第一服务器,实现了有效的资源监听机制,能够通过资源池变化反映数据库的连接变化,并及时将数据库的连接变化反馈给第一服务器,以便第一服务器对资源池进行动态抢占及加锁。可选的,变更通知可以包括通知状态、触发事件类型和触发事件对应的资源路径等,通知状态表示第一服务器与第二服务器的连接状态(比如连接正常、连接断开或会话失效等)。
还可选的,第一服务器在生成加锁请求时,还可以建立第一数据队列与相应监听对象和触发事件类型之间的监听关系,并对监听关系进行存储。基于此,每次第一服务器接收到第二服务器发送的变更通知时,可以将变更通知与存储的监听关系进行匹配,进而根据匹配得到的监听关系确定第一服务器上响应本次变更的数据队列。
步骤S607:第一服务器从第二服务器获取第一资源池的资源信息。
步骤S608:第一服务器根据资源信息判断是否加锁成功,若是,执行步骤S609,若否,执行步骤S610至S611。
步骤S609:第一服务器将第一数据队列与第一数据库连接以进行数据同步。
步骤S610:第一服务器检测第二服务器发送的变更通知。
步骤S611:若接收到变更通知,继续执行步骤S607。
可以理解的是,本实施例中步骤S600、S603、S606至S609的具体实现方式还可以参照上述实施例一中对步骤S500至S506的描述,在此不再赘述。
在一些可选的实施方式中,第一服务器还可以接收客户端发送的处理请求(比如HTTP请求),并根据处理请求进行交互处理,得到处理结果,再将处理结果返回给客户端。
其中,针对第一服务器根据处理请求进行交互处理这一步骤,一些实现方式中,处理请求可以是查询请求,则第一服务器可以获取查询请求指定的实例标识信息(或第一服务器标识信息)。第一服务器根据实例标识信息(或第一服务器标识信息)查询目标数据队列连接的数据库信息,以作为处理结果。其中,目标数据队列是与实例标识信息匹配的数据队列,实例标识信息包括ip地址或编号等,数据库信息包括但不限于数据库个数和数据库名称。或者,第一服务器可以根据查询请求指定的数据库信息,查询目标数据库连接的数据队列,以 作为处理结果。其中,目标数据库是与指定的数据库信息匹配的数据库。
另一些实现方式中,处理请求可以是干预请求,则第一服务器可以根据干预请求,得到干预请求指定的第五数据队列和第四数据库,并向第二服务器发送第五数据队列对第四数据库的释放请求,第二服务器响应于释放请求,在第四数据库对应的资源池中删去第五数据队列创建的资源。
可见,实施上述方法实施例,能够监听整个数据同步系统的配置变更,并结合配置变更情况适应性地采取相应的负载分配方式,即动态调整各个第一服务器上数据队列与数据库的连接,无需人为配置,故各个数据队列可以灵活抢占各个数据库的资源池,并根据资源池的资源创建情况分析是否加锁成功,加锁成功即建立连接,加锁失败则继续对资源池进行变更监听以等待下一次加锁机会,从而在实现分布式部署的同时,便于水平扩缩容,降低了对数据同步系统的运维难度。
本申请实施例还提供一种数据同步装置。请参阅图7,图7是本申请实施例所应用的一种数据同步装置的结构框图。如图7所示,该数据同步装置700包括:
获取模块710,用于响应于数据同步系统配置信息的变更,获取数据同步系统的目标配置信息;
确定模块720,用于根据目标配置信息,从第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从数据同步系统的所有数据库中确定待加锁的第一数据库;
生成模块730,用于生成加锁请求,其中,加锁请求用于指示第二服务器在第一数据库对应的第一资源池中创建第一数据队列对应的第一资源;
发送模块740,用于向第二服务器发送加锁请求;
获取模块710,还用于从第二服务器获取第一资源池的资源信息;
判断模块750,用于根据资源信息判断是否加锁成功;
同步模块760,用于在加锁成功时,将第一数据队列与第一数据库连接以进行数据同步;
监听模块770,用于在加锁失败时,对第一资源池进行变更监听。
需要说明的是,本实施例的具体实现过程可参见上述方法实施例所描述的具体实现过程,亦不再赘述。
本申请实施例还提供了一种计算机设备,该计算机设备包括存储器和处理器,存储器上存储有程序,程序被处理器执行时实现上述数据同步方法。
本申请实施例还提供了一种存储介质,用于计算机可读存储,存储介质存储有一个或者多个程序,一个或者多个程序可被一个或者多个处理器执行,以实现上述数据同步方法。该存储介质可以是非易失性,也可以是易失性,不做具体限定。
本领域普通技术人员可以理解,上文中所公开方法中的全部或某些步骤、系统、设备中的功能模块/单元可以被实施为软件、固件、硬件及其适当的组合。
在硬件实施方式中,在以上描述中提及的功能模块/单元之间的划分不一定对应于物理组件的划分;例如,一个物理组件可以具有多个功能,或者一个功能或步骤可以由若干物理组件合作执行。某些物理组件或所有物理组件可以被实施为由处理器,如中央处理器、数字信 号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质(或非暂时性介质)和通信介质(或暂时性介质)。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息(诸如计算机可读指令、数据结构、程序模块或其他数据)的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘(DVD)或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。
以上参照附图说明了本申请的优选实施例,并非因此局限本申请的权利范围。本领域技术人员不脱离本申请的范围和实质内所作的任何修改、等同替换和改进,均应在本申请的权利范围之内。

Claims (20)

  1. 一种数据同步方法,其中,应用于数据同步系统,所述数据同步系统包括数据库、第一服务器和第二服务器,所述方法包括:
    响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;
    根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;
    生成加锁请求,并向第二服务器发送所述加锁请求,其中,所述加锁请求用于指示所述第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;
    从所述第二服务器获取所述第一资源池的资源信息;
    根据所述资源信息判断是否加锁成功,若加锁成功,将所述第一数据队列与所述第一数据库连接以进行数据同步,若加锁失败,对所述第一资源池进行变更监听。
  2. 根据权利要求1所述的方法,其中,所述目标配置信息包括所述数据同步系统中所有所述数据库和所有所述第一服务器的配置信息,所述第一服务器的配置信息包括所述第一服务器上运行的所有数据队列;在所述获取所述数据同步系统的目标配置信息之后,所述方法还包括:
    获取存储的本地配置信息,所述本地配置信息为上一次所述数据同步系统的配置信息发生变更时对所述数据同步系统获取到的配置信息;
    将所述目标配置信息与所述本地配置信息进行对比,得到对比结果;
    所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    在所述对比结果包括新增数据库或者任一数据队列被删除的情况下,根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列。
  3. 根据权利要求2所述的方法,其中,所述将所述目标配置信息与所述本地配置信息进行对比,得到对比结果之后,所述方法还包括:
    在所述对比结果包括第二数据库被删除的情况下,当所述第一服务器上运行有与所述第二数据库连接的第二数据队列,则向所述第二服务器发送所述第二数据队列对所述第二数据库的释放请求,所述释放请求用于指示所述第二服务器从所述第二数据库对应的第二资源池中删去所述第二数据队列创建的第二资源;或者,当所述第一服务器上运行有对所述第二资源池进行变更监听的第三数据队列,则向所述第二服务器发送所述第三数据队列对所述第二数据库的监听取消请求,所述监听取消请求用于指示所述第二服务器从所述第二资源池中删去所述第三数据队列创建的第三资源;
    和/或,在所述对比结果包括第三数据库被修改的情况下,且所述第一服务器上运行有与所述第三数据库连接的第四数据队列,则向所述第二服务器发送所述第四数据队列对所述第三数据库的重加锁请求,其中,所述重加锁请求用于指示所述第二服务器从所述第三数据库对应的第三资源池中删除所述第四数据队列创建的第四资源,并指示所述第二服务器在所述 第三资源池中为所述第四数据队列创建新的第四资源。
  4. 根据权利要求1至3任一项所述的方法,其中,所述根据所述资源信息判断是否加锁成功,包括:
    根据所述资源信息,确定所述第一资源池内各个资源的排序编号,所述排序编号根据所述资源在所述第一资源池中的创建次序所生成;
    判断所述第一资源的排序编号是否在所述第一资源池内所有资源的排序编号中取值最小;
    若是,则判定加锁成功;
    若否,则判定加锁失败。
  5. 根据权利要求1至3任一项所述的方法,其中,所述目标配置信息包括所述第一服务器上运行的各个数据队列的数据库连接上限值;所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    获取所述第一服务器上运行的至少一个数据队列各自对应的加锁数量,所述加锁数量表示所述数据队列已连接的数据库数量;
    从所述至少一个数据队列中确定待加锁的第一数据队列,所述第一数据队列满足:所述第一数据队列对应的加锁数量小于所述第一数据队列的数据库连接上限值。
  6. 根据权利要求1至3任一项所述的方法,其中,所述目标配置信息包括所述第一服务器上运行的各个数据队列的事务处理上限值,所述事务处理上限值表示所述数据队列在指定时间内的最大事务处理量;所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    获取所述第一服务器上运行的至少一个数据队列各自对应的当前事务处理能力,所述当前事务处理能力表示所述数据队列当前在所述指定时间内的事务处理量;
    从所述至少一个数据队列中确定待加锁的第一数据队列,所述第一数据队列满足:所述第一数据队列对应的当前事务处理能力小于所述第一数据队列的事务处理上限值。
  7. 根据权利要求1至3任一项所述的方法,其中,所述目标配置信息包括所述数据同步系统中所有所述数据库的配置信息,所述生成加锁请求,包括:
    根据所述数据同步系统中所有所述数据库的配置信息,确定所述第一数据库的识别信息;获取设定的监听对象和触发事件类型;
    结合所述识别信息、所述监听对象和所述触发事件类型,生成加锁请求,所述加锁请求还用于指示所述第二服务器根据所述识别信息确定所述第一数据库对应的第一资源池,以及指示第二服务器根据所述监听对象和所述触发事件类型生成监听器以对所述第一资源池进行变更监听;
    所述若加锁失败,对所述第一资源池进行变更监听,包括:
    若加锁失败,检测所述第二服务器发送的变更通知,所述变更通知是所述第二服务器利用所述监听器对所述第一资源池中的所述监听对象监听到触发事件时所生成,所述触发事件满足所述触发事件类型;
    若接收到所述变更通知,则继续执行所述从所述第二服务器获取所述第一资源池的资源 信息,并根据所述资源信息判断是否加锁成功的步骤。
  8. 一种数据同步装置,其中,应用于数据同步系统,所述数据同步系统包括数据库、第一服务器和第二服务器,所述装置包括:
    获取模块,用于响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;
    确定模块,用于根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;
    生成模块,用于生成加锁请求,其中,所述加锁请求用于指示第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;
    发送模块,用于向所述第二服务器发送所述加锁请求;
    所述获取模块,还用于从所述第二服务器获取所述第一资源池的资源信息;
    判断模块,用于根据所述资源信息判断是否加锁成功;
    同步模块,用于在加锁成功时,将所述第一数据队列与所述第一数据库连接以进行数据同步;
    监听模块,用于在加锁失败时,对所述第一资源池进行变更监听。
  9. 一种计算机设备,所述计算机设备包括存储器和处理器,所述存储器上存储有程序,其中,所述程序被所述处理器执行时实现如下步骤:
    响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;
    根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;
    生成加锁请求,并向第二服务器发送所述加锁请求,其中,所述加锁请求用于指示所述第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;
    从所述第二服务器获取所述第一资源池的资源信息;
    根据所述资源信息判断是否加锁成功,若加锁成功,将所述第一数据队列与所述第一数据库连接以进行数据同步,若加锁失败,对所述第一资源池进行变更监听。
  10. 根据权利要求9所述的计算机设备,其中,所述目标配置信息包括所述数据同步系统中所有所述数据库和所有所述第一服务器的配置信息,所述第一服务器的配置信息包括所述第一服务器上运行的所有数据队列;在所述获取所述数据同步系统的目标配置信息之后,所述方法还包括:
    获取存储的本地配置信息,所述本地配置信息为上一次所述数据同步系统的配置信息发生变更时对所述数据同步系统获取到的配置信息;
    将所述目标配置信息与所述本地配置信息进行对比,得到对比结果;
    所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    在所述对比结果包括新增数据库或者任一数据队列被删除的情况下,根据所述目标配置 信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列。
  11. 根据权利要求10所述的计算机设备,其中,所述将所述目标配置信息与所述本地配置信息进行对比,得到对比结果之后,所述方法还包括:
    在所述对比结果包括第二数据库被删除的情况下,当所述第一服务器上运行有与所述第二数据库连接的第二数据队列,则向所述第二服务器发送所述第二数据队列对所述第二数据库的释放请求,所述释放请求用于指示所述第二服务器从所述第二数据库对应的第二资源池中删去所述第二数据队列创建的第二资源;或者,当所述第一服务器上运行有对所述第二资源池进行变更监听的第三数据队列,则向所述第二服务器发送所述第三数据队列对所述第二数据库的监听取消请求,所述监听取消请求用于指示所述第二服务器从所述第二资源池中删去所述第三数据队列创建的第三资源;
    和/或,在所述对比结果包括第三数据库被修改的情况下,且所述第一服务器上运行有与所述第三数据库连接的第四数据队列,则向所述第二服务器发送所述第四数据队列对所述第三数据库的重加锁请求,其中,所述重加锁请求用于指示所述第二服务器从所述第三数据库对应的第三资源池中删除所述第四数据队列创建的第四资源,并指示所述第二服务器在所述第三资源池中为所述第四数据队列创建新的第四资源。
  12. 根据权利要求9至11任一项所述的计算机设备,其中,所述根据所述资源信息判断是否加锁成功,包括:
    根据所述资源信息,确定所述第一资源池内各个资源的排序编号,所述排序编号根据所述资源在所述第一资源池中的创建次序所生成;
    判断所述第一资源的排序编号是否在所述第一资源池内所有资源的排序编号中取值最小;
    若是,则判定加锁成功;
    若否,则判定加锁失败。
  13. 根据权利要求9至11任一项所述的计算机设备,其中,所述目标配置信息包括所述第一服务器上运行的各个数据队列的数据库连接上限值;所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    获取所述第一服务器上运行的至少一个数据队列各自对应的加锁数量,所述加锁数量表示所述数据队列已连接的数据库数量;
    从所述至少一个数据队列中确定待加锁的第一数据队列,所述第一数据队列满足:所述第一数据队列对应的加锁数量小于所述第一数据队列的数据库连接上限值。
  14. 根据权利要求9至11任一项所述的计算机设备,其中,所述目标配置信息包括所述第一服务器上运行的各个数据队列的事务处理上限值,所述事务处理上限值表示所述数据队列在指定时间内的最大事务处理量;所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    获取所述第一服务器上运行的至少一个数据队列各自对应的当前事务处理能力,所述当前事务处理能力表示所述数据队列当前在所述指定时间内的事务处理量;
    从所述至少一个数据队列中确定待加锁的第一数据队列,所述第一数据队列满足:所述 第一数据队列对应的当前事务处理能力小于所述第一数据队列的事务处理上限值。
  15. 根据权利要求9至11任一项所述的计算机设备,其中,所述目标配置信息包括所述数据同步系统中所有所述数据库的配置信息,所述生成加锁请求,包括:
    根据所述数据同步系统中所有所述数据库的配置信息,确定所述第一数据库的识别信息;
    获取设定的监听对象和触发事件类型;
    结合所述识别信息、所述监听对象和所述触发事件类型,生成加锁请求,所述加锁请求还用于指示所述第二服务器根据所述识别信息确定所述第一数据库对应的第一资源池,以及指示第二服务器根据所述监听对象和所述触发事件类型生成监听器以对所述第一资源池进行变更监听;
    所述若加锁失败,对所述第一资源池进行变更监听,包括:
    若加锁失败,检测所述第二服务器发送的变更通知,所述变更通知是所述第二服务器利用所述监听器对所述第一资源池中的所述监听对象监听到触发事件时所生成,所述触发事件满足所述触发事件类型;
    若接收到所述变更通知,则继续执行所述从所述第二服务器获取所述第一资源池的资源信息,并根据所述资源信息判断是否加锁成功的步骤。
  16. 一种存储介质,用于计算机可读存储,其中,所述存储介质存储有一个或者多个程序,所述一个或者多个程序可被一个或者多个处理器执行,以执行如下步骤:
    响应于数据同步系统配置信息的变更,获取所述数据同步系统的目标配置信息;
    根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,以及从所述数据同步系统的所有数据库中确定待加锁的第一数据库;
    生成加锁请求,并向第二服务器发送所述加锁请求,其中,所述加锁请求用于指示所述第二服务器在所述第一数据库对应的第一资源池中创建所述第一数据队列对应的第一资源;
    从所述第二服务器获取所述第一资源池的资源信息;
    根据所述资源信息判断是否加锁成功,若加锁成功,将所述第一数据队列与所述第一数据库连接以进行数据同步,若加锁失败,对所述第一资源池进行变更监听。
  17. 根据权利要求16所述的存储介质,其中,所述目标配置信息包括所述数据同步系统中所有所述数据库和所有所述第一服务器的配置信息,所述第一服务器的配置信息包括所述第一服务器上运行的所有数据队列;在所述获取所述数据同步系统的目标配置信息之后,所述方法还包括:
    获取存储的本地配置信息,所述本地配置信息为上一次所述数据同步系统的配置信息发生变更时对所述数据同步系统获取到的配置信息;
    将所述目标配置信息与所述本地配置信息进行对比,得到对比结果;
    所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    在所述对比结果包括新增数据库或者任一数据队列被删除的情况下,根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列。
  18. 根据权利要求17所述的存储介质,其中,所述将所述目标配置信息与所述本地配置信息进行对比,得到对比结果之后,所述方法还包括:
    在所述对比结果包括第二数据库被删除的情况下,当所述第一服务器上运行有与所述第二数据库连接的第二数据队列,则向所述第二服务器发送所述第二数据队列对所述第二数据库的释放请求,所述释放请求用于指示所述第二服务器从所述第二数据库对应的第二资源池中删去所述第二数据队列创建的第二资源;或者,当所述第一服务器上运行有对所述第二资源池进行变更监听的第三数据队列,则向所述第二服务器发送所述第三数据队列对所述第二数据库的监听取消请求,所述监听取消请求用于指示所述第二服务器从所述第二资源池中删去所述第三数据队列创建的第三资源;
    和/或,在所述对比结果包括第三数据库被修改的情况下,且所述第一服务器上运行有与所述第三数据库连接的第四数据队列,则向所述第二服务器发送所述第四数据队列对所述第三数据库的重加锁请求,其中,所述重加锁请求用于指示所述第二服务器从所述第三数据库对应的第三资源池中删除所述第四数据队列创建的第四资源,并指示所述第二服务器在所述第三资源池中为所述第四数据队列创建新的第四资源。
  19. 根据权利要求16至18任一项所述的存储介质,其中,所述根据所述资源信息判断是否加锁成功,包括:
    根据所述资源信息,确定所述第一资源池内各个资源的排序编号,所述排序编号根据所述资源在所述第一资源池中的创建次序所生成;
    判断所述第一资源的排序编号是否在所述第一资源池内所有资源的排序编号中取值最小;
    若是,则判定加锁成功;
    若否,则判定加锁失败。
  20. 根据权利要求16至18任一项所述的存储介质,其中,所述目标配置信息包括所述第一服务器上运行的各个数据队列的数据库连接上限值;所述根据所述目标配置信息,从所述第一服务器上运行的至少一个数据队列中确定待加锁的第一数据队列,包括:
    获取所述第一服务器上运行的至少一个数据队列各自对应的加锁数量,所述加锁数量表示所述数据队列已连接的数据库数量;
    从所述至少一个数据队列中确定待加锁的第一数据队列,所述第一数据队列满足:所述第一数据队列对应的加锁数量小于所述第一数据队列的数据库连接上限值。
PCT/CN2022/088533 2021-08-30 2022-04-22 一种数据同步方法及装置、计算机设备、存储介质 WO2023029519A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111007698.6 2021-08-30
CN202111007698.6A CN113704354B (zh) 2021-08-30 2021-08-30 一种数据同步方法及装置、计算机设备、存储介质

Publications (1)

Publication Number Publication Date
WO2023029519A1 true WO2023029519A1 (zh) 2023-03-09

Family

ID=78657061

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/088533 WO2023029519A1 (zh) 2021-08-30 2022-04-22 一种数据同步方法及装置、计算机设备、存储介质

Country Status (2)

Country Link
CN (1) CN113704354B (zh)
WO (1) WO2023029519A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116662016A (zh) * 2023-07-25 2023-08-29 太平金融科技服务(上海)有限公司 端口切换方法、装置、计算机设备、存储介质和程序产品
CN117171262A (zh) * 2023-08-09 2023-12-05 飞算数智科技(深圳)有限公司 数据同步的方法、装置、存储介质及电子设备

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113704354B (zh) * 2021-08-30 2023-10-20 康键信息技术(深圳)有限公司 一种数据同步方法及装置、计算机设备、存储介质
CN114356895B (zh) * 2022-03-16 2022-06-07 希望知舟技术(深圳)有限公司 基于异常工况数据库管理的方法、装置、设备及存储介质
CN114745571B (zh) * 2022-04-15 2024-01-23 网易(杭州)网络有限公司 直播状态信息同步方法、装置、电子设备和可读存储介质
CN115470302B (zh) * 2022-10-25 2023-05-09 以萨技术股份有限公司 一种基于canal的数据库双向同步方法、介质及设备
CN117041044A (zh) * 2023-08-23 2023-11-10 中电金信软件有限公司 网关配置方法、装置及系统

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100088702A1 (en) * 2008-10-06 2010-04-08 Microsoft Corporation Checking transactional memory implementations
CN108073658A (zh) * 2016-11-16 2018-05-25 中国移动通信集团广西有限公司 一种数据同步系统及方法
CN108573006A (zh) * 2017-06-06 2018-09-25 北京金山云网络技术有限公司 跨机房数据同步系统、方法及装置、电子设备
CN109753364A (zh) * 2018-12-28 2019-05-14 北京明朝万达科技股份有限公司 一种基于网络的分布式锁的实现方法、设备及介质
CN112307037A (zh) * 2019-07-26 2021-02-02 北京京东振世信息技术有限公司 一种数据同步方法和装置
CN112905322A (zh) * 2021-02-09 2021-06-04 掌阅科技股份有限公司 资源加锁的方法、计算设备及计算机存储介质
CN113704354A (zh) * 2021-08-30 2021-11-26 康键信息技术(深圳)有限公司 一种数据同步方法及装置、计算机设备、存储介质

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109542611B (zh) * 2017-09-21 2021-05-14 中国移动通信集团重庆有限公司 数据库即服务系统、数据库调度方法、设备及存储介质
CN112015713B (zh) * 2019-05-30 2024-03-26 阿里云计算有限公司 数据库任务的处理方法、装置、电子设备及可读介质
CN112527899A (zh) * 2020-12-03 2021-03-19 北京百度网讯科技有限公司 数据同步的方法、装置、设备以及存储介质
CN112783859B (zh) * 2021-01-08 2023-03-07 河北志晟信息技术股份有限公司 一种数据库的轻量级并发迁移方法

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100088702A1 (en) * 2008-10-06 2010-04-08 Microsoft Corporation Checking transactional memory implementations
CN108073658A (zh) * 2016-11-16 2018-05-25 中国移动通信集团广西有限公司 一种数据同步系统及方法
CN108573006A (zh) * 2017-06-06 2018-09-25 北京金山云网络技术有限公司 跨机房数据同步系统、方法及装置、电子设备
CN109753364A (zh) * 2018-12-28 2019-05-14 北京明朝万达科技股份有限公司 一种基于网络的分布式锁的实现方法、设备及介质
CN112307037A (zh) * 2019-07-26 2021-02-02 北京京东振世信息技术有限公司 一种数据同步方法和装置
CN112905322A (zh) * 2021-02-09 2021-06-04 掌阅科技股份有限公司 资源加锁的方法、计算设备及计算机存储介质
CN113704354A (zh) * 2021-08-30 2021-11-26 康键信息技术(深圳)有限公司 一种数据同步方法及装置、计算机设备、存储介质

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116662016A (zh) * 2023-07-25 2023-08-29 太平金融科技服务(上海)有限公司 端口切换方法、装置、计算机设备、存储介质和程序产品
CN116662016B (zh) * 2023-07-25 2023-10-20 太平金融科技服务(上海)有限公司 端口切换方法、装置、计算机设备、存储介质和程序产品
CN117171262A (zh) * 2023-08-09 2023-12-05 飞算数智科技(深圳)有限公司 数据同步的方法、装置、存储介质及电子设备

Also Published As

Publication number Publication date
CN113704354B (zh) 2023-10-20
CN113704354A (zh) 2021-11-26

Similar Documents

Publication Publication Date Title
WO2023029519A1 (zh) 一种数据同步方法及装置、计算机设备、存储介质
US10764369B2 (en) Data storage method and server applicable to distributed server cluster
US11172023B2 (en) Data synchronization method and system
US10255343B2 (en) Initialization protocol for a peer-to-peer replication environment
WO2019047479A1 (zh) 一种普适多源异构大规模数据同步系统
US20070061379A1 (en) Method and apparatus for sequencing transactions globally in a distributed database cluster
KR101871383B1 (ko) 계층적 데이터 구조의 노드 상에서 재귀적 이벤트 리스너를 사용하기 위한 방법 및 시스템
US20120005680A1 (en) Processing a batched unit of work
US11741075B2 (en) Methods and system of tracking transactions for distributed ledger
CN103780615B (zh) 一种在多个服务器间客户端会话数据共享方法
US7870248B2 (en) Exploiting service heartbeats to monitor file share
CN105069152B (zh) 数据处理方法及装置
US10795910B2 (en) Robust communication system for guaranteed message sequencing with the detection of duplicate senders
KR20220074971A (ko) 블록체인 기반 데이터 프로세싱 방법, 장치 및 디바이스, 그리고 판독가능 저장 매체
US20150324222A1 (en) System and method for adaptively integrating a database state notification service with a distributed transactional middleware machine
CN112000444B (zh) 数据库事务处理方法、装置、存储介质和电子设备
CN112631756A (zh) 一种应用于航天测控软件的分布式调控方法及装置
CN112468310B (zh) 流媒体集群节点管理方法、装置及存储介质
US8230444B2 (en) Global attribute uniqueness (GAU) using an ordered message service (OMS)
CN109753292B (zh) 一种在多单实例数据库服务中部署多个应用的方法及装置
US20080034053A1 (en) Mail Server Clustering
CN116347467B (zh) 5g网络中udr进行用户数据管理方法及系统
US11863617B1 (en) Dynamic decentralized hierarchical Holon network system
CN117056131B (zh) 基于区块链网络的数据处理方法及相关设备
Kumar et al. Analysis of Raft Consensus Algorithm

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22862665

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE