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

CNDB-12342 Fix query view builder inifinite loop #1516

Open
wants to merge 2 commits into
base: cndb-main-release-20250109
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ private synchronized List<SSTableReader> findNonIndexedSSTables(ColumnFamilyStor
// 1. The current view does not contain the SSTable
// 2. The SSTable is not marked compacted
// 3. The column index does not have a completion marker
if (!view.hasIndexForSSTable(sstable)
if (!view.containsSSTableIndex(sstable.descriptor)
&& !sstable.isMarkedCompacted()
&& !IndexDescriptor.isIndexBuildCompleteOnDisk(sstable, indexContext))
{
Expand Down
7 changes: 5 additions & 2 deletions src/java/org/apache/cassandra/index/sai/plan/QueryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ else if (indexContext.isDropped())
{
// Index was dropped deliberately by the user.
// We cannot recover here.
refViewFragment.release();
throw new MissingIndexException(indexContext, "Index " + indexContext.getIndexName() +
" not found for memtable: " + memtable);
}
Expand Down Expand Up @@ -217,10 +216,14 @@ else if (!processedMemtables.contains(memtable))
// Lookup and reference the indexes corresponding to the sstables:
for (SSTableReader sstable : refViewFragment.sstables)
{
// Empty sstables are ok to not have the index.
if (sstable.getTotalRows() == 0)
continue;

// If the IndexViewManager never saw this sstable, then we need to spin.
// Let's hope in the next iteration we get the indexView based on the same sstable set
// as the refViewFragment.
if (!indexView.containsSSTable(sstable))
if (!indexView.isAwareOfSSTable(sstable.descriptor))
{
if (MonotonicClock.approxTime.isAfter(start + 100))
NoSpamLogger.log(logger, NoSpamLogger.Level.WARN, 1, TimeUnit.SECONDS,
Expand Down
29 changes: 22 additions & 7 deletions src/java/org/apache/cassandra/index/sai/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ public Collection<SSTableIndex> getIndexes()
return view.values();
}

public boolean containsSSTable(SSTableReader sstable)
{
return sstables.contains(sstable.descriptor);
}

public int size()
{
return view.size();
Expand All @@ -122,10 +117,30 @@ public int size()
{
return view.get(descriptor);
}

/**
* Tells if an index for the given sstable exists.
* It's equivalent to {@code getSSTableIndex(descriptor) != null }.
* @param descriptor identifies the sstable
*/
public boolean containsSSTableIndex(Descriptor descriptor)
{
return view.containsKey(descriptor);
}

public boolean hasIndexForSSTable(SSTableReader sstable)
/**
* Returns true if this view has been based on the Cassandra view containing given sstable.
* In other words, it tells if SAI was given a chance to load the index for the given sstable.
* It does not determine if the index exists and was actually loaded.
* To check the existence of the index, use {@link #containsSSTableIndex(Descriptor)}.
* <p>
* This method allows to distinguish a situation when the sstable has no index, the index is
* invalid, or was not loaded for whatever reason,
* from a situation where the view hasn't been updated yet to reflect the newly added sstable.
*/
public boolean isAwareOfSSTable(Descriptor descriptor)
{
return view.containsKey(sstable.descriptor);
return sstables.contains(descriptor);
}

/**
Expand Down