Skip to content

Commit f2fec11

Browse files
committed
If an error would appear before setting buildstate->index_file_fd = -1
in `InitBuildState` we would try to close that file descriptor (which would be 0) in `BuildIndexCleanup` function because of condition `if (buildstate->index_file_fd != -1)` and trying to close fd 0 was crashing the server. Now we will check if the fd is greater than 0 before closing it.
1 parent b3c6d92 commit f2fec11

16 files changed

+2
-20
lines changed

lantern_hnsw/src/hnsw/build.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static void BuildIndexCleanup(ldb_HnswBuildState *buildstate)
455455
buildstate->external_socket->close(buildstate->external_socket);
456456
}
457457

458-
if(buildstate->index_file_fd != -1) {
458+
if(buildstate->index_file_fd > 0) {
459459
// index_file_fd will only exist when we mmap the index file to memory
460460
if(!buildstate->external && buildstate->index_buffer) {
461461
int munmap_ret = munmap(buildstate->index_buffer, buildstate->index_buffer_size);

lantern_hnsw/test/expected/hnsw_correct.out

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ SELECT
2222
l2sq_dist(v, '{0,0}') AS dist
2323
FROM
2424
small_world;
25-
WARNING: this hook is experimental and can cause undefined behaviour
2625
-- Get the results with the index
2726
CREATE TEMP TABLE results_w_index AS
2827
SELECT

lantern_hnsw/test/expected/hnsw_cost_estimate.out

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ INFO: done init usearch index
6363
INFO: inserted 0 elements
6464
INFO: done saving 0 vectors
6565
SET _lantern_internal.is_test = true;
66-
WARNING: this hook is experimental and can cause undefined behaviour
6766
SELECT is_cost_estimate_within_error('EXPLAIN SELECT * FROM empty_table ORDER BY v <?> ''{1,2}'' LIMIT 10', 0.47);
6867
DEBUG: LANTERN - Query cost estimator
6968
DEBUG: LANTERN - ---------------------

lantern_hnsw/test/expected/hnsw_create.out

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ CREATE TABLE IF NOT EXISTS sift_base10k (
7171
\copy sift_base10k (v) FROM '/tmp/lantern/vector_datasets/siftsmall_base_arrays.csv' with csv;
7272
SET lantern.pgvector_compat=FALSE;
7373
CREATE INDEX hnsw_idx ON sift_base10k USING lantern_hnsw (v dist_l2sq_ops) WITH (M=2, ef_construction=10, ef=4, dim=128);
74-
WARNING: this hook is experimental and can cause undefined behaviour
7574
INFO: done init usearch index
7675
INFO: inserted 10000 elements
7776
INFO: done saving 10000 vectors

lantern_hnsw/test/expected/hnsw_create_expr.out

-6
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,10 @@ SET enable_seqscan = false;
6767
SET lantern.pgvector_compat=FALSE;
6868
-- This should success
6969
CREATE INDEX ON test_table USING lantern_hnsw (int_to_fixed_binary_real_array(id)) WITH (M=2);
70-
WARNING: this hook is experimental and can cause undefined behaviour
71-
WARNING: this hook is experimental and can cause undefined behaviour
72-
WARNING: this hook is experimental and can cause undefined behaviour
73-
WARNING: this hook is experimental and can cause undefined behaviour
74-
WARNING: this hook is experimental and can cause undefined behaviour
7570
INFO: done init usearch index
7671
INFO: inserted 3 elements
7772
INFO: done saving 3 vectors
7873
SELECT _lantern_internal.validate_index('test_table_int_to_fixed_binary_real_array_idx', false);
79-
WARNING: this hook is experimental and can cause undefined behaviour
8074
INFO: validate_index() start for test_table_int_to_fixed_binary_real_array_idx
8175
INFO: validate_index() done, no issues found.
8276
validate_index

lantern_hnsw/test/expected/hnsw_create_unlogged.out

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ CREATE UNLOGGED TABLE IF NOT EXISTS sift_base10k (
5151
\copy sift_base10k (v) FROM '/tmp/lantern/vector_datasets/siftsmall_base_arrays.csv' with csv;
5252
SET lantern.pgvector_compat=FALSE;
5353
CREATE INDEX hnsw_idx ON sift_base10k USING lantern_hnsw (v dist_l2sq_ops) WITH (M=2, ef_construction=10, ef=4, dim=128);
54-
WARNING: this hook is experimental and can cause undefined behaviour
5554
INFO: done init usearch index
5655
INFO: inserted 10000 elements
5756
INFO: done saving 10000 vectors

lantern_hnsw/test/expected/hnsw_dist_func.out

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ SET enable_seqscan=FALSE;
3838
SET lantern.pgvector_compat=FALSE;
3939
-- Verify that the distance functions work (check distances)
4040
SELECT ROUND(l2sq_dist(v, '{0,1,0}')::numeric, 2) FROM small_world_l2 ORDER BY v <?> '{0,1,0}';
41-
WARNING: this hook is experimental and can cause undefined behaviour
4241
round
4342
-------
4443
0.00

lantern_hnsw/test/expected/hnsw_extras.out

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ EXPLAIN (COSTS FALSE) SELECT id FROM sift_base1k order by v <-> :'v777' LIMIT 10
5151

5252
SET lantern.pgvector_compat=FALSE;
5353
EXPLAIN (COSTS FALSE) SELECT id FROM sift_base1k order by v <?> :'v777' LIMIT 10;
54-
WARNING: this hook is experimental and can cause undefined behaviour
5554
QUERY PLAN
5655
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5756
Limit

lantern_hnsw/test/expected/hnsw_index_from_file.out

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ SELECT * FROM ldb_get_indexes('sift_base1k');
5555
SET enable_seqscan=FALSE;
5656
SET lantern.pgvector_compat=FALSE;
5757
SELECT v AS v777 FROM sift_base1k WHERE id = 777 \gset
58-
WARNING: this hook is experimental and can cause undefined behaviour
5958
EXPLAIN (COSTS FALSE) SELECT ROUND(l2sq_dist(v, :'v777')::numeric, 2) FROM sift_base1k order by v <?> :'v777' LIMIT 10;
6059
QUERY PLAN
6160
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

lantern_hnsw/test/expected/hnsw_insert.out

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ SET enable_seqscan = false;
6868
SET lantern.pgvector_compat = false;
6969
-- Inserting vectors of the same dimension and nulls should work
7070
INSERT INTO small_world (v) VALUES ('{1,1,2}');
71-
WARNING: this hook is experimental and can cause undefined behaviour
7271
INSERT INTO small_world (v) VALUES (NULL);
7372
-- Inserting vectors of different dimension should fail
7473
\set ON_ERROR_STOP off

lantern_hnsw/test/expected/hnsw_insert_unlogged.out

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ SET enable_seqscan = false;
6868
SET lantern.pgvector_compat = false;
6969
-- Inserting vectors of the same dimension and nulls should work
7070
INSERT INTO small_world (v) VALUES ('{1,1,2}');
71-
WARNING: this hook is experimental and can cause undefined behaviour
7271
INSERT INTO small_world (v) VALUES (NULL);
7372
-- Inserting vectors of different dimension should fail
7473
\set ON_ERROR_STOP off

lantern_hnsw/test/expected/hnsw_operators.out

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ INFO: done saving 2 vectors
88
-- should rewrite operator
99
SET lantern.pgvector_compat=FALSE;
1010
SELECT * FROM op_test ORDER BY v <?> ARRAY[1,1,1];
11-
WARNING: this hook is experimental and can cause undefined behaviour
1211
v
1312
---------
1413
{1,1,1}

lantern_hnsw/test/expected/hnsw_select.out

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ SET enable_seqscan=FALSE;
4343
SET lantern.pgvector_compat=FALSE;
4444
-- Verify that basic queries still work given our query parser and planner hooks
4545
SELECT 0 + 1;
46-
WARNING: this hook is experimental and can cause undefined behaviour
4746
?column?
4847
----------
4948
1

lantern_hnsw/test/expected/hnsw_todo.out

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ INFO: done init usearch index
2222
INFO: inserted 8 elements
2323
INFO: done saving 8 vectors
2424
SELECT _lantern_internal.validate_index('small_world_l2_vector_idx', false);
25-
WARNING: this hook is experimental and can cause undefined behaviour
2625
INFO: validate_index() start for small_world_l2_vector_idx
2726
INFO: validate_index() done, no issues found.
2827
validate_index

lantern_hnsw/test/expected/hnsw_vector.out

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ RESET client_min_messages;
1010
SET lantern.pgvector_compat=FALSE;
1111
-- Verify basic functionality of pgvector
1212
SELECT '[1,2,3]'::vector;
13-
WARNING: this hook is experimental and can cause undefined behaviour
1413
vector
1514
---------
1615
[1,2,3]

lantern_hnsw/test/test_runner.sh

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function run_regression_test {
4646
-e 's! Average Peak Memory: [0-9]\{1,\}kB!!' \
4747
-e 's! time=[0-9]\+\.[0-9]\+\.\.[0-9]\+\.[0-9]\+!!' | \
4848
grep -v 'DEBUG: rehashing catalog cache id' | \
49+
grep -v 'WARNING: this hook is experimental and can cause undefined behaviour' | \
4950
grep -Gv '^ Planning Time:' | \
5051
grep -Gv '^ Execution Time:' | \
5152
# ignore lines in explain(format json) output that differ among pg12-pg16

0 commit comments

Comments
 (0)