WO2021129477A1 - Data synchronization method and related device - Google Patents

Data synchronization method and related device Download PDF

Info

Publication number
WO2021129477A1
WO2021129477A1 PCT/CN2020/136716 CN2020136716W WO2021129477A1 WO 2021129477 A1 WO2021129477 A1 WO 2021129477A1 CN 2020136716 W CN2020136716 W CN 2020136716W WO 2021129477 A1 WO2021129477 A1 WO 2021129477A1
Authority
WO
WIPO (PCT)
Prior art keywords
partition
leader
offset
data
follower
Prior art date
Application number
PCT/CN2020/136716
Other languages
French (fr)
Chinese (zh)
Inventor
汝佳
赵东
智伟
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021129477A1 publication Critical patent/WO2021129477A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • 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

Definitions

  • the present invention relates to the field of information technology, in particular to a data synchronization method and related equipment.
  • Kafka The distributed publish-subscribe messaging system
  • Kafka has good functional characteristics. It provides message persistence through the disk structure, can maintain long-term stable performance, has high throughput, can support millions of messages per second, and can Supports parallel data loading, so Kafka is generally used to process massive streams of data generated by application service systems or artificial intelligence (AI) platforms.
  • AI artificial intelligence
  • Kafka usually caches message data on the local disk.
  • the object of publishing and subscribing in Kafka is a category (topic).
  • Each topic represents a type of data, and a topic is divided into multiple partitions. (partition), each partition is an ordered queue. The different partitions of each topic are distributed on different disks or hosts.
  • each partition has multiple replicas (replica), and a primary replica is elected among multiple replicas. It can be called a leader partition, and the remaining replicas are slave replicas, which can also be called a follower partition.
  • Follower partition will continuously synchronize the latest message data from leader partition.
  • leader partition Consumers (clients that subscribe to messages from topics) and producers (clients that publish messages to topics) directly interact with leader partition when they consume and produce .
  • clients clients that subscribe to messages from topics
  • producers clients that publish messages to topics
  • leader partition When a node where a leader partition is located suddenly fails or loses power, the follower partition corresponding to the partition will elect a new leader partition to ensure service reliability and data security.
  • the copies existing in the Kafka cluster need to be migrated to ensure the integrity of the copy.
  • the current copy of the Kafka cluster The migration is to complete the copy migration through the migration tool provided by Kafka itself, but this method is not flexible enough, the migration time is longer, the efficiency is low, and it will continue to occupy the central processing unit (CPU) resources and network bandwidth resources. Affect the normal operation of the business.
  • the embodiment of the present invention discloses a data synchronization method and related equipment.
  • a follower partition can flexibly select data to be synchronized from a leader partition, thereby improving data synchronization efficiency, shortening data synchronization time, and reducing impact on services.
  • this application provides a data synchronization method, including: follower partition obtaining an offset selection strategy for the follower partition; the follower partition determines the leader of the topic to be synchronized based on the offset selection strategy The target offset in the leader partition of the leader partition; the follower partition starts to synchronize the data in the leader partition to the follower partition starting from the determined target offset of the leader partition.
  • the follower partition can flexibly select the target offset that needs to be synchronized according to needs, and after determining the target offset, start to synchronize the data in the leader partition to the follower from the target offset determined in the leader partition partition, which can improve data synchronization efficiency, shorten data synchronization time, and expand applicable scenarios.
  • the follower partition sends a query request to the leader partition, and the query request is used to query the offset in the leader partition at the current moment; the follower partition calculates the current moment The difference between the offset in the leader partition and the offset in the follower partition, and when the difference is greater than a preset threshold, it is determined to synchronize the data in the leader partition to the follower partition.
  • the follower partition before the follower partition performs data synchronization, it needs to query the offset in the leader partition at the current moment, and then calculate the difference between the offset in the leader partition and the offset in the follower partition, and Data synchronization is performed when the difference is greater than the preset threshold. This can avoid frequent data synchronization, and only perform data synchronization when the conditions are met, thereby improving system efficiency.
  • the offset selection strategy is an offset adaptive determination strategy
  • the follower partition obtains the average data writing speed of the leader partition; the follower partition is based on the leader partition The average write speed of the data is calculated, and the target offset is calculated.
  • the follower partition when the follower partition selects the offset strategy as the offset adaptive determination strategy, it needs to obtain the average data writing speed of the leader partition, so as to calculate the target offset.
  • the offset selection strategy is an offset adaptive determination strategy
  • the follower partition obtains the start offset of the leader partition and the average write data of the leader partition Speed; the follower partition calculates the target offset according to the start offset of the leader partition and the average data write speed of the leader partition.
  • the follower partition needs to obtain the leader partition's starting offset and the average data writing speed, so as to ensure the calculated target offset more precise.
  • the target offset is the maximum offset of the leader partition at the current moment
  • the target offset is the start offset of the leader partition.
  • the target offset is determined by comparing the relationship between the average data write speed of the leader partition and the data synchronous transmission speed, so that it can be ensured that the determined target offset is more reasonable.
  • the target offset is the maximum offset of the leader partition at the current moment
  • the target offset Is the starting offset of the leader partition.
  • the relationship between the average data write speed of the leader partition and the data synchronization transmission speed, and the relationship between the synchronization time required by the current total amount of data of the leader partition and the preset duration are considered at the same time, so as to determine the target Offset, which can further improve the rationality and accuracy of the determined target offset.
  • the offset selection strategy is a selection strategy based on data value
  • the follower partition obtains the consumption offsets of multiple consumer groups, and the follower partition determines the smallest consumption
  • the offset is the target offset; wherein the consumer group is used to consume the data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used to indicate The number of data in the leader partition consumed by the consumer group.
  • the follower partition selection strategy is a data value-based selection strategy
  • the minimum consumption offset is determined as the target offset.
  • this application provides a data synchronization device, including: an acquiring unit, configured to acquire an offset selection strategy; and a processing unit, configured to determine the leader partition of the topic to be synchronized based on the offset selection strategy The synchronization unit is used to synchronize the data in the leader partition from the determined target offset of the leader partition.
  • the data synchronization device further includes a sending unit, the sending unit is configured to send a query request to the leader partition, and the query request is used to query the leader partition at the current moment Offset; the processing unit is also used to calculate the difference between the offset in the leader partition at the current moment and the offset in the data synchronization device, and when the difference is greater than a preset When the threshold is used, it is determined to synchronize the data in the leader partition.
  • the offset selection strategy is an offset adaptive determination strategy
  • the processing unit is specifically configured to: obtain the average data writing speed of the leader partition; The average data writing speed is calculated, and the target offset is calculated.
  • the offset selection strategy is an offset adaptive determination strategy
  • the processing unit is specifically configured to: obtain the starting offset of the leader partition and the leader partition The average data write speed of the; according to the start offset of the leader partition and the average data write speed of the leader partition, the target offset is calculated.
  • the target offset is the maximum offset of the leader partition at the current moment
  • the target offset is the start offset of the leader partition.
  • the target offset is the maximum offset of the leader partition at the current moment
  • the target offset Is the starting offset of the leader partition.
  • the offset selection strategy is a selection strategy based on data value
  • the processing unit is specifically configured to: obtain the consumption offsets of multiple consumer groups, and determine the smallest The consumption offset is the target offset; wherein the consumer group is used to consume the data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used for Indicates the amount of data in the leader partition consumed by the consumer group.
  • the present application provides a computing device.
  • the computing device includes a processor and a memory.
  • the processor executes computer instructions stored in the memory, so that the computing device executes the first aspect described above and in combination with the first aspect described above.
  • any one of the implementation methods are possible.
  • the present application provides a computer storage medium that stores a computer program that, when executed by a computing device, implements any one of the foregoing first aspect and a combination of the foregoing first aspect Way of realization.
  • the present application provides a computer program product.
  • the computer program product includes computer instructions.
  • the computing device can execute the above-mentioned first aspect and in combination with the above-mentioned first aspect. Any one of the methods in the implementation.
  • FIG. 1A is a schematic diagram of an application scenario provided by an embodiment of the present application.
  • FIG. 1B is a schematic diagram of another application scenario provided by an embodiment of the present application.
  • FIG. 1C is a schematic diagram of another application scenario provided by an embodiment of the present application.
  • FIG. 2 is a schematic diagram of data synchronization provided by an embodiment of the present application.
  • FIG. 3 is a schematic flowchart of a data synchronization method provided by an embodiment of the present application.
  • FIG. 4 is a schematic structural diagram of a data synchronization device provided by an embodiment of the present application.
  • Fig. 5 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
  • Kafka is a distributed messaging system that supports partitions, multiple copies, and coordination based on zookeeper. It can process large amounts of data in real time to meet various demand scenarios: such as batch processing systems based on hadoop and low-latency real-time systems , Storm/spark streaming engine, access log, message service, etc. Kafka's characteristics include: high throughput, low latency, strong scalability, good durability, high fault tolerance, support for high concurrency, and it is widely used for log collection and user activity tracking.
  • Zookeeper is a distributed, open source distributed application coordination service, and an important component of Hadoop and Hbase. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc. Zookeeper's goal is to encapsulate key services that are complex and error-prone, and provide users with simple and easy-to-use interfaces and systems with high performance and stable functions.
  • FIG. 1A shows a possible application scenario of an embodiment of the present application.
  • node 110, node 120, and node 130 are node devices in Kafka cluster 100, such as servers, etc., each node stores different partitions of different topics, for example, node 110 stores the first partition The leader partition 111 of the first partition, a follower partition 112 of the first partition, and a follower partition 113 of the second partition; the node 120 stores a follower partition 121 of the first partition, a follower partition 122 of the second partition, and the leader partition 123 of the third partition; The node 130 stores the two follower partitions 131 and 132 of the third partition and the leader partition of the second partition.
  • the first partition, the second partition, and the third partition may be different partitions under the same topic, or different partitions under different topics, and each partition uses three copies for storage.
  • the Kafka cluster 100 needs to be expanded, that is, a new node 140 is added.
  • a new node 140 is added.
  • there is no data stored on the newly added node 140 is not balanced.
  • the copy migration tool kafka-reassign-partitions provided by kafka is used to migrate the follower partition 112 in the node 110 to the node 140, and the follower partition 131 in the node 130 to the node 140.
  • Figure 1B shows yet another possible application scenario.
  • the node 110 stores a leader partition 111 of the first partition, a follower partition 112 of the first partition, and a follower partition 113 of the second partition;
  • the node 120 stores a follower partition 121 of the first partition and the second partition.
  • the node 130 stores two follower partitions 131 and 132 of the third partition and the leader partition of the second partition.
  • the migration tool is used to connect the follower partition 121 and the leader in the node 120
  • the partition 123 is migrated to the node 110, and the follower partition 122 in the node 120 is migrated to the node 130.
  • Figure 1C shows yet another possible application scenario.
  • the node 110 stores the leader partition 111 of the first partition, a follower partition 112 of the first partition, and a follower partition 113 of the second partition;
  • the node 120 stores a follower partition 121 and the third partition of the first partition.
  • the leader partition 131 of the second partition is stored in the node 130.
  • the data distribution of the cluster 100 is not balanced, and a migration tool needs to be used to migrate the follower partition 113 stored in the node 110 to the node 130 to achieve a more balanced data distribution of the cluster 100.
  • the migration it is necessary to use a migration tool to migrate the follower partition on a node to another node, and the migration here does not refer to the direct transfer of data from one node.
  • the copy migration tool kafka-reassign-partitions provided by kafka is used to complete the migration of the follower partition (ie data synchronization).
  • the copy synchronization thread will be from the follower partition.
  • the leader partition pulls data until the data of the follower partition is synchronized with the data of the leader partition.
  • the newly created follower partition will synchronize from the start offset of the leader partition when synchronizing data.
  • the amount of cached data of the leader partition is large, it takes a lot of time to complete the data synchronization, and In the process of data synchronization, the CPU resources and network bandwidth resources of the nodes will continue to be occupied, which will affect the normal operation of the business.
  • the value of the data cached in Kafka will gradually decrease over time. The business or application is only interested in the latest data.
  • Cached data is meaningless, and the follower partition can only be synchronized from the starting offset of the leader partition, and the offset cannot be flexibly specified. That is, the synchronization cannot be started from any offset according to actual needs.
  • the historical cache data is synchronized.
  • this application provides a data synchronization method and related equipment, which can flexibly select the data to be synchronized from the leader partition during data synchronization, improve data synchronization efficiency, shorten data synchronization time, and reduce business Impact.
  • FIG. 2 is a schematic diagram of data synchronization provided by the present application.
  • the node 210 deploys a leader partition of a certain partition.
  • the leader partition caches the data written by the producer, including historical written data and the latest written data.
  • the node 220 deploys the corresponding partition of the same partition.
  • Follower partition and follower partition need to synchronize data from the leader partition in node 210.
  • follower partition can flexibly select the data that needs to be synchronized. For example, it can start data synchronization from the start offset of leader partition, that is, offset 1. , Synchronize all data; you can also start synchronization from offset 7 and only synchronize the latest data written by the leader partition; or select any offset (for example, offset 5, etc.) to start synchronization.
  • FIG. 3 is a schematic flowchart of a data synchronization method provided by an embodiment of the present application. As shown in Figure 3, the method includes but is not limited to the following steps:
  • the follower partition acquires an offset selection strategy.
  • the user can access zookeeper through the World Wide Web (Web) browser or other interfaces (such as restful interface, etc.) provided by the Kafka cluster, and set the offset selection strategy, which is set in the unit of topic. That is, set the offset acquisition strategy for all partitions under the same topic.
  • JSON JavaScript object notation
  • all nodes in the kafka cluster will elect a management node, which uses the watch mechanism to monitor zookeeper. Therefore, when the offset acquisition strategy is recorded in the directory specified by zookeeper, the management node will sense that the zookeeper directory has changed, and then send a synchronization request to the relevant node, that is, a new follower of the topic corresponding to the offset acquisition strategy For partition nodes, after receiving the synchronization request sent by the management node, the relevant node will start the replica synchronization thread. After the replica synchronization thread is started, the relevant node will read the offset acquisition strategy of the related topic on the zookeeper.
  • the follower partition sends a query request to the leader partition, and the query request is used to query the offset in the leader partition at the current moment; the follower partition calculates the maximum offset of the leader partition at the current moment The difference between the maximum offset from the follower partition, and when the difference is greater than the preset threshold, it is determined to synchronize the data in the leader partition to the follower partition.
  • each log has an offset to uniquely mark a message.
  • the value of the offset is an 8-byte number to indicate its position in the partition. Therefore, in the leader partition and the follower partition
  • Each stored message corresponds to a unique offset.
  • the follower partition After the follower partition starts the replica synchronization thread, it sends a query request to the leader partition to obtain the maximum offset of the leader partition at the current moment, and then calculates the difference with its own offset. If the difference exceeds the preset threshold, it means There is a large amount of data in the leader partition that has not been synchronized to the follower partition. At this time, the follower partition needs to synchronize the data in the leader partition to the local.
  • the preset threshold can be set as required, which is not limited in this application.
  • the follower partition determines the target offset in the leader partition of the topic to be synchronized based on the offset selection strategy.
  • the follower partition needs to determine the offset selection strategy before data synchronization. After the offset selection strategy is determined, it needs to further determine the target offset in the leader partition of the topic to be synchronized, that is, from which offset The volume starts to synchronize data.
  • the offset selection strategy is an offset adaptive determination strategy
  • the follower partition obtains the average data writing speed of the leader partition; the follower partition obtains the average data writing speed of the leader partition , Calculate the target offset.
  • the follower partition obtains the average data write speed of the leader partition through the interface provided by the Java management extensions (JMX) in the node where the leader partition is located, for example, obtains the leader partition in the last hour through the interface provided by JMX The average data write speed of the partition.
  • JMX Java management extensions
  • the target offset can be calculated.
  • the follower partition after the follower partition obtains the average data write speed of the leader partition, it can further send a query request to the leader partition to query the starting offset of the leader partition, and then according to the leader partition’s starting offset obtained by the query.
  • the average data write speed of the shift and leader partition, and the target shift is calculated.
  • the follower partition After the follower partition obtains the average data write speed of the leader partition, it first determines whether the speed threshold is set.
  • the speed threshold is used to limit the data synchronization transmission speed of the follower partition, so as to avoid excessive occupation during data synchronization. Excessive CPU resources and network bandwidth and other resources can avoid affecting the business and causing the business to fail to run normally. If the speed threshold is set, the speed threshold is used as the data synchronization transmission speed; if the threshold is not set, the consumption speed of the follower partition is used as the data synchronization transmission speed.
  • the follower partition when the follower partition performs data synchronization, its essence is to start a new consumer thread in the follower partition, and the follower partition acts as a consumer to consume data in the leader partition to achieve data synchronization. Therefore, if the speed threshold is not set, the consumption speed of the follower partition is the data synchronization transmission speed.
  • the follower partition judges the relationship between the data synchronization transmission speed and the leader partition’s average data write speed.
  • the leader partition’s average data write speed is greater than the data synchronization transmission speed, it means that even if the follower partition has been continuously performing data synchronization, Nor can it completely catch up with the leader partition, that is, the follower partition has been synchronizing the historical data of the leader partition. Therefore, in this case, only the latest data in the leader partition needs to be synchronized, and the maximum value of the leader partition at the current moment As the target offset, the follower partition starts data synchronization from the largest offset of the leader partition at the current moment.
  • the follower partition When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, it means that the follower partition must be able to catch up with the leader partition after sufficient time, that is, the follower partition can synchronize all data in the leader partition to the local. In this scenario, further judgment processing is required to determine the final target offset.
  • follower partition calculates the time required to synchronize the current total data volume of the leader partition.
  • follower partition can obtain the total amount of current data while obtaining the average write speed of the leader partition through the interface provided by JMX, or obtain the total amount of current data of the leader partition through other methods. This application will not do this. limited.
  • the follower partition After the follower partition obtains the current total amount of data, it divides the total amount of data by the data synchronization transmission speed to obtain the synchronization time. When the synchronization time is less than or equal to the preset time, it means that the current total amount of data in the leader partition is not very large, and the synchronization process will not cause excessive resource consumption.
  • the follower partition uses the start offset of the leader partition as the target offset
  • the follower partition synchronizes all data in the leader partition to the local.
  • the preset time can be set according to needs, for example, it can be set to one hour, which is not limited in this application.
  • the target offset can be calculated according to the following formula 1:
  • y0 represents the starting offset of the leader partition
  • y represents the target offset
  • y1 represents the maximum offset of the leader partition
  • n represents the average data volume of a message
  • v1 represents the average data write speed of the leader partition
  • V2 represents the data synchronous transmission speed.
  • the target offset can be calculated, starting from the target offset Synchronize the data in the leader partition, which can avoid the long-term occupation of CPU and network bandwidth and other resources during the data synchronization process, which will affect the business, and avoid the synchronization of some outdated and meaningless historical data to improve synchronization efficiency , Shorten the synchronization time.
  • the offset selection strategy is a selection strategy based on data value
  • the follower partition obtains the consumption offsets of multiple consumer groups
  • the follower partition determines the smallest consumption bias
  • the offset is the target offset, where the consumer group is used to consume the data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used to indicate the consumption The number of data in the leader partition consumed by the user group.
  • each consumer belongs to a specific group, and each consumer can be assigned a group name, if not specified, it belongs to the default group.
  • Consumer groups consume data in units of topics, and different consumer groups can consume the same topic. For consumers in a consumer group, consumers in the same group cannot consume the same partition of the same topic, that is, different consumers cannot consume the same partition, but the same consumer can consume multiple partitions .
  • the topic to be synchronized when multiple consumer groups consume data in the topic at the same time, find the consumer who consumes the leader partition to be synchronized from each consumer group, and obtain the consumer's consumption Offset, that is, the consumer has currently consumed the amount of data in the leader partition, and then compares the obtained consumption offset, and selects the smallest consumption offset as the target offset.
  • the offset selection strategy is an offset specification strategy
  • the follower partition uses the specified offset as the target offset.
  • the follower partition determines that the data in the leader partition needs to be synchronized to the follower partition, it directly uses the specified offset as the target offset, and starts data synchronization from the target offset.
  • the specific value of the designated offset can be set according to actual needs, which is not limited in this application.
  • the follower partition starts to synchronize the data in the leader partition to the follower partition from the determined target offset of the leader partition.
  • the follower partition After the follower partition determines the target offset, it starts a consuming thread to consume the data in the leader partition from the target offset, that is, synchronizes the data in the leader partition to the local.
  • steps S301 to S303 involved in the foregoing method embodiments are only schematic descriptions and summaries, and should not constitute specific limitations. The involved steps can be added, reduced, or combined as needed.
  • the data synchronization device 400 includes an acquisition unit 410, a processing unit 420, and a synchronization unit 430. among them,
  • the obtaining unit 410 is configured to obtain an offset selection strategy.
  • the acquiring unit 410 is configured to perform the foregoing step S301, and optionally perform optional methods in the foregoing steps.
  • the processing unit 420 is configured to determine the target offset in the leader partition of the topic to be synchronized based on the offset selection strategy.
  • the processing unit 420 is configured to execute the aforementioned step S302, and optionally execute an optional method in the aforementioned step.
  • the synchronization unit 430 is configured to synchronize data in the leader partition from the determined target offset of the leader partition.
  • the synchronization unit 430 is configured to perform the foregoing step S303, and optionally perform optional methods in the foregoing steps.
  • the data synchronization device 400 further includes a sending unit 440, the sending unit 440 is configured to send a query request to the leader partition, and the query request is used to query the leader at the current moment the offset in the partition; the processing unit 420 is further configured to calculate the difference between the offset in the leader partition and the offset in the data synchronization device at the current moment, and calculate the difference in the difference When the value is greater than the preset threshold, it is determined to synchronize the data in the leader partition.
  • the offset selection strategy is an offset adaptive determination strategy
  • the processing unit 420 is specifically configured to: obtain the average data writing speed of the leader partition; according to the leader partition The average write speed of the data is calculated, and the target offset is calculated.
  • the offset selection strategy is an offset adaptive determination strategy
  • the processing unit 420 is specifically configured to: obtain the starting offset of the leader partition and the leader The average data write speed of the partition; the target offset is calculated according to the start offset of the leader partition and the average data write speed of the leader partition.
  • the target offset is the maximum offset of the leader partition at the current moment
  • the target offset is the start offset of the leader partition.
  • the target offset is the maximum offset of the leader partition at the current moment
  • the target offset Is the starting offset of the leader partition.
  • the offset selection strategy is a selection strategy based on data value
  • the processing unit 420 is specifically configured to: obtain the consumption offsets of multiple consumer groups, and determine the smallest total value.
  • the consumption offset is the target offset; wherein, the consumer group is used to consume the data in the topic to be synchronized, and each consumer group includes at least one consumer, and the consumption offset is used Indicates the number of data in the leader partition consumed by the consumer group.
  • the structure of the data synchronization device and the process of using the data synchronization device to achieve data synchronization are only an example, and should not constitute a specific limitation.
  • the units in the data synchronization device can be added, reduced, or combined as needed.
  • the operation and/or function of each module in the data synchronization device is to realize the corresponding process of the method described in FIG. 3 above, and is not repeated here for brevity.
  • FIG. 5 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
  • the computing device 500 includes a processor 510, a communication interface 520, and a memory 530, and the processor 510, the communication interface 520, and the memory 530 are connected to each other through an internal bus 540.
  • the computing device may be a library server.
  • the computing device 500 may be a server where a follower partition is deployed in FIGS. 1A-1C, 2 and 3.
  • the functions executed by the servers in FIGS. 1A-1C, 2 and 3 are actually executed by the processor 510 of the server.
  • the processor 510 may be composed of one or more general-purpose processors, such as a central processing unit (CPU), or a combination of a CPU and a hardware chip.
  • the foregoing hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof.
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general array logic (generic array logic, GAL), or any combination thereof.
  • the bus 540 may be a peripheral component interconnect standard (PCI) bus or an extended industry standard architecture (EISA) bus, etc.
  • PCI peripheral component interconnect standard
  • EISA extended industry standard architecture
  • the bus 540 can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, only one thick line is used in FIG. 5 to represent it, but it does not mean that there is only one bus or one type of bus.
  • the memory 530 may include a volatile memory (volatile memory), such as a random access memory (random access memory, RAM); the memory 530 may also include a non-volatile memory (non-volatile memory), such as a read-only memory (read-only memory). Only memory, ROM, flash memory, hard disk drive (HDD), or solid-state drive (SSD); the memory 530 may also include a combination of the above types.
  • the program code may be used to implement the functional unit shown in the data synchronization device 400, or used to implement the method steps in the method embodiment shown in FIG. 3 with the follower partition as the execution subject.
  • the embodiments of the present application also provide a computer-readable storage medium on which a computer program is stored.
  • the program When the program is executed by a processor, it can implement part or all of the steps of any one of the above method embodiments, and realize the above Figure 4 describes the function of any one of the functional units.
  • the embodiments of the present application also provide a computer-readable storage medium on which a computer program is stored.
  • the program When the program is executed by a processor, it can implement part or all of the steps of any one of the above method embodiments, and realize the above Figure 4 describes the function of any one of the functional units.
  • the embodiments of the present application also provide a computer program product, which when it runs on a computer or a processor, enables the computer or the processor to execute one or more steps in any of the foregoing methods. If each component unit of the aforementioned equipment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in the computer readable storage medium.
  • the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not be implemented in this application.
  • the implementation process of the example constitutes any limitation.
  • the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the technical solution of the present application essentially or the part that contributes to the existing technology or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .

Landscapes

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

Abstract

The present application provides a data synchronization method and a related device. The method comprises: a follower partition obtains an offset selection policy; the follower partition determines a target offset in a leader partition of a topic to be synchronized based on the offset selection policy; and the follower partition starts to synchronize data in the leader partition from the target offset determined in the leader partition to the follower partition. The method can improve the flexibility and efficiency of data synchronization and reduce the data synchronization time.

Description

一种数据同步的方法及相关设备A data synchronization method and related equipment
本申请要求于2019年12月27日提交中国专利局、申请号为201911423080.0、申请名称为“一种数据同步的方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on December 27, 2019, the application number is 201911423080.0, and the application name is "a method of data synchronization and related equipment", the entire content of which is incorporated herein by reference Applying.
技术领域Technical field
本发明涉及信息技术领域,尤其涉及一种数据同步的方法及相关设备。The present invention relates to the field of information technology, in particular to a data synchronization method and related equipment.
背景技术Background technique
分布式发布订阅消息系统(kafka)具备良好的功能特性,它通过磁盘结构提供消息的持久化,可以保持长时间的稳定性能,具备高吞吐量,能够支持每秒数百万的消息,而且可以支持并行数据加载,所以kafka一般用于处理应用服务系统或人工智能(artificial intellingence,AI)平台产生的海量流数据。The distributed publish-subscribe messaging system (kafka) has good functional characteristics. It provides message persistence through the disk structure, can maintain long-term stable performance, has high throughput, can support millions of messages per second, and can Supports parallel data loading, so Kafka is generally used to process massive streams of data generated by application service systems or artificial intelligence (AI) platforms.
Kafka作为当前最常用的分布式消息队列系统,通常会缓存消息数据在本地磁盘上,kafka中发布订阅的对象是类别(topic),每个topic表示一类数据,一个topic又分为多个分区(partition),每个partition就是一个有序的队列。每个topic的不同partition分布在不同的磁盘或主机上,同时,kafka为了保证可靠性,每个partition又存在多个副本(replica),多个副本之间会选举出一个主副本,主副本又可以称为领导者分区(leader partition),其余的副本为从副本,又可以称为跟随者分区(follower partition)。Follower partition会持续的从leader partition同步最新的消息数据,消费者(从topic订阅消息的客户端)和生产者(向topic发布消息的客户端)在进行消费和生产时,直接和leader partition进行交互。当某个leader partition所在的节点突然发生故障或者掉电时,该partition对应的follower partition会选举出新的leader partition,从而保证服务的可靠性和数据的安全性。As the most commonly used distributed message queuing system, Kafka usually caches message data on the local disk. The object of publishing and subscribing in Kafka is a category (topic). Each topic represents a type of data, and a topic is divided into multiple partitions. (partition), each partition is an ordered queue. The different partitions of each topic are distributed on different disks or hosts. At the same time, in order to ensure the reliability of Kafka, each partition has multiple replicas (replica), and a primary replica is elected among multiple replicas. It can be called a leader partition, and the remaining replicas are slave replicas, which can also be called a follower partition. Follower partition will continuously synchronize the latest message data from leader partition. Consumers (clients that subscribe to messages from topics) and producers (clients that publish messages to topics) directly interact with leader partition when they consume and produce . When a node where a leader partition is located suddenly fails or loses power, the follower partition corresponding to the partition will elect a new leader partition to ensure service reliability and data security.
当kafka集群中的节点发生故障无法恢复,或者需要扩充kafka集群的存储容量(即增加节点数量)时,需要对kafka集群中存在的副本进行迁移以保证副本的完整性,当前对kafka集群中副本的迁移是通过kafka本身提供的迁移工具完成副本迁移,但这种方式不够灵活,迁移时间较长,效率较低,且会持续占用中央处理器(central processing unit,CPU)资源和网络带宽资源,影响业务的正常运行。When a node in the Kafka cluster fails and cannot be recovered, or the storage capacity of the Kafka cluster needs to be expanded (that is, to increase the number of nodes), the copies existing in the Kafka cluster need to be migrated to ensure the integrity of the copy. The current copy of the Kafka cluster The migration is to complete the copy migration through the migration tool provided by Kafka itself, but this method is not flexible enough, the migration time is longer, the efficiency is low, and it will continue to occupy the central processing unit (CPU) resources and network bandwidth resources. Affect the normal operation of the business.
发明内容Summary of the invention
本发明实施例公开了一种数据同步的方法及相关设备,follower partition能够从leader partition中灵活选择需要同步的数据,提高数据同步效率,缩短数据同步时间,降低对业务的影响。The embodiment of the present invention discloses a data synchronization method and related equipment. A follower partition can flexibly select data to be synchronized from a leader partition, thereby improving data synchronization efficiency, shortening data synchronization time, and reducing impact on services.
第一方面,本申请提供了一种数据同步的方法,包括:跟随者分区follower partition获取偏移量选取策略;所述follower partition基于所述偏移量选取策略确定在待同步的话题topic的领导者分区leader partition中的目标偏移量;所述follower partition从所述leader  partition的确定的目标偏移量开始同步所述leader partition中的数据到所述follower partition。In the first aspect, this application provides a data synchronization method, including: follower partition obtaining an offset selection strategy for the follower partition; the follower partition determines the leader of the topic to be synchronized based on the offset selection strategy The target offset in the leader partition of the leader partition; the follower partition starts to synchronize the data in the leader partition to the follower partition starting from the determined target offset of the leader partition.
在本申请实施例中,follower partition可以根据需要灵活选择需要同步的目标偏移量,并在确定目标偏移量之后,从leader partition中确定的目标偏移量开始同步leader partition中的数据到follower partition,这样可以提高数据同步效率,缩短数据同步时间,扩展适用场景。In the embodiment of this application, the follower partition can flexibly select the target offset that needs to be synchronized according to needs, and after determining the target offset, start to synchronize the data in the leader partition to the follower from the target offset determined in the leader partition partition, which can improve data synchronization efficiency, shorten data synchronization time, and expand applicable scenarios.
在一种可能的实现方式中,所述follower partition向所述leader partition发送查询请求,所述查询请求用于查询当前时刻所述leader partition中的偏移量;所述follower partition计算所述当前时刻所述leader partition中的偏移量与所述follower partition中的偏移量的差值,并在所述差值大于预设阈值时确定同步所述leader partition中的数据到所述follower partition。In a possible implementation manner, the follower partition sends a query request to the leader partition, and the query request is used to query the offset in the leader partition at the current moment; the follower partition calculates the current moment The difference between the offset in the leader partition and the offset in the follower partition, and when the difference is greater than a preset threshold, it is determined to synchronize the data in the leader partition to the follower partition.
在本申请实施例中,follower partition在进行数据同步之前,需要查询当前时刻leader partition中的偏移量,然后计算leader partition中的偏移量与follower partition中的偏移量的差值,并在差值大于预设阈值时进行数据同步。这样可以避免频繁的进行数据同步,只有在满足条件时才进行数据同步,从而提高系统效率。In the embodiment of this application, before the follower partition performs data synchronization, it needs to query the offset in the leader partition at the current moment, and then calculate the difference between the offset in the leader partition and the offset in the follower partition, and Data synchronization is performed when the difference is greater than the preset threshold. This can avoid frequent data synchronization, and only perform data synchronization when the conditions are met, thereby improving system efficiency.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,所述follower partition获取所述leader partition的数据平均写入速度;所述follower partition根据所述leader partition的数据平均写入速度,计算得到所述目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the follower partition obtains the average data writing speed of the leader partition; the follower partition is based on the leader partition The average write speed of the data is calculated, and the target offset is calculated.
在本申请实施例中,follower partition在偏移量选取策略为偏移量自适应确定策略时,需要获取leader partition的数据平均写入速度,从而计算得到目标偏移量。In the embodiment of the present application, when the follower partition selects the offset strategy as the offset adaptive determination strategy, it needs to obtain the average data writing speed of the leader partition, so as to calculate the target offset.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,所述follower partition获取所述leader partition的起始偏移量和所述leader partition的数据平均写入速度;所述follower partition根据所述leader partition的起始偏移量和leader partition的数据平均写入速度,计算得到所述目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the follower partition obtains the start offset of the leader partition and the average write data of the leader partition Speed; the follower partition calculates the target offset according to the start offset of the leader partition and the average data write speed of the leader partition.
在本申请实施例中,偏移量选取策略为偏移量自适应确定策略时,follower partition需要获取leader partition的起始偏移量和数据平均写入速度,这样保证计算得到的目标偏移量更加准确。In the embodiment of this application, when the offset selection strategy is an offset adaptive determination strategy, the follower partition needs to obtain the leader partition's starting offset and the average data writing speed, so as to ensure the calculated target offset more precise.
在一种可能的实现方式中,在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度时,所述目标偏移量为所述leader partition的起始偏移量。In a possible implementation manner, when the average data write speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, the target offset is the start offset of the leader partition.
在本申请实施例中,通过比较leader partition的数据平均写入速度和数据同步传输速度的关系,从而确定目标偏移量,这样,可以保证所确定的目标偏移量更加合理。In the embodiment of the present application, the target offset is determined by comparing the relationship between the average data write speed of the leader partition and the data synchronous transmission speed, so that it can be ensured that the determined target offset is more reasonable.
在一种可能的实现方式中,在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度、并且所述leader partition的当前数据总量所需要的同步时间小于预设时长时,所述目标偏移量为所述leader partition的起始偏移量。In a possible implementation manner, when the average data write speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, and the synchronization time required by the total amount of current data of the leader partition is less than the preset duration, the target offset Is the starting offset of the leader partition.
在本申请实施例中,同时考虑leader partition的数据平均写入速度与数据同步传输速度 之间的关系、以及leader partition的当前数据总量所需要的同步时间与预设时长的关系,从而确定目标偏移量,这样可以进一步提高所确定的目标偏移量的合理性和准确性。In the embodiment of this application, the relationship between the average data write speed of the leader partition and the data synchronization transmission speed, and the relationship between the synchronization time required by the current total amount of data of the leader partition and the preset duration are considered at the same time, so as to determine the target Offset, which can further improve the rationality and accuracy of the determined target offset.
在一种可能的实现方式中,所述偏移量选取策略为基于数据价值的选取策略,所述follower partition获取多个消费者组的消费偏移量,所述follower partition确定最小的所述消费偏移量为所述目标偏移量;其中,所述消费者组用于消费所述待同步topic中的数据,每个消费者组包括至少一个消费者,所述消费偏移量用于指示所述消费者组所消费的所述leader partition中的数据的数量。In a possible implementation manner, the offset selection strategy is a selection strategy based on data value, the follower partition obtains the consumption offsets of multiple consumer groups, and the follower partition determines the smallest consumption The offset is the target offset; wherein the consumer group is used to consume the data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used to indicate The number of data in the leader partition consumed by the consumer group.
在本申请实施例中,follower partition在偏移量选取策略为基于数据价值的选取策略时,需要获取多个消费待同步topic中的数据的消费者组的消费偏移量,从而确定目标偏移量,即将最小的消费偏移量确定为目标偏移量。In the embodiment of this application, when the follower partition selection strategy is a data value-based selection strategy, it is necessary to obtain the consumption offsets of multiple consumer groups that consume the data in the topic to be synchronized, so as to determine the target offset The minimum consumption offset is determined as the target offset.
第二方面,本申请提供了一种数据同步装置,包括:获取单元,用于获取偏移量选取策略;处理单元,用于基于所述偏移量选取策略确定在待同步的topic的leader partition中的目标偏移量;同步单元,用于从所述leader partition的确定的目标偏移量开始同步所述leader partition中的数据。In a second aspect, this application provides a data synchronization device, including: an acquiring unit, configured to acquire an offset selection strategy; and a processing unit, configured to determine the leader partition of the topic to be synchronized based on the offset selection strategy The synchronization unit is used to synchronize the data in the leader partition from the determined target offset of the leader partition.
在一种可能的实现方式中,所述数据同步装置还包括发送单元,所述发送单元,用于向所述leader partition发送查询请求,所述查询请求用于查询当前时刻所述leader partition中的偏移量;所述处理单元,还用于计算所述当前时刻所述leader partition中的偏移量与所述数据同步装置中的偏移量的差值,并在所述差值大于预设阈值时确定同步所述leader partition中的数据。In a possible implementation manner, the data synchronization device further includes a sending unit, the sending unit is configured to send a query request to the leader partition, and the query request is used to query the leader partition at the current moment Offset; the processing unit is also used to calculate the difference between the offset in the leader partition at the current moment and the offset in the data synchronization device, and when the difference is greater than a preset When the threshold is used, it is determined to synchronize the data in the leader partition.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,所述处理单元,具体用于:获取leader partition的数据平均写入速度;根据所述leader partition的数据平均写入速度,计算得到所述目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the processing unit is specifically configured to: obtain the average data writing speed of the leader partition; The average data writing speed is calculated, and the target offset is calculated.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,所述处理单元,具体用于:获取所述leader partition的起始偏移量和所述leader partition的数据平均写入速度;根据所述leader partition的起始偏移量和leader partition的数据平均写入速度,计算得到所述目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the processing unit is specifically configured to: obtain the starting offset of the leader partition and the leader partition The average data write speed of the; according to the start offset of the leader partition and the average data write speed of the leader partition, the target offset is calculated.
在一种可能的实现方式中,在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度时,所述目标偏移量为所述leader partition的起始偏移量。In a possible implementation manner, when the average data write speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, the target offset is the start offset of the leader partition.
在一种可能的实现方式中,在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度、并且所述leader partition的当前数据总量所需要的同步时间小于预设时长时,所述目标偏移量为所述leader partition的起始偏移量。In a possible implementation manner, when the average data write speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, and the synchronization time required by the total amount of current data of the leader partition is less than the preset duration, the target offset Is the starting offset of the leader partition.
在一种可能的实现方式中,所述偏移量选取策略为基于数据价值的选取策略,所述处理单元,具体用于:获取多个消费者组的消费偏移量,确定最小的所述消费偏移量为所述 目标偏移量;其中,所述消费者组用于消费所述待同步topic中的数据,每个消费者组包括至少一个消费者,所述消费偏移量用于指示所述消费者组所消费的所述leader partition中的数据的数量。In a possible implementation manner, the offset selection strategy is a selection strategy based on data value, and the processing unit is specifically configured to: obtain the consumption offsets of multiple consumer groups, and determine the smallest The consumption offset is the target offset; wherein the consumer group is used to consume the data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used for Indicates the amount of data in the leader partition consumed by the consumer group.
第三方面,本申请提供了一种计算设备,所述计算设备包括处理器和存储器,所述处理器执行所述存储器存储的计算机指令,使得所述计算设备执行上述第一方面以及结合上述第一方面中的任意一种实现方式的方法。In a third aspect, the present application provides a computing device. The computing device includes a processor and a memory. The processor executes computer instructions stored in the memory, so that the computing device executes the first aspect described above and in combination with the first aspect described above. On the one hand, any one of the implementation methods.
第四方面,本申请提供了一种计算机存储介质,所述计算机存储介质存储有计算机程序,所述计算机程序在被计算设备执行时实现上述第一方面以及结合上述第一方面中的任意一种实现方式的方法。In a fourth aspect, the present application provides a computer storage medium that stores a computer program that, when executed by a computing device, implements any one of the foregoing first aspect and a combination of the foregoing first aspect Way of realization.
第五方面,本申请提供了一种计算机程序产品,所述计算机程序产品包括计算机指令,当所述计算机指令被计算设备执行时,所述计算设备可以执行上述第一方面以及结合上述第一方面中的任意一种实现方式的方法。In a fifth aspect, the present application provides a computer program product. The computer program product includes computer instructions. When the computer instructions are executed by a computing device, the computing device can execute the above-mentioned first aspect and in combination with the above-mentioned first aspect. Any one of the methods in the implementation.
附图说明Description of the drawings
图1A是本申请实施例提供的一种应用场景的示意图;FIG. 1A is a schematic diagram of an application scenario provided by an embodiment of the present application;
图1B是本申请实施例提供的又一种应用场景的示意图;FIG. 1B is a schematic diagram of another application scenario provided by an embodiment of the present application;
图1C是本申请实施例提供的又一种应用场景的示意图;FIG. 1C is a schematic diagram of another application scenario provided by an embodiment of the present application;
图2是本申请实施例提供的一种数据同步的示意图;FIG. 2 is a schematic diagram of data synchronization provided by an embodiment of the present application;
图3是本申请实施例提供的一种数据同步的方法的流程示意图;FIG. 3 is a schematic flowchart of a data synchronization method provided by an embodiment of the present application;
图4是本申请实施例提供的一种数据同步装置的结构示意图;FIG. 4 is a schematic structural diagram of a data synchronization device provided by an embodiment of the present application;
图5是本申请实施例提供的一种计算设备的结构示意图。Fig. 5 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面结合附图对本申请实施例中的技术方案进行清楚、完整的描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The following describes the technical solutions in the embodiments of the present application clearly and completely with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of this application.
在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。The reference to "embodiments" herein means that a specific feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art clearly and implicitly understand that the embodiments described herein can be combined with other embodiments.
首先,结合附图对本申请中所涉及的部分用语和相关技术进行解释说明,以便于本领域技术人员理解。First of all, some terms and related technologies involved in this application will be explained in conjunction with the drawings to facilitate the understanding of those skilled in the art.
Kafka是一个分布式、支持分区的、多副本的、基于zookeeper协调的分布式消息系统, 它可以实时的处理大量数据以满足各种需求场景:比如基于hadoop的批处理系统,低延迟的实时系统,storm/spark流式处理引擎,访问日志,消息服务等等。Kafka的特性包括:高吞吐量、低时延,可扩展性强,持久性好,容错性高,支持高并发,广泛用于日志收集、用户活动跟踪等。Kafka is a distributed messaging system that supports partitions, multiple copies, and coordination based on zookeeper. It can process large amounts of data in real time to meet various demand scenarios: such as batch processing systems based on hadoop and low-latency real-time systems , Storm/spark streaming engine, access log, message service, etc. Kafka's characteristics include: high throughput, low latency, strong scalability, good durability, high fault tolerance, support for high concurrency, and it is widely used for log collection and user activity tracking.
Zookeeper是一个分布式的、开放源码的分布式应用程序协调服务,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。Zookeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。Zookeeper is a distributed, open source distributed application coordination service, and an important component of Hadoop and Hbase. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc. Zookeeper's goal is to encapsulate key services that are complex and error-prone, and provide users with simple and easy-to-use interfaces and systems with high performance and stable functions.
图1A示出了本申请实施例的一种可能的应用场景。在该应用场景中,节点110、节点120和节点130为kafka集群100中的节点设备,例如:服务器等,每个节点上都存储了不同topic的不同partition,例如节点110中存储了第一分区的leader partition111和第一分区的一个follower partition112、以及第二分区的一个follower partition113;节点120中存储了第一分区的一个follower partition121、第二分区的一个follower partition122、以及第三分区的leader partition123;节点130中存储了第三分区的两个follower partition131和132、第二分区的leader partition。第一分区、第二分区和第三分区可以是同一个topic下的不同分区,也可以是不同topic下的不同分区,每个分区采用三副本进行存储。此时需要对kafka集群100进行扩容,即新增了一个节点140,此时新增的节点140上没有存储数据,整个kafka集群100的数据分布并不均衡,需要使用迁移工具将其它节点上存储的分区迁移一部分到新增的节点140上,以保证整个集群的数据分布均衡。例如,利用kafka提供的副本迁移工具kafka-reassign-partitions将节点110中的follower partition112迁移到节点140中,将节点130中的follower partition131迁移到节点140中。Figure 1A shows a possible application scenario of an embodiment of the present application. In this application scenario, node 110, node 120, and node 130 are node devices in Kafka cluster 100, such as servers, etc., each node stores different partitions of different topics, for example, node 110 stores the first partition The leader partition 111 of the first partition, a follower partition 112 of the first partition, and a follower partition 113 of the second partition; the node 120 stores a follower partition 121 of the first partition, a follower partition 122 of the second partition, and the leader partition 123 of the third partition; The node 130 stores the two follower partitions 131 and 132 of the third partition and the leader partition of the second partition. The first partition, the second partition, and the third partition may be different partitions under the same topic, or different partitions under different topics, and each partition uses three copies for storage. At this time, the Kafka cluster 100 needs to be expanded, that is, a new node 140 is added. At this time, there is no data stored on the newly added node 140. The data distribution of the entire Kafka cluster 100 is not balanced. You need to use a migration tool to store other nodes. Part of the partition migration is to the newly added node 140 to ensure a balanced data distribution throughout the cluster. For example, the copy migration tool kafka-reassign-partitions provided by kafka is used to migrate the follower partition 112 in the node 110 to the node 140, and the follower partition 131 in the node 130 to the node 140.
图1B示出了又一种可能的应用场景。如图1B所示,节点110中存储了第一分区的leader partition111和第一分区的一个follower partition112、以及第二分区的一个follower partition113;节点120中存储了第一分区的一个follower partition121、第二分区的一个follower partition122、以及第三分区的leader partition123;节点130中存储了第三分区的两个follower partition131和132、第二分区的leader partition。此时,节点120在运行过程中出现故障,需要将节点120中存储的数据迁移到节点110和节点130中以实现整个集群100的数据分布均衡,利用迁移工具将节点120中的follower partition121和leader partition123迁移到节点110中,将节点120中的follower partition122迁移到节点130中。Figure 1B shows yet another possible application scenario. As shown in Figure 1B, the node 110 stores a leader partition 111 of the first partition, a follower partition 112 of the first partition, and a follower partition 113 of the second partition; the node 120 stores a follower partition 121 of the first partition and the second partition. One follower partition 122 of the partition and the leader partition 123 of the third partition; the node 130 stores two follower partitions 131 and 132 of the third partition and the leader partition of the second partition. At this time, the node 120 fails during operation, and the data stored in the node 120 needs to be migrated to the node 110 and the node 130 to achieve the data distribution balance of the entire cluster 100. The migration tool is used to connect the follower partition 121 and the leader in the node 120 The partition 123 is migrated to the node 110, and the follower partition 122 in the node 120 is migrated to the node 130.
图1C示出了又一种可能的应用场景。如图1C所示,节点110中存储了第一分区的leader partition111和第一分区的一个follower partition112、以及第二分区的一个follower partition113;节点120中存储了第一分区的一个follower partition121和第三分区的leader partition122;节点130中存储了第二分区的leader partition131。此时,集群100的数据分布并不均衡,需要利用迁移工具将节点110中存储的follower partition113迁移到节点130中,以实现集群100的数据分布更加均衡。Figure 1C shows yet another possible application scenario. As shown in Figure 1C, the node 110 stores the leader partition 111 of the first partition, a follower partition 112 of the first partition, and a follower partition 113 of the second partition; the node 120 stores a follower partition 121 and the third partition of the first partition. The leader partition 122 of the partition; the leader partition 131 of the second partition is stored in the node 130. At this time, the data distribution of the cluster 100 is not balanced, and a migration tool needs to be used to migrate the follower partition 113 stored in the node 110 to the node 130 to achieve a more balanced data distribution of the cluster 100.
对于上述图1A、图1B和图1C所示的应用场景,都需要利用迁移工具将某个节点上的follower partition迁移到另一个节点上,而这里的迁移并不是指将数据直接从一个节点搬 运到另一个节点,而是以同步的方式从follower partition对应的leader partition处拉取数据,最终达到和leader partition中的数据一致,完成实现迁移的目的。而当前都是利用kafka提供的副本迁移工具kafka-reassign-partitions以完成follower partition的迁移(即数据同步),当节点中有新的follower partition被创建时,副本同步线程会从该follower partition对应的leader partition处拉取数据,直到该follower partition的数据与leader partition的数据同步。但是在上述方案中,新创建的follower partition在同步数据时会从leader partition的起始偏移量开始同步,当leader partition的缓存数据量很大时,需要花费大量的时间来完成数据同步,且在数据同步的过程中会持续占用节点的CPU资源、网络带宽资源等,影响业务的正常运行,此外,很多场景下,kafka中缓存的数据价值会随着时间的推移而逐渐减小,而实际业务或应用只对最新的数据感兴趣,例如在统计一分钟内目标出现的次数的应用场景中,只是当前一分钟内的数据有价值,而之前的数据价值较低,因此,同步大量的历史缓存数据并没有意义,而follower partition只能从leader partition的起始偏移量进行同步,不能灵活指定偏移量,即无法根据实际需要从任意偏移量开始进行同步,无法避免对没有价值的历史缓存数据进行同步。For the application scenarios shown in Figure 1A, Figure 1B, and Figure 1C, it is necessary to use a migration tool to migrate the follower partition on a node to another node, and the migration here does not refer to the direct transfer of data from one node. To another node, it pulls data from the leader partition corresponding to the follower partition in a synchronous manner, and finally achieves the consistency with the data in the leader partition, completing the purpose of migrating. At present, the copy migration tool kafka-reassign-partitions provided by kafka is used to complete the migration of the follower partition (ie data synchronization). When a new follower partition is created in the node, the copy synchronization thread will be from the follower partition. The leader partition pulls data until the data of the follower partition is synchronized with the data of the leader partition. However, in the above scheme, the newly created follower partition will synchronize from the start offset of the leader partition when synchronizing data. When the amount of cached data of the leader partition is large, it takes a lot of time to complete the data synchronization, and In the process of data synchronization, the CPU resources and network bandwidth resources of the nodes will continue to be occupied, which will affect the normal operation of the business. In addition, in many scenarios, the value of the data cached in Kafka will gradually decrease over time. The business or application is only interested in the latest data. For example, in an application scenario that counts the number of occurrences of a target within one minute, only the current data within one minute is valuable, while the previous data is of low value. Therefore, a large amount of history is synchronized Cached data is meaningless, and the follower partition can only be synchronized from the starting offset of the leader partition, and the offset cannot be flexibly specified. That is, the synchronization cannot be started from any offset according to actual needs. The historical cache data is synchronized.
为了解决上述问题,本申请提供了一种数据同步的方法及相关设备,可以在进行数据同步时,从leader partition中灵活选择需要同步的数据,提高数据同步效率,缩短数据同步时间,降低对业务的影响。In order to solve the above problems, this application provides a data synchronization method and related equipment, which can flexibly select the data to be synchronized from the leader partition during data synchronization, improve data synchronization efficiency, shorten data synchronization time, and reduce business Impact.
参见图2,图2是本申请提供的一种数据同步的示意图。如图2所示,节点210部署了某个分区的leader partition,该leader partition中缓存了生产者写入的数据,包括历史写入数据和最新写入数据,节点220部署了该相同分区对应的follower partition,follower partition需要从节点210中的leader partition同步数据,follower partition可以灵活选择需要同步的数据,例如,可以从leader partition的起始偏移量,即偏移量1的地方开始进行数据同步,将所有的数据进行同步;也可以从偏移量7的地方开始同步,只同步leader partition最新写入的数据;或者是选择任意偏移量(例如偏移量5等)开始同步。Refer to FIG. 2, which is a schematic diagram of data synchronization provided by the present application. As shown in Figure 2, the node 210 deploys a leader partition of a certain partition. The leader partition caches the data written by the producer, including historical written data and the latest written data. The node 220 deploys the corresponding partition of the same partition. Follower partition and follower partition need to synchronize data from the leader partition in node 210. Follower partition can flexibly select the data that needs to be synchronized. For example, it can start data synchronization from the start offset of leader partition, that is, offset 1. , Synchronize all data; you can also start synchronization from offset 7 and only synchronize the latest data written by the leader partition; or select any offset (for example, offset 5, etc.) to start synchronization.
结合图1A、图1B和图1C所示的应用场景、以及图2所示的数据同步示意图,参阅图3,图3是本申请实施例提供的一种数据同步的方法的流程示意图。如图3所示,该方法包括但不限于以下步骤:With reference to the application scenarios shown in FIG. 1A, FIG. 1B, and FIG. 1C, and the data synchronization schematic diagram shown in FIG. 2, refer to FIG. 3. FIG. 3 is a schematic flowchart of a data synchronization method provided by an embodiment of the present application. As shown in Figure 3, the method includes but is not limited to the following steps:
S301:跟随者分区follower partition获取偏移量选取策略。S301: The follower partition acquires an offset selection strategy.
举例说明,用户可以通过kafka集群提供的万维网(world wide web,Web)浏览器或其它接口(例如restful接口等)访问zookeeper,设置偏移量选取策略,该策略是以topic为单位进行设置的,即对同一个topic下的所有partition设置偏移量获取策略。在设置完成后,可以将设置好的偏移量获取策略保存为JavaScript对象符号(JavaScript object notation,JSON)格式的文件,并将该文件记录在zookeeper的指定目录下。For example, the user can access zookeeper through the World Wide Web (Web) browser or other interfaces (such as restful interface, etc.) provided by the Kafka cluster, and set the offset selection strategy, which is set in the unit of topic. That is, set the offset acquisition strategy for all partitions under the same topic. After the setting is complete, you can save the set offset acquisition strategy as a JavaScript object notation (JSON) format file, and record the file in the specified directory of zookeeper.
此外,kafka集群中的所有节点会选举出一个管理节点,该管理节点利用watch机制监测zookeeper。因此当将偏移量获取策略记录在zookeeper指定的目录下时,管理节点会感知到zookeeper的目录发生变化,然后发送同步请求到相关节点,即新建了该偏移量获取策 略对应的topic的follower partition的节点,相关节点在接收到管理节点发送的同步请求之后,则会启动副本同步线程,在副本同步线程启动后,相关节点会读取zookeeper上的相关topic的偏移量获取策略。In addition, all nodes in the kafka cluster will elect a management node, which uses the watch mechanism to monitor zookeeper. Therefore, when the offset acquisition strategy is recorded in the directory specified by zookeeper, the management node will sense that the zookeeper directory has changed, and then send a synchronization request to the relevant node, that is, a new follower of the topic corresponding to the offset acquisition strategy For partition nodes, after receiving the synchronization request sent by the management node, the relevant node will start the replica synchronization thread. After the replica synchronization thread is started, the relevant node will read the offset acquisition strategy of the related topic on the zookeeper.
一种可能的实现方式,该follower partition向leader partition发送查询请求,所述查询请求用于查询当前时刻所述leader partition中的偏移量;该follower partition计算当前时刻leader partition的最大的偏移量与follower partition的最大的偏移量的差值,并在差值大于预设阈值时确定同步leader partition中的数据到follower partition。In a possible implementation manner, the follower partition sends a query request to the leader partition, and the query request is used to query the offset in the leader partition at the current moment; the follower partition calculates the maximum offset of the leader partition at the current moment The difference between the maximum offset from the follower partition, and when the difference is greater than the preset threshold, it is determined to synchronize the data in the leader partition to the follower partition.
具体地,每个日志都有一个偏移量来唯一的标记一条消息,偏移量的值为8个字节的数字,用来表示其在partition中的位置,因此,leader partition和follower partition中存储的每一个消息(即数据)都对应一个唯一的偏移量。Follower partition在启动副本同步线程之后,向leader partition发送查询请求以获取当前时刻leader partition的最大的偏移量,然后计算与自身的偏移量的差值,若差值超过预设阈值,则说明leader partition中存在大量的数据还没有同步到follower partition中,此时,follower partition需要将leader partition中的数据同步到本地。应理解,预设阈值可以根据需要进行设置,本申请对此不作限定。Specifically, each log has an offset to uniquely mark a message. The value of the offset is an 8-byte number to indicate its position in the partition. Therefore, in the leader partition and the follower partition Each stored message (ie data) corresponds to a unique offset. After the follower partition starts the replica synchronization thread, it sends a query request to the leader partition to obtain the maximum offset of the leader partition at the current moment, and then calculates the difference with its own offset. If the difference exceeds the preset threshold, it means There is a large amount of data in the leader partition that has not been synchronized to the follower partition. At this time, the follower partition needs to synchronize the data in the leader partition to the local. It should be understood that the preset threshold can be set as required, which is not limited in this application.
S302:跟随者分区基于偏移量选取策略确定在待同步的话题的领导者分区中的目标偏移量。S302: The follower partition determines the target offset in the leader partition of the topic to be synchronized based on the offset selection strategy.
具体地,follower partition在进行数据同步之前需要确定偏移量选取策略,在确定偏移量选取策略确定之后,需要进一步在待同步的topic的leader partition中的目标偏移量,即从哪个偏移量开始进行数据同步。Specifically, the follower partition needs to determine the offset selection strategy before data synchronization. After the offset selection strategy is determined, it needs to further determine the target offset in the leader partition of the topic to be synchronized, that is, from which offset The volume starts to synchronize data.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,该follower partition获取leader partition的数据平均写入速度;该follower partition根据leader partition的数据平均写入速度,计算得到目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the follower partition obtains the average data writing speed of the leader partition; the follower partition obtains the average data writing speed of the leader partition , Calculate the target offset.
具体地,该follower partition通过leader partition所在的节点中的Java管理扩展(Java management extensions,JMX)提供的接口获取到leader partition的数据平均写入速度,例如通过JMX提供的接口获取最近一小时内leader partition的数据平均写入速度。Follower partition在获取到leader partition的数据平均写入速度之后,可以计算得到目标偏移量。Specifically, the follower partition obtains the average data write speed of the leader partition through the interface provided by the Java management extensions (JMX) in the node where the leader partition is located, for example, obtains the leader partition in the last hour through the interface provided by JMX The average data write speed of the partition. After the follower partition obtains the average write speed of the leader partition's data, the target offset can be calculated.
可选的,follower partition在获取到leader partition的数据平均写入速度之后,可以进一步的向leader partition发送查询请求,查询leader partition的起始偏移量,然后根据查询得到的leader partition的起始偏移量和leader partition的数据平均写入速度,计算得到目标偏移量。Optionally, after the follower partition obtains the average data write speed of the leader partition, it can further send a query request to the leader partition to query the starting offset of the leader partition, and then according to the leader partition’s starting offset obtained by the query. The average data write speed of the shift and leader partition, and the target shift is calculated.
示例性的,follower partition在获取到leader partition的数据平均写入速度之后,首先判断是否设置了速度阈值,该速度阈值是用于限制follower partition的数据同步传输速度,避免在进行数据同步时占用过多的CPU资源和网络带宽等资源,避免对业务造成影响,导致业务不能正常运行。若设置了速度阈值,则将该速度阈值作为数据同步传输速度;若没有设置阈值,则将follower partition的消费速度作为数据同步传输速度。Exemplarily, after the follower partition obtains the average data write speed of the leader partition, it first determines whether the speed threshold is set. The speed threshold is used to limit the data synchronization transmission speed of the follower partition, so as to avoid excessive occupation during data synchronization. Excessive CPU resources and network bandwidth and other resources can avoid affecting the business and causing the business to fail to run normally. If the speed threshold is set, the speed threshold is used as the data synchronization transmission speed; if the threshold is not set, the consumption speed of the follower partition is used as the data synchronization transmission speed.
举例说明,follower partition在进行数据同步时,其本质是在follower partition中另起一个消费线程,follower partition作为一个消费者去消费leader partition中的数据以实现数据的同步。因此,在没有设置速度阈值的情况下,follower partition的消费速度即为数据同 步传输速度。For example, when the follower partition performs data synchronization, its essence is to start a new consumer thread in the follower partition, and the follower partition acts as a consumer to consume data in the leader partition to achieve data synchronization. Therefore, if the speed threshold is not set, the consumption speed of the follower partition is the data synchronization transmission speed.
然后,follower partition判断数据同步传输速度与leader partition的数据平均写入速度的大小关系,当leader partition的数据平均写入速度大于数据同步传输速度,则说明即使follower partition一直不间断的进行数据同步,也不能完全追赶上leader partition,即follower partition一直同步的是leader partition的历史数据,因此,在这种情况下,只需要同步leader partition中的最新数据即可,则将上述当前时刻leader partition的最大的偏移量作为目标偏移量,follower partition从当前时刻leader partition的最大的偏移量开始进行数据同步。当leader partition的数据平均写入速度小于或等于数据同步传输速度,则说明follower partition经过足够的时间之后,一定可以追赶上leader partition,即follower partition可以实现将leader partition中的所有数据同步到本地,在这种场景下,需要进行进一步的判断处理,从而确定最终的目标偏移量。Then, the follower partition judges the relationship between the data synchronization transmission speed and the leader partition’s average data write speed. When the leader partition’s average data write speed is greater than the data synchronization transmission speed, it means that even if the follower partition has been continuously performing data synchronization, Nor can it completely catch up with the leader partition, that is, the follower partition has been synchronizing the historical data of the leader partition. Therefore, in this case, only the latest data in the leader partition needs to be synchronized, and the maximum value of the leader partition at the current moment As the target offset, the follower partition starts data synchronization from the largest offset of the leader partition at the current moment. When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, it means that the follower partition must be able to catch up with the leader partition after sufficient time, that is, the follower partition can synchronize all data in the leader partition to the local. In this scenario, further judgment processing is required to determine the final target offset.
一种可能的实现方式,follower partition计算同步leader partition的当前数据总量所需要的时间。可选的,follower partition可以通过JMX提供的接口在获取leader partition的平均写入速度的同时获取到当前数据总量,也可以通过其它方式获取到leader partition的当前数据总量,本申请对此不作限定。Follower partition在获取到当前数据总量之后,利用该数据总量除以数据同步传输速度得到同步时间。当同步时间小于或等于预设时间时,则说明leader partition当前的数据总量并不是很多,同步过程不会造成过大的资源消耗,follower partition将leader partition的起始偏移量作为目标偏移量,follower partition将leader partition中的所有数据都同步到本地。预设时间可以根据需要进行设置,例如可以设置为一小时,本申请对此不作限定。A possible implementation is that the follower partition calculates the time required to synchronize the current total data volume of the leader partition. Optionally, follower partition can obtain the total amount of current data while obtaining the average write speed of the leader partition through the interface provided by JMX, or obtain the total amount of current data of the leader partition through other methods. This application will not do this. limited. After the follower partition obtains the current total amount of data, it divides the total amount of data by the data synchronization transmission speed to obtain the synchronization time. When the synchronization time is less than or equal to the preset time, it means that the current total amount of data in the leader partition is not very large, and the synchronization process will not cause excessive resource consumption. The follower partition uses the start offset of the leader partition as the target offset The follower partition synchronizes all data in the leader partition to the local. The preset time can be set according to needs, for example, it can be set to one hour, which is not limited in this application.
当同步时间大于预设时间时,可以根据下述公式1计算目标偏移量:When the synchronization time is greater than the preset time, the target offset can be calculated according to the following formula 1:
((y-y0)*n)/v1=((y1-y)*n)/(v2-v1)  公式1((y-y0)*n)/v1=((y1-y)*n)/(v2-v1) Formula 1
其中,y0表示leader partition的起始偏移量,y表示目标偏移量,y1表示leader partition的最大的偏移量,n表示平均一条消息的数据量,v1表示leader partition的数据平均写入速度,v2表示数据同步传输速度。Among them, y0 represents the starting offset of the leader partition, y represents the target offset, y1 represents the maximum offset of the leader partition, n represents the average data volume of a message, and v1 represents the average data write speed of the leader partition , V2 represents the data synchronous transmission speed.
对上述公式1进行进一步简化,可以得到下述公式2:Simplifying the above formula 1 further, the following formula 2 can be obtained:
y=(y1*v1+(v2-v1)y0)/v2  公式2y=(y1*v1+(v2-v1)y0)/v2 Formula 2
可以看出,在得到leader partition的起始偏移量和最大的偏移量、leader partition的数据平均写入速度以及数据同步传输速度之后,可以计算得到目标偏移量,从目标偏移量开始同步leader partition中的数据,这样既可以避免在数据同步过程中,长期占用CPU和网络带宽等资源,对业务造成影响,又可以避免对一些过期的、没有意义的历史数据进行同步,提高同步效率,缩短同步时间。It can be seen that after obtaining the starting offset and maximum offset of the leader partition, the average data writing speed of the leader partition, and the data synchronization transmission speed, the target offset can be calculated, starting from the target offset Synchronize the data in the leader partition, which can avoid the long-term occupation of CPU and network bandwidth and other resources during the data synchronization process, which will affect the business, and avoid the synchronization of some outdated and meaningless historical data to improve synchronization efficiency , Shorten the synchronization time.
在又一种可能的实现方式中,所述偏移量选取策略为基于数据价值的选取策略,所述follower partition获取多个消费者组的消费偏移量,所述follower partition确定最小的消费偏移量为目标偏移量,其中,所述消费者组用于消费所述待同步topic中的数据,每个消费者组包括至少一个消费者,所述消费偏移量用于指示所述消费者组所消费的所述leader partition中的数据的数量。In another possible implementation manner, the offset selection strategy is a selection strategy based on data value, the follower partition obtains the consumption offsets of multiple consumer groups, and the follower partition determines the smallest consumption bias The offset is the target offset, where the consumer group is used to consume the data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used to indicate the consumption The number of data in the leader partition consumed by the user group.
具体地,每个消费者都属于一个特定的组,可以为每个消费者指定组名字,若不指定 则属于默认的组。消费者组在消费数据时,是以topic为单位进行的,不同消费者组之间可以消费同一个topic。而对于一个消费者组内的消费者来说,同一个组内的消费者不能消费同一个topic的同一个partition,即不同消费者不能消费同一个partition,但同一个消费者可以消费多个partition。Specifically, each consumer belongs to a specific group, and each consumer can be assigned a group name, if not specified, it belongs to the default group. Consumer groups consume data in units of topics, and different consumer groups can consume the same topic. For consumers in a consumer group, consumers in the same group cannot consume the same partition of the same topic, that is, different consumers cannot consume the same partition, but the same consumer can consume multiple partitions .
因此,对于待同步topic来说,当存在多个消费者组同时消费该topic内的数据时,从每个消费者组中找到消费待同步的leader partition的消费者,并获取该消费者的消费偏移量,即该消费者当前已经消费了leader partition中的数据的数量,然后将获取到的那个消费偏移量进行比较,选择最小的消费偏移量作为目标偏移量。Therefore, for the topic to be synchronized, when multiple consumer groups consume data in the topic at the same time, find the consumer who consumes the leader partition to be synchronized from each consumer group, and obtain the consumer's consumption Offset, that is, the consumer has currently consumed the amount of data in the leader partition, and then compares the obtained consumption offset, and selects the smallest consumption offset as the target offset.
容易理解,将最小的消费偏移量作为目标偏移量,可以保证在leader partition所在的节点突然出现故障发生宕机时,所有的消费者组仍能够完整消费该topic内的数据,避免对业务造成影响。It is easy to understand that using the smallest consumption offset as the target offset can ensure that when the leader partition node suddenly fails and goes down, all consumer groups can still consume the data in the topic completely, avoiding business Make an impact.
在又一种可能的实现方式中,所述偏移量选取策略为偏移量指定策略,所述follower partition使用指定的偏移量作为目标偏移量。In another possible implementation manner, the offset selection strategy is an offset specification strategy, and the follower partition uses the specified offset as the target offset.
具体地,该follower partition在确定需要同步leader partition中的数据到follower partition后,直接利用指定的偏移量作为目标偏移量,并从目标偏移量开始进行数据同步。指定的偏移量的具体值可以根据实际需要进行设置,本申请对此不作限定。Specifically, after the follower partition determines that the data in the leader partition needs to be synchronized to the follower partition, it directly uses the specified offset as the target offset, and starts data synchronization from the target offset. The specific value of the designated offset can be set according to actual needs, which is not limited in this application.
S303:跟随者分区从领导者分区的确定的目标偏移量开始同步领导者分区中的数据到该跟随者分区。S303: The follower partition starts to synchronize the data in the leader partition to the follower partition from the determined target offset of the leader partition.
具体地,follower partition在确定目标偏移量之后,启动一个消费线程从目标偏移量开始消费leader partition中数据,即将leader partition中的数据同步到本地。Specifically, after the follower partition determines the target offset, it starts a consuming thread to consume the data in the leader partition from the target offset, that is, synchronizes the data in the leader partition to the local.
应理解,上述方法实施例所涉及的步骤S301至步骤S303只是示意性的描述概括,不应构成具体限定,可以根据需要对所涉及的步骤进行增加、减少或合并。It should be understood that steps S301 to S303 involved in the foregoing method embodiments are only schematic descriptions and summaries, and should not constitute specific limitations. The involved steps can be added, reduced, or combined as needed.
上述详细阐述了本申请实施例的方法,为了便于更好的实施本申请实施例的上述方案,相应地,下面还提供用于配合实施上述方案的相关设备。The foregoing describes the methods of the embodiments of the present application in detail. In order to facilitate better implementation of the above solutions of the embodiments of the present application, correspondingly, the following also provides related equipment for cooperating with the implementation of the foregoing solutions.
参见图4,图4是本申请实施例提供的一种数据同步装置的结构示意图。如图4所示,该数据同步装置400包括获取单元410、处理单元420和同步单元430。其中,Refer to FIG. 4, which is a schematic structural diagram of a data synchronization device provided by an embodiment of the present application. As shown in FIG. 4, the data synchronization device 400 includes an acquisition unit 410, a processing unit 420, and a synchronization unit 430. among them,
获取单元410,用于获取偏移量选取策略。The obtaining unit 410 is configured to obtain an offset selection strategy.
具体地,所述获取单元410用于执行前述步骤S301,且可选的执行前述步骤中可选的方法。Specifically, the acquiring unit 410 is configured to perform the foregoing step S301, and optionally perform optional methods in the foregoing steps.
处理单元420,用于基于所述偏移量选取策略确定在待同步的topic的leader partition中的目标偏移量。The processing unit 420 is configured to determine the target offset in the leader partition of the topic to be synchronized based on the offset selection strategy.
具体地,所述处理单元420用于执行前述步骤S302,且可选的执行前述步骤中可选的方法。Specifically, the processing unit 420 is configured to execute the aforementioned step S302, and optionally execute an optional method in the aforementioned step.
同步单元430,用于从所述leader partition的确定的目标偏移量开始同步所述leader partition中的数据。The synchronization unit 430 is configured to synchronize data in the leader partition from the determined target offset of the leader partition.
具体地,所述同步单元430用于执行前述步骤S303,且可选的执行前述步骤中可选的方法。Specifically, the synchronization unit 430 is configured to perform the foregoing step S303, and optionally perform optional methods in the foregoing steps.
在一种可能的实现方式中,所述数据同步装置400还包括发送单元440,所述发送单元440,用于向所述leader partition发送查询请求,所述查询请求用于查询当前时刻所述leader partition中的偏移量;所述处理单元420,还用于计算所述当前时刻所述leader partition中的偏移量与所述数据同步装置中的偏移量的差值,并在所述差值大于预设阈值时确定同步所述leader partition中的数据。In a possible implementation manner, the data synchronization device 400 further includes a sending unit 440, the sending unit 440 is configured to send a query request to the leader partition, and the query request is used to query the leader at the current moment the offset in the partition; the processing unit 420 is further configured to calculate the difference between the offset in the leader partition and the offset in the data synchronization device at the current moment, and calculate the difference in the difference When the value is greater than the preset threshold, it is determined to synchronize the data in the leader partition.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,所述处理单元420,具体用于:获取leader partition的数据平均写入速度;根据所述leader partition的数据平均写入速度,计算得到所述目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the processing unit 420 is specifically configured to: obtain the average data writing speed of the leader partition; according to the leader partition The average write speed of the data is calculated, and the target offset is calculated.
在一种可能的实现方式中,所述偏移量选取策略为偏移量自适应确定策略,所述处理单元420,具体用于:获取所述leader partition的起始偏移量和所述leader partition的数据平均写入速度;根据所述leader partition的起始偏移量和leader partition的数据平均写入速度,计算得到所述目标偏移量。In a possible implementation manner, the offset selection strategy is an offset adaptive determination strategy, and the processing unit 420 is specifically configured to: obtain the starting offset of the leader partition and the leader The average data write speed of the partition; the target offset is calculated according to the start offset of the leader partition and the average data write speed of the leader partition.
在一种可能的实现方式中,在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度时,所述目标偏移量为所述leader partition的起始偏移量。In a possible implementation manner, when the average data write speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, the target offset is the start offset of the leader partition.
在一种可能的实现方式中,在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度、并且所述leader partition的当前数据总量所需要的同步时间小于预设时长时,所述目标偏移量为所述leader partition的起始偏移量。In a possible implementation manner, when the average data write speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, and the synchronization time required by the total amount of current data of the leader partition is less than the preset duration, the target offset Is the starting offset of the leader partition.
在一种可能的实现方式中,所述偏移量选取策略为基于数据价值的选取策略,所述处理单元420,具体用于:获取多个消费者组的消费偏移量,确定最小的所述消费偏移量为所述目标偏移量;其中,所述消费者组用于消费所述待同步topic中的数据,每个消费者组包括至少一个消费者,所述消费偏移量用于指示所述消费者组所消费的所述leader partition中的数据的数量。In a possible implementation, the offset selection strategy is a selection strategy based on data value, and the processing unit 420 is specifically configured to: obtain the consumption offsets of multiple consumer groups, and determine the smallest total value. The consumption offset is the target offset; wherein, the consumer group is used to consume the data in the topic to be synchronized, and each consumer group includes at least one consumer, and the consumption offset is used Indicates the number of data in the leader partition consumed by the consumer group.
需要说明的是,上述数据同步装置的结构以及利用数据同步装置实现数据同步的过程仅仅作为一种示例,不应构成具体限定,可以根据需要对数据同步装置中的各个单元进行增加、减少或合并。此外,数据同步装置中的各个模块的操作和/或功能为了实现上述图3所描述的方法的相应流程,为了简洁,在此不再赘述。It should be noted that the structure of the data synchronization device and the process of using the data synchronization device to achieve data synchronization are only an example, and should not constitute a specific limitation. The units in the data synchronization device can be added, reduced, or combined as needed. . In addition, the operation and/or function of each module in the data synchronization device is to realize the corresponding process of the method described in FIG. 3 above, and is not repeated here for brevity.
参见图5,图5是本申请实施例提供的一种计算设备的结构示意图。如图5所示,该计算设备500包括:处理器510、通信接口520以及存储器530,所述处理器510、通信接口520以及存储器530通过内部总线540相互连接。应理解,该计算设备可以是库服务器。Referring to FIG. 5, FIG. 5 is a schematic structural diagram of a computing device provided by an embodiment of the present application. As shown in FIG. 5, the computing device 500 includes a processor 510, a communication interface 520, and a memory 530, and the processor 510, the communication interface 520, and the memory 530 are connected to each other through an internal bus 540. It should be understood that the computing device may be a library server.
所述计算设备500可以是图1A-图1C、图2和图3中部署了follower partition的服务器。图1A-图1C、图2和图3中的服务器所执行的功能实际上是由所述服务器的处理器510来执行。The computing device 500 may be a server where a follower partition is deployed in FIGS. 1A-1C, 2 and 3. The functions executed by the servers in FIGS. 1A-1C, 2 and 3 are actually executed by the processor 510 of the server.
所述处理器510可以由一个或者多个通用处理器构成,例如中央处理器(central processing unit,CPU),或者CPU和硬件芯片的组合。上述硬件芯片可以是专用集成电路 (application-specific integrated circuit,ASIC)、可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD)、现场可编程逻辑门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合。The processor 510 may be composed of one or more general-purpose processors, such as a central processing unit (CPU), or a combination of a CPU and a hardware chip. The foregoing hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general array logic (generic array logic, GAL), or any combination thereof.
总线540可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。所述总线540可以分为地址总线、数据总线、控制总线等。为便于表示,图5中仅用一条粗线表示,但不表示仅有一根总线或一种类型的总线。The bus 540 may be a peripheral component interconnect standard (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus 540 can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, only one thick line is used in FIG. 5 to represent it, but it does not mean that there is only one bus or one type of bus.
存储器530可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM);存储器530也可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM)、快闪存储器(flash memory)、硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器530还可以包括上述种类的组合。程序代码可以是用来实现数据同步装置400所示的功能单元,或者用于实现图3所示的方法实施例中以follower partition为执行主体的方法步骤。The memory 530 may include a volatile memory (volatile memory), such as a random access memory (random access memory, RAM); the memory 530 may also include a non-volatile memory (non-volatile memory), such as a read-only memory (read-only memory). Only memory, ROM, flash memory, hard disk drive (HDD), or solid-state drive (SSD); the memory 530 may also include a combination of the above types. The program code may be used to implement the functional unit shown in the data synchronization device 400, or used to implement the method steps in the method embodiment shown in FIG. 3 with the follower partition as the execution subject.
本申请实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时,可以实现上述方法实施例中记载的任意一种的部分或全部步骤,以及实现上述图4所描述的任意一个功能单元的功能。The embodiments of the present application also provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it can implement part or all of the steps of any one of the above method embodiments, and realize the above Figure 4 describes the function of any one of the functional units.
本申请实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时,可以实现上述方法实施例中记载的任意一种的部分或全部步骤,以及实现上述图4所描述的任意一个功能单元的功能。The embodiments of the present application also provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it can implement part or all of the steps of any one of the above method embodiments, and realize the above Figure 4 describes the function of any one of the functional units.
本申请实施例还提供了一种计算机程序产品,当其在计算机或处理器上运行时,使得计算机或处理器执行上述任一个方法中的一个或多个步骤。上述所涉及的设备的各组成单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在所述计算机可读取存储介质中。The embodiments of the present application also provide a computer program product, which when it runs on a computer or a processor, enables the computer or the processor to execute one or more steps in any of the foregoing methods. If each component unit of the aforementioned equipment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in the computer readable storage medium.
在上述实施例中,对各个实施例的描述各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。In the above-mentioned embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in an embodiment, reference may be made to related descriptions of other embodiments.
还应理解,在本申请的各种实施例中,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should also be understood that, in the various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not be implemented in this application. The implementation process of the example constitutes any limitation.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of description, the specific working process of the system, device and unit described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的 介质。If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solution of the present application essentially or the part that contributes to the existing technology or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .
以上所述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: The technical solutions recorded in the embodiments are modified, or some of the technical features are equivalently replaced; these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims (17)

  1. 一种数据同步的方法,其特征在于,所述方法包括:A method for data synchronization, characterized in that the method includes:
    跟随者分区follower partition获取偏移量选取策略;Follower partition follower partition obtains offset selection strategy;
    所述follower partition基于所述偏移量选取策略确定在待同步的话题topic的领导者分区leader partition中的目标偏移量;The follower partition determines the target offset in the leader partition of the topic to be synchronized based on the offset selection strategy;
    所述follower partition从所述leader partition的确定的目标偏移量开始同步所述leader partition中的数据到所述follower partition。The follower partition starts to synchronize the data in the leader partition to the follower partition from the determined target offset of the leader partition.
  2. 如权利要求1所述的方法,其特征在于,所述方法还包括:The method of claim 1, wherein the method further comprises:
    所述follower partition向所述leader partition发送查询请求,所述查询请求用于查询当前时刻所述leader partition中的偏移量;The follower partition sends a query request to the leader partition, and the query request is used to query the offset in the leader partition at the current moment;
    所述follower partition计算所述当前时刻所述leader partition中的偏移量与所述follower partition中的偏移量的差值,并在所述差值大于预设阈值时确定同步所述leader partition中的数据到所述follower partition。The follower partition calculates the difference between the offset in the leader partition and the offset in the follower partition at the current moment, and determines to synchronize the leader partition when the difference is greater than a preset threshold The data to the follower partition.
  3. 如权利要求1或2所述的方法,其特征在于,所述偏移量选取策略为偏移量自适应确定策略,所述follower partition基于所述偏移量选取策略确定在待同步的topic的leader partition中的偏移量,包括:The method according to claim 1 or 2, wherein the offset selection strategy is an offset adaptive determination strategy, and the follower partition determines the location of the topic to be synchronized based on the offset selection strategy. The offset in the leader partition, including:
    所述follower partition获取所述leader partition的数据平均写入速度;The follower partition obtains the average data writing speed of the leader partition;
    所述follower partition根据所述leader partition的数据平均写入速度,计算得到所述目标偏移量。The follower partition calculates the target offset according to the average data writing speed of the leader partition.
  4. 如权利要求1或2所述的方法,其特征在于,所述偏移量选取策略为偏移量自适应确定策略,所述follower partition基于所述偏移量选取策略确定在待同步的topic的leader partition中的偏移量,包括:The method according to claim 1 or 2, wherein the offset selection strategy is an offset adaptive determination strategy, and the follower partition determines the location of the topic to be synchronized based on the offset selection strategy. The offset in the leader partition, including:
    所述follower partition获取所述leader partition的起始偏移量和所述leader partition的数据平均写入速度;The follower partition obtains the start offset of the leader partition and the average data write speed of the leader partition;
    所述follower partition根据所述leader partition的起始偏移量和leader partition的数据平均写入速度,计算得到所述目标偏移量。The follower partition calculates the target offset according to the start offset of the leader partition and the average data writing speed of the leader partition.
  5. 如权利要求3或4所述的方法,其特征在于,The method of claim 3 or 4, wherein:
    在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;When the average data writing speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment;
    在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度时,所述目标偏移量为所述leader partition的起始偏移量。When the average data write speed of the leader partition is less than or equal to the data synchronous transmission speed, the target offset is the start offset of the leader partition.
  6. 如权利要求3或4所述的方法,其特征在于,The method of claim 3 or 4, wherein:
    在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;When the average data writing speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment;
    在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度、并且所述leader partition的当前数据总量所需要的同步时间小于预设时长时,所述目标偏移量为所述leader partition的起始偏移量。When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, and the synchronization time required by the current total amount of data of the leader partition is less than the preset duration, the target offset is The starting offset of the leader partition.
  7. 如权利要求1或2所述的方法,其特征在于,所述偏移量选取策略为基于数据价值的选取策略,所述follower partition基于所述偏移量选取策略确定在待同步的topic的leader partition中的偏移量,包括:The method of claim 1 or 2, wherein the offset selection strategy is a selection strategy based on data value, and the follower partition determines the leader of the topic to be synchronized based on the offset selection strategy. The offset in the partition, including:
    所述follower partition获取多个消费者组的消费偏移量,所述follower partition确定最小的所述消费偏移量为所述目标偏移量;The follower partition obtains consumption offsets of multiple consumer groups, and the follower partition determines that the smallest consumption offset is the target offset;
    其中,所述消费者组用于消费所述待同步topic中的数据,每个消费者组包括至少一个消费者,所述消费偏移量用于指示所述消费者组所消费的所述leader partition中的数据的数量。Wherein, the consumer group is used to consume data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used to indicate the leader consumed by the consumer group The number of data in the partition.
  8. 一种数据同步装置,其特征在于,包括:A data synchronization device is characterized in that it comprises:
    获取单元,用于获取偏移量选取策略;The acquiring unit is used to acquire the offset selection strategy;
    处理单元,用于基于所述偏移量选取策略确定在待同步的topic的leader partition中的目标偏移量;A processing unit, configured to determine the target offset in the leader partition of the topic to be synchronized based on the offset selection strategy;
    同步单元,用于从所述leader partition的确定的目标偏移量开始同步所述leader partition中的数据。The synchronization unit is configured to synchronize data in the leader partition from the determined target offset of the leader partition.
  9. 如权利要求8所述的数据同步装置,其特征在于,所述数据同步装置还包括发送单元,The data synchronization device according to claim 8, wherein the data synchronization device further comprises a sending unit,
    所述发送单元,用于向所述leader partition发送查询请求,所述查询请求用于查询当前时刻所述leader partition中的偏移量;The sending unit is configured to send a query request to the leader partition, and the query request is used to query the offset in the leader partition at the current moment;
    所述处理单元,还用于计算所述当前时刻所述leader partition中的偏移量与所述数据同步装置中的偏移量的差值,并在所述差值大于预设阈值时确定同步所述leader partition中的数据。The processing unit is further configured to calculate the difference between the offset in the leader partition at the current moment and the offset in the data synchronization device, and determine synchronization when the difference is greater than a preset threshold Data in the leader partition.
  10. 如权利要求8或9所述的数据同步装置,其特征在于,所述偏移量选取策略为偏移量自适应确定策略,所述处理单元,具体用于:The data synchronization device according to claim 8 or 9, wherein the offset selection strategy is an offset adaptive determination strategy, and the processing unit is specifically configured to:
    获取leader partition的数据平均写入速度;Get the average data write speed of leader partition;
    根据所述leader partition的数据平均写入速度,计算得到所述目标偏移量。According to the average data writing speed of the leader partition, the target offset is calculated.
  11. 如权利要求8或9所述的数据同步装置,其特征在于,所述偏移量选取策略为偏移量自适应确定策略,所述处理单元,具体用于:The data synchronization device according to claim 8 or 9, wherein the offset selection strategy is an offset adaptive determination strategy, and the processing unit is specifically configured to:
    获取所述leader partition的起始偏移量和所述leader partition的数据平均写入速度;Obtaining the start offset of the leader partition and the average data writing speed of the leader partition;
    根据所述leader partition的起始偏移量和leader partition的数据平均写入速度,计算得到所述目标偏移量。The target offset is calculated according to the start offset of the leader partition and the average data write speed of the leader partition.
  12. 如权利要求10或11所述的数据同步装置,其特征在于,The data synchronization device according to claim 10 or 11, wherein:
    在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;When the average data writing speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment;
    在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度时,所述目标偏移量为所述leader partition的起始偏移量。When the average data write speed of the leader partition is less than or equal to the data synchronous transmission speed, the target offset is the start offset of the leader partition.
  13. 如权利要求10或11所述的数据同步装置,其特征在于,The data synchronization device according to claim 10 or 11, wherein:
    在所述leader partition的数据平均写入速度大于所述leader partition的数据同步传输速度时,所述目标偏移量为当前时刻所述leader partition的最大的偏移量;When the average data writing speed of the leader partition is greater than the data synchronization transmission speed of the leader partition, the target offset is the maximum offset of the leader partition at the current moment;
    在所述leader partition的数据平均写入速度小于或等于所述数据同步传输速度、并且所述leader partition的当前数据总量所需要的同步时间小于预设时长时,所述目标偏移量为所述leader partition的起始偏移量。When the average data write speed of the leader partition is less than or equal to the data synchronization transmission speed, and the synchronization time required by the current total amount of data of the leader partition is less than the preset duration, the target offset is The starting offset of the leader partition.
  14. 如权利要求8或9所述的数据同步装置,其特征在于,所述偏移量选取策略为基于数据价值的选取策略,所述处理单元,具体用于:The data synchronization device according to claim 8 or 9, wherein the offset selection strategy is a selection strategy based on data value, and the processing unit is specifically configured to:
    获取多个消费者组的消费偏移量,确定最小的所述消费偏移量为所述目标偏移量;Acquiring consumption offsets of multiple consumer groups, and determining the smallest consumption offset as the target offset;
    其中,所述消费者组用于消费所述待同步topic中的数据,每个消费者组包括至少一个消费者,所述消费偏移量用于指示所述消费者组所消费的所述leader partition中的数据的数量。Wherein, the consumer group is used to consume data in the topic to be synchronized, each consumer group includes at least one consumer, and the consumption offset is used to indicate the leader consumed by the consumer group The number of data in the partition.
  15. 一种计算设备,其特征在于,所述计算设备包括处理器和存储器,所述处理器执行所述存储器存储的计算机指令,使得所述计算设备执行权利要求1-7任一项所述的方法。A computing device, wherein the computing device includes a processor and a memory, and the processor executes computer instructions stored in the memory, so that the computing device executes the method according to any one of claims 1-7 .
  16. 一种计算机存储介质,其特征在于,所述计算机存储介质存储有计算机程序,所述计算机程序在被计算设备执行时实现权利要求1-7任一项所述的方法。A computer storage medium, wherein the computer storage medium stores a computer program, and the computer program implements the method according to any one of claims 1-7 when executed by a computing device.
  17. 一种计算机程序产品,所述计算机程序产品包括计算机指令,当所述计算机指令被计算设备执行时,所述计算设备可以执行权利要求1-7任一项所述的方法。A computer program product, the computer program product comprising computer instructions, and when the computer instructions are executed by a computing device, the computing device can execute the method according to any one of claims 1-7.
PCT/CN2020/136716 2019-12-27 2020-12-16 Data synchronization method and related device WO2021129477A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911423080.0A CN113055430A (en) 2019-12-27 2019-12-27 Data synchronization method and related equipment
CN201911423080.0 2019-12-27

Publications (1)

Publication Number Publication Date
WO2021129477A1 true WO2021129477A1 (en) 2021-07-01

Family

ID=76507531

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/136716 WO2021129477A1 (en) 2019-12-27 2020-12-16 Data synchronization method and related device

Country Status (2)

Country Link
CN (1) CN113055430A (en)
WO (1) WO2021129477A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113872888A (en) * 2021-09-27 2021-12-31 南威软件股份有限公司 Method, system and medium for Kafka backlog queue pursuit
CN114827049A (en) * 2022-03-02 2022-07-29 厦门服云信息科技有限公司 Accumulated data consumption method based on kafka, terminal equipment and storage medium
CN115150471A (en) * 2022-06-27 2022-10-04 北京百度网讯科技有限公司 Data processing method, device, equipment, storage medium and program product

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114385081B (en) * 2021-12-27 2023-03-24 联通智网科技股份有限公司 Disk protection method for kafka cluster and related equipment
CN115037745B (en) * 2022-05-18 2023-09-26 阿里巴巴(中国)有限公司 Method and device for electing in distributed system
CN115052006B (en) * 2022-08-12 2022-11-18 佛山赛思禅科技有限公司 Data synchronization method and system based on leader node
CN116955427B (en) * 2023-09-18 2023-12-15 北京长亭科技有限公司 Method and device for processing real-time multi-rule dynamic expression data based on Flink frame

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105912628A (en) * 2016-04-07 2016-08-31 北京奇虎科技有限公司 Synchronization method and device for master database and slave database
CN106790378A (en) * 2016-11-11 2017-05-31 北京奇虎科技有限公司 The full synchronous method of data of equipment room, apparatus and system
US20170242889A1 (en) * 2016-02-24 2017-08-24 Salesforce.Com, Inc. Cache Based Efficient Access Scheduling for Super Scaled Stream Processing Systems
CN109388677A (en) * 2018-08-23 2019-02-26 顺丰科技有限公司 Method of data synchronization, device, equipment and its storage medium between cluster

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170242889A1 (en) * 2016-02-24 2017-08-24 Salesforce.Com, Inc. Cache Based Efficient Access Scheduling for Super Scaled Stream Processing Systems
CN105912628A (en) * 2016-04-07 2016-08-31 北京奇虎科技有限公司 Synchronization method and device for master database and slave database
CN106790378A (en) * 2016-11-11 2017-05-31 北京奇虎科技有限公司 The full synchronous method of data of equipment room, apparatus and system
CN109388677A (en) * 2018-08-23 2019-02-26 顺丰科技有限公司 Method of data synchronization, device, equipment and its storage medium between cluster

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113872888A (en) * 2021-09-27 2021-12-31 南威软件股份有限公司 Method, system and medium for Kafka backlog queue pursuit
CN113872888B (en) * 2021-09-27 2023-05-19 南威软件股份有限公司 Method, system and medium for catch-up of Kafka backlog queue
CN114827049A (en) * 2022-03-02 2022-07-29 厦门服云信息科技有限公司 Accumulated data consumption method based on kafka, terminal equipment and storage medium
CN114827049B (en) * 2022-03-02 2023-05-09 厦门服云信息科技有限公司 Pile-up data consumption method based on kafka, terminal equipment and storage medium
CN115150471A (en) * 2022-06-27 2022-10-04 北京百度网讯科技有限公司 Data processing method, device, equipment, storage medium and program product
CN115150471B (en) * 2022-06-27 2024-03-29 北京百度网讯科技有限公司 Data processing method, apparatus, device, storage medium, and program product

Also Published As

Publication number Publication date
CN113055430A (en) 2021-06-29

Similar Documents

Publication Publication Date Title
WO2021129477A1 (en) Data synchronization method and related device
US11379461B2 (en) Multi-master architectures for distributed databases
US20220121384A1 (en) Hot Data Management Method, Apparatus, and System
US20200012568A1 (en) Scalable log-based continuous data protection for distributed databases
US9460185B2 (en) Storage device selection for database partition replicas
CA2952988C (en) Method and system for routing data flows in a cloud storage system
JP6404907B2 (en) Efficient read replica
US9330108B2 (en) Multi-site heat map management
US10853193B2 (en) Database system recovery using non-volatile system memory
JP6225262B2 (en) System and method for supporting partition level journaling to synchronize data in a distributed data grid
US10747739B1 (en) Implicit checkpoint for generating a secondary index of a table
US10102230B1 (en) Rate-limiting secondary index creation for an online table
WO2021057108A1 (en) Data reading method, data writing method, and server
US11256719B1 (en) Ingestion partition auto-scaling in a time-series database
US10135703B1 (en) Generating creation performance metrics for a secondary index of a table
CN104298574A (en) Data high-speed storage processing system
CN105760391B (en) Method, data node, name node and system for dynamically redistributing data
TWI484335B (en) Cached data processing method, processing system, and means
US8621260B1 (en) Site-level sub-cluster dependencies
WO2022252631A1 (en) Method and apparatus for distributed application, and computer device and storage medium
US11093493B1 (en) Dynamically switching between query and scan for optimizing table reads
Edmondson et al. QoS-enabled distributed mutual exclusion in public clouds
US10303787B2 (en) Forgetting items with knowledge based synchronization
CN110636090B (en) Data synchronization method and device under narrow bandwidth condition
Zhuang et al. Design of a more scalable database system

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

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20905405

Country of ref document: EP

Kind code of ref document: A1