卡桑德拉写锁 [英] Cassandra write lock

查看:92
本文介绍了卡桑德拉写锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个使用Cassandra的项目,而我陷入了一个优化点.考虑到读取动作对Cassandra来说是沉重的负担,我们想更改数据库结构.

I'm doing a project where we use Cassandra and I've stumped at an optimisation point. We want to change the database structure considering that read actions are a pretty heavy load on Cassandra.

我在文档和论坛中搜索了答案,但找不到以下问题的明确答案.

I searched the documentation and forums for an answer but I couldn't find a clear answer to the following question.

当前,我们小批量地向Cassandra写信,并且阅读将不断发生.我们希望使批次更大,因此我们可能每10-15分钟左右更换一半的桌子.据我所知,Cassandra仅在应用写操作时锁定该行.但这是真的吗?还是在写入表时锁定整个表.并且(也许是一个愚蠢的问题)在有写锁的情况下可以阅读吗? (因为只有写锁对,您仍有机会阅读吗?).

Currently we write in small batches to Cassandra and reading will happen continuously. We want to make the batches bigger so we maybe change like half the table every 10-15 minutes or so. And as far as I could find Cassandra only locks the row when applying a write action. But is this true? Or does it lock a whole table when writing in it. And (maybe a little bit of a stupid question) can you read while there is a write-lock? (because there is a chance you can still read when there is only a write-lock right?).

文档没有显示这种流程,并且这个问题似乎从未被问过. 在此先谢谢您!

The documentation does not show this kind of flow and the question seems to have never been asked before. Thanks in advanced!

推荐答案

Cassandra不锁定行

在Cassandra中,批处理用于实现原子性.原子表示如果任何批次成功,则全部成功.

In Cassandra batch is used to achieve Atomicity. Atomic means that if any of the batch succeeds, all of it will.

为了实现原子性,默认情况下,Cassandra首先将序列化的批处理写入批处理日志系统表,该表将序列化的批处理作为blob数据使用.当批处理中的行已成功写入并保留(或提示)后,批处理日志数据将被删除

To achieve atomicity, By default Cassandra first writes the serialized batch to the batchlog system table that consumes the serialized batch as blob data. When the rows in the batch have been successfully written and persisted (or hinted) the batchlog data is removed

尽管原子批处理可以保证原子性. 没有批量隔离.客户端能够读取该批处理中的第一批更新的行,而其他行仍在服务器上进行更新.但是,分区键中的交易行更新是隔离的:客户端无法读取部分更新.

Although atomic batch guarantees atomicity. there is no batch isolation. Clients are able to read the first updated rows from the batch, while other rows are still being updated on the server. However, transactional row updates within a partition key are isolated: clients cannot read a partial update.

来源: http://docs.datastax.com/zh/cql/3.1/cql/cql_reference/batch_r.html

另一件事建议批量不要太小. cassandra.yaml中有两个配置属性,不建议更改batch_size_warn_threshold_in_kbbatch_size_fail_threshold_in_kb

Another Thing It is recommended that batch size must be small. There are two configuration property in cassandra.yaml, which not recommended to change batch_size_warn_threshold_in_kb and batch_size_fail_threshold_in_kb

默认值:

batch_size_warn_threshold_in_kb: 5
batch_size_fail_threshold_in_kb: 50

因此,当批次大小为5k时,将记录警告,而当批次大小为50k或刨丝器时,批次将失败.

So when your batch size is 5k, a warning will be logged and when the batch size is 50k or grater your batch will failed.

这篇关于卡桑德拉写锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆