Skip to content

Commit 4d34b45

Browse files
authored
fix: upgrade instructions (#203)
* fix: upgrade instructions Signed-off-by: usamoi <usamoi@outlook.com> * fix: rename scripts to install Signed-off-by: usamoi <usamoi@outlook.com> * fix: ipc error-handling Signed-off-by: usamoi <usamoi@outlook.com> * feat: soft version Signed-off-by: usamoi <usamoi@outlook.com> * chore: freebsd Signed-off-by: usamoi <usamoi@outlook.com> --------- Signed-off-by: usamoi <usamoi@outlook.com>
1 parent 78cc08b commit 4d34b45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6757
-309
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
sudo apt-get -y install ruby-dev libarchive-tools
100100
sudo gem install --no-document fpm
101101
mkdir ./artifacts
102-
cargo pgrx package
102+
./ci_package.sh
103103
if [[ "${{ matrix.arch }}" == "aarch64" ]]; then
104104
cargo build --target aarch64-unknown-linux-gnu --release --features "pg${{ matrix.version }}" --no-default-features
105105
mv ./target/aarch64-unknown-linux-gnu/release/libvectors.so ./target/release/vectors-pg${{ matrix.version }}/usr/lib/postgresql/${{ matrix.version }}/lib/vectors.so
@@ -116,6 +116,8 @@ jobs:
116116
--package ../vectors-pg${{ matrix.version }}_${{ github.event.inputs.version }}_${{ matrix.platform }}.deb \
117117
--architecture ${{ matrix.platform }} \
118118
.
119+
env:
120+
VERSION: ${{ matrix.version }}
119121
- name: Upload Release
120122
uses: actions/upload-release-asset@v1
121123
env:
@@ -167,9 +169,9 @@ jobs:
167169
strategy:
168170
matrix:
169171
include:
170-
- { version: 14, latest: false }
171-
- { version: 15, latest: false }
172-
- { version: 16, latest: true }
172+
- { version: 14 }
173+
- { version: 15 }
174+
- { version: 16 }
173175
steps:
174176
- name: Checkout
175177
uses: actions/checkout@v3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ docker run \
4949
--name pgvecto-rs-demo \
5050
-e POSTGRES_PASSWORD=mysecretpassword \
5151
-p 5432:5432 \
52-
-d tensorchord/pgvecto-rs:pg16-latest
52+
-d tensorchord/pgvecto-rs:pg16-v0.1.13
5353
```
5454

5555
## Development with envd

crates/c/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
println!("cargo:rerun-if-changed=src/c.h");
33
println!("cargo:rerun-if-changed=src/c.c");
44
cc::Build::new()
5-
.compiler("/usr/bin/clang-16")
5+
.compiler("clang-16")
66
.file("./src/c.c")
77
.opt_level(3)
88
.debug(true)

crates/c/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(linkage)]
2-
31
mod c;
42

53
#[allow(unused_imports)]

crates/service/src/prelude/error.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,29 @@ The given vector is invalid for input.
6262
ADVICE: Check if dimensions and scalar type of the vector is matched with the index.\
6363
")]
6464
Unmatched2,
65+
#[error("\
66+
IPC connection is closed unexpected.
67+
ADVICE: The error is raisen by background worker errors. \
68+
Please check the full PostgreSQL log to get more information.\
69+
")]
70+
Ipc,
71+
#[error("\
72+
The extension is upgraded. However, the index files is outdated.
73+
ADVICE: Please read `https://github.com/tensorchord/pgvecto.rs/blob/main/docs/upgrade.md`.\
74+
")]
75+
Upgrade,
6576
}
6677

67-
pub trait FriendlyErrorLike {
68-
fn friendly(self) -> !;
78+
pub trait FriendlyErrorLike: Sized {
79+
fn convert(self) -> FriendlyError;
80+
fn friendly(self) -> ! {
81+
panic!("pgvecto.rs: {}", self.convert());
82+
}
6983
}
7084

7185
impl FriendlyErrorLike for FriendlyError {
72-
fn friendly(self) -> ! {
73-
panic!("pgvecto.rs: {}", self);
86+
fn convert(self) -> FriendlyError {
87+
self
7488
}
7589
}
7690

crates/service/src/worker/metadata.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use serde::{Deserialize, Serialize};
2+
use std::error::Error;
3+
use std::path::Path;
4+
use thiserror::Error;
5+
6+
#[derive(Debug, Error)]
7+
pub enum MetadataError {
8+
#[error("Invalid version.")]
9+
InvalidVersion,
10+
}
11+
12+
#[derive(Debug, Clone, Serialize, Deserialize)]
13+
pub struct Metadata {
14+
#[serde(default)]
15+
pub version: Option<u64>,
16+
#[serde(default)]
17+
pub soft_version: Option<u64>,
18+
}
19+
20+
impl Metadata {
21+
const VERSION: u64 = 1;
22+
const SOFT_VERSION: u64 = 1;
23+
}
24+
25+
impl Metadata {
26+
pub fn write(path: impl AsRef<Path>) {
27+
let metadata = Metadata {
28+
version: Some(Self::VERSION),
29+
soft_version: Some(Self::SOFT_VERSION),
30+
};
31+
let contents = serde_json::to_string(&metadata).unwrap();
32+
std::fs::write(path, contents).unwrap();
33+
}
34+
pub fn read(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>> {
35+
use MetadataError::*;
36+
let contents = std::fs::read_to_string(path)?;
37+
let metadata = serde_json::from_str::<Metadata>(&contents)?;
38+
if Self::VERSION != metadata.version.ok_or(InvalidVersion)? {
39+
return Err(Box::new(InvalidVersion));
40+
}
41+
if Self::SOFT_VERSION <= metadata.soft_version.ok_or(InvalidVersion)? {
42+
return Err(Box::new(InvalidVersion));
43+
}
44+
Ok(())
45+
}
46+
}

crates/service/src/worker/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod instance;
2+
pub mod metadata;
23

34
use self::instance::Instance;
45
use crate::index::IndexOptions;
@@ -16,14 +17,6 @@ use std::collections::HashMap;
1617
use std::path::PathBuf;
1718
use std::sync::Arc;
1819

19-
fn magic() -> &'static [u8] {
20-
&[1, 4, 53, 23, 34, 92, 34, 23]
21-
}
22-
23-
fn check(data: &[u8]) -> bool {
24-
magic() == data
25-
}
26-
2720
pub struct Worker {
2821
path: PathBuf,
2922
protect: Mutex<WorkerProtect>,
@@ -33,7 +26,6 @@ pub struct Worker {
3326
impl Worker {
3427
pub fn create(path: PathBuf) -> Arc<Self> {
3528
std::fs::create_dir(&path).unwrap();
36-
std::fs::write(path.join("magic"), magic()).unwrap();
3729
std::fs::create_dir(path.join("indexes")).unwrap();
3830
let startup = FileAtomic::create(path.join("startup"), WorkerStartup::new());
3931
let indexes = HashMap::new();
@@ -42,17 +34,18 @@ impl Worker {
4234
});
4335
let protect = WorkerProtect { startup, indexes };
4436
sync_dir(&path);
37+
self::metadata::Metadata::write(path.join("metadata"));
4538
Arc::new(Worker {
4639
path,
4740
protect: Mutex::new(protect),
4841
view: ArcSwap::new(view),
4942
})
5043
}
44+
pub fn check(path: PathBuf) -> bool {
45+
self::metadata::Metadata::read(path.join("metadata")).is_ok()
46+
}
5147
pub fn open(path: PathBuf) -> Arc<Self> {
5248
let startup = FileAtomic::<WorkerStartup>::open(path.join("startup"));
53-
if !check(&std::fs::read(path.join("magic")).unwrap_or_default()) {
54-
panic!("Please delete the directory pg_vectors in Postgresql data folder. The files are created by older versions of postgresql or broken.");
55-
}
5649
clean(
5750
path.join("indexes"),
5851
startup.get().indexes.keys().map(|s| s.to_string()),

docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
We have prebuild image at [tensorchord/pgvecto-rs](https://hub.docker.com/r/tensorchord/pgvecto-rs). You can try it with
66

77
```
8-
docker run --name pgvecto-rs-demo -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d tensorchord/pgvecto-rs:pg16-latest
8+
docker run --name pgvecto-rs-demo -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d tensorchord/pgvecto-rs:pg16-v0.1.13
99
```
1010

1111
Connect to the database and enable the extension.

docs/upgrade.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Upgrade
2+
3+
## `The extension is upgraded. However, the index files is outdated.`
4+
5+
You may see this error if you upgrade the extension. On this condition, you should follow these steps:
6+
7+
* Delete the old index folder.
8+
9+
You can delete the folder with this command:
10+
11+
```shell
12+
rm -rf $(psql -U postgres -tAqX -c $'SELECT CONCAT(CURRENT_SETTING(\'data_directory\'), \'/pg_vectors\');')
13+
```
14+
15+
If you are using Docker, you can just delete `pg_vectors` folder under the volume directory too.
16+
17+
You need to restart PostgreSQL.
18+
19+
* Reindex.
20+
21+
You can list all indexes that needed to be reindexed with this command:
22+
23+
```sql
24+
SELECT
25+
I.oid AS indexrelid,
26+
I.relname AS indexname
27+
FROM pg_index X
28+
JOIN pg_class I ON I.oid = X.indexrelid
29+
JOIN pg_am A ON A.oid = I.relam
30+
WHERE A.amname = 'vectors';
31+
```
32+
33+
If you get the result like this:
34+
35+
```
36+
indexrelid | indexname
37+
------------+------------
38+
17988 | t_val_idx
39+
17989 | t_val_idx1
40+
17990 | t_val_idx2
41+
17991 | t_val_idx3
42+
```
43+
44+
You will reindex them with this SQL:
45+
46+
```sql
47+
REINDEX INDEX t_val_idx;
48+
REINDEX INDEX t_val_idx1;
49+
REINDEX INDEX t_val_idx2;
50+
REINDEX INDEX t_val_idx3;
51+
```

scripts/ci_package.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
cargo pgrx package

0 commit comments

Comments
 (0)