@@ -157,11 +157,15 @@ protected Clock getClock() {
157157 * and throws an exception otherwise.
158158 * This check should be called before installing any x-pack metadata to the cluster state,
159159 * to ensure that the other nodes that are part of the cluster will be able to deserialize
160- * that metadata.
160+ * that metadata. Note that if the cluster state already contains x-pack metadata, this
161+ * check assumes that the nodes are already ready to receive additional x-pack metadata.
161162 * Having this check properly in place everywhere allows to install x-pack into a cluster
162163 * using a rolling restart.
163164 */
164165 public static void checkReadyForXPackCustomMetadata (ClusterState clusterState ) {
166+ if (alreadyContainsXPackCustomMetadata (clusterState )) {
167+ return ;
168+ }
165169 List <DiscoveryNode > notReadyNodes = nodesNotReadyForXPackCustomMetadata (clusterState );
166170 if (notReadyNodes .isEmpty () == false ) {
167171 throw new IllegalStateException ("The following nodes are not ready yet for enabling x-pack custom metadata: " + notReadyNodes );
@@ -173,25 +177,15 @@ public static void checkReadyForXPackCustomMetadata(ClusterState clusterState) {
173177 * See {@link #checkReadyForXPackCustomMetadata} for more details.
174178 */
175179 public static boolean isReadyForXPackCustomMetadata (ClusterState clusterState ) {
176- return nodesNotReadyForXPackCustomMetadata (clusterState ).isEmpty ();
180+ return alreadyContainsXPackCustomMetadata ( clusterState ) || nodesNotReadyForXPackCustomMetadata (clusterState ).isEmpty ();
177181 }
178182
179183 /**
180184 * Returns the list of nodes that won't allow this node from adding x-pack metadata to the cluster state.
181185 * See {@link #checkReadyForXPackCustomMetadata} for more details.
182186 */
183187 public static List <DiscoveryNode > nodesNotReadyForXPackCustomMetadata (ClusterState clusterState ) {
184- // check if there's already x-pack metadata in the cluster state; if so, any further metadata won't hurt
185- final MetaData metaData = clusterState .metaData ();
186- if (metaData .custom (LicensesMetaData .TYPE ) != null ||
187- metaData .custom (MLMetadataField .TYPE ) != null ||
188- metaData .custom (WatcherMetaData .TYPE ) != null ||
189- clusterState .custom (TokenMetaData .TYPE ) != null ) {
190- return Collections .emptyList ();
191- }
192-
193- // if there's no x-pack metadata yet in the cluster state, check that all nodes would be capable
194- // of deserializing newly added x-pack metadata
188+ // check that all nodes would be capable of deserializing newly added x-pack metadata
195189 final List <DiscoveryNode > notReadyNodes = StreamSupport .stream (clusterState .nodes ().spliterator (), false ).filter (node -> {
196190 final String xpackInstalledAttr = node .getAttributes ().getOrDefault (XPACK_INSTALLED_NODE_ATTR , "false" );
197191
@@ -204,6 +198,14 @@ public static List<DiscoveryNode> nodesNotReadyForXPackCustomMetadata(ClusterSta
204198 return notReadyNodes ;
205199 }
206200
201+ private static boolean alreadyContainsXPackCustomMetadata (ClusterState clusterState ) {
202+ final MetaData metaData = clusterState .metaData ();
203+ return metaData .custom (LicensesMetaData .TYPE ) != null ||
204+ metaData .custom (MLMetadataField .TYPE ) != null ||
205+ metaData .custom (WatcherMetaData .TYPE ) != null ||
206+ clusterState .custom (TokenMetaData .TYPE ) != null ;
207+ }
208+
207209 @ Override
208210 public Settings additionalSettings () {
209211 final String xpackInstalledNodeAttrSetting = "node.attr." + XPACK_INSTALLED_NODE_ATTR ;
0 commit comments