Skip to content

Commit 758b110

Browse files
authored
Clean up TOC if immutable components are disabled (#1267)
If immutable components is enabled, but then disabled for some reason, building an index where some components had a generation was correctly removing the previous index files from disk, but those file were not removed from the TOC itself. This led to potential issue correctly reading the TOC later.
1 parent c66bd8c commit 758b110

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,19 @@ private CountDownLatch shouldWritePerSSTableFiles(SSTableReader sstable, IndexDe
301301

302302
private static void prepareForRebuild(IndexComponents.ForRead components, Set<Component> replacedComponents)
303303
{
304-
// The current components will be replaced by "other" components if either 1) we either use immutable components,
305-
// or 2) the old components are from an old version. In the later cases, even if immutable components is not in
306-
// use, then newly written components will have a different version and thus be different files.
307-
if (components.version().useImmutableComponentFiles() || !components.version().equals(Version.latest()))
304+
// The current components are "replaced" (by "other" components) if the build create different components than
305+
// the existing ones. This will happen in the following cases:
306+
// 1. if we use immutable components, that's the point of immutable components.
307+
// 2. when we do not use immutable components, there is still 2 cases where this will happen:
308+
// a) the old components are from an older version: a new build will alawys be for `Version.latest()` and
309+
// so will create new files in that case.
310+
// b) the old components are from a non-0 generation: a new build will always be for generation 0 and so
311+
// here again new files will be created. Note that "normally" we should not have non-0 generation in the
312+
// first place if immutable components are not used, but we handle this case to better support "downgrades"
313+
// where immutable components was enabled, but then disabled for some reason. If that happens, we still
314+
// want to ensure a new build removes the old files both from disk (happens below) and from the sstable TOC
315+
// (which is what `replacedComponents` is about).
316+
if (components.version().useImmutableComponentFiles() || !components.version().equals(Version.latest()) || components.generation() != 0)
308317
replacedComponents.addAll(components.allAsCustomComponents());
309318

310319
if (!components.version().useImmutableComponentFiles())

0 commit comments

Comments
 (0)