Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "content" tier as new "data_content" role #62247

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
import java.util.Set;

/**
* The {@code DataTier} class encapsulates the formalization of the "hot",
* "warm", "cold", and "frozen" tiers as node roles. In contains the roles
* themselves as well as helpers for validation and determining if a node has
* a tier configured.
* The {@code DataTier} class encapsulates the formalization of the "content",
* "hot", "warm", "cold", and "frozen" tiers as node roles. In contains the
* roles themselves as well as helpers for validation and determining if a node
* has a tier configured.
*
* Related:
* {@link org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider}
*/
public class DataTier {

public static final String DATA_CONTENT = "data_content";
public static final String DATA_HOT = "data_hot";
public static final String DATA_WARM = "data_warm";
public static final String DATA_COLD = "data_cold";
Expand All @@ -38,7 +39,8 @@ public class DataTier {
* Returns true if the given tier name is a valid tier
*/
public static boolean validTierName(String tierName) {
return DATA_HOT.equals(tierName) ||
return DATA_CONTENT.equals(tierName) ||
DATA_HOT.equals(tierName) ||
DATA_WARM.equals(tierName) ||
DATA_COLD.equals(tierName) ||
DATA_FROZEN.equals(tierName);
Expand All @@ -61,6 +63,23 @@ public static boolean isExplicitDataTier(Settings settings) {
return false;
}

public static DiscoveryNodeRole DATA_CONTENT_NODE_ROLE = new DiscoveryNodeRole("data_content", "s") {
@Override
public boolean isEnabledByDefault(final Settings settings) {
return false;
}

@Override
public Setting<Boolean> legacySetting() {
return null;
}

@Override
public boolean canContainData() {
return true;
}
};

public static DiscoveryNodeRole DATA_HOT_NODE_ROLE = new DiscoveryNodeRole("data_hot", "h") {
@Override
public boolean isEnabledByDefault(final Settings settings) {
Expand Down Expand Up @@ -129,6 +148,10 @@ public boolean canContainData() {
}
};

public static boolean isContentNode(DiscoveryNode discoveryNode) {
return discoveryNode.getRoles().contains(DATA_CONTENT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE);
}

public static boolean isHotNode(DiscoveryNode discoveryNode) {
return discoveryNode.getRoles().contains(DATA_HOT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ public List<Setting<?>> getSettings() {
@Override
public Set<DiscoveryNodeRole> getRoles() {
return new HashSet<>(Arrays.asList(
DataTier.DATA_CONTENT_NODE_ROLE,
DataTier.DATA_HOT_NODE_ROLE,
DataTier.DATA_WARM_NODE_ROLE,
DataTier.DATA_COLD_NODE_ROLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public void testNodeSelection() {
.map(DiscoveryNode::getId)
.toArray(String[]::new);

final String[] contentNodes =
StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false)
.map(n -> n.value)
.filter(DataTier::isContentNode)
.map(DiscoveryNode::getId)
.toArray(String[]::new);

final String[] hotNodes =
StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false)
.map(n -> n.value)
Expand Down Expand Up @@ -69,11 +76,13 @@ public void testNodeSelection() {
.toArray(String[]::new);

assertThat(discoveryNodes.resolveNodes("data:true"), arrayContainingInAnyOrder(dataNodes));
assertThat(discoveryNodes.resolveNodes("data_content:true"), arrayContainingInAnyOrder(contentNodes));
assertThat(discoveryNodes.resolveNodes("data_hot:true"), arrayContainingInAnyOrder(hotNodes));
assertThat(discoveryNodes.resolveNodes("data_warm:true"), arrayContainingInAnyOrder(warmNodes));
assertThat(discoveryNodes.resolveNodes("data_cold:true"), arrayContainingInAnyOrder(coldNodes));
assertThat(discoveryNodes.resolveNodes("data_frozen:true"), arrayContainingInAnyOrder(frozenNodes));
Set<String> allTiers = new HashSet<>(Arrays.asList(hotNodes));
Set<String> allTiers = new HashSet<>(Arrays.asList(contentNodes));
allTiers.addAll(Arrays.asList(hotNodes));
allTiers.addAll(Arrays.asList(warmNodes));
allTiers.addAll(Arrays.asList(coldNodes));
allTiers.addAll(Arrays.asList(frozenNodes));
Expand All @@ -100,6 +109,7 @@ private static DiscoveryNode newNode(int nodeId, Map<String, String> attributes,
private static List<DiscoveryNode> randomNodes(final int numNodes) {
Set<DiscoveryNodeRole> allRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES);
allRoles.remove(DiscoveryNodeRole.DATA_ROLE);
allRoles.add(DataTier.DATA_CONTENT_NODE_ROLE);
allRoles.add(DataTier.DATA_HOT_NODE_ROLE);
allRoles.add(DataTier.DATA_WARM_NODE_ROLE);
allRoles.add(DataTier.DATA_COLD_NODE_ROLE);
Expand Down