Do not try to read empty files.

CI report [1].

  [1]: https://clickhouse-test-reports.s3.yandex.net/30190/fe534553b2a0ac543795956b3fbde673cf5a342b/functional_stateless_tests_(debug).html#fail1

Fixes: 01560_ttl_remove_empty_parts in debug build (and some other tests)
v0: fix MergeTreeDataPartCompact::loadIndexGranularity()/MergeTreeDataPartWide::loadIndexGranularity()
v2: use EmptyReadBuffer in DiskLocal::readFile()
v3: introduce ReadBufferFromEmptyFile
v4: rebase against readbuffer-real-size branch
This commit is contained in:
Azat Khuzhin 2021-10-17 10:41:11 +03:00
parent b0f9112696
commit a630821f60
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#pragma once
#include <IO/ReadBuffer.h>
namespace DB
{
/// In case of empty file it does not make any sense to read it.
///
/// Plus regular readers from file has an assert that buffer is not empty, that will fail:
/// - ReadBufferFromFileDescriptor
/// - SynchronousReader
/// - ThreadPoolReader
class ReadBufferFromEmptyFile : public ReadBufferFromFileBase
{
private:
bool nextImpl() override { return false; }
std::string getFileName() const override { return "<empty>"; }
off_t seek(off_t /*off*/, int /*whence*/) override { return 0; }
off_t getPosition() override { return 0; }
};
}

View File

@ -1,4 +1,5 @@
#include <IO/createReadBufferFromFileBase.h>
#include <IO/ReadBufferFromEmptyFile.h>
#include <IO/ReadBufferFromFile.h>
#include <IO/MMapReadBufferFromFileWithCache.h>
#include <IO/AsynchronousReadBufferFromFile.h>
@ -33,6 +34,8 @@ std::unique_ptr<ReadBufferFromFileBase> createReadBufferFromFileBase(
char * existing_memory,
size_t alignment)
{
if (size.has_value() && !*size)
return std::make_unique<ReadBufferFromEmptyFile>();
size_t estimated_size = size.has_value() ? *size : 0;
if (!existing_memory