更新后的数据仍然存在于 CQL table

Updated data still persist in CQL table

我使用 CQL 创建了一个 table 并将 SET 作为列。

CREATE TABLE z_test.activity_follow (
    activity_type_id text,
    error_message text,
    error_type text,
    file text,
    line_no text,
    project_api_key text,
    project_name text,
    project_party_id text,
    release_stage_id text,
    stage_name text,
    project_type_name text,
    activity_type_name text,
    account_id text,
    created_at text,
    secure_url text,
    error_count text,
    user_id set<text>,
    PRIMARY KEY (activity_type_id,error_message,error_type,file,line_no,project_api_key,project_name,project_party_id,release_stage_id,stage_name,project_type_name,activity_type_name,account_id,created_at,secure_url)
);

其中 z_test 是我的键空间。 然后我使用以下查询将一个值插入 table,

UPDATE z_test.activity_follow SET user_id = user_id + {'46'} , error_count = '4' 
                               WHERE  activity_type_id = '1'
                                         AND error_message = '1'
                                         AND error_type = '1'
                                         AND FILE = '1'
                                         AND line_no = '1'
                                         AND project_api_key = '1'
                                         AND project_name = '1'
                                         AND project_party_id = '1'
                                         AND release_stage_id = '1'
                                         AND stage_name = '1'
                                         AND project_type_name = '1'
                                         AND activity_type_name = '1'
                                         AND account_id = '1'
                                         AND secure_url = '1'
                                         AND created_at = '1'




UPDATE z_test.activity_follow SET user_id = user_id + {'464'} , error_count = '4'
                               WHERE  activity_type_id = '1'
                                         AND error_message = '1'
                                         AND error_type = '1'
                                         AND FILE = '1'
                                         AND line_no = '1'
                                         AND project_api_key = '1'
                                         AND project_name = '1'
                                         AND project_party_id = '1'
                                         AND release_stage_id = '1'
                                         AND stage_name = '1'
                                         AND project_type_name = '1'
                                         AND activity_type_name = '1'
                                         AND account_id = '1'
                                         AND secure_url = '1'
                                         AND created_at = '1'

值插入成功。我使用了以下 select 语句,

SELECT * FROM z_test.users WHERE emails CONTAINS 'test@mail.com';

我得到了以下结果,

 activity_type_id | error_message                      | error_type     | file                                                               | line_no | project_api_key                      | project_name             | project_party_id | release_stage_id | stage_name  | project_type_name | activity_type_name | account_id | created_at          | secure_url                                      | error_count | user_id
------------------+------------------------------------+----------------+--------------------------------------------------------------------+---------+--------------------------------------+--------------------------+------------------+------------------+-------------+-------------------+--------------------+------------+---------------------+-------------------------------------------------+-------------+---------
                1 | alebvevcbvghhgrt123 is not defined | ReferenceError | http://localhost/ems-sdk/netspective_ems_js/example/automatic.html |      19 | 8aec5ce3-e924-3090-9bfe-57a440feba5f | Prescribewell-citrus-123 |               48 |                4 | Development |               Php |          exception |         47 | 2015-03-03 04:04:23 | PRE-EX-429c3daae9c108dffec32f113b9ca9cff1bb0468 |           1 |  {'464'}

然后我使用

从 table 中删除了一封电子邮件
UPDATE z_test.activity_follow SET user_id = user_id - {'46'} , error_count = '4' 
                               WHERE  activity_type_id = '1'
                                         AND error_message = '1'
                                         AND error_type = '1'
                                         AND FILE = '1'
                                         AND line_no = '1'
                                         AND project_api_key = '1'
                                         AND project_name = '1'
                                         AND project_party_id = '1'
                                         AND release_stage_id = '1'
                                         AND stage_name = '1'
                                         AND project_type_name = '1'
                                         AND activity_type_name = '1'
                                         AND account_id = '1'
                                         AND secure_url = '1'
                                         AND created_at = '1'

现在当我使用上面的查询时,

SELECT * FROM z_test.activity_follow WHERE user_id CONTAINS '46';

它仍然是 returns 行,

   activity_type_id | error_message                      | error_type     | file                                                               | line_no | project_api_key                      | project_name             | project_party_id | release_stage_id | stage_name  | project_type_name | activity_type_name | account_id | created_at          | secure_url                                      | error_count | user_id
------------------+------------------------------------+----------------+--------------------------------------------------------------------+---------+--------------------------------------+--------------------------+------------------+------------------+-------------+-------------------+--------------------+------------+---------------------+-------------------------------------------------+-------------+---------
                1 | alebvevcbvghhgrt123 is not defined | ReferenceError | http://localhost/ems-sdk/netspective_ems_js/example/automatic.html |      19 | 8aec5ce3-e924-3090-9bfe-57a440feba5f | Prescribewell-citrus-123 |               48 |                4 | Development |               Php |          exception |         47 | 2015-03-03 04:04:23 | PRE-EX-429c3daae9c108dffec32f113b9ca9cff1bb0468 |           1 |  {'464'}

为什么我会出现这种行为?它在 CQL 中是预期的吗?如果我可以删除这个怎么办?我已经将每个值都设为 1 进行测试,我也尝试了其他值。

您使用什么客户端来执行您的 CQL 语句?这一切都是在 cqlsh 或其他东西中完成的吗?

这只是一个黑暗的猜测,但是如果你 运行 两个 CQL 语句快速地一个接一个地匹配相同的主键,它们可能在 cassandra 中被赋予相同的写入时间,这意味着一个的突变将被忽略。

参见:Cassandra: Writes after setting a column to null are lost randomly. Is this a bug, or I am doing something wrong?

如果您运行正在使用 Cassandra 2.1.2+,那么如果在同一毫秒 (CASSANDRA-6123) 有 writes/upates,cassandra 现在将打破平局