From d85aeae3dcbd3ad4ed44ba03a45e2ed2b9bb9578 Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Tue, 20 Aug 2024 16:45:14 +0400 Subject: [PATCH] close index file fd only if index is not build via socket --- CMakeLists.txt | 3 ++- sql/updates/0.3.2--0.3.3.sql | 0 src/hnsw/build.c | 7 +++---- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 sql/updates/0.3.2--0.3.3.sql diff --git a/CMakeLists.txt b/CMakeLists.txt index 193161aef..9f82858e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.3) include(CheckSymbolExists) -set(LANTERN_VERSION 0.3.2) +set(LANTERN_VERSION 0.3.3) project( LanternDB @@ -263,6 +263,7 @@ endif() set (_update_files sql/updates/0.3.0--0.3.1.sql sql/updates/0.3.1--0.3.2.sql + sql/updates/0.3.2--0.3.3.sql ) # Generate version information for the binary diff --git a/sql/updates/0.3.2--0.3.3.sql b/sql/updates/0.3.2--0.3.3.sql new file mode 100644 index 000000000..e69de29bb diff --git a/src/hnsw/build.c b/src/hnsw/build.c index f28360db7..950d046da 100644 --- a/src/hnsw/build.c +++ b/src/hnsw/build.c @@ -552,6 +552,7 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_ if(buildstate->index_file_path) { index_file_fd = open(buildstate->index_file_path, O_RDONLY); + assert(index_file_fd > 0); } else if(buildstate->external) { external_index_receive_index_file(buildstate->external_socket, &num_added_vectors, &result_buf); } else { @@ -565,10 +566,9 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_ usearch_save(buildstate->usearch_index, tmp_index_file_path, &error); assert(error == NULL); index_file_fd = open(tmp_index_file_path, O_RDONLY); + assert(index_file_fd > 0); } - assert(index_file_fd > 0); - if(!buildstate->external) { num_added_vectors = usearch_size(buildstate->usearch_index, &error); } @@ -598,10 +598,9 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_ munmap_ret = munmap(result_buf, index_file_stat.st_size); assert(munmap_ret == 0); LDB_UNUSED(munmap_ret); + close(index_file_fd); } - close(index_file_fd); - if(buildstate->external) { buildstate->external_socket->close(buildstate->external_socket); }