ClickHouse/dbms/src/IO/createReadBufferFromFileBase.cpp

48 lines
1.5 KiB
C++
Raw Normal View History

#include <IO/createReadBufferFromFileBase.h>
#include <IO/ReadBufferFromFile.h>
2019-02-07 15:08:45 +00:00
#if defined(__linux__) || defined(__FreeBSD__)
#include <IO/ReadBufferAIO.h>
#endif
#include <Common/ProfileEvents.h>
namespace ProfileEvents
{
extern const Event CreatedReadBufferOrdinary;
extern const Event CreatedReadBufferAIO;
2019-08-29 15:48:00 +00:00
extern const Event CreatedReadBufferAIOFailed;
}
namespace DB
{
2016-06-25 04:29:09 +00:00
std::unique_ptr<ReadBufferFromFileBase> createReadBufferFromFileBase(const std::string & filename_, size_t estimated_size,
size_t aio_threshold, size_t buffer_size_, int flags_, char * existing_memory_, size_t alignment)
{
2019-08-29 15:48:00 +00:00
#if defined(__linux__) || defined(__FreeBSD__)
if (aio_threshold && estimated_size >= aio_threshold)
{
2019-08-29 15:48:00 +00:00
/// Attempt to open a file with O_DIRECT
try
{
auto res = std::make_unique<ReadBufferAIO>(filename_, buffer_size_, flags_, existing_memory_);
ProfileEvents::increment(ProfileEvents::CreatedReadBufferAIO);
return res;
}
catch (const ErrnoException &)
{
/// Fallback to cached IO if O_DIRECT is not supported.
ProfileEvents::increment(ProfileEvents::CreatedReadBufferAIOFailed);
}
}
#else
2019-08-29 15:48:00 +00:00
(void)aio_threshold;
(void)estimated_size;
#endif
2019-08-29 15:48:00 +00:00
ProfileEvents::increment(ProfileEvents::CreatedReadBufferOrdinary);
return std::make_unique<ReadBufferFromFile>(filename_, buffer_size_, flags_, existing_memory_, alignment);
}
}