@@ -49,40 +49,48 @@ public class CoordinationMetaData implements Writeable, ToXContentFragment {
49
49
50
50
private final VotingConfiguration lastAcceptedConfiguration ;
51
51
52
- private final Set <DiscoveryNode > votingTombstones ;
52
+ private final Set <VotingTombstone > votingTombstones ;
53
53
54
54
private static final ParseField TERM_PARSE_FIELD = new ParseField ("term" );
55
55
private static final ParseField LAST_COMMITTED_CONFIGURATION_FIELD = new ParseField ("last_committed_config" );
56
56
private static final ParseField LAST_ACCEPTED_CONFIGURATION_FIELD = new ParseField ("last_accepted_config" );
57
+ private static final ParseField VOTING_TOMBSTONES_FIELD = new ParseField ("voting_tombstones" );
57
58
58
59
private static long term (Object [] termAndConfigs ) {
59
60
return (long )termAndConfigs [0 ];
60
61
}
61
62
62
63
@ SuppressWarnings ("unchecked" )
63
- private static VotingConfiguration lastCommittedConfig (Object [] termAndConfig ) {
64
- List <String > nodeIds = (List <String >) termAndConfig [1 ];
64
+ private static VotingConfiguration lastCommittedConfig (Object [] fields ) {
65
+ List <String > nodeIds = (List <String >) fields [1 ];
65
66
return new VotingConfiguration (new HashSet <>(nodeIds ));
66
67
}
67
68
68
69
@ SuppressWarnings ("unchecked" )
69
- private static VotingConfiguration lastAcceptedConfig (Object [] termAndConfig ) {
70
- List <String > nodeIds = (List <String >) termAndConfig [2 ];
70
+ private static VotingConfiguration lastAcceptedConfig (Object [] fields ) {
71
+ List <String > nodeIds = (List <String >) fields [2 ];
71
72
return new VotingConfiguration (new HashSet <>(nodeIds ));
72
73
}
73
74
75
+ @ SuppressWarnings ("unchecked" )
76
+ private static Set <VotingTombstone > votingTombstones (Object [] fields ) {
77
+ Set <VotingTombstone > votingTombstones = new HashSet <>((List <VotingTombstone >) fields [3 ]);
78
+ return votingTombstones ;
79
+ }
80
+
74
81
private static final ConstructingObjectParser <CoordinationMetaData , Void > PARSER = new ConstructingObjectParser <>(
75
82
"coordination_metadata" ,
76
- termAndConfigs -> new CoordinationMetaData (term (termAndConfigs ), lastCommittedConfig (termAndConfigs ),
77
- lastAcceptedConfig (termAndConfigs ), Collections . emptySet ( )));
83
+ fields -> new CoordinationMetaData (term (fields ), lastCommittedConfig (fields ),
84
+ lastAcceptedConfig (fields ), votingTombstones ( fields )));
78
85
static {
79
86
PARSER .declareLong (ConstructingObjectParser .constructorArg (), TERM_PARSE_FIELD );
80
87
PARSER .declareStringArray (ConstructingObjectParser .constructorArg (), LAST_COMMITTED_CONFIGURATION_FIELD );
81
88
PARSER .declareStringArray (ConstructingObjectParser .constructorArg (), LAST_ACCEPTED_CONFIGURATION_FIELD );
89
+ PARSER .declareObjectArray (ConstructingObjectParser .constructorArg (), VotingTombstone .PARSER , VOTING_TOMBSTONES_FIELD );
82
90
}
83
91
84
92
public CoordinationMetaData (long term , VotingConfiguration lastCommittedConfiguration , VotingConfiguration lastAcceptedConfiguration ,
85
- Set <DiscoveryNode > votingTombstones ) {
93
+ Set <VotingTombstone > votingTombstones ) {
86
94
this .term = term ;
87
95
this .lastCommittedConfiguration = lastCommittedConfiguration ;
88
96
this .lastAcceptedConfiguration = lastAcceptedConfiguration ;
@@ -93,7 +101,7 @@ public CoordinationMetaData(StreamInput in) throws IOException {
93
101
term = in .readLong ();
94
102
lastCommittedConfiguration = new VotingConfiguration (in );
95
103
lastAcceptedConfiguration = new VotingConfiguration (in );
96
- votingTombstones = Collections .unmodifiableSet (in .readSet (DiscoveryNode ::new ));
104
+ votingTombstones = Collections .unmodifiableSet (in .readSet (VotingTombstone ::new ));
97
105
}
98
106
99
107
public static Builder builder () {
@@ -117,8 +125,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
117
125
return builder
118
126
.field (TERM_PARSE_FIELD .getPreferredName (), term )
119
127
.field (LAST_COMMITTED_CONFIGURATION_FIELD .getPreferredName (), lastCommittedConfiguration )
120
- .field (LAST_ACCEPTED_CONFIGURATION_FIELD .getPreferredName (), lastAcceptedConfiguration );
121
- // TODO include voting tombstones here
128
+ .field (LAST_ACCEPTED_CONFIGURATION_FIELD .getPreferredName (), lastAcceptedConfiguration )
129
+ . field ( VOTING_TOMBSTONES_FIELD . getPreferredName (), votingTombstones );
122
130
}
123
131
124
132
public static CoordinationMetaData fromXContent (XContentParser parser ) throws IOException {
@@ -137,7 +145,7 @@ public VotingConfiguration getLastCommittedConfiguration() {
137
145
return lastCommittedConfiguration ;
138
146
}
139
147
140
- public Set <DiscoveryNode > getVotingTombstones () {
148
+ public Set <VotingTombstone > getVotingTombstones () {
141
149
return votingTombstones ;
142
150
}
143
151
@@ -177,7 +185,7 @@ public static class Builder {
177
185
private long term = 0 ;
178
186
private VotingConfiguration lastCommittedConfiguration = VotingConfiguration .EMPTY_CONFIG ;
179
187
private VotingConfiguration lastAcceptedConfiguration = VotingConfiguration .EMPTY_CONFIG ;
180
- private final Set <DiscoveryNode > votingTombstones = new HashSet <>();
188
+ private final Set <VotingTombstone > votingTombstones = new HashSet <>();
181
189
182
190
public Builder () {
183
191
@@ -205,7 +213,7 @@ public Builder lastAcceptedConfiguration(VotingConfiguration config) {
205
213
return this ;
206
214
}
207
215
208
- public Builder addVotingTombstone (DiscoveryNode tombstone ) {
216
+ public Builder addVotingTombstone (VotingTombstone tombstone ) {
209
217
votingTombstones .add (tombstone );
210
218
return this ;
211
219
}
@@ -220,6 +228,97 @@ public CoordinationMetaData build() {
220
228
}
221
229
}
222
230
231
+ public static class VotingTombstone implements Writeable , ToXContentFragment {
232
+ private final String nodeId ;
233
+ private final String nodeName ;
234
+
235
+ public VotingTombstone (DiscoveryNode node ) {
236
+ this (node .getId (), node .getName ());
237
+ }
238
+
239
+ public VotingTombstone (StreamInput in ) throws IOException {
240
+ this .nodeId = in .readString ();
241
+ this .nodeName = in .readString ();
242
+ }
243
+
244
+ public VotingTombstone (String nodeId , String nodeName ) {
245
+ this .nodeId = nodeId ;
246
+ this .nodeName = nodeName ;
247
+ }
248
+
249
+ @ Override
250
+ public void writeTo (StreamOutput out ) throws IOException {
251
+ out .writeString (nodeId );
252
+ out .writeString (nodeName );
253
+ }
254
+
255
+ public String getNodeId () {
256
+ return nodeId ;
257
+ }
258
+
259
+ public String getNodeName () {
260
+ return nodeName ;
261
+ }
262
+
263
+ private static final ParseField NODE_ID_PARSE_FIELD = new ParseField ("node_id" );
264
+ private static final ParseField NODE_NAME_PARSE_FIELD = new ParseField ("node_name" );
265
+
266
+ private static String nodeId (Object [] nodeIdAndName ) {
267
+ return (String ) nodeIdAndName [0 ];
268
+ }
269
+
270
+ private static String nodeName (Object [] nodeIdAndName ) {
271
+ return (String ) nodeIdAndName [1 ];
272
+ }
273
+
274
+ private static final ConstructingObjectParser <VotingTombstone , Void > PARSER = new ConstructingObjectParser <>(
275
+ "voting_tombstone" ,
276
+ nodeIdAndName -> new VotingTombstone (nodeId (nodeIdAndName ), nodeName (nodeIdAndName ))
277
+ );
278
+
279
+ static {
280
+ PARSER .declareString (ConstructingObjectParser .constructorArg (), NODE_ID_PARSE_FIELD );
281
+ PARSER .declareString (ConstructingObjectParser .constructorArg (), NODE_NAME_PARSE_FIELD );
282
+ }
283
+
284
+ public static VotingTombstone fromXContent (XContentParser parser ) throws IOException {
285
+ return PARSER .parse (parser , null );
286
+ }
287
+
288
+ @ Override
289
+ public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
290
+ return builder .startObject ()
291
+ .field (NODE_ID_PARSE_FIELD .getPreferredName (), nodeId )
292
+ .field (NODE_NAME_PARSE_FIELD .getPreferredName (), nodeName )
293
+ .endObject ();
294
+ }
295
+
296
+ @ Override
297
+ public boolean equals (Object o ) {
298
+ if (this == o ) return true ;
299
+ if (o == null || getClass () != o .getClass ()) return false ;
300
+ VotingTombstone that = (VotingTombstone ) o ;
301
+ return Objects .equals (nodeId , that .nodeId ) &&
302
+ Objects .equals (nodeName , that .nodeName );
303
+ }
304
+
305
+ @ Override
306
+ public int hashCode () {
307
+ return Objects .hash (nodeId , nodeName );
308
+ }
309
+
310
+ @ Override
311
+ public String toString () {
312
+ StringBuilder sb = new StringBuilder ();
313
+ if (nodeName .length () > 0 ) {
314
+ sb .append ('{' ).append (nodeName ).append ('}' );
315
+ }
316
+ sb .append ('{' ).append (nodeId ).append ('}' );
317
+ return sb .toString ();
318
+ }
319
+
320
+ }
321
+
223
322
/**
224
323
* A collection of persistent node ids, denoting the voting configuration for cluster state changes.
225
324
*/
0 commit comments