@@ -782,6 +782,15 @@ static int s_test_s3_aws_xml_get_body_at_path(struct aws_allocator *allocator, v
782782 return AWS_OP_SUCCESS ;
783783}
784784
785+ static void s_s3_range_size_alignment (uint64_t * range_size ) {
786+ /* TODO: Round up the part size should be part of the memory pool impl. We should let memory pool to decide
787+ * what's the best round up for the part size. */
788+ if (* range_size > g_s3_optimal_range_size_alignment && * range_size % g_s3_optimal_range_size_alignment != 0 ) {
789+ /* Only apply alignment for sizes above minimum to avoid excessive rounding */
790+ * range_size = ((* range_size / g_s3_optimal_range_size_alignment ) + 1 ) * g_s3_optimal_range_size_alignment ;
791+ }
792+ }
793+
785794AWS_TEST_CASE (test_s3_calculate_client_optimal_range_size , s_test_s3_calculate_client_optimal_range_size )
786795static int s_test_s3_calculate_client_optimal_range_size (struct aws_allocator * allocator , void * ctx ) {
787796 (void )ctx ;
@@ -799,9 +808,9 @@ static int s_test_s3_calculate_client_optimal_range_size(struct aws_allocator *a
799808
800809 /* Expected: 1GB / 10 / 3 = 34.13MB -> rounded up to alignment boundary */
801810 uint64_t memory_constrained = memory_limit / max_connections / 3 ;
802- uint64_t aligned_size =
803- (( memory_constrained / g_s3_optimal_range_size_alignment ) + 1 ) * g_s3_optimal_range_size_alignment ;
804- uint64_t expected = ( aligned_size < g_default_part_size_fallback ) ? g_default_part_size_fallback : aligned_size ;
811+ s_s3_range_size_alignment ( & memory_constrained );
812+ uint64_t expected =
813+ ( memory_constrained < g_default_part_size_fallback ) ? g_default_part_size_fallback : memory_constrained ;
805814 ASSERT_UINT_EQUALS (expected , client_optimal_range_size );
806815 }
807816
@@ -841,9 +850,9 @@ static int s_test_s3_calculate_client_optimal_range_size(struct aws_allocator *a
841850
842851 /* Expected: 300MB / 10 / 3 = 10MB -> rounded up to alignment boundary */
843852 uint64_t memory_constrained = memory_limit / max_connections / 3 ;
844- uint64_t aligned_size =
845- (( memory_constrained / g_s3_optimal_range_size_alignment ) + 1 ) * g_s3_optimal_range_size_alignment ;
846- uint64_t expected = ( aligned_size < g_default_part_size_fallback ) ? g_default_part_size_fallback : aligned_size ;
853+ s_s3_range_size_alignment ( & memory_constrained );
854+ uint64_t expected =
855+ ( memory_constrained < g_default_part_size_fallback ) ? g_default_part_size_fallback : memory_constrained ;
847856 ASSERT_UINT_EQUALS (expected , client_optimal_range_size );
848857 }
849858
@@ -880,72 +889,73 @@ static int s_test_s3_calculate_request_optimal_range_size(struct aws_allocator *
880889
881890 /* Test 1: Estimated part size is larger than client size - use client size */
882891 {
883- uint64_t client_optimal_range_size = g_s3_optimal_range_size_alignment * 5 ; /* 160 MB (5 * 32MB) */
884- uint64_t estimated_part_size = MB_TO_BYTES (200 ); /* 200 MB */
892+ uint64_t client_optimal_range_size = MB_TO_BYTES ( 160 ) ; /* 160 MB (5 * 32MB) */
893+ uint64_t estimated_part_size = MB_TO_BYTES (200 ); /* 200 MB */
885894
886895 ASSERT_SUCCESS (aws_s3_calculate_request_optimal_range_size (
887896 client_optimal_range_size , estimated_part_size , & request_optimal_range_size ));
888897
889898 /* Expected: min(160MB, 200MB) = 160MB */
890- uint64_t expected = g_s3_optimal_range_size_alignment * 5 ; /* 160 MB (5 * 32MB) */
899+ uint64_t expected = client_optimal_range_size ; /* 160 MB (5 * 32MB) */
900+ s_s3_range_size_alignment (& expected );
891901 ASSERT_UINT_EQUALS (expected , request_optimal_range_size );
892902 }
893903
894904 /* Test 2: Estimated part size is smaller than client size - use estimated size */
895905 {
896- uint64_t client_optimal_range_size = g_s3_optimal_range_size_alignment * 8 ; /* 64 MB (8 * 8MB) */
897- uint64_t estimated_part_size = MB_TO_BYTES (50 ); /* 50 MB */
906+ uint64_t client_optimal_range_size = MB_TO_BYTES ( 64 ) ; /* 64 MB */
907+ uint64_t estimated_part_size = MB_TO_BYTES (50 ); /* 50 MB */
898908
899909 ASSERT_SUCCESS (aws_s3_calculate_request_optimal_range_size (
900910 client_optimal_range_size , estimated_part_size , & request_optimal_range_size ));
901911
902912 /* Expected: min(64MB, 50MB) = 50MB -> rounded up to alignment boundary */
903913 uint64_t smaller_size = estimated_part_size ; /* 50MB is smaller than 64MB */
904- uint64_t aligned_size =
905- ((smaller_size / g_s3_optimal_range_size_alignment ) + 1 ) * g_s3_optimal_range_size_alignment ;
906- uint64_t expected = (aligned_size < g_default_part_size_fallback ) ? g_default_part_size_fallback : aligned_size ;
914+ s_s3_range_size_alignment (& smaller_size );
915+ uint64_t expected = (smaller_size < g_default_part_size_fallback ) ? g_default_part_size_fallback : smaller_size ;
907916 ASSERT_UINT_EQUALS (expected , request_optimal_range_size );
908917 }
909918
910919 /* Test 3: Estimated part size is very small - apply minimum constraint */
911920 {
912- uint64_t client_optimal_range_size = g_s3_optimal_range_size_alignment * 5 ; /* 160 MB (5 * 32MB) */
913- uint64_t estimated_part_size = MB_TO_BYTES (1 ); /* 1 MB */
921+ uint64_t client_optimal_range_size = MB_TO_BYTES ( 160 ) ; /* 160 MB */
922+ uint64_t estimated_part_size = MB_TO_BYTES (1 ); /* 1 MB */
914923
915924 ASSERT_SUCCESS (aws_s3_calculate_request_optimal_range_size (
916925 client_optimal_range_size , estimated_part_size , & request_optimal_range_size ));
917926
918927 /* Expected: min(160MB, 1MB) = minimum size (minimum constraint) */
919928 uint64_t expected = g_default_part_size_fallback ; /* minimum size */
929+ s_s3_range_size_alignment (& expected );
920930 ASSERT_UINT_EQUALS (expected , request_optimal_range_size );
921931 }
922932
923933 /* Test 4: Zero estimated part size (unknown) - use client size */
924934 {
925- uint64_t client_optimal_range_size = g_s3_optimal_range_size_alignment * 5 ; /* 160 MB (5 * 32MB) */
926- uint64_t estimated_part_size = 0 ; /* 0 - unknown */
935+ uint64_t client_optimal_range_size = MB_TO_BYTES ( 160 ) ; /* 160 MB */
936+ uint64_t estimated_part_size = 0 ; /* 0 - unknown */
927937
928938 ASSERT_SUCCESS (aws_s3_calculate_request_optimal_range_size (
929939 client_optimal_range_size , estimated_part_size , & request_optimal_range_size ));
930940
931941 /* Expected: use client_optimal_range_size when estimated is unknown */
932- uint64_t expected = g_s3_optimal_range_size_alignment * 5 ; /* 160 MB (5 * 32MB) */
942+ uint64_t expected = client_optimal_range_size ; /* 160 MB (5 * 32MB) */
943+ s_s3_range_size_alignment (& expected );
933944 ASSERT_UINT_EQUALS (expected , request_optimal_range_size );
934945 }
935946
936947 /* Test 5: Alignment to buffer pool boundaries */
937948 {
938- uint64_t client_optimal_range_size = g_s3_optimal_range_size_alignment * 5 ; /* 40 MB (5 * 8MB) */
939- uint64_t estimated_part_size = MB_TO_BYTES (9 ); /* 9 MB */
949+ uint64_t client_optimal_range_size = MB_TO_BYTES ( 40 ) ; /* 40 MB (5 * 8MB) */
950+ uint64_t estimated_part_size = MB_TO_BYTES (9 ); /* 9 MB */
940951
941952 ASSERT_SUCCESS (aws_s3_calculate_request_optimal_range_size (
942953 client_optimal_range_size , estimated_part_size , & request_optimal_range_size ));
943954
944955 /* Expected: min(40MB, 9MB) = 9MB -> rounded up to alignment boundary */
945956 uint64_t smaller_size = estimated_part_size ; /* 9MB is smaller than 40MB */
946- uint64_t aligned_size =
947- ((smaller_size / g_s3_optimal_range_size_alignment ) + 1 ) * g_s3_optimal_range_size_alignment ;
948- uint64_t expected = (aligned_size < g_default_part_size_fallback ) ? g_default_part_size_fallback : aligned_size ;
957+ s_s3_range_size_alignment (& smaller_size );
958+ uint64_t expected = (smaller_size < g_default_part_size_fallback ) ? g_default_part_size_fallback : smaller_size ;
949959 ASSERT_UINT_EQUALS (expected , request_optimal_range_size );
950960 }
951961
0 commit comments