Skip to content
Merged
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
27 changes: 19 additions & 8 deletions src/java/org/apache/cassandra/io/sstable/format/TOCComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,29 @@ public static Set<Component> loadOrCreate(Descriptor descriptor)
{
try
{
SSTableWatcher.instance.discoverComponents(descriptor);
return TOCComponent.loadTOC(descriptor);
// Try loading TOC first without discovering components or checking file existence.
return TOCComponent.loadTOC(descriptor, false);
}
catch (FileNotFoundException | NoSuchFileException e)
{
Set<Component> components = descriptor.discoverComponents();
if (components.isEmpty())
return components; // sstable doesn't exist yet
SSTableWatcher.instance.discoverComponents(descriptor);

// Try loading TOC again after discovering components, still without existence checks
try
{
return TOCComponent.loadTOC(descriptor, false);
}
catch (FileNotFoundException | NoSuchFileException e2)
{
// Still no TOC, create it from discovered components
Set<Component> components = descriptor.discoverComponents();
if (components.isEmpty())
return components; // sstable doesn't exist yet

components.add(Components.TOC);
TOCComponent.appendTOC(descriptor, components);
return components;
components.add(Components.TOC);
TOCComponent.appendTOC(descriptor, components);
return components;
}
}
}
catch (IOException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ private ICompressor getEncryptor(Descriptor desc, boolean writeTime)
}

File compressionFile = desc.fileFor(Components.COMPRESSION_INFO);
if (!compressionFile.exists())
return null;

Choose a reason for hiding this comment

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

This check is not needed?

Copy link
Author

Choose a reason for hiding this comment

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

From what I can tell it's an optimization to return early. The exists() triggers an opening of the file though and that is what causes issues.


try
{
Expand All @@ -364,10 +362,12 @@ private ICompressor getEncryptor(Descriptor desc, boolean writeTime)
return compressor.encryptionOnly();
return null;
}
catch (Exception e)
catch (Throwable t)
{
// If we can't read the compression metadata, assume no encryption
logger.debug("Could not read compression metadata for {}: {}", desc, e.getMessage());
// If we can't read the compression metadata, assume no encryption.
// During flush, the compression file may not be accessible yet in some implementations
// causing FSReadError. Catch Throwable to handle both Exception and Error.
logger.debug("Could not read compression metadata for {}: {}", desc, t.getMessage());
return null;
}
}
Expand Down