Skip to content

Commit ac01b73

Browse files
committed
refactor: unify strong typed object id
1 parent 887cc81 commit ac01b73

File tree

151 files changed

+1207
-1390
lines changed

Some content is hidden

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

151 files changed

+1207
-1390
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/secret/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
type SecretId = u32;
15+
type SecretId = risingwave_pb::id::SecretId;
1616

1717
mod secret_manager;
1818
pub use secret_manager::*;

src/common/secret/src/secret_manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl LocalSecretManager {
8181
let mut secret_guard = self.secrets.write();
8282
if secret_guard.insert(secret_id, secret).is_some() {
8383
tracing::error!(
84-
secret_id = secret_id,
84+
secret_id = %secret_id,
8585
"adding a secret but it already exists, overwriting it"
8686
);
8787
};
@@ -91,7 +91,7 @@ impl LocalSecretManager {
9191
let mut secret_guard = self.secrets.write();
9292
if secret_guard.insert(secret_id, secret).is_none() {
9393
tracing::error!(
94-
secret_id = secret_id,
94+
secret_id = %secret_id,
9595
"updating a secret but it does not exist, adding it"
9696
);
9797
}
@@ -146,15 +146,15 @@ impl LocalSecretManager {
146146
}
147147

148148
pub fn fill_secret(&self, secret_ref: PbSecretRef) -> SecretResult<String> {
149-
let secret_guard: RwLockReadGuard<'_, parking_lot::RawRwLock, HashMap<u32, Vec<u8>>> =
149+
let secret_guard: RwLockReadGuard<'_, parking_lot::RawRwLock, HashMap<SecretId, Vec<u8>>> =
150150
self.secrets.read();
151151
self.fill_secret_inner(secret_ref, &secret_guard)
152152
}
153153

154154
fn fill_secret_inner(
155155
&self,
156156
secret_ref: PbSecretRef,
157-
secret_guard: &RwLockReadGuard<'_, parking_lot::RawRwLock, HashMap<u32, Vec<u8>>>,
157+
secret_guard: &RwLockReadGuard<'_, parking_lot::RawRwLock, HashMap<SecretId, Vec<u8>>>,
158158
) -> SecretResult<String> {
159159
let secret_id = secret_ref.secret_id;
160160
let pb_secret_bytes = secret_guard

src/common/src/catalog/mod.rs

Lines changed: 3 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ pub use schema::{Field, FieldDisplay, FieldLike, Schema, test_utils as schema_te
3939
use crate::array::DataChunk;
4040
pub use crate::constants::hummock;
4141
use crate::error::BoxedError;
42-
pub use crate::id::{DatabaseId, SchemaId, TableId};
42+
pub use crate::id::{
43+
ConnectionId, DatabaseId, FunctionId, IndexId, ObjectId, SchemaId, SecretId, TableId,
44+
};
4345

4446
/// The global version of the catalog.
4547
pub type CatalogVersion = u64;
@@ -148,8 +150,6 @@ pub trait SysCatalogReader: Sync + Send + 'static {
148150

149151
pub type SysCatalogReaderRef = Arc<dyn SysCatalogReader>;
150152

151-
pub type ObjectId = u32;
152-
153153
#[derive(Clone, Debug, PartialEq, Default, Copy)]
154154
pub struct TableOption {
155155
pub retention_seconds: Option<u32>, // second
@@ -178,75 +178,6 @@ impl TableOption {
178178
}
179179
}
180180

181-
#[derive(Clone, Copy, Debug, Display, Default, Hash, PartialOrd, PartialEq, Eq)]
182-
#[display("{index_id}")]
183-
pub struct IndexId {
184-
pub index_id: u32,
185-
}
186-
187-
impl IndexId {
188-
pub const fn new(index_id: u32) -> Self {
189-
IndexId { index_id }
190-
}
191-
192-
/// Sometimes the id field is filled later, we use this value for better debugging.
193-
pub const fn placeholder() -> Self {
194-
IndexId {
195-
index_id: OBJECT_ID_PLACEHOLDER,
196-
}
197-
}
198-
199-
pub fn index_id(&self) -> u32 {
200-
self.index_id
201-
}
202-
}
203-
204-
impl From<u32> for IndexId {
205-
fn from(id: u32) -> Self {
206-
Self::new(id)
207-
}
208-
}
209-
impl From<IndexId> for u32 {
210-
fn from(id: IndexId) -> Self {
211-
id.index_id
212-
}
213-
}
214-
215-
#[derive(Clone, Copy, Debug, Display, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
216-
pub struct FunctionId(pub u32);
217-
218-
impl FunctionId {
219-
pub const fn new(id: u32) -> Self {
220-
FunctionId(id)
221-
}
222-
223-
pub const fn placeholder() -> Self {
224-
FunctionId(OBJECT_ID_PLACEHOLDER)
225-
}
226-
227-
pub fn function_id(&self) -> u32 {
228-
self.0
229-
}
230-
}
231-
232-
impl From<u32> for FunctionId {
233-
fn from(id: u32) -> Self {
234-
Self::new(id)
235-
}
236-
}
237-
238-
impl From<&u32> for FunctionId {
239-
fn from(id: &u32) -> Self {
240-
Self::new(*id)
241-
}
242-
}
243-
244-
impl From<FunctionId> for u32 {
245-
fn from(id: FunctionId) -> Self {
246-
id.0
247-
}
248-
}
249-
250181
#[derive(Clone, Copy, Debug, Display, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
251182
#[display("{user_id}")]
252183
pub struct UserId {
@@ -283,76 +214,6 @@ impl From<UserId> for u32 {
283214
}
284215
}
285216

286-
#[derive(Clone, Copy, Debug, Display, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
287-
pub struct ConnectionId(pub u32);
288-
289-
impl ConnectionId {
290-
pub const fn new(id: u32) -> Self {
291-
ConnectionId(id)
292-
}
293-
294-
pub const fn placeholder() -> Self {
295-
ConnectionId(OBJECT_ID_PLACEHOLDER)
296-
}
297-
298-
pub fn connection_id(&self) -> u32 {
299-
self.0
300-
}
301-
}
302-
303-
impl From<u32> for ConnectionId {
304-
fn from(id: u32) -> Self {
305-
Self::new(id)
306-
}
307-
}
308-
309-
impl From<&u32> for ConnectionId {
310-
fn from(id: &u32) -> Self {
311-
Self::new(*id)
312-
}
313-
}
314-
315-
impl From<ConnectionId> for u32 {
316-
fn from(id: ConnectionId) -> Self {
317-
id.0
318-
}
319-
}
320-
321-
#[derive(Clone, Copy, Debug, Display, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
322-
pub struct SecretId(pub u32);
323-
324-
impl SecretId {
325-
pub const fn new(id: u32) -> Self {
326-
SecretId(id)
327-
}
328-
329-
pub const fn placeholder() -> Self {
330-
SecretId(OBJECT_ID_PLACEHOLDER)
331-
}
332-
333-
pub fn secret_id(&self) -> u32 {
334-
self.0
335-
}
336-
}
337-
338-
impl From<u32> for SecretId {
339-
fn from(id: u32) -> Self {
340-
Self::new(id)
341-
}
342-
}
343-
344-
impl From<&u32> for SecretId {
345-
fn from(id: &u32) -> Self {
346-
Self::new(*id)
347-
}
348-
}
349-
350-
impl From<SecretId> for u32 {
351-
fn from(id: SecretId) -> Self {
352-
id.0
353-
}
354-
}
355-
356217
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
357218
pub enum ConflictBehavior {
358219
#[default]

src/connector/src/sink/catalog/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct SinkFormatDesc {
100100
pub options: BTreeMap<String, String>,
101101
pub secret_refs: BTreeMap<String, PbSecretRef>,
102102
pub key_encode: Option<SinkEncode>,
103-
pub connection_id: Option<u32>,
103+
pub connection_id: Option<ConnectionId>,
104104
}
105105

106106
/// TODO: consolidate with [`crate::source::SourceFormat`] and [`crate::parser::ProtocolProperties`].
@@ -384,7 +384,7 @@ impl SinkCatalog {
384384
properties: self.properties.clone(),
385385
sink_type: self.sink_type.to_proto() as i32,
386386
format_desc: self.format_desc.as_ref().map(|f| f.to_proto()),
387-
connection_id: self.connection_id.map(|id| id.into()),
387+
connection_id: self.connection_id,
388388
initialized_at_epoch: self.initialized_at_epoch.map(|e| e.0),
389389
created_at_epoch: self.created_at_epoch.map(|e| e.0),
390390
db_name: self.db_name.clone(),
@@ -496,7 +496,7 @@ impl From<PbSink> for SinkCatalog {
496496
owner: pb.owner.into(),
497497
sink_type: SinkType::from_proto(sink_type),
498498
format_desc,
499-
connection_id: pb.connection_id.map(ConnectionId),
499+
connection_id: pb.connection_id,
500500
created_at_epoch: pb.created_at_epoch.map(Epoch::from),
501501
initialized_at_epoch: pb.initialized_at_epoch.map(Epoch::from),
502502
db_name: pb.db_name,

src/connector/src/with_options.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::collections::{BTreeMap, HashMap};
1616
use std::marker::PhantomData;
1717
use std::time::Duration;
1818

19+
use risingwave_pb::id::SecretId;
1920
use risingwave_pb::secret::PbSecretRef;
2021

2122
use crate::error::ConnectorResult;
@@ -264,12 +265,12 @@ impl WithOptionsSecResolved {
264265
&mut self,
265266
update_alter_props: BTreeMap<String, String>,
266267
update_alter_secret_refs: BTreeMap<String, PbSecretRef>,
267-
) -> ConnectorResult<(Vec<u32>, Vec<u32>)> {
268+
) -> ConnectorResult<(Vec<SecretId>, Vec<SecretId>)> {
268269
let to_add_secret_dep = update_alter_secret_refs
269270
.values()
270271
.map(|new_rely_secret| new_rely_secret.secret_id)
271272
.collect();
272-
let mut to_remove_secret_dep: Vec<u32> = vec![];
273+
let mut to_remove_secret_dep: Vec<SecretId> = vec![];
273274

274275
// make sure the key in update_alter_props and update_alter_secret_refs not collide
275276
for key in update_alter_props.keys() {

src/frontend/src/binder/expr/function/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use risingwave_common::catalog::INFORMATION_SCHEMA_SCHEMA_NAME;
2424
use risingwave_common::types::{DataType, MapType};
2525
use risingwave_expr::aggregate::AggType;
2626
use risingwave_expr::window_function::WindowFuncKind;
27-
use risingwave_pb::user::grant_privilege::PbObject;
2827
use risingwave_sqlparser::ast::{
2928
self, Expr as AstExpr, Function, FunctionArg, FunctionArgExpr, FunctionArgList, Ident,
3029
OrderByExpr, Statement, Window,
@@ -178,12 +177,7 @@ impl Binder {
178177
// record the dependency upon the UDF
179178
referred_udfs.insert(func.id);
180179
self.check_privilege(
181-
ObjectCheckItem::new(
182-
func.owner,
183-
AclMode::Execute,
184-
func.name.clone(),
185-
PbObject::FunctionId(func.id.function_id()),
186-
),
180+
ObjectCheckItem::new(func.owner, AclMode::Execute, func.name.clone(), func.id),
187181
self.database_id,
188182
)?;
189183

@@ -232,12 +226,7 @@ impl Binder {
232226
// record the dependency upon the UDF
233227
referred_udfs.insert(func.id);
234228
self.check_privilege(
235-
ObjectCheckItem::new(
236-
func.owner,
237-
AclMode::Execute,
238-
func.name.clone(),
239-
PbObject::FunctionId(func.id.function_id()),
240-
),
229+
ObjectCheckItem::new(func.owner, AclMode::Execute, func.name.clone(), func.id),
241230
self.database_id,
242231
)?;
243232
Some(func.clone())

src/frontend/src/binder/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub use relation::{
6060
};
6161
// Re-export common types
6262
pub use risingwave_common::gap_fill::FillStrategy;
63+
use risingwave_common::id::ObjectId;
6364
pub use select::{BoundDistinct, BoundSelect};
6465
pub use set_expr::*;
6566
pub use statement::BoundStatement;
@@ -69,7 +70,7 @@ pub use values::BoundValues;
6970
use crate::catalog::catalog_service::CatalogReadGuard;
7071
use crate::catalog::root_catalog::SchemaPath;
7172
use crate::catalog::schema_catalog::SchemaCatalog;
72-
use crate::catalog::{CatalogResult, DatabaseId, TableId, ViewId};
73+
use crate::catalog::{CatalogResult, DatabaseId, ViewId};
7374
use crate::error::ErrorCode;
7475
use crate::session::{AuthContext, SessionImpl, StagingCatalogManager, TemporarySourceManager};
7576
use crate::user::user_service::UserInfoReadGuard;
@@ -127,7 +128,7 @@ pub struct Binder {
127128
shared_views: HashMap<ViewId, ShareId>,
128129

129130
/// The included relations while binding a query.
130-
included_relations: HashSet<TableId>,
131+
included_relations: HashSet<ObjectId>,
131132

132133
/// The included user-defined functions while binding a query.
133134
included_udfs: HashSet<FunctionId>,
@@ -317,7 +318,7 @@ impl Binder {
317318
/// After the plan is built, the referenced relations may be changed. We cannot rely on the
318319
/// collection result of plan, because we still need to record the dependencies that have been
319320
/// optimised away.
320-
pub fn included_relations(&self) -> &HashSet<TableId> {
321+
pub fn included_relations(&self) -> &HashSet<ObjectId> {
321322
&self.included_relations
322323
}
323324

0 commit comments

Comments
 (0)