Skip to Content
设计数据密集型应用程序 (Chinese Edition), 2nd Edition
book

设计数据密集型应用程序 (Chinese Edition), 2nd Edition

by Martin Kleppmann, Chris Riccomini
February 2026
Beginner to intermediate
672 pages
7h 53m
Chinese
O'Reilly Media, Inc.
Content preview from 设计数据密集型应用程序 (Chinese Edition), 2nd Edition

第七章. 分片

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

显然,我们必须摆脱顺序思维的束缚,避免限制计算机能力。我们需要定义数据优先级与描述,阐明关系而非程序。

格蕾丝·默里·霍珀,《管理与未来计算机》(1962年)

分布式数据库通常通过两种方式将数据分布到节点上:

  • 它会在多个节点上存储相同数据的副本。这便是复制机制,我们在 第六章中已进行过讨论。

  • 当数据量过大或写入吞吐量过高导致单节点无法处理时,系统会将数据拆分为 更小的分片分区,并将不同分片存储在不同节点上。本章将详细探讨 分片机制。

通常,分片被定义为每条数据(每条记录、行或文档) 仅属于一个分片。实现此目标的方法多种多样,本章将深入探讨。 实际上,每个分片本身就是一个小型数据库,尽管某些数据库系统 支持同时涉及多个分片的操作。

分片通常与复制结合使用,使每个分片的副本存储在多个节点上。这意味着尽管每条记录仅属于一个分片,但为实现容错性,它仍可能存储在多个不同节点上。

单个节点可存储多个分片。若采用单领袖复制模型,分片与复制的组合可如图7-1所示:每个分片的领袖节点分配给某一节点,其追随者节点则分配给其他节点。每个节点可能同时担任某些分片的领袖和另一些分片的追随者,但每个分片仍仅有一个领袖。

Diagram illustrating the combination of replication and sharding, showing nodes acting as leaders for some shards and followers for others, with arrows indicating replication streams.
图7-1. 复制与分片结合 :每个节点既是某些分片的领导者,也是其他分片的追随者

第6章关于数据库复制的所有内容同样适用于分片复制。由于分片方案的选择基本独立于复制方案的选择,为简化说明,本章将忽略复制机制。

分片的优缺点

数据库分片的根本动因在于可扩展性。当数据量或写吞吐量超出单节点承载能力时,分片便成为解决方案——它能将数据与写操作分散至多个节点。(若问题在于读吞吐量,则未必需要分片,可采用 ...

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

技术主管的进阶之路 (Chinese Edition)

技术主管的进阶之路 (Chinese Edition)

Anemari Fiser
企业级Java开发中的应用人工智能 (Chinese Edition)

企业级Java开发中的应用人工智能 (Chinese Edition)

Alex Soto Bueno, Markus Eisele, Natale Vinto

Publisher Resources

ISBN: 0642572336233