2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/createWriteBufferFromFileBase.h>
|
|
|
|
#include <IO/WriteBufferFromFile.h>
|
2018-08-22 05:56:06 +00:00
|
|
|
#if defined(__linux__)
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBufferAIO.h>
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
2015-04-07 14:16:49 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
|
|
|
|
namespace ProfileEvents
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const Event CreatedWriteBufferOrdinary;
|
|
|
|
extern const Event CreatedWriteBufferAIO;
|
2016-10-24 02:02:37 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 14:16:49 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-08-22 05:56:06 +00:00
|
|
|
#if !defined(__linux__)
|
2016-10-26 22:27:38 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2018-08-22 05:56:06 +00:00
|
|
|
extern const int NOT_IMPLEMENTED;
|
2016-10-26 22:27:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-04 19:34:34 +00:00
|
|
|
std::unique_ptr<WriteBufferFromFileBase> createWriteBufferFromFileBase(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_, mode_t mode, char * existing_memory_,
|
|
|
|
size_t alignment)
|
2015-04-07 14:16:49 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if ((aio_threshold == 0) || (estimated_size < aio_threshold))
|
|
|
|
{
|
|
|
|
ProfileEvents::increment(ProfileEvents::CreatedWriteBufferOrdinary);
|
2018-09-04 19:34:34 +00:00
|
|
|
return std::make_unique<WriteBufferFromFile>(filename_, buffer_size_, flags_, mode, existing_memory_, alignment);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-22 05:56:06 +00:00
|
|
|
#if defined(__linux__)
|
2017-04-01 07:20:54 +00:00
|
|
|
ProfileEvents::increment(ProfileEvents::CreatedWriteBufferAIO);
|
2018-09-04 19:34:34 +00:00
|
|
|
return std::make_unique<WriteBufferAIO>(filename_, buffer_size_, flags_, mode, existing_memory_);
|
2016-10-26 22:27:38 +00:00
|
|
|
#else
|
2018-09-04 19:34:34 +00:00
|
|
|
throw Exception("AIO is not implemented yet on non-Linux OS", ErrorCodes::NOT_IMPLEMENTED);
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-04-07 14:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|