Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share a single fileinfo for the hash index string overflow file #2895

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/include/storage/storage_structure/in_mem_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<common::page_idx_t>& pageCounter);
explicit InMemFile(
std::shared_ptr<common::FileInfo> fileInfo, std::atomic<common::page_idx_t>& pageCounter);

void addANewPage();

Expand All @@ -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<common::FileInfo> fileInfo;
std::shared_ptr<common::FileInfo> fileInfo;
std::unordered_map<common::page_idx_t, std::unique_ptr<InMemPage>> pages;
PageCursor nextPosToAppend;
std::atomic<common::page_idx_t>& pageCounter;
Expand Down
10 changes: 7 additions & 3 deletions src/storage/index/hash_index_builder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "storage/index/hash_index_builder.h"

#include <fcntl.h>

#include <cstring>

#include "common/type_utils.h"
Expand Down Expand Up @@ -263,10 +265,12 @@ PrimaryKeyIndexBuilder::PrimaryKeyIndexBuilder(
keyDataTypeID,
[&]<IndexHashable T>(T) {
if constexpr (std::is_same_v<T, ku_string_t>) {
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<InMemFile>(
StorageUtils::getOverflowFileName(fileHandle->getFileInfo()->path), vfs,
overflowPageCounter);
auto overflowFile =
std::make_unique<InMemFile>(overflowFileInfo, overflowPageCounter);
hashIndexBuilders.push_back(
std::make_unique<HashIndexBuilder<std::string_view, ku_string_t>>(
fileHandle, std::move(overflowFile), i, keyDataType));
Expand Down
13 changes: 2 additions & 11 deletions src/storage/storage_structure/in_mem_file.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include "storage/storage_structure/in_mem_file.h"

#include <fcntl.h>

#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"
Expand All @@ -15,11 +12,8 @@ using namespace kuzu::common;
namespace kuzu {
namespace storage {

InMemFile::InMemFile(
std::string filePath, common::VirtualFileSystem* vfs, std::atomic<page_idx_t>& 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> fileInfo, std::atomic<page_idx_t>& pageCounter)
: fileInfo{fileInfo}, nextPosToAppend(0, 0), pageCounter(pageCounter) {}

void InMemFile::addANewPage() {
page_idx_t newPageIdx = pageCounter.fetch_add(1);
Expand Down Expand Up @@ -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
Expand Down
Loading