You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "shubhamranjan (via GitHub)" <gi...@apache.org> on 2026/03/10 19:58:19 UTC
[PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
shubhamranjan opened a new pull request, #4205:
URL: https://github.com/apache/solr/pull/4205
https://issues.apache.org/jira/browse/SOLR-18098
# Description
Replication fails with `EOFException` when transferring files whose size is an exact multiple of `PACKET_SZ` (1 MB). For example, replicating a file that is exactly 1 MB, 2 MB, etc. causes the follower to crash.
# Solution
The root cause is in `IndexFetcher.FileFetcher.fetchPackets()`. The replication packet protocol has three packet types:
1. **Data packet**: `int(size) + long(checksum) + byte[size]`
2. **Zero-length data packet**: `int(0) + long(checksum)` — sent when the last chunk fills exactly `PACKET_SZ`
3. **EOF marker**: `int(0)` — no checksum follows
The old code treated *any* `packetSize == 0` as a loop-continue, skipping the checksum at step 2. Those 8 unread checksum bytes were then interpreted as the next packet size → garbage value → `EOFException`.
The fix reorders `fetchPackets()` to:
1. Detect the EOF marker (`size=0` and `fis.peek() == -1`)
2. Read the checksum for **all** data packets, including zero-length ones
3. Skip zero-length data packets only after consuming their checksum
**AI Disclosure:** Claude (Anthropic) was used as an aid during diagnosis and development — specifically for analyzing the packet protocol interaction between `DirectoryFileStream.write()` and `fetchPackets()`, reasoning through the checksum read misalignment, and drafting test cases. All changes were reviewed, verified, and refined by a human (me) before submission.
# Tests
Added `IndexFetcherPacketProtocolTest` with 18 unit tests that exercise the packet protocol between `DirectoryFileStream` (sender) and `FileFetcher.fetchPackets` (receiver) in isolation:
- **Exact multiples of PACKET_SZ**: 1 MB, 2 MB, 3 MB, 63 MB
- **Non-multiples**: empty, 1 byte, 100 bytes, 100 KB, 512 KB
- **Boundary cases**: PACKET_SZ ± 1 byte, 1.5× PACKET_SZ, 2× PACKET_SZ ± 1
- **Error handling**: checksum mismatch detection
- **Buffer resize**: large multi-packet file (5 MB + 12345 bytes)
- **Successive transfers**: multiple exact-size files in sequence
Run with: `./gradlew :solr:core:test --tests "IndexFetcherPacketProtocolTest"`
# Checklist
Please review the following and check all that apply:
- [x] I have reviewed the guidelines for [How to Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my code conforms to the standards described there to the best of my ability.
- [x] I have created a Jira issue and added the issue ID to my pull request title.
- [x] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
- [x] I have developed this patch against the `main` branch.
- [x] I have run `./gradlew check`.
- [x] I have added tests for my changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "anshumg (via GitHub)" <gi...@apache.org>.
anshumg commented on PR #4205:
URL: https://github.com/apache/solr/pull/4205#issuecomment-4625687188
That's strange! I ran it and it passed locally :( Taking a look at it now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on PR #4205:
URL: https://github.com/apache/solr/pull/4205#issuecomment-4625428596
This PR does not pass precommit:
```
> Task :solr:modules:cuvs:ecjLintMain
/home/runner/work/solr/solr/solr/core/src/test/org/apache/solr/handler/IndexFetcherPacketProtocolTest.java:278: warning: [UnnecessarilyFullyQualified] This fully qualified name is unambiguous to the compiler if imported.
Method writeMethod = stream.getClass().getMethod("write", java.io.OutputStream.class);
> Task :solr:modules:cuvs:compileJava
> Task :solr:modules:cuvs:classes
> Task :solr:core:compileTestJava
^
(see https://errorprone.info/bugpattern/UnnecessarilyFullyQualified)
Did you mean 'Method writeMethod = stream.getClass().getMethod("write", OutputStream.class);'?
/home/runner/work/solr/solr/solr/core/src/test/org/apache/solr/handler/IndexFetcherPacketProtocolTest.java:380: warning: [UnnecessarilyFullyQualified] This fully qualified name is unambiguous to the compiler if imported.
return java.lang.reflect.Proxy.newProxyInstance(
^
(see https://errorprone.info/bugpattern/UnnecessarilyFullyQualified)
Did you mean 'return Proxy.newProxyInstance('?
error: warnings found and -Werror specified
Note: Some input files use or override a deprecated API.
> Task :solr:core:compileTestJava FAILED
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "shubhamranjan (via GitHub)" <gi...@apache.org>.
shubhamranjan commented on PR #4205:
URL: https://github.com/apache/solr/pull/4205#issuecomment-4321802423
@iamsanjay have updated the PR as per suggested changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "anshumg (via GitHub)" <gi...@apache.org>.
anshumg merged PR #4205:
URL: https://github.com/apache/solr/pull/4205
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "iamsanjay (via GitHub)" <gi...@apache.org>.
iamsanjay commented on PR #4205:
URL: https://github.com/apache/solr/pull/4205#issuecomment-4204527040
How about fixing DirectoryFileStream.write() at point where it's adding extra packet?
LocalFsFileStream.write() stops where bytesRead <= 0,
```
long bytesRead = channel.read(bb);
if (bytesRead <= 0) {
writeNothingAndFlush();
// we close because DeflaterOutputStream requires a close call, but the request
// outputstream is protected
fos.close();
break;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "shubhamranjan (via GitHub)" <gi...@apache.org>.
shubhamranjan commented on PR #4205:
URL: https://github.com/apache/solr/pull/4205#issuecomment-4321710256
> How about fixing DirectoryFileStream.write() at point where it's adding extra packet? LocalFsFileStream.write() stops where bytesRead <= 0,
>
> ```
> long bytesRead = channel.read(bb);
> if (bytesRead <= 0) {
> writeNothingAndFlush();
> // we close because DeflaterOutputStream requires a close call, but the request
> // outputstream is protected
> fos.close();
> break;
> }
> ```
yeah, sounds like a better approach to fix at the sender side. Will refactor. Thank you ! 🙌
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18098: Fix replication failure for files with exact MB sizes [solr]
Posted by "anshumg (via GitHub)" <gi...@apache.org>.
anshumg commented on PR #4205:
URL: https://github.com/apache/solr/pull/4205#issuecomment-4626043499
I'll merge this in once the tests pass. I'd missed enabling error-prone locally.
https://github.com/apache/solr/pull/4498
@janhoy - thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org