Skip to content

Commit

Permalink
IGNITE-12111 Cluster ID and tag to identify cluster - Fixes apache#7922.
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Kasnacheev <[email protected]>
  • Loading branch information
Sergey Chugunov authored and alamar committed Jun 22, 2020
1 parent 16a7035 commit 385ff65
Show file tree
Hide file tree
Showing 13 changed files with 1,559 additions and 6 deletions.
42 changes: 41 additions & 1 deletion modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
* caching nodes, and get other useful information about topology.
*/
public interface IgniteCluster extends ClusterGroup, IgniteAsyncSupport {
/**
* Maximum length of {@link IgniteCluster#tag()} tag.
*/
public static final int MAX_TAG_LENGTH = 280;

/**
* Gets local grid node.
*
Expand Down Expand Up @@ -558,9 +563,44 @@ public IgniteFuture<Collection<ClusterStartNodeResult>> startNodesAsync(Collecti
*/
public boolean isWalEnabled(String cacheName);

/**
* Cluster ID is a unique identifier automatically generated when cluster starts up for the very first time.
*
* It is a cluster-wide property so all nodes of the cluster (including client nodes) return the same value.
*
* In in-memory clusters ID is generated again upon each cluster restart.
* In clusters running in persistent mode cluster ID is stored to disk and is used even after full cluster restart.
*
* @return Unique cluster ID.
*/
public UUID id();

/**
* User-defined tag describing the cluster.
*
* @return Current tag value same across all nodes of the cluster.
*/
public String tag();

/**
* Enables user to add a specific label to the cluster e.g. to describe purpose of the cluster
* or any its characteristics.
* Tag is set cluster-wide,
* value set on one node will be distributed across all nodes (including client nodes) in the cluster.
*
* Maximum tag length is limited by {@link #MAX_TAG_LENGTH} value.
*
* @param tag New tag to be set.
*
* @throws IgniteCheckedException In case tag change is requested on inactive cluster
* or concurrent tag change request was completed before the current one.
* Also provided tag is checked for max length.
*/
public void tag(String tag) throws IgniteCheckedException;

/**
* @return Value of manual baseline control or auto adjusting baseline. {@code True} If cluster in auto-adjust.
* {@code False} If cluster in manuale.
* {@code False} If cluster in manual.
*/
public boolean isBaselineAutoAdjustEnabled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,21 @@ public IgniteClusterAsyncImpl(IgniteClusterImpl cluster) {
return cluster.isWalEnabled(cacheName);
}

/** {@inheritDoc} */
@Override public UUID id() {
return cluster.id();
}

/** {@inheritDoc} */
@Override public String tag() {
return cluster.tag();
}

/** {@inheritDoc} */
@Override public void tag(String tag) throws IgniteCheckedException {
cluster.tag(tag);
}

/** {@inheritDoc} */
@Override public boolean isBaselineAutoAdjustEnabled() {
return cluster.isBaselineAutoAdjustEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public class IgniteClusterImpl extends ClusterGroupAdapter implements IgniteClus
/** Minimal IgniteProductVersion supporting BaselineTopology */
private static final IgniteProductVersion MIN_BLT_SUPPORTING_VER = IgniteProductVersion.fromString("2.4.0");

/** Unique ID of cluster. Generated on start, shared by all nodes. */
private volatile UUID id;

/** User-defined human-readable tag. Generated automatically on start, can be changed later. */
private volatile String tag;

/**
* Required by {@link Externalizable}.
*/
Expand Down Expand Up @@ -639,6 +645,65 @@ private boolean changeWalMode(String cacheName, boolean enabled) {
}
}

/** {@inheritDoc} */
@Override public UUID id() {
return id;
}

/**
* Not part of public API.
* Enables ClusterProcessor to set ID in the following cases:
* <ol>
* <li>For the first time on node startup.</li>
* <li>Set to null on client disconnect.</li>
* <li>Set to some not-null value on client reconnect.</li>
* </ol>
*
* @param id ID to set.
*/
public void setId(UUID id) {
this.id = id;
}

/** {@inheritDoc} */
@Override public String tag() {
return tag;
}

/** {@inheritDoc} */
@Override public void tag(String tag) throws IgniteCheckedException {
if (tag == null || tag.isEmpty())
throw new IgniteCheckedException("Please provide not-null and not empty string for cluster tag");

if (tag.length() > MAX_TAG_LENGTH) {
throw new IgniteCheckedException("Maximum tag length is exceeded, max length is " +
MAX_TAG_LENGTH +
" symbols, provided value has " +
tag.length() +
" symbols.");
}

if (!ctx.state().publicApiActiveState(true))
throw new IgniteCheckedException("Can not change cluster tag on inactive cluster. To activate the cluster call Ignite.active(true).");

ctx.cluster().updateTag(tag);
}

/**
* Not part of public API.
* Enables ClusterProcessor to set tag in the following cases:
* <ol>
* <li>For the first time on node startup.</li>
* <li>Set to null on client disconnect.</li>
* <li>Set to some not-null value on client reconnect.</li>
* </ol>
*
* @param tag Tag to set.
*/
public void setTag(@Nullable String tag) {
this.tag = tag;
}

/** {@inheritDoc} */
@Override public boolean isBaselineAutoAdjustEnabled() {
return ctx.state().isBaselineAutoAdjustEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ else if (customMsg instanceof ChangeGlobalStateMessage) {
ctx.authentication().onLocalJoin();

ctx.encryption().onLocalJoin();

ctx.cluster().onLocalJoin();
}

IgniteInternalFuture<Boolean> transitionWaitFut = ctx.state().onLocalJoin(discoCache);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.processors.cluster;

import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;
import org.apache.ignite.internal.util.typedef.internal.S;

/**
* Container class to send cluster ID and tag in disco data and to write them atomically to metastorage.
*/
public class ClusterIdAndTag implements Serializable {
/** */
private static final long serialVersionUID = 0L;

/** */
private final UUID id;

/** */
private final String tag;

/**
* @param id Cluster ID.
* @param tag Cluster tag.
*/
public ClusterIdAndTag(UUID id, String tag) {
this.id = id;
this.tag = tag;
}

/**
* @return Value of cluster id.
*/
public UUID id() {
return id;
}

/**
* @return Value of cluster tag.
*/
public String tag() {
return tag;
}

/** {@inheritDoc} */
@Override public int hashCode() {
return Objects.hash(id, tag);
}

/** {@inheritDoc} */
@Override public boolean equals(Object obj) {
if (!(obj instanceof ClusterIdAndTag))
return false;

ClusterIdAndTag idAndTag = (ClusterIdAndTag)obj;

return id.equals(idAndTag.id) && tag.equals(idAndTag.tag);
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(ClusterIdAndTag.class, this);
}
}
Loading

0 comments on commit 385ff65

Please sign in to comment.