@@ -19,6 +19,7 @@ use kafka_protocol::{
19
19
} ,
20
20
protocol:: { buf:: ByteBuf , Decodable , Encodable , Message , StrBytes } ,
21
21
} ;
22
+ use rustls:: crypto:: hash:: Hash ;
22
23
use std:: { cmp:: max, sync:: Arc } ;
23
24
use std:: {
24
25
collections:: { hash_map:: Entry , HashMap } ,
@@ -1107,13 +1108,15 @@ impl Session {
1107
1108
mut req : messages:: OffsetCommitRequest ,
1108
1109
header : RequestHeader ,
1109
1110
) -> anyhow:: Result < messages:: OffsetCommitResponse > {
1110
- let collection_partitions = self
1111
- . fetch_collection_partitions ( req. topics . iter ( ) . map ( |topic| & topic. name ) )
1112
- . await ?
1113
- . into_iter ( )
1114
- . map ( |( topic_name, partitions) | {
1115
- self . encrypt_topic_name ( topic_name)
1116
- . map ( |encrypted_name| ( encrypted_name, partitions) )
1111
+ let collections = self
1112
+ . fetch_collections ( req. topics . iter ( ) . map ( |topic| & topic. name ) )
1113
+ . await ?;
1114
+
1115
+ let desired_topic_partitions = collections
1116
+ . iter ( )
1117
+ . map ( |( topic_name, collection) | {
1118
+ self . encrypt_topic_name ( topic_name. clone ( ) )
1119
+ . map ( |encrypted_name| ( encrypted_name, collection. partitions . len ( ) ) )
1117
1120
} )
1118
1121
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
1119
1122
@@ -1128,33 +1131,23 @@ impl Session {
1128
1131
. connect_to_group_coordinator ( req. group_id . as_str ( ) )
1129
1132
. await ?;
1130
1133
1131
- client. ensure_topics ( collection_partitions ) . await ?;
1134
+ client. ensure_topics ( desired_topic_partitions ) . await ?;
1132
1135
1133
1136
let mut resp = client. send_request ( req. clone ( ) , Some ( header) ) . await ?;
1134
1137
1135
- let auth = self
1136
- . auth
1137
- . as_mut ( )
1138
- . ok_or ( anyhow:: anyhow!( "Session not authenticated" ) ) ?;
1139
-
1140
- let flow_client = auth. flow_client ( & self . app ) . await ?. clone ( ) ;
1141
-
1142
- // Redeclare to drop mutability
1143
- let auth = self . auth . as_ref ( ) . unwrap ( ) ;
1144
-
1145
1138
for topic in resp. topics . iter_mut ( ) {
1146
1139
let encrypted_name = topic. name . clone ( ) ;
1147
1140
let decrypted_name = self . decrypt_topic_name ( topic. name . to_owned ( ) ) ?;
1148
1141
1149
- let collection_partitions = Collection :: new (
1150
- & self . app ,
1151
- auth ,
1152
- & flow_client . pg_client ( ) ,
1153
- decrypted_name . as_str ( ) ,
1154
- )
1155
- . await ?
1156
- . context ( format ! ( "unable to look up partitions for {:?}" , topic . name ) ) ?
1157
- . partitions ;
1142
+ let collection_partitions = & collections
1143
+ . iter ( )
1144
+ . find ( | ( topic_name , _ ) | topic_name == & decrypted_name )
1145
+ . context ( format ! (
1146
+ "unable to look up partitions for {:?}" ,
1147
+ decrypted_name
1148
+ ) ) ?
1149
+ . 1
1150
+ . partitions ;
1158
1151
1159
1152
for partition in & topic. partitions {
1160
1153
if let Some ( error) = partition. error_code . err ( ) {
@@ -1201,10 +1194,9 @@ impl Session {
1201
1194
. committed_offset ;
1202
1195
1203
1196
metrics:: gauge!( "dekaf_committed_offset" , "group_id" =>req. group_id. to_string( ) , "journal_name" =>journal_name) . set ( committed_offset as f64 ) ;
1197
+ tracing:: info!( topic_name = ?topic. name, partitions = ?topic. partitions, committed_offset, "Committed offset" ) ;
1204
1198
}
1205
1199
}
1206
-
1207
- tracing:: info!( topic_name = ?topic. name, partitions = ?topic. partitions, "Committed offset" ) ;
1208
1200
}
1209
1201
1210
1202
Ok ( resp)
@@ -1217,12 +1209,12 @@ impl Session {
1217
1209
header : RequestHeader ,
1218
1210
) -> anyhow:: Result < messages:: OffsetFetchResponse > {
1219
1211
let collection_partitions = if let Some ( topics) = & req. topics {
1220
- self . fetch_collection_partitions ( topics. iter ( ) . map ( |topic| & topic. name ) )
1212
+ self . fetch_collections ( topics. iter ( ) . map ( |topic| & topic. name ) )
1221
1213
. await ?
1222
1214
. into_iter ( )
1223
- . map ( |( topic_name, partitions ) | {
1215
+ . map ( |( topic_name, collection ) | {
1224
1216
self . encrypt_topic_name ( topic_name)
1225
- . map ( |encrypted_name| ( encrypted_name, partitions) )
1217
+ . map ( |encrypted_name| ( encrypted_name, collection . partitions . len ( ) ) )
1226
1218
} )
1227
1219
. collect :: < Result < Vec < _ > , _ > > ( ) ?
1228
1220
} else {
@@ -1350,10 +1342,10 @@ impl Session {
1350
1342
}
1351
1343
}
1352
1344
1353
- async fn fetch_collection_partitions (
1345
+ async fn fetch_collections (
1354
1346
& mut self ,
1355
1347
topics : impl IntoIterator < Item = & TopicName > ,
1356
- ) -> anyhow:: Result < Vec < ( TopicName , usize ) > > {
1348
+ ) -> anyhow:: Result < Vec < ( TopicName , Collection ) > > {
1357
1349
let auth = self
1358
1350
. auth
1359
1351
. as_mut ( )
@@ -1369,7 +1361,7 @@ impl Session {
1369
1361
let collection = Collection :: new ( app, auth, flow_client, topic. as_ref ( ) )
1370
1362
. await ?
1371
1363
. context ( format ! ( "unable to look up partitions for {:?}" , topic) ) ?;
1372
- Ok :: < ( TopicName , usize ) , anyhow:: Error > ( ( topic. clone ( ) , collection. partitions . len ( ) ) )
1364
+ Ok :: < ( TopicName , Collection ) , anyhow:: Error > ( ( topic. clone ( ) , collection) )
1373
1365
} ) )
1374
1366
. await
1375
1367
}
0 commit comments