Replace estimated_size with optional<size> for IDisk::readFile()

v2: rebase to fix conflicts in DiskEncrypted.cpp
This commit is contained in:
Azat Khuzhin 2021-10-18 21:18:41 +03:00
parent c0b01e7b0b
commit 2b96433daf
21 changed files with 34 additions and 31 deletions

View File

@ -89,15 +89,15 @@ std::unique_ptr<ReadBufferFromFileBase>
DiskCacheWrapper::readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const
std::optional<size_t> size) const
{
if (!cache_file_predicate(path))
return DiskDecorator::readFile(path, settings, estimated_size);
return DiskDecorator::readFile(path, settings, size);
LOG_DEBUG(log, "Read file {} from cache", backQuote(path));
if (cache_disk->exists(path))
return cache_disk->readFile(path, settings, estimated_size);
return cache_disk->readFile(path, settings, size);
auto metadata = acquireDownloadMetadata(path);
@ -131,7 +131,7 @@ DiskCacheWrapper::readFile(
auto tmp_path = path + ".tmp";
{
auto src_buffer = DiskDecorator::readFile(path, settings, estimated_size);
auto src_buffer = DiskDecorator::readFile(path, settings, size);
auto dst_buffer = cache_disk->writeFile(tmp_path, settings.local_fs_buffer_size, WriteMode::Rewrite);
copyData(*src_buffer, *dst_buffer);
}
@ -155,9 +155,9 @@ DiskCacheWrapper::readFile(
}
if (metadata->status == DOWNLOADED)
return cache_disk->readFile(path, settings, estimated_size);
return cache_disk->readFile(path, settings, size);
return DiskDecorator::readFile(path, settings, estimated_size);
return DiskDecorator::readFile(path, settings, size);
}
std::unique_ptr<WriteBufferFromFileBase>

View File

@ -37,7 +37,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(const String & path, size_t buf_size, WriteMode mode) override;

View File

@ -115,9 +115,9 @@ void DiskDecorator::listFiles(const String & path, std::vector<String> & file_na
std::unique_ptr<ReadBufferFromFileBase>
DiskDecorator::readFile(
const String & path, const ReadSettings & settings, size_t estimated_size) const
const String & path, const ReadSettings & settings, std::optional<size_t> size) const
{
return delegate->readFile(path, settings, estimated_size);
return delegate->readFile(path, settings, size);
}
std::unique_ptr<WriteBufferFromFileBase>

View File

@ -38,7 +38,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,

View File

@ -252,10 +252,10 @@ void DiskEncrypted::copy(const String & from_path, const std::shared_ptr<IDisk>
std::unique_ptr<ReadBufferFromFileBase> DiskEncrypted::readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const
std::optional<size_t> size) const
{
auto wrapped_path = wrappedPath(path);
auto buffer = delegate->readFile(wrapped_path, settings, estimated_size);
auto buffer = delegate->readFile(wrapped_path, settings, size);
if (buffer->eof())
{
/// File is empty, that's a normal case, see DiskEncrypted::truncateFile().

View File

@ -122,7 +122,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,

View File

@ -259,9 +259,9 @@ void DiskLocal::replaceFile(const String & from_path, const String & to_path)
fs::rename(from_file, to_file);
}
std::unique_ptr<ReadBufferFromFileBase> DiskLocal::readFile(const String & path, const ReadSettings & settings, size_t estimated_size) const
std::unique_ptr<ReadBufferFromFileBase> DiskLocal::readFile(const String & path, const ReadSettings & settings, std::optional<size_t> size) const
{
return createReadBufferFromFileBase(fs::path(disk_path) / path, settings, estimated_size);
return createReadBufferFromFileBase(fs::path(disk_path) / path, settings, size);
}
std::unique_ptr<WriteBufferFromFileBase>

View File

@ -74,7 +74,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,

View File

@ -315,7 +315,7 @@ void DiskMemory::replaceFileImpl(const String & from_path, const String & to_pat
files.insert(std::move(node));
}
std::unique_ptr<ReadBufferFromFileBase> DiskMemory::readFile(const String & path, const ReadSettings &, size_t) const
std::unique_ptr<ReadBufferFromFileBase> DiskMemory::readFile(const String & path, const ReadSettings &, std::optional<size_t>) const
{
std::lock_guard lock(mutex);

View File

@ -65,7 +65,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,

View File

@ -187,10 +187,10 @@ void DiskRestartProxy::listFiles(const String & path, std::vector<String> & file
}
std::unique_ptr<ReadBufferFromFileBase> DiskRestartProxy::readFile(
const String & path, const ReadSettings & settings, size_t estimated_size) const
const String & path, const ReadSettings & settings, std::optional<size_t> size) const
{
ReadLock lock (mutex);
auto impl = DiskDecorator::readFile(path, settings, estimated_size);
auto impl = DiskDecorator::readFile(path, settings, size);
return std::make_unique<RestartAwareReadBuffer>(*this, std::move(impl));
}

View File

@ -46,7 +46,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(const String & path, size_t buf_size, WriteMode mode) override;
void removeFile(const String & path) override;
void removeFileIfExists(const String & path) override;

View File

@ -182,7 +182,7 @@ bool DiskWebServer::exists(const String & path) const
}
std::unique_ptr<ReadBufferFromFileBase> DiskWebServer::readFile(const String & path, const ReadSettings & read_settings, size_t) const
std::unique_ptr<ReadBufferFromFileBase> DiskWebServer::readFile(const String & path, const ReadSettings & read_settings, std::optional<size_t>) const
{
LOG_TRACE(log, "Read from path: {}", path);
auto iter = files.find(path);

View File

@ -63,7 +63,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
/// Disk info

View File

@ -94,7 +94,7 @@ DiskHDFS::DiskHDFS(
}
std::unique_ptr<ReadBufferFromFileBase> DiskHDFS::readFile(const String & path, const ReadSettings & read_settings, size_t) const
std::unique_ptr<ReadBufferFromFileBase> DiskHDFS::readFile(const String & path, const ReadSettings & read_settings, std::optional<size_t>) const
{
auto metadata = readMeta(path);

View File

@ -50,7 +50,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(const String & path, size_t buf_size, WriteMode mode) override;

View File

@ -166,7 +166,7 @@ public:
virtual std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings = ReadSettings{},
size_t estimated_size = 0) const = 0;
std::optional<size_t> size = {}) const = 0;
/// Open the file for write and return WriteBufferFromFileBase object.
virtual std::unique_ptr<WriteBufferFromFileBase> writeFile(

View File

@ -222,7 +222,7 @@ void DiskS3::moveFile(const String & from_path, const String & to_path, bool sen
fs::rename(fs::path(metadata_path) / from_path, fs::path(metadata_path) / to_path);
}
std::unique_ptr<ReadBufferFromFileBase> DiskS3::readFile(const String & path, const ReadSettings & read_settings, size_t) const
std::unique_ptr<ReadBufferFromFileBase> DiskS3::readFile(const String & path, const ReadSettings & read_settings, std::optional<size_t>) const
{
auto settings = current_settings.get();
auto metadata = readMeta(path);

View File

@ -77,7 +77,7 @@ public:
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
const ReadSettings & settings,
size_t estimated_size) const override;
std::optional<size_t> size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,

View File

@ -28,11 +28,13 @@ namespace ErrorCodes
std::unique_ptr<ReadBufferFromFileBase> createReadBufferFromFileBase(
const std::string & filename,
const ReadSettings & settings,
size_t estimated_size,
std::optional<size_t> size,
int flags,
char * existing_memory,
size_t alignment)
{
size_t estimated_size = size.has_value() ? *size : 0;
if (!existing_memory
&& settings.local_fs_method == ReadMethod::mmap
&& settings.mmap_threshold

View File

@ -10,12 +10,13 @@ namespace DB
{
/** Create an object to read data from a file.
* estimated_size - the number of bytes to read
*
* @param size - the number of bytes to read
*/
std::unique_ptr<ReadBufferFromFileBase> createReadBufferFromFileBase(
const std::string & filename,
const ReadSettings & settings,
size_t estimated_size,
std::optional<size_t> size,
int flags_ = -1,
char * existing_memory = nullptr,
size_t alignment = 0);