Skip to content

Commit 28a4bb6

Browse files
author
Denis Deyneko
committed
Add a version of the save graph without taking locks, when the caller guarantees no index update operations are sent to the index.
1 parent cae9852 commit 28a4bb6

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

include/index.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,16 @@ template <typename T, typename TagT = uint32_t, typename LabelT = uint32_t> clas
8787
DISKANN_DLLEXPORT ~Index();
8888

8989
// Saves graph, data, metadata and associated tags.
90+
// Takes exclusive locks on update, tags, consolidate_delete and delete. Some of these locks
91+
// are used in search and lookup methods which means those will be blocked until save completes.
9092
DISKANN_DLLEXPORT void save(const char *filename, bool compact_before_save = false);
9193

94+
// Same as above, but adds ability to skip btaining locks.
95+
// if no_lock is true, the function will not acquire any locks. This is useful for customers
96+
// that can guarantee no updates to the index will happen while saving. In this case, the query
97+
// part continue to work.
98+
DISKANN_DLLEXPORT void save(const char *filename, bool compact_before_save, bool no_lock);
99+
92100
// Load functions
93101
#ifdef EXEC_ENV_OLS
94102
DISKANN_DLLEXPORT void load(AlignedFileReader &reader, uint32_t num_threads, uint32_t search_l);

nuget/DiskANN-preview.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>DiskANN-preview.win-x64</id>
5-
<version>0.13.729.3-temp</version>
5+
<version>0.13.729.3</version>
66
<authors>DiskANN team</authors>
77
<owners>DiskANN team</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>

src/index.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,28 @@ _u64 Index<T, TagT, LabelT>::save_delete_list(const std::string& filename) const
411411
}
412412

413413
template <typename T, typename TagT, typename LabelT>
414-
void Index<T, TagT, LabelT>::save(const char *filename, bool compact_before_save)
414+
void Index<T, TagT, LabelT>::save(const char *filename, bool compact_before_save /* = false */)
415+
{
416+
save(filename, compact_before_save, false);
417+
}
418+
419+
template <typename T, typename TagT, typename LabelT>
420+
void Index<T, TagT, LabelT>::save(const char *filename, bool compact_before_save, bool no_lock)
415421
{
416422
diskann::Timer timer;
417423

418-
std::unique_lock<std::shared_timed_mutex> ul(_update_lock);
419-
std::unique_lock<std::shared_timed_mutex> cl(_consolidate_lock);
420-
std::unique_lock<std::shared_timed_mutex> tl(_tag_lock);
421-
std::unique_lock<std::shared_timed_mutex> dl(_delete_lock);
424+
std::unique_lock<std::shared_timed_mutex> ul(_update_lock, std::defer_lock);
425+
std::unique_lock<std::shared_timed_mutex> cl(_consolidate_lock, std::defer_lock);
426+
std::unique_lock<std::shared_timed_mutex> tl(_tag_lock, std::defer_lock);
427+
std::unique_lock<std::shared_timed_mutex> dl(_delete_lock, std::defer_lock);
428+
429+
if (!no_lock)
430+
{
431+
ul.lock();
432+
cl.lock();
433+
tl.lock();
434+
dl.lock();
435+
}
422436

423437
bool frozen_points_compacted = false;
424438
if (compact_before_save)

0 commit comments

Comments
 (0)