Skip to content

Commit 8e70654

Browse files
committed
fix
1 parent ef96f5e commit 8e70654

File tree

14 files changed

+324
-297
lines changed

14 files changed

+324
-297
lines changed

src/meta/app/src/schema/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ pub use table::SetTableColumnMaskPolicyReq;
126126
pub use table::SetTableRowAccessPolicyReply;
127127
pub use table::SetTableRowAccessPolicyReq;
128128
pub use table::SnapshotRef;
129-
pub use table::SnapshotRefInfo;
130129
pub use table::SnapshotRefType;
131130
pub use table::SwapTableReply;
132131
pub use table::SwapTableReq;

src/meta/app/src/schema/table/mod.rs

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -194,41 +194,25 @@ pub struct TableMeta {
194194
pub struct SnapshotRef {
195195
/// After this timestamp, the reference becomes inactive.
196196
pub expire_at: Option<DateTime<Utc>>,
197-
198-
pub info: SnapshotRefInfo,
199-
}
200-
201-
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
202-
pub enum SnapshotRefInfo {
203-
Branch {
204-
/// The latest snapshot location that this reference currently points to.
205-
head: String,
206-
/// The earliest protected snapshot location on the snapshot chain.
207-
anchor: String,
208-
},
209-
Tag(String),
197+
/// The type of the reference.
198+
pub typ: SnapshotRefType,
199+
/// The location of the snapshot that this reference points to.
200+
pub loc: String,
210201
}
211202

212-
impl SnapshotRef {
213-
pub fn ref_type(&self) -> SnapshotRefType {
214-
match self.info {
215-
SnapshotRefInfo::Branch { .. } => SnapshotRefType::Branch,
216-
SnapshotRefInfo::Tag(_) => SnapshotRefType::Tag,
217-
}
218-
}
219-
220-
pub fn head(&self) -> &String {
221-
match &self.info {
222-
SnapshotRefInfo::Branch { head, .. } => head,
223-
SnapshotRefInfo::Tag(loc) => loc,
224-
}
225-
}
226-
}
227-
228-
#[derive(Clone, Debug, PartialEq, Eq)]
203+
#[derive(
204+
serde::Serialize,
205+
serde::Deserialize,
206+
Clone,
207+
Debug,
208+
Eq,
209+
PartialEq,
210+
num_derive::FromPrimitive,
211+
Hash,
212+
)]
229213
pub enum SnapshotRefType {
230-
Branch,
231-
Tag,
214+
Branch = 0,
215+
Tag = 1,
232216
}
233217

234218
impl From<&AstSnapshotRefType> for SnapshotRefType {
@@ -387,9 +371,9 @@ impl TableInfo {
387371
name, self.desc
388372
)));
389373
};
390-
let ref_type = table_ref.ref_type();
374+
let ref_type = &table_ref.typ;
391375
if let Some(typ) = typ {
392-
if &ref_type != typ {
376+
if ref_type != typ {
393377
return Err(ErrorCode::MismatchedReferenceType(format!(
394378
"'{}' is a {} reference, please use 'AT({} => {})' instead.",
395379
name, ref_type, ref_type, name,

src/meta/proto-conv/src/table_from_to_protobuf_impl.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -499,39 +499,22 @@ impl FromToProto for mt::SnapshotRef {
499499
}
500500
fn from_pb(p: pb::SnapshotRef) -> Result<Self, Incompatible> {
501501
reader_check_msg(p.ver, p.min_reader_ver)?;
502-
let expire_at = p.expire_at.map(DateTime::<Utc>::from_pb).transpose()?;
503-
let Some(info) = p.info else {
504-
return Err(Incompatible::new(
505-
"SnapshotRefInfo cannot be None".to_string(),
506-
));
507-
};
508-
let info = match info {
509-
pb::snapshot_ref::Info::Branch(branch) => mt::SnapshotRefInfo::Branch {
510-
head: branch.head,
511-
anchor: branch.anchor,
512-
},
513-
pb::snapshot_ref::Info::Tag(loc) => mt::SnapshotRefInfo::Tag(loc),
502+
let v = Self {
503+
expire_at: p.expire_at.map(DateTime::<Utc>::from_pb).transpose()?,
504+
typ: FromPrimitive::from_i32(p.typ)
505+
.ok_or_else(|| Incompatible::new(format!("invalid RefType: {}", p.typ)))?,
506+
loc: p.loc,
514507
};
515-
let v = Self { expire_at, info };
516508
Ok(v)
517509
}
518510

519511
fn to_pb(&self) -> Result<pb::SnapshotRef, Incompatible> {
520-
let expire_at = self.expire_at.map(|x| x.to_pb()).transpose()?;
521-
let info = match &self.info {
522-
mt::SnapshotRefInfo::Branch { head, anchor } => {
523-
pb::snapshot_ref::Info::Branch(pb::snapshot_ref::Branch {
524-
head: head.clone(),
525-
anchor: anchor.clone(),
526-
})
527-
}
528-
mt::SnapshotRefInfo::Tag(loc) => pb::snapshot_ref::Info::Tag(loc.clone()),
529-
};
530512
let p = pb::SnapshotRef {
531513
ver: VER,
532514
min_reader_ver: MIN_READER_VER,
533-
expire_at,
534-
info: Some(info),
515+
expire_at: self.expire_at.map(|x| x.to_pb()).transpose()?,
516+
typ: self.typ.clone() as i32,
517+
loc: self.loc.clone(),
535518
};
536519
Ok(p)
537520
}

src/meta/proto-conv/tests/it/v161_snapshot_ref.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use chrono::Utc;
1919
use databend_common_expression as ce;
2020
use databend_common_meta_app::schema as mt;
2121
use databend_common_meta_app::schema::SnapshotRef;
22+
use databend_common_meta_app::schema::SnapshotRefType;
2223
use fastrace::func_name;
2324
use maplit::btreemap;
2425
use maplit::btreeset;
@@ -41,10 +42,10 @@ fn test_decode_v161_snapshot_ref() -> anyhow::Result<()> {
4142
10, 7, 160, 6, 161, 1, 168, 6, 24, 64, 0, 162, 1, 23, 50, 48, 49, 52, 45, 49, 49, 45, 50,
4243
56, 32, 49, 50, 58, 48, 48, 58, 48, 57, 32, 85, 84, 67, 170, 1, 23, 50, 48, 49, 52, 45, 49,
4344
49, 45, 50, 57, 32, 49, 50, 58, 48, 48, 58, 49, 48, 32, 85, 84, 67, 186, 1, 7, 160, 6, 161,
44-
1, 168, 6, 24, 226, 1, 1, 1, 170, 2, 52, 10, 8, 98, 114, 97, 110, 99, 104, 95, 49, 18, 40,
45+
1, 168, 6, 24, 226, 1, 1, 1, 170, 2, 47, 10, 8, 98, 114, 97, 110, 99, 104, 95, 49, 18, 35,
4546
10, 23, 50, 48, 49, 52, 45, 49, 49, 45, 50, 56, 32, 49, 50, 58, 48, 48, 58, 48, 57, 32, 85,
46-
84, 67, 18, 6, 10, 1, 97, 18, 1, 98, 160, 6, 161, 1, 168, 6, 24, 170, 2, 19, 10, 5, 116,
47-
97, 103, 95, 49, 18, 10, 26, 1, 99, 160, 6, 161, 1, 168, 6, 24, 160, 6, 161, 1, 168, 6, 24,
47+
84, 67, 26, 1, 97, 160, 6, 161, 1, 168, 6, 24, 170, 2, 21, 10, 5, 116, 97, 103, 95, 49, 18,
48+
12, 16, 1, 26, 1, 99, 160, 6, 161, 1, 168, 6, 24, 160, 6, 161, 1, 168, 6, 24,
4849
];
4950

5051
let want = || mt::TableMeta {
@@ -73,14 +74,13 @@ fn test_decode_v161_snapshot_ref() -> anyhow::Result<()> {
7374
refs: btreemap! {
7475
"branch_1".to_string() => SnapshotRef {
7576
expire_at: Some(Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap()),
76-
info: mt::SnapshotRefInfo::Branch {
77-
head: "a".to_string(),
78-
anchor: "b".to_string(),
79-
},
77+
typ: SnapshotRefType::Branch,
78+
loc: "a".to_string(),
8079
},
8180
"tag_1".to_string() => SnapshotRef {
8281
expire_at: None,
83-
info: mt::SnapshotRefInfo::Tag("c".to_string()),
82+
typ: SnapshotRefType::Tag,
83+
loc: "c".to_string(),
8484
}
8585
},
8686
};

src/meta/protos/proto/table.proto

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,14 @@ message SnapshotRef {
149149
uint64 ver = 100;
150150
uint64 min_reader_ver = 101;
151151

152-
optional string expire_at = 1;
153-
154-
message Branch {
155-
string head = 1;
156-
string anchor = 2;
152+
enum RefType {
153+
Branch = 0;
154+
Tag = 1;
157155
}
158156

159-
oneof info {
160-
Branch branch = 2;
161-
string tag = 3;
162-
}
157+
optional string expire_at = 1;
158+
RefType typ = 2;
159+
string loc = 3;
163160
}
164161

165162
message RowAccessPolicyColumnMap {

0 commit comments

Comments
 (0)