Skip to content

Commit

Permalink
Save index file in postgres data dir (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 authored Jan 6, 2024
1 parent 0d14aa4 commit 9ac519e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ static void BuildIndex(
struct stat index_file_stat;
char *result_buf = NULL;
char *tmp_index_file_path = NULL;
const char *tmp_index_file_fmt_str = "/tmp/ldb-index-%d.bin";
// size of static name + max digits of uint32 (Oid) 10 + 1 for nullbyte and - 2 for %d format specifier
const uint32 tmp_index_file_char_cnt = strlen(tmp_index_file_fmt_str) + 9;
const char *tmp_index_file_fmt_str = "%s/ldb-index-%d.bin";
// parent_dir + max digits of uint32 (Oid) 10
const uint32 tmp_index_file_char_cnt = MAXPGPATH + strlen(tmp_index_file_fmt_str) + 10;
int index_file_fd;
int munmap_ret;
usearch_metadata_t metadata;
Expand Down Expand Up @@ -514,10 +514,11 @@ static void BuildIndex(
if(buildstate->index_file_path == NULL) {
// Save index into temporary file
// To later mmap it into memory
// Filename is /tmp/ldb-index-$relfilenode.bin
// The file will be removed in the end
tmp_index_file_path = palloc0(tmp_index_file_char_cnt);
snprintf(tmp_index_file_path, tmp_index_file_char_cnt, tmp_index_file_fmt_str, index->rd_rel->relfilenode);
// Create index file directory string: $pg_data_dir/ldb_indexes/index-$relfilenode.bin
snprintf(
tmp_index_file_path, tmp_index_file_char_cnt, tmp_index_file_fmt_str, DataDir, index->rd_rel->relfilenode);
usearch_save(buildstate->usearch_index, tmp_index_file_path, NULL, &error);
assert(error == NULL);
index_file_fd = open(tmp_index_file_path, O_RDONLY);
Expand Down

0 comments on commit 9ac519e

Please sign in to comment.