Skip to content

Conversation

@michaeljmarshall
Copy link
Member

@michaeljmarshall michaeljmarshall commented Apr 17, 2025

What is the issue

Fixes: https://github.com/riptano/cndb/issues/13693

What does this PR fix and why was it fixed

The new design is to:

  1. Make sai View reference-able so that it holds references to the underlying SSTableIndexs. When the view is released the final time, it releases the indexes. This moves all of the complexity of grabbing references to sstable update time and out of the query path, which seems like a generally good improvement.
  2. Observe that SSTableIndex holds a reference to its associated sstable reader.

Note also that we need to create the memtable index on deletions in order to make the index-first solution work.

Also note that sstables indexes are added before they are removed on flush, so this change in design is safe for flush.

@github-actions
Copy link

Checklist before you submit for review

  • Make sure there is a PR in the CNDB project updating the Converged Cassandra version
  • Use NoSpamLogger for log lines that may appear frequently in the logs
  • Verify test results on Butler
  • Test coverage for new/modified code is > 80%
  • Proper code formatting
  • Proper title for each commit staring with the project-issue number, like CNDB-1234
  • Each commit has a meaningful description
  • Each commit is not very long and contains related changes
  • Renames, moves and reformatting are in distinct commits
  • All new files should contain the DataStax copyright header instead of the Apache License one

@jasonstack
Copy link

jasonstack commented Apr 21, 2025

I will review it tmr.


Update: I won't be able to review it on Tuesday. Will do it within this week.

if (matcher.apply(cv))
{
// We can exit now because we won't find a better candidate
var candidate = new PqInfo(searcher.getPQ(), searcher.containsUnitVectors(), segment.metadata.numRows);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: make sure the PQ is safe to use after releasing the view.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about adding a SSTableIndex in PqInfo and release it when PqInfo is done

((StorageAttachedIndex) cfs.getIndexManager().getIndex(indexMetadata)).getIndexContext().prepareSSTablesForRebuild(sstables);
assertEmpty(execute("SELECT * FROM %s WHERE a=1"));
assertEmpty(execute("SELECT * FROM %s WHERE c=1"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test testIndexRebuildWhenAddingSStableViaRemoteReload was added to test legacy writer behavior that built index on writer. Now writer only builds index on flush, not reload.

During sstable reload, reloaded sstable should have index attached (compaction task would abort if failed to build index; if initial index build is not completed, index is not-queryable, it's fine); unless it's added as shallow sstable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test can be removed if you prefer


var sstableReaders = new ArrayList<SSTableReader>(saiView.size());
// These are already referenced because they are referenced by the same view we just referenced.
// TODO review saiView.match() method for boolean predicates.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an issue about boolean predicate support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create it. The point is that we have a data structure in the view to efficiently get the indexes that might satisfy the predicate. Without using match, we're just searching all indexes.

Copy link

@pkolaczk pkolaczk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice simplification and this avoids all the looping with matching the indexes to sstables. However I have a concern if we don't miss any data in a very narrow race window when flush happens.

Copy link

@jasonstack jasonstack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment on potential race with shallow sstable, the rest LGTM

newViewIndexes.clear();

// Throw after releasing already referenced indexes
if (iterations++ > 1000)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be nice have a config property

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is likely that we'll hit this unless there is a bug in the logic. We have a similar ceiling at 1000 for the chunk cache:

if (buf == null && ++spin == 1000)
{
String msg = String.format("Could not acquire a reference to for %s after 1000 attempts. " +
"This is likely due to the chunk cache being too small for the " +
"number of concurrently running requests.", chunkKey);
throw new RuntimeException(msg);
// Note: this might also be caused by reference counting errors, especially double release of
// chunks.
}

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 6, 2025

@michaeljmarshall michaeljmarshall merged commit 8f31782 into main May 6, 2025
6 of 71 checks passed
@michaeljmarshall michaeljmarshall deleted the cndb-13693 branch May 6, 2025 17:58
@cassci-bot
Copy link

❌ Build ds-cassandra-pr-gate/PR-1700 rejected by Butler


2 new test failure(s) in 10 builds
See build details here


Found 2 new test failures

Test Explanation Branch history Upstream history
...d.t.s.VectorDistributedTest.rangeRestrictedTest regression 🔴🔵🔵🔵🔵🔵🔵 🔵🔵🔵🔵🔵🔵🔵
o.a.c.u.b.BinLogTest.testTruncationReleasesLogS... regression 🔴🔵🔴🔵🔴🔵🔴 🔵🔵🔵🔵🔵🔵🔵

Found 22 known test failures

michaeljmarshall added a commit that referenced this pull request May 9, 2025
…iew (#1700)

Fixes: riptano/cndb#13693

The new design is to:

1. Make sai `View` reference-able so that it holds references to the
underlying `SSTableIndex`s. When the `view` is released the final time,
it releases the indexes. This moves all of the complexity of grabbing
references to sstable update time and out of the query path, which seems
like a generally good improvement.
2. Observe that `SSTableIndex` holds a reference to its associated
sstable reader.

Note also that we need to create the memtable index on deletions in
order to make the index-first solution work.

Also note that sstables indexes are added before they are removed on
flush, so this change in design is safe for flush.

(cherry picked from commit 8f31782)
driftx pushed a commit that referenced this pull request Jun 13, 2025
…iew (#1700)

Fixes: riptano/cndb#13693

The new design is to:

1. Make sai `View` reference-able so that it holds references to the
underlying `SSTableIndex`s. When the `view` is released the final time,
it releases the indexes. This moves all of the complexity of grabbing
references to sstable update time and out of the query path, which seems
like a generally good improvement.
2. Observe that `SSTableIndex` holds a reference to its associated
sstable reader.

Note also that we need to create the memtable index on deletions in
order to make the index-first solution work.

Also note that sstables indexes are added before they are removed on
flush, so this change in design is safe for flush.
driftx pushed a commit that referenced this pull request Jun 13, 2025
…iew (#1700)

Fixes: riptano/cndb#13693

The new design is to:

1. Make sai `View` reference-able so that it holds references to the
underlying `SSTableIndex`s. When the `view` is released the final time,
it releases the indexes. This moves all of the complexity of grabbing
references to sstable update time and out of the query path, which seems
like a generally good improvement.
2. Observe that `SSTableIndex` holds a reference to its associated
sstable reader.

Note also that we need to create the memtable index on deletions in
order to make the index-first solution work.

Also note that sstables indexes are added before they are removed on
flush, so this change in design is safe for flush.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants