@@ -882,6 +882,45 @@ private void verifyUploadedSegments(RemoteSegmentStoreDirectory remoteSegmentSto
882882 assertTrue (remoteStoreRefreshListener .isRemoteSegmentStoreInSync ());
883883 }
884884
885+ public void testSkipsMetadataUploadWhenNoNewSegments () throws IOException {
886+ setup (true , 2 );
887+
888+ indexShard .refresh ("initial-upload" );
889+
890+ try (Store remoteStore = indexShard .remoteStore ()) {
891+ RemoteSegmentStoreDirectory remoteSegmentStoreDirectory =
892+ (RemoteSegmentStoreDirectory ) ((FilterDirectory ) ((FilterDirectory ) remoteStore .directory ()).getDelegate ()).getDelegate ();
893+
894+ final int initialCount = remoteSegmentStoreDirectory .getSegmentsUploadedToRemoteStore ().size ();
895+
896+ indexShard .refresh ("test-optimization" );
897+
898+ int afterOptimizationCount = remoteSegmentStoreDirectory .getSegmentsUploadedToRemoteStore ().size ();
899+ assertEquals ("No new segments should be uploaded when optimization kicks in" , initialCount , afterOptimizationCount );
900+ }
901+ }
902+
903+ public void testUploadsWhenNewSegmentsPresent () throws Exception {
904+ setup (true , 1 );
905+
906+ indexShard .refresh ("initial-upload" );
907+
908+ try (Store remoteStore = indexShard .remoteStore ()) {
909+ RemoteSegmentStoreDirectory remoteSegmentStoreDirectory =
910+ (RemoteSegmentStoreDirectory ) ((FilterDirectory ) ((FilterDirectory ) remoteStore .directory ()).getDelegate ()).getDelegate ();
911+
912+ final int initialCount = remoteSegmentStoreDirectory .getSegmentsUploadedToRemoteStore ().size ();
913+
914+ indexDoc (indexShard , "new-doc" , "{}" );
915+ indexShard .refresh ("new-segment-refresh" );
916+
917+ assertBusy (() -> {
918+ int afterNewSegmentCount = remoteSegmentStoreDirectory .getSegmentsUploadedToRemoteStore ().size ();
919+ assertTrue ("Expected new uploads after adding new segments" , afterNewSegmentCount > initialCount );
920+ });
921+ }
922+ }
923+
885924 public void testRemoteSegmentStoreNotInSync () throws IOException {
886925 setup (true , 3 );
887926 remoteStoreRefreshListener .afterRefresh (true );
0 commit comments