Skip to content

Commit 3b78959

Browse files
committed
feat: add etag field to StageFile
1. add an `Option<String>` etag field to StageFile 2. updated proto-conv version 3. added parse_stage_file_v7 and parse_stage_file_latest test Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
1 parent 8337678 commit 3b78959

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ impl FromToProto for mt::StageFile {
657657
Some(c) => Some(mt::UserIdentity::from_pb(c)?),
658658
None => None,
659659
},
660+
etag: p.etag.clone(),
660661
})
661662
}
662663

@@ -672,6 +673,7 @@ impl FromToProto for mt::StageFile {
672673
Some(c) => Some(mt::UserIdentity::to_pb(c)?),
673674
None => None,
674675
},
676+
etag: self.etag.clone(),
675677
})
676678
}
677679
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const META_CHANGE_LOG: &[(u64, &str)] = &[
4242
7,
4343
"2022-09-09: Add: table.proto/{TableCopiedFileInfo,TableCopiedFileLock} type",
4444
),
45+
(8, "2022-09-16: Add: users.proto/StageFile::entity_tag"),
4546
];
4647

4748
pub const VER: u64 = META_CHANGE_LOG.last().unwrap().0;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
use std::collections::HashSet;
1616

17+
use common_datavalues::chrono::DateTime;
18+
use common_datavalues::chrono::NaiveDate;
19+
use common_datavalues::chrono::NaiveDateTime;
20+
use common_datavalues::chrono::NaiveTime;
21+
use common_datavalues::chrono::Utc;
1722
use common_meta_types as mt;
1823
use common_meta_types::UserInfo;
1924
use common_meta_types::UserPrivilegeType;
@@ -148,6 +153,22 @@ pub(crate) fn test_gcs_stage_info() -> mt::UserStageInfo {
148153
}
149154
}
150155

156+
pub(crate) fn test_stage_file() -> mt::StageFile {
157+
let dt = NaiveDateTime::new(
158+
NaiveDate::from_ymd(2022, 9, 16),
159+
NaiveTime::from_hms(0, 1, 2),
160+
);
161+
let user_id = mt::UserIdentity::new("datafuselabs", "datafuselabs.rs");
162+
mt::StageFile {
163+
path: "/path/to/stage".to_string(),
164+
size: 233,
165+
md5: None,
166+
last_modified: DateTime::from_utc(dt, Utc),
167+
creator: Some(user_id),
168+
etag: None,
169+
}
170+
}
171+
151172
#[test]
152173
fn test_user_pb_from_to() -> anyhow::Result<()> {
153174
let test_user_info = test_user_info();
@@ -253,6 +274,15 @@ fn test_build_user_pb_buf() -> anyhow::Result<()> {
253274
println!("{:?}", buf);
254275
}
255276

277+
// StageFile
278+
{
279+
let stage_file = test_stage_file();
280+
let p = stage_file.to_pb()?;
281+
let mut buf = vec![];
282+
common_protos::prost::Message::encode(&p, &mut buf)?;
283+
println!("{:?}", buf);
284+
}
285+
256286
// Stage on local file system
257287
{
258288
let fs_stage_info = test_fs_stage_info();

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
//! Test UserStageInfo
1616
17+
use common_datavalues::chrono::DateTime;
18+
use common_datavalues::chrono::NaiveDate;
19+
use common_datavalues::chrono::NaiveDateTime;
20+
use common_datavalues::chrono::NaiveTime;
21+
use common_datavalues::chrono::Utc;
1722
use common_meta_types as mt;
1823
use common_storage::StorageFsConfig;
1924
use common_storage::StorageGcsConfig;
@@ -24,6 +29,13 @@ use crate::common;
2429
use crate::user_proto_conv::test_fs_stage_info;
2530
use crate::user_proto_conv::test_gcs_stage_info;
2631
use crate::user_proto_conv::test_s3_stage_info;
32+
use crate::user_proto_conv::test_stage_file;
33+
34+
#[test]
35+
fn test_stage_file_latest() -> anyhow::Result<()> {
36+
common::test_pb_from_to("stage_file", test_stage_file())?;
37+
Ok(())
38+
}
2739

2840
#[test]
2941
fn test_user_stage_fs_latest() -> anyhow::Result<()> {
@@ -43,6 +55,36 @@ fn test_user_stage_gcs_latest() -> anyhow::Result<()> {
4355
Ok(())
4456
}
4557

58+
#[test]
59+
fn test_stage_file_v7() -> anyhow::Result<()> {
60+
// Encoded data of version 6 of StageFile:
61+
// Generated with common::test_pb_from_to.
62+
let stage_file_v7 = vec![
63+
10, 14, 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 116, 97, 103, 101, 16, 233, 1, 34,
64+
23, 50, 48, 50, 50, 45, 48, 57, 45, 49, 54, 32, 48, 48, 58, 48, 49, 58, 48, 50, 32, 85, 84,
65+
67, 42, 37, 10, 12, 100, 97, 116, 97, 102, 117, 115, 101, 108, 97, 98, 115, 18, 15, 100,
66+
97, 116, 97, 102, 117, 115, 101, 108, 97, 98, 115, 46, 114, 115, 160, 6, 8, 168, 6, 1, 160,
67+
6, 8, 168, 6, 1,
68+
];
69+
70+
let dt = NaiveDateTime::new(
71+
NaiveDate::from_ymd(2022, 9, 16),
72+
NaiveTime::from_hms(0, 1, 2),
73+
);
74+
let user_id = mt::UserIdentity::new("datafuselabs", "datafuselabs.rs");
75+
let want = mt::StageFile {
76+
path: "/path/to/stage".to_string(),
77+
size: 233,
78+
md5: None,
79+
last_modified: DateTime::from_utc(dt, Utc),
80+
creator: Some(user_id),
81+
..Default::default()
82+
};
83+
84+
common::test_load_old(func_name!(), stage_file_v7.as_slice(), want)?;
85+
Ok(())
86+
}
87+
4688
#[test]
4789
fn test_user_stage_fs_v6() -> anyhow::Result<()> {
4890
// Encoded data of version 6 of user_stage_fs:

src/meta/protos/proto/user.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,5 @@ message StageFile {
222222
optional string md5 = 3;
223223
string last_modified = 4;
224224
optional UserIdentity creator = 5;
225+
optional string etag = 6;
225226
}

src/meta/types/src/user_stage.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,12 @@ impl UserStageInfo {
258258
}
259259
}
260260

261-
#[derive(Default, Debug, Clone)]
261+
#[derive(Default, Debug, Clone, PartialEq, Eq)]
262262
pub struct StageFile {
263263
pub path: String,
264264
pub size: u64,
265265
pub md5: Option<String>,
266266
pub last_modified: DateTime<Utc>,
267267
pub creator: Option<UserIdentity>,
268+
pub etag: Option<String>,
268269
}

src/query/service/src/interpreters/interpreter_common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub async fn list_files_from_dal(
232232
.last_modified()
233233
.map_or(Utc::now(), |t| Utc.timestamp(t.unix_timestamp(), 0)),
234234
creator: None,
235+
etag: meta.etag().map(str::to_string),
235236
})
236237
.collect::<Vec<StageFile>>();
237238

0 commit comments

Comments
 (0)