@@ -20,16 +20,17 @@ use crate::http::COMPONENT;
2020use crate :: http:: error:: CustomError ;
2121use crate :: http:: jwt:: json_web_token:: Identity ;
2222use crate :: http:: shared:: AppState ;
23- use crate :: state:: command:: EntryCommand ;
23+ use crate :: shard:: transmission:: frame:: ShardResponse ;
24+ use crate :: shard:: transmission:: message:: { ShardRequest , ShardRequestPayload } ;
2425use axum:: extract:: { Path , Query , State } ;
2526use axum:: http:: StatusCode ;
2627use axum:: routing:: delete;
2728use axum:: { Extension , Router , debug_handler} ;
2829use err_trail:: ErrContext ;
2930use iggy_common:: Identifier ;
30- use iggy_common:: IggyError ;
3131use iggy_common:: Validatable ;
3232use iggy_common:: delete_segments:: DeleteSegments ;
33+ use iggy_common:: sharding:: IggyNamespace ;
3334use send_wrapper:: SendWrapper ;
3435use std:: sync:: Arc ;
3536use tracing:: instrument;
@@ -57,44 +58,62 @@ async fn delete_segments(
5758 query. validate ( ) ?;
5859 let segments_count = query. segments_count ;
5960
60- let ( numeric_stream_id, numeric_topic_id) = state
61- . shard
62- . shard ( )
63- . resolve_topic_id ( & query. stream_id , & query. topic_id ) ?;
64- state. shard . shard ( ) . metadata . perm_delete_segments (
61+ let partition = state. shard . shard ( ) . resolve_partition_for_delete_segments (
6562 identity. user_id ,
66- numeric_stream_id,
67- numeric_topic_id,
63+ & query. stream_id ,
64+ & query. topic_id ,
65+ partition_id as usize ,
6866 ) ?;
69- {
70- let delete_future = SendWrapper :: new ( state. shard . shard ( ) . delete_segments_base (
71- numeric_stream_id,
72- numeric_topic_id,
73- partition_id as usize ,
74- segments_count,
75- ) ) ;
7667
77- delete_future. await . error ( |e : & IggyError | {
78- format ! (
79- "{COMPONENT} (error: {e}) - failed to delete segments for topic with ID: {topic_id} in stream with ID: {stream_id}"
80- )
81- } ) ?
82- } ;
68+ let namespace = IggyNamespace :: new (
69+ partition. stream_id ,
70+ partition. topic_id ,
71+ partition. partition_id ,
72+ ) ;
73+ let request = ShardRequest :: data_plane (
74+ namespace,
75+ ShardRequestPayload :: DeleteSegments { segments_count } ,
76+ ) ;
77+
78+ let delete_future = SendWrapper :: new ( state. shard . shard ( ) . send_to_data_plane ( request) ) ;
79+ match delete_future. await ? {
80+ ShardResponse :: DeleteSegments {
81+ deleted_segments,
82+ deleted_messages,
83+ } => {
84+ state
85+ . shard
86+ . shard ( )
87+ . metrics
88+ . decrement_segments ( deleted_segments as u32 ) ;
89+ state
90+ . shard
91+ . shard ( )
92+ . metrics
93+ . decrement_messages ( deleted_messages) ;
94+ }
95+ ShardResponse :: ErrorResponse ( err) => return Err ( err. into ( ) ) ,
96+ _ => unreachable ! ( "Expected DeleteSegments" ) ,
97+ }
8398
84- let command = EntryCommand :: DeleteSegments ( DeleteSegments {
99+ let command = DeleteSegments {
85100 stream_id : query. stream_id . clone ( ) ,
86101 topic_id : query. topic_id . clone ( ) ,
87102 partition_id : query. partition_id ,
88103 segments_count,
89- } ) ;
90- let state_future =
91- SendWrapper :: new ( state. shard . shard ( ) . state . apply ( identity. user_id , & command) ) ;
92-
93- state_future. await
94- . error ( |e : & IggyError | {
95- format ! (
96- "{COMPONENT} (error: {e}) - failed to apply delete segments, stream ID: {stream_id}, topic ID: {topic_id}"
97- )
98- } ) ?;
104+ } ;
105+ let entry_command = crate :: state:: command:: EntryCommand :: DeleteSegments ( command) ;
106+ let state_future = SendWrapper :: new (
107+ state
108+ . shard
109+ . shard ( )
110+ . state
111+ . apply ( identity. user_id , & entry_command) ,
112+ ) ;
113+ state_future. await . error ( |e : & iggy_common:: IggyError | {
114+ format ! (
115+ "{COMPONENT} (error: {e}) - failed to apply delete segments, stream ID: {stream_id}, topic ID: {topic_id}"
116+ )
117+ } ) ?;
99118 Ok ( StatusCode :: NO_CONTENT )
100119}
0 commit comments