Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
236
|
第
13
章
将哈希值映射到节点 ID 的最直接的方法是将哈希值除以集群大小再取其余数(取模)。
如果系统中有 N 个节点,则目标节点 ID 可以通过 hash(v) mod N 算出。该方法的主
要问题是,每当添加或删除节点、集群大小从 N 更改为 N' 时,hash(v) mod N' 算
出的很多值都和原来不同。这意味着大部分数据都要被移动。
一致性哈希
为了缓解该问题,一些数据库(例如 Apache Cassandra 和 Riak)使用一种叫作
一致性哈
希
(consistent hashing)的分区方案。如前所述,路由键的值被输入哈希函数,返回的哈
希值被映射到一个
环
上,以便在超过最大值之后回卷到最小值。每个节点在环上拥有自
己的位置,负责前一个节点到当前节点之间的值
范围
。
使用一致性哈希能减少维持数据均衡所需的移动次数:节点离开或加入只会影响到环上
与该节点
直接相邻
的节点,而不影响整个集群。定义中的
一致性
表示:当哈希表大小发
生变化时,如果我们有 K 个可能的哈希键和 n 个节点,平均而言,我们仅需移动 K/n
个键。也就是说,一致性哈希函数的输出受函数范围变化的影响最小 [KARGER97]。
13.7 Percolator
分布式事务
回到分布式事务上来,由于允许一些读取和写入异常,隔离级别可能很难论证。如果
应用程序不要求可串行化,避免写入异常的一种方法是使用 SQL-92 中描述的
快照隔离
(Snapshot Isolation,SI)事务模型。
快照隔离保证事务内的所有读取结果与数据库的某个快照一致。快照中包含了在事务的 ...
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

解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787111655169