Skip to content

Commit b4ed67d

Browse files
committed
Merge branch 'master' into translog-generation
* master: Format RemovePluginCommand to 100-column limit Add Javadocs for RemovePluginCommand#execute Avoid overflow when computing total FS stats Mark EvilJNANativesTests as awaiting fixes Format EvilJNANativesTests to 100-column limit Upgrade from JNA 4.2.2 to JNA 4.4.0 Task Manager should be able to support non-transport tasks (#23619)
2 parents b79053e + 2eafe83 commit b4ed67d

File tree

13 files changed

+194
-84
lines changed

13 files changed

+194
-84
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,6 @@
15781578
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]PluginSecurity.java" checks="LineLength" />
15791579
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]PluginsService.java" checks="LineLength" />
15801580
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]ProgressInputStream.java" checks="LineLength" />
1581-
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]RemovePluginCommand.java" checks="LineLength" />
15821581
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]RepositoryPlugin.java" checks="LineLength" />
15831582
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]ScriptPlugin.java" checks="LineLength" />
15841583
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]SearchPlugin.java" checks="LineLength" />
@@ -3945,7 +3944,6 @@
39453944
<suppress files="plugins[/\\]store-smb[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]store[/\\]smbsimplefs[/\\]SmbSimpleFsDirectoryService.java" checks="LineLength" />
39463945
<suppress files="qa[/\\]backwards-5.0[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]backwards[/\\]IndexingIT.java" checks="LineLength" />
39473946
<suppress files="qa[/\\]evil-tests[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]bootstrap[/\\]ESPolicyUnitTests.java" checks="LineLength" />
3948-
<suppress files="qa[/\\]evil-tests[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]bootstrap[/\\]EvilJNANativesTests.java" checks="LineLength" />
39493947
<suppress files="qa[/\\]evil-tests[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]bootstrap[/\\]EvilSecurityTests.java" checks="LineLength" />
39503948
<suppress files="qa[/\\]evil-tests[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]bootstrap[/\\]SystemCallFilterTests.java" checks="LineLength" />
39513949
<suppress files="qa[/\\]evil-tests[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]cli[/\\]EvilCommandTests.java" checks="LineLength" />

buildSrc/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ snakeyaml = 1.15
1010
# When updating log4j, please update also docs/java-api/index.asciidoc
1111
log4j = 2.7
1212
slf4j = 1.6.2
13-
jna = 4.2.2
13+
jna = 4.4.0
1414

1515
# test dependencies
1616
randomizedrunner = 2.5.0

core/licenses/jna-4.2.2.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/licenses/jna-4.4.0.jar.sha1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cb208278274bf12ebdb56c61bd7407e6f774d65a

core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ private double addDouble(double current, double other) {
138138

139139
public void add(Path path) {
140140
total = FsProbe.adjustForHugeFilesystems(addLong(total, path.total));
141-
free = addLong(free, path.free);
142-
available = addLong(available, path.available);
141+
free = FsProbe.adjustForHugeFilesystems(addLong(free, path.free));
142+
available = FsProbe.adjustForHugeFilesystems(addLong(available, path.available));
143143
if (path.spins != null && path.spins.booleanValue()) {
144144
// Spinning is contagious!
145145
spins = Boolean.TRUE;

core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
package org.elasticsearch.plugins;
2121

22+
import java.io.IOException;
2223
import java.nio.file.AtomicMoveNotSupportedException;
2324
import java.nio.file.Files;
2425
import java.nio.file.Path;
2526
import java.nio.file.StandardCopyOption;
2627
import java.util.ArrayList;
2728
import java.util.List;
29+
import java.util.Locale;
2830

2931
import joptsimple.OptionSet;
3032
import joptsimple.OptionSpec;
@@ -39,67 +41,93 @@
3941
import static org.elasticsearch.cli.Terminal.Verbosity.VERBOSE;
4042

4143
/**
42-
* A command for the plugin cli to remove a plugin from elasticsearch.
44+
* A command for the plugin CLI to remove a plugin from Elasticsearch.
4345
*/
4446
class RemovePluginCommand extends EnvironmentAwareCommand {
4547

4648
private final OptionSpec<String> arguments;
4749

4850
RemovePluginCommand() {
49-
super("Removes a plugin from elasticsearch");
51+
super("removes a plugin from Elasticsearch");
5052
this.arguments = parser.nonOptions("plugin name");
5153
}
5254

5355
@Override
54-
protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
55-
String arg = arguments.value(options);
56-
execute(terminal, arg, env);
56+
protected void execute(final Terminal terminal, final OptionSet options, final Environment env)
57+
throws Exception {
58+
final String pluginName = arguments.value(options);
59+
execute(terminal, pluginName, env);
5760
}
5861

59-
// pkg private for testing
60-
void execute(Terminal terminal, String pluginName, Environment env) throws Exception {
62+
/**
63+
* Remove the plugin specified by {@code pluginName}.
64+
*
65+
* @param terminal the terminal to use for input/output
66+
* @param pluginName the name of the plugin to remove
67+
* @param env the environment for the local node
68+
* @throws IOException if any I/O exception occurs while performing a file operation
69+
* @throws UserException if plugin name is null
70+
* @throws UserException if plugin directory does not exist
71+
* @throws UserException if the plugin bin directory is not a directory
72+
*/
73+
void execute(final Terminal terminal, final String pluginName, final Environment env)
74+
throws IOException, UserException {
6175
if (pluginName == null) {
6276
throw new UserException(ExitCodes.USAGE, "plugin name is required");
6377
}
6478

65-
terminal.println("-> Removing " + Strings.coalesceToEmpty(pluginName) + "...");
79+
terminal.println("-> removing [" + Strings.coalesceToEmpty(pluginName) + "]...");
6680

6781
final Path pluginDir = env.pluginsFile().resolve(pluginName);
6882
if (Files.exists(pluginDir) == false) {
69-
throw new UserException(
70-
ExitCodes.CONFIG,
71-
"plugin " + pluginName + " not found; run 'elasticsearch-plugin list' to get list of installed plugins");
83+
final String message = String.format(
84+
Locale.ROOT,
85+
"plugin [%s] not found; "
86+
+ "run 'elasticsearch-plugin list' to get list of installed plugins",
87+
pluginName);
88+
throw new UserException(ExitCodes.CONFIG, message);
7289
}
7390

7491
final List<Path> pluginPaths = new ArrayList<>();
7592

7693
final Path pluginBinDir = env.binFile().resolve(pluginName);
7794
if (Files.exists(pluginBinDir)) {
7895
if (Files.isDirectory(pluginBinDir) == false) {
79-
throw new UserException(ExitCodes.IO_ERROR, "Bin dir for " + pluginName + " is not a directory");
96+
throw new UserException(
97+
ExitCodes.IO_ERROR, "bin dir for " + pluginName + " is not a directory");
8098
}
8199
pluginPaths.add(pluginBinDir);
82-
terminal.println(VERBOSE, "Removing: " + pluginBinDir);
100+
terminal.println(VERBOSE, "removing [" + pluginBinDir + "]");
83101
}
84102

85-
terminal.println(VERBOSE, "Removing: " + pluginDir);
103+
terminal.println(VERBOSE, "removing [" + pluginDir + "]");
86104
final Path tmpPluginDir = env.pluginsFile().resolve(".removing-" + pluginName);
87105
try {
88106
Files.move(pluginDir, tmpPluginDir, StandardCopyOption.ATOMIC_MOVE);
89107
} catch (final AtomicMoveNotSupportedException e) {
90-
// this can happen on a union filesystem when a plugin is not installed on the top layer; we fall back to a non-atomic move
108+
/*
109+
* On a union file system if the plugin that we are removing is not installed on the
110+
* top layer then atomic move will not be supported. In this case, we fall back to a
111+
* non-atomic move.
112+
*/
91113
Files.move(pluginDir, tmpPluginDir);
92114
}
93115
pluginPaths.add(tmpPluginDir);
94116

95117
IOUtils.rm(pluginPaths.toArray(new Path[pluginPaths.size()]));
96118

97-
// we preserve the config files in case the user is upgrading the plugin, but we print
98-
// a message so the user knows in case they want to remove manually
119+
/*
120+
* We preserve the config files in case the user is upgrading the plugin, but we print a
121+
* message so the user knows in case they want to remove manually.
122+
*/
99123
final Path pluginConfigDir = env.configFile().resolve(pluginName);
100124
if (Files.exists(pluginConfigDir)) {
101-
terminal.println(
102-
"-> Preserving plugin config files [" + pluginConfigDir + "] in case of upgrade, delete manually if not needed");
125+
final String message = String.format(
126+
Locale.ROOT,
127+
"-> preserving plugin config files [%s] in case of upgrade; "
128+
+ "delete manually if not needed",
129+
pluginConfigDir);
130+
terminal.println(message);
103131
}
104132
}
105133

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.tasks;
21+
22+
/**
23+
* An interface for a request that can be used to register a task manager task
24+
*/
25+
public interface TaskAwareRequest {
26+
/**
27+
* Set a reference to task that caused this task to be run.
28+
*/
29+
default void setParentTask(String parentTaskNode, long parentTaskId) {
30+
setParentTask(new TaskId(parentTaskNode, parentTaskId));
31+
}
32+
33+
/**
34+
* Set a reference to task that created this request.
35+
*/
36+
void setParentTask(TaskId taskId);
37+
38+
/**
39+
* Get a reference to the task that created this request. Implementers should default to
40+
* {@link TaskId#EMPTY_TASK_ID}, meaning "there is no parent".
41+
*/
42+
TaskId getParentTask();
43+
44+
/**
45+
* Returns the task object that should be used to keep track of the processing of the request.
46+
*
47+
* A request can override this method and return null to avoid being tracked by the task
48+
* manager.
49+
*/
50+
default Task createTask(long id, String type, String action, TaskId parentTaskId) {
51+
return new Task(id, type, action, getDescription(), parentTaskId);
52+
}
53+
54+
/**
55+
* Returns optional description of the request to be displayed by the task manager
56+
*/
57+
default String getDescription() {
58+
return "";
59+
}
60+
}

core/src/main/java/org/elasticsearch/tasks/TaskManager.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,14 @@
3535
import org.elasticsearch.common.unit.TimeValue;
3636
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
3737
import org.elasticsearch.common.util.concurrent.ConcurrentMapLong;
38-
import org.elasticsearch.transport.TransportRequest;
3938

4039
import java.io.IOException;
4140
import java.util.Collections;
4241
import java.util.HashMap;
43-
import java.util.HashSet;
4442
import java.util.Iterator;
4543
import java.util.Map;
46-
import java.util.Set;
4744
import java.util.concurrent.ConcurrentHashMap;
4845
import java.util.concurrent.atomic.AtomicLong;
49-
import java.util.function.Consumer;
5046

5147
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
5248

@@ -83,7 +79,7 @@ public void setTaskResultsService(TaskResultsService taskResultsService) {
8379
* <p>
8480
* Returns the task manager tracked task or null if the task doesn't support the task manager
8581
*/
86-
public Task register(String type, String action, TransportRequest request) {
82+
public Task register(String type, String action, TaskAwareRequest request) {
8783
Task task = request.createTask(taskIdGenerator.incrementAndGet(), type, action, request.getParentTask());
8884
if (task == null) {
8985
return null;

core/src/main/java/org/elasticsearch/transport/TransportRequest.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
import org.elasticsearch.common.io.stream.StreamInput;
2323
import org.elasticsearch.common.io.stream.StreamOutput;
24-
import org.elasticsearch.tasks.Task;
24+
import org.elasticsearch.tasks.TaskAwareRequest;
2525
import org.elasticsearch.tasks.TaskId;
2626

2727
import java.io.IOException;
2828

29-
public abstract class TransportRequest extends TransportMessage {
29+
public abstract class TransportRequest extends TransportMessage implements TaskAwareRequest {
3030
public static class Empty extends TransportRequest {
3131
public static final Empty INSTANCE = new Empty();
3232
}
@@ -39,43 +39,22 @@ public static class Empty extends TransportRequest {
3939
public TransportRequest() {
4040
}
4141

42-
/**
43-
* Set a reference to task that caused this task to be run.
44-
*/
45-
public void setParentTask(String parentTaskNode, long parentTaskId) {
46-
setParentTask(new TaskId(parentTaskNode, parentTaskId));
47-
}
48-
4942
/**
5043
* Set a reference to task that created this request.
5144
*/
45+
@Override
5246
public void setParentTask(TaskId taskId) {
5347
this.parentTaskId = taskId;
5448
}
5549

5650
/**
5751
* Get a reference to the task that created this request. Defaults to {@link TaskId#EMPTY_TASK_ID}, meaning "there is no parent".
5852
*/
53+
@Override
5954
public TaskId getParentTask() {
6055
return parentTaskId;
6156
}
6257

63-
/**
64-
* Returns the task object that should be used to keep track of the processing of the request.
65-
*
66-
* A request can override this method and return null to avoid being tracked by the task manager.
67-
*/
68-
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
69-
return new Task(id, type, action, getDescription(), parentTaskId);
70-
}
71-
72-
/**
73-
* Returns optional description of the request to be displayed by the task manager
74-
*/
75-
public String getDescription() {
76-
return "";
77-
}
78-
7958
@Override
8059
public void readFrom(StreamInput in) throws IOException {
8160
super.readFrom(in);

0 commit comments

Comments
 (0)