From e58385d5aca6bcc629f191ef2123843ff9dc33d5 Mon Sep 17 00:00:00 2001 From: Paul Wise Date: Mon, 1 Aug 2022 10:32:31 +0800 Subject: [PATCH] Add support for using AsyncFileReader on filesystems without O_DIRECT support. This fixes a test failure on the Linux tmpfs filesystem. Fixes: https://github.com/microsoft/SPTAG/issues/329 --- AnnService/inc/Helper/AsyncFileReader.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AnnService/inc/Helper/AsyncFileReader.h b/AnnService/inc/Helper/AsyncFileReader.h index d8cc593b..4e02a0c6 100644 --- a/AnnService/inc/Helper/AsyncFileReader.h +++ b/AnnService/inc/Helper/AsyncFileReader.h @@ -517,6 +517,10 @@ namespace SPTAG std::uint16_t threadPoolSize = 4) { m_fileHandle = open(filePath, O_RDONLY | O_DIRECT); + // O_DIRECT isn't supported on some filesystems + if (m_fileHandle <= 0 && errno == EINVAL) { + m_fileHandle = open(filePath, O_RDONLY); + } if (m_fileHandle <= 0) { LOG(LogLevel::LL_Error, "Failed to create file handle: %s: %s\n", filePath, strerror(errno)); return false;