8181import java .util .concurrent .Semaphore ;
8282import java .util .concurrent .TimeUnit ;
8383import java .util .concurrent .atomic .AtomicBoolean ;
84- import java .util .concurrent .atomic .AtomicReference ;
8584import java .util .function .Predicate ;
8685import java .util .stream .Collectors ;
8786import java .util .stream .Stream ;
9190 */
9291public final class NodeEnvironment implements Closeable {
9392 public static class NodePath {
94- /* ${data.paths}/nodes/{node.id} */
93+ /* ${data.paths}/nodes/0 */
9594 public final Path path ;
96- /* ${data.paths}/nodes/{node.id} /indices */
95+ /* ${data.paths}/nodes/0 /indices */
9796 public final Path indicesPath ;
9897 /** Cached FileStore from path */
9998 public final FileStore fileStore ;
@@ -152,18 +151,11 @@ public String toString() {
152151 private final Path sharedDataPath ;
153152 private final Lock [] locks ;
154153
155- private final int nodeLockId ;
156154 private final AtomicBoolean closed = new AtomicBoolean (false );
157155 private final Map <ShardId , InternalShardLock > shardLocks = new HashMap <>();
158156
159157 private final NodeMetaData nodeMetaData ;
160158
161- /**
162- * Maximum number of data nodes that should run in an environment.
163- */
164- public static final Setting <Integer > MAX_LOCAL_STORAGE_NODES_SETTING = Setting .intSetting ("node.max_local_storage_nodes" , 1 , 1 ,
165- Property .NodeScope );
166-
167159 /**
168160 * Seed for determining a persisted unique uuid of this node. If the node has already a persisted uuid on disk,
169161 * this seed will be ignored and the uuid from disk will be reused.
@@ -184,25 +176,23 @@ public String toString() {
184176
185177 public static class NodeLock implements Releasable {
186178
187- private final int nodeId ;
188179 private final Lock [] locks ;
189180 private final NodePath [] nodePaths ;
190181
191182 /**
192183 * Tries to acquire a node lock for a node id, throws {@code IOException} if it is unable to acquire it
193184 * @param pathFunction function to check node path before attempt of acquiring a node lock
194185 */
195- public NodeLock (final int nodeId , final Logger logger ,
186+ public NodeLock (final Logger logger ,
196187 final Environment environment ,
197188 final CheckedFunction <Path , Boolean , IOException > pathFunction ) throws IOException {
198- this .nodeId = nodeId ;
199189 nodePaths = new NodePath [environment .dataFiles ().length ];
200190 locks = new Lock [nodePaths .length ];
201191 try {
202192 final Path [] dataPaths = environment .dataFiles ();
203193 for (int dirIndex = 0 ; dirIndex < dataPaths .length ; dirIndex ++) {
204194 Path dataDir = dataPaths [dirIndex ];
205- Path dir = resolveNodePath (dataDir , nodeId );
195+ Path dir = resolveNodePath (dataDir );
206196 if (pathFunction .apply (dir ) == false ) {
207197 continue ;
208198 }
@@ -248,61 +238,35 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
248238 nodePaths = null ;
249239 sharedDataPath = null ;
250240 locks = null ;
251- nodeLockId = -1 ;
252241 nodeMetaData = new NodeMetaData (generateNodeId (settings ), Version .CURRENT );
253242 return ;
254243 }
255244 boolean success = false ;
256- NodeLock nodeLock = null ;
257245
258246 try {
259247 sharedDataPath = environment .sharedDataFile ();
260- IOException lastException = null ;
261- int maxLocalStorageNodes = MAX_LOCAL_STORAGE_NODES_SETTING .get (settings );
262248
263- final AtomicReference <IOException > onCreateDirectoriesException = new AtomicReference <>();
264- for (int possibleLockId = 0 ; possibleLockId < maxLocalStorageNodes ; possibleLockId ++) {
265- try {
266- nodeLock = new NodeLock (possibleLockId , logger , environment ,
267- dir -> {
268- try {
269- Files .createDirectories (dir );
270- } catch (IOException e ) {
271- onCreateDirectoriesException .set (e );
272- throw e ;
273- }
274- return true ;
275- });
276- break ;
277- } catch (LockObtainFailedException e ) {
278- // ignore any LockObtainFailedException
279- } catch (IOException e ) {
280- if (onCreateDirectoriesException .get () != null ) {
281- throw onCreateDirectoriesException .get ();
282- }
283- lastException = e ;
284- }
249+ for (Path path : environment .dataFiles ()) {
250+ Files .createDirectories (resolveNodePath (path ));
285251 }
286252
287- if (nodeLock == null ) {
253+ final NodeLock nodeLock ;
254+ try {
255+ nodeLock = new NodeLock (logger , environment , dir -> true );
256+ } catch (IOException e ) {
288257 final String message = String .format (
289258 Locale .ROOT ,
290- "failed to obtain node locks, tried [%s] with lock id%s;" +
291- " maybe these locations are not writable or multiple nodes were started without increasing [%s] (was [%d])?" ,
292- Arrays .toString (environment .dataFiles ()),
293- maxLocalStorageNodes == 1 ? " [0]" : "s [0--" + (maxLocalStorageNodes - 1 ) + "]" ,
294- MAX_LOCAL_STORAGE_NODES_SETTING .getKey (),
295- maxLocalStorageNodes );
296- throw new IllegalStateException (message , lastException );
259+ "failed to obtain node locks, tried %s;" +
260+ " maybe these locations are not writable or multiple nodes were started on the same data path?" ,
261+ Arrays .toString (environment .dataFiles ()));
262+ throw new IllegalStateException (message , e );
297263 }
264+
298265 this .locks = nodeLock .locks ;
299266 this .nodePaths = nodeLock .nodePaths ;
300- this .nodeLockId = nodeLock .nodeId ;
301267 this .nodeMetaData = loadOrCreateNodeMetaData (settings , logger , nodePaths );
302268
303- if (logger .isDebugEnabled ()) {
304- logger .debug ("using node location [{}], local_lock_id [{}]" , nodePaths , nodeLockId );
305- }
269+ logger .debug ("using node location {}" , Arrays .toString (nodePaths ));
306270
307271 maybeLogPathDetails ();
308272 maybeLogHeapDetails ();
@@ -334,11 +298,10 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
334298 * Resolve a specific nodes/{node.id} path for the specified path and node lock id.
335299 *
336300 * @param path the path
337- * @param nodeLockId the node lock id
338301 * @return the resolved path
339302 */
340- public static Path resolveNodePath (final Path path , final int nodeLockId ) {
341- return path .resolve (NODES_FOLDER ).resolve (Integer . toString ( nodeLockId ) );
303+ public static Path resolveNodePath (final Path path ) {
304+ return path .resolve (NODES_FOLDER ).resolve ("0" );
342305 }
343306
344307 private void maybeLogPathDetails () throws IOException {
@@ -805,14 +768,6 @@ public NodePath[] nodePaths() {
805768 return nodePaths ;
806769 }
807770
808- public int getNodeLockId () {
809- assertEnvIsLocked ();
810- if (nodePaths == null || locks == null ) {
811- throw new IllegalStateException ("node is not configured to store local location" );
812- }
813- return nodeLockId ;
814- }
815-
816771 /**
817772 * Returns all index paths.
818773 */
@@ -1137,12 +1092,12 @@ private static boolean isIndexMetaDataPath(Path path) {
11371092 *
11381093 * @param indexSettings settings for the index
11391094 */
1140- public static Path resolveBaseCustomLocation (IndexSettings indexSettings , Path sharedDataPath , int nodeLockId ) {
1095+ public static Path resolveBaseCustomLocation (IndexSettings indexSettings , Path sharedDataPath ) {
11411096 String customDataDir = indexSettings .customDataPath ();
11421097 if (customDataDir != null ) {
11431098 // This assert is because this should be caught by MetaDataCreateIndexService
11441099 assert sharedDataPath != null ;
1145- return sharedDataPath .resolve (customDataDir ).resolve (Integer . toString ( nodeLockId ) );
1100+ return sharedDataPath .resolve (customDataDir ).resolve ("0" );
11461101 } else {
11471102 throw new IllegalArgumentException ("no custom " + IndexMetaData .SETTING_DATA_PATH + " setting available" );
11481103 }
@@ -1156,11 +1111,11 @@ public static Path resolveBaseCustomLocation(IndexSettings indexSettings, Path s
11561111 * @param indexSettings settings for the index
11571112 */
11581113 private Path resolveIndexCustomLocation (IndexSettings indexSettings ) {
1159- return resolveIndexCustomLocation (indexSettings , sharedDataPath , nodeLockId );
1114+ return resolveIndexCustomLocation (indexSettings , sharedDataPath );
11601115 }
11611116
1162- private static Path resolveIndexCustomLocation (IndexSettings indexSettings , Path sharedDataPath , int nodeLockId ) {
1163- return resolveBaseCustomLocation (indexSettings , sharedDataPath , nodeLockId ).resolve (indexSettings .getUUID ());
1117+ private static Path resolveIndexCustomLocation (IndexSettings indexSettings , Path sharedDataPath ) {
1118+ return resolveBaseCustomLocation (indexSettings , sharedDataPath ).resolve (indexSettings .getUUID ());
11641119 }
11651120
11661121 /**
@@ -1172,11 +1127,11 @@ private static Path resolveIndexCustomLocation(IndexSettings indexSettings, Path
11721127 * @param shardId shard to resolve the path to
11731128 */
11741129 public Path resolveCustomLocation (IndexSettings indexSettings , final ShardId shardId ) {
1175- return resolveCustomLocation (indexSettings , shardId , sharedDataPath , nodeLockId );
1130+ return resolveCustomLocation (indexSettings , shardId , sharedDataPath );
11761131 }
11771132
1178- public static Path resolveCustomLocation (IndexSettings indexSettings , final ShardId shardId , Path sharedDataPath , int nodeLockId ) {
1179- return resolveIndexCustomLocation (indexSettings , sharedDataPath , nodeLockId ).resolve (Integer .toString (shardId .id ()));
1133+ public static Path resolveCustomLocation (IndexSettings indexSettings , final ShardId shardId , Path sharedDataPath ) {
1134+ return resolveIndexCustomLocation (indexSettings , sharedDataPath ).resolve (Integer .toString (shardId .id ()));
11801135 }
11811136
11821137 /**
0 commit comments