【发布时间】:2015-11-17 07:00:17
【问题描述】:
我的架构是:
CREATE TABLE friends (
userId timeuuid,
friendId timeuuid,
status varchar,
ts timeuuid,
PRIMARY KEY (userId,friendId)
);
CREATE TABLE friends_by_status (
userId timeuuid,
friendId timeuuid,
status varchar,
ts timeuuid,
PRIMARY KEY ((userId,status), ts)
)with clustering order by (ts desc);
在这里,每当提出好友请求时,我都会在两个表中插入记录。 当我想检查用户的一对一状态时,我会使用这个查询:
SELECT status FROM friends WHERE userId=xxx AND friendId=xxx;
当我需要查询所有处于待处理状态的记录时,我会使用:
SELECT * FROM friends_by_status WHERE userId=xxx AND status='pending';
但是,当状态发生变化时,我可以更新 'friends' 表中的 'status' 和 'ts',但不能更新 'friends_by_status' 表都是 PRIMARY KEY 的一部分。
您可以看到,即使我对其进行非规范化,我肯定需要更新 'friends_by_status' 表中的 'status' 和 'ts' 以保持一致性。
我可以保持一致性的唯一方法是删除记录并再次插入。
但在 cassandra 模型中也不建议频繁删除。 As said in Cassaandra Spottify summit.
我发现这是 Cassandra 的最大限制。
有没有其他方法可以解决这个问题。
感谢任何解决方案。
【问题讨论】:
标签: cassandra cassandra-2.0 clustered-index nosql