8
8
9
9
package org .opensearch .remotemigration ;
10
10
11
- import org .opensearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
12
11
import org .opensearch .client .Client ;
13
- import org .opensearch .cluster .metadata .IndexMetadata ;
14
12
import org .opensearch .common .settings .Settings ;
15
13
import org .opensearch .common .settings .SettingsException ;
16
- import org .opensearch .core .rest .RestStatus ;
17
- import org .opensearch .index .IndexSettings ;
18
- import org .opensearch .indices .replication .common .ReplicationType ;
19
- import org .opensearch .snapshots .SnapshotInfo ;
20
- import org .opensearch .snapshots .SnapshotState ;
21
14
import org .opensearch .test .InternalTestCluster ;
22
15
import org .opensearch .test .OpenSearchIntegTestCase ;
23
16
24
17
import java .nio .file .Path ;
25
18
import java .util .Optional ;
26
19
27
- import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_REMOTE_SEGMENT_STORE_REPOSITORY ;
28
- import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_REMOTE_STORE_ENABLED ;
29
- import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY ;
30
- import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_REPLICATION_TYPE ;
31
- import static org .opensearch .index .IndexSettings .INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING ;
32
20
import static org .opensearch .node .remotestore .RemoteStoreNodeService .CompatibilityMode .MIXED ;
33
21
import static org .opensearch .node .remotestore .RemoteStoreNodeService .CompatibilityMode .STRICT ;
34
22
import static org .opensearch .node .remotestore .RemoteStoreNodeService .Direction .REMOTE_STORE ;
@@ -92,13 +80,7 @@ public void testNewRestoredIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMix
92
80
assertNodeInCluster (remoteNodeName );
93
81
94
82
logger .info ("Create a non remote-backed index" );
95
- client .admin ()
96
- .indices ()
97
- .prepareCreate (TEST_INDEX )
98
- .setSettings (
99
- Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 ).put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 ).build ()
100
- )
101
- .get ();
83
+ createIndex (TEST_INDEX , 0 );
102
84
103
85
logger .info ("Verify that non remote stored backed index is created" );
104
86
assertNonRemoteStoreBackedIndex (TEST_INDEX );
@@ -115,21 +97,12 @@ public void testNewRestoredIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMix
115
97
116
98
logger .info ("Create snapshot of non remote stored backed index" );
117
99
118
- SnapshotInfo snapshotInfo = client ().admin ()
119
- .cluster ()
120
- .prepareCreateSnapshot (snapshotRepoName , snapshotName )
121
- .setIndices (TEST_INDEX )
122
- .setWaitForCompletion (true )
123
- .get ()
124
- .getSnapshotInfo ();
125
-
126
- assertEquals (SnapshotState .SUCCESS , snapshotInfo .state ());
127
- assertTrue (snapshotInfo .successfulShards () > 0 );
128
- assertEquals (0 , snapshotInfo .failedShards ());
100
+ createSnapshot (snapshotRepoName , snapshotName , TEST_INDEX );
129
101
130
102
logger .info ("Restore index from snapshot under NONE direction" );
131
103
String restoredIndexName1 = TEST_INDEX + "-restored1" ;
132
104
restoreSnapshot (snapshotRepoName , snapshotName , restoredIndexName1 );
105
+ ensureGreen (restoredIndexName1 );
133
106
134
107
logger .info ("Verify that restored index is non remote-backed" );
135
108
assertNonRemoteStoreBackedIndex (restoredIndexName1 );
@@ -138,6 +111,7 @@ public void testNewRestoredIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMix
138
111
setDirection (REMOTE_STORE .direction );
139
112
String restoredIndexName2 = TEST_INDEX + "-restored2" ;
140
113
restoreSnapshot (snapshotRepoName , snapshotName , restoredIndexName2 );
114
+ ensureGreen (restoredIndexName2 );
141
115
142
116
logger .info ("Verify that restored index is non remote-backed" );
143
117
assertRemoteStoreBackedIndex (restoredIndexName2 );
@@ -146,10 +120,10 @@ public void testNewRestoredIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMix
146
120
// compatibility mode setting test
147
121
148
122
public void testSwitchToStrictMode () throws Exception {
149
- logger .info (" --> initialize cluster" );
123
+ logger .info ("Initialize cluster" );
150
124
initializeCluster (false );
151
125
152
- logger .info (" --> create a mixed mode cluster" );
126
+ logger .info ("Create a mixed mode cluster" );
153
127
setClusterMode (MIXED .mode );
154
128
addRemote = true ;
155
129
String remoteNodeName = internalCluster ().startNode ();
@@ -159,58 +133,21 @@ public void testSwitchToStrictMode() throws Exception {
159
133
assertNodeInCluster (remoteNodeName );
160
134
assertNodeInCluster (nonRemoteNodeName );
161
135
162
- logger .info (" --> attempt switching to strict mode" );
136
+ logger .info ("Attempt switching to strict mode" );
163
137
SettingsException exception = assertThrows (SettingsException .class , () -> setClusterMode (STRICT .mode ));
164
138
assertEquals (
165
139
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes" ,
166
140
exception .getMessage ()
167
141
);
168
142
169
- logger .info (" --> stop remote node so that cluster had only non-remote nodes" );
143
+ logger .info ("Stop remote node so that cluster had only non-remote nodes" );
170
144
internalCluster ().stopRandomNode (InternalTestCluster .nameFilter (remoteNodeName ));
171
145
ensureStableCluster (2 );
172
146
173
- logger .info (" --> attempt switching to strict mode" );
147
+ logger .info ("Attempt switching to strict mode" );
174
148
setClusterMode (STRICT .mode );
175
149
}
176
150
177
- // restore indices from a snapshot
178
- private void restoreSnapshot (String snapshotRepoName , String snapshotName , String restoredIndexName ) {
179
- RestoreSnapshotResponse restoreSnapshotResponse = client .admin ()
180
- .cluster ()
181
- .prepareRestoreSnapshot (snapshotRepoName , snapshotName )
182
- .setWaitForCompletion (false )
183
- .setIndices (TEST_INDEX )
184
- .setRenamePattern (TEST_INDEX )
185
- .setRenameReplacement (restoredIndexName )
186
- .get ();
187
-
188
- assertEquals (restoreSnapshotResponse .status (), RestStatus .ACCEPTED );
189
- ensureGreen (restoredIndexName );
190
- }
191
-
192
- // verify that the created index is not remote store backed
193
- private void assertNonRemoteStoreBackedIndex (String indexName ) {
194
- Settings indexSettings = client .admin ().indices ().prepareGetIndex ().execute ().actionGet ().getSettings ().get (indexName );
195
- assertEquals (ReplicationType .DOCUMENT .toString (), indexSettings .get (SETTING_REPLICATION_TYPE ));
196
- assertNull (indexSettings .get (SETTING_REMOTE_STORE_ENABLED ));
197
- assertNull (indexSettings .get (SETTING_REMOTE_SEGMENT_STORE_REPOSITORY ));
198
- assertNull (indexSettings .get (SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY ));
199
- }
200
-
201
- // verify that the created index is remote store backed
202
- private void assertRemoteStoreBackedIndex (String indexName ) {
203
- Settings indexSettings = client .admin ().indices ().prepareGetIndex ().execute ().actionGet ().getSettings ().get (indexName );
204
- assertEquals (ReplicationType .SEGMENT .toString (), indexSettings .get (SETTING_REPLICATION_TYPE ));
205
- assertEquals ("true" , indexSettings .get (SETTING_REMOTE_STORE_ENABLED ));
206
- assertEquals (REPOSITORY_NAME , indexSettings .get (SETTING_REMOTE_SEGMENT_STORE_REPOSITORY ));
207
- assertEquals (REPOSITORY_2_NAME , indexSettings .get (SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY ));
208
- assertEquals (
209
- IndexSettings .DEFAULT_REMOTE_TRANSLOG_BUFFER_INTERVAL ,
210
- INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING .get (indexSettings )
211
- );
212
- }
213
-
214
151
// bootstrap a cluster
215
152
private void initializeCluster (boolean remoteClusterManager ) {
216
153
addRemote = remoteClusterManager ;
0 commit comments