Skip to content

SOLR-18250: GCSBackupRepository.copyIndexFileTo must not swallow failures - #4726

Open
iprithv wants to merge 1 commit into
apache:mainfrom
iprithv:gcs-copyIndexFileTo-fix
Open

SOLR-18250: GCSBackupRepository.copyIndexFileTo must not swallow failures#4726
iprithv wants to merge 1 commit into
apache:mainfrom
iprithv:gcs-copyIndexFileTo-fix

Conversation

@iprithv

@iprithv iprithv commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-18250

GCSBackupRepository.copyIndexFileTo currently:

Swallows all exceptions via a bare catch (Exception e) { log.info("Here's an exception e", e); }, so a failed or incomplete restore can look successful.
Uses while (readChannel.read(buffer) > 0), which is incorrect per ReadableByteChannel.read: a 0 return is not EOF, so the loop can terminate early and leave a truncated destination file. The S3 equivalent already uses != -1.

Signed-off-by: prithvi <prithvisivasankar@gmail.com>
@iprithv

iprithv commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

return repo;
}

private static class TestGCSBackupRepository extends GCSBackupRepository {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe just a bit of docs to cue the user that we are udisng this to be able to simulate certain behaviors?

});
}

private static Object invokeAndUnwrap(Method method, Object target, Object[] args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

huh.. everytime I see these very advanced java method manipulation, I get slightly nervous, but maybe just a quick doc that says what we are using this for?

});
}

private static ReadChannel createZeroFirstReadChannel(ReadChannel delegate) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

likewise a doc, and I think it's cool how you are setting up specific scenarios.

@epugh epugh changed the title GCSBackupRepository.copyIndexFileTo must not swallow failures SOLR-18250: GCSBackupRepository.copyIndexFileTo must not swallow failures Aug 12, 2026
@epugh

epugh commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

@iprithv there is a template for prs, and I tweaked the title and added the link to jira in the PR ;-). that allows linking to jira ;-)

@epugh

epugh commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

i ran the ci/cd jobs, can you review.. this seems reasonable fix direction with tests!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes robustness and observability issues in the GCS backup restore path by ensuring GCSBackupRepository.copyIndexFileTo neither truncates output on zero-byte reads nor hides underlying failures, aligning behavior with the S3 repository’s semantics.

Changes:

  • Fix copyIndexFileTo read loop to use read(...) != -1 so 0 is not treated as EOF, preventing truncated restores.
  • Stop swallowing exceptions: log failures at error level and propagate IOExceptions; wrap unexpected runtime failures in an IOException with context.
  • Add/extend unit tests covering read failures, zero-byte reads, and a successful copy path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
solr/modules/gcs-repository/src/java/org/apache/solr/gcs/GCSBackupRepository.java Fixes the copy loop EOF condition and ensures failures are propagated instead of being swallowed.
solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSBackupRepositoryTest.java Adds tests validating failure propagation and correct handling of zero-byte reads during copy.
changelog/unreleased/gcs-copyIndexFileTo-fix.yml Adds a changelog entry describing the fix (needs links to match project conventions).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1 to +5
title: >
Fixed GCS backup restores silently swallowing failures and stopping early on zero-byte reads (SOLR-18250).
type: fixed
authors:
- name: Prithvi S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants