Skip to Content
Dapr学习手册
book

Dapr学习手册

by Haishi Bai, Yaron Schneider
November 2021
Beginner to intermediate
239 pages
4h 15m
Chinese
China Electric Power Press Ltd.
Content preview from Dapr学习手册
状态
93
2.2.1
并发模型
Dapr
兼容的状态存储需要使用
ETag
来支持乐观并发。当状态项被检索时,
它与
ETag
相关联。当服务实例试图更新状态项时,要更新的状态项必须在数
据存储中带有相同的
ETag
。乐观并发假设状态存储的大多数更新可以相互独
立地进行,因为特定状态项通常都只有单个变更者。当多个服务实例试图更
新同一个状态项时,第一个写入者将成功,因为它持有匹配的
ETag
。其他更
新尝试将会失败,这些服务实例需要检索最新的状态并再次尝试。如果客户
端省略了
ETag
,状态存储应该会恢复到后写入者获胜(
last-write-wins
),这
意味着最后收到的写入请求会覆盖之前的请求。
2.2.2
一致性模型
Dapr
要求状态存储默认支持最终一致性。状态存储也可以选择支持强一致性
写入。例如,默认的
Dapr Redis
状态存储实现使用最终一致性。但是,如果
客户端发送带有强一致性标志的请求,
Dapr
会等到所有的复制体都确认了写
入请求后才返回给调用者。
要编写旨在与多个数据存储一起工作的应用程序,你应该假设状态存储支持
最终一致性。某些框架更偏向强一致性,因为强一致性更容易推理。然而,
我们相信最终一致性对于分布式系统来说更自然,并且它已经被广泛采用。
因此,
Dapr
选择最终一致性作为默认行为。
2.2.3
批量操作和事务
Dapr
要求数据存储确保单个插入、更新或删除操作的事务隔离。
Dapr
状态
API
也定义了批量读取、批量删除和批量更新操作,但并没有强制要求将这
些操作作为单一事务处理。
Dapr
定义了独立的事务性存储接口,支持将多个数据库操作作为隔离的事务 ...
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

流畅的Python(第2版)

流畅的Python(第2版)

Luciano Ramalho
数据科学原理

数据科学原理

Posts & Telecom Press, Sinan Ozdemir
Python预测分析实战

Python预测分析实战

Posts & Telecom Press, Alvaro Fuentes
机器学习开发者指南

机器学习开发者指南

Posts & Telecom Press, Rodolfo Bonnin

Publisher Resources

ISBN: 9787519859367