27
27
import org .apache .logging .log4j .message .ParameterizedMessage ;
28
28
import org .elasticsearch .Version ;
29
29
import org .elasticsearch .action .ActionListener ;
30
- import org .elasticsearch .action .support . IndicesOptions ;
30
+ import org .elasticsearch .action .admin . cluster . snapshots . restore . RestoreSnapshotRequest ;
31
31
import org .elasticsearch .cluster .ClusterChangedEvent ;
32
32
import org .elasticsearch .cluster .ClusterState ;
33
33
import org .elasticsearch .cluster .ClusterStateApplier ;
78
78
import java .util .HashSet ;
79
79
import java .util .List ;
80
80
import java .util .Map ;
81
- import java .util .Objects ;
82
81
import java .util .Optional ;
83
82
import java .util .Set ;
84
83
import java .util .function .Predicate ;
100
99
* <p>
101
100
* Restore operation is performed in several stages.
102
101
* <p>
103
- * First {@link #restoreSnapshot(RestoreRequest , org.elasticsearch.action.ActionListener)}
102
+ * First {@link #restoreSnapshot(RestoreSnapshotRequest , org.elasticsearch.action.ActionListener)}
104
103
* method reads information about snapshot and metadata from repository. In update cluster state task it checks restore
105
104
* preconditions, restores global state if needed, creates {@link RestoreInProgress} record with list of shards that needs
106
105
* to be restored and adds this shard to the routing table using
@@ -172,28 +171,30 @@ public RestoreService(ClusterService clusterService, RepositoriesService reposit
172
171
* @param request restore request
173
172
* @param listener restore listener
174
173
*/
175
- public void restoreSnapshot (final RestoreRequest request , final ActionListener <RestoreCompletionResponse > listener ) {
174
+ public void restoreSnapshot (final RestoreSnapshotRequest request , final ActionListener <RestoreCompletionResponse > listener ) {
176
175
try {
177
176
// Read snapshot info and metadata from the repository
178
- Repository repository = repositoriesService .repository (request .repositoryName );
177
+ final String repositoryName = request .repository ();
178
+ Repository repository = repositoriesService .repository (repositoryName );
179
179
final RepositoryData repositoryData = repository .getRepositoryData ();
180
+ final String snapshotName = request .snapshot ();
180
181
final Optional <SnapshotId > incompatibleSnapshotId =
181
- repositoryData .getIncompatibleSnapshotIds ().stream ().filter (s -> request . snapshotName .equals (s .getName ())).findFirst ();
182
+ repositoryData .getIncompatibleSnapshotIds ().stream ().filter (s -> snapshotName .equals (s .getName ())).findFirst ();
182
183
if (incompatibleSnapshotId .isPresent ()) {
183
- throw new SnapshotRestoreException (request . repositoryName , request . snapshotName , "cannot restore incompatible snapshot" );
184
+ throw new SnapshotRestoreException (repositoryName , snapshotName , "cannot restore incompatible snapshot" );
184
185
}
185
186
final Optional <SnapshotId > matchingSnapshotId = repositoryData .getSnapshotIds ().stream ()
186
- .filter (s -> request . snapshotName .equals (s .getName ())).findFirst ();
187
+ .filter (s -> snapshotName .equals (s .getName ())).findFirst ();
187
188
if (matchingSnapshotId .isPresent () == false ) {
188
- throw new SnapshotRestoreException (request . repositoryName , request . snapshotName , "snapshot does not exist" );
189
+ throw new SnapshotRestoreException (repositoryName , snapshotName , "snapshot does not exist" );
189
190
}
190
191
191
192
final SnapshotId snapshotId = matchingSnapshotId .get ();
192
193
final SnapshotInfo snapshotInfo = repository .getSnapshotInfo (snapshotId );
193
- final Snapshot snapshot = new Snapshot (request . repositoryName , snapshotId );
194
+ final Snapshot snapshot = new Snapshot (repositoryName , snapshotId );
194
195
195
196
// Make sure that we can restore from this snapshot
196
- validateSnapshotRestorable (request . repositoryName , snapshotInfo );
197
+ validateSnapshotRestorable (repositoryName , snapshotInfo );
197
198
198
199
// Resolve the indices from the snapshot that need to be restored
199
200
final List <String > indicesInSnapshot = filterIndices (snapshotInfo .indices (), request .indices (), request .indicesOptions ());
@@ -218,7 +219,7 @@ public void restoreSnapshot(final RestoreRequest request, final ActionListener<R
218
219
219
220
// Now we can start the actual restore process by adding shards to be recovered in the cluster state
220
221
// and updating cluster metadata (global and index) as needed
221
- clusterService .submitStateUpdateTask (request . cause () , new ClusterStateUpdateTask () {
222
+ clusterService .submitStateUpdateTask ("restore_snapshot[" + snapshotName + ']' , new ClusterStateUpdateTask () {
222
223
String restoreUUID = UUIDs .randomBase64UUID ();
223
224
RestoreInfo restoreInfo = null ;
224
225
@@ -261,7 +262,7 @@ public ClusterState execute(ClusterState currentState) {
261
262
String renamedIndexName = indexEntry .getKey ();
262
263
IndexMetaData snapshotIndexMetaData = metaData .index (index );
263
264
snapshotIndexMetaData = updateIndexSettings (snapshotIndexMetaData ,
264
- request .indexSettings , request .ignoreIndexSettings );
265
+ request .indexSettings () , request .ignoreIndexSettings () );
265
266
try {
266
267
snapshotIndexMetaData = metaDataIndexUpgradeService .upgradeIndexMetaData (snapshotIndexMetaData ,
267
268
minIndexCompatibilityVersion );
@@ -535,7 +536,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
535
536
536
537
} catch (Exception e ) {
537
538
logger .warn (() -> new ParameterizedMessage ("[{}] failed to restore snapshot" ,
538
- request .repositoryName + ":" + request .snapshotName ), e );
539
+ request .repository () + ":" + request .snapshot () ), e );
539
540
listener .onFailure (e );
540
541
}
541
542
}
@@ -820,7 +821,7 @@ public static int failedShards(ImmutableOpenMap<ShardId, RestoreInProgress.Shard
820
821
return failedShards ;
821
822
}
822
823
823
- private Map <String , String > renamedIndices (RestoreRequest request , List <String > filteredIndices ) {
824
+ private Map <String , String > renamedIndices (RestoreSnapshotRequest request , List <String > filteredIndices ) {
824
825
Map <String , String > renamedIndices = new HashMap <>();
825
826
for (String index : filteredIndices ) {
826
827
String renamedIndex = index ;
@@ -829,7 +830,7 @@ private Map<String, String> renamedIndices(RestoreRequest request, List<String>
829
830
}
830
831
String previousIndex = renamedIndices .put (renamedIndex , index );
831
832
if (previousIndex != null ) {
832
- throw new SnapshotRestoreException (request .repositoryName , request .snapshotName ,
833
+ throw new SnapshotRestoreException (request .repository () , request .snapshot () ,
833
834
"indices [" + index + "] and [" + previousIndex + "] are renamed into the same index [" + renamedIndex + "]" );
834
835
}
835
836
}
@@ -919,203 +920,4 @@ public static boolean isRepositoryInUse(ClusterState clusterState, String reposi
919
920
}
920
921
return false ;
921
922
}
922
-
923
- /**
924
- * Restore snapshot request
925
- */
926
- public static class RestoreRequest {
927
-
928
- private final String cause ;
929
-
930
- private final String repositoryName ;
931
-
932
- private final String snapshotName ;
933
-
934
- private final String [] indices ;
935
-
936
- private final String renamePattern ;
937
-
938
- private final String renameReplacement ;
939
-
940
- private final IndicesOptions indicesOptions ;
941
-
942
- private final Settings settings ;
943
-
944
- private final TimeValue masterNodeTimeout ;
945
-
946
- private final boolean includeGlobalState ;
947
-
948
- private final boolean partial ;
949
-
950
- private final boolean includeAliases ;
951
-
952
- private final Settings indexSettings ;
953
-
954
- private final String [] ignoreIndexSettings ;
955
-
956
- /**
957
- * Constructs new restore request
958
- *
959
- * @param repositoryName repositoryName
960
- * @param snapshotName snapshotName
961
- * @param indices list of indices to restore
962
- * @param indicesOptions indices options
963
- * @param renamePattern pattern to rename indices
964
- * @param renameReplacement replacement for renamed indices
965
- * @param settings repository specific restore settings
966
- * @param masterNodeTimeout master node timeout
967
- * @param includeGlobalState include global state into restore
968
- * @param partial allow partial restore
969
- * @param indexSettings index settings that should be changed on restore
970
- * @param ignoreIndexSettings index settings that shouldn't be restored
971
- * @param cause cause for restoring the snapshot
972
- */
973
- public RestoreRequest (String repositoryName , String snapshotName , String [] indices , IndicesOptions indicesOptions ,
974
- String renamePattern , String renameReplacement , Settings settings ,
975
- TimeValue masterNodeTimeout , boolean includeGlobalState , boolean partial , boolean includeAliases ,
976
- Settings indexSettings , String [] ignoreIndexSettings , String cause ) {
977
- this .repositoryName = Objects .requireNonNull (repositoryName );
978
- this .snapshotName = Objects .requireNonNull (snapshotName );
979
- this .indices = indices ;
980
- this .renamePattern = renamePattern ;
981
- this .renameReplacement = renameReplacement ;
982
- this .indicesOptions = indicesOptions ;
983
- this .settings = settings ;
984
- this .masterNodeTimeout = masterNodeTimeout ;
985
- this .includeGlobalState = includeGlobalState ;
986
- this .partial = partial ;
987
- this .includeAliases = includeAliases ;
988
- this .indexSettings = indexSettings ;
989
- this .ignoreIndexSettings = ignoreIndexSettings ;
990
- this .cause = cause ;
991
- }
992
-
993
- /**
994
- * Returns restore operation cause
995
- *
996
- * @return restore operation cause
997
- */
998
- public String cause () {
999
- return cause ;
1000
- }
1001
-
1002
- /**
1003
- * Returns repository name
1004
- *
1005
- * @return repository name
1006
- */
1007
- public String repositoryName () {
1008
- return repositoryName ;
1009
- }
1010
-
1011
- /**
1012
- * Returns snapshot name
1013
- *
1014
- * @return snapshot name
1015
- */
1016
- public String snapshotName () {
1017
- return snapshotName ;
1018
- }
1019
-
1020
- /**
1021
- * Return the list of indices to be restored
1022
- *
1023
- * @return the list of indices
1024
- */
1025
- public String [] indices () {
1026
- return indices ;
1027
- }
1028
-
1029
- /**
1030
- * Returns indices option flags
1031
- *
1032
- * @return indices options flags
1033
- */
1034
- public IndicesOptions indicesOptions () {
1035
- return indicesOptions ;
1036
- }
1037
-
1038
- /**
1039
- * Returns rename pattern
1040
- *
1041
- * @return rename pattern
1042
- */
1043
- public String renamePattern () {
1044
- return renamePattern ;
1045
- }
1046
-
1047
- /**
1048
- * Returns replacement pattern
1049
- *
1050
- * @return replacement pattern
1051
- */
1052
- public String renameReplacement () {
1053
- return renameReplacement ;
1054
- }
1055
-
1056
- /**
1057
- * Returns repository-specific restore settings
1058
- *
1059
- * @return restore settings
1060
- */
1061
- public Settings settings () {
1062
- return settings ;
1063
- }
1064
-
1065
- /**
1066
- * Returns true if global state should be restore during this restore operation
1067
- *
1068
- * @return restore global state flag
1069
- */
1070
- public boolean includeGlobalState () {
1071
- return includeGlobalState ;
1072
- }
1073
-
1074
- /**
1075
- * Returns true if incomplete indices will be restored
1076
- *
1077
- * @return partial indices restore flag
1078
- */
1079
- public boolean partial () {
1080
- return partial ;
1081
- }
1082
-
1083
- /**
1084
- * Returns true if aliases should be restore during this restore operation
1085
- *
1086
- * @return restore aliases state flag
1087
- */
1088
- public boolean includeAliases () {
1089
- return includeAliases ;
1090
- }
1091
-
1092
- /**
1093
- * Returns index settings that should be changed on restore
1094
- *
1095
- * @return restore aliases state flag
1096
- */
1097
- public Settings indexSettings () {
1098
- return indexSettings ;
1099
- }
1100
-
1101
- /**
1102
- * Returns index settings that that shouldn't be restored
1103
- *
1104
- * @return restore aliases state flag
1105
- */
1106
- public String [] ignoreIndexSettings () {
1107
- return ignoreIndexSettings ;
1108
- }
1109
-
1110
-
1111
- /**
1112
- * Return master node timeout
1113
- *
1114
- * @return master node timeout
1115
- */
1116
- public TimeValue masterNodeTimeout () {
1117
- return masterNodeTimeout ;
1118
- }
1119
-
1120
- }
1121
923
}
0 commit comments