diff --git a/dbms/src/Common/ProfileEvents.cpp b/dbms/src/Common/ProfileEvents.cpp index d045816873f..191325df1a8 100644 --- a/dbms/src/Common/ProfileEvents.cpp +++ b/dbms/src/Common/ProfileEvents.cpp @@ -7,10 +7,13 @@ M(SelectQuery) \ M(InsertQuery) \ M(FileOpen) \ + M(FileOpenFailed) \ M(Seek) \ M(ReadBufferFromFileDescriptorRead) \ + M(ReadBufferFromFileDescriptorReadFailed) \ M(ReadBufferFromFileDescriptorReadBytes) \ M(WriteBufferFromFileDescriptorWrite) \ + M(WriteBufferFromFileDescriptorWriteFailed) \ M(WriteBufferFromFileDescriptorWriteBytes) \ M(ReadBufferAIORead) \ M(ReadBufferAIOReadBytes) \ diff --git a/dbms/src/IO/ReadBufferAIO.cpp b/dbms/src/IO/ReadBufferAIO.cpp index 8610abd1df5..b531354a31e 100644 --- a/dbms/src/IO/ReadBufferAIO.cpp +++ b/dbms/src/IO/ReadBufferAIO.cpp @@ -12,6 +12,7 @@ namespace ProfileEvents { extern const Event FileOpen; + extern const Event FileOpenFailed; extern const Event ReadBufferAIORead; extern const Event ReadBufferAIOReadBytes; } @@ -49,6 +50,7 @@ ReadBufferAIO::ReadBufferAIO(const std::string & filename_, size_t buffer_size_, fd = ::open(filename.c_str(), open_flags); if (fd == -1) { + ProfileEvents::increment(ProfileEvents::FileOpenFailed); auto error_code = (errno == ENOENT) ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE; throwFromErrno("Cannot open file " + filename, error_code); } diff --git a/dbms/src/IO/ReadBufferFromFile.cpp b/dbms/src/IO/ReadBufferFromFile.cpp index db14405c5bf..eff1d8aebf2 100644 --- a/dbms/src/IO/ReadBufferFromFile.cpp +++ b/dbms/src/IO/ReadBufferFromFile.cpp @@ -8,6 +8,7 @@ namespace ProfileEvents { extern const Event FileOpen; + extern const Event FileOpenFailed; } @@ -41,11 +42,19 @@ ReadBufferFromFile::ReadBufferFromFile( fd = open(file_name.c_str(), flags == -1 ? O_RDONLY : flags); if (-1 == fd) + { + ProfileEvents::increment(ProfileEvents::FileOpenFailed); throwFromErrno("Cannot open file " + file_name, errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE); + } #ifdef __APPLE__ if (o_direct) + { if (fcntl(fd, F_NOCACHE, 1) == -1) + { + ProfileEvents::increment(ProfileEvents::FileOpenFailed); throwFromErrno("Cannot set F_NOCACHE on file " + file_name, ErrorCodes::CANNOT_OPEN_FILE); + } + } #endif } diff --git a/dbms/src/IO/ReadBufferFromFileDescriptor.cpp b/dbms/src/IO/ReadBufferFromFileDescriptor.cpp index 55198364fed..d7dd4135ae8 100644 --- a/dbms/src/IO/ReadBufferFromFileDescriptor.cpp +++ b/dbms/src/IO/ReadBufferFromFileDescriptor.cpp @@ -16,6 +16,7 @@ namespace ProfileEvents { extern const Event ReadBufferFromFileDescriptorRead; + extern const Event ReadBufferFromFileDescriptorReadFailed; extern const Event ReadBufferFromFileDescriptorReadBytes; extern const Event Seek; } @@ -63,7 +64,10 @@ bool ReadBufferFromFileDescriptor::nextImpl() break; if (-1 == res && errno != EINTR) + { + ProfileEvents::increment(ProfileEvents::ReadBufferFromFileDescriptorReadFailed); throwFromErrno("Cannot read from file " + getFileName(), ErrorCodes::CANNOT_READ_FROM_FILE_DESCRIPTOR); + } if (res > 0) bytes_read += res; diff --git a/dbms/src/IO/WriteBufferAIO.cpp b/dbms/src/IO/WriteBufferAIO.cpp index 105492af3b2..4c7fc6d417e 100644 --- a/dbms/src/IO/WriteBufferAIO.cpp +++ b/dbms/src/IO/WriteBufferAIO.cpp @@ -9,6 +9,7 @@ namespace ProfileEvents { extern const Event FileOpen; + extern const Event FileOpenFailed; extern const Event WriteBufferAIOWrite; extern const Event WriteBufferAIOWriteBytes; } @@ -58,6 +59,7 @@ WriteBufferAIO::WriteBufferAIO(const std::string & filename_, size_t buffer_size fd = ::open(filename.c_str(), open_flags, mode_); if (fd == -1) { + ProfileEvents::increment(ProfileEvents::FileOpenFailed); auto error_code = (errno == ENOENT) ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE; throwFromErrno("Cannot open file " + filename, error_code); } diff --git a/dbms/src/IO/WriteBufferFromFile.cpp b/dbms/src/IO/WriteBufferFromFile.cpp index c088c65d345..4c00337433c 100644 --- a/dbms/src/IO/WriteBufferFromFile.cpp +++ b/dbms/src/IO/WriteBufferFromFile.cpp @@ -10,6 +10,7 @@ namespace ProfileEvents { extern const Event FileOpen; + extern const Event FileOpenFailed; } namespace DB @@ -44,13 +45,21 @@ WriteBufferFromFile::WriteBufferFromFile( fd = open(file_name.c_str(), flags == -1 ? O_WRONLY | O_TRUNC | O_CREAT : flags, mode); if (-1 == fd) + { + ProfileEvents::increment(ProfileEvents::FileOpenFailed); throwFromErrno("Cannot open file " + file_name, errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE); + } #ifdef __APPLE__ if (o_direct) - if (fcntl(fd, F_NOCACHE, 1) == -1) + { + if (fcntl(fd, F_NOCACHE, 1) == -1) + { + ProfileEvents::increment(ProfileEvents::FileOpenFailed); throwFromErrno("Cannot set F_NOCACHE on file " + file_name, ErrorCodes::CANNOT_OPEN_FILE); - #endif + } + } +#endif } diff --git a/dbms/src/IO/WriteBufferFromFileDescriptor.cpp b/dbms/src/IO/WriteBufferFromFileDescriptor.cpp index 2bca68dd08e..2da52ffb91a 100644 --- a/dbms/src/IO/WriteBufferFromFileDescriptor.cpp +++ b/dbms/src/IO/WriteBufferFromFileDescriptor.cpp @@ -12,6 +12,7 @@ namespace ProfileEvents { extern const Event WriteBufferFromFileDescriptorWrite; + extern const Event WriteBufferFromFileDescriptorWriteFailed; extern const Event WriteBufferFromFileDescriptorWriteBytes; } @@ -49,7 +50,10 @@ void WriteBufferFromFileDescriptor::nextImpl() } if ((-1 == res || 0 == res) && errno != EINTR) + { + ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWriteFailed); throwFromErrno("Cannot write to file " + getFileName(), ErrorCodes::CANNOT_WRITE_TO_FILE_DESCRIPTOR); + } if (res > 0) bytes_written += res;