10
10
11
11
import org .apache .logging .log4j .LogManager ;
12
12
import org .apache .logging .log4j .Logger ;
13
+ import org .opensearch .Version ;
14
+ import org .opensearch .cluster .ClusterState ;
15
+ import org .opensearch .cluster .metadata .IndexMetadata ;
13
16
import org .opensearch .cluster .node .DiscoveryNode ;
14
17
import org .opensearch .cluster .node .DiscoveryNodes ;
15
- import org .opensearch .cluster .metadata .IndexMetadata ;
16
18
import org .opensearch .common .collect .Tuple ;
19
+ import org .opensearch .common .settings .Settings ;
17
20
import org .opensearch .node .remotestore .RemoteStoreNodeAttribute ;
18
21
19
22
import java .nio .ByteBuffer ;
23
26
import java .util .List ;
24
27
import java .util .Locale ;
25
28
import java .util .Map ;
26
- import java .util .Optional ;
27
29
import java .util .Objects ;
30
+ import java .util .Optional ;
28
31
import java .util .function .Function ;
29
32
33
+ import static org .opensearch .indices .RemoteStoreSettings .CLUSTER_REMOTE_STORE_PATH_HASH_ALGORITHM_SETTING ;
34
+ import static org .opensearch .indices .RemoteStoreSettings .CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING ;
35
+
30
36
/**
31
37
* Utils for remote store
32
38
*
@@ -161,17 +167,43 @@ public static RemoteStorePathStrategy determineRemoteStorePathStrategy(IndexMeta
161
167
assert remoteCustomData == null || remoteCustomData .containsKey (RemoteStoreEnums .PathType .NAME );
162
168
if (remoteCustomData != null && remoteCustomData .containsKey (RemoteStoreEnums .PathType .NAME )) {
163
169
RemoteStoreEnums .PathType pathType = RemoteStoreEnums .PathType .parseString (
164
- remoteCustomData .get (RemoteStoreEnums .PathType .NAME )
170
+ remoteCustomData .get (RemoteStoreEnums .PathType .NAME )
165
171
);
166
172
String hashAlgoStr = remoteCustomData .get (RemoteStoreEnums .PathHashAlgorithm .NAME );
167
173
RemoteStoreEnums .PathHashAlgorithm hashAlgorithm = Objects .nonNull (hashAlgoStr )
168
- ? RemoteStoreEnums .PathHashAlgorithm .parseString (hashAlgoStr )
169
- : null ;
174
+ ? RemoteStoreEnums .PathHashAlgorithm .parseString (hashAlgoStr )
175
+ : null ;
170
176
return new RemoteStorePathStrategy (pathType , hashAlgorithm );
171
177
}
172
178
return new RemoteStorePathStrategy (RemoteStoreEnums .PathType .FIXED );
173
179
}
174
180
181
+ /**
182
+ * Generates the remote store path type information to be added to custom data of index metadata during migration
183
+ *
184
+ * @param clusterSettings Current Cluster settings from {@link ClusterState}
185
+ * @param discoveryNodes Current {@link DiscoveryNodes} from the cluster state
186
+ * @return {@link Map} to be added as custom data in index metadata
187
+ */
188
+ public static Map <String , String > determineRemoteStorePathStrategyDuringMigration (
189
+ Settings clusterSettings ,
190
+ DiscoveryNodes discoveryNodes
191
+ ) {
192
+ Version minNodeVersion = discoveryNodes .getMinNodeVersion ();
193
+ RemoteStoreEnums .PathType pathType = Version .CURRENT .compareTo (minNodeVersion ) <= 0
194
+ ? CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING .get (clusterSettings )
195
+ : RemoteStoreEnums .PathType .FIXED ;
196
+ RemoteStoreEnums .PathHashAlgorithm pathHashAlgorithm = pathType == RemoteStoreEnums .PathType .FIXED
197
+ ? null
198
+ : CLUSTER_REMOTE_STORE_PATH_HASH_ALGORITHM_SETTING .get (clusterSettings );
199
+ Map <String , String > remoteCustomData = new HashMap <>();
200
+ remoteCustomData .put (RemoteStoreEnums .PathType .NAME , pathType .name ());
201
+ if (Objects .nonNull (pathHashAlgorithm )) {
202
+ remoteCustomData .put (RemoteStoreEnums .PathHashAlgorithm .NAME , pathHashAlgorithm .name ());
203
+ }
204
+ return remoteCustomData ;
205
+ }
206
+
175
207
/**
176
208
* Fetches segment and translog repository names from remote store node attributes.
177
209
* Returns a blank {@link HashMap} if the cluster does not contain any remote nodes.
@@ -183,10 +215,10 @@ public static RemoteStorePathStrategy determineRemoteStorePathStrategy(IndexMeta
183
215
*/
184
216
public static Map <String , String > getRemoteStoreRepoName (DiscoveryNodes discoveryNodes ) {
185
217
Optional <DiscoveryNode > remoteNode = discoveryNodes .getNodes ()
186
- .values ()
187
- .stream ()
188
- .filter (DiscoveryNode ::isRemoteStoreNode )
189
- .findFirst ();
218
+ .values ()
219
+ .stream ()
220
+ .filter (DiscoveryNode ::isRemoteStoreNode )
221
+ .findFirst ();
190
222
return remoteNode .map (RemoteStoreNodeAttribute ::getDataRepoNames ).orElseGet (HashMap ::new );
191
223
}
192
224
}
0 commit comments