Justin
Justin

Reputation: 745

Updated data still persist in CQL table

I created a table with SET as a column using CQL .

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)
);

Where z_test is my keyspace. Then i inserted one value into the table using following query,

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'

The values is inserted successfully. And i used following select statement,

SELECT * FROM z_test.users WHERE emails CONTAINS '[email protected]';

And i got the following result,

 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'}

Then i removed one email from the table using,

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'

Now when i am using the above query ,

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

And it still returns the row,

   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'}

Why i am getting this behavior? is it expected in CQL? If i can remove this how? I have given every value as 1 for test, i tried it with other values also.

Upvotes: 2

Views: 74

Answers (1)

Andy Tolbert
Andy Tolbert

Reputation: 11638

What client are you using to perform your CQL statements? Is this all done in cqlsh or something else?

This is just a shot in a dark guess, but if you run two CQL statements matching the same primary key quickly after one another, it's possible that they are given the same writetime in cassandra which means one of the mutations will be ignored.

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

If you are running Cassandra 2.1.2+ cassandra will now break ties if there are writes/upates at the same millisecond (CASSANDRA-6123)

Upvotes: 3

Related Questions