1414import org .opensearch .core .xcontent .ToXContentFragment ;
1515import org .opensearch .core .xcontent .XContentBuilder ;
1616import org .opensearch .core .xcontent .XContentParser ;
17+ import org .opensearch .index .remote .RemoteStoreEnums .PathHashAlgorithm ;
18+ import org .opensearch .index .remote .RemoteStoreEnums .PathType ;
19+ import org .opensearch .index .remote .RemoteStorePathStrategy ;
1720import org .opensearch .index .snapshots .IndexShardSnapshotStatus ;
1821
1922import java .io .IOException ;
2023import java .util .ArrayList ;
2124import java .util .List ;
25+ import java .util .Objects ;
2226
2327/**
2428 * Remote Store based Shard snapshot metadata
@@ -41,8 +45,10 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment,
4145 private final String repositoryBasePath ;
4246 private final String indexUUID ;
4347 private final List <String > fileNames ;
48+ private final PathType pathType ;
49+ private final PathHashAlgorithm pathHashAlgorithm ;
4450
45- static final String DEFAULT_VERSION = "1 " ;
51+ static final String DEFAULT_VERSION = "2 " ;
4652 static final String NAME = "name" ;
4753 static final String VERSION = "version" ;
4854 static final String INDEX_VERSION = "index_version" ;
@@ -61,6 +67,8 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment,
6167
6268 static final String TOTAL_FILE_COUNT = "number_of_files" ;
6369 static final String TOTAL_SIZE = "total_size" ;
70+ static final String PATH_TYPE = "path_type" ;
71+ static final String PATH_HASH_ALGORITHM = "path_hash_algorithm" ;
6472
6573 private static final ParseField PARSE_NAME = new ParseField (NAME );
6674 private static final ParseField PARSE_VERSION = new ParseField (VERSION );
@@ -75,6 +83,8 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment,
7583 private static final ParseField PARSE_REMOTE_STORE_REPOSITORY = new ParseField (REMOTE_STORE_REPOSITORY );
7684 private static final ParseField PARSE_REPOSITORY_BASE_PATH = new ParseField (REPOSITORY_BASE_PATH );
7785 private static final ParseField PARSE_FILE_NAMES = new ParseField (FILE_NAMES );
86+ private static final ParseField PARSE_PATH_TYPE = new ParseField (PATH_TYPE );
87+ private static final ParseField PARSE_PATH_HASH_ALGORITHM = new ParseField (PATH_HASH_ALGORITHM );
7888
7989 /**
8090 * Serializes shard snapshot metadata info into JSON
@@ -101,6 +111,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
101111 builder .value (fileName );
102112 }
103113 builder .endArray ();
114+ builder .field (PATH_TYPE , pathType .getCode ());
115+ builder .field (PATH_HASH_ALGORITHM , pathHashAlgorithm .getCode ());
104116 return builder ;
105117 }
106118
@@ -116,31 +128,27 @@ public RemoteStoreShardShallowCopySnapshot(
116128 String indexUUID ,
117129 String remoteStoreRepository ,
118130 String repositoryBasePath ,
119- List <String > fileNames
131+ List <String > fileNames ,
132+ PathType pathType ,
133+ PathHashAlgorithm pathHashAlgorithm
120134 ) {
121- this .version = DEFAULT_VERSION ;
122- verifyParameters (
123- version ,
135+ this (
136+ DEFAULT_VERSION ,
124137 snapshot ,
125138 indexVersion ,
126139 primaryTerm ,
127140 commitGeneration ,
141+ startTime ,
142+ time ,
143+ totalFileCount ,
144+ totalSize ,
128145 indexUUID ,
129146 remoteStoreRepository ,
130- repositoryBasePath
147+ repositoryBasePath ,
148+ fileNames ,
149+ pathType ,
150+ pathHashAlgorithm
131151 );
132- this .snapshot = snapshot ;
133- this .indexVersion = indexVersion ;
134- this .primaryTerm = primaryTerm ;
135- this .commitGeneration = commitGeneration ;
136- this .startTime = startTime ;
137- this .time = time ;
138- this .totalFileCount = totalFileCount ;
139- this .totalSize = totalSize ;
140- this .indexUUID = indexUUID ;
141- this .remoteStoreRepository = remoteStoreRepository ;
142- this .repositoryBasePath = repositoryBasePath ;
143- this .fileNames = fileNames ;
144152 }
145153
146154 private RemoteStoreShardShallowCopySnapshot (
@@ -156,7 +164,9 @@ private RemoteStoreShardShallowCopySnapshot(
156164 String indexUUID ,
157165 String remoteStoreRepository ,
158166 String repositoryBasePath ,
159- List <String > fileNames
167+ List <String > fileNames ,
168+ PathType pathType ,
169+ PathHashAlgorithm pathHashAlgorithm
160170 ) {
161171 verifyParameters (
162172 version ,
@@ -181,6 +191,8 @@ private RemoteStoreShardShallowCopySnapshot(
181191 this .remoteStoreRepository = remoteStoreRepository ;
182192 this .repositoryBasePath = repositoryBasePath ;
183193 this .fileNames = fileNames ;
194+ this .pathType = pathType ;
195+ this .pathHashAlgorithm = pathHashAlgorithm ;
184196 }
185197
186198 /**
@@ -203,6 +215,8 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
203215 long primaryTerm = -1 ;
204216 long commitGeneration = -1 ;
205217 List <String > fileNames = new ArrayList <>();
218+ PathType pathType = null ;
219+ PathHashAlgorithm pathHashAlgorithm = null ;
206220
207221 if (parser .currentToken () == null ) { // fresh parser? move to the first token
208222 parser .nextToken ();
@@ -237,6 +251,10 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
237251 remoteStoreRepository = parser .text ();
238252 } else if (PARSE_REPOSITORY_BASE_PATH .match (currentFieldName , parser .getDeprecationHandler ())) {
239253 repositoryBasePath = parser .text ();
254+ } else if (PARSE_PATH_TYPE .match (currentFieldName , parser .getDeprecationHandler ())) {
255+ pathType = PathType .fromCode (parser .intValue ());
256+ } else if (PARSE_PATH_HASH_ALGORITHM .match (currentFieldName , parser .getDeprecationHandler ())) {
257+ pathHashAlgorithm = PathHashAlgorithm .fromCode (parser .intValue ());
240258 } else {
241259 throw new OpenSearchParseException ("unknown parameter [{}]" , currentFieldName );
242260 }
@@ -266,7 +284,9 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
266284 indexUUID ,
267285 remoteStoreRepository ,
268286 repositoryBasePath ,
269- fileNames
287+ fileNames ,
288+ pathType ,
289+ pathHashAlgorithm
270290 );
271291 }
272292
@@ -433,7 +453,9 @@ public RemoteStoreShardShallowCopySnapshot asClone(String targetSnapshotName, lo
433453 indexUUID ,
434454 remoteStoreRepository ,
435455 repositoryBasePath ,
436- fileNames
456+ fileNames ,
457+ pathType ,
458+ pathHashAlgorithm
437459 );
438460 }
439461
@@ -449,4 +471,11 @@ public IndexShardSnapshotStatus getIndexShardSnapshotStatus() {
449471 null
450472 ); // Not adding a real generation here as it doesn't matter to callers
451473 }
474+
475+ public RemoteStorePathStrategy getRemoteStorePathStrategy () {
476+ if (Objects .nonNull (pathType ) && Objects .nonNull (pathHashAlgorithm )) {
477+ return new RemoteStorePathStrategy (pathType , pathHashAlgorithm );
478+ }
479+ return new RemoteStorePathStrategy (PathType .FIXED );
480+ }
452481}
0 commit comments