diff options
author | Simon Rettberg | 2018-05-16 13:08:44 +0200 |
---|---|---|
committer | Simon Rettberg | 2018-05-16 13:08:44 +0200 |
commit | e519e8edee76b0861f0684823f8f2a0cb9938ff3 (patch) | |
tree | 0380ebc565c0c17af8671b8f965c5015f8c16cf3 /src/main/java/org/openslx/filetransfer/util | |
parent | Add PrioThreadFactory (diff) | |
download | master-sync-shared-e519e8edee76b0861f0684823f8f2a0cb9938ff3.tar.gz master-sync-shared-e519e8edee76b0861f0684823f8f2a0cb9938ff3.tar.xz master-sync-shared-e519e8edee76b0861f0684823f8f2a0cb9938ff3.zip |
More speedup: LZ4 and empty chunk detection
Diffstat (limited to 'src/main/java/org/openslx/filetransfer/util')
3 files changed, 49 insertions, 2 deletions
diff --git a/src/main/java/org/openslx/filetransfer/util/ChunkList.java b/src/main/java/org/openslx/filetransfer/util/ChunkList.java index 11f64e8..91d6f1e 100644 --- a/src/main/java/org/openslx/filetransfer/util/ChunkList.java +++ b/src/main/java/org/openslx/filetransfer/util/ChunkList.java @@ -69,8 +69,14 @@ public class ChunkList if ( index >= allChunks.size() ) break; if ( sum != null ) { - if ( allChunks.get( index ).setSha1Sum( sum ) && firstNew == -1 ) { - firstNew = index; + FileChunk chunk = allChunks.get( index ); + if ( chunk.setSha1Sum( sum ) ) { + if ( firstNew == -1 ) { + firstNew = index; + } + if ( chunk.status == ChunkStatus.MISSING && Arrays.equals( FileChunk.NULL_BLOCK_SHA1, sum ) ) { + markMissingAsComplete( index ); + } } if ( !hasChecksum ) { hasChecksum = true; @@ -473,4 +479,16 @@ public class ChunkList return true; } + /** + * Returns true if the last chunk is exactly 16MiB and all zeros + * @return + */ + public boolean lastChunkIsZero() + { + if ( allChunks.isEmpty() ) + return false; + FileChunk chunk = allChunks.get( allChunks.size() - 1 ); + return chunk.sha1sum != null && Arrays.equals( FileChunk.NULL_BLOCK_SHA1, chunk.sha1sum ); + } + } diff --git a/src/main/java/org/openslx/filetransfer/util/FileChunk.java b/src/main/java/org/openslx/filetransfer/util/FileChunk.java index f302b3c..6594e31 100644 --- a/src/main/java/org/openslx/filetransfer/util/FileChunk.java +++ b/src/main/java/org/openslx/filetransfer/util/FileChunk.java @@ -1,5 +1,6 @@ package org.openslx.filetransfer.util; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.zip.CRC32; @@ -28,6 +29,13 @@ public class FileChunk private boolean writtenToDisk = false; private ChunkSource localSource = null; + static final byte[] NULL_BLOCK_SHA1 = new byte[] { + 0x3b, 0x44, 0x17, (byte)0xfc, 0x42, 0x1c, (byte)0xee, 0x30, (byte)0xa9, (byte)0xad, 0x0f, + (byte)0xd9, 0x31, (byte)0x92, 0x20, (byte)0xa8, (byte)0xda, (byte)0xe3, 0x2d, (byte)0xa2 + }; + + static final long NULL_BLOCK_CRC32 = 2759631178l; + public FileChunk( long startOffset, long endOffset, byte[] sha1sum ) { this.range = new FileRange( startOffset, endOffset ); @@ -43,6 +51,20 @@ public class FileChunk if ( this.sha1sum != null || sha1sum == null || sha1sum.length != SHA1_LENGTH ) return false; this.sha1sum = sha1sum; + if ( Arrays.equals( sha1sum, NULL_BLOCK_SHA1 ) ) { + // + writtenToDisk = true; + if ( crc32 == null ) { + crc32 = new CRC32() { + @Override + public long getValue() + { + return NULL_BLOCK_CRC32; + } + }; + } + return true; + } if ( this.status == ChunkStatus.COMPLETE ) { this.status = ChunkStatus.HASHING; } diff --git a/src/main/java/org/openslx/filetransfer/util/IncomingTransferBase.java b/src/main/java/org/openslx/filetransfer/util/IncomingTransferBase.java index 0355182..eaef63b 100644 --- a/src/main/java/org/openslx/filetransfer/util/IncomingTransferBase.java +++ b/src/main/java/org/openslx/filetransfer/util/IncomingTransferBase.java @@ -643,6 +643,13 @@ public abstract class IncomingTransferBase extends AbstractTransfer implements H if ( state == TransferState.FINISHED ) { return; } + try { + if ( tmpFileHandle.length() < fileSize && chunks.lastChunkIsZero() ) { + tmpFileHandle.setLength( fileSize ); + } + } catch ( IOException e) { + LOGGER.warn( "Cannot extend file size to " + fileSize ); + } safeClose( tmpFileHandle ); if ( localCopyManager != null ) { localCopyManager.interrupt(); |