Skip to content

Commit ae55510

Browse files
committed
defer closing of vector indices
1 parent 39cc91e commit ae55510

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## WIP
4+
5+
### Improved
6+
7+
- [Vector] Defer closing of vector indices until after async executor is
8+
shutdown to avoid segfault due to trying to save a closed index.
9+
310
## 0.9.21 (2025-03-18)
411

512
### Added
@@ -9,8 +16,9 @@
916
indexing is implemented with [usearch](https://github.com/unum-cloud/usearch).
1017
- [Vector] Corresponding `add-vec`, `remove-vec`, and `search-vec` functions to
1118
work with vector index. Similar to full-text search, vector search also
12-
support domain semantics to allow grouping of vectors into domains, see
13-
[doc](doc/vector.md).
19+
support domain semantics to allow grouping of vectors into domains.
20+
- [Doc] [Vector doc](doc/vector.md). **Note**, you may need to install some
21+
native dependencies on your system to load Datalevin: OpenMP and Vector Math.
1422
- [Datalog] New data type `:db.type/vec`, for which a vector index is
1523
automatically created for them to allow a query function `vec-neighbors` to
1624
return the datoms with neighboring vector values.

doc/install.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ For `dep.edn`, this is known to work:
5656
```
5757
Then `clj -A:jvm-base`
5858

59+
### Native Dependencies
60+
61+
For now, Datalevin requires some system libraries to be present, such as `libc`,
62+
`libomp`, and `libmvec`. These are easy to get:
63+
64+
* Linux needs [OpenMP](https://www.openmp.org/) and [Vectorized
65+
Math](https://sourceware.org/glibc/wiki/libmvec) from GCC, e.g. on
66+
Debian/Ubuntu, `apt-get install g++-12 gcc-12`
67+
68+
* MacOSX needs the same libraries as the above from Clang, e.g. `brew
69+
install libomp llvm`
70+
71+
Otherwise, Datalevin may fail to load and report
72+
`java.lang.UnsatisfiedLinkError`.
73+
5974
### Other JVM Languages
6075

6176
Datalevin can be used in other JVM languages than Clojure, such as Java, Scala, Kotlin,

doc/vector.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ MacOSX on both x86_64 and arm64 CPUs.
1717

1818
## Native Dependencies
1919

20-
The vector feature expects some native dependencies on your system.
20+
The vector feature expects some native dependencies on your system:
2121

22-
* Linux on arm64 and x86_64, needs OpenMP and Vectorized Math from GCC,
23-
e.g. on latest Debian/Ubuntu, `apt-get install g++-12 gcc-12`
22+
* Linux needs [OpenMP](https://www.openmp.org/) and [Vectorized
23+
Math](https://sourceware.org/glibc/wiki/libmvec) from GCC, e.g. on
24+
Debian/Ubuntu, `apt-get install g++-12 gcc-12`
2425

25-
* MacOSX on arm64 and x86_64, needs the same from Clang, e.g. `brew install libomp llvm`
26+
* MacOSX needs the same libraries as the above from Clang, e.g. `brew
27+
install libomp llvm`
28+
29+
Otherwise, Datalevin may fail to load and report
30+
`java.lang.UnsatisfiedLinkError`.
2631

2732
## Configurations
2833

script/compile-native-intel-mac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ echo $JAVA_HOME
1515
args_app=(
1616
"--verbose"
1717
"--native-compiler-path=/usr/local/opt/llvm/bin/clang"
18+
"--native-compiler-options='-I/usr/local/opt/llvm/include -L/usr/local/opt/llvm/lib'"
1819
"-jar" "target/main.uberjar.jar"
1920
"-H:Name=dtlv"
2021
)
2122

2223
args_test0=(
2324
"--verbose"
2425
"--native-compiler-path=/usr/local/opt/llvm/bin/clang"
26+
"--native-compiler-options='-I/usr/local/opt/llvm/include -L/usr/local/opt/llvm/lib'"
2527
"-jar" "target/test0.uberjar.jar"
2628
"-H:Name=dtlv-test0"
2729
)

src/datalevin/binding/cpp.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,15 @@
556556
(close-kv [this]
557557
(when-not (.isClosed env)
558558
(stop-scheduled-sync scheduled-sync)
559-
(doseq [idx (keep @l/vector-indices (u/list-files (.dir this)))]
560-
(v/close-vecs idx))
561559
(swap! l/lmdb-dirs disj (l/dir this))
562560
(when (zero? (count @l/lmdb-dirs))
563561
(a/shutdown-executor)
564562
(u/shutdown-query-thread-pool)
565563
(u/shutdown-scheduler))
566564
(.sync env 1)
567565
(.close env)
566+
(doseq [idx (keep @l/vector-indices (u/list-files (.dir this)))]
567+
(v/close-vecs idx))
568568
(when (@info :temp?) (u/delete-files (@info :dir)))
569569
nil))
570570

0 commit comments

Comments
 (0)