本文介绍了NoSQL 中的先读后写是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一本书中读到:Cassandra 是一个 NoSQL 数据库,它提倡先读后写而不是关系模型".

I read in a book : "Cassandra is an NoSQL database and promotes read-before-write instead of relational model".

先读后写"在 NoSQL 上下文中是什么意思?

What does "read-before-write" means in a NoSQL context?

推荐答案

先读后写意味着在修改单元格之前先检查它的值.

Read before write means that you are checking the value of a cell before modifying it.

先读后写是 Cassandra 中的一个巨大的反模式.你阅读的任何鼓励这样做的书都应该被怀疑.通常 Cassandra 写入是在没有关于数据库当前状态的任何信息的情况下执行的.这样做的副作用之一是所有对 Cassandra 的写入实际上都是更新操作.这允许极快的写入,但也有一些限制.

Read-Before write is a huge anti-pattern in Cassandra. Any book you read that encourages doing this should be looked at with suspicion. Normally Cassandra writes are performed without having any information about the current state of the database. One of the side effects of this is that all writes to Cassandra are actually update operations. This is allows for extremely fast writes but does have some limitations.

如果你真的需要在写入之前检查数据库的状态,Cassandra 提供了检查和设置"(CAS)操作,它使用 PAXOS 在修改记录之前建立数据库状态.这些写成update table set x = 3 if y = 1.CAS 查询比 C* 中的正常写入慢几个数量级,应谨慎使用.

If you really need to check the state of the database before writing, Cassandra provides "Check and Set"(CAS) operations which use PAXOS to establish database state prior to modifying the record. These are written like update table set x = 3 if y = 1. CAS queries are orders of magnitude slower than a normal write in C* and should be used sparingly.

这篇关于NoSQL 中的先读后写是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:49