Skip to content

Commit

Permalink
add new role for Offline Nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Bansal <[email protected]>
  • Loading branch information
linuxpi committed May 9, 2024
1 parent 48da1b8 commit f8d8f0b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public static boolean isSearchNode(Settings settings) {
return hasRole(settings, DiscoveryNodeRole.SEARCH_ROLE);
}

public static boolean isOfflineNode(Settings settings) {
return hasRole(settings, DiscoveryNodeRole.OFFLINE_ROLE);
}

private final String nodeName;
private final String nodeId;
private final String ephemeralId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ public Setting<Boolean> legacySetting() {

};

/**
* Represents the role for a Offline node, which is dedicated only to run background tasks.
*/
public static final DiscoveryNodeRole OFFLINE_ROLE = new DiscoveryNodeRole("offline", "o") {

@Override
public Setting<Boolean> legacySetting() {
// offline role is added in 2.15 so doesn't need to configure legacy setting
return null;
}
};

/**
* The built-in node roles.
*/
Expand Down
15 changes: 15 additions & 0 deletions server/src/main/java/org/opensearch/env/NodeEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Semaphore;
Expand Down Expand Up @@ -391,6 +392,20 @@ public NodeEnvironment(Settings settings, Environment environment, IndexStoreLis
ensureNoFileCacheData(fileCacheNodePath);
}

if (DiscoveryNode.isOfflineNode(settings) && DiscoveryNode.getRolesFromSettings(settings).size() > 1) {
final String message = String.format(

Check warning on line 396 in server/src/main/java/org/opensearch/env/NodeEnvironment.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/env/NodeEnvironment.java#L396

Added line #L396 was not covered by tests
Locale.ROOT,
"Offline Nodes cannot be used with any other roles, only %s role should be provided. Please remove %s roles",
DiscoveryNodeRole.OFFLINE_ROLE.roleName(),
DiscoveryNode.getRolesFromSettings(settings)
.stream()
.map(DiscoveryNodeRole::roleName)
.filter(role1 -> Objects.equals(role1, DiscoveryNodeRole.OFFLINE_ROLE.roleName()))
.collect(Collectors.joining(","))

Check warning on line 404 in server/src/main/java/org/opensearch/env/NodeEnvironment.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/env/NodeEnvironment.java#L399-L404

Added lines #L399 - L404 were not covered by tests
);
throw new IllegalStateException(message);

Check warning on line 406 in server/src/main/java/org/opensearch/env/NodeEnvironment.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/env/NodeEnvironment.java#L406

Added line #L406 was not covered by tests
}

this.nodeMetadata = loadNodeMetadata(settings, logger, nodePaths);
this.indexStoreListener = indexStoreListener;
success = true;
Expand Down

0 comments on commit f8d8f0b

Please sign in to comment.