Skip to content

Commit

Permalink
Rename NodeEnvironment.NodePath to DataPath (#86942)
Browse files Browse the repository at this point in the history
The NodePath inner class of NodeEnvironment represents path.data entries
of the node. The name however is sometimes confusing since these are the
data paths, and there is normally no singular concept of "node path" (an
installation has several different paths). This commit renames NodePath
to DataPath, as well as all methods and variables referring to it, so
that the more general term "node paths" can be utilized for something
node wide: the paths in environment (in a future PR).
  • Loading branch information
rjernst committed May 19, 2022
1 parent a445cd0 commit e87b786
Show file tree
Hide file tree
Showing 29 changed files with 289 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
@State(Scope.Benchmark)
public class AvailableIndexFoldersBenchmark {

private NodeEnvironment.NodePath nodePath;
private NodeEnvironment.DataPath dataPath;
private NodeEnvironment nodeEnv;
private Set<String> excludedDirs;

@Setup
public void setup() throws IOException {
Path path = Files.createTempDirectory("test");
String[] paths = new String[] { path.toString() };
nodePath = new NodeEnvironment.NodePath(path);
dataPath = new NodeEnvironment.DataPath(path);

LogConfigurator.setNodeName("test");
Settings settings = Settings.builder()
Expand All @@ -54,30 +54,30 @@ public void setup() throws IOException {
.build();
nodeEnv = new NodeEnvironment(settings, new Environment(settings, null));

Files.createDirectories(nodePath.indicesPath);
Files.createDirectories(dataPath.indicesPath);
excludedDirs = new HashSet<>();
int numIndices = 5000;
for (int i = 0; i < numIndices; i++) {
String dirName = "dir" + i;
Files.createDirectory(nodePath.indicesPath.resolve(dirName));
Files.createDirectory(dataPath.indicesPath.resolve(dirName));
excludedDirs.add(dirName);
}
if (nodeEnv.availableIndexFoldersForPath(nodePath).size() != numIndices) {
if (nodeEnv.availableIndexFoldersForPath(dataPath).size() != numIndices) {
throw new IllegalStateException("bad size");
}
if (nodeEnv.availableIndexFoldersForPath(nodePath, excludedDirs::contains).size() != 0) {
if (nodeEnv.availableIndexFoldersForPath(dataPath, excludedDirs::contains).size() != 0) {
throw new IllegalStateException("bad size");
}
}

@Benchmark
public Set<String> availableIndexFolderNaive() throws IOException {
return nodeEnv.availableIndexFoldersForPath(nodePath);
return nodeEnv.availableIndexFoldersForPath(dataPath);
}

@Benchmark
public Set<String> availableIndexFolderOptimized() throws IOException {
return nodeEnv.availableIndexFoldersForPath(nodePath, excludedDirs::contains);
return nodeEnv.availableIndexFoldersForPath(dataPath, excludedDirs::contains);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public void testCorruptIndex() throws Exception {
final MockTerminal terminal = new MockTerminal();
final OptionParser parser = command.getParser();

final Settings nodePathSettings = internalCluster().dataPathSettings(node);
final Settings dataPathSettings = internalCluster().dataPathSettings(node);

final Environment environment = TestEnvironment.newEnvironment(
Settings.builder().put(internalCluster().getDefaultSettings()).put(nodePathSettings).build()
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build()
);
final OptionSet options = parser.parse("-index", indexName, "-shard-id", "0");

Expand Down Expand Up @@ -663,7 +663,7 @@ public static Path getPathToShardData(String nodeId, ShardId shardId, String sha
final NodesStatsResponse nodeStatsResponse = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get();
final Set<Path> paths = StreamSupport.stream(nodeStatsResponse.getNodes().get(0).getFs().spliterator(), false)
.map(
nodePath -> PathUtils.get(nodePath.getPath())
dataPath -> PathUtils.get(dataPath.getPath())
.resolve(NodeEnvironment.INDICES_FOLDER)
.resolve(shardId.getIndex().getUUID())
.resolve(Integer.toString(shardId.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DetachClusterCommand() {
}

@Override
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
protected void processDataPaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);

terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ public static Tuple<Long, ClusterState> loadTermAndClusterState(PersistedCluster
return Tuple.tuple(bestOnDiskState.currentTerm, clusterState(env, bestOnDiskState));
}

protected void processNodePaths(Terminal terminal, OptionSet options, Environment env) throws IOException, UserException {
protected void processDataPaths(Terminal terminal, OptionSet options, Environment env) throws IOException, UserException {
terminal.println(Terminal.Verbosity.VERBOSE, "Obtaining lock for node");
try (NodeEnvironment.NodeLock lock = new NodeEnvironment.NodeLock(logger, env, Files::exists)) {
final Path[] dataPaths = Arrays.stream(lock.getNodePaths()).filter(Objects::nonNull).map(p -> p.path).toArray(Path[]::new);
final Path[] dataPaths = Arrays.stream(lock.getDataPaths()).filter(Objects::nonNull).map(p -> p.path).toArray(Path[]::new);
if (dataPaths.length == 0) {
throw new ElasticsearchException(NO_NODE_FOLDER_FOUND_MSG);
}
processNodePaths(terminal, dataPaths, options, env);
processDataPaths(terminal, dataPaths, options, env);
} catch (LockObtainFailedException e) {
throw new ElasticsearchException(FAILED_TO_OBTAIN_NODE_LOCK_MSG, e);
}
Expand All @@ -156,7 +156,7 @@ protected static void confirm(Terminal terminal, String msg) {
public final void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
terminal.println(STOP_WARNING_MSG);
if (validateBeforeLock(terminal, env)) {
processNodePaths(terminal, options, env);
processDataPaths(terminal, options, env);
}
}

Expand All @@ -177,16 +177,16 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) {
* @param options the command line options
* @param env the env of the node to process
*/
protected abstract void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException,
protected abstract void processDataPaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException,
UserException;

protected static NodeEnvironment.NodePath[] toNodePaths(Path[] dataPaths) {
return Arrays.stream(dataPaths).map(ElasticsearchNodeCommand::createNodePath).toArray(NodeEnvironment.NodePath[]::new);
protected static NodeEnvironment.DataPath[] toDataPaths(Path[] paths) {
return Arrays.stream(paths).map(ElasticsearchNodeCommand::createDataPath).toArray(NodeEnvironment.DataPath[]::new);
}

private static NodeEnvironment.NodePath createNodePath(Path path) {
private static NodeEnvironment.DataPath createDataPath(Path path) {
try {
return new NodeEnvironment.NodePath(path);
return new NodeEnvironment.DataPath(path);
} catch (IOException e) {
throw new ElasticsearchException("Unable to investigate path [" + path + "]", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public RemoveCustomsCommand() {
}

@Override
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException,
protected void processDataPaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException,
UserException {
final List<String> customsToRemove = arguments.values(options);
if (customsToRemove.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RemoveSettingsCommand() {
}

@Override
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException,
protected void processDataPaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException,
UserException {
final List<String> settingsToRemove = arguments.values(options);
if (settingsToRemove.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) {
return true;
}

protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
protected void processDataPaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);

final Tuple<Long, ClusterState> state = loadTermAndClusterState(persistedClusterStateService, env);
Expand Down

0 comments on commit e87b786

Please sign in to comment.