-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: usamoi <usamoi@outlook.com>
- Loading branch information
Showing
39 changed files
with
6,665 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::error::Error; | ||
use std::path::Path; | ||
use thiserror::Error; | ||
|
||
#[repr(u64)] | ||
enum Version { | ||
V1 = 1, | ||
} | ||
|
||
const VERSION: Version = Version::V1; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum MetadataError { | ||
#[error("Invalid version.")] | ||
InvalidVersion, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Metadata { | ||
pub version: Option<u64>, | ||
} | ||
|
||
impl Metadata { | ||
pub fn write(path: impl AsRef<Path>) { | ||
let metadata = Metadata { | ||
version: Some(VERSION as u64), | ||
}; | ||
let contents = serde_json::to_string(&metadata).unwrap(); | ||
std::fs::write(path, contents).unwrap(); | ||
} | ||
pub fn read(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>> { | ||
let contents = std::fs::read_to_string(path)?; | ||
let metadata = serde_json::from_str::<Metadata>(&contents)?; | ||
if metadata.version != Some(VERSION as u64) { | ||
return Err(Box::new(MetadataError::InvalidVersion)); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Upgrade | ||
|
||
## `The extension is upgraded. However, the index files is outdated.` | ||
|
||
You may see this error if you upgrade the extension. On this condition, you should follow these steps: | ||
|
||
* Delete the old index folder. | ||
|
||
You can delete the folder with this command: | ||
|
||
```shell | ||
rm -rf $(psql -U postgres -tAqX -c $'SELECT CONCAT(CURRENT_SETTING(\'data_directory\'), \'/pg_vectors\');') | ||
``` | ||
|
||
If you are using Docker, you can just delete `pg_vectors` folder under the volume directory too. | ||
|
||
You need to restart PostgreSQL. | ||
|
||
* Reindex. | ||
|
||
You can list all indexes that needed to be reindexed with this command: | ||
|
||
```sql | ||
SELECT | ||
I.oid AS indexrelid, | ||
I.relname AS indexname | ||
FROM pg_index X | ||
JOIN pg_class I ON I.oid = X.indexrelid | ||
JOIN pg_am A ON A.oid = I.relam | ||
WHERE A.amname = 'vectors'; | ||
``` | ||
|
||
If you get the result like this: | ||
|
||
``` | ||
indexrelid | indexname | ||
------------+------------ | ||
17988 | t_val_idx | ||
17989 | t_val_idx1 | ||
17990 | t_val_idx2 | ||
17991 | t_val_idx3 | ||
``` | ||
|
||
You will reindex them with this SQL: | ||
|
||
```sql | ||
REINDEX INDEX t_val_idx; | ||
REINDEX INDEX t_val_idx1; | ||
REINDEX INDEX t_val_idx2; | ||
REINDEX INDEX t_val_idx3; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
cargo pgrx package |
Oops, something went wrong.