gpt4 book ai didi

java - Cassandra - 使计数器更新和正常更新原子化

转载 作者:行者123 更新时间:2023-12-01 20:25:10 25 4
gpt4 key购买 nike

我正在经历这个Instagram engineering article他们在哪里提到了非规范化计数器,我引用

To reduce the resources needed for each of these operations, we denormalized the counter for likes on the post. Whenever a new like comes in, the count is increased in the database. Therefore, each read of the count will just be a simple “select” which is a lot more efficient.

There is also an added benefit of denormalizing counters in the same database where the liker to the post is stored. Both updates can be included in one transaction, making the updates atomic and consistent all the time. Whereas before the change, the counter in cache could be inconsistent with what was stored in the database due to timeout, retries etc.

我尝试更新计数器表和普通表,其中有批量喜欢该帖子的用户使用,

BEGIN BATCH 
UPDATE postlike_counter_counter
set likecount = likecount+1
where postid = c77b9e44-379b-11e7-93dc-dd4982fae088;
INSERT INTO postlikes (postid, likedtime, likedby) values(c77b9e44-379b-11e7-93dc-dd4982fae088, unixTimestampOf(now()),
{"firstname": 'fname', "lastname": 'lname', "profileimgurl":'img/pic'});
APPLY BATCH;

我看到错误,仅在 COUNTER 批处理中允许计数器突变如果我将其作为反批处理,我得到,COUNTER 批处理中只允许反突变

有什么办法可以让我完成这项工作吗?如果不是,那么当他们写下上述引文时,这篇文章到底是什么意思?

最佳答案

Ashraful Islam 已经回答了为什么 Cassandra 不允许在单个批处理中混合计数器查询和非计数器查询的问题。但是您引用的上下文并没有发生在 cassandra 世界中。 Instagram engineering article (De-normalizing Counters)试图在 PgQ 中进行解释world(实际上可能的话,它们也不是计数器数据类型,而是作为计数器维护)

关于java - Cassandra - 使计数器更新和正常更新原子化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43961209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com