@@ -55,11 +55,14 @@ impl SimpleBatchCoordinator {
5555 }
5656
5757 /// Retrieves the directory of the given topic/partition.
58- fn partition_index_file_from_topic_dir (
59- topic_dir : & mut PathBuf ,
60- partition : u64 ,
61- ) -> & mut PathBuf {
62- topic_dir. push ( format ! ( "{:0>20}.index" , partition. to_string( ) ) ) ;
58+ fn partition_index_file_from_topic_dir < ' a > (
59+ topic_dir : & ' a mut PathBuf ,
60+ partition : & ' a [ u8 ] ,
61+ ) -> & ' a mut PathBuf {
62+ topic_dir. push ( format ! (
63+ "{:0>20}.index" ,
64+ partition. iter( ) . map( |b| b. to_string( ) ) . collect:: <String >( )
65+ ) ) ;
6366
6467 ( topic_dir) as _
6568 }
@@ -105,7 +108,7 @@ impl CommitFile for SimpleBatchCoordinator {
105108
106109 let current_partition_file = Self :: partition_index_file_from_topic_dir (
107110 & mut current_topic_dir,
108- batch. topic_id_partition . 1 ,
111+ & batch. topic_id_partition . 1 ,
109112 ) ;
110113
111114 let file = Self :: open_or_create_file ( current_partition_file) ;
@@ -162,7 +165,7 @@ impl FindBatches for SimpleBatchCoordinator {
162165
163166 let current_partition_file = Self :: partition_index_file_from_topic_dir (
164167 & mut current_topic_dir,
165- request. topic_id_partition . 1 ,
168+ & request. topic_id_partition . 1 ,
166169 ) ;
167170
168171 let file = Self :: open_file ( current_partition_file) ;
@@ -383,10 +386,10 @@ mod tests {
383386 #[ test]
384387 fn test_partition_index_file_from_topic_dir ( ) {
385388 let mut topic_dir = PathBuf :: from ( "test_topic" ) ;
386- let partition = 42 ;
389+ let partition = Vec :: from ( & 42_u8 . to_be_bytes ( ) ) ;
387390
388391 let result =
389- SimpleBatchCoordinator :: partition_index_file_from_topic_dir ( & mut topic_dir, partition) ;
392+ SimpleBatchCoordinator :: partition_index_file_from_topic_dir ( & mut topic_dir, & partition) ;
390393
391394 assert_eq ! (
392395 result. to_str( ) . expect( "" ) ,
@@ -461,11 +464,11 @@ mod tests {
461464 let whole_dir = temp_dir. clone ( ) ;
462465
463466 let topic = "test_topic" . to_string ( ) ;
464- let partition = 1 ;
467+ let partition = Vec :: from ( & 1_u8 . to_be_bytes ( ) ) ;
465468
466469 let object_key = Uuid :: new_v4 ( ) . into_bytes ( ) ;
467470 let batches = vec ! [ CommitBatchRequest {
468- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
471+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
469472 byte_offset: 0 ,
470473 size: 100 ,
471474 request_id: 1 ,
@@ -479,9 +482,10 @@ mod tests {
479482 last_sequence: 0 ,
480483 } ] ;
481484
482- let expected_file_path = temp_dir
483- . join ( & topic)
484- . join ( format ! ( "{:0>20}.index" , partition) ) ;
485+ let expected_file_path = temp_dir. join ( & topic) . join ( format ! (
486+ "{:0>20}.index" ,
487+ partition. iter( ) . map( |b| b. to_string( ) ) . collect:: <String >( )
488+ ) ) ;
485489
486490 // File shouldn't exist yet
487491 assert ! ( !expected_file_path. exists( ) ) ;
@@ -518,15 +522,15 @@ mod tests {
518522 let _ = std:: fs:: create_dir ( index_path) ;
519523
520524 let topic = "test_topic" . to_string ( ) ;
521- let partition = 1 ;
525+ let partition = Vec :: from ( & 1_u8 . to_be_bytes ( ) ) ;
522526
523527 // First, create an index file with some data
524528 let object_key = Uuid :: new_v4 ( ) . into_bytes ( ) ;
525529 let offset = 0 ;
526530 let size = 100 ;
527531
528532 let batches = vec ! [ CommitBatchRequest {
529- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
533+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
530534 byte_offset: offset,
531535 size,
532536 request_id: 1 ,
@@ -582,7 +586,7 @@ mod tests {
582586 let _ = std:: fs:: create_dir ( & index_path) ;
583587
584588 let topic = "test_topic" . to_string ( ) ;
585- let partition = 1 ;
589+ let partition = Vec :: from ( & 1_u8 . to_be_bytes ( ) ) ;
586590
587591 // First, create an index file with some data
588592 let object_key = Uuid :: new_v4 ( ) . into_bytes ( ) ;
@@ -591,7 +595,7 @@ mod tests {
591595 let size = 100 ;
592596
593597 let batches = vec ! [ CommitBatchRequest {
594- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
598+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
595599 byte_offset: offset,
596600 size,
597601 request_id: 1 ,
@@ -608,7 +612,7 @@ mod tests {
608612 coordinator. commit_file ( object_key, 1 , 100 , batches) . await ;
609613
610614 let batches = vec ! [ CommitBatchRequest {
611- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
615+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
612616 byte_offset: 1 ,
613617 size,
614618 request_id: 1 ,
@@ -627,7 +631,7 @@ mod tests {
627631 . await ;
628632
629633 let batches = vec ! [ CommitBatchRequest {
630- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
634+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
631635 byte_offset: 1 ,
632636 size,
633637 request_id: 2 ,
@@ -649,15 +653,18 @@ mod tests {
649653
650654 index_path. push ( & topic) ;
651655
652- index_path. push ( format ! ( "{:0>20}.index" , partition. to_string( ) ) ) ;
656+ index_path. push ( format ! (
657+ "{:0>20}.index" ,
658+ partition. iter( ) . map( |b| b. to_string( ) ) . collect:: <String >( )
659+ ) ) ;
653660
654661 let data = std:: fs:: read ( index_path) ?;
655662
656663 assert_eq ! ( data. len( ) , Index :: packed_size( ) * 3 ) ;
657664
658665 // Now try to find the batch
659666 let find_requests = vec ! [ FindBatchRequest {
660- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
667+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
661668 offset,
662669 max_partition_fetch_bytes: 1024 ,
663670 } ] ;
@@ -675,7 +682,7 @@ mod tests {
675682 assert_eq ! ( batch. metadata. byte_size, size) ;
676683
677684 let find_requests = vec ! [ FindBatchRequest {
678- topic_id_partition: TopicIdPartition ( topic. clone( ) , partition) ,
685+ topic_id_partition: TopicIdPartition ( topic. clone( ) , partition. clone ( ) ) ,
679686 offset: 1 ,
680687 max_partition_fetch_bytes: 1024 ,
681688 } ] ;
@@ -706,7 +713,10 @@ mod tests {
706713 let coordinator = SimpleBatchCoordinator :: new ( temp_dir. to_str ( ) . expect ( "" ) . to_string ( ) ) ;
707714
708715 let find_requests = vec ! [ FindBatchRequest {
709- topic_id_partition: TopicIdPartition ( "nonexistent_topic" . to_string( ) , 1 ) ,
716+ topic_id_partition: TopicIdPartition (
717+ "nonexistent_topic" . to_string( ) ,
718+ Vec :: from( & 1_u8 . to_be_bytes( ) ) ,
719+ ) ,
710720 offset: 0 ,
711721 max_partition_fetch_bytes: 1024 ,
712722 } ] ;
0 commit comments