Skip to Content
Kafka权威指南
book

Kafka权威指南

by Neha Narkhede, Gwen Shapira, Todd Palino
January 2018
Beginner to intermediate
234 pages
7h 8m
Chinese
Posts & Telecom Press
Content preview from Kafka权威指南
86
5
5.5.7
 被删除的事件
如果只为每个键保留最近的一个消息,那么当需要删除某个特定键所对应的所有消息时,
我们该怎么办?这种情况是有可能发生的,比如一个用户不再使用我们的服务,那么完全
可以把与这个用户相关的所有信息从系统中删除。
为了彻底把一个键从系统里删除,应用程序必须发送一个包含该键且值为 null 的消息。清
理线程发现该消息时,会先进行常规的清理,只保留值为 null 的消息。该消息(被称为
碑消息
)会被保留一段时间,时间长短是可配置的。在这期间,消费者可以看到这个墓碑
消息,并且发现它的值已经被删除。于是,如果消费者往数据库里复制
Kafka
的数据,当
它看到这个墓碑消息时,就知道应该要把相关的用户信息从数据库里删除。在这个时间段
过后,清理线程会移除这个墓碑消息,这个键也将从
Kafka
分区里消失。重要的是,要留
给消费者足够多的时间,让他看到墓碑消息,因为如果消费者离线几个小时并错过了墓碑
消息,就看不到这个键,也就不知道它已经从
Kafka
里删除,从而也就不会去删除数据库
里的相关数据了。
5.5.8
 何时会清理主题
就像
delete
策略不会删除当前活跃的片段一样,
compact
策略也不会对当前片段进行清理。
只有旧片段里的消息才会被清理。
0.10.0
和更早的版本里,
Kafka
会在包含脏记录的主题数量达到
50%
时进行清理。这样
做的目的是避免太过频繁的清理(因为清理会影响主题的读写性能),同时也避免存在太
多脏记录(因为它们会占用磁盘空间)。浪费
50%
的磁盘空间给主题存放脏记录,然后进 ...
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

精通機器學習

精通機器學習

Aurélien Géron
精通特征工程

精通特征工程

Alice Zheng, Amanda Casari
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115473271