@@ -367,7 +367,7 @@ FIXTURE_TEST(test_upload_compacted_segments, reupload_fixture) {
367
367
FIXTURE_TEST (test_upload_compacted_segments_concat, reupload_fixture) {
368
368
std::vector<segment_desc> segments = {
369
369
{manifest_ntp, model::offset (0 ), model::term_id (1 ), 1000 , 2 },
370
- {manifest_ntp, model::offset (1000 ), model::term_id (4 ), 10 , 2 },
370
+ {manifest_ntp, model::offset (1000 ), model::term_id (1 ), 10 , 2 },
371
371
};
372
372
373
373
initialize (segments);
@@ -385,7 +385,7 @@ FIXTURE_TEST(test_upload_compacted_segments_concat, reupload_fixture) {
385
385
386
386
auto manifest = verify_manifest_request (*part);
387
387
verify_segment_request (" 0-1-v1.log" , manifest);
388
- verify_segment_request (" 1000-4 -v1.log" , manifest);
388
+ verify_segment_request (" 1000-1 -v1.log" , manifest);
389
389
390
390
BOOST_REQUIRE (part->archival_meta_stm ());
391
391
const cloud_storage::partition_manifest& stm_manifest
@@ -414,7 +414,7 @@ FIXTURE_TEST(test_upload_compacted_segments_concat, reupload_fixture) {
414
414
BOOST_REQUIRE_EQUAL (replaced[1 ].base_offset , model::offset{1000 });
415
415
416
416
verify_concat_segment_request (
417
- {" 0-1-v1.log" , " 1000-4 -v1.log" }, part->archival_meta_stm ()->manifest ());
417
+ {" 0-1-v1.log" , " 1000-1 -v1.log" }, part->archival_meta_stm ()->manifest ());
418
418
}
419
419
420
420
FIXTURE_TEST (
@@ -746,10 +746,10 @@ FIXTURE_TEST(test_upload_limit, reupload_fixture) {
746
746
// NOTE: different terms so compaction leaves one segment each.
747
747
std::vector<segment_desc> segments = {
748
748
{manifest_ntp, model::offset (0 ), model::term_id (1 ), 10 , 2 },
749
- {manifest_ntp, model::offset (10 ), model::term_id (2 ), 10 , 2 },
750
- {manifest_ntp, model::offset (20 ), model::term_id (3 ), 10 , 2 },
751
- {manifest_ntp, model::offset (30 ), model::term_id (4 ), 10 , 2 },
752
- {manifest_ntp, model::offset (40 ), model::term_id (5 ), 10 , 2 },
749
+ {manifest_ntp, model::offset (10 ), model::term_id (1 ), 10 , 2 },
750
+ {manifest_ntp, model::offset (20 ), model::term_id (1 ), 10 , 2 },
751
+ {manifest_ntp, model::offset (30 ), model::term_id (1 ), 10 , 2 },
752
+ {manifest_ntp, model::offset (40 ), model::term_id (1 ), 10 , 2 },
753
753
};
754
754
755
755
initialize (segments);
@@ -768,9 +768,9 @@ FIXTURE_TEST(test_upload_limit, reupload_fixture) {
768
768
get_targets ().find (manifest_url)->second .content );
769
769
770
770
verify_segment_request (" 0-1-v1.log" , manifest);
771
- verify_segment_request (" 10-2 -v1.log" , manifest);
772
- verify_segment_request (" 20-3 -v1.log" , manifest);
773
- verify_segment_request (" 30-4 -v1.log" , manifest);
771
+ verify_segment_request (" 10-1 -v1.log" , manifest);
772
+ verify_segment_request (" 20-1 -v1.log" , manifest);
773
+ verify_segment_request (" 30-1 -v1.log" , manifest);
774
774
775
775
BOOST_REQUIRE (part->archival_meta_stm ());
776
776
const cloud_storage::partition_manifest& stm_manifest
@@ -790,7 +790,7 @@ FIXTURE_TEST(test_upload_limit, reupload_fixture) {
790
790
create_segment (
791
791
{manifest_ntp,
792
792
last_segment->offsets ().get_committed_offset () + model::offset{1 },
793
- model::term_id{6 },
793
+ model::term_id{2 },
794
794
10 });
795
795
}
796
796
@@ -805,13 +805,13 @@ FIXTURE_TEST(test_upload_limit, reupload_fixture) {
805
805
BOOST_REQUIRE_EQUAL (get_requests ().size (), 9 );
806
806
807
807
verify_segment_request (
808
- " 40-5 -v1.log" , part->archival_meta_stm ()->manifest ());
808
+ " 40-1 -v1.log" , part->archival_meta_stm ()->manifest ());
809
809
verify_segment_request (
810
- " 50-6 -v1.log" , part->archival_meta_stm ()->manifest ());
810
+ " 50-2 -v1.log" , part->archival_meta_stm ()->manifest ());
811
811
verify_segment_request (
812
- " 65-6 -v1.log" , part->archival_meta_stm ()->manifest ());
812
+ " 65-2 -v1.log" , part->archival_meta_stm ()->manifest ());
813
813
verify_segment_request (
814
- " 85-6 -v1.log" , part->archival_meta_stm ()->manifest ());
814
+ " 85-2 -v1.log" , part->archival_meta_stm ()->manifest ());
815
815
816
816
BOOST_REQUIRE_EQUAL (
817
817
stm_manifest.get_last_uploaded_compacted_offset (), model::offset{});
@@ -828,9 +828,9 @@ FIXTURE_TEST(test_upload_limit, reupload_fixture) {
828
828
verify_concat_segment_request (
829
829
{
830
830
" 0-1-v1.log" ,
831
- " 10-2 -v1.log" ,
832
- " 20-3 -v1.log" ,
833
- " 30-4 -v1.log" ,
831
+ " 10-1 -v1.log" ,
832
+ " 20-1 -v1.log" ,
833
+ " 30-1 -v1.log" ,
834
834
},
835
835
part->archival_meta_stm ()->manifest ());
836
836
@@ -841,3 +841,74 @@ FIXTURE_TEST(test_upload_limit, reupload_fixture) {
841
841
replaced = stm_manifest.replaced_segments ();
842
842
BOOST_REQUIRE_EQUAL (replaced.size (), 4 );
843
843
}
844
+
845
+ FIXTURE_TEST (test_upload_compacted_segments_cross_term, reupload_fixture) {
846
+ std::vector<segment_desc> segments = {
847
+ {manifest_ntp, model::offset (0 ), model::term_id (1 ), 1000 , 2 },
848
+ {manifest_ntp, model::offset (1000 ), model::term_id (4 ), 10 , 2 },
849
+ };
850
+
851
+ initialize (segments);
852
+ auto action = ss::defer ([this ] { archiver->stop ().get (); });
853
+
854
+ auto part = app.partition_manager .local ().get (manifest_ntp);
855
+ listen ();
856
+
857
+ // Upload two non compacted segments, no segment is compacted yet.
858
+ archival::ntp_archiver::batch_result expected{{2 , 0 , 0 }, {0 , 0 , 0 }};
859
+ upload_and_verify (archiver.value (), expected);
860
+
861
+ // Two segments, two indices, one manifest
862
+ BOOST_REQUIRE_EQUAL (get_requests ().size (), 5 );
863
+
864
+ auto manifest = verify_manifest_request (*part);
865
+ verify_segment_request (" 0-1-v1.log" , manifest);
866
+ verify_segment_request (" 1000-4-v1.log" , manifest);
867
+
868
+ BOOST_REQUIRE (part->archival_meta_stm ());
869
+ const cloud_storage::partition_manifest& stm_manifest
870
+ = part->archival_meta_stm ()->manifest ();
871
+ verify_stm_manifest (stm_manifest, segments);
872
+
873
+ BOOST_REQUIRE_EQUAL (
874
+ stm_manifest.get_last_uploaded_compacted_offset (), model::offset{});
875
+
876
+ // Mark both segments compacted, and re-upload. Both segments are
877
+ // re-uploaded.
878
+ reset_http_call_state ();
879
+
880
+ vlog (test_log.info , " Waiting for segments to self-compact" );
881
+ auto seg = self_compact_next_segment ();
882
+ vlog (test_log.info , " Self-compaction completed" );
883
+
884
+ expected = archival::ntp_archiver::batch_result{{0 , 0 , 0 }, {2 , 0 , 0 }};
885
+ upload_and_verify (archiver.value (), expected);
886
+ BOOST_REQUIRE_EQUAL (get_requests ().size (), 5 );
887
+
888
+ BOOST_REQUIRE_EQUAL (
889
+ stm_manifest.get_last_uploaded_compacted_offset (),
890
+ seg->offsets ().get_committed_offset ());
891
+
892
+ auto replaced = stm_manifest.replaced_segments ();
893
+ BOOST_REQUIRE_EQUAL (replaced.size (), 2 );
894
+ BOOST_REQUIRE_EQUAL (replaced[0 ].base_offset , model::offset{0 });
895
+ BOOST_REQUIRE_EQUAL (replaced[1 ].base_offset , model::offset{1000 });
896
+
897
+ // We can't reupload x-term so we should end up with two
898
+ // compacted uploads.
899
+
900
+ BOOST_REQUIRE_EQUAL (
901
+ stm_manifest.get (model::offset (0 ))->base_offset , model::offset (0 ));
902
+ BOOST_REQUIRE_EQUAL (
903
+ stm_manifest.get (model::offset (0 ))->committed_offset , model::offset (999 ));
904
+ BOOST_REQUIRE_EQUAL (
905
+ stm_manifest.get (model::offset (0 ))->segment_term , model::term_id (1 ));
906
+
907
+ BOOST_REQUIRE_EQUAL (
908
+ stm_manifest.get (model::offset (1000 ))->base_offset , model::offset (1000 ));
909
+ BOOST_REQUIRE_EQUAL (
910
+ stm_manifest.get (model::offset (1000 ))->committed_offset ,
911
+ model::offset (1009 ));
912
+ BOOST_REQUIRE_EQUAL (
913
+ stm_manifest.get (model::offset (1000 ))->segment_term , model::term_id (4 ));
914
+ }
0 commit comments