You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "smiklosovic (via GitHub)" <gi...@apache.org> on 2025/08/12 13:05:01 UTC

[PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

smiklosovic opened a new pull request, #4300:
URL: https://github.com/apache/cassandra/pull/4300

   …ion when compaction contains fully expired SSTables
   
   Thanks for sending a pull request! Here are some tips if you're new here:
    
    * Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
    * Be sure to keep the PR description updated to reflect all changes.
    * Write your PR title to summarize what this PR proposes.
    * If possible, provide a concise example to reproduce the issue for a faster review.
    * Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
    * If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
    
   Commit messages should follow the following format:
   
   ```
   <One sentence description, usually Jira title or CHANGES.txt summary>
   
   <Optional lengthier description (context on patch)>
   
   patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
   
   Co-authored-by: Name1 <email1>
   Co-authored-by: Name2 <email2>
   
   ```
   
   The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276019920


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()
+                                                                                 .stream()
+                                                                                 .filter(Index::includeFullyExpiredTablesInCompaction)
+                                                                                 .collect(Collectors.toList());
+
+            if (!indexesReceptiveToFullyExpiredSSTables.isEmpty() && !fullyExpiredSSTables.isEmpty())
+            {
+                try (WriteContext ctx = cfs.keyspace.getWriteHandler().createContextForIndexing())
+                {
+                    for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+                    {
+                        expiredSSTable.getScanner()
+                                      .forEachRemaining(partition ->
+                                                        partition.forEachRemaining(unfiltered -> {
+                                                            if (unfiltered instanceof Row)
+                                                            {
+                                                                for (Index index : indexesReceptiveToFullyExpiredSSTables)

Review Comment:
   Actually, I think that `versions` should be just ... 1? If you look into what `IndexGCTransaction` is doing:
   
   ````
           public void start()
           {
               if (versions > 0)
                   rows = new Row[versions];
           }
   ````
   
   So rows will not be null only in case versions is > than 0, sure. And then on `commit` 
   
   ````
           public void commit()
           {
               if (rows == null)
                   return;
   ````
   
   This is not be null so it will proceed 
   
   and then this will just go over one row for all indexers.
   
   ````
   try (WriteContext ctx = keyspace.getWriteHandler().createContextForIndexing())
   {
       for (Index index : indexes)
       {
           Index.Indexer indexer = index.indexerFor(key, columns, nowInSec, ctx, Type.COMPACTION);
           if (indexer == null)
               continue;
   
           indexer.begin();
           for (Row row : rows)
               if (row != null)
                   indexer.removeRow(row);
           indexer.finish();
       }
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2275974552


##########
src/java/org/apache/cassandra/index/Index.java:
##########
@@ -422,6 +422,27 @@ default SSTableFlushObserver getFlushObserver(Descriptor descriptor, OperationTy
      */
     public void validate(PartitionUpdate update) throws InvalidRequestException;
 
+
+    /**
+     * When a secondary index is created on a column for a table with e.g. TWCS strategy,
+     * when this table contains SSTables which are evaluated as fully expired upon compaction,
+     * they are by default filtered out as they can be dropped in their entirety. However, once dropped like that,
+     * the index implementation is not notified about this fact via IndexGCTransaction as compaction on
+     * non-fully expired tables would do. This in turn means that custom index will never know that some data have
+     * been removed hence data custom index implementation is responsible for will grow beyond any limit.
+     *
+     * Override this method and return true in index implementation only in case you want to be notified about
+     * dropped fully-expired data. This will eventually mean that {@link Indexer#removeRow(Row)} will be called
+     * for rows contained in fully expired table. Return false if you do not want to be notified like this and
+     * your index is managing fully expired data in other way.
+     *
+     * @return true when fully expired tables should be included in compaction process, false otherwise.
+     */
+    public default boolean includeFullyExpiredTablesInCompaction()
+    {
+        return false;

Review Comment:
   `notifyIndexerAboutRowsInFullyExpiredSSTables` ?
   
   I think this describes what it does the best.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` for `versions` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.
   
   `IndexGCTransaction` needs `versions` (currenty set to `1`) as we have "one row to merge".
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.
   
   Also, the reason I can not do transaction per partition, only per row, is that IndexGCTransaction is row-oriented, not partition oriented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276019920


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()
+                                                                                 .stream()
+                                                                                 .filter(Index::includeFullyExpiredTablesInCompaction)
+                                                                                 .collect(Collectors.toList());
+
+            if (!indexesReceptiveToFullyExpiredSSTables.isEmpty() && !fullyExpiredSSTables.isEmpty())
+            {
+                try (WriteContext ctx = cfs.keyspace.getWriteHandler().createContextForIndexing())
+                {
+                    for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+                    {
+                        expiredSSTable.getScanner()
+                                      .forEachRemaining(partition ->
+                                                        partition.forEachRemaining(unfiltered -> {
+                                                            if (unfiltered instanceof Row)
+                                                            {
+                                                                for (Index index : indexesReceptiveToFullyExpiredSSTables)

Review Comment:
   Actually, I think that `versions` should be just ... 1? If you look into what `IndexGCTransaction` is doing:
   
   ````
           public void start()
           {
               if (versions > 0)
                   rows = new Row[versions];
           }
   ````
   
   So rows will not be null only in case versions is > than 0, sure. And then on `commit` 
   
   ````
           public void commit()
           {
               if (rows == null)
                   return;
   ````
   
   This is not be null so it will proceed 
   
   and then this will just go over one row for all indexers.
   
   ````
               try (WriteContext ctx = keyspace.getWriteHandler().createContextForIndexing())
               {
                   for (Index index : indexes)
                   {
                       Index.Indexer indexer = index.indexerFor(key, columns, nowInSec, ctx, Type.COMPACTION);
                       if (indexer == null)
                           continue;
   
                       indexer.begin();
                       for (Row row : rows)
                           if (row != null)
                               indexer.removeRow(row);
                       indexer.finish();
                   }
               }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   I am not completely sure this whole logic makes sense. First of all, I do not think you can do one transaction _per partition_. Because it needs `versions` (currenty set to `1`). I am not sure what I should set that to because this is there when it is going to be _compacted_ but we are not compacting anything really ...
   
   So, we get IndexGCTransaction.
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.
   
   Also, the reason I can not do transaction per partition, only per row, is that IndexGCTransaction is row-oriented, not partition oriented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   I am not completely sure this whole logic makes sense. First of all, I do not think you can do one transaction _per partition_. Because it needs `versions` (currenty set to `1`) (and even conceptually, I do not know how many rows there will be in advance as I am just iterating over them?) I am not sure what I should set that to because this is there when it is going to be _compacted_ but we are not compacting anything really so 1 makes sense?
   
   So, we get IndexGCTransaction.
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.
   
   Also, the reason I can not do transaction per partition, only per row, is that IndexGCTransaction is row-oriented, not partition oriented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "blambov (via GitHub)" <gi...@apache.org>.
blambov commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2275893538


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()
+                                                                                 .stream()
+                                                                                 .filter(Index::includeFullyExpiredTablesInCompaction)
+                                                                                 .collect(Collectors.toList());
+
+            if (!indexesReceptiveToFullyExpiredSSTables.isEmpty() && !fullyExpiredSSTables.isEmpty())
+            {
+                try (WriteContext ctx = cfs.keyspace.getWriteHandler().createContextForIndexing())
+                {
+                    for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+                    {
+                        expiredSSTable.getScanner()
+                                      .forEachRemaining(partition ->
+                                                        partition.forEachRemaining(unfiltered -> {
+                                                            if (unfiltered instanceof Row)
+                                                            {
+                                                                for (Index index : indexesReceptiveToFullyExpiredSSTables)

Review Comment:
   Can we use `indexManager.newCompactionTransaction` created once for every partition?
   
   This will also use indexes that don't set `includeFullyExpiredTablesInCompaction`, which shouldn't be an issue. If we do that, we can change the index collection to just a check if one of the indexes needs it.



##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()

Review Comment:
   Can we move the expired sstables processing to a separate method?



##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()
+                                                                                 .stream()
+                                                                                 .filter(Index::includeFullyExpiredTablesInCompaction)
+                                                                                 .collect(Collectors.toList());
+
+            if (!indexesReceptiveToFullyExpiredSSTables.isEmpty() && !fullyExpiredSSTables.isEmpty())

Review Comment:
   
   Nit: I'd check `fullyExpiredSSTables` first to avoid going through the indexes if it is empty.



##########
src/java/org/apache/cassandra/index/Index.java:
##########
@@ -422,6 +422,27 @@ default SSTableFlushObserver getFlushObserver(Descriptor descriptor, OperationTy
      */
     public void validate(PartitionUpdate update) throws InvalidRequestException;
 
+
+    /**
+     * When a secondary index is created on a column for a table with e.g. TWCS strategy,
+     * when this table contains SSTables which are evaluated as fully expired upon compaction,
+     * they are by default filtered out as they can be dropped in their entirety. However, once dropped like that,
+     * the index implementation is not notified about this fact via IndexGCTransaction as compaction on
+     * non-fully expired tables would do. This in turn means that custom index will never know that some data have
+     * been removed hence data custom index implementation is responsible for will grow beyond any limit.
+     *
+     * Override this method and return true in index implementation only in case you want to be notified about
+     * dropped fully-expired data. This will eventually mean that {@link Indexer#removeRow(Row)} will be called
+     * for rows contained in fully expired table. Return false if you do not want to be notified like this and
+     * your index is managing fully expired data in other way.
+     *
+     * @return true when fully expired tables should be included in compaction process, false otherwise.
+     */
+    public default boolean includeFullyExpiredTablesInCompaction()
+    {
+        return false;

Review Comment:
   This should be true by default (as the safer option) and overridden by SAI and SASI.
   
   And perhaps call it `listRowsInExpiredSSTables`, `needsRowsInExpiredSSTables` or something similar?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276007313


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()
+                                                                                 .stream()
+                                                                                 .filter(Index::includeFullyExpiredTablesInCompaction)
+                                                                                 .collect(Collectors.toList());
+
+            if (!indexesReceptiveToFullyExpiredSSTables.isEmpty() && !fullyExpiredSSTables.isEmpty())
+            {
+                try (WriteContext ctx = cfs.keyspace.getWriteHandler().createContextForIndexing())
+                {
+                    for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+                    {
+                        expiredSSTable.getScanner()
+                                      .forEachRemaining(partition ->
+                                                        partition.forEachRemaining(unfiltered -> {
+                                                            if (unfiltered instanceof Row)
+                                                            {
+                                                                for (Index index : indexesReceptiveToFullyExpiredSSTables)

Review Comment:
   well that is not so easy because `newCompactionTransaction` takes `int versions` as third parameter which is by the current execution path resolved in `getRowMergeListener` which gets `List<UnfilteredRowIterator> versions`. I am not completely sure how to get this stuff in there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` for `versions` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.
   
   `IndexGCTransaction` needs `versions` (currenty set to `1`) as we have "one row to merge".
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   I am not completely sure this whole logic makes sense. First of all, I do not think you can do one transaction _per partition_. Because it needs `versions` (currenty set to `1`). I am not sure what I should set that to because this is there when it is going to be _compacted_ but we are not compacting anything really so 1 makes sense?
   
   So, we get IndexGCTransaction.
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.
   
   Also, the reason I can not do transaction per partition, only per row, is that IndexGCTransaction is row-oriented, not partition oriented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "blambov (via GitHub)" <gi...@apache.org>.
blambov commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276249630


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   We definitely don't want to materialize the whole partition, but the number rows in the partition should not matter here. The number of "versions", i.e. sources for each merged row, in this case is always one (only the obsoleted sstable). Thus we should be able to move the transaction initialization as it is to the per-partition section.
   
   As the row is deleted, something like
   ```
   transaction.onRowMerge(null, (Row) unfiltered);
   ```
   should be the correct usage.
   
   If this doesn't work, let's not spend any more time on it and go back to your original implementation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2275950430


##########
src/java/org/apache/cassandra/index/Index.java:
##########
@@ -422,6 +422,27 @@ default SSTableFlushObserver getFlushObserver(Descriptor descriptor, OperationTy
      */
     public void validate(PartitionUpdate update) throws InvalidRequestException;
 
+
+    /**
+     * When a secondary index is created on a column for a table with e.g. TWCS strategy,
+     * when this table contains SSTables which are evaluated as fully expired upon compaction,
+     * they are by default filtered out as they can be dropped in their entirety. However, once dropped like that,
+     * the index implementation is not notified about this fact via IndexGCTransaction as compaction on
+     * non-fully expired tables would do. This in turn means that custom index will never know that some data have
+     * been removed hence data custom index implementation is responsible for will grow beyond any limit.
+     *
+     * Override this method and return true in index implementation only in case you want to be notified about
+     * dropped fully-expired data. This will eventually mean that {@link Indexer#removeRow(Row)} will be called
+     * for rows contained in fully expired table. Return false if you do not want to be notified like this and
+     * your index is managing fully expired data in other way.
+     *
+     * @return true when fully expired tables should be included in compaction process, false otherwise.
+     */
+    public default boolean includeFullyExpiredTablesInCompaction()
+    {
+        return false;

Review Comment:
   ah right ... i didn't think we are going to be so bold here 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   I am not completely sure this whole logic makes sense. First of all, I do not think you can do one transaction _per partition_. Because it needs `versions`. I am not sure what I should set that to because this is there when it is going to be _compacted_ but we are not compacting anything really ...
   
   So, we get IndexGCTransaction.
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.
   
   Also, the reason I can not do transaction per partition, only per row, is that IndexGCTransaction is row-oriented, not partition oriented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276166559


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276019920


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()
+                                                                                 .stream()
+                                                                                 .filter(Index::includeFullyExpiredTablesInCompaction)
+                                                                                 .collect(Collectors.toList());
+
+            if (!indexesReceptiveToFullyExpiredSSTables.isEmpty() && !fullyExpiredSSTables.isEmpty())
+            {
+                try (WriteContext ctx = cfs.keyspace.getWriteHandler().createContextForIndexing())
+                {
+                    for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+                    {
+                        expiredSSTable.getScanner()
+                                      .forEachRemaining(partition ->
+                                                        partition.forEachRemaining(unfiltered -> {
+                                                            if (unfiltered instanceof Row)
+                                                            {
+                                                                for (Index index : indexesReceptiveToFullyExpiredSSTables)

Review Comment:
   Actually, I think that `versions` should be just ... 1? If you look into what `IndexGCTransaction` is doing:
   
   ````
           public void start()
           {
               if (versions > 0)
                   rows = new Row[versions];
           }
   ````
   
   So rows will not be null only in case versions is > than 0, sure. And then on `commit` 
   
   ````
           public void commit()
           {
               if (rows == null)
                   return;
   ````
   
   This is not be null so it will proceed 
   
   and then this will just go over one row for all indexers.
   
   ````
   try (WriteContext ctx = keyspace.getWriteHandler().createContextForIndexing())
   {
       for (Index index : indexes)
       {
           Index.Indexer indexer = index.indexerFor(key, columns, nowInSec, ctx, Type.COMPACTION);
           if (indexer == null)
               continue;
   
           indexer.begin();
           for (Row row : rows)
               if (row != null)
                   indexer.removeRow(row);
           indexer.finish();
       }
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276166559


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` for `versions` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2275933657


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()

Review Comment:
   sure



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276116854


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {
+                                                    if (unfiltered instanceof Row)
+                                                    {
+                                                        CompactionTransaction transaction = cfs.indexManager.newCompactionTransaction(partition.partitionKey(),
+                                                                                                                                      partition.columns(),
+                                                                                                                                      1,
+                                                                                                                                      FBUtilities.nowInSeconds(),
+                                                                                                                                      // only indexes which matter
+                                                                                                                                      indexes);

Review Comment:
   indexes which matter only, which have `notifyIndexerAboutRowsInFullyExpiredSSTables` to be true. I have accommodated `newCompactionTransaction` to pass indexes explicitly. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #4300: CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables
URL: https://github.com/apache/cassandra/pull/4300


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` for `versions` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.
   
   `IndexGCTransaction' needs `versions` (currenty set to `1`) as we have "one row to merge".
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.
   
   Also, the reason I can not do transaction per partition, only per row, is that IndexGCTransaction is row-oriented, not partition oriented.



##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` for `versions` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   To have one transaction per partition, we would need to first iterate over all rows and put them to list, then get list's size, then use this size while creating `IndexGCTransaction` for `versions` and then iterate over all such rows and call `transaction.onRowMerge` on them.
   
   But I am not sure about holding rows in a list while we iterating over them. This can use a lot of memory, basically we would hold whole partition until we can run transaction on that.
   
   `IndexGCTransaction` needs `versions` (currently set to `1`) as we have "one row to merge".
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2275933657


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -171,7 +177,45 @@ public boolean apply(SSTableReader sstable)
             long inputSizeBytes;
             long timeSpentWritingKeys;
 
+            List<Index> indexesReceptiveToFullyExpiredSSTables = cfs.indexManager.listIndexes()

Review Comment:
   no problem, I think having it as method in index manager is the way to go here 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276131662


##########
src/java/org/apache/cassandra/db/compaction/CompactionTask.java:
##########
@@ -102,6 +110,43 @@ public boolean reduceScopeForLimitedSpace(Set<SSTableReader> nonExpiredSSTables,
         return false;
     }
 
+    private void maybeNotifyIndexersAboutRowsInFullyExpiredSSTables(Set<SSTableReader> fullyExpiredSSTables)
+    {
+        if (fullyExpiredSSTables.isEmpty())
+            return;
+
+        List<Index> indexes = cfs.indexManager.listIndexes()
+                                              .stream()
+                                              .filter(Index::notifyIndexerAboutRowsInFullyExpiredSSTables)
+                                              .collect(Collectors.toList());
+
+        if (indexes.isEmpty())
+            return;
+
+        for (SSTableReader expiredSSTable : fullyExpiredSSTables)
+        {
+            expiredSSTable.getScanner()
+                          .forEachRemaining(partition ->
+                                            {
+                                                partition.forEachRemaining(unfiltered -> {

Review Comment:
   I am not completely sure this whole logic makes sense. First of all, I do not think you can do one transaction _per partition_. Because it needs `versions`. I am not sure what I should set that to because this is there when it is going to be _compacted_ but we are not compacting anything really ...
   
   So, we get IndexGCTransaction.
   
   Then, it will initialize `rows` in IndexGCTransaction's `start`. The size of the rows array is derived from `versions`. Then it will go over rows in `commit` etc.
   
   However, to have individual rows in `rows` not null, it has to go over  `onRowMerge` where it is "merging" rows. Then it will run it through `Rows.diff` and if builders are not null, it will populate `rows`
   
   Calling it like this did not help
   
   ````
   transaction.onRowMerge((Row) unfiltered);
   ````
   
   but this did the trick
   
   ````
   transaction.onRowMerge((Row) unfiltered, (Row) unfiltered);
   ````
   
   Basically we are "merging" row into itself and the diff is the row? Does this make sense? The test passes though.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20829 Secondary index implementations do not integrate with IndexGCTransaction when compaction contains fully expired SSTables [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4300:
URL: https://github.com/apache/cassandra/pull/4300#discussion_r2276146985


##########
src/java/org/apache/cassandra/index/SecondaryIndexManager.java:
##########
@@ -1224,7 +1224,19 @@ public CompactionTransaction newCompactionTransaction(DecoratedKey key,
                                                           int nowInSec)
     {
         // the check for whether there are any registered indexes is already done in CompactionIterator
-        return new IndexGCTransaction(key, regularAndStaticColumns, keyspace, versions, nowInSec, writableIndexes.values());
+        return newCompactionTransaction(key, regularAndStaticColumns, versions, nowInSec, writableIndexes.values());
+    }
+
+    /**
+     * Transaction for use when merging rows during compaction

Review Comment:
   todo: fix the comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org