2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/createReadBufferFromFileBase.h>
|
|
|
|
#include <IO/ReadBufferFromFile.h>
|
2019-02-07 15:08:45 +00:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__)
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBufferAIO.h>
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
2015-03-30 22:10:59 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
|
|
|
|
namespace ProfileEvents
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const Event CreatedReadBufferOrdinary;
|
|
|
|
extern const Event CreatedReadBufferAIO;
|
2019-08-29 15:48:00 +00:00
|
|
|
extern const Event CreatedReadBufferAIOFailed;
|
2016-10-24 02:02:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 22:10:59 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-06-25 04:29:09 +00:00
|
|
|
std::unique_ptr<ReadBufferFromFileBase> createReadBufferFromFileBase(const std::string & filename_, size_t estimated_size,
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t aio_threshold, size_t buffer_size_, int flags_, char * existing_memory_, size_t alignment)
|
2015-03-30 22:10:59 +00:00
|
|
|
{
|
2019-08-29 15:48:00 +00:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__)
|
|
|
|
if (aio_threshold && estimated_size >= aio_threshold)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-10-26 22:27:38 +00:00
|
|
|
#else
|
2019-08-29 15:48:00 +00:00
|
|
|
(void)aio_threshold;
|
|
|
|
(void)estimated_size;
|
2016-10-26 22:27:38 +00:00
|
|
|
#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);
|
2015-03-30 22:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|