Skip to content

Commit 432707d

Browse files
authored
ArcadeData#2915 fix: ensure Jvector HNSW graph file is closed and flushed to disk on database close (ArcadeData#2916)
* ArcadeData#2915 fix: ensure Jvector HNSW graph file is closed and flushed to disk on database close * fix: address PR ArcadeData#2916 review comments for HNSW graph persistence Improvements to code quality and maintainability: * Enhanced exception logging: Include full stack trace when closing graph file for better debugging. Changed from logging only the error message to passing the exception object to LogManager for complete context. * Refactored deleteDirectory() helper: Replaced manual recursive directory traversal with modern java.nio.file.Files.walk() API. This approach is more robust, efficient, and follows Java best practices for file tree operations. - Uses try-with-resources for proper resource management - Sorts in reverse order to delete files before directories - Provides better exception handling with IOException All existing tests continue to pass (22/22). Addresses review comments from PR ArcadeData#2916: - ArcadeData#2916 (comment) - ArcadeData#2916 (comment) * ArcadeData#2915 fix: ensure Jvector HNSW graph file is closed and flushed to disk on database close
1 parent 4cd8881 commit 432707d

2 files changed

Lines changed: 406 additions & 1 deletion

File tree

engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,12 @@ private LSMVectorIndexGraphFile discoverAndLoadGraphFile() {
491491
final DatabaseInternal database = getDatabase();
492492
final String expectedGraphFileName = mutable.getName() + "_" + LSMVectorIndexGraphFile.FILE_EXT;
493493

494+
LogManager.instance().log(this, Level.FINE,
495+
"Discovering graph file for index %s, looking for: %s", indexName, expectedGraphFileName);
496+
494497
// Look for ComponentFile in FileManager
495498
for (final ComponentFile file : database.getFileManager().getFiles()) {
496-
if (LSMVectorIndexGraphFile.FILE_EXT.equals(file.getFileExtension()) &&
499+
if (file != null && LSMVectorIndexGraphFile.FILE_EXT.equals(file.getFileExtension()) &&
497500
file.getComponentName().equals(expectedGraphFileName)) {
498501

499502
final int pageSize = file instanceof com.arcadedb.engine.PaginatedComponentFile ?
@@ -513,6 +516,8 @@ private LSMVectorIndexGraphFile discoverAndLoadGraphFile() {
513516
}
514517
}
515518

519+
LogManager.instance().log(this, Level.FINE,
520+
"No graph file found in FileManager for index %s. Graph will be built on first search.", indexName);
516521
return null;
517522
} catch (final Exception e) {
518523
LogManager.instance().log(this, Level.WARNING,
@@ -2129,6 +2134,16 @@ public void close() {
21292134
// to avoid path transformation issues during replication.
21302135

21312136
mutable.close();
2137+
2138+
// Close graph file to ensure graph data is flushed to disk
2139+
if (graphFile != null) {
2140+
try {
2141+
graphFile.close();
2142+
} catch (final Exception e) {
2143+
LogManager.instance().log(this, Level.WARNING,
2144+
"Error closing graph file for index %s", e, indexName);
2145+
}
2146+
}
21322147
} finally {
21332148
lock.writeLock().unlock();
21342149
}

0 commit comments

Comments
 (0)