diff --git a/crates/base/src/search.rs b/crates/base/src/search.rs index e622f4500..d2e5f90f1 100644 --- a/crates/base/src/search.rs +++ b/crates/base/src/search.rs @@ -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 } } diff --git a/crates/service/src/version.rs b/crates/service/src/version.rs index cc72dc313..84fda5494 100644 --- a/crates/service/src/version.rs +++ b/crates/service/src/version.rs @@ -18,7 +18,7 @@ pub struct Version { } impl Version { - const VERSION: u64 = 3; + const VERSION: u64 = 4; const SOFT_VERSION: u64 = 0; } diff --git a/src/index/utils.rs b/src/index/utils.rs index 2af00fcfa..81d6860e5 100644 --- a/src/index/utils.rs +++ b/src/index/utils.rs @@ -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 {