forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 21
CNDB-13483: Fix loading PQ file when disabled_reads is true #1713
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
Open
michaeljmarshall
wants to merge
16
commits into
main
Choose a base branch
from
cndb-13483
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
504b382
CNDB-13483: Fix loading PQ file when disabled_reads is true
michaeljmarshall 60d19fe
Refactor code to pull PQ fetching logic into single class
michaeljmarshall 7ffd115
Add comment asking about reducing memory utilization when loading PQ
michaeljmarshall a988897
Fix the broken allRowsHaveVectorsInWrittenSegments method
michaeljmarshall d3b2b22
Log IOException and continue processing to prevent unnecessary flakiness
michaeljmarshall 58fbc17
Merge remote-tracking branch 'datastax/main' into cndb-13483
michaeljmarshall 6e4b72d
Cleanup unused throws in method signature
michaeljmarshall bbfec37
Add test; minor fixes exposed by tests
michaeljmarshall 0e3700b
Tweak postings strcuture logic (deeper changes to come)
michaeljmarshall cf9a2bd
Add more tests
michaeljmarshall 2c820b7
Refactor API for getting postings structures
michaeljmarshall 18f883e
Merge remote-tracking branch 'datastax/main' into cndb-13483
michaeljmarshall 3748693
Initial refactors after review
michaeljmarshall b5441cd
Push getting PqInfo into SearchableIndex interface
michaeljmarshall a872344
Fix comments; add version filtering to getPostingsStructures
michaeljmarshall e342824
More cleanup
michaeljmarshall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,16 @@ | |
import org.apache.cassandra.db.virtual.SimpleDataSet; | ||
import org.apache.cassandra.dht.AbstractBounds; | ||
import org.apache.cassandra.index.sai.disk.EmptyIndex; | ||
import org.apache.cassandra.index.sai.disk.V1MetadataOnlySearchableIndex; | ||
import org.apache.cassandra.index.sai.disk.PrimaryKeyMapIterator; | ||
import org.apache.cassandra.index.sai.disk.SearchableIndex; | ||
import org.apache.cassandra.index.sai.disk.format.IndexComponents; | ||
import org.apache.cassandra.index.sai.disk.format.IndexFeatureSet; | ||
import org.apache.cassandra.index.sai.disk.format.Version; | ||
import org.apache.cassandra.index.sai.disk.v1.PerIndexFiles; | ||
import org.apache.cassandra.index.sai.disk.v1.Segment; | ||
import org.apache.cassandra.index.sai.disk.v1.SegmentMetadata; | ||
import org.apache.cassandra.index.sai.disk.v1.V1SearchableIndex; | ||
import org.apache.cassandra.index.sai.iterators.KeyRangeAntiJoinIterator; | ||
import org.apache.cassandra.index.sai.iterators.KeyRangeIterator; | ||
import org.apache.cassandra.index.sai.plan.Expression; | ||
|
@@ -92,8 +96,20 @@ private static SearchableIndex createSearchableIndex(SSTableContext sstableConte | |
{ | ||
if (CassandraRelevantProperties.SAI_INDEX_READS_DISABLED.getBoolean()) | ||
{ | ||
logger.info("Creating dummy (empty) index searcher for sstable {} as SAI index reads are disabled", sstableContext.sstable.descriptor); | ||
return new EmptyIndex(); | ||
var context = perIndexComponents.context(); | ||
if (!perIndexComponents.isEmpty() | ||
&& context != null | ||
&& context.isVector() | ||
&& CassandraRelevantProperties.SAI_INDEX_LOAD_SEGMENT_METADATA_ONLY.getBoolean()) | ||
{ | ||
logger.info("Creating a lazy index searcher for sstable {} as SAI index reads are disabled, but this is a vector index", sstableContext.sstable.descriptor.id); | ||
michaeljmarshall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return new V1MetadataOnlySearchableIndex(sstableContext, perIndexComponents); | ||
} | ||
else | ||
{ | ||
logger.info("Creating dummy (empty) index searcher for sstable {} as SAI index reads are disabled", sstableContext.sstable.descriptor); | ||
return new EmptyIndex(); | ||
} | ||
} | ||
|
||
return perIndexComponents.onDiskFormat().newSearchableIndex(sstableContext, perIndexComponents); | ||
|
@@ -122,6 +138,22 @@ public List<Segment> getSegments() | |
return searchableIndex.getSegments(); | ||
} | ||
|
||
public List<SegmentMetadata> getSegmentMetadatas() | ||
{ | ||
return searchableIndex.getSegmentMetadatas(); | ||
} | ||
|
||
public boolean areSegmentsLoaded() | ||
{ | ||
return searchableIndex instanceof V1SearchableIndex; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public PerIndexFiles indexFiles() | ||
{ | ||
assert searchableIndex instanceof V1MetadataOnlySearchableIndex; | ||
michaeljmarshall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ((V1MetadataOnlySearchableIndex) searchableIndex).indexFiles(); | ||
} | ||
|
||
public long indexFileCacheSize() | ||
{ | ||
return searchableIndex.indexFileCacheSize(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 235 additions & 0 deletions
235
src/java/org/apache/cassandra/index/sai/disk/V1MetadataOnlySearchableIndex.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.cassandra.index.sai.disk; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
|
||
import org.apache.cassandra.db.DecoratedKey; | ||
import org.apache.cassandra.db.PartitionPosition; | ||
import org.apache.cassandra.db.virtual.SimpleDataSet; | ||
import org.apache.cassandra.dht.AbstractBounds; | ||
import org.apache.cassandra.dht.Token; | ||
import org.apache.cassandra.index.sai.IndexContext; | ||
import org.apache.cassandra.index.sai.QueryContext; | ||
import org.apache.cassandra.index.sai.SSTableContext; | ||
import org.apache.cassandra.index.sai.disk.format.IndexComponents; | ||
import org.apache.cassandra.index.sai.disk.v1.MetadataSource; | ||
import org.apache.cassandra.index.sai.disk.v1.PerIndexFiles; | ||
import org.apache.cassandra.index.sai.disk.v1.Segment; | ||
import org.apache.cassandra.index.sai.disk.v1.SegmentMetadata; | ||
import org.apache.cassandra.index.sai.iterators.KeyRangeIterator; | ||
import org.apache.cassandra.index.sai.plan.Expression; | ||
import org.apache.cassandra.index.sai.plan.Orderer; | ||
import org.apache.cassandra.index.sai.utils.PrimaryKey; | ||
import org.apache.cassandra.index.sai.utils.PrimaryKeyWithSortKey; | ||
import org.apache.cassandra.index.sai.utils.TypeUtil; | ||
import org.apache.cassandra.io.sstable.format.SSTableReader; | ||
import org.apache.cassandra.io.util.FileUtils; | ||
import org.apache.cassandra.utils.CloseableIterator; | ||
import org.apache.cassandra.utils.Throwables; | ||
|
||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.CELL_COUNT; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.COLUMN_NAME; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.COMPONENT_METADATA; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.END_TOKEN; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.MAX_SSTABLE_ROW_ID; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.MAX_TERM; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.MIN_SSTABLE_ROW_ID; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.MIN_TERM; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.START_TOKEN; | ||
import static org.apache.cassandra.index.sai.virtual.SegmentsSystemView.TABLE_NAME; | ||
|
||
/** | ||
* An index that eagerly loads segment metadata and nothing else. It is currently only used for vector indexes to | ||
* read PQ files during compaction. | ||
michaeljmarshall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public class V1MetadataOnlySearchableIndex implements SearchableIndex | ||
{ | ||
private final List<SegmentMetadata> metadatas; | ||
private final DecoratedKey minKey; | ||
private final DecoratedKey maxKey; // in token order | ||
private final ByteBuffer minTerm; | ||
private final ByteBuffer maxTerm; | ||
private final long minSSTableRowId, maxSSTableRowId; | ||
private final long numRows; | ||
private final IndexContext indexContext; | ||
private PerIndexFiles indexFiles; | ||
|
||
public V1MetadataOnlySearchableIndex(SSTableContext sstableContext, IndexComponents.ForRead perIndexComponents) | ||
{ | ||
try | ||
{ | ||
this.indexContext = perIndexComponents.context(); | ||
this.indexFiles = new PerIndexFiles(perIndexComponents); | ||
|
||
final MetadataSource source = MetadataSource.loadMetadata(perIndexComponents); | ||
|
||
// We skip loading the terms distribution becuase this class doesn't use them for now. | ||
metadatas = SegmentMetadata.load(source, indexContext, false); | ||
|
||
this.minKey = metadatas.get(0).minKey.partitionKey(); | ||
this.maxKey = metadatas.get(metadatas.size() - 1).maxKey.partitionKey(); | ||
|
||
var version = perIndexComponents.version(); | ||
this.minTerm = metadatas.stream().map(m -> m.minTerm).min(TypeUtil.comparator(indexContext.getValidator(), version)).orElse(null); | ||
this.maxTerm = metadatas.stream().map(m -> m.maxTerm).max(TypeUtil.comparator(indexContext.getValidator(), version)).orElse(null); | ||
|
||
this.numRows = metadatas.stream().mapToLong(m -> m.numRows).sum(); | ||
|
||
this.minSSTableRowId = metadatas.get(0).minSSTableRowId; | ||
this.maxSSTableRowId = metadatas.get(metadatas.size() - 1).maxSSTableRowId; | ||
} | ||
catch (Throwable t) | ||
{ | ||
FileUtils.closeQuietly(indexFiles); | ||
FileUtils.closeQuietly(sstableContext); | ||
throw Throwables.unchecked(t); | ||
} | ||
} | ||
|
||
@Override | ||
public long indexFileCacheSize() | ||
{ | ||
// In V1IndexSearcher we accumulate the index file cache size from the segments, so this is 0. | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long getRowCount() | ||
{ | ||
return numRows; | ||
} | ||
|
||
@Override | ||
public long minSSTableRowId() | ||
{ | ||
return minSSTableRowId; | ||
} | ||
@Override | ||
public long maxSSTableRowId() | ||
{ | ||
return maxSSTableRowId; | ||
} | ||
|
||
@Override | ||
public ByteBuffer minTerm() | ||
{ | ||
return minTerm; | ||
} | ||
|
||
@Override | ||
public ByteBuffer maxTerm() | ||
{ | ||
return maxTerm; | ||
} | ||
|
||
@Override | ||
public DecoratedKey minKey() | ||
{ | ||
return minKey; | ||
} | ||
|
||
@Override | ||
public DecoratedKey maxKey() | ||
{ | ||
return maxKey; | ||
} | ||
|
||
@Override | ||
public KeyRangeIterator search(Expression expression, | ||
AbstractBounds<PartitionPosition> keyRange, | ||
QueryContext context, | ||
boolean defer, | ||
int limit) throws IOException | ||
{ | ||
// This index is not meant for searching, only for accessing metadata and index files | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<CloseableIterator<PrimaryKeyWithSortKey>> orderBy(Orderer orderer, | ||
Expression slice, | ||
AbstractBounds<PartitionPosition> keyRange, | ||
QueryContext context, | ||
int limit, | ||
long totalRows) throws IOException | ||
{ | ||
// This index is not meant for searching, only for accessing metadata and index files | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<Segment> getSegments() | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<SegmentMetadata> getSegmentMetadatas() | ||
{ | ||
return metadatas; | ||
} | ||
|
||
public PerIndexFiles indexFiles() | ||
{ | ||
return indexFiles; | ||
} | ||
|
||
@Override | ||
public void populateSystemView(SimpleDataSet dataSet, SSTableReader sstable) | ||
michaeljmarshall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Token.TokenFactory tokenFactory = sstable.metadata().partitioner.getTokenFactory(); | ||
|
||
for (SegmentMetadata metadata : metadatas) | ||
{ | ||
dataSet.row(sstable.metadata().keyspace, indexContext.getIndexName(), sstable.getFilename(), metadata.segmentRowIdOffset) | ||
.column(TABLE_NAME, sstable.descriptor.cfname) | ||
.column(COLUMN_NAME, indexContext.getColumnName()) | ||
.column(CELL_COUNT, metadata.numRows) | ||
.column(MIN_SSTABLE_ROW_ID, metadata.minSSTableRowId) | ||
.column(MAX_SSTABLE_ROW_ID, metadata.maxSSTableRowId) | ||
.column(START_TOKEN, tokenFactory.toString(metadata.minKey.partitionKey().getToken())) | ||
.column(END_TOKEN, tokenFactory.toString(metadata.maxKey.partitionKey().getToken())) | ||
.column(MIN_TERM, "N/A") | ||
.column(MAX_TERM, "N/A") | ||
.column(COMPONENT_METADATA, metadata.componentMetadatas.asMap()); | ||
} | ||
} | ||
|
||
@Override | ||
public long estimateMatchingRowsCount(Expression predicate, AbstractBounds<PartitionPosition> keyRange) | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException | ||
{ | ||
FileUtils.closeQuietly(indexFiles); | ||
} | ||
|
||
@Override | ||
public List<CloseableIterator<PrimaryKeyWithSortKey>> orderResultsBy(QueryContext context, List<PrimaryKey> keys, Orderer orderer, int limit, long totalRows) throws IOException | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.