Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add util function fence_vector_index #521

Merged
merged 1 commit into from
Jul 8, 2024
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
34 changes: 34 additions & 0 deletions src/index/functions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
use super::utils::from_oid_to_handle;
use crate::error::check_client;
use crate::ipc::client;
use base::index::StatError;
use pgrx::pg_sys::Oid;

#[pgrx::pg_extern(volatile, strict, parallel_safe)]
fn _vectors_pgvectors_upgrade() {
if crate::bgworker::is_started() {
return;
}
let _ = std::fs::remove_dir_all("pg_vectors");
}

#[pgrx::pg_extern(volatile, strict, parallel_safe)]
fn _vectors_fence_vector_index(oid: Oid) {
let handle = from_oid_to_handle(oid);
let mut rpc = check_client(client());
loop {
pgrx::check_for_interrupts!();
match rpc.stat(handle) {
Ok(s) => {
if !s.indexing {
break;
}
}
Err(StatError::NotExist) => pgrx::error!("internal error"),
}
unsafe {
pgrx::pg_sys::WaitLatch(
pgrx::pg_sys::MyLatch,
(pgrx::pg_sys::WL_LATCH_SET
| pgrx::pg_sys::WL_TIMEOUT
| pgrx::pg_sys::WL_EXIT_ON_PM_DEATH) as _,
1000,
pgrx::pg_sys::WaitEventTimeout_WAIT_EVENT_PG_SLEEP,
);
pgrx::pg_sys::ResetLatch(pgrx::pg_sys::MyLatch);
}
}
}
3 changes: 3 additions & 0 deletions src/sql/finalize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ $$;
CREATE FUNCTION alter_vector_index("index" OID, "key" TEXT, "value" TEXT) RETURNS void
STRICT LANGUAGE c AS 'MODULE_PATHNAME', '_vectors_alter_vector_index_wrapper';

CREATE FUNCTION fence_vector_index(oid) RETURNS void
STRICT PARALLEL SAFE LANGUAGE c AS 'MODULE_PATHNAME', '_vectors_fence_vector_index_wrapper';

CREATE FUNCTION vector_dims(vector) RETURNS INT
STRICT PARALLEL SAFE LANGUAGE c AS 'MODULE_PATHNAME', '_vectors_vecf32_dims_wrapper';

Expand Down
Loading