Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YCQL] Deleting rows does not work if rows have been deleted by the TTL previously #13820

Open
in-cloud-opensource opened this issue Aug 31, 2022 · 5 comments
Assignees
Labels
area/docdb YugabyteDB core features area/ycql Yugabyte CQL (YCQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@in-cloud-opensource
Copy link

in-cloud-opensource commented Aug 31, 2022

Jira Link: DB-3328

Description

Hi,

We noticed some unexpected behavior when using the YCQL-API and Yugabyte.

Version 2.14.1.0 build 36 revision aa9d62a build_type RELEASE built at 08 Aug 2022 08:45:12 UTC.

Deleting a range of rows does not work if rows with the same partition key have been deleted by the TTL-Feature previously.
To reproduce the bug, it is necessary to create a table with a partition key, cluster key and the default_time_to_live property.
The timing of the delete queries also matters (detailed description in the comments below).

Preparation:

// Start the yugabyte container
docker run --rm -d --name yugabyte yugabytedb/yugabyte:2.14.1.0-b36 bin/yugabyted start --daemon=false

// Connect into the container
docker exec -it yugabyte /bin/bash

// Open the ycqlsh
ycqlsh

The following steps describe how to reproduce the bug:

// Create a test keyspace
create keyspace ks;
use ks;

// Create a table with partition key, cluster key and a default_time_to_live
create table test (key text, sort text, value text, primary key((key), sort)) with default_time_to_live = 30;


// Upsert some rows with the same partition key and different cluster key.
update test set value = 'v1' where key = 'A' and sort = 'A';
update test set value = 'v1' where key = 'A' and sort = 'B';

// Delete all rows where key = 'A'  *before*  they expire.
delete from test where key = 'A';


/////////////////////////////////////////////////////////////////////////////////////
// Wait until the rows would have been expired, if they had not been deleted.      //
// So at least default_time_to_live seconds. In this example 30 seconds.           //
/////////////////////////////////////////////////////////////////////////////////////


// Upsert the same rows again.
update test set value = 'v1' where key = 'A' and sort = 'A';
update test set value = 'v1' where key = 'A' and sort = 'B';


// Try to delete all rows where key = 'A'.
// This delete query does not work as expected.
// It runs as if the rows were deleted. But a select query shows that they still exist.
delete from test where key = 'A';

// The rows with partition key = 'A' still exist.
// Which is is not expected
select key, sort, value, ttl(value) from test;

Seems to be a bug?

Regards

@in-cloud-opensource in-cloud-opensource added area/ycql Yugabyte CQL (YCQL) status/awaiting-triage Issue awaiting triage labels Aug 31, 2022
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Aug 31, 2022
@yugabyte-ci yugabyte-ci removed the status/awaiting-triage Issue awaiting triage label Sep 2, 2022
@yugabyte-ci yugabyte-ci added area/docdb YugabyteDB core features and removed area/ycql Yugabyte CQL (YCQL) labels Oct 12, 2022
@yugabyte-ci yugabyte-ci assigned arybochkin and unassigned jmeehan16 Sep 20, 2023
@yugabyte-ci yugabyte-ci added priority/highest Highest priority issue and removed priority/medium Medium priority issue labels Sep 22, 2023
@rthallamko3 rthallamko3 assigned yusong-yan and unassigned arybochkin Feb 5, 2024
@yusong-yan
Copy link
Contributor

This issue can be constantly reproduced on 2.14 cluster
Screenshot 2024-02-06 at 6 24 10 PM

However, the issue seems to be fixed in the master version as I am no longer able to reproduce it anymore
Screenshot 2024-02-06 at 6 33 07 PM

@yusong-yan
Copy link
Contributor

Here is what I saw from the sst file.
First two upsert

SubDocKey(DocKey(0xabed, ["A"], ["A"]), [ColumnId(2); HT{ physical: 1707413501356944 }]) -> "v1"
SubDocKey(DocKey(0xabed, ["A"], ["B"]), [ColumnId(2); HT{ physical: 1707413503528423 }]) -> "v1"

The delete command before they expire

SubDocKey(DocKey(0xabed, ["A"], ["A"]), [HT{ physical: 1707413516031093 }]) -> DEL
SubDocKey(DocKey(0xabed, ["A"], ["B"]), [HT{ physical: 1707413516031093 w: 1 }]) -> DEL

Second two upsert

SubDocKey(DocKey(0xabed, ["A"], ["A"]), [ColumnId(2); HT{ physical: 1707413931774837 }]) -> "v1"
SubDocKey(DocKey(0xabed, ["A"], ["B"]), [ColumnId(2); HT{ physical: 1707413932164249 }]) -> "v1"

Then the second delete command get executed, but it didn't show up in sst file as expected.

@rthallamko3 rthallamko3 added the area/ycql Yugabyte CQL (YCQL) label Feb 14, 2024
@yusong-yan
Copy link
Contributor

After running the second delete from test where key = 'A'; command, the while (VERIFY_RESULT(iterator.HasNext()))
loop was never entered, which means no deletion happened.

Status QLWriteOperation::Apply(const DocOperationApplyData& data) {
        ...
        // Create iterator.
        DocRowwiseIterator iterator(
            projection, *doc_read_context_, txn_op_context_,
            data.doc_write_batch->doc_db(), data.deadline, data.read_time);
        RETURN_NOT_OK(iterator.Init(spec));

        // Iterate through rows and delete those that match the condition.
        // TODO(mihnea): We do not lock here, so other write transactions coming in might appear
        // partially applied if they happen in the middle of a ranged delete.
        while (VERIFY_RESULT(iterator.HasNext())) {
          existing_row.Clear();
          RETURN_NOT_OK(iterator.NextRow(&existing_row));

          // Match the row with the where condition before deleting it.
          bool match = false;
          RETURN_NOT_OK(spec.Match(existing_row, &match));
          if (match) {
            const DocPath row_path(iterator.row_key());
            RETURN_NOT_OK(DeleteRow(row_path, data.doc_write_batch, data.read_time, data.deadline));
        ...

@yugabyte-ci yugabyte-ci assigned suranjan and unassigned yusong-yan Feb 14, 2024
@yugabyte-ci yugabyte-ci removed the area/docdb YugabyteDB core features label Feb 14, 2024
@rthallamko3 rthallamko3 added the area/docdb YugabyteDB core features label Mar 6, 2024
@rthallamko3 rthallamko3 assigned yusong-yan and unassigned suranjan Mar 6, 2024
@rthallamko3
Copy link
Contributor

Fixed by the refactoring in #12241 , so its a problem for 2.14.x customers only.

@yugabyte-ci yugabyte-ci added priority/high High Priority and removed priority/highest Highest priority issue labels Mar 19, 2024
@rthallamko3 rthallamko3 added priority/medium Medium priority issue and removed priority/high High Priority labels Mar 26, 2024
@rthallamko3
Copy link
Contributor

Lowering the severity as the impact is only on 2.14.x customers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docdb YugabyteDB core features area/ycql Yugabyte CQL (YCQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

7 participants