Skip to content

Commit a11ee70

Browse files
fix for create and update stream validation
added validation - time partition cannot be part of custom partition
1 parent 03b3226 commit a11ee70

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

server/src/handlers/http/logstream.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ fn validate_custom_partition(custom_partition: &str) -> Result<(), CreateStreamE
246246
Ok(())
247247
}
248248

249+
fn validate_time_with_custom_partition(
250+
time_partition: &str,
251+
custom_partition: &str,
252+
) -> Result<(), CreateStreamError> {
253+
let custom_partition_list = custom_partition.split(',').collect::<Vec<&str>>();
254+
if custom_partition_list.contains(&time_partition) {
255+
return Err(CreateStreamError::Custom {
256+
msg: format!(
257+
"time partition {} cannot be set as custom partition",
258+
time_partition
259+
),
260+
status: StatusCode::BAD_REQUEST,
261+
});
262+
}
263+
Ok(())
264+
}
265+
249266
fn validate_static_schema(
250267
body: &Bytes,
251268
stream_name: &str,
@@ -338,6 +355,10 @@ async fn create_update_stream(
338355
validate_custom_partition(&custom_partition)?;
339356
}
340357

358+
if !time_partition.is_empty() && !custom_partition.is_empty() {
359+
validate_time_with_custom_partition(&time_partition, &custom_partition)?;
360+
}
361+
341362
let schema = validate_static_schema(
342363
body,
343364
stream_name,
@@ -741,6 +762,7 @@ pub async fn update_custom_partition_in_stream(
741762
custom_partition: &str,
742763
) -> Result<(), CreateStreamError> {
743764
let static_schema_flag = STREAM_INFO.get_static_schema_flag(&stream_name).unwrap();
765+
let time_partition = STREAM_INFO.get_time_partition(&stream_name).unwrap();
744766
if static_schema_flag.is_some() {
745767
let schema = STREAM_INFO.schema(&stream_name).unwrap();
746768

@@ -766,6 +788,18 @@ pub async fn update_custom_partition_in_stream(
766788
status: StatusCode::BAD_REQUEST,
767789
});
768790
}
791+
792+
if let Some(time_partition) = time_partition.clone() {
793+
if time_partition == *partition {
794+
return Err(CreateStreamError::Custom {
795+
msg: format!(
796+
"time partition {} cannot be set as custom partition",
797+
partition
798+
),
799+
status: StatusCode::BAD_REQUEST,
800+
});
801+
}
802+
}
769803
}
770804
}
771805
}

0 commit comments

Comments
 (0)