Small refactoring

This commit is contained in:
alesapin 2018-12-25 13:35:46 +03:00
parent 4309775fc8
commit c91687f9d7
3 changed files with 20 additions and 8 deletions

View File

@ -72,13 +72,14 @@ bool CachedCompressedReadBuffer::nextImpl()
CachedCompressedReadBuffer::CachedCompressedReadBuffer(
const std::string & path_, UncompressedCache * cache_,
size_t estimated_size_, size_t aio_threshold_, size_t buf_size_)
const std::string & path_, UncompressedCache * cache_, size_t estimated_size_, size_t aio_threshold_,
size_t buf_size_)
: ReadBuffer(nullptr, 0), path(path_), cache(cache_), buf_size(buf_size_), estimated_size(estimated_size_),
aio_threshold(aio_threshold_), file_pos(0)
{
}
void CachedCompressedReadBuffer::seek(size_t offset_in_compressed_file, size_t offset_in_decompressed_block)
{
if (owned_cell &&

View File

@ -6,7 +6,6 @@
#include <IO/CompressedReadBufferBase.h>
#include <IO/UncompressedCache.h>
#include <port/clock.h>
#include <Compression/ICompressionCodec.h>
namespace DB
@ -43,7 +42,8 @@ private:
public:
CachedCompressedReadBuffer(
const std::string & path_, UncompressedCache * cache_, size_t estimated_size_, size_t aio_threshold_, size_t buf_size_ = DBMS_DEFAULT_BUFFER_SIZE);
const std::string & path_, UncompressedCache * cache_, size_t estimated_size_, size_t aio_threshold_,
size_t buf_size_ = DBMS_DEFAULT_BUFFER_SIZE);
void seek(size_t offset_in_compressed_file, size_t offset_in_decompressed_block);

View File

@ -58,13 +58,20 @@ size_t CompressedReadBufferBase::readCompressedData(size_t & size_decompressed,
if (!codec)
codec = CompressionCodecFactory::instance().get(method);
else if (method != codec->getMethodByte())
throw Exception("Data compressed with different method, given method byte " + getHexUIntLowercase(method) + ", previous method byte " + getHexUIntLowercase(codec->getMethodByte()), ErrorCodes::CANNOT_DECOMPRESS);
throw Exception("Data compressed with different methods, given method byte "
+ getHexUIntLowercase(method)
+ ", previous method byte "
+ getHexUIntLowercase(codec->getMethodByte()),
ErrorCodes::CANNOT_DECOMPRESS);
size_compressed_without_checksum = ICompressionCodec::readCompressedBlockSize(own_compressed_buffer.data());
size_decompressed = ICompressionCodec::readDecompressedBlockSize(own_compressed_buffer.data());
if (size_compressed_without_checksum > DBMS_MAX_COMPRESSED_SIZE)
throw Exception("Too large size_compressed_without_checksum: " + toString(size_compressed_without_checksum) + ". Most likely corrupted data.", ErrorCodes::TOO_LARGE_SIZE_COMPRESSED);
throw Exception("Too large size_compressed_without_checksum: "
+ toString(size_compressed_without_checksum)
+ ". Most likely corrupted data.",
ErrorCodes::TOO_LARGE_SIZE_COMPRESSED);
ProfileEvents::increment(ProfileEvents::ReadCompressedBytes, size_compressed_without_checksum + CHECKSUM_SIZE);
@ -95,7 +102,7 @@ size_t CompressedReadBufferBase::readCompressedData(size_t & size_decompressed,
}
return size_compressed_without_checksum + sizeof(checksum);
return size_compressed_without_checksum + CHECKSUM_SIZE;
}
@ -109,7 +116,11 @@ void CompressedReadBufferBase::decompress(char * to, size_t size_decompressed, s
if (!codec)
codec = CompressionCodecFactory::instance().get(method);
else if (codec->getMethodByte() != method)
throw Exception("Data compressed with different method, given method byte " + getHexUIntLowercase(method) + ", previous method byte " + getHexUIntLowercase(codec->getMethodByte()), ErrorCodes::CANNOT_DECOMPRESS);
throw Exception("Data compressed with different methods, given method byte "
+ getHexUIntLowercase(method)
+ ", previous method byte "
+ getHexUIntLowercase(codec->getMethodByte()),
ErrorCodes::CANNOT_DECOMPRESS);
codec->decompress(compressed_buffer, size_compressed_without_checksum, to);
}