14
14
import org .opensearch .core .xcontent .ToXContentFragment ;
15
15
import org .opensearch .core .xcontent .XContentBuilder ;
16
16
import 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 ;
17
20
import org .opensearch .index .snapshots .IndexShardSnapshotStatus ;
18
21
19
22
import java .io .IOException ;
20
23
import java .util .ArrayList ;
21
24
import java .util .List ;
25
+ import java .util .Objects ;
22
26
23
27
/**
24
28
* Remote Store based Shard snapshot metadata
@@ -41,8 +45,10 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment,
41
45
private final String repositoryBasePath ;
42
46
private final String indexUUID ;
43
47
private final List <String > fileNames ;
48
+ private final PathType pathType ;
49
+ private final PathHashAlgorithm pathHashAlgorithm ;
44
50
45
- static final String DEFAULT_VERSION = "1 " ;
51
+ static final String DEFAULT_VERSION = "2 " ;
46
52
static final String NAME = "name" ;
47
53
static final String VERSION = "version" ;
48
54
static final String INDEX_VERSION = "index_version" ;
@@ -61,6 +67,8 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment,
61
67
62
68
static final String TOTAL_FILE_COUNT = "number_of_files" ;
63
69
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" ;
64
72
65
73
private static final ParseField PARSE_NAME = new ParseField (NAME );
66
74
private static final ParseField PARSE_VERSION = new ParseField (VERSION );
@@ -75,6 +83,8 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment,
75
83
private static final ParseField PARSE_REMOTE_STORE_REPOSITORY = new ParseField (REMOTE_STORE_REPOSITORY );
76
84
private static final ParseField PARSE_REPOSITORY_BASE_PATH = new ParseField (REPOSITORY_BASE_PATH );
77
85
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 );
78
88
79
89
/**
80
90
* Serializes shard snapshot metadata info into JSON
@@ -101,6 +111,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
101
111
builder .value (fileName );
102
112
}
103
113
builder .endArray ();
114
+ builder .field (PATH_TYPE , pathType .getCode ());
115
+ builder .field (PATH_HASH_ALGORITHM , pathHashAlgorithm .getCode ());
104
116
return builder ;
105
117
}
106
118
@@ -116,31 +128,27 @@ public RemoteStoreShardShallowCopySnapshot(
116
128
String indexUUID ,
117
129
String remoteStoreRepository ,
118
130
String repositoryBasePath ,
119
- List <String > fileNames
131
+ List <String > fileNames ,
132
+ PathType pathType ,
133
+ PathHashAlgorithm pathHashAlgorithm
120
134
) {
121
- this .version = DEFAULT_VERSION ;
122
- verifyParameters (
123
- version ,
135
+ this (
136
+ DEFAULT_VERSION ,
124
137
snapshot ,
125
138
indexVersion ,
126
139
primaryTerm ,
127
140
commitGeneration ,
141
+ startTime ,
142
+ time ,
143
+ totalFileCount ,
144
+ totalSize ,
128
145
indexUUID ,
129
146
remoteStoreRepository ,
130
- repositoryBasePath
147
+ repositoryBasePath ,
148
+ fileNames ,
149
+ pathType ,
150
+ pathHashAlgorithm
131
151
);
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 ;
144
152
}
145
153
146
154
private RemoteStoreShardShallowCopySnapshot (
@@ -156,7 +164,9 @@ private RemoteStoreShardShallowCopySnapshot(
156
164
String indexUUID ,
157
165
String remoteStoreRepository ,
158
166
String repositoryBasePath ,
159
- List <String > fileNames
167
+ List <String > fileNames ,
168
+ PathType pathType ,
169
+ PathHashAlgorithm pathHashAlgorithm
160
170
) {
161
171
verifyParameters (
162
172
version ,
@@ -181,6 +191,8 @@ private RemoteStoreShardShallowCopySnapshot(
181
191
this .remoteStoreRepository = remoteStoreRepository ;
182
192
this .repositoryBasePath = repositoryBasePath ;
183
193
this .fileNames = fileNames ;
194
+ this .pathType = pathType ;
195
+ this .pathHashAlgorithm = pathHashAlgorithm ;
184
196
}
185
197
186
198
/**
@@ -203,6 +215,8 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
203
215
long primaryTerm = -1 ;
204
216
long commitGeneration = -1 ;
205
217
List <String > fileNames = new ArrayList <>();
218
+ PathType pathType = null ;
219
+ PathHashAlgorithm pathHashAlgorithm = null ;
206
220
207
221
if (parser .currentToken () == null ) { // fresh parser? move to the first token
208
222
parser .nextToken ();
@@ -237,6 +251,10 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
237
251
remoteStoreRepository = parser .text ();
238
252
} else if (PARSE_REPOSITORY_BASE_PATH .match (currentFieldName , parser .getDeprecationHandler ())) {
239
253
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 ());
240
258
} else {
241
259
throw new OpenSearchParseException ("unknown parameter [{}]" , currentFieldName );
242
260
}
@@ -266,7 +284,9 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
266
284
indexUUID ,
267
285
remoteStoreRepository ,
268
286
repositoryBasePath ,
269
- fileNames
287
+ fileNames ,
288
+ pathType ,
289
+ pathHashAlgorithm
270
290
);
271
291
}
272
292
@@ -433,7 +453,9 @@ public RemoteStoreShardShallowCopySnapshot asClone(String targetSnapshotName, lo
433
453
indexUUID ,
434
454
remoteStoreRepository ,
435
455
repositoryBasePath ,
436
- fileNames
456
+ fileNames ,
457
+ pathType ,
458
+ pathHashAlgorithm
437
459
);
438
460
}
439
461
@@ -449,4 +471,11 @@ public IndexShardSnapshotStatus getIndexShardSnapshotStatus() {
449
471
null
450
472
); // Not adding a real generation here as it doesn't matter to callers
451
473
}
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
+ }
452
481
}
0 commit comments