Skip to content

Commit

Permalink
pool: don't treat an empty file as a sparse file
Browse files Browse the repository at this point in the history
Motivation:

The checksum calculation currently treats an empty file as a sparse file
and attempts to fill in the missing gaps.  Sparse file handling is
currently broken, so such attempts will fail.

See #6655.

Modification:

Do not consider an empty file as sparse.

Result:

A bug is fixed where the checksum calculation would fail for empty
files.

Target: master
Requires-notes: yes
Requires-book: no
Request: 8.1
Request: 8.0
Request: 7.2
Request: 7.1
Request: 7.0
Request: 6.2
Patch: https://rb.dcache.org/r/13564/
Acked-by: Lea Morschel
  • Loading branch information
paulmillar committed Jun 22, 2022
1 parent 543750a commit 433c089
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private Set<Checksum> finalizeChecksums() {
synchronized (_dataRangeSet) {
synchronized (_digests) {
try {

if (_dataRangeSet.asRanges().size() != 1 || _nextChecksumOffset == 0) {
if (_dataRangeSet.asRanges().size() > 1
|| (_dataRangeSet.asRanges().size() == 1 && _nextChecksumOffset == 0)) {
feedZerosToDigesterForRangeGaps();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.dcache.pool.repository.FileRepositoryChannel;
import org.dcache.pool.repository.FileStore;
Expand All @@ -41,12 +42,15 @@

public class ChecksumChannelTest {

private static final Checksum EMPTY_MD5_CHECKSUM = new Checksum(ChecksumType.MD5_TYPE,
"d41d8cd98f00b204e9800998ecf8427e");

private ChecksumChannel chksumChannel;

private final byte[] data = "\0Just\0A\0Short\0TestString\0To\0Verify\0\0Checksumming\0\0Works\12".getBytes(
StandardCharsets.ISO_8859_1); // \12 is a octal 10, linefeed
private final Checksum expectedChecksum = ChecksumType.MD5_TYPE.calculate(data);

private int blocksize = 2;
private int blockcount = data.length / blocksize;
private ByteBuffer[] buffers = new ByteBuffer[blockcount];
Expand Down Expand Up @@ -319,6 +323,13 @@ public void shouldFillUpRangeGapsWithZerosOnGetChecksum() throws IOException {
assertThat(chksumChannel.getChecksums(), contains(expectedChecksum));
}

@Test
public void shouldNotFillUpRangeGapsWithZeroLengthFile() throws IOException {
chksumChannel.close();
Set<Checksum> results = chksumChannel.getChecksums();
assertThat(results, contains(EMPTY_MD5_CHECKSUM));
}

private Map<Long, ByteBuffer> getNonZeroBlocksFromByteArray(byte[] bytes) {
Map<Long, ByteBuffer> result = new TreeMap<>();
for (int position = 0; position < bytes.length; position++) {
Expand Down

0 comments on commit 433c089

Please sign in to comment.