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 new role for Offline Nodes #13613

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -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);
}

Comment on lines +131 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DiscoveryNode has instance methods for these too. Do we need one for the 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 @@
ensureNoFileCacheData(fileCacheNodePath);
}

if (DiscoveryNode.isOfflineNode(settings) && DiscoveryNode.getRolesFromSettings(settings).size() > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you help add tests for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are pending. will be working on adding those

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
Loading