2015-04-07 14:16:49 +00:00
|
|
|
#include <DB/IO/createWriteBufferFromFileBase.h>
|
|
|
|
#include <DB/IO/WriteBufferFromFile.h>
|
2016-12-24 01:03:10 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(__FreeBSD__)
|
2015-04-07 14:16:49 +00:00
|
|
|
#include <DB/IO/WriteBufferAIO.h>
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2015-04-16 12:06:05 +00:00
|
|
|
#include <DB/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
|
|
|
|
{
|
|
|
|
|
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-04-07 14:16:49 +00:00
|
|
|
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);
|
|
|
|
return new WriteBufferFromFile(filename_, buffer_size_, flags_, mode, 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::CreatedWriteBufferAIO);
|
|
|
|
return new WriteBufferAIO(filename_, buffer_size_, flags_, mode, 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-04-07 14:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|