2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/createReadBufferFromFileBase.h>
|
|
|
|
#include <IO/ReadBufferFromFile.h>
|
2016-12-24 01:03:10 +00:00
|
|
|
#if !defined(__APPLE__) && !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;
|
2016-10-24 02:02:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 22:10:59 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2016-12-24 01:03:10 +00:00
|
|
|
#if defined(__APPLE__) || defined(__FreeBSD__)
|
2016-10-26 22:27:38 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int NOT_IMPLEMENTED;
|
2016-10-26 22:27:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-03-30 22:10:59 +00:00
|
|
|
|
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
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if ((aio_threshold == 0) || (estimated_size < aio_threshold))
|
|
|
|
{
|
|
|
|
ProfileEvents::increment(ProfileEvents::CreatedReadBufferOrdinary);
|
|
|
|
return std::make_unique<ReadBufferFromFile>(filename_, buffer_size_, flags_, existing_memory_, alignment);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-24 01:03:10 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(__FreeBSD__)
|
2017-04-01 07:20:54 +00:00
|
|
|
ProfileEvents::increment(ProfileEvents::CreatedReadBufferAIO);
|
|
|
|
return std::make_unique<ReadBufferAIO>(filename_, buffer_size_, flags_, existing_memory_);
|
2016-10-26 22:27:38 +00:00
|
|
|
#else
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception("AIO is not implemented yet on MacOS X", ErrorCodes::NOT_IMPLEMENTED);
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-03-30 22:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|