Skip to content

Commit 096e713

Browse files
committed
review comments
1 parent 68e43e3 commit 096e713

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

server/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,39 +242,31 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
242242
return;
243243
}
244244
boolean success = false;
245-
NodeLock nodeLock = null;
246245

247246
try {
248247
sharedDataPath = environment.sharedDataFile();
249-
IOException exception = null;
250248

251-
try {
252-
nodeLock = new NodeLock(logger, environment,
253-
dir -> {
254-
Files.createDirectories(dir);
255-
return true;
256-
});
257-
} catch (LockObtainFailedException e) {
258-
// ignore any LockObtainFailedException
259-
} catch (IOException e) {
260-
exception = e;
249+
for (Path path : environment.dataFiles()) {
250+
Files.createDirectories(resolveNodePath(path));
261251
}
262252

263-
if (nodeLock == null) {
253+
final NodeLock nodeLock;
254+
try {
255+
nodeLock = new NodeLock(logger, environment, dir -> true);
256+
} catch (IOException e) {
264257
final String message = String.format(
265258
Locale.ROOT,
266-
"failed to obtain node locks, tried [%s] with lock id [0];" +
259+
"failed to obtain node locks, tried %s;" +
267260
" maybe these locations are not writable or multiple nodes were started on the same data path?",
268261
Arrays.toString(environment.dataFiles()));
269-
throw new IllegalStateException(message, exception);
262+
throw new IllegalStateException(message, e);
270263
}
264+
271265
this.locks = nodeLock.locks;
272266
this.nodePaths = nodeLock.nodePaths;
273267
this.nodeMetaData = loadOrCreateNodeMetaData(settings, logger, nodePaths);
274268

275-
if (logger.isDebugEnabled()) {
276-
logger.debug("using node location {}", Arrays.toString(nodePaths));
277-
}
269+
logger.debug("using node location {}", Arrays.toString(nodePaths));
278270

279271
maybeLogPathDetails();
280272
maybeLogHeapDetails();

server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
public class NodeEnvironmentTests extends ESTestCase {
6060
private final IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("foo", Settings.EMPTY);
6161

62-
public void testNodeLockSingleEnvironment() throws IOException {
62+
public void testNodeLock() throws IOException {
6363
final Settings settings = buildEnvSettings(Settings.EMPTY);
6464
NodeEnvironment env = newNodeEnvironment(settings);
6565
List<String> dataPaths = Environment.PATH_DATA_SETTING.get(settings);

0 commit comments

Comments
 (0)