88
99package org .opensearch .remotestore ;
1010
11- import org .junit .After ;
12- import org .junit .Before ;
11+ import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsResponse ;
1312import org .opensearch .action .admin .indices .stats .IndicesStatsRequest ;
1413import org .opensearch .action .admin .indices .stats .IndicesStatsResponse ;
15- import org .opensearch .action .index .IndexResponse ;
16- import org .opensearch .cluster .metadata .IndexMetadata ;
17- import org .opensearch .common .UUIDs ;
18- import org .opensearch .common .io .FileSystemUtils ;
1914import org .opensearch .common .settings .Settings ;
20- import org .opensearch .common .util .FeatureFlags ;
21- import org .opensearch .index .IndexModule ;
22- import org .opensearch .index .IndexSettings ;
23- import org .opensearch .index .store .RemoteSegmentStoreDirectory ;
24- import org .opensearch .indices .replication .common .ReplicationType ;
25- import org .opensearch .snapshots .AbstractSnapshotIntegTestCase ;
26- import org .opensearch .test .FeatureFlagSetter ;
2715import org .opensearch .test .OpenSearchIntegTestCase ;
2816
29- import java .io .IOException ;
3017import java .nio .file .Path ;
31- import java .util .Arrays ;
32- import java .util .Collections ;
3318import java .util .Locale ;
3419import java .util .Set ;
3520import java .util .concurrent .TimeUnit ;
36- import java .util .stream .Collectors ;
3721
38- import static org .opensearch .test . hamcrest . OpenSearchAssertions . assertAcked ;
22+ import static org .opensearch .index . remote . RemoteRefreshSegmentPressureSettings . REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED ;
3923
4024@ OpenSearchIntegTestCase .ClusterScope (scope = OpenSearchIntegTestCase .Scope .TEST , numDataNodes = 0 )
41- public class RemoteStoreRefreshListenerIT extends AbstractSnapshotIntegTestCase {
42-
43- private static final String REPOSITORY_NAME = "my-segment-repo-1" ;
44- private static final String INDEX_NAME = "remote-store-test-idx-1" ;
45-
46- @ Override
47- protected Settings featureFlagSettings () {
48- return Settings .builder ()
49- .put (super .featureFlagSettings ())
50- .put (FeatureFlags .SEGMENT_REPLICATION_EXPERIMENTAL , "true" )
51- .put (FeatureFlags .REMOTE_STORE , "true" )
52- .build ();
53- }
54-
55- @ Before
56- public void setup () {
57- FeatureFlagSetter .set (FeatureFlags .REMOTE_STORE );
58- internalCluster ().startClusterManagerOnlyNode ();
59- }
60-
61- @ Override
62- public Settings indexSettings () {
63- return remoteStoreIndexSettings (0 );
64- }
65-
66- private Settings remoteStoreIndexSettings (int numberOfReplicas ) {
67- return Settings .builder ()
68- .put (super .indexSettings ())
69- .put (IndexSettings .INDEX_REFRESH_INTERVAL_SETTING .getKey (), "300s" )
70- .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
71- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , numberOfReplicas )
72- .put (IndexModule .INDEX_QUERY_CACHE_ENABLED_SETTING .getKey (), false )
73- .put (IndexMetadata .SETTING_REPLICATION_TYPE , ReplicationType .SEGMENT )
74- .put (IndexMetadata .SETTING_REMOTE_STORE_ENABLED , true )
75- .put (IndexMetadata .SETTING_REMOTE_STORE_REPOSITORY , REPOSITORY_NAME )
76- .build ();
77- }
78-
79- @ After
80- public void teardown () {
81- logger .info ("--> Deleting the repository={}" , REPOSITORY_NAME );
82- assertAcked (clusterAdmin ().prepareDeleteRepository (REPOSITORY_NAME ));
83- }
25+ public class RemoteStoreRefreshListenerIT extends AbstractRemoteStoreMockRepositoryIntegTestCase {
8426
8527 public void testRemoteRefreshRetryOnFailure () throws Exception {
8628
@@ -107,76 +49,16 @@ public void testRemoteRefreshRetryOnFailure() throws Exception {
10749 Set <String > filesInRepo = getSegmentFiles (segmentDataRepoPath );
10850 assertTrue (filesInRepo .containsAll (filesInLocal ));
10951 }, 60 , TimeUnit .SECONDS );
52+ deleteRepo ();
11053 }
11154
112- private void setup (Path repoLocation , double ioFailureRate , String skipExceptionBlobList ) {
113- logger .info ("--> Creating repository={} at the path={}" , REPOSITORY_NAME , repoLocation );
114- // The random_control_io_exception_rate setting ensures that 10-25% of all operations to remote store results in
115- /// IOException. skip_exception_on_verification_file & skip_exception_on_list_blobs settings ensures that the
116- // repository creation can happen without failure.
117- createRepository (
118- REPOSITORY_NAME ,
119- "mock" ,
120- Settings .builder ()
121- .put ("location" , repoLocation )
122- .put ("random_control_io_exception_rate" , ioFailureRate )
123- .put ("skip_exception_on_verification_file" , true )
124- .put ("skip_exception_on_list_blobs" , true )
125- .put ("max_failure_number" , Long .MAX_VALUE )
126- );
127-
128- internalCluster ().startDataOnlyNodes (1 );
129- createIndex (INDEX_NAME );
130- logger .info ("--> Created index={}" , INDEX_NAME );
131- ensureYellowAndNoInitializingShards (INDEX_NAME );
132- logger .info ("--> Cluster is yellow with no initializing shards" );
133- ensureGreen (INDEX_NAME );
134- logger .info ("--> Cluster is green" );
135- }
136-
137- /**
138- * Gets all segment files which starts with "_". For instance, _0.cfe, _o.cfs etc.
139- *
140- * @param location the path to location where segment files are being searched.
141- * @return set of file names of all segment file or empty set if there was IOException thrown.
142- */
143- private Set <String > getSegmentFiles (Path location ) {
144- try {
145- return Arrays .stream (FileSystemUtils .files (location ))
146- .filter (path -> path .getFileName ().toString ().startsWith ("_" ))
147- .map (path -> path .getFileName ().toString ())
148- .map (this ::getLocalSegmentFilename )
149- .collect (Collectors .toSet ());
150- } catch (IOException exception ) {
151- logger .error ("Exception occurred while getting segment files" , exception );
152- }
153- return Collections .emptySet ();
154- }
155-
156- private String getLocalSegmentFilename (String remoteFilename ) {
157- return remoteFilename .split (RemoteSegmentStoreDirectory .SEGMENT_NAME_UUID_SEPARATOR )[0 ];
158- }
159-
160- private IndexResponse indexSingleDoc () {
161- return client ().prepareIndex (INDEX_NAME )
162- .setId (UUIDs .randomBase64UUID ())
163- .setSource (randomAlphaOfLength (5 ), randomAlphaOfLength (5 ))
164- .get ();
165- }
55+ public void testRemoteRefreshSegmentPressureSettingChanged () {
56+ Settings request = Settings .builder ().put (REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED .getKey (), true ).build ();
57+ ClusterUpdateSettingsResponse response = client ().admin ().cluster ().prepareUpdateSettings ().setPersistentSettings (request ).get ();
58+ assertEquals (response .getPersistentSettings ().get (REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED .getKey ()), "true" );
16659
167- private void indexData (int numberOfIterations , boolean invokeFlush ) {
168- logger .info ("--> Indexing data for {} iterations with flush={}" , numberOfIterations , invokeFlush );
169- for (int i = 0 ; i < numberOfIterations ; i ++) {
170- int numberOfOperations = randomIntBetween (1 , 5 );
171- logger .info ("--> Indexing {} operations in iteration #{}" , numberOfOperations , i );
172- for (int j = 0 ; j < numberOfOperations ; j ++) {
173- indexSingleDoc ();
174- }
175- if (invokeFlush ) {
176- flush (INDEX_NAME );
177- } else {
178- refresh (INDEX_NAME );
179- }
180- }
60+ request = Settings .builder ().put (REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED .getKey (), false ).build ();
61+ response = client ().admin ().cluster ().prepareUpdateSettings ().setPersistentSettings (request ).get ();
62+ assertEquals (response .getPersistentSettings ().get (REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED .getKey ()), "false" );
18163 }
18264}
0 commit comments