Skip to content

Commit 4b16c61

Browse files
authored
CNDB-13305: change IndexComponentDiscovery#discoverComponents signature to use SSTableReader and add more loggings to index tracking (#1644)
1 parent 99b27c3 commit 4b16c61

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

src/java/org/apache/cassandra/index/sai/IndexContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ public Pair<Set<SSTableIndex>, Set<SSTableContext>> getBuiltIndexes(Collection<S
925925
var perIndexComponents = perSSTableComponents.indexDescriptor().perIndexComponents(this);
926926
if (!perSSTableComponents.isComplete() || !perIndexComponents.isComplete())
927927
{
928-
logger.debug(logMessage("An on-disk index build for SSTable {} has not completed."), context.descriptor());
928+
logger.debug(logMessage("An on-disk index build for SSTable {} has not completed (per-index components={})."), context.descriptor(), perIndexComponents.all());
929929
return;
930930
}
931931

src/java/org/apache/cassandra/index/sai/SSTableContextManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public Optional<Set<SSTableContext>> update(Collection<SSTableReader> removed, I
8282
{
8383
if (sstable.isMarkedCompacted())
8484
{
85+
logger.debug("Skipped tracking sstable {} because it's marked compacted", sstable);
8586
continue;
8687
}
8788

@@ -94,6 +95,7 @@ public Optional<Set<SSTableContext>> update(Collection<SSTableReader> removed, I
9495
// validation (it would fail), and we also don't want to add it to the returned contexts, since it's
9596
// not ready yet. We know a future call of this method will be triggered for that sstable once the
9697
// index finishes building.
98+
logger.debug("Skipped tracking sstable {} because per sstable components are not complete (components={})", sstable, perSSTableComponents.all());
9799
continue;
98100
}
99101

src/java/org/apache/cassandra/index/sai/disk/format/DefaultIndexComponentDiscovery.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
package org.apache.cassandra.index.sai.disk.format;
2020

2121
import org.apache.cassandra.io.sstable.Descriptor;
22+
import org.apache.cassandra.io.sstable.format.SSTableReader;
2223
import org.apache.cassandra.schema.TableMetadata;
2324

2425
public class DefaultIndexComponentDiscovery extends IndexComponentDiscovery
2526
{
2627
@Override
27-
public SSTableIndexComponentsState discoverComponents(Descriptor descriptor, TableMetadata metadata)
28+
public SSTableIndexComponentsState discoverComponents(SSTableReader sstable)
2829
{
29-
SSTableIndexComponentsState groups = tryDiscoverComponentsFromTOC(descriptor);
30+
SSTableIndexComponentsState groups = tryDiscoverComponentsFromTOC(sstable.getDescriptor());
3031
return groups == null
31-
? discoverComponentsFromDiskFallback(descriptor)
32+
? discoverComponentsFromDiskFallback(sstable.getDescriptor())
3233
: groups;
3334
}
3435
}

src/java/org/apache/cassandra/index/sai/disk/format/IndexComponentDiscovery.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.cassandra.io.sstable.Component;
3636
import org.apache.cassandra.io.sstable.Descriptor;
3737
import org.apache.cassandra.io.sstable.SSTable;
38+
import org.apache.cassandra.io.sstable.format.SSTableReader;
3839
import org.apache.cassandra.io.util.PathUtils;
3940
import org.apache.cassandra.schema.TableMetadata;
4041
import org.apache.cassandra.utils.FBUtilities;
@@ -74,15 +75,14 @@ public static IndexComponentDiscovery instance()
7475
* Note that "discovery" in this method only means finding out the "build ID" (version and generation) that should
7576
* be used for each group of components (per-sstable and per-index).
7677
*
77-
* @param descriptor the descriptor of the sstable for which to discover components.
78-
* @param metadata the metadata of the table the sstable belongs to.
78+
* @param sstable the sstable reader for which to discover components.
7979
* @return the discovered {@link ComponentsBuildId} to use for both per-sstable and each per-index components. The
8080
* returned build IDs should usually correspond to existing index components on disk but this is not a strong
8181
* asumption: if some group of components corresponding to the returned build ID has no completion marker or is
8282
* missing files, the group will not be usuable (and the corresponding index/indexes will not be usable) but this
8383
* should be handled "gracefully" by callers.
8484
*/
85-
public abstract SSTableIndexComponentsState discoverComponents(Descriptor descriptor, TableMetadata metadata);
85+
public abstract SSTableIndexComponentsState discoverComponents(SSTableReader sstable);
8686

8787
protected static IndexComponentType completionMarker(@Nullable String name)
8888
{

src/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.apache.cassandra.io.storage.StorageProvider;
5353
import org.apache.cassandra.io.util.File;
5454
import org.apache.cassandra.io.util.FileHandle;
55-
import org.apache.cassandra.schema.TableMetadata;
5655
import org.apache.cassandra.utils.NoSpamLogger;
5756
import org.apache.lucene.store.BufferedChecksumIndexInput;
5857
import org.apache.lucene.store.ChecksumIndexInput;
@@ -108,7 +107,7 @@ public static IndexDescriptor empty(Descriptor descriptor)
108107

109108
public static IndexDescriptor load(SSTableReader sstable, Set<IndexContext> indices)
110109
{
111-
SSTableIndexComponentsState discovered = IndexComponentDiscovery.instance().discoverComponents(sstable.descriptor, sstable.metadata());
110+
SSTableIndexComponentsState discovered = IndexComponentDiscovery.instance().discoverComponents(sstable);
112111
IndexDescriptor descriptor = new IndexDescriptor(sstable.descriptor);
113112
descriptor.initialize(indices, discovered);
114113
return descriptor;
@@ -221,13 +220,14 @@ private static Component customComponentFor(ComponentsBuildId buildId, IndexComp
221220
* where (post-flush) index building is done on separate dedicated services, and this method allows to reload the
222221
* result of such external services once it is made available locally.
223222
*
224-
* @param metadata The metadata of the table this descriptor is for.
223+
* @param sstable the sstable reader to reload index components
225224
* @param indices The set of indices to should part of the reloaded descriptor.
226225
* @return this descriptor, for chaining purpose.
227226
*/
228-
public IndexDescriptor reload(TableMetadata metadata, Set<IndexContext> indices)
227+
public IndexDescriptor reload(SSTableReader sstable, Set<IndexContext> indices)
229228
{
230-
SSTableIndexComponentsState discovered = IndexComponentDiscovery.instance().discoverComponents(descriptor, metadata);
229+
Preconditions.checkArgument(sstable.getDescriptor().equals(this.descriptor));
230+
SSTableIndexComponentsState discovered = IndexComponentDiscovery.instance().discoverComponents(sstable);
231231

232232
// We want to make sure the descriptor only has data for the provided `indices` on reload, so we remove any
233233
// index data that is not in the ones provided. This essentially make sure we don't hold up memory for

test/unit/org/apache/cassandra/index/sai/disk/format/IndexDescriptorTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
import org.apache.cassandra.index.sai.SAITester;
4040
import org.apache.cassandra.io.sstable.Component;
4141
import org.apache.cassandra.io.sstable.Descriptor;
42+
import org.apache.cassandra.io.sstable.format.SSTableReader;
4243
import org.apache.cassandra.io.util.File;
4344
import org.apache.cassandra.io.util.PathUtils;
45+
import org.mockito.Mockito;
4446
import org.mortbay.util.IO;
4547

4648
import static org.apache.cassandra.index.sai.SAIUtil.setLatestVersion;
@@ -90,9 +92,9 @@ private IndexDescriptor loadDescriptor(IndexContext... contexts)
9092
static IndexDescriptor loadDescriptor(Descriptor sstableDescriptor, IndexContext... contexts)
9193
{
9294
IndexDescriptor indexDescriptor = IndexDescriptor.empty(sstableDescriptor);
93-
// Note: passing `null` as metadata is a bit hacky, but it only exists to be passed to the underlying index
94-
// discovery class, and the default one ignores it so ... keeping it simple.
95-
indexDescriptor.reload(null, new HashSet<>(Arrays.asList(contexts)));
95+
SSTableReader sstable = Mockito.mock(SSTableReader.class);
96+
Mockito.when(sstable.getDescriptor()).thenReturn(sstableDescriptor);
97+
indexDescriptor.reload(sstable, new HashSet<>(Arrays.asList(contexts)));
9698
return indexDescriptor;
9799
}
98100

@@ -232,8 +234,9 @@ public void testReload() throws Throwable
232234
createFakePerSSTableComponents(descriptor, latest, 0);
233235
createFakePerIndexComponents(descriptor, indexContext, latest, 0);
234236

235-
// See comment on `loadDescriptor` regarding passing null
236-
indexDescriptor.reload(null, Set.of(indexContext));
237+
SSTableReader sstable = Mockito.mock(SSTableReader.class);
238+
Mockito.when(sstable.getDescriptor()).thenReturn(descriptor);
239+
indexDescriptor.reload(sstable, Set.of(indexContext));
237240

238241
// Both the perSSTableComponents and perIndexComponents should now be complete and the components should be present
239242

test/unit/org/apache/cassandra/index/sai/disk/v1/LegacyOnDiskFormatTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void setup() throws Throwable
9797
.addRegularColumn("text_value", UTF8Type.instance)
9898
.build();
9999
sstable = TrieIndexFormat.instance.getReaderFactory().openNoValidation(descriptor, TableMetadataRef.forOfflineTools(tableMetadata));
100-
indexDescriptor = IndexDescriptor.empty(sstable.descriptor).reload(tableMetadata, Set.of(intContext, textContext));
100+
indexDescriptor = IndexDescriptor.empty(sstable.descriptor).reload(sstable, Set.of(intContext, textContext));
101101
pkFactory = indexDescriptor.perSSTableComponents().version().onDiskFormat().newPrimaryKeyFactory(tableMetadata.comparator);
102102
}
103103

0 commit comments

Comments
 (0)