Skip to Content
Kafka权威指南(第2版)
book

Kafka权威指南(第2版)

by Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
November 2022
Beginner to intermediate
346 pages
11h
Chinese
Posts & Telecom Press
Content preview from Kafka权威指南(第2版)
126
7
7.3.3
 最少同步副本
min.insync.replicas
参数可以配置在主题级别和
broker
级别。
如前所述,尽管为一个主题配置了
3
个副
本,还是会出现只剩下一个同步副本的情况。如
果这个同步副本变为不可用,则必须在可用性和一致性之间做出选择,而这是一个两难的
选择。根据
Kafka
对可靠性保证的定义
,一条消息只有在被写入所有同步副本之后才被认
为是已提交的,但如果这里的“所有”只包含一个同步副本,那么当这个副本变为不可用
时,数据就有可能丢失。
如果想确保已提交的数据被写入不止一个副本,就要把最少同步副本设置得大一些。对于
一个包含
3
个副本的主题
,如果
min.insync.replicas
被设置为
2
,那么至少需要有两个同
步副本才能向分区写入数据。
如果
3
个副
本都是同步的,那么一切正常进行。即使其中一个副本变为不可用,也不会有
什么问题。但是,如果有两个副本变为不可用,那么
broker
会停止接受生产者的请求。
尝试发送数据的生产者会收到
NotEnoughReplicasException
异常,不过消费者仍然可以继
续读取已有的数据。实际上,如果使用这样的配置,那么当只剩下一个同步副本时,它就
变成只读的了。这样做是为了避免在发生不彻底的选举时数据的写入和读取出现非预期的
行为。要脱离这种只读状态,必须让两个不可用分区中的一个重新变为可用(比如重启
broker
,并等待它变为同步的。
7.3.4
 保持副本同步
前面提到过,不同步副本会降低总体可靠性,所以要尽量避免出现这种情况。一个副本 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

时间序列分析实战:基于机器学习和统计学

时间序列分析实战:基于机器学习和统计学

Aileen Nielsen
Spark机器学习实战

Spark机器学习实战

Posts & Telecom Press, Siamak Amirghodsi, Meenakshi Rajendran, Broderick Hall, Shuen Mei
写给系统管理员的Python脚本编程指南

写给系统管理员的Python脚本编程指南

Posts & Telecom Press, Ganesh Sanjiv Naik
Kubernetes编程

Kubernetes编程

Michael Hausenblas, Stefan Schimanski

Publisher Resources

ISBN: 9787115601421