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

fix: take MyDatabaseId into handle to resolve conflicts of OIDs in multidatabases #445

Merged
merged 1 commit into from
Mar 23, 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
29 changes: 19 additions & 10 deletions crates/base/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,44 @@ use std::fmt::Display;

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Handle {
newtype: u128,
tenant_id: u128,
cluster_id: u64,
database_id: u32,
index_id: u32,
}

impl Handle {
pub fn new(newtype: u128) -> Self {
Self { newtype }
}
pub fn as_u128(self) -> u128 {
self.newtype
pub fn new(tenant_id: u128, cluster_id: u64, database_id: u32, index_id: u32) -> Self {
Self {
tenant_id,
cluster_id,
database_id,
index_id,
}
}
}

impl Display for Handle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:x}", self.as_u128())
write!(
f,
"{:032x}{:016x}{:08x}{:08x}",
self.tenant_id, self.cluster_id, self.database_id, self.index_id
)
}
}

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Pointer {
newtype: u64,
value: u64,
}

impl Pointer {
pub fn new(value: u64) -> Self {
Self { newtype: value }
Self { value }
}
pub fn as_u64(self) -> u64 {
self.newtype
self.value
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/service/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Version {
}

impl Version {
const VERSION: u64 = 3;
const VERSION: u64 = 4;
const SOFT_VERSION: u64 = 0;
}

Expand Down
9 changes: 5 additions & 4 deletions src/index/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ pub fn from_oid_to_handle(oid: pgrx::pg_sys::Oid) -> Handle {
if SYSTEM_IDENTIFIER.get() == 0 {
SYSTEM_IDENTIFIER.set(unsafe { pgrx::pg_sys::GetSystemIdentifier() });
}
let a = 0u128;
let b = SYSTEM_IDENTIFIER.get() as u128;
let c = oid.as_u32() as u128;
Handle::new(a << 96 | b << 32 | c)
let tenant_id = 0_u128;
let cluster_id = SYSTEM_IDENTIFIER.get();
let database_id = unsafe { pgrx::pg_sys::MyDatabaseId.as_u32() };
let index_id = oid.as_u32();
Handle::new(tenant_id, cluster_id, database_id, index_id)
}

pub fn pointer_to_ctid(pointer: Pointer) -> pgrx::pg_sys::ItemPointerData {
Expand Down