Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ailego/buffer/vector_page_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,18 @@ VecBufferPool::VecBufferPool(const std::string &filename, bool writable) {
#endif
throw std::runtime_error("Failed to stat file: " + filename);
}
#if !defined(_MSC_VER)
// Atomic replacement between the two opens must not mix metadata from one
// file with pages from another. Windows CRT opens prevent deletion while
// either descriptor is live; POSIX needs an explicit identity check.
struct stat meta_st;
if (fstat(meta_fd_, &meta_st) < 0 || st.st_dev != meta_st.st_dev ||
st.st_ino != meta_st.st_ino) {
::close(fd_);
::close(meta_fd_);
throw std::runtime_error("Backing file changed while opening: " + filename);
}
#endif
file_size_ = st.st_size;
initial_file_size_ = file_size_;
#if defined(__linux__) && !defined(__ANDROID__)
Expand Down
8 changes: 6 additions & 2 deletions src/ailego/io/libaio_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ typedef int (*aio_getevents_fn)(io_context_t ctx, long min_nr, long nr,
class LibAioLoader {
public:
static LibAioLoader &Instance() {
static LibAioLoader instance;
return instance;
// Global thread pools may join workers during static destruction, after
// this loader would be destroyed. Their thread-local AIO contexts still
// need io_destroy(), so retain the loader and library until process exit.
// Individual AIO contexts must still be destroyed by their owners.
static LibAioLoader *const instance = new LibAioLoader();
return *instance;
}

// Load (or confirm already loaded) libaio. Returns true on success.
Expand Down
23 changes: 14 additions & 9 deletions src/core/algorithm/diskann/diskann_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ int DiskAnnContext::resize_fetch_sector_buffer(
}

int DiskAnnContext::init(ContextType type, uint32_t /*graph_degree*/,
uint32_t pq_chunk_num, uint32_t element_size) {
uint32_t pq_chunk_num, uint32_t element_size,
bool setup_io_context) {
if (!entity_ || element_size == 0) {
LOG_ERROR("Invalid DiskAnn context parameters");
return IndexError_InvalidArgument;
Expand Down Expand Up @@ -137,10 +138,12 @@ int DiskAnnContext::init(ContextType type, uint32_t /*graph_degree*/,
return IndexError_NoMemory;
}

ret = setup_io_ctx(io_ctx_);
if (ret != 0) {
LOG_ERROR("setup io ctx error, ret=%d", ret);
return ret;
if (setup_io_context) {
ret = setup_io_ctx(io_ctx_);
if (ret != 0) {
LOG_ERROR("setup io ctx error, ret=%d", ret);
return ret;
}
}
break;

Expand All @@ -150,10 +153,12 @@ int DiskAnnContext::init(ContextType type, uint32_t /*graph_degree*/,
return ret;
}

ret = setup_io_ctx(io_ctx_);
if (ret != 0) {
LOG_ERROR("setup fetch io ctx error, ret=%d", ret);
return ret;
if (setup_io_context) {
ret = setup_io_ctx(io_ctx_);
if (ret != 0) {
LOG_ERROR("setup fetch io ctx error, ret=%d", ret);
return ret;
}
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/core/algorithm/diskann/diskann_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DiskAnnContext : public IndexContext,
public:
//! Init
int init(ContextType type, uint32_t graph_degree, uint32_t pq_chunk_num,
uint32_t element_size);
uint32_t element_size, bool setup_io_context = true);

//! Update context, the context may be shared by different searcher/streamer
int update_context(ContextType type, const IndexMeta &meta,
Expand Down
Loading
Loading