19
19
20
20
public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep {
21
21
public static final String NAME = "shrunk-shards-allocated" ;
22
- private final int numberOfShards ;
23
22
private String shrunkIndexPrefix ;
24
23
25
- public ShrunkShardsAllocatedStep (StepKey key , StepKey nextStepKey , int numberOfShards , String shrunkIndexPrefix ) {
24
+ public ShrunkShardsAllocatedStep (StepKey key , StepKey nextStepKey , String shrunkIndexPrefix ) {
26
25
super (key , nextStepKey );
27
- this .numberOfShards = numberOfShards ;
28
26
this .shrunkIndexPrefix = shrunkIndexPrefix ;
29
27
}
30
28
31
- public int getNumberOfShards () {
32
- return numberOfShards ;
33
- }
34
-
35
29
String getShrunkIndexPrefix () {
36
30
return shrunkIndexPrefix ;
37
31
}
@@ -42,23 +36,22 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
42
36
// active
43
37
boolean indexExists = clusterState .metaData ().index (shrunkIndexPrefix + index .getName ()) != null ;
44
38
if (indexExists == false ) {
45
- return new Result (false , new Info (false , -1 , - 1 , false ));
39
+ return new Result (false , new Info (false , -1 , false ));
46
40
}
47
41
boolean allShardsActive = ActiveShardCount .ALL .enoughShardsActive (clusterState , shrunkIndexPrefix + index .getName ());
48
42
int numShrunkIndexShards = clusterState .metaData ().index (shrunkIndexPrefix + index .getName ()).getNumberOfShards ();
49
- boolean isConditionMet = numShrunkIndexShards == numberOfShards && allShardsActive ;
50
- if (isConditionMet ) {
43
+ if (allShardsActive ) {
51
44
return new Result (true , null );
52
45
} else {
53
- return new Result (false , new Info (true , numberOfShards , numShrunkIndexShards , allShardsActive ));
46
+ return new Result (false , new Info (true , numShrunkIndexShards , allShardsActive ));
54
47
}
55
48
}
56
-
49
+
57
50
@ Override
58
51
public int hashCode () {
59
- return Objects .hash (super .hashCode (), numberOfShards , shrunkIndexPrefix );
52
+ return Objects .hash (super .hashCode (), shrunkIndexPrefix );
60
53
}
61
-
54
+
62
55
@ Override
63
56
public boolean equals (Object obj ) {
64
57
if (obj == null ) {
@@ -68,54 +61,42 @@ public boolean equals(Object obj) {
68
61
return false ;
69
62
}
70
63
ShrunkShardsAllocatedStep other = (ShrunkShardsAllocatedStep ) obj ;
71
- return super .equals (obj ) &&
72
- Objects .equals (numberOfShards , other .numberOfShards ) &&
73
- Objects .equals (shrunkIndexPrefix , other .shrunkIndexPrefix );
64
+ return super .equals (obj ) && Objects .equals (shrunkIndexPrefix , other .shrunkIndexPrefix );
74
65
}
75
66
76
67
public static final class Info implements ToXContentObject {
77
68
78
- private final int expectedShards ;
79
69
private final int actualShards ;
80
70
private final boolean shrunkIndexExists ;
81
71
private final boolean allShardsActive ;
82
72
private final String message ;
83
73
84
- static final ParseField EXPECTED_SHARDS = new ParseField ("expected_shards" );
85
74
static final ParseField ACTUAL_SHARDS = new ParseField ("actual_shards" );
86
75
static final ParseField SHRUNK_INDEX_EXISTS = new ParseField ("shrunk_index_exists" );
87
76
static final ParseField ALL_SHARDS_ACTIVE = new ParseField ("all_shards_active" );
88
77
static final ParseField MESSAGE = new ParseField ("message" );
89
78
static final ConstructingObjectParser <Info , Void > PARSER = new ConstructingObjectParser <>("shrunk_shards_allocated_step_info" ,
90
- a -> new Info ((boolean ) a [0 ], (int ) a [1 ], (int ) a [ 2 ], ( boolean ) a [3 ]));
79
+ a -> new Info ((boolean ) a [0 ], (int ) a [1 ], (boolean ) a [2 ]));
91
80
static {
92
81
PARSER .declareBoolean (ConstructingObjectParser .constructorArg (), SHRUNK_INDEX_EXISTS );
93
- PARSER .declareInt (ConstructingObjectParser .constructorArg (), EXPECTED_SHARDS );
94
82
PARSER .declareInt (ConstructingObjectParser .constructorArg (), ACTUAL_SHARDS );
95
83
PARSER .declareBoolean (ConstructingObjectParser .constructorArg (), ALL_SHARDS_ACTIVE );
96
84
PARSER .declareString ((i , s ) -> {}, MESSAGE );
97
85
}
98
86
99
- public Info (boolean shrunkIndexExists , int expectedShards , int actualShards , boolean allShardsActive ) {
100
- this .expectedShards = expectedShards ;
87
+ public Info (boolean shrunkIndexExists , int actualShards , boolean allShardsActive ) {
101
88
this .actualShards = actualShards ;
102
89
this .shrunkIndexExists = shrunkIndexExists ;
103
90
this .allShardsActive = allShardsActive ;
104
91
if (shrunkIndexExists == false ) {
105
92
message = "Waiting for shrunk index to be created" ;
106
- } else if (actualShards != expectedShards ) {
107
- message = "Waiting for shrunk index shards to be " + expectedShards ;
108
93
} else if (allShardsActive == false ) {
109
94
message = "Waiting for all shard copies to be active" ;
110
95
} else {
111
96
message = "" ;
112
97
}
113
98
}
114
99
115
- public int getExpectedShards () {
116
- return expectedShards ;
117
- }
118
-
119
100
public int getActualShards () {
120
101
return actualShards ;
121
102
}
@@ -133,7 +114,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
133
114
builder .startObject ();
134
115
builder .field (MESSAGE .getPreferredName (), message );
135
116
builder .field (SHRUNK_INDEX_EXISTS .getPreferredName (), shrunkIndexExists );
136
- builder .field (EXPECTED_SHARDS .getPreferredName (), expectedShards );
137
117
builder .field (ACTUAL_SHARDS .getPreferredName (), actualShards );
138
118
builder .field (ALL_SHARDS_ACTIVE .getPreferredName (), allShardsActive );
139
119
builder .endObject ();
@@ -142,7 +122,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
142
122
143
123
@ Override
144
124
public int hashCode () {
145
- return Objects .hash (shrunkIndexExists , expectedShards , actualShards , allShardsActive );
125
+ return Objects .hash (shrunkIndexExists , actualShards , allShardsActive );
146
126
}
147
127
148
128
@ Override
@@ -155,7 +135,6 @@ public boolean equals(Object obj) {
155
135
}
156
136
Info other = (Info ) obj ;
157
137
return Objects .equals (shrunkIndexExists , other .shrunkIndexExists ) &&
158
- Objects .equals (expectedShards , other .expectedShards ) &&
159
138
Objects .equals (actualShards , other .actualShards ) &&
160
139
Objects .equals (allShardsActive , other .allShardsActive );
161
140
}
0 commit comments