@@ -195,27 +195,24 @@ public NodeLock(final Logger logger,
195195 final Environment environment ,
196196 final CheckedFunction <Path , Boolean , IOException > pathFunction ,
197197 final Function <Path , Path > subPathMapping ) throws IOException {
198- nodePaths = new NodePath [environment . dataFiles (). length ];
199- locks = new Lock [nodePaths . length ];
198+ nodePaths = new NodePath [1 ];
199+ locks = new Lock [1 ];
200200 try {
201- final Path [] dataPaths = environment .dataFiles ();
202- for (int dirIndex = 0 ; dirIndex < dataPaths .length ; dirIndex ++) {
203- Path dataDir = dataPaths [dirIndex ];
204- Path dir = subPathMapping .apply (dataDir );
205- if (pathFunction .apply (dir ) == false ) {
206- continue ;
207- }
208- try (Directory luceneDir = FSDirectory .open (dir , NativeFSLockFactory .INSTANCE )) {
209- logger .trace ("obtaining node lock on {} ..." , dir .toAbsolutePath ());
210- locks [dirIndex ] = luceneDir .obtainLock (NODE_LOCK_FILENAME );
211- nodePaths [dirIndex ] = new NodePath (dir );
212- } catch (IOException e ) {
213- logger .trace (() -> new ParameterizedMessage (
214- "failed to obtain node lock on {}" , dir .toAbsolutePath ()), e );
215- // release all the ones that were obtained up until now
216- throw (e instanceof LockObtainFailedException ? e
217- : new IOException ("failed to obtain lock on " + dir .toAbsolutePath (), e ));
218- }
201+ Path dataDir = environment .dataFile ();
202+ Path dir = subPathMapping .apply (dataDir );
203+ if (pathFunction .apply (dir ) == false ) {
204+ return ;
205+ }
206+ try (Directory luceneDir = FSDirectory .open (dir , NativeFSLockFactory .INSTANCE )) {
207+ logger .trace ("obtaining node lock on {} ..." , dir .toAbsolutePath ());
208+ locks [0 ] = luceneDir .obtainLock (NODE_LOCK_FILENAME );
209+ nodePaths [0 ] = new NodePath (dir );
210+ } catch (IOException e ) {
211+ logger .trace (() -> new ParameterizedMessage (
212+ "failed to obtain node lock on {}" , dir .toAbsolutePath ()), e );
213+ // release all the ones that were obtained up until now
214+ throw (e instanceof LockObtainFailedException ? e
215+ : new IOException ("failed to obtain lock on " + dir .toAbsolutePath (), e ));
219216 }
220217 } catch (IOException e ) {
221218 close ();
@@ -247,10 +244,7 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
247244
248245 try {
249246 sharedDataPath = environment .sharedDataFile ();
250-
251- for (Path path : environment .dataFiles ()) {
252- Files .createDirectories (path );
253- }
247+ Files .createDirectories (environment .dataFile ());
254248
255249 final NodeLock nodeLock ;
256250 try {
@@ -259,8 +253,8 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
259253 final String message = String .format (
260254 Locale .ROOT ,
261255 "failed to obtain node locks, tried %s;" +
262- " maybe these locations are not writable or multiple nodes were started on the same data path?" ,
263- Arrays . toString ( environment .dataFiles () ));
256+ " maybe this location is not writable or multiple nodes were started on the same data path?" ,
257+ environment .dataFile ( ));
264258 throw new IllegalStateException (message , e );
265259 }
266260
@@ -308,33 +302,31 @@ private static boolean upgradeLegacyNodeFolders(Logger logger, Settings settings
308302 boolean upgradeNeeded = false ;
309303
310304 // check if we can do an auto-upgrade
311- for (Path path : environment .dataFiles ()) {
312- final Path nodesFolderPath = path .resolve ("nodes" );
313- if (Files .isDirectory (nodesFolderPath )) {
314- final List <Integer > nodeLockIds = new ArrayList <>();
315-
316- try (DirectoryStream <Path > stream = Files .newDirectoryStream (nodesFolderPath )) {
317- for (Path nodeLockIdPath : stream ) {
318- String fileName = nodeLockIdPath .getFileName ().toString ();
319- if (Files .isDirectory (nodeLockIdPath ) && fileName .chars ().allMatch (Character ::isDigit )) {
320- int nodeLockId = Integer .parseInt (fileName );
321- nodeLockIds .add (nodeLockId );
322- } else if (FileSystemUtils .isDesktopServicesStore (nodeLockIdPath ) == false ) {
323- throw new IllegalStateException ("unexpected file/folder encountered during data folder upgrade: " +
324- nodeLockIdPath );
325- }
305+ final Path nodesFolderPath = environment .dataFile ().resolve ("nodes" );
306+ if (Files .isDirectory (nodesFolderPath )) {
307+ final List <Integer > nodeLockIds = new ArrayList <>();
308+
309+ try (DirectoryStream <Path > stream = Files .newDirectoryStream (nodesFolderPath )) {
310+ for (Path nodeLockIdPath : stream ) {
311+ String fileName = nodeLockIdPath .getFileName ().toString ();
312+ if (Files .isDirectory (nodeLockIdPath ) && fileName .chars ().allMatch (Character ::isDigit )) {
313+ int nodeLockId = Integer .parseInt (fileName );
314+ nodeLockIds .add (nodeLockId );
315+ } else if (FileSystemUtils .isDesktopServicesStore (nodeLockIdPath ) == false ) {
316+ throw new IllegalStateException ("unexpected file/folder encountered during data folder upgrade: " +
317+ nodeLockIdPath );
326318 }
327319 }
320+ }
328321
329- if (nodeLockIds .isEmpty () == false ) {
330- upgradeNeeded = true ;
322+ if (nodeLockIds .isEmpty () == false ) {
323+ upgradeNeeded = true ;
331324
332- if (nodeLockIds .equals (Arrays .asList (0 )) == false ) {
333- throw new IllegalStateException ("data path " + nodesFolderPath + " cannot be upgraded automatically because it " +
334- "contains data from nodes with ordinals " + nodeLockIds + ", due to previous use of the now obsolete " +
335- "[node.max_local_storage_nodes] setting. Please check the breaking changes docs for the current version of " +
336- "Elasticsearch to find an upgrade path" );
337- }
325+ if (nodeLockIds .equals (Arrays .asList (0 )) == false ) {
326+ throw new IllegalStateException ("data path " + nodesFolderPath + " cannot be upgraded automatically because it " +
327+ "contains data from nodes with ordinals " + nodeLockIds + ", due to previous use of the now obsolete " +
328+ "[node.max_local_storage_nodes] setting. Please check the breaking changes docs for the current version of " +
329+ "Elasticsearch to find an upgrade path" );
338330 }
339331 }
340332 }
@@ -344,7 +336,7 @@ private static boolean upgradeLegacyNodeFolders(Logger logger, Settings settings
344336 return false ;
345337 }
346338
347- logger .info ("upgrading legacy data folders : {}" , Arrays . toString ( environment .dataFiles () ));
339+ logger .info ("upgrading legacy data folder : {}" , environment .dataFile ( ));
348340
349341 // acquire locks on legacy path for duration of upgrade (to ensure there is no older ES version running on this path)
350342 final NodeLock legacyNodeLock ;
@@ -354,8 +346,8 @@ private static boolean upgradeLegacyNodeFolders(Logger logger, Settings settings
354346 final String message = String .format (
355347 Locale .ROOT ,
356348 "failed to obtain legacy node locks, tried %s;" +
357- " maybe these locations are not writable or multiple nodes were started on the same data path?" ,
358- Arrays . toString ( environment .dataFiles () ));
349+ " maybe this location is not writable or multiple nodes were started on the same data path?" ,
350+ environment .dataFile ( ));
359351 throw new IllegalStateException (message , e );
360352 }
361353
@@ -429,7 +421,7 @@ private static boolean upgradeLegacyNodeFolders(Logger logger, Settings settings
429421 }
430422
431423 // upgrade successfully completed, remove legacy nodes folders
432- IOUtils .rm (Stream . of ( environment .dataFiles ()). map ( path -> path . resolve ("nodes" )). toArray ( Path []:: new ));
424+ IOUtils .rm (environment .dataFile (). resolve ("nodes" ));
433425
434426 return true ;
435427 }
0 commit comments