WO2019154394A1 - 分布式数据库集群***、数据同步方法及存储介质 - Google Patents

分布式数据库集群***、数据同步方法及存储介质 Download PDF

Info

Publication number
WO2019154394A1
WO2019154394A1 PCT/CN2019/074699 CN2019074699W WO2019154394A1 WO 2019154394 A1 WO2019154394 A1 WO 2019154394A1 CN 2019074699 W CN2019074699 W CN 2019074699W WO 2019154394 A1 WO2019154394 A1 WO 2019154394A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
operation instruction
cluster system
distributed database
synchronization
Prior art date
Application number
PCT/CN2019/074699
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 中兴通讯股份有限公司
Priority to EP19751274.2A priority Critical patent/EP3754514B1/en
Priority to JP2020565003A priority patent/JP7090744B2/ja
Publication of WO2019154394A1 publication Critical patent/WO2019154394A1/zh

Links

Images

Classifications

    • 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/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems
    • 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
    • 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/2365Ensuring data consistency and integrity
    • 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/24Querying
    • G06F16/242Query formulation
    • 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/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • G06F16/2438Embedded query languages
    • 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
    • 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
    • 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/48Program initiating; Program switching, e.g. by interrupt
    • 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/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • 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]
    • 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/5016Allocation 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 the resource being the memory
    • 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
    • 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/5018Thread allocation
    • 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 disclosure relates to the field of distributed databases, and in particular, to a distributed database cluster system, a data synchronization method, and a storage medium.
  • data synchronization between data clusters mainly relies on data migration between points.
  • data synchronized by different data nodes between clusters may not achieve global consistency at the point in time.
  • two data nodes A and B in the primary cluster synchronize data to two data nodes A' and B' in the standby cluster.
  • A' synchronizes the data of A at time T0, but B'
  • the data of B at time T1 is synchronized. If the switchover occurs, the service needs to be migrated to the standby cluster. The data of the standby cluster cannot be switched to the standby cluster immediately.
  • the business data cannot be restored to a consistent point in time.
  • the embodiments of the present disclosure provide a distributed database clustering system, a data synchronization method, and a storage medium to solve at least the problem that data synchronized by different data nodes in the related art may fail to achieve global consistency at a time point.
  • a distributed database cluster system including: a first synchronization clock module, a first data synchronization module, and a plurality of first database groups, wherein the plurality of first database groups are Each of the first database groups includes a first primary database, the first synchronous clock module is configured to periodically send clock synchronization instructions; the first data synchronization module is configured to respectively set each of the first primary databases in the The database operation instruction recorded between two adjacent clock synchronization instructions sent by a synchronous clock module is packaged into a first operation instruction block, and the first operation instruction block is transmitted.
  • a distributed database cluster system including: a second data synchronization module and a plurality of second database groups, wherein each of the plurality of second database groups is second
  • the database group includes a second primary database
  • the second data synchronization module is configured to receive an operation instruction block sent by the distributed database cluster system of the peer end, wherein the operation instruction block includes a first operation instruction block or a second operation instruction.
  • the first operation instruction block encapsulating a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database of the distributed database cluster system of the opposite end, the second operation instruction Blocking a database operation instruction that satisfies a filter condition in a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database of the distributed database cluster system of the peer end, wherein the filter condition
  • the method includes: the database operation instruction is in a global transaction committed state; executing the received operation instruction block Database manipulation instructions.
  • a data synchronization method for a first distributed database cluster system including a plurality of first database groups, wherein each of the plurality of first database groups A database group includes a first primary database, the method comprising: the first distributed database cluster system periodically sends a clock synchronization instruction; the first distributed database cluster system respectively adjacent each first primary database The database operation instruction recorded between the two clock synchronization instructions is packaged into a first operation instruction block, and the first operation instruction block is transmitted.
  • a data synchronization method for a second distributed database cluster system including a plurality of second database groups, wherein each of the plurality of second database groups
  • the second database group includes a second primary database
  • the method comprising: the second distributed database cluster system receives an operation instruction block sent by the first distributed database cluster system, wherein the operation instruction block includes a first operation instruction a block or a second operation instruction block, the first operation instruction block encapsulating a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database of the first distributed database cluster system,
  • the second operation instruction block encapsulates a database operation instruction that satisfies a filtering condition in a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database of the first distributed database cluster system.
  • the filtering condition includes: the database operation instruction is in a global transaction committed state; the second distributed The database cluster system executes the received database operation instructions in the operation instruction block.
  • a storage medium having stored therein a computer program, wherein the computer program is configured to execute the steps of any one of the method embodiments described above.
  • an electronic device comprising a memory and a processor, wherein the memory stores a computer program, the processor being configured to execute the computer program to perform any of the above The steps in the method embodiments.
  • the distributed database cluster system since the distributed database cluster system periodically sends clock synchronization instructions internally, during the data synchronization process, the operation instructions recorded for each primary database are recorded between adjacent two clock synchronization instructions.
  • the database operation instruction is encapsulated into a first operation instruction block and sent, so as to ensure that the data packets on which the data synchronization is based have the same time reference point for each primary database, and therefore, the synchronization of different data nodes in the related art can be solved.
  • Data may not be able to achieve global consistency at the point in time, so that data records synchronized by different data nodes are based on the same time reference point, ensuring global consistency on the recorded data.
  • FIG. 1 is a schematic structural diagram of a distributed database cluster system according to Embodiment 1 of the present disclosure
  • FIG. 2 is a first preferred architectural diagram of a distributed database cluster system according to Embodiment 1 of the present disclosure
  • FIG. 3 is a second preferred architectural diagram of a distributed database cluster system according to Embodiment 1 of the present disclosure.
  • FIG. 4 is a schematic structural diagram of a distributed database cluster system according to Embodiment 2 of the present disclosure.
  • FIG. 5 is a schematic diagram of a preferred architecture of a distributed database cluster system according to Embodiment 2 of the present disclosure
  • FIG. 6 is a flowchart of a data synchronization method according to Embodiment 3 of the present disclosure.
  • FIG. 7 is a flowchart of a data synchronization method according to Embodiment 4 of the present disclosure.
  • FIG. 8 is a schematic architectural diagram of an apparatus for ensuring global consistency of distributed database data synchronization according to Embodiment 5 of the present disclosure
  • FIG. 10 is a schematic diagram of a SQL statement cut packet according to Embodiment 6 of the present disclosure.
  • FIG. 11 is a flowchart of SQL statement line parallel processing according to Embodiment 7 of the present disclosure.
  • FIG. 14 is a schematic diagram of a system architecture in a distributed database cluster data synchronization high performance mode according to Embodiment 9 of the present disclosure.
  • FIG. 15 is a schematic diagram of a system architecture in a distributed database cluster data synchronization high performance mode according to Embodiment 10 of the present disclosure
  • FIG. 16 is a system architecture diagram of a distributed database quasi-real time backup according to Embodiment 11 of the present disclosure
  • FIG. 17 is a system architecture diagram of data extraction based on distributed database delta data according to Embodiment 12 of the present disclosure.
  • the distributed database cluster system consists of multiple database groups. Each database group consists of multiple independent database nodes. The database node data in the group is completely consistent. Only one node in the group provides a write service to the database. The primary database, other data nodes use the replication technology between databases to synchronize data to the local, called the standby database. Provide database functions to applications in the form of data services, and provide a unified standard interface for applications, such as SQL interfaces.
  • the present disclosure proposes a distributed database cluster system, a data synchronization method, and a storage medium.
  • the present disclosure will be described in detail below with reference to the drawings in conjunction with the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments may be combined with each other without conflict.
  • FIG. 1 is a schematic structural diagram of a distributed database cluster system according to Embodiment 1 of the present disclosure.
  • the distributed database cluster system may include: a first synchronous clock module 12, a first data synchronization module 14, and a plurality of a first database group 16, wherein each of the plurality of first database groups 16 includes a first primary database (not shown),
  • the first synchronous clock module 12 is configured to periodically send a clock synchronization instruction
  • the first data synchronization module 14 is configured to package the database operation instructions recorded between the adjacent two clock synchronization instructions sent by the first synchronization clock module 12 by each first primary database into a first operation instruction. Blocking and transmitting the first operational instruction block.
  • the first synchronous clock module 12 in the distributed database cluster system periodically sends a clock synchronization instruction, and the first data synchronization module 14 in the data synchronization process, the operation instructions recorded for each primary database are
  • the database operation instruction recorded between two adjacent clock synchronization instructions is packaged into a first operation instruction block and transmitted, thereby ensuring that the data packets on which the data synchronization is based have the same time reference point for each primary database, thus It can solve the problem that the data synchronized by different data nodes in the related art may fail to achieve the global consistency at the time point, so that the data records synchronized by different data nodes are based on the same time reference point, and the global consistency on the recorded data is guaranteed. .
  • the first data synchronization module 14 determines which instructions of the database operation instruction recorded by each first primary database between the adjacent two clock synchronization instructions sent by the first synchronization clock module 12, and then encapsulates them into The first operational instruction block, within the distributed database cluster system, there are many ways to achieve such a goal. An embodiment that is easy to implement and does not require major changes to the processing mode of an existing distributed database cluster system is given below.
  • the first synchronization clock module 12 is configured to periodically send the clock synchronization instruction to each first primary database; the first primary database is configured to write the received database operation instruction to the Writing a log file of the first primary database, and writing the received clock synchronization instruction to the log file; the first data synchronization module 14 is configured to separately acquire the log file of each first primary database, A database operation instruction sandwiched between two clock synchronization instructions in the log file is packaged into the first operation instruction block, and the first operation instruction block is transmitted. It can be seen that in this way, the primary database normally writes the received clock synchronization instruction and the normal database operation instruction to the log file, and the first data synchronization module 14 can read the log file and synchronize the instruction according to the clock in the log.
  • the database operation instruction is segmented, and a database operation instruction sandwiched between two clock synchronization instructions is packaged into the first operation instruction block.
  • a more common database operation statement can be taken to generate a clock synchronization instruction, so that the primary database can conveniently write it together with the normal database operation statement to the log file.
  • a preferred database operation statement is SQL, that is, a synchronous clock SQL statement can be used as a clock synchronization instruction, and a database operation instruction also uses a SQL statement.
  • the solution in this embodiment is directed to the operation instructions recorded in each of the main databases, and the database operation instructions recorded between the adjacent two clock synchronization instructions are packaged into the first operation instruction block and sent. Therefore, for each primary database, the data packets on which the data synchronization is based all have the same time reference point, and are globally consistent at the operational command record level of the database.
  • the execution time of each operation command is very small and presents a relatively uniform distribution.
  • the database execution level can basically achieve global consistency. Considering that in an actual distributed database cluster system, there are occasions when the processing tasks in the database cluster are less distributed or the processing resource bandwidth is smaller. At this time, there may be differences in the execution status of different processing tasks in the same database cluster. At this time, at least one of the following two processing methods (final global consistency and real-time global consistency) can be used to ensure global consistency at the database execution level.
  • the first data synchronization module 14 is configured to send the first operation instruction block to the distributed database cluster system of the opposite end.
  • the first operation instruction block of the distributed database cluster system sent to the peer end is a database operation instruction recorded between the two synchronization clock signals recorded by the primary database, and the consistency operation filtering is not performed for these database operation instructions.
  • the data synchronization module of the distributed database cluster system of the peer end normally synchronizes it to the corresponding primary database of the distributed database cluster system of the peer.
  • the peer distributed database cluster system performs global consistency filtering when the service performs cluster switching. This embodiment is applicable to the scenario where the RPO index is high in the disaster recovery system. The data can be efficiently transmitted to the peer cluster and persisted to ensure that the RPO is as small as possible.
  • a first consistency filtering module 22 is added to the distributed database cluster system.
  • 2 is a first preferred architectural diagram of a distributed database cluster system according to Embodiment 1 of the present disclosure. As shown in FIG. 2, the distributed database cluster system further includes a first consistency filtering module 22.
  • the first data synchronization module 14 is configured to send the first operation instruction block to the first consistency filtering module 22.
  • the first consistency filtering module 22 is configured to receive the first operation instruction block sent by the first data synchronization module 14, and perform global consistency filtering on the first operation instruction block, where the first The database operation instruction that satisfies the filtering condition in the operation instruction block is encapsulated into a second operation instruction block, and the second operation instruction block is sent to the distributed database cluster system of the peer end, wherein the filtering condition includes: the database operation The instruction is in the global transaction committed state.
  • the database operation instruction that has not been executed yet can be filtered out from the first operation instruction block, and only the executed database operation instruction is packaged into the second operation instruction block and sent to the second operation instruction block.
  • the distributed database clustering system of the peer end so that the distributed database clustering system of the peer end synchronizes the data that has been executed by the current distributed database clustering system, so that the data synchronized to the standby cluster is always in a consistent state.
  • This embodiment is suitable for a scenario in the disaster recovery system where the RTO indicator is required to be high.
  • the business can take over the peer distributed database cluster at any time, and the RTO can be equal to zero.
  • the distributed database clustering system of the peer end has filtering requirements for receiving data, and only the data objects (databases, tables, etc.) that satisfy certain conditions need to be distributed to the peer.
  • the database clustering system can also deliver the filtering task to the first consistency filtering module 22 at this time.
  • the filtering condition may be increased.
  • the filtering condition may further include: the database operation instruction conforms to a data object filtering rule corresponding to the distributed database cluster system of the peer end.
  • the first consistency filtering module 22 is further configured to execute the database operation instruction in the first operation instruction block in the global transaction uncommitted state. Caching, and adding the cached database operation instruction to the first operation instruction when receiving the first operation instruction block corresponding to the current first primary database sent by the first data synchronization module 14 The first operational instruction block is then globally consistent filtered after the block.
  • the first consistency filtering module 22 can conveniently determine whether the database operation instruction is currently in a globally committed or uncommitted state, and can be distributed.
  • the database cluster system is improved.
  • 3 is a schematic diagram of a second preferred architecture of a distributed database cluster system according to Embodiment 1 of the present disclosure. As shown in FIG. 3, the distributed database cluster system further includes a global transaction management module 32, and the global transaction management module 32 is configured. To manage the global transaction ID that uniquely identifies the global transaction, and to record the status and lifecycle of each global transaction.
  • the first synchronization clock module 12 is configured to periodically request a current active transaction list of each first primary database, and record the current active transaction list and a timestamp for obtaining the current active transaction list in the first primary database. Corresponding synchronization table, and carrying the timestamp and the information of the current active transaction list in the clock synchronization instruction sent to the first primary database.
  • the first consistency filtering module 22 is configured to search for the current active transaction list recorded last time in the synchronization table corresponding to the current first primary database, and the last active record in the current active transaction list
  • the database operation instruction corresponding to the global transaction ID is culled, and the remaining database operation instruction is encapsulated into the second operation instruction block as a database operation instruction that satisfies the filter condition in the global transaction committed state.
  • the first data synchronization module 14 is further configured to receive synchronization location request information sent by the distributed database cluster system of the opposite end, where the synchronization location request information carries the distributed database cluster system and the pair a synchronization position between the distributed database cluster systems of the end; performing encapsulation of the database operation instructions recorded by each of the first primary databases according to the synchronization locations carried by the synchronization location request information.
  • the distributed database cluster system may be the primary distributed database cluster system, which needs to be the initiator of data synchronization. However, after its failure, the distributed database cluster system may become a standby distributed database cluster system. At this time, it also serves as the receiving end of data synchronization. Therefore, as a preferred implementation, the distributed database cluster system
  • Each module also has the following features.
  • the first data synchronization module 14 is further configured to: receive the distributed database cluster system of the peer end.
  • the transmitted operation instruction block wherein the operation instruction block includes a first operation instruction block or a second operation instruction block; and executes the received database operation instruction in the operation instruction block.
  • the first data synchronization module 14 is configured to execute the received database operation instruction in the operation instruction block by:
  • the playback file is parsed, and the database operation instructions in the playback file are split into rows and placed into different working threads for processing.
  • the first data synchronization module 14 is configured to parse the playback file by splitting the database operation instructions in the playback file into different work threads. deal with:
  • the database operation instructions of different transactions are put into different work threads for processing.
  • the first data synchronization module 14 may be further configured to: after executing the received database operation instruction in the operation instruction block, Persist the location where the database operation instruction was executed to a file.
  • the peer distributed database cluster system performs global consistency filtering when the service performs cluster switching.
  • the first data synchronization module 14 may be required to replace the distributed database cluster system.
  • the first consistency filtering module 22 is invoked.
  • the first consistency filtering module 22 is configured to:
  • the data of the first primary database is rolled back to the state recorded when the switching reference time point is The data of the first primary database is restored to a globally consistent state.
  • the first consistency filtering module 22 is configured to roll back data of the first primary database to a state recorded when the switching reference time point is performed, and The data of the first primary database is restored to a globally consistent state:
  • a reverse database operation instruction is generated for the database operation instruction in the global transaction uncommitted state at the time of switching the reference time point, and the reverse database operation instruction is executed.
  • the distributed database clustering system can be used as the receiving end of the data synchronization.
  • the distributed database cluster system may include: a second data synchronization module 42 and a plurality of second database groups 44, wherein Each of the plurality of second database sets 44 includes a second primary database (not shown),
  • the second data synchronization module 42 is configured to receive an operation instruction block sent by the distributed database cluster system of the peer end, where the operation instruction block includes a first operation instruction block or a second operation instruction block, and the first operation instruction
  • the block encapsulates a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database of the peer distributed distributed database cluster system
  • the second operation instruction block encapsulates the distribution of the opposite end
  • Each first primary database of the database cluster system satisfies a database operation instruction of a filter condition in a database operation instruction recorded between two adjacent clock synchronization instructions, wherein the filter condition includes: the database operation instruction is in Global transaction committed status;
  • the distributed database cluster system as the receiving end of the data synchronization can be executed by the second data synchronization module 42 according to the operation instruction block sent by the distributed database cluster system of the data synchronization initiation end, and the data synchronization process is completed. Because the operation instruction block sent in the operation instruction block of the first distributed database cluster system carries the database operation instruction recorded between the adjacent two clock synchronization instructions, thereby ensuring For each primary database, the data packets on which the data synchronization is based all have the same time reference point.
  • the second data synchronization module 42 is configured to execute the received database operation instruction in the operation instruction block by:
  • the playback file is parsed, and the database operation instructions in the playback file are split into rows and placed into different working threads for processing.
  • the second data synchronization module 42 is configured to parse the playback file by splitting the database operation instructions in the playback file into different work threads. deal with:
  • the database operation instructions of different transactions are put into different work threads for processing.
  • the second data synchronization module 42 is further configured to: after executing the received database operation instruction in the operation instruction block, the The location where the execution of the database operation instruction succeeded is persisted to the file.
  • FIG. 5 is a schematic diagram of a preferred architecture of a distributed database cluster system according to Embodiment 2 of the present disclosure.
  • the distributed database cluster system can perform global consistency filtering when the service performs cluster switching.
  • the distributed database cluster system may further include a second consistency filtering module 52.
  • the second data synchronization module 42 is configured to invoke the second consistency filtering module if the distributed database cluster system needs to take over the distributed distributed database cluster system of the opposite end to become a primary distributed database cluster system. 52;
  • the second consistency filtering module 52 is configured to:
  • the data of the second primary database is rolled back to the state recorded when the switching reference time point is The data of the second primary database is restored to a globally consistent state.
  • the second consistency filtering module 52 is configured to roll back data of the second primary database to a state recorded when the switching reference time point is performed, and The data of the second primary database is restored to a globally consistent state:
  • a reverse database operation instruction is generated for the database operation instruction in the global transaction uncommitted state at the time of switching the reference time point, and the reverse database operation instruction is executed.
  • FIG. 6 is a flowchart of a data synchronization method according to Embodiment 3 of the present disclosure.
  • the data synchronization method is applied to a first distributed database cluster system comprising a plurality of first database groups 16, wherein each of the plurality of first database groups 16 includes a first primary database.
  • the method includes:
  • Step S602 the first distributed database cluster system periodically sends a clock synchronization instruction
  • Step S604 the first distributed database cluster system respectively encapsulates the database operation instruction recorded by each first primary database between two adjacent clock synchronization instructions into a first operation instruction block, and sends the first Operation instruction block.
  • the first distributed database cluster system periodically sends a clock synchronization instruction.
  • the operation instructions recorded in each primary database of the first distributed database cluster system are two adjacent clocks.
  • the database operation instructions recorded between the synchronization instructions are packaged into the first operation instruction block and transmitted, thereby ensuring that the data packets on which the data synchronization is based have the same time reference point for each primary database, and thus the related technology can be solved.
  • the data synchronized by different data nodes may not achieve the problem of global consistency at the time point, so that the data records synchronized by different data nodes are based on the same time reference point, and the global consistency on the recorded data is guaranteed.
  • the first distributed database cluster system periodically sends the clock synchronization instruction to each of the first primary databases.
  • the first distributed database cluster system respectively encapsulates a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database into a first operation instruction block, and the method further includes:
  • the first primary database writes the received database operation instruction to the log file of the first primary database, and writes the received clock synchronization instruction to the log file.
  • the first distributed database cluster system respectively encapsulates the database operation instructions recorded by each first primary database between two adjacent clock synchronization instructions into a first operation instruction block, including: the first distributed database cluster
  • the system separately obtains the log file of each first primary database, and encapsulates a database operation instruction sandwiched between two clock synchronization instructions in the log file into the first operation instruction block. It can be seen that in this way, the primary database normally writes the received clock synchronization instruction and the normal database operation instruction to the log file, and the first distributed database cluster system can read the log file and synchronize according to the clock in the log.
  • the instruction splits the database operation instruction, and encapsulates the database operation instruction sandwiched between the two clock synchronization instructions into the first operation instruction block.
  • a more common database operation statement can be taken to generate a clock synchronization instruction, so that the primary database can conveniently write it together with the normal database operation statement to the log file.
  • a preferred database operation statement is SQL, that is, a synchronous clock SQL statement can be used as a clock synchronization instruction, and a database operation instruction also uses a SQL statement.
  • the solution in this embodiment is directed to the operation instructions recorded in each of the main databases, and the database operation instructions recorded between the adjacent two clock synchronization instructions are packaged into the first operation instruction block and sent. Therefore, for each primary database, the data packets on which the data synchronization is based all have the same time reference point, and are globally consistent at the operational command record level of the database.
  • the execution time of each operation command is very small and presents a relatively uniform distribution.
  • the database execution level can basically achieve global consistency. Considering that in an actual distributed database cluster system, there are occasions when the processing tasks in the database cluster are less distributed or the processing resource bandwidth is smaller. At this time, there may be differences in the execution status of different processing tasks in the same database cluster. At this time, at least one of the following two processing methods (final global consistency and real-time global consistency) can be used to ensure global consistency at the database execution level.
  • the first distributed database cluster system sends the first operational instruction block to the second distributed database cluster system.
  • the first operation instruction block sent to the second distributed database cluster system at this time is a database operation instruction recorded between the two synchronization clock signals recorded by the primary database, and the consistency operation filtering is not performed for these database operation instructions.
  • the data synchronization module of the second distributed database cluster system normally synchronizes it to the corresponding primary database of the second distributed database cluster system.
  • the second distributed database cluster system performs global consistency filtering when the service performs cluster switching. This embodiment is applicable to the scenario where the RPO index is high in the disaster recovery system. The data can be efficiently transmitted to the peer cluster and persisted to ensure that the RPO is as small as possible.
  • the first distributed database cluster system performs global consistency filtering on the first operation instruction block, and encapsulates the database operation instruction in the first operation instruction block that satisfies the filtering condition into a second The instruction block is operated, and the second operation instruction block is sent to the second distributed database cluster system, wherein the filtering condition comprises: the database operation instruction is in a global transaction committed state.
  • the filtering condition comprises: the database operation instruction is in a global transaction committed state.
  • the second distributed database cluster system such that the second distributed database cluster system synchronizes the data that has been executed by the first distributed database cluster system, so that the data synchronized to the standby cluster is always in a consistent state.
  • This embodiment is suitable for a scenario in the disaster recovery system where the RTO indicator is required to be high.
  • the business can take over the peer distributed database cluster at any time, and the RTO can be equal to zero.
  • the second distributed database cluster system has screening requirements for receiving data, and only data objects (databases, tables, etc.) that satisfy certain conditions need to be sent to the second distributed.
  • the filtering condition may be increased.
  • the filtering condition may further include: the database operation instruction conforms to a data object filtering rule corresponding to the second distributed database cluster system.
  • the first distributed database cluster system caches database operation instructions in the first operation instruction block that are in a global transaction uncommitted state, and And adding the cached database operation instruction to the next first operation instruction block corresponding to the current first primary database, and then performing global consistency filtering on the next first operation instruction block.
  • the first distributed database cluster system can conveniently judge whether the database operation instruction is currently in a global submitted or uncommitted state, and may The first distributed database cluster system was improved.
  • the first distributed database cluster system manages a global transaction identifier ID capable of uniquely identifying a global transaction, and records a status and a life cycle of each global transaction;
  • the first distributed database cluster system manages to periodically request a current active transaction list of each first primary database, and records the current active transaction list and a time stamp for obtaining the current active transaction list in the first primary Corresponding to the synchronization table of the database, and carrying the timestamp and the information of the current active transaction list in the clock synchronization instruction sent to the first primary database;
  • the first distributed database cluster system performs global consistency filtering on the first operation instruction block, and the database operation instruction that satisfies the filtering condition in the first operation instruction block is encapsulated into a second operation instruction block, including:
  • the first distributed database cluster system searches for the current active transaction list of the last record in the synchronization table corresponding to the current first primary database, and corresponds to the global transaction ID in the current active transaction list that is recorded last time.
  • the database operation instruction is culled, and the remaining database operation instructions are packaged into the second operation instruction block as a database operation instruction that satisfies the filter condition in the global transaction committed state.
  • the synchronization position between the second distributed database cluster system of the peer end and the current first distributed database cluster system can be obtained before the data synchronization processing is performed.
  • the embodiment further provides a storage medium in which a computer program is stored, wherein the computer program is set to execute the method described in this embodiment at runtime.
  • FIG. 7 is a flowchart of a data synchronization method according to Embodiment 4 of the present disclosure.
  • the data synchronization method can be applied to a second distributed database cluster system comprising a plurality of second database sets 44, wherein each of the plurality of second database sets 44 includes a second primary database .
  • the method can include:
  • Step S702 the second distributed database cluster system receives an operation instruction block sent by the first distributed database cluster system, where the operation instruction block includes a first operation instruction block or a second operation instruction block, the first The operation instruction block encapsulates a database operation instruction recorded by each first primary database of the first distributed database cluster system between two adjacent clock synchronization instructions, and the second operation instruction block is encapsulated with the a database operation instruction that satisfies a filter condition in a database operation instruction recorded between two adjacent clock synchronization instructions of each first primary database of a distributed database cluster system, wherein the filter condition includes: the database operation The instruction is in the global transaction committed state;
  • Step S704 the second distributed database cluster system executes the received database operation instruction in the operation instruction block.
  • the second distributed database cluster system which is the receiving end of the data synchronization, can execute according to the operation instruction block sent by the first distributed database cluster system of the originating end of the data synchronization, and complete the data synchronization process. Because the operation instruction block sent in the operation instruction block of the first distributed database cluster system carries the database operation instruction recorded between the adjacent two clock synchronization instructions, thereby ensuring For each primary database, the data packets on which the data synchronization is based all have the same time reference point.
  • the second distributed database cluster system executing the received database operation instruction in the operation instruction block may include:
  • the second distributed database cluster system persists the database operation instruction in the operation instruction block to a playback file
  • the second distributed database cluster system parses the playback file, and the database operation instructions in the playback file are split into rows and placed into different working threads for processing.
  • the second distributed database cluster system parses the playback file, and the database operation instructions in the playback file are split into rows and placed into different working threads for processing.
  • the second distributed database cluster system splits the database operation instruction in the operation instruction block into different data rows according to a table name and a primary key, and the database operation instructions of the same data row form a transaction in a sequential order;
  • the second distributed database cluster system puts the database operation instructions of different transactions into different work threads for processing.
  • the method may further include: The second distributed database cluster system persists the location where the execution of the database operation instruction is successful to the file.
  • the second distributed database cluster system can perform global consistency filtering when the service performs cluster switching.
  • the second distributed database cluster system is a standby distributed database cluster system, in a case where the second distributed database cluster system needs to take over the first distributed database cluster system to become a primary distributed database cluster system.
  • the method may further include:
  • the second distributed database cluster system acquires a synchronization table corresponding to each second primary database, determines a timestamp of the last synchronization of each second primary database according to the synchronization table, and determines an earliest timestamp from the Switching the reference time point;
  • the second distributed database cluster system rolls back data of the second primary database to the switching reference time point The state of the time record and restore the data of the second primary database to a globally consistent state.
  • the second distributed database cluster system rolls back data of the second primary database to a state recorded when the switching reference time point, and data of the second primary database Restoring to a globally consistent state includes:
  • the second distributed database cluster system generates a reverse database operation instruction for the database operation instruction after the switching reference time point, and executes the reverse database operation instruction;
  • the second distributed database cluster system generates a reverse database operation instruction for the database operation instruction in the global transaction uncommitted state when the handover reference time point is performed, and executes the reverse database operation instruction.
  • the embodiment further provides a storage medium in which a computer program is stored, wherein the computer program is set to execute the method described in this embodiment at runtime.
  • This embodiment describes a distributed database data synchronization apparatus and method that ensures global consistency.
  • 8 is a schematic architectural diagram of an apparatus for ensuring globally consistent distributed database data synchronization according to Embodiment 5 of the present disclosure. As shown in FIG. 8, the apparatus for ensuring globally consistent distributed database data synchronization according to the present disclosure includes the following modules:
  • the distributed database cluster is composed of multiple database groups 80.
  • Each database group 80 is composed of multiple independent database nodes.
  • the database node data in the group is completely consistent. Only one node in the group database node provides external write service.
  • As the primary database other data nodes synchronize data to the local through the replication technology between databases, which is called the standby database.
  • the synchronous clock module 82 is configured to periodically send a SQL statement for each primary data node in the distributed database, and the information carried includes the timestamp of the synchronous clock module 82 and the current global active transaction list.
  • the global transaction management module 84 is configured to uniformly manage a globally unique transaction ID in a distributed environment.
  • the global transaction ID uniquely identifies a global transaction, and records the state and life cycle of each global transaction.
  • Each transaction within the cluster requests the global transaction management module 84 to create a unique transaction ID that is inserted into the data row.
  • the management module 86 is configured to uniformly manage the networking information of the distributed database cluster.
  • the consistency filtering module 88 performs global consistency filtering on the data by using the global active transaction ID and filters out the SQL statement containing the specified data object (library, table) according to the filtering rule.
  • the data synchronization module 810 is configured to collect logs of the primary database nodes in the distributed database, generate SQL statements by parsing logs, compress and transfer SQL statement block messages, and persist SQL messages and parallel playback of SQL rows.
  • the synchronization table is first established in the active and standby clusters.
  • the synchronization table mainly contains two pieces of information: timestamp information and a global active transaction list.
  • the synchronous clock module 82 periodically requests the global transaction management module 84 for the current active transaction list. After obtaining the response of the global transaction management module 84, it sends an insert statement to all the primary databases in the primary cluster, and inserts a timestamp for obtaining the current active global transaction list. And current global active transaction list information.
  • the data synchronization module 810 of the primary cluster periodically collects the log files of the primary data nodes in the primary cluster.
  • the log files are reversely parsed, SQL statements are generated, and the SQL statements are streamed by using the synchronous clock.
  • the block is performed, and the consistency module is used to filter the consistency of the SQL statement and the specified rules.
  • the filtered SQL block is compressed into the sending queue.
  • the sending thread then sends the message in the send queue to the data synchronization module 810 in the standby cluster.
  • the data synchronization module 810 in the standby cluster puts the SQL message into the receiving queue in the memory, and calls the writing thread to persist the SQL statement block in the receiving queue to the file, and then starts the playback thread.
  • Split the statement block in the file into several tasks, hand it to the worker thread, and synchronize the data to the database node of the standby cluster.
  • the log files of the data nodes in the main cluster are sliced according to the unified time of the cluster, and the transactions in the slice are uniformly processed on the active/standby cluster according to different service scenarios, and succeed or fail simultaneously;
  • the data on the cluster is consistent in real time or ultimately consistent.
  • the standby cluster can distribute the transactions within the slice according to the table name and the primary key value, and the multiple threads execute in parallel to solve the problem that the playback performance is low due to insufficient concurrency.
  • the distributed database data synchronization method for ensuring global consistency includes the following steps:
  • step S902 when the data synchronization module 810 of the primary cluster is started, the timing acquisition metadata task thread is initialized, and the database node connected to the data synchronization module 810 is ensured to be the primary node in the database group 80.
  • the startup thread periodically reports the status to the management node.
  • the data synchronization module 810 of the standby cluster When the data synchronization module 810 of the standby cluster is started, the concurrent task thread pool, the initialization message writing thread, the SQL playback thread and the garbage cleaning thread are initialized according to the configuration file, and the log synchronization position is first sent to the data synchronization module 810 of the primary cluster after startup.
  • step S904 the data synchronization module 810 of the primary cluster periodically sends the acquisition/synchronization cluster networking data request to the management module 86, and compares the data in the memory after receiving the response from the management module 86. If the data is empty, the memory structure is initialized with the current data; if there is data, the data is compared according to the order of the database group 80, and the data is consistent. If not, the data node is determined according to whether the database node is connected or not.
  • step S906 after the data synchronization module 810 of the primary cluster starts and synchronizes the cluster networking information, the data synchronization module 810 of the standby cluster waits for the synchronization location request information to be pushed. After receiving the synchronization location information, the new task is started according to the current location.
  • Step S908 the data synchronization module 810 of the primary cluster initiates a database connection according to the synchronization location, initializes the memory for parsing the log file, cyclically accepts the log information pushed by the database, and then enters the SQL statement blocking process given in Embodiment 6.
  • the SQL statement block is sent to the consistency filtering module 88 according to the actual deployment.
  • Step S910 performing global consistency filtering and rule filtering on the SQL statement block.
  • the specific procedure is referred to FIG. 12 or FIG. 13 in Embodiment 8.
  • Step S912 when the data synchronization module 810 of the primary cluster receives the SQL statement block request sent by the data synchronization module 810 of the standby cluster, it first determines whether the message is to be retransmitted, and if the retransmission is needed, directly sends the message of the sending queue, if If no retransmission is required, a message is sent from the sending buffer queue to the data synchronization module 810 of the standby cluster.
  • Step S914 after receiving the message packet, the data synchronization module 810 of the standby cluster puts the message into the receiving list. Do message packet verification. Then the SQL statement block message is placed in the write queue, the write thread will persist the message from the write queue to the SQL playback file, and then check if there is a message blocking in the receive queue, if there is, then wake up and hang Thread; no, judge whether the current message group is over, update the data synchronization position, and then cyclically read the write queue.
  • step S916 the SQL playback thread of the standby cluster data synchronization module 810 parses the SQL playback file, parses the transaction statement block between the two synchronization clocks and splits the rows according to the row.
  • the specific method refer to the SQL row parallel processing flow described in Embodiment 7. . After the statement block is successfully played back in parallel, the position of the data playback is persisted to the file for playback exception and used during recovery.
  • step S918 the data cleaning thread of the data synchronization module 810 of the standby cluster periodically cleans up data that has exceeded the saved time and successfully played back.
  • the method provides a unified clock for the entire cluster through the synchronous clock module 82, and performs unified slice processing on the data.
  • the consistency filtering module 88 performs global consistency filtering on the sliced data, and considers the disaster recovery index RPO ( The recovery point target, that is, how much data the system tolerates, and the RTO (recovery time target, that is, the time from the occurrence of the disaster to the recovery of the system), and the service filtering and extraction requirements for the data, the synchronous clock module 82, the global transaction
  • RPO The recovery point target, that is, how much data the system tolerates
  • RTO recovery time target, that is, the time from the occurrence of the disaster to the recovery of the system
  • Different programming of the management module 84, the consistency filtering module 88, and the data synchronization module 810 can efficiently meet various service scenarios such as multi-city, remote disaster recovery, data subscription, and data extraction in the same city, and ensure data clusters in a distributed environment.
  • the global consistency makes the clusters in different
  • FIG. 10 is a schematic diagram of a SQL statement cut packet according to Embodiment 6 of the present disclosure. As shown in Figure 10:
  • the synchronous clock module 82 periodically sends a synchronous clock SQL statement to the database. The corresponding statement will eventually fall into the database log.
  • the data synchronization module 810 parses the log and uses the synchronous clock SQL statement to segment the application SQL.
  • the specific method is that all the SQL between the two synchronized clocks is regarded as a message.
  • the statement block After the statement block is filtered, it is packaged and compressed, and placed in the send buffer queue. Then, the sending thread sends a SQL statement message from the buffer queue to the peer data synchronization module 810.
  • FIG. 11 is a flowchart of SQL statement line parallel processing according to Embodiment 7 of the present disclosure. As shown in Figure 11, the SQL statement block is divided into multiple transactions according to the data line, as follows:
  • the data row is selected according to the table name and the primary key, and the SQL of the same data row is composed into a transaction in sequence, and the SQL of different data rows is handed over to different worker threads for processing.
  • the worker thread processes a batch of SQL statements in parallel to ensure that the playback is successful, and then reads the next SQL statement block.
  • This embodiment describes a specific process of real-time global consistency filtering and final global consistency filtering.
  • step S1202 the latest record is first found from the synchronization table.
  • Step S1204 Obtain a global active transaction list at the time of the latest synchronization from the record.
  • step S1206 the SQL statement block is filtered by using the global active transaction ID.
  • Step S1208 Determine whether there is a configuration data object filtering rule for the globally submitted SQL statement in the statement block. If yes, proceed to step S1210, and if not, submit the sending queue.
  • step S1210 according to the filtering rule, the related SQL statement is filtered out and submitted to the sending queue.
  • step S1212 the SQL statement that is not globally submitted is stored in the buffer queue.
  • step S1214 before the next batch of statements is filtered, the SQL statements in the buffer queue are first merged into the statement block.
  • step S1302 when the active/standby cluster switching needs to be performed, the standby cluster finds the latest synchronous clock record from the synchronization tables of all the data nodes.
  • step S1304 all the latest synchronized clock records are compared, and the time (T0) of the earliest synchronized clock recording of the timestamp is found as the coincident point of the switching.
  • step S1306 all the data nodes that receive the synchronization clock message later than T0 are found.
  • step S1308 by parsing the log file, all reverse SQL statements that are rolled back to the time T0 are generated, and the SQL statement is executed to roll back the node data to the time when the T0 time synchronization clock message is received, so that the data of all the nodes in the cluster are aligned to one. Time point (time T0).
  • step S1310 the current global active transaction ID of the time point (T0) in the synchronous clock table is used to filter out corresponding SQL statements in the log file of the standby cluster data node. Although these statements are submitted on a single point, the global transaction is performed. unsubmitted. These transactions are globally active.
  • step S1312 a reverse SQL statement is generated and executed, and finally the distributed database standby cluster reaches a globally consistent state.
  • This embodiment describes a distributed database asynchronous data synchronization high performance mode (ie, a final global consistency scheme).
  • FIG. 14 is a schematic diagram of a system architecture in a distributed database cluster data synchronization high performance mode according to Embodiment 9 of the present disclosure.
  • the primary distributed database cluster synchronizes data to the standby cluster.
  • the networking of the two clusters is the same. Consistency filtering is not performed during data synchronization, and global consistency filtering is performed only when the service performs cluster switching.
  • Distributed Database Asynchronous Data Synchronization The processing in high performance mode includes the following steps.
  • the database will periodically push the log file to the data synchronization module 810.
  • the data synchronization module 810 parses the log, and treats all the SQL between the two synchronized SQLs as one message block, and encapsulates it into a statement block. After the SQL statement block is packaged and compressed, it is put into the send buffer queue, and then the sending thread sends a SQL statement message from the buffer queue to the peer data synchronization module 810.
  • the data synchronization module 810 of the standby cluster puts the message into the receiving list.
  • the SQL statement block message is persisted to the SQL playback file, and then the SQL playback thread parses the SQL playback file, parses the transaction statement block between the two synchronization messages, splits the line, and plays back the SQL statement in parallel. , to achieve the purpose of synchronizing data.
  • the consistency filtering module 88 is only enabled when an active/standby cluster switching is required.
  • the filtration step is referred to Figure 13.
  • This embodiment is applicable to the scenario where the RPO index is high in the disaster recovery system.
  • the data can be efficiently transmitted to the peer cluster and persisted to ensure that the RPO is as small as possible.
  • This embodiment describes a distributed database cluster data synchronization high performance mode (i.e., a real-time global consistency scheme).
  • FIG. 15 is a schematic diagram of a system architecture in a distributed database cluster data synchronization high performance mode according to Embodiment 10 of the present disclosure.
  • the primary database cluster synchronizes the data to the standby cluster.
  • the networking of the two clusters is the same.
  • Consistency filtering is performed during data synchronization, so that the data synchronized to the standby cluster is consistent in a consistent state.
  • Distributed Database Cluster Data Synchronization High-performance mode processing includes the following steps.
  • the synchronous clock module 82 sends a synchronous SQL statement to the database.
  • the database will periodically push the log file to the data synchronization module 810.
  • the data synchronization module 810 parses the log, and treats all the SQL between the two synchronized SQLs as one message block, and encapsulates it into a statement block.
  • the consistency filtering module 88 filters out the statement in the statement block that is in the global transaction committed state by using the global active transaction ID. For the specific process, refer to FIG.
  • the SQL statement block that has been submitted by the global transaction is packaged and compressed, and then placed in the send buffer queue, and then the sending thread sends a SQL statement message from the buffer queue to the peer data synchronization module 810.
  • the data synchronization module 810 of the standby cluster puts the message into the receiving list.
  • the SQL statement block message is persisted to the SQL playback file, and then the SQL playback thread parses the SQL playback file, parses the transaction statement block between the two synchronization messages, splits the line, and plays back the SQL statement in parallel. , to achieve the purpose of synchronizing data. Since the SQL statement blocks are synchronized globally, the data in the standby cluster database is always in a globally consistent state.
  • This embodiment is suitable for a scenario in the disaster recovery system where the RTO indicator is required to be high.
  • the business can take over the peer distributed database cluster at any time, and the RTO can be equal to zero.
  • This embodiment describes data synchronization (quasi-real time backup) under incremental data subscription based on a distributed database.
  • FIG. 16 is a system architecture diagram of a distributed database quasi-real time backup according to Embodiment 11 of the present disclosure. As shown in FIG. 16 , there are two database clusters in this embodiment, where the remote database cluster serves as a database cluster of the subscription service system cluster, and the two cluster networkings may be inconsistent.
  • the process of quasi-real-time backup under incremental data subscription based on distributed database includes the following steps.
  • the database will periodically push the log file to the data synchronization module 810.
  • the data synchronization module 810 parses the log, and treats all the SQL between the two synchronized SQLs as one message block, and encapsulates it into a statement block.
  • the consistency filtering module 88 uses the global active transaction ID to cache the globally active SQL statement in the statement block into the active statement queue, and merges into the statement fast when filtering the next statement block.
  • the SQL statements filtered out in this way are all statements in which the global transaction has been committed. Then, according to the subscription rules, the data objects (databases, tables) involved are filtered.
  • the SQL statement block that has been submitted by the filtered global transaction is packaged and compressed, and then placed in the send buffer queue, and then the sending thread sends a SQL statement message from the buffer queue to the peer data synchronization module 810.
  • the data synchronization module 810 of the remote cluster puts the message into the receiving list.
  • the SQL statement block message is persisted to the SQL playback file, and then the SQL playback thread parses the SQL playback file, parsing the transaction statement block between the two synchronization messages, and splitting according to the row, according to the cluster group
  • the SQL statement is played back in parallel to achieve the purpose of quasi-real time backup data.
  • This embodiment describes data synchronization (data extraction) based on distributed database delta data.
  • FIG. 17 is a system architecture diagram of data extraction based on distributed database delta data according to Embodiment 12 of the present disclosure.
  • an online online transaction system for generating data
  • an online analysis system OLAP
  • a data warehouse system for data analysis services
  • Big data platform for online data analysis including Hadop-based data warehouse tool Hive, general cluster computing framework (Spark) component for processing structured data, Spark SQL, Hadoop distributed file system (Hadoop Distribute File System) For short, HDFS), etc.
  • the OLTP system imports data into the big data platform for analysis and mining of big data platforms.
  • Data extraction based on distributed database delta data includes the following steps.
  • the synchronous clock module 82 periodically sends a synchronous SQL statement to the database.
  • the OLTP type service database cluster periodically pushes the log file to the data synchronization module 810.
  • the data synchronization module 810 parses the log, and treats all the SQL between the two synchronized SQLs as one message block, and encapsulates it into a statement block.
  • the consistency filtering module 88 uses the global active transaction ID to cache the globally active SQL statement in the statement block into the active statement queue, and merges into the statement fast when filtering the next statement block.
  • the SQL statements filtered out in this way are all statements in which the global transaction has been committed. Then, according to the data extraction rule, the related data objects (database, table) are filtered.
  • the data synchronization module 810 of the big data platform side puts the message into the receiving list.
  • the SQL statement block message is persisted to the SQL playback file, and then the SQL playback thread parses the SQL playback file, parses the transaction statement block between the two synchronization messages, splits the line, and plays back to the large
  • the calculation layer performs SQL calculation, and the data calculation result is updated to the storage system of the big data platform.
  • the distributed database clustering system and the data synchronization method according to the present disclosure can expand the application of the distributed database cluster in the fields of teaching, finance, government, enterprise, internet, etc., saving system resources and improving system performance. Ensure data consistency and enhance user experience. The promotion of distributed databases has a good demonstration significance.
  • modules or steps of the present disclosure described above can be implemented by a general-purpose computing device that can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated as a single integrated circuit module. As such, the disclosure is not limited to any specific combination of hardware and software.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Testing Resistance To Weather, Investigating Materials By Mechanical Methods (AREA)
  • Hardware Redundancy (AREA)

Abstract

本公开提供了分布式数据库集群***、数据同步方法及存储介质。分布式数据库集群***包括:第一同步时钟模块、第一数据同步模块和多个第一数据库组,所述多个第一数据库组中的每个第一数据库组包括一个第一主数据库,所述第一同步时钟模块设置为定期发送时钟同步指令;所述第一数据同步模块设置为分别将每个第一主数据库在所述第一同步时钟模块发送的相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。通过本公开,解决相关技术中不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题,使得不同的数据节点同步的数据记录基于相同的时间参照点,保证记录数据上的全局一致性。

Description

分布式数据库集群***、数据同步方法及存储介质 技术领域
本公开涉及分布式数据库领域,具体而言,涉及分布式数据库集群***、数据同步方法及存储介质。
背景技术
近年来有越来越多的组织开始关注和使用开源数据库产品,例如MySQL(SQL代表Structured Query Language,即结构化查询语言)。随着业务和技术的发展,数据库技术正朝着集群化的方向发展。集群间的数据同步技术是备灾方案的基础技术,开展两个数据中心间高效、一致的数据同步方法的研究具有重大而深远的意义。
目前,在分布式数据库领域内,数据集群间的数据同步,主要还是依托点到点之间的数据迁移。但是,由于服务器和网络的差异等多种因素,集群间不同的数据节点同步的数据可能无法达成时间点上的全局一致性。例如,主集群内A、B两个数据节点将数据同步到备集群内的A’和B’两个数据节点上,在某时刻,A’同步了A在T0时刻的数据,但B’却同步了B在T1时刻的数据。如果此时发生切换,业务需要迁移到备集群上,由于备集群的数据在全局上不是一致的,业务无法立即切换到备集群上。而且,因为没有参考的时间点或时钟,业务数据也无法恢复到一致的时间点上。
除了主备数据库集群之间的切换场景,其他涉及到数据同步的场景下,包括但不限于增量数据订阅、增量数据抽取的场景下,也同样存在集群间不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题。
发明内容
本公开实施例提供了分布式数据库集群***、数据同步方法及存储介质,以至少解决相关技术中不同的数据节点同步的数据可能无法达成时间 点上的全局一致性的问题。
根据本公开的一个实施例,提供了一种分布式数据库集群***,包括:第一同步时钟模块、第一数据同步模块和多个第一数据库组,其中,所述多个第一数据库组中的每个第一数据库组包括一个第一主数据库,所述第一同步时钟模块设置为定期发送时钟同步指令;所述第一数据同步模块设置为分别将每个第一主数据库在所述第一同步时钟模块发送的相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。
根据本公开的另一个实施例,提供了一种分布式数据库集群***,包括:第二数据同步模块和多个第二数据库组,其中,所述多个第二数据库组中的每个第二数据库组包括一个第二主数据库,所述第二数据同步模块设置为接收对端的分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块,所述第一操作指令块封装有所述对端的分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令,所述第二操作指令块封装有所述对端的分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令中满足过滤条件的数据库操作指令,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态;执行接收的所述操作指令块中的数据库操作指令。
根据本公开的又一个实施例,提供了一种数据同步方法,应用于包含多个第一数据库组的第一分布式数据库集群***,其中,所述多个第一数据库组中的每个第一数据库组包括一个第一主数据库,所述方法包括:所述第一分布式数据库集群***定期发送时钟同步指令;所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。
根据本公开的再一个实施例,提供了一种数据同步方法,应用于包含 多个第二数据库组的第二分布式数据库集群***,其中,所述多个第二数据库组中的每个第二数据库组包括一个第二主数据库,所述方法包括:所述第二分布式数据库集群***接收第一分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块,所述第一操作指令块封装有所述第一分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令,所述第二操作指令块封装有所述第一分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令中满足过滤条件的数据库操作指令,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态;所述第二分布式数据库集群***执行接收的所述操作指令块中的数据库操作指令。
根据本公开的再一个实施例,还提供了一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行上述任一项方法实施例中的步骤。
根据本公开的又一个实施例,还提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行上述任一项方法实施例中的步骤。
通过本公开,由于分布式数据库集群***内部定期发送时钟同步指令,而数据同步过程中,针对于每个主数据库所记录的操作指令,都是将相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块并发送,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,因此,可以解决相关技术中不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题,使得不同的数据节点同步的数据记录基于相同的时间参照点,保证记录数据上的全局一致性。
附图说明
此处所说明的附图用来提供对本公开的进一步理解,构成本申请的一部分,本公开的示意性实施例及其说明用于解释本公开,并不构成对本公 开的不当限定。在附图中:
图1是根据本公开实施例1的分布式数据库集群***的架构示意图;
图2是根据本公开实施例1的分布式数据库集群***的第一优选架构示意图;
图3是根据本公开实施例1的分布式数据库集群***的第二优选架构示意图;
图4是根据本公开实施例2的分布式数据库集群***的架构示意图;
图5是根据本公开实施例2的分布式数据库集群***的优选架构示意图;
图6是根据本公开实施例3的数据同步方法的流程图;
图7是根据本公开实施例4的数据同步方法的流程图;
图8是根据本公开实施例5的确保全局一致性的分布式数据库数据同步的装置的架构示意图;
图9是根据本公开实施例5的数据同步方法的详细工作流程图;
图10是根据本公开实施例6的SQL语句切分组包的示意图;
图11是根据本公开实施例7的SQL语句行并行处理的流程图;
图12是根据本公开实施例8的实时全局一致性过滤的流程图;
图13是根据本公开实施例8的最终全局一致性过滤的流程图;
图14是根据本公开实施例9的分布式数据库集群数据同步高性能模式下的***架构示意图;
图15是根据本公开实施例10的分布式数据库集群数据同步高性能模式下的***架构示意图;
图16是根据本公开实施例11的分布式数据库准实时备份的***架构图;以及
图17是根据本公开实施例12的基于分布式数据库增量数据的数据抽 取的***架构图。
具体实施方式
分布式数据库集群***由多个数据库组构成,每个数据库组由多个独立的数据库节点构成,组内的数据库节点数据是完全一致的,组内数据库节点只有一个节点对外提供写服务,称为主数据库,其他数据节点通过数据库间的复制技术,将数据同步到本地,称为备数据库。对外以数据服务的方式向应用提供数据库功能,对应用提供统一的标准接口,例如SQL接口。
针对于分布式数据库集群***之间的同步,例如,数据集群间的数据同步、增量数据订阅、增量数据抽取等等,相关技术中的数据同步方案往往存在无法提供全局一致性的问题和缺陷。
针对以上问题,本公开提出了分布式数据库集群***、数据同步方法及存储介质。下文中将参考附图并结合实施例来详细说明本公开。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
需要说明的是,本公开的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。
实施例1
该实施例提供了一种分布式数据库集群***。图1是根据本公开实施例1的分布式数据库集群***的架构示意图,如图1所示,该分布式数据库集群***可以包括:第一同步时钟模块12、第一数据同步模块14和多个第一数据库组16,其中,所述多个第一数据库组16中的每个第一数据库组16包括一个第一主数据库(图中未示出),
所述第一同步时钟模块12设置为定期发送时钟同步指令;
所述第一数据同步模块14设置为分别将每个第一主数据库在所述第 一同步时钟模块12发送的相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。
通过以上方案,分布式数据库集群***中第一同步时钟模块12定期发送时钟同步指令,而第一数据同步模块14在数据同步过程中,针对于每个主数据库所记录的操作指令,都是将相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块并发送,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,因此,可以解决相关技术中不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题,使得不同的数据节点同步的数据记录基于相同的时间参照点,保证记录数据上的全局一致性。
对于第一数据同步模块14如何确定每个第一主数据库在所述第一同步时钟模块12发送的相邻两个时钟同步指令之间所记录的数据库操作指令是哪些指令,进而将其封装成第一操作指令块,在分布式数据库集群***内部,存在很多方式可以实现这样的目标。以下给出一个容易实现且无需对现有的分布式数据库集群***的处理模式进行较大变动的实施方式。
作为一个示例性实施方式,所述第一同步时钟模块12设置为定期向每个第一主数据库发送所述时钟同步指令;所述第一主数据库设置为将接收到的数据库操作指令写入所述第一主数据库的日志文件,以及将接收到的所述时钟同步指令写入所述日志文件;所述第一数据同步模块14设置为分别获取每个第一主数据库的所述日志文件,将所述日志文件中夹在两条时钟同步指令之间的数据库操作指令封装成所述第一操作指令块,并发送所述第一操作指令块。可见,通过这种方式,主数据库将接收到的时钟同步指令和普通的数据库操作指令都正常写入日志文件,所述第一数据同步模块14可以读取日志文件并根据日志中的时钟同步指令对数据库操作指令进行切分,将夹在两条时钟同步指令之间的数据库操作指令封装成所述第一操作指令块。为了便于主数据库的日志记录,可以采取较常见的数据库操作语句来生成时钟同步指令,这样,主数据库可以很方便地将其连同普通数据库操作语句写入日志文件。对于目前的分布式数据库集群*** 而言,一种比较优选的数据库操作语句是SQL,即,可以采用同步时钟SQL语句作为时钟同步指令,数据库操作指令也采用SQL语句。
如上所述,本实施例中的方案针对于每个主数据库所记录的操作指令,都是将相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块并发送,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,在数据库的操作命令记录层面达到全局一致。在数据库集群中处理任务分布较均衡或处理资源带宽充分的情况下,各个操作命令执行时长非常小且呈现比较均匀的分布,此时在数据库执行层面基本也能够达到全局一致。考虑到在实际的分布式数据库集群***中,偶尔会存在数据库集群中处理任务分布较不均衡或处理资源带宽较小的情况,此时,可能会存在同一数据库集群中不同处理任务执行状态的差异,此时,可以采用以下两种处理方式(最终全局一致和实时全局一致)至少之一来保证在数据库执行层面的全局一致。
最终全局一致方案
在该方案中,所述第一数据同步模块14设置为发送所述第一操作指令块给对端的分布式数据库集群***。此时发送给对端的分布式数据库集群***的第一操作指令块是主数据库记录的在两个同步时钟信号之间的数据库操作指令,对于这些数据库操作指令不会进行一致性过滤。对端的分布式数据库集群***的数据同步模块正常将其同步到对端的分布式数据库集群***的对应的主数据库中。但是,对端的分布式数据库集群***在业务进行集群切换时进行一次全局一致性过滤。该实施例适合灾备***中对RPO指标要求高的场景,数据可以高效的传输到对端集群并持久化,保证RPO尽可能的小。该处理方式下的在业务进行集群切换时在同步接受端进行一次全局一致性过滤的具体实施方式可以查阅实施例8。
实时全局一致方案
根据该实时全局一致方案,在分布式数据库集群***新增第一一致性 过滤模块22。图2是根据本公开实施例1的分布式数据库集群***的第一优选架构示意图,如图2所示,该分布式数据库集群***还包括第一一致性过滤模块22。
所述第一数据同步模块14设置为发送所述第一操作指令块给所述第一一致性过滤模块22。所述第一一致性过滤模块22设置为接收所述第一数据同步模块14发送的所述第一操作指令块,对所述第一操作指令块进行全局一致性过滤,将所述第一操作指令块中满足过滤条件的数据库操作指令封装成第二操作指令块,并将所述第二操作指令块发送到对端的分布式数据库集群***,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态。通过该方案,可以从第一操作指令块之中筛除尚未执行完毕(即处于全局事务未提交状态)的数据库操作指令,仅仅保留已执行完毕的数据库操作指令封装成第二操作指令块发送到对端的分布式数据库集群***,这样,对端的分布式数据库集群***同步的是当前分布式数据库集群***已经执行完毕的数据,这样同步到备集群上的数据一直处在一致状态中。该实施例适合灾备***中对RTO指标要求高的场景。业务可以在任何时候接管对端分布式数据库集群,RTO可以等于零。该处理方式下的在同步发起端实时进行全局一致性过滤的具体实施方式可以查阅实施例8。
考虑到增量数据订阅、增量数据抽取的场景中,对端的分布式数据库集群***对接收数据有筛选需求,仅仅满足特定条件的数据对象(数据库、表等)才需要发送到对端的分布式数据库集群***,此时可以将该过滤任务也交给所述第一一致性过滤模块22。可以增加过滤条件,例如,所述过滤条件还可以包括:所述数据库操作指令符合所述对端的分布式数据库集群***所对应的数据对象过滤规则。
对于尚未执行完毕(即处于全局事务未提交状态)的数据库操作指令,所述第一一致性过滤模块22还设置为将所述第一操作指令块中处于全局事务未提交状态的数据库操作指令进行缓存,并在下一次接收到所述第一数据同步模块14发送的对应于当前第一主数据库的所述第一操作指令块 时,将缓存的所述数据库操作指令加入所述第一操作指令块后再对所述第一操作指令块进行全局一致性过滤。
为了较方便的在分布式数据库集群***内部进行全局的事务管理,从而第一一致性过滤模块22能够很方便地进行数据库操作指令当前处于全局已提交还是未提交的状态的判断,可以对分布式数据库集群***进行改进。图3是根据本公开实施例1的分布式数据库集群***的第二优选架构示意图,如图3所示,该分布式数据库集群***还包括全局事务管理模块32,所述全局事务管理模块32设置为管理能够唯一标识全局事务的全局事务标识ID,并记录每个全局事务的状态和生命周期。
所述第一同步时钟模块12设置为定期请求每个第一主数据库的当前活跃事务列表,将所述当前活跃事务列表和获取所述当前活跃事务列表的时间戳记录在所述第一主数据库对应的同步表中,并将所述时间戳和所述当前活跃事务列表的信息携带在发往所述第一主数据库的所述时钟同步指令中。所述第一一致性过滤模块22设置为查找当前第一主数据库对应的所述同步表中最近一次记录的所述当前活跃事务列表,并将最近一次记录的所述当前活跃事务列表中的全局事务ID所对应的数据库操作指令剔除,将剩余的数据库操作指令作为满足处于全局事务已提交状态的过滤条件的数据库操作指令封装成所述第二操作指令块。
作为一种优选的实施方式,在进行数据同步处理之前,可以获得对端的分布式数据库集群***的与当前分布式数据库集群***之间的同步位置。此时,所述第一数据同步模块14还设置为接收对端的分布式数据库集群***发来的同步位置请求信息,其中,所述同步位置请求信息携带所述分布式数据库集群***与所述对端的分布式数据库集群***之间的同步位置;根据所述同步位置请求信息携带的所述同步位置执行对每个第一主数据库所记录的数据库操作指令的封装。
以上所描述的是分布式数据库集群***在作为数据同步的发起端时,各个模块所执行的功能。需要注意的是,分布式数据库集群***在实际应 用中,其角色是经常需要变换的,例如,分布式数据库集群***当前可能是主分布式数据库集群***,此时需要作为数据同步的发起端。但是,在其故障后,分布式数据库集群***可能变为备分布式数据库集群***,此时,它又要作为数据同步的接受端,因此,作为一种优选的实施方式,分布式数据库集群***的各个模块还具有以下功能。
作为数据同步的接受端,接收到发起端发来的数据同步包,需要执行同步包内容完成数据同步,此时,所述第一数据同步模块14还设置为:接收对端的分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块;执行接收的所述操作指令块中的数据库操作指令。
作为一种示例性实施方式,所述第一数据同步模块14设置为通过以下方式执行接收的所述操作指令块中的所述数据库操作指令:
将所述操作指令块中的所述数据库操作指令持久化到回放文件中;
解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理。
作为一种示例性实施方式,所述第一数据同步模块14设置为通过以下方式解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理:
按照表名和主键将所述操作指令块中的所述数据库操作指令拆分成不同的数据行,同一数据行的所述数据库操作指令按照先后顺序组成一个事务;
将不同事务的所述数据库操作指令放入不同的工作线程进行处理。
为了以备回放失败时的任务回复,作为一种示例性实施方式,所述第一数据同步模块14还可以设置为:在执行接收的所述操作指令块中的所述数据库操作指令成功后,将执行数据库操作指令成功的位置持久化到文件中。
如上述最终全局一致方案所述,对端的分布式数据库集群***在业务 进行集群切换时进行一次全局一致性过滤。考虑到所述分布式数据库集群***作为所述对端的分布式数据库集群***的备分布式数据库集群***的情况,可以让所述第一数据同步模块14在所述分布式数据库集群***需要接替所述对端的分布式数据库集群***成为主分布式数据库集群***的情况下,调用第一一致性过滤模块22。
在该示例性实施方式中,所述第一一致性过滤模块22设置为:
获取每个第一主数据库对应的同步表,根据所述同步表确定每个第一主数据库的最近一次同步的时间戳,并从中确定出最早的时间戳作为切换参考时间点;
对于最近一次同步的时间戳晚于所述切换参考时间点的每个第一主数据库,将所述第一主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第一主数据库的数据恢复到全局一致的状态。
作为一种示例性实施方式,所述第一一致性过滤模块22设置为通过以下方式将所述第一主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第一主数据库的数据恢复到全局一致的状态:
对于所述切换参考时间点之后的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令;
对于所述切换参考时间点时处于全局事务未提交状态的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令。
实施例2
该实施例提供了另一种分布式数据库集群***。该分布式数据库集群***可以作为数据同步的接受端,当然,在其同时被赋予了数据同步的发起端的功能的情况下,其同样也可以作为数据同步的发起端,此时可以参照实施例1。图4是根据本公开实施例2的分布式数据库集群***的架构示意图,如图4所示,该分布式数据库集群***可以包括:第二数据同步模块42和多个第二数据库组44,其中,所述多个第二数据库组44中的每个第二数据库组44包括一个第二主数据库(图中未示出),
所述第二数据同步模块42设置为接收对端的分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块,所述第一操作指令块封装有所述对端的分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令,所述第二操作指令块封装有所述对端的分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令中满足过滤条件的数据库操作指令,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态;
执行接收的所述操作指令块中的数据库操作指令。
通过以上方案,作为数据同步的接受端的分布式数据库集群***可以通过所述第二数据同步模块42按照数据同步的发起端的分布式数据库集群***发来的操作指令块进行执行,完成数据同步过程。由于发来的操作指令块中,针对于第一分布式数据库集群***每个主数据库所记录的操作指令,携带的都是相邻两个时钟同步指令之间所记录的数据库操作指令,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,因此,可以解决相关技术中不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题,使得不同的数据节点同步的数据记录基于相同的时间参照点,保证记录数据上的全局一致性。
作为一种示例性实施方式,所述第二数据同步模块42设置为通过以下方式执行接收的所述操作指令块中的所述数据库操作指令:
将所述操作指令块中的所述数据库操作指令持久化到回放文件中;
解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理。
作为一种示例性实施方式,所述第二数据同步模块42设置为通过以下方式解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理:
按照表名和主键将所述操作指令块中的所述数据库操作指令拆分成 不同的数据行,同一数据行的所述数据库操作指令按照先后顺序组成一个事务;
将不同事务的所述数据库操作指令放入不同的工作线程进行处理。
为了以备回放失败时的任务回复,作为一种示例性实施方式,所述第二数据同步模块42还设置为:在执行接收的所述操作指令块中的所述数据库操作指令成功后,将执行数据库操作指令成功的位置持久化到文件中。
图5是根据本公开实施例2的分布式数据库集群***的优选架构示意图。针对于最终全局一致方案,该分布式数据库集群***在业务进行集群切换时可以进行一次全局一致性过滤。考虑到所述分布式数据库集群***作为备分布式数据库集群***的情况,如图5所示,该分布式数据库集群***还可以包括第二一致性过滤模块52,
所述第二数据同步模块42设置为在所述分布式数据库集群***需要接替所述对端的分布式数据库集群***成为主分布式数据库集群***的情况下,调用所述第二一致性过滤模块52;
所述第二一致性过滤模块52设置为:
获取每个第二主数据库对应的同步表,根据所述同步表确定每个第二主数据库的最近一次同步的时间戳,并从中确定出最早的时间戳作为切换参考时间点;
对于最近一次同步的时间戳晚于所述切换参考时间点的每个第二主数据库,将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态。
作为一种示例性实施方式,所述第二一致性过滤模块52设置为通过以下方式将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态:
对于所述切换参考时间点之后的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令;
对于所述切换参考时间点时处于全局事务未提交状态的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令。
实施例3
本实施例描述了数据同步的发起端的处理流程。图6是根据本公开实施例3的数据同步方法的流程图。该数据同步方法应用于包含多个第一数据库组16的第一分布式数据库集群***,其中,所述多个第一数据库组16中的每个第一数据库组16包括一个第一主数据库。如图6所示,所述方法包括:
步骤S602,所述第一分布式数据库集群***定期发送时钟同步指令;
步骤S604,所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。
通过以上方案,第一分布式数据库集群***定期发送时钟同步指令,在数据同步过程中,针对于第一分布式数据库集群***每个主数据库所记录的操作指令,都是将相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块并发送,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,因此,可以解决相关技术中不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题,使得不同的数据节点同步的数据记录基于相同的时间参照点,保证记录数据上的全局一致性。
对于如何确定每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令是哪些指令,进而将其封装成第一操作指令块,在第一分布式数据库集群***内部,存在很多方式可以实现这样的目标。以下给出一个容易实现且无需对现有的分布式数据库集群***的处理模式进行较大变动的实施方式。
作为一个示例性实施方式,所述第一分布式数据库集群***定期向每个第一主数据库发送所述时钟同步指令。所述第一分布式数据库集群*** 分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块之前,所述方法还包括:所述第一主数据库将接收到的数据库操作指令写入所述第一主数据库的日志文件,以及将接收到的所述时钟同步指令写入所述日志文件。所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块包括:所述第一分布式数据库集群***分别获取每个第一主数据库的所述日志文件,将所述日志文件中夹在两条时钟同步指令之间的数据库操作指令封装成所述第一操作指令块。可见,通过这种方式,主数据库将接收到的时钟同步指令和普通的数据库操作指令都正常写入日志文件,所述第一分布式数据库集群***可以读取日志文件并根据日志中的时钟同步指令对数据库操作指令进行切分,将夹在两条时钟同步指令之间的数据库操作指令封装成所述第一操作指令块。为了便于主数据库的日志记录,可以采取较常见的数据库操作语句来生成时钟同步指令,这样,主数据库可以很方便地将其连同普通数据库操作语句写入日志文件。对于目前的分布式数据库集群***而言,一种比较优选的数据库操作语句是SQL,即,可以采用同步时钟SQL语句作为时钟同步指令,数据库操作指令也采用SQL语句。
如上所述,本实施例中的方案针对于每个主数据库所记录的操作指令,都是将相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块并发送,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,在数据库的操作命令记录层面达到全局一致。在数据库集群中处理任务分布较均衡或处理资源带宽充分的情况下,各个操作命令执行时长非常小且呈现比较均匀的分布,此时在数据库执行层面基本也能够达到全局一致。考虑到在实际的分布式数据库集群***中,偶尔会存在数据库集群中处理任务分布较不均衡或处理资源带宽较小的情况,此时,可能会存在同一数据库集群中不同处理任务执行状态的差异,此时,可以采用以下两种处理方式(最终全局一致和实时全局一致)至少之一来保证在数据库执行层面的全局一致。
最终全局一致方案
在该方案中,所述第一分布式数据库集群***发送所述第一操作指令块给第二分布式数据库集群***。此时发送给第二分布式数据库集群***的第一操作指令块是主数据库记录的在两个同步时钟信号之间的数据库操作指令,对于这些数据库操作指令不会进行一致性过滤。第二分布式数据库集群***的数据同步模块正常将其同步到第二分布式数据库集群***的对应的主数据库中。但是,第二分布式数据库集群***在业务进行集群切换时进行一次全局一致性过滤。该实施例适合灾备***中对RPO指标要求高的场景,数据可以高效的传输到对端集群并持久化,保证RPO尽可能的小。该处理方式下的在业务进行集群切换时在同步接受端进行一次全局一致性过滤的具体实施方式可以查阅实施例8。
实时全局一致方案
根据该实时全局一致方案,所述第一分布式数据库集群***对所述第一操作指令块进行全局一致性过滤,将所述第一操作指令块中满足过滤条件的数据库操作指令封装成第二操作指令块,并将所述第二操作指令块发送到第二分布式数据库集群***,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态。通过该方案,可以从第一操作指令块之中筛除尚未执行完毕(即处于全局事务未提交状态)的数据库操作指令,仅仅保留已执行完毕的数据库操作指令封装成第二操作指令块发送到第二分布式数据库集群***,这样,第二分布式数据库集群***同步的是当前第一分布式数据库集群***已经执行完毕的数据,这样同步到备集群上的数据一直处在一致状态中。该实施例适合灾备***中对RTO指标要求高的场景。业务可以在任何时候接管对端分布式数据库集群,RTO可以等于零。该处理方式下的在同步发起端实时进行全局一致性过滤的具体实施方式可以查阅实施例8。
考虑到增量数据订阅、增量数据抽取的场景中,第二分布式数据库集群***对接收数据有筛选需求,仅仅满足特定条件的数据对象(数据库、 表等)才需要发送到第二分布式数据库集群***。因此,可以增加过滤条件,例如,所述过滤条件还可以包括:所述数据库操作指令符合所述第二分布式数据库集群***所对应的数据对象过滤规则。
对于尚未执行完毕(即处于全局事务未提交状态)的数据库操作指令,所述第一分布式数据库集群***将所述第一操作指令块中处于全局事务未提交状态的数据库操作指令进行缓存,并将缓存的所述数据库操作指令加入对应于当前第一主数据库的下一个第一操作指令块后再对所述下一个第一操作指令块进行全局一致性过滤。
为了较方便的在第一分布式数据库集群***内部进行全局的事务管理,从而第一分布式数据库集群***能够很方便地进行数据库操作指令当前处于全局已提交还是未提交的状态的判断,可以对第一分布式数据库集群***进行改进。所述第一分布式数据库集群***管理能够唯一标识全局事务的全局事务标识ID,并记录每个全局事务的状态和生命周期;
所述第一分布式数据库集群***管理定期向请求每个第一主数据库的当前活跃事务列表,将所述当前活跃事务列表和获取所述当前活跃事务列表的时间戳记录在所述第一主数据库对应的同步表中,并将所述时间戳和所述当前活跃事务列表的信息携带在发往所述第一主数据库的所述时钟同步指令中;
所述第一分布式数据库集群***对所述第一操作指令块进行全局一致性过滤,将所述第一操作指令块中满足过滤条件的数据库操作指令封装成第二操作指令块包括:所述第一分布式数据库集群***查找当前第一主数据库对应的所述同步表中最近一次记录的所述当前活跃事务列表,并将最近一次记录的所述当前活跃事务列表中的全局事务ID所对应的数据库操作指令剔除,将剩余的数据库操作指令作为满足处于全局事务已提交状态的过滤条件的数据库操作指令封装成所述第二操作指令块。
作为一种优选的实施方式,在进行数据同步处理之前,可以获得对端的第二分布式数据库集群***的与当前第一分布式数据库集群***之间 的同步位置。所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块之前,该方法还可以包括:所述第一分布式数据库集群***接收第二分布式数据库集群***发来的同步位置请求信息,其中,所述同步位置请求信息携带所述第一分布式数据库集群***与所述第二分布式数据库集群***之间的同步位置;所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块可以包括:所述第一分布式数据库集群***根据所述同步位置请求信息携带的所述同步位置执行对每个第一主数据库所记录的数据库操作指令的封装。
本实施例还提供了一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行本实施例所述的方法。
实施例4
本实施例描述了数据同步的接受端的处理流程。图7是根据本公开实施例4的数据同步方法的流程图。该数据同步方法可以应用于包含多个第二数据库组44的第二分布式数据库集群***,其中,所述多个第二数据库组44中的每个第二数据库组44包括一个第二主数据库。所述方法可以包括:
步骤S702,所述第二分布式数据库集群***接收第一分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块,所述第一操作指令块封装有所述第一分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令,所述第二操作指令块封装有所述第一分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令中满足过滤条件的数据库操作指令,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态;
步骤S704,所述第二分布式数据库集群***执行接收的所述操作指 令块中的数据库操作指令。
通过以上方案,作为数据同步的接受端的第二分布式数据库集群***可以按照数据同步的发起端的第一分布式数据库集群***发来的操作指令块进行执行,完成数据同步过程。由于发来的操作指令块中,针对于第一分布式数据库集群***每个主数据库所记录的操作指令,携带的都是相邻两个时钟同步指令之间所记录的数据库操作指令,从而保证针对于每个主数据库,数据同步所基于的数据包都具有相同的时间参照点,因此,可以解决相关技术中不同的数据节点同步的数据可能无法达成时间点上的全局一致性的问题,使得不同的数据节点同步的数据记录基于相同的时间参照点,保证记录数据上的全局一致性。
作为一种示例性实施方式,所述第二分布式数据库集群***执行接收的所述操作指令块中的数据库操作指令可以包括:
所述第二分布式数据库集群***将所述操作指令块中的所述数据库操作指令持久化到回放文件中;
所述第二分布式数据库集群***解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理。
作为一种示例性实施方式,所述第二分布式数据库集群***解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理可以包括:
所述第二分布式数据库集群***按照表名和主键将所述操作指令块中的所述数据库操作指令拆分成不同的数据行,同一数据行的所述数据库操作指令按照先后顺序组成一个事务;
所述第二分布式数据库集群***将不同事务的所述数据库操作指令放入不同的工作线程进行处理。
为了以备回放失败时的任务回复,作为一种示例性实施方式,在所述第二分布式数据库集群***执行接收的所述操作指令块中的所述数据库操作指令成功之后,还可以包括:所述第二分布式数据库集群***将执行 数据库操作指令成功的位置持久化到文件中。
针对于最终全局一致方案,该第二分布式数据库集群***在业务进行集群切换时可以进行一次全局一致性过滤。考虑到所述第二分布式数据库集群***作为备分布式数据库集群***,在所述第二分布式数据库集群***需要接替所述第一分布式数据库集群***成为主分布式数据库集群***的情况下,所述方法还可以包括:
所述第二分布式数据库集群***获取每个第二主数据库对应的同步表,根据所述同步表确定每个第二主数据库的最近一次同步的时间戳,并从中确定出最早的时间戳作为切换参考时间点;
对于最近一次同步的时间戳晚于所述切换参考时间点的每个第二主数据库,所述第二分布式数据库集群***将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态。
作为一种示例性实施方式,所述第二分布式数据库集群***将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态包括:
所述第二分布式数据库集群***对于所述切换参考时间点之后的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令;
所述第二分布式数据库集群***对于所述切换参考时间点时处于全局事务未提交状态的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令。
本实施例还提供了一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行本实施例所述的方法。
实施例5
本实施例描述了确保全局一致性的分布式数据库数据同步装置及方法。图8是根据本公开实施例5的确保全局一致性的分布式数据库数据同步的装置的架构示意图。如图8所示,本公开所述确保全局一致性的分布 式数据库数据同步的装置包括以下模块:
分布式数据库集群由多个数据库组80构成,每个数据库组80由多个独立的数据库节点构成,组内的数据库节点数据是完全一致的,组内数据库节点只有一个节点对外提供写服务,称为主数据库,其他数据节点通过数据库间的复制技术,将数据同步到本地,称为备数据库。对外以数据服务的方式向应用提供数据库功能,对应用提供统一的标准SQL接口。
同步时钟模块82,设置为定时为分布式数据库内的每个主数据节点发送一条SQL语句,携带的信息有同步时钟模块82的时间戳以及当前全局活跃事务列表。
全局事务管理模块84,设置为统一管理分布式环境下的全局唯一的事务ID,全局事务ID唯一标识一个全局事务,同时记录每个全局事务的状态和生命周期。集群内每个事务都会向全局事务管理模块84申请创建唯一的事务ID,***到数据行中。
管理模块86,设置为统一管理分布式数据库集群的组网信息。
一致性过滤模块88,利用全局活跃事务ID对数据进行全局一致性过滤和根据过滤规则,过滤出含有指定数据对象(库、表)的SQL语句。
数据同步模块810,设置为收集分布式数据库内主数据库节点的日志,通过解析日志生成SQL语句,SQL语句块消息打包压缩传输,SQL消息持久化以及SQL行并行回放。
基于以上的架构,在数据同步过程中,首先在主备集群中先建立同步表,同步表主要含两个信息:时间戳信息和全局活跃事务列表。同步时钟模块82定时向全局事务管理模块84请求当前活跃事务列表,获得全局事务管理模块84的响应后,向主集群中的所有主数据库发送一条***语句,***获取当前活跃全局事务列表的时间戳和当前全局活跃事务列表信息。主集群的数据同步模块810定时会收集主集群内主数据节点的日志文件,在收到备集群的同步请求后,会对日志文件进行反向解析,生成SQL语句,利用同步时钟将SQL语句流进行分块,并利用一致性模块对SQL语 句记性一致性和指定规则的过滤,最后将过滤后的SQL语句块压缩放进发送队列中。然后发送线程将发送队列中的消息发送到备集群中的数据同步模块810中。备集群中的数据同步模块810在接收到SQL块消息后,将SQL消息放入内存中的接收队列,并调用写入线程将接收队列中的SQL语句块持久化到文件中,再启动回放线程将文件中的语句块拆分成若干个任务,交给工作线程,将数据同步到备集群的数据库节点上。
通过以上过程,将主集群内各数据节点的日志文件按照集群统一的时间进行切片,切片中的事务在根据业务场景的不同在主/备集群上进行统一处理,同时成功或者同时失败;保证备集群上的数据是实时一致或是最终一致。在此基础上,备集群可以将切片内事务按照表名和主键值进行分发,多线程并行执行,解决并发不足造成回放性能低的问题。
图9是根据本公开实施例5的数据同步方法的详细工作流程图。如图9所示,该确保全局一致性的分布式数据库数据同步方法包括以下步骤:
步骤S902,主集群的数据同步模块810启动时,会初始化定时获取元数据任务线程,保证数据同步模块810连接的数据库节点为数据库组80中的主节点。启动线程定时向管理节点上报状态。备集群的数据同步模块810启动时,根据配置文件初始化并发工作线程池,初始化消息写入线程,SQL回放线程以及垃圾清理线程,启动后首先向主集群的数据同步模块810发送日志同步位置。
步骤S904,主集群的数据同步模块810会定时发送获取/同步集群组网数据请求到管理模块86,收到管理模块86的响应后对比内存中的数据。如果数据为空,则用当前数据初始化内存结构;如果有数据则根据数据库组80顺序比较数据是否一致,一致则不处理,若不一致,则根据是否已连接数据库节点来决定是否立即更新数据信息。
步骤S906,主集群的数据同步模块810启动并同步好集群组网信息后,等待备集群的数据同步模块810推送同步位置请求信息,接收到同步位置信息后,按照当前位置开始新任务。
步骤S908,主集群的数据同步模块810,按照同步位置发起数据库连接,初始化内存用于解析日志文件,循环接受数据库推送的日志信息,然后进入实施例6中所给出的SQL语句分块流程。根据实际部署将SQL语句块发送到一致性过滤模块88。
步骤S910,对SQL语句块进行全局一致性过滤和规则过滤。具体流程参考实施例8中的图12或图13。
步骤S912,主集群的数据同步模块810收到备集群的数据同步模块810发送的SQL语句块请求时,先判断消息是否要重发,如果需要重发则直接将发送队列的消息发送出去,如果不需要重发,则从发送缓存队列中取消息发送给备集群的数据同步模块810。
步骤S914,备集群的数据同步模块810接到消息包后,把消息放入接收列表中。做消息包校验。然后SQL语句块消息被放入写入队列,写入线程就会从写入队列中将消息持久化到SQL回放文件中,然后检查是否有消息阻塞在接收队列中,如果有,则唤醒挂起的线程;没有,判断当前消息组是否结束,更新数据同步位置后,循环读取写入队列。
步骤S916,备集群数据同步模块810的SQL回放线程解析SQL回放文件,将两个同步时钟间的事务语句块解析出来按行拆分,具体方法参考实施例7中所述的SQL行并行处理流程。当语句块并行回放成功后,将数据回放的位置持久化到文件中,以备回放异常,恢复时使用。
步骤S918,备集群的数据同步模块810的数据清理线程,会定时清理超过保存时间且成功回放过的数据。
综上所述,该方法通过同步时钟模块82为整个集群提供统一的时钟,将数据进行统一切片处理;利用一致性过滤模块88对切片的数据进行全局一致性过滤,同时考虑灾难恢复指标RPO(复原点目标,即***最大容忍丢失多少数据)和RTO(复原时间目标,即***从发生灾难到恢复运行的时间)的要求,以及业务对数据过滤和抽取需求,对同步时钟模块82、全局事务管理模块84、一致性过滤模块88、数据同步模块810的不同编 排,可以高效地满足同城多活、异地灾备、数据订阅以及数据抽取等多种业务场景,同时保证分布式环境下数据集群间的全局一致性,使得处在异地的集群可以迅速接管业务,是一项极具特色的亮点功能,对分布式数据库在金融领域、互联网领域、教育领域等的推广,起到很好的推进作用。
实施例6
图10是根据本公开实施例6的SQL语句切分组包的示意图。如图10所示:
同步时钟模块82定时会向数据库中发送同步时钟SQL语句。对应的语句最终会落在数据库日志中。
数据同步模块810在收到数据库推送的日志后,会对日志进行解析,用同步时钟SQL语句对应用SQL进行切分,具体的做法就是已两个同步时钟SQL之间的所有SQL视为一个消息块,封装成一个语句块。
语句块经过过滤后,进行打包压缩,放入发送缓冲队列中,然后发送线程从缓冲队列中取SQL语句消息发送到对端数据同步模块810中去。
实施例7
图11是根据本公开实施例7的SQL语句行并行处理的流程图。如图11,SQL语句块被按照数据行划分成多个事务,具体的做法如下:
按照表名和主键将数据行选出来,同一数据行的SQL按照先后顺序组成一个事务,不同数据行的SQL交给不同的工作线程处理。
工作线程并行处理一批SQL语句,保证回放成功,然后读取下一个SQL语句块。
实施例8
本实施例描述了实时全局一致性过滤和最终全局一致性过滤两种过滤方式的具体过程。
图12是根据本公开实施例8的实时全局一致性过滤的流程图,流程说明如下:
步骤S1202,首先从同步表中找最近一次记录。
步骤S1204,从该记录中获取最近一次同步时的全局活跃事务列表。
步骤S1206,利用全局活跃事务ID对SQL语句块进行过滤。
步骤S1208,对于语句块中全局已提交的SQL语句,确定是否有配置数据对象过滤规则,如果有,则进行步骤S1210,没有则提交发送队列。
步骤S1210,根据过滤规则,将涉及到的SQL语句过滤出来,提交发送队列。
步骤S1212,对于未全局提交的SQL语句,存入缓冲队列中。
步骤S1214,进行下一批语句过滤前,先将缓冲队列中的SQL语句合并到语句块中。
图13是根据本公开实施例8的最终全局一致性过滤的流程图,流程说明如下:
步骤S1302,一旦需要进行主备集群切换时,备集群从所有数据节点的同步表中找出最近一次的同步时钟记录。
步骤S1304,比较所有最近一次的同步时钟记录,找出时间戳最早的同步时钟记录的时间(T0)作为切换的一致点。
步骤S1306,找出所有收到晚于T0时刻同步时钟消息的数据节点。
步骤S1308,通过解析日志文件,生成回退到T0时刻的所有反向SQL语句,执行SQL语句将节点数据回滚到接收T0时刻同步时钟消息的时刻,这样集群内所有节点的数据都对齐到一个时间点(T0时刻)。
步骤S1310,利用同步时钟表中该时间点(T0)的当前全局活跃事务ID,过滤出备集群数据节点中日志文件中对应的SQL语句,这些语句虽然在单点上提交了,但全局上事务未提交。这些事务处于全局活跃状态。
步骤S1312,生成反向SQL语句并执行,最终分布式数据库备集群达到全局一致的状态。
以下实施例9至12描述了将本公开的方法应用在不同场景下的具体 处理流程。
实施例9
该实施例描述了分布式数据库异步数据同步高性能模式(即最终全局一致性方案)。
图14是根据本公开实施例9的分布式数据库集群数据同步高性能模式下的***架构示意图。
如图14所示,该实施例中存在两个集群***,主分布式数据库集群会将数据同步到备集群中,两个集群的组网是一致的。数据同步过程中不会进行一致性过滤,仅在业务进行集群切换时进行一次全局一致性过滤。分布式数据库异步数据同步高性能模式下的处理过程包括以下步骤。
1.同步时钟模块82时会向数据库中发送同步SQL语句。
2.数据库会定时将日志文件推送到数据同步模块810。
3.数据同步模块810在收到数据库推送的日志后,会对日志进行解析,以两个同步SQL之间的所有SQL视为一个消息块,封装成一个语句块。将SQL语句块打包压缩后,放入发送缓冲队列中,然后发送线程从缓冲队列中取SQL语句消息发送到对端数据同步模块810中去。
4.备集群的数据同步模块810接到消息包后,把消息放入接收列表中。做消息包校验后,SQL语句块消息被持久化到SQL回放文件中,然后SQL回放线程解析SQL回放文件,将两个同步消息间的事务语句块解析出来按行拆分,并行回放SQL语句,达到同步数据的目的。
5.一致性过滤模块88仅在需要进行主备集群切换时才启用。过滤步骤参考附图13。
该实施例适合灾备***中对RPO指标要求高的场景,数据可以高效的传输到对端集群并持久化,保证RPO尽可能的小。
实施例10
该实施例描述了分布式数据库集群数据同步高性能模式(即实时全局 一致性方案)。
图15是根据本公开实施例10的分布式数据库集群数据同步高性能模式下的***架构示意图。
如图15所示,该实施例中存在两个数据库集群***,主数据库集群会将数据同步到备集群中,两个集群的组网是一致的。数据同步过程中会进行一致性过滤,这样同步到备集群上的数据一致处在一致状态中。分布式数据库集群数据同步高性能模式下的处理包括以下步骤。
1.同步时钟模块82会向数据库中发送同步SQL语句。
2.数据库会定时将日志文件推送到数据同步模块810。
3.数据同步模块810在收到数据库推送的日志后,会对日志进行解析,以两个同步SQL之间的所有SQL视为一个消息块,封装成一个语句块。
4.一致性过滤模块88利用全局活跃事务ID,将该语句块中处在全局事务已提交状态的语句过滤出来,具体流程参考图12。
5.将全局事务已提交的SQL语句块打包压缩后,放入发送缓冲队列中,然后发送线程从缓冲队列中取SQL语句消息发送到对端数据同步模块810中去。
6.备集群的数据同步模块810接到消息包后,把消息放入接收列表中。做消息包校验后,SQL语句块消息被持久化到SQL回放文件中,然后SQL回放线程解析SQL回放文件,将两个同步消息间的事务语句块解析出来按行拆分,并行回放SQL语句,达到同步数据的目的。由于每次同步的SQL语句块在全局都是一致的,因此,备集群数据库内的数据一直处在全局一致的状态。
该实施例适合灾备***中对RTO指标要求高的场景。业务可以在任何时候接管对端分布式数据库集群,RTO可以等于零。
实施例11
该实施例描述了基于分布式数据库的增量数据订阅下的数据同步(准 实时备份)。
图16是根据本公开实施例11的分布式数据库准实时备份的***架构图。如图16所示,该实施例中存在两个数据库集群,其中远端数据库集群作为订阅业务***集群的数据库集群,两个集群组网可以不一致。基于分布式数据库的增量数据订阅下的准实时备份的过程包括以下步骤。
1.同步时钟模块82时会向数据库中发送同步SQL语句。
2.数据库会定时将日志文件推送到数据同步模块810。
3.数据同步模块810在收到数据库推送的日志后,会对日志进行解析,以两个同步SQL之间的所有SQL视为一个消息块,封装成一个语句块。
4.一致性过滤模块88利用全局活跃事务ID,将该语句块中处在全局活跃的SQL语句,缓存到活跃语句队列中,在过滤下一个语句块时合并到语句快中。这样过滤出来的SQL语句都是全局事务已提交状态的语句。然后根据订阅规则,对涉及的数据对象(数据库、表)进行过滤。
5.将过滤后全局事务已提交的SQL语句块打包压缩后,放入发送缓冲队列中,然后发送线程从缓冲队列中取SQL语句消息发送到对端数据同步模块810中去。
6.远端集群的数据同步模块810接到消息包后,把消息放入接收列表中。做消息包校验后,SQL语句块消息被持久化到SQL回放文件中,然后SQL回放线程解析SQL回放文件,将两个同步消息间的事务语句块解析出来按行拆分,根据集群组网情况,并行回放SQL语句,达到准实时备份数据的目的。
实施例12
该实施例描述了基于分布式数据库增量数据的数据同步(数据抽取)。
图17是根据本公开实施例12的基于分布式数据库增量数据的数据抽取的***架构图。如图17所示,该实施例中存在两种类型的业务***:产生数据的在线联机交易***(OLTP)以及数据分析业务为主的在线分 析***(OLAP)和数据仓库***(BI),图例中以数据在线分析的大数据平台(包括诸如基于Hadoop的数据仓库工具Hive、用于处理结构化数据的通用的集群计算框架(Spark)组件Spark SQL、Hadoop的分布式文件***(Hadoop Distribute File System,简称为HDFS)等等)为例。OLTP***把数据导入到大数据平台中,供大数据平台进行分析挖掘。基于分布式数据库增量数据的数据抽取包括以下步骤。
1.同步时钟模块82会定时向数据库中发送同步SQL语句。
2.OLTP类型业务数据库集群会定时将日志文件推送到数据同步模块810。
3.数据同步模块810在收到数据库推送的日志后,会对日志进行解析,以两个同步SQL之间的所有SQL视为一个消息块,封装成一个语句块。
4.一致性过滤模块88利用全局活跃事务ID,将该语句块中处在全局活跃的SQL语句,缓存到活跃语句队列中,在过滤下一个语句块时合并到语句快中。这样过滤出来的SQL语句都是全局事务已提交状态的语句。然后根据数据抽取规则,对涉及的数据对象(数据库、表)进行过滤。
5.将抽取后全局事务已提交的SQL语句块打包压缩后,放入发送缓冲队列中,然后发送线程从缓冲队列中取SQL语句消息发送到大数据平台端的数据同步模块810中去。
6.大数据平台端的数据同步模块810接到消息包后,把消息放入接收列表中。做消息包校验后,SQL语句块消息被持久化到SQL回放文件中,然后SQL回放线程解析SQL回放文件,将两个同步消息间的事务语句块解析出来按行拆分,并行回放到大数据平台的数据计算层中,由计算层进行SQL计算,将数据计算结果更新到大数据平台的存储***中。
综上所述,根据本公开所提出的分布式数据库集群***和数据同步方法可以扩大分布式数据库集群在教学、金融、政企、互联网等领域的应用,节省了***资源投入,提升***性能,保障数据的一致性,提升用户使用体验。对于分布式数据库的推广具有良好的示范意义。
显然,本领域的技术人员应该明白,上述的本公开的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本公开不限制于任何特定的硬件和软件结合。
以上所述仅为本公开的优选实施例而已,并不用于限制本公开,对于本领域的技术人员来说,本公开可以有各种更改和变化。凡在本公开的原则之内,所作的任何修改、等同替换、改进等,均应包含在本公开的保护范围之内。

Claims (36)

  1. 一种分布式数据库集群***,包括:第一同步时钟模块、第一数据同步模块和多个第一数据库组,其中,所述多个第一数据库组中的每个第一数据库组包括一个第一主数据库,
    所述第一同步时钟模块设置为定期发送时钟同步指令;
    所述第一数据同步模块设置为分别将每个第一主数据库在所述第一同步时钟模块发送的相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。
  2. 根据权利要求1所述的分布式数据库集群***,其中,
    所述第一同步时钟模块设置为定期向每个第一主数据库发送所述时钟同步指令;
    所述第一主数据库设置为将接收到的数据库操作指令写入所述第一主数据库的日志文件,以及将接收到的所述时钟同步指令写入所述日志文件;
    所述第一数据同步模块设置为分别获取每个第一主数据库的所述日志文件,将所述日志文件中夹在两条时钟同步指令之间的数据库操作指令封装成所述第一操作指令块,并发送所述第一操作指令块。
  3. 根据权利要求1或2所述的分布式数据库集群***,其中,所述第一数据同步模块设置为发送所述第一操作指令块给对端的分布式数据库集群***。
  4. 根据权利要求1或2所述的分布式数据库集群***,其中,还包括:第一一致性过滤模块,
    所述第一数据同步模块设置为发送所述第一操作指令块给所述第一一致性过滤模块;
    所述第一一致性过滤模块设置为接收所述第一数据同步模块发送的所述第一操作指令块,对所述第一操作指令块进行全局一致性过滤, 将所述第一操作指令块中满足过滤条件的数据库操作指令封装成第二操作指令块,并将所述第二操作指令块发送到对端的分布式数据库集群***,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态。
  5. 根据权利要求4所述的分布式数据库集群***,其中,所述过滤条件还包括:所述数据库操作指令符合所述对端的分布式数据库集群***所对应的数据对象过滤规则。
  6. 根据权利要求4或5所述的分布式数据库集群***,其中,所述第一一致性过滤模块还设置为:
    将所述第一操作指令块中处于全局事务未提交状态的数据库操作指令进行缓存,并在下一次接收到所述第一数据同步模块发送的对应于当前第一主数据库的所述第一操作指令块时,将缓存的所述数据库操作指令加入所述第一操作指令块后再对所述第一操作指令块进行全局一致性过滤。
  7. 根据权利要求4至6中任一项所述的分布式数据库集群***,还包括:全局事务管理模块,
    所述全局事务管理模块设置为管理能够唯一标识全局事务的全局事务标识ID,并记录每个全局事务的状态和生命周期;
    所述第一同步时钟模块设置为定期请求每个第一主数据库的当前活跃事务列表,将所述当前活跃事务列表和获取所述当前活跃事务列表的时间戳记录在所述第一主数据库对应的同步表中,并将所述时间戳和所述当前活跃事务列表的信息携带在发往所述第一主数据库的所述时钟同步指令中;
    所述第一一致性过滤模块设置为查找当前第一主数据库对应的所述同步表中最近一次记录的所述当前活跃事务列表,并将最近一次记录的所述当前活跃事务列表中的全局事务ID所对应的数据库操作指 令剔除,将剩余的数据库操作指令作为满足处于全局事务已提交状态的过滤条件的数据库操作指令封装成所述第二操作指令块。
  8. 根据权利要求1所述的分布式数据库集群***,其中,所述第一数据同步模块还设置为:
    接收对端的分布式数据库集群***发来的同步位置请求信息,其中,所述同步位置请求信息携带所述分布式数据库集群***与所述对端的分布式数据库集群***之间的同步位置;
    根据所述同步位置请求信息携带的所述同步位置执行对每个第一主数据库所记录的数据库操作指令的封装。
  9. 根据权利要求1至8中任一项所述的分布式数据库集群***,其中,所述第一数据同步模块还设置为:
    接收对端的分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块;
    执行接收的所述操作指令块中的数据库操作指令。
  10. 根据权利要求9所述的分布式数据库集群***,其中,所述第一数据同步模块设置为通过以下方式执行接收的所述操作指令块中的所述数据库操作指令:
    将所述操作指令块中的所述数据库操作指令持久化到回放文件中;
    解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理。
  11. 根据权利要求10所述的分布式数据库集群***,其中,所述第一数据同步模块设置为通过以下方式解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理:
    按照表名和主键将所述操作指令块中的所述数据库操作指令拆分 成不同的数据行,同一数据行的所述数据库操作指令按照先后顺序组成一个事务;
    将不同事务的所述数据库操作指令放入不同的工作线程进行处理。
  12. 根据权利要求9至11中任一项所述的分布式数据库集群***,其中,所述第一数据同步模块还设置为:
    在执行接收的所述操作指令块中的所述数据库操作指令成功后,将执行数据库操作指令成功的位置持久化到文件中。
  13. 根据权利要求9至11中任一项所述的分布式数据库集群***,其中,在所述分布式数据库集群***作为所述对端的分布式数据库集群***的备分布式数据库集群***的情况下,
    所述第一数据同步模块设置为在所述分布式数据库集群***需要接替所述对端的分布式数据库集群***成为主分布式数据库集群***的情况下,调用第一一致性过滤模块;
    所述第一一致性过滤模块设置为:
    获取每个第一主数据库对应的同步表,根据所述同步表确定每个第一主数据库的最近一次同步的时间戳,并从中确定出最早的时间戳作为切换参考时间点;
    对于最近一次同步的时间戳晚于所述切换参考时间点的每个第一主数据库,将所述第一主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第一主数据库的数据恢复到全局一致的状态。
  14. 根据权利要求13所述的分布式数据库集群***,其中,所述第一一致性过滤模块设置为通过以下方式将所述第一主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第一主数据库的数据恢复到全局一致的状态:
    对于所述切换参考时间点之后的数据库操作指令生成反向数据库 操作指令,并执行所述反向数据库操作指令;
    对于所述切换参考时间点时处于全局事务未提交状态的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令。
  15. 一种分布式数据库集群***,包括:第二数据同步模块和多个第二数据库组,其中,所述多个第二数据库组中的每个第二数据库组包括一个第二主数据库,
    所述第二数据同步模块设置为接收对端的分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第二操作指令块,所述第一操作指令块封装有所述对端的分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令,所述第二操作指令块封装有所述对端的分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令中满足过滤条件的数据库操作指令,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态;
    执行接收的所述操作指令块中的数据库操作指令。
  16. 根据权利要求15所述的分布式数据库集群***,其中,所述第二数据同步模块设置为通过以下方式执行接收的所述操作指令块中的所述数据库操作指令:
    将所述操作指令块中的所述数据库操作指令持久化到回放文件中;
    解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理。
  17. 根据权利要求16所述的分布式数据库集群***,其中,所述第二数据同步模块设置为通过以下方式解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理:
    按照表名和主键将所述操作指令块中的所述数据库操作指令拆分成不同的数据行,同一数据行的所述数据库操作指令按照先后顺序组成一个事务;
    将不同事务的所述数据库操作指令放入不同的工作线程进行处理。
  18. 根据权利要求15至17中任一项所述的分布式数据库集群***,其中,所述第二数据同步模块还设置为:
    在执行接收的所述操作指令块中的所述数据库操作指令成功后,将执行数据库操作指令成功的位置持久化到文件中。
  19. 根据权利要求15至17中任一项所述的分布式数据库集群***,还包括第二一致性过滤模块,
    所述第二数据同步模块设置为在所述分布式数据库集群***需要接替所述对端的分布式数据库集群***成为主分布式数据库集群***的情况下,调用所述第二一致性过滤模块;
    所述第二一致性过滤模块设置为:
    获取每个第二主数据库对应的同步表,根据所述同步表确定每个第二主数据库的最近一次同步的时间戳,并从中确定出最早的时间戳作为切换参考时间点;
    对于最近一次同步的时间戳晚于所述切换参考时间点的每个第二主数据库,将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态。
  20. 根据权利要求19所述的分布式数据库集群***,其中,所述第二一致性过滤模块设置为通过以下方式将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态:
    对于所述切换参考时间点之后的数据库操作指令生成反向数据库 操作指令,并执行所述反向数据库操作指令;
    对于所述切换参考时间点时处于全局事务未提交状态的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令。
  21. 一种数据同步方法,应用于包含多个第一数据库组的第一分布式数据库集群***,其中,所述多个第一数据库组中的每个第一数据库组包括一个第一主数据库,所述方法包括:
    所述第一分布式数据库集群***定期发送时钟同步指令;
    所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块,并发送所述第一操作指令块。
  22. 根据权利要求21所述的方法,其中,
    所述第一分布式数据库集群***定期发送时钟同步指令包括:所述第一分布式数据库集群***定期向每个第一主数据库发送所述时钟同步指令;
    所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块之前,所述方法还包括:所述第一主数据库将接收到的数据库操作指令写入所述第一主数据库的日志文件,以及将接收到的所述时钟同步指令写入所述日志文件;
    所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块包括:所述第一分布式数据库集群***分别获取每个第一主数据库的所述日志文件,将所述日志文件中夹在两条时钟同步指令之间的数据库操作指令封装成所述第一操作指令块。
  23. 根据权利要求21或22所述的方法,其中,所述第一分布式 数据库集群***发送所述第一操作指令块包括:
    所述第一分布式数据库集群***发送所述第一操作指令块给第二分布式数据库集群***。
  24. 根据权利要求21或22所述的方法,其中,
    所述第一分布式数据库集群***发送所述第一操作指令块包括:
    所述第一分布式数据库集群***对所述第一操作指令块进行全局一致性过滤,将所述第一操作指令块中满足过滤条件的数据库操作指令封装成第二操作指令块,并将所述第二操作指令块发送到第二分布式数据库集群***,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态。
  25. 根据权利要求24所述的方法,其中,所述过滤条件还包括:所述数据库操作指令符合所述第二分布式数据库集群***所对应的数据对象过滤规则。
  26. 根据权利要求24或25所述的方法,还包括:
    所述第一分布式数据库集群***将所述第一操作指令块中处于全局事务未提交状态的数据库操作指令进行缓存,并将缓存的所述数据库操作指令加入对应于当前第一主数据库的下一个第一操作指令块后再对所述下一个第一操作指令块进行全局一致性过滤。
  27. 根据权利要求24至26中任一项所述的方法,还包括:
    所述第一分布式数据库集群***管理能够唯一标识全局事务的全局事务标识ID,并记录每个全局事务的状态和生命周期;
    所述第一分布式数据库集群***管理定期请求每个第一主数据库的当前活跃事务列表,将所述当前活跃事务列表和获取所述当前活跃事务列表的时间戳记录在所述第一主数据库对应的同步表中,并将所述时间戳和所述当前活跃事务列表的信息携带在发往所述第一主数据 库的所述时钟同步指令中;
    所述第一分布式数据库集群***对所述第一操作指令块进行全局一致性过滤,将所述第一操作指令块中满足过滤条件的数据库操作指令封装成第二操作指令块包括:所述第一分布式数据库集群***查找当前第一主数据库对应的所述同步表中最近一次记录的所述当前活跃事务列表,并将最近一次记录的所述当前活跃事务列表中的全局事务ID所对应的数据库操作指令剔除,将剩余的数据库操作指令作为满足处于全局事务已提交状态的过滤条件的数据库操作指令封装成所述第二操作指令块。
  28. 根据权利要求21所述的方法,其中,
    所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块之前,还包括:所述第一分布式数据库集群***接收第二分布式数据库集群***发来的同步位置请求信息,其中,所述同步位置请求信息携带所述第一分布式数据库集群***与所述第二分布式数据库集群***之间的同步位置;
    所述第一分布式数据库集群***分别将每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令封装成第一操作指令块包括:所述第一分布式数据库集群***根据所述同步位置请求信息携带的所述同步位置执行对每个第一主数据库所记录的数据库操作指令的封装。
  29. 一种数据同步方法,应用于包含多个第二数据库组的第二分布式数据库集群***,其中,所述多个第二数据库组中的每个第二数据库组包括一个第二主数据库,所述方法包括:
    所述第二分布式数据库集群***接收第一分布式数据库集群***发送的操作指令块,其中,所述操作指令块包括第一操作指令块或第 二操作指令块,所述第一操作指令块封装有所述第一分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令,所述第二操作指令块封装有所述第一分布式数据库集群***的每个第一主数据库在相邻两个时钟同步指令之间所记录的数据库操作指令中满足过滤条件的数据库操作指令,其中,所述过滤条件包括:所述数据库操作指令处于全局事务已提交状态;
    所述第二分布式数据库集群***执行接收的所述操作指令块中的数据库操作指令。
  30. 根据权利要求29所述的方法,其中,所述第二分布式数据库集群***执行接收的所述操作指令块中的数据库操作指令包括:
    所述第二分布式数据库集群***将所述操作指令块中的所述数据库操作指令持久化到回放文件中;
    所述第二分布式数据库集群***解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理。
  31. 根据权利要求30所述的方法,其中,所述第二分布式数据库集群***解析所述回放文件,将所述回放文件中的所述数据库操作指令按行拆分放入不同的工作线程进行处理包括:
    所述第二分布式数据库集群***按照表名和主键将所述操作指令块中的所述数据库操作指令拆分成不同的数据行,同一数据行的所述数据库操作指令按照先后顺序组成一个事务;
    所述第二分布式数据库集群***将不同事务的所述数据库操作指令放入不同的工作线程进行处理。
  32. 根据权利要求29至31中任一项所述的方法,其中,在所述第二分布式数据库集群***执行接收的所述操作指令块中的所述数据库操作指令成功之后,还包括:
    所述第二分布式数据库集群***将执行数据库操作指令成功的位置持久化到文件中。
  33. 根据权利要求29至31中任一项所述的方法,其中,在所述第二分布式数据库集群***需要接替所述第一分布式数据库集群***成为主分布式数据库集群***的情况下,所述方法还包括:
    所述第二分布式数据库集群***获取每个第二主数据库对应的同步表,根据所述同步表确定每个第二主数据库的最近一次同步的时间戳,并从中确定出最早的时间戳作为切换参考时间点;
    对于最近一次同步的时间戳晚于所述切换参考时间点的每个第二主数据库,所述第二分布式数据库集群***将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态。
  34. 根据权利要求33所述的方法,其中,所述第二分布式数据库集群***将所述第二主数据库的数据回滚到所述切换参考时间点时记录的状态,并将所述第二主数据库的数据恢复到全局一致的状态包括:
    所述第二分布式数据库集群***对于所述切换参考时间点之后的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令;
    所述第二分布式数据库集群***对于所述切换参考时间点时处于全局事务未提交状态的数据库操作指令生成反向数据库操作指令,并执行所述反向数据库操作指令。
  35. 一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行所述权利要求21至34任一项中所述的方法。
  36. 一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行所述权利要求21至34任一项中所述的方法。
PCT/CN2019/074699 2018-02-12 2019-02-03 分布式数据库集群***、数据同步方法及存储介质 WO2019154394A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP19751274.2A EP3754514B1 (en) 2018-02-12 2019-02-03 Distributed database cluster system, data synchronization method and storage medium
JP2020565003A JP7090744B2 (ja) 2018-02-12 2019-02-03 分散データベースクラスタシステム、及びデータ同期方法

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810147335.4A CN110209726B (zh) 2018-02-12 2018-02-12 分布式数据库集群***、数据同步方法及存储介质
CN201810147335.4 2018-02-12

Publications (1)

Publication Number Publication Date
WO2019154394A1 true WO2019154394A1 (zh) 2019-08-15

Family

ID=67548760

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/074699 WO2019154394A1 (zh) 2018-02-12 2019-02-03 分布式数据库集群***、数据同步方法及存储介质

Country Status (4)

Country Link
EP (1) EP3754514B1 (zh)
JP (1) JP7090744B2 (zh)
CN (1) CN110209726B (zh)
WO (1) WO2019154394A1 (zh)

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110489491A (zh) * 2019-08-26 2019-11-22 湖南中车时代通信信号有限公司 一种适用于a/b网双集群的全量数据同步装置
CN111782634A (zh) * 2020-06-29 2020-10-16 京东数字科技控股有限公司 数据分布式存储方法、装置、电子设备及存储介质
CN111930830A (zh) * 2020-06-22 2020-11-13 心有灵犀科技股份有限公司 一种基于共享数据库的分布式事务数据处理方法及***
CN112052270A (zh) * 2020-08-26 2020-12-08 南京越扬科技有限公司 一种通过大数据进行用户画像深度分析的方法及***
CN112231396A (zh) * 2020-09-15 2021-01-15 山东浪潮通软信息科技有限公司 一种跨数据库增量同步数据的方法
CN112463762A (zh) * 2020-11-06 2021-03-09 苏州浪潮智能科技有限公司 跨集群实时数据迁移与同步的方法、***、设备及介质
CN113254535A (zh) * 2021-06-08 2021-08-13 成都新潮传媒集团有限公司 一种mongodb到mysql的数据同步方法、装置及计算机可读存储介质
CN113596190A (zh) * 2021-07-23 2021-11-02 浪潮云信息技术股份公司 基于Kubernetes的应用分布式多活***及方法
CN113918657A (zh) * 2021-12-14 2022-01-11 天津南大通用数据技术股份有限公司 一种并行高性能增量同步方法
CN114301563A (zh) * 2021-12-24 2022-04-08 中国航发控制***研究所 集群间多余度同步电路、总线***及集群间同步的方法
CN114579671A (zh) * 2022-05-09 2022-06-03 高伟达软件股份有限公司 集群间数据同步方法及装置
CN115544172A (zh) * 2022-11-28 2022-12-30 杭州欧若数网科技有限公司 一种一主多从的集群间数据实时同步的方法和***
CN116991691A (zh) * 2023-09-26 2023-11-03 中国铁塔股份有限公司 数据库测试方法、装置、电子设备及可读存储介质
CN117093640A (zh) * 2023-10-18 2023-11-21 上海柯林布瑞信息技术有限公司 基于池化技术的数据抽取方法及装置
CN117827981A (zh) * 2024-03-06 2024-04-05 北京万里开源软件有限公司 一种MySQL数据库集群的链路检测方法及***
CN117992257A (zh) * 2024-04-07 2024-05-07 天津南大通用数据技术股份有限公司 一种分布式数据库并行数据采集处理方法

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110661857B (zh) * 2019-09-12 2021-12-07 京东数字科技控股有限公司 一种数据同步方法和装置
CN110795506A (zh) * 2019-10-23 2020-02-14 广州巨杉软件开发有限公司 基于分布式逻辑时间戳的分布式数据库管理方法及装置
CN110866009A (zh) * 2019-10-29 2020-03-06 广州西山居世游网络科技有限公司 一种实时并发同步服务的方法及***
CN111209342B (zh) * 2020-01-13 2023-04-07 阿里巴巴集团控股有限公司 分布式***、数据同步与节点管理方法、设备及存储介质
CN112068994A (zh) * 2020-08-21 2020-12-11 苏州浪潮智能科技有限公司 存储集群运行时数据持久化的方法、装置、设备和介质
CN112131245A (zh) * 2020-09-23 2020-12-25 华东计算技术研究所(中国电子科技集团公司第三十二研究所) 拟态防御架构的高性能数据访问***及方法
CN112434064B (zh) * 2020-11-19 2023-09-29 脸萌有限公司 数据处理方法、装置、介质及电子设备
CN113127436B (zh) * 2021-04-28 2023-07-25 北京奇艺世纪科技有限公司 一种数据同步方法、装置、服务器及存储介质
CN113641756A (zh) * 2021-07-26 2021-11-12 浪潮卓数大数据产业发展有限公司 一种分布式高并发的数据存储方法
CN114528266B (zh) * 2022-01-28 2024-01-26 苏州浪潮智能科技有限公司 实现数据库和缓存一致性的方法、***、设备和存储介质
CN114697346B (zh) * 2022-04-22 2024-06-11 厦门飞鱼科技有限公司 服务器节点之间数据同步的方法
CN114942965B (zh) * 2022-06-29 2022-12-16 北京柏睿数据技术股份有限公司 一种数据库主备同步操作的加速方法和***
CN117112314B (zh) * 2023-10-24 2024-02-06 深圳市科力锐科技有限公司 业务数据切换方法、装置、设备及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6125368A (en) * 1997-02-28 2000-09-26 Oracle Corporation Fault-tolerant timestamp generation for multi-node parallel databases
CN101401073A (zh) * 2006-04-06 2009-04-01 国际商业机器公司 跨存储子***的一致更新
CN102693324A (zh) * 2012-01-09 2012-09-26 西安电子科技大学 一种分布式数据库同步***、同步方法和节点管理方法
CN104182441A (zh) * 2014-02-27 2014-12-03 无锡天脉聚源传媒科技有限公司 一种数据表同步方法及装置

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6516327B1 (en) * 1998-12-24 2003-02-04 International Business Machines Corporation System and method for synchronizing data in multiple databases
US20070061379A1 (en) * 2005-09-09 2007-03-15 Frankie Wong Method and apparatus for sequencing transactions globally in a distributed database cluster
US7552295B2 (en) * 2006-01-03 2009-06-23 International Business Machines Corporation Maintaining consistency when mirroring data using different copy technologies
JP5042644B2 (ja) * 2007-01-24 2012-10-03 株式会社日立製作所 リモートコピーシステム
JP4916420B2 (ja) * 2007-11-16 2012-04-11 株式会社日立製作所 ストレージシステム及びリモートコピー制御方法
CN103902617B (zh) * 2012-12-28 2017-06-09 华为技术有限公司 分布式数据库同步方法和***
WO2015008484A1 (ja) * 2013-07-16 2015-01-22 Mame・Design株式会社 バックアップ制御装置及びバックアップ制御方法
CN105512171B (zh) * 2015-11-23 2019-05-21 北京奇虎科技有限公司 数据库同步的方法及装置
CN106484565B (zh) * 2016-09-22 2019-06-28 华为数字技术(成都)有限公司 多数据中心间的数据同步方法及相关设备
CN107391635A (zh) * 2017-06-30 2017-11-24 北京奇虎科技有限公司 数据同步***及方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6125368A (en) * 1997-02-28 2000-09-26 Oracle Corporation Fault-tolerant timestamp generation for multi-node parallel databases
CN101401073A (zh) * 2006-04-06 2009-04-01 国际商业机器公司 跨存储子***的一致更新
CN102693324A (zh) * 2012-01-09 2012-09-26 西安电子科技大学 一种分布式数据库同步***、同步方法和节点管理方法
CN104182441A (zh) * 2014-02-27 2014-12-03 无锡天脉聚源传媒科技有限公司 一种数据表同步方法及装置

Cited By (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110489491B (zh) * 2019-08-26 2023-07-04 湖南中车时代通信信号有限公司 一种适用于a/b网双集群的全量数据同步装置
CN110489491A (zh) * 2019-08-26 2019-11-22 湖南中车时代通信信号有限公司 一种适用于a/b网双集群的全量数据同步装置
CN111930830A (zh) * 2020-06-22 2020-11-13 心有灵犀科技股份有限公司 一种基于共享数据库的分布式事务数据处理方法及***
CN111930830B (zh) * 2020-06-22 2024-04-16 心有灵犀科技股份有限公司 一种基于共享数据库的分布式事务数据处理方法及***
CN111782634A (zh) * 2020-06-29 2020-10-16 京东数字科技控股有限公司 数据分布式存储方法、装置、电子设备及存储介质
CN112052270A (zh) * 2020-08-26 2020-12-08 南京越扬科技有限公司 一种通过大数据进行用户画像深度分析的方法及***
CN112231396A (zh) * 2020-09-15 2021-01-15 山东浪潮通软信息科技有限公司 一种跨数据库增量同步数据的方法
CN112463762A (zh) * 2020-11-06 2021-03-09 苏州浪潮智能科技有限公司 跨集群实时数据迁移与同步的方法、***、设备及介质
CN113254535A (zh) * 2021-06-08 2021-08-13 成都新潮传媒集团有限公司 一种mongodb到mysql的数据同步方法、装置及计算机可读存储介质
CN113596190A (zh) * 2021-07-23 2021-11-02 浪潮云信息技术股份公司 基于Kubernetes的应用分布式多活***及方法
CN113596190B (zh) * 2021-07-23 2023-05-26 浪潮云信息技术股份公司 基于Kubernetes的应用分布式多活***及方法
CN113918657B (zh) * 2021-12-14 2022-03-15 天津南大通用数据技术股份有限公司 一种并行高性能增量同步方法
CN113918657A (zh) * 2021-12-14 2022-01-11 天津南大通用数据技术股份有限公司 一种并行高性能增量同步方法
CN114301563A (zh) * 2021-12-24 2022-04-08 中国航发控制***研究所 集群间多余度同步电路、总线***及集群间同步的方法
CN114301563B (zh) * 2021-12-24 2023-05-05 中国航发控制***研究所 集群间多余度同步电路、总线***及集群间同步的方法
CN114579671A (zh) * 2022-05-09 2022-06-03 高伟达软件股份有限公司 集群间数据同步方法及装置
CN115544172A (zh) * 2022-11-28 2022-12-30 杭州欧若数网科技有限公司 一种一主多从的集群间数据实时同步的方法和***
CN116991691A (zh) * 2023-09-26 2023-11-03 中国铁塔股份有限公司 数据库测试方法、装置、电子设备及可读存储介质
CN116991691B (zh) * 2023-09-26 2024-01-30 中国铁塔股份有限公司 数据库测试方法、装置、电子设备及可读存储介质
CN117093640A (zh) * 2023-10-18 2023-11-21 上海柯林布瑞信息技术有限公司 基于池化技术的数据抽取方法及装置
CN117093640B (zh) * 2023-10-18 2024-01-23 上海柯林布瑞信息技术有限公司 基于池化技术的数据抽取方法及装置
CN117827981A (zh) * 2024-03-06 2024-04-05 北京万里开源软件有限公司 一种MySQL数据库集群的链路检测方法及***
CN117992257A (zh) * 2024-04-07 2024-05-07 天津南大通用数据技术股份有限公司 一种分布式数据库并行数据采集处理方法

Also Published As

Publication number Publication date
JP2021513715A (ja) 2021-05-27
CN110209726A (zh) 2019-09-06
EP3754514B1 (en) 2024-05-08
EP3754514A4 (en) 2020-12-23
JP7090744B2 (ja) 2022-06-24
EP3754514A1 (en) 2020-12-23
CN110209726B (zh) 2023-10-20

Similar Documents

Publication Publication Date Title
WO2019154394A1 (zh) 分布式数据库集群***、数据同步方法及存储介质
CN109101627B (zh) 异构数据库同步方法及装置
US11893264B1 (en) Methods and systems to interface between a multi-site distributed storage system and an external mediator to efficiently process events related to continuity
US10565071B2 (en) Smart data replication recoverer
JP2020514902A (ja) データセット及び他の管理オブジェクトをクラウドベースのストレージシステムに同期複製すること
JP2019036353A (ja) 索引更新パイプライン
CN111078667B (zh) 一种数据迁移的方法以及相关装置
US10534796B1 (en) Maintaining an active-active cloud across different types of cloud storage services
JP2016524750A5 (zh)
US20120278429A1 (en) Cluster system, synchronization controlling method, server, and synchronization controlling program
US8527454B2 (en) Data replication using a shared resource
US20240143450A1 (en) Standbys for continuous data protection-enabled objects
WO2017014814A1 (en) Replicating memory volumes
US11042454B1 (en) Restoration of a data source
US20240152432A1 (en) Using a stream of source system storage changes to update a continuous data protection-enabled hot standby
CN111404737B (zh) 一种容灾处理方法以及相关装置
WO2021082925A1 (zh) 一种交易处理的方法及装置
US20230409442A1 (en) Techniques for maintaining data consistency during disaster recovery
US11079960B2 (en) Object storage system with priority meta object replication
US11093465B2 (en) Object storage system with versioned meta objects
CN111522688B (zh) 分布式***的数据备份方法及装置
Solissa et al. Hadoop high availability with Linux HA
CN115168109A (zh) 一种数据恢复方法、装置、设备及存储介质
CN117171132A (zh) 数据同步方法、装置及介质
WO2016122690A1 (en) File system replication

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: 19751274

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2020565003

Country of ref document: JP

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2019751274

Country of ref document: EP

Effective date: 20200914