diff --git a/src/include/storage/storage_structure/in_mem_file.h b/src/include/storage/storage_structure/in_mem_file.h index a5713ccfca..e6945c1bfc 100644 --- a/src/include/storage/storage_structure/in_mem_file.h +++ b/src/include/storage/storage_structure/in_mem_file.h @@ -18,8 +18,8 @@ namespace storage { // InMemFile holds a collection of in-memory page in the memory. class InMemFile { public: - explicit InMemFile(std::string filePath, common::VirtualFileSystem* vfs, - std::atomic& pageCounter); + explicit InMemFile( + std::shared_ptr fileInfo, std::atomic& pageCounter); void addANewPage(); @@ -45,8 +45,7 @@ class InMemFile { private: static const uint64_t END_OF_PAGE = common::BufferPoolConstants::PAGE_4KB_SIZE - sizeof(common::page_idx_t); - std::string filePath; - std::unique_ptr fileInfo; + std::shared_ptr fileInfo; std::unordered_map> pages; PageCursor nextPosToAppend; std::atomic& pageCounter; diff --git a/src/storage/index/hash_index_builder.cpp b/src/storage/index/hash_index_builder.cpp index 5b9c4417a7..e3614566df 100644 --- a/src/storage/index/hash_index_builder.cpp +++ b/src/storage/index/hash_index_builder.cpp @@ -1,5 +1,7 @@ #include "storage/index/hash_index_builder.h" +#include + #include #include "common/type_utils.h" @@ -263,10 +265,12 @@ PrimaryKeyIndexBuilder::PrimaryKeyIndexBuilder( keyDataTypeID, [&](T) { if constexpr (std::is_same_v) { + auto overflowFileInfo = std::shared_ptr(vfs->openFile( + StorageUtils::getOverflowFileName(fileHandle->getFileInfo()->path), + O_CREAT | O_WRONLY)); for (auto i = 0u; i < NUM_HASH_INDEXES; i++) { - auto overflowFile = std::make_unique( - StorageUtils::getOverflowFileName(fileHandle->getFileInfo()->path), vfs, - overflowPageCounter); + auto overflowFile = + std::make_unique(overflowFileInfo, overflowPageCounter); hashIndexBuilders.push_back( std::make_unique>( fileHandle, std::move(overflowFile), i, keyDataType)); diff --git a/src/storage/storage_structure/in_mem_file.cpp b/src/storage/storage_structure/in_mem_file.cpp index bfbc02e627..9d4c1d2107 100644 --- a/src/storage/storage_structure/in_mem_file.cpp +++ b/src/storage/storage_structure/in_mem_file.cpp @@ -1,11 +1,8 @@ #include "storage/storage_structure/in_mem_file.h" -#include - #include "common/constants.h" #include "common/exception/copy.h" #include "common/exception/message.h" -#include "common/file_system/virtual_file_system.h" #include "common/type_utils.h" #include "common/types/ku_string.h" #include "common/types/types.h" @@ -15,11 +12,8 @@ using namespace kuzu::common; namespace kuzu { namespace storage { -InMemFile::InMemFile( - std::string filePath, common::VirtualFileSystem* vfs, std::atomic& pageCounter) - : filePath{std::move(filePath)}, nextPosToAppend(0, 0), pageCounter(pageCounter) { - fileInfo = vfs->openFile(this->filePath, O_CREAT | O_WRONLY); -} +InMemFile::InMemFile(std::shared_ptr fileInfo, std::atomic& pageCounter) + : fileInfo{fileInfo}, nextPosToAppend(0, 0), pageCounter(pageCounter) {} void InMemFile::addANewPage() { page_idx_t newPageIdx = pageCounter.fetch_add(1); @@ -122,9 +116,6 @@ bool InMemFile::equals(std::string_view keyToLookup, const ku_string_t& keyInEnt } void InMemFile::flush() { - if (filePath.empty()) { - throw CopyException("InMemPages: Empty filename"); - } for (auto& [pageIndex, page] : pages) { // actual page index is stored inside of the InMemPage and does not correspond to the index // in the vector