Package org.elasticsearch.env
Class NodeEnvironment
org.elasticsearch.env.NodeEnvironment
- All Implemented Interfaces:
,
public final class NodeEnvironment
extends
implements
A component that holds all data paths for a single node.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static interface
A functional interface that people can use to referenceshardLock(ShardId, String, long)
-
Field Summary
Modifier and TypeFieldDescriptionstatic >
If true the [verbose] SegmentInfos.infoStream logging is sent to System.out.static
static >
Maximum number of data nodes that should run in an environment.static >
Seed for determining a persisted unique uuid of this node.static
static
-
Constructor Summary
ConstructorDescriptionNodeEnvironment(Settings settings, Environment environment)
Setup the environment. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
acquireFSLockForPaths(IndexSettings indexSettings, ... shardPaths)
Acquires, then releases, allwrite.lock
files in the given shard paths.<>
Returns all folder names in ${data.paths}/nodes/{node.id}/indices folder<>
<> excludeIndexPathIdsPredicate)
Returns folder names in ${data.paths}/nodes/{node.id}/indices folder that don't match the given predicate.<>
Return all directory names in the nodes/{node.id}/indices directory for the given node path.<>
availableIndexFoldersForPath(NodeEnvironment.NodePath nodePath, <> excludeIndexPathIdsPredicate)
Return directory names in the nodes/{node.id}/indices directory for the given node path that don't match the given predicate.[]
availableShardPaths(ShardId shardId)
Returns all shard paths excluding custom shard path.void
close()
void
deleteIndexDirectorySafe(Index index, long lockTimeoutMS, IndexSettings indexSettings, <[]> listener)
Deletes an indexes data directory recursively iff all of the indexes shards locks were successfully acquired.void
deleteIndexDirectoryUnderLock(Index index, IndexSettings indexSettings, <[]> listener)
Deletes an indexes data directory recursively.void
deleteShardDirectorySafe(ShardId shardId, IndexSettings indexSettings, <[]> listener)
Deletes a shard data directory iff the shards locks were successfully acquired.void
deleteShardDirectoryUnderLock(ShardLock lock, IndexSettings indexSettings, <[]> listener)
Deletes a shard data directory.<ShardId>
findAllShardIds(Index index)
Tries to find all allocated shards for the given index on the current node.static
generateNodeId(Settings settings)
int
boolean
[]
indexPaths(Index index)
Returns all index paths.lockAllForIndex(Index index, IndexSettings settings, lockDetails, long lockTimeoutMS)
Tries to lock all local shards for the given index.<ShardId>
Returns all currently lock shards.[]
Returns an array of all of the nodes data locations.nodeId()
returns the unique uuid describing this node.Returns an array of all of theNodeEnvironment.NodePath
s.static
customDataPath, sharedDataPath, int nodeLockId)
Resolve the custom path for a index's shard.customDataPath, ShardId shardId)
Resolve the custom path for a index's shard.static
customDataPath, ShardId shardId, sharedDataPath, int nodeLockId)
[]
indexFolderName)
Resolves all existing paths toindexFolderName
in ${data.paths}/nodes/{node.id}/indicesstatic
path, int nodeLockId)
Resolve a specific nodes/{node.id} path for the specified path and node lock id.<>
shardCountPerPath(Index index)
Find all the shards for this index, returning a map of theNodePath
to the number of shards on that pathTries to lock the given shards ID.Tries to lock the given shards ID.static
shardPath)
Returns theNodePath.path
for this shard.Returns shared data path for this node environmentMethods inherited from class java.lang.
, , , , , , , , , ,
-
Field Details
-
MAX_LOCAL_STORAGE_NODES_SETTING
public static final > MAX_LOCAL_STORAGE_NODES_SETTINGMaximum number of data nodes that should run in an environment. -
NODE_ID_SEED_SETTING
public static final > NODE_ID_SEED_SETTINGSeed for determining a persisted unique uuid of this node. If the node has already a persisted uuid on disk, this seed will be ignored and the uuid from disk will be reused. -
ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING
public static final > ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTINGIf true the [verbose] SegmentInfos.infoStream logging is sent to System.out. -
NODES_FOLDER
public static final NODES_FOLDER- See Also:
- Constant Field Values
-
INDICES_FOLDER
public static final INDICES_FOLDER- See Also:
- Constant Field Values
-
NODE_LOCK_FILENAME
public static final NODE_LOCK_FILENAME- See Also:
- Constant Field Values
-
-
Constructor Details
-
NodeEnvironment
Setup the environment.- Parameters:
settings
- settings from elasticsearch.yml- Throws:
-
-
Method Details
-
resolveNodePath
public static resolveNodePath( path, int nodeLockId)Resolve a specific nodes/{node.id} path for the specified path and node lock id.- Parameters:
path
- the pathnodeLockId
- the node lock id- Returns:
- the resolved path
-
generateNodeId
-
deleteShardDirectorySafe
public void deleteShardDirectorySafe(ShardId shardId, IndexSettings indexSettings, <[]> listener) throws , ShardLockObtainFailedExceptionDeletes a shard data directory iff the shards locks were successfully acquired.- Parameters:
shardId
- the id of the shard to delete to delete- Throws:
- if an IOException occurs
ShardLockObtainFailedException
-
acquireFSLockForPaths
Acquires, then releases, allwrite.lock
files in the given shard paths. The "write.lock" file is assumed to be under the shard path's "index" directory as used by Elasticsearch.- Throws:
org.apache.lucene.store.LockObtainFailedException
- if any of the locks could not be acquired
-
deleteShardDirectoryUnderLock
public void deleteShardDirectoryUnderLock(ShardLock lock, IndexSettings indexSettings, <[]> listener) throwsDeletes a shard data directory. Note: this method assumes that the shard lock is acquired. This method will also attempt to acquire the write locks for the shard's paths before deleting the data, but this is best effort, as the lock is released before the deletion happens in order to allow the folder to be deleted- Parameters:
lock
- the shards lock- Throws:
- if an IOException occurs
ElasticsearchException
- if the write.lock is not acquirable
-
deleteIndexDirectorySafe
public void deleteIndexDirectorySafe(Index index, long lockTimeoutMS, IndexSettings indexSettings, <[]> listener) throws , ShardLockObtainFailedExceptionDeletes an indexes data directory recursively iff all of the indexes shards locks were successfully acquired. If any of the indexes shard directories can't be locked non of the shards will be deleted- Parameters:
index
- the index to deletelockTimeoutMS
- how long to wait for acquiring the indices shard locksindexSettings
- settings for the index being deleted- Throws:
- if any of the shards data directories can't be locked or deleted
ShardLockObtainFailedException
-
deleteIndexDirectoryUnderLock
public void deleteIndexDirectoryUnderLock(Index index, IndexSettings indexSettings, <[]> listener) throwsDeletes an indexes data directory recursively. Note: this method assumes that the shard lock is acquired- Parameters:
index
- the index to deleteindexSettings
- settings for the index being deleted- Throws:
-
lockAllForIndex
public <ShardLock> lockAllForIndex(Index index, IndexSettings settings, lockDetails, long lockTimeoutMS) throws ShardLockObtainFailedExceptionTries to lock all local shards for the given index. If any of the shard locks can't be acquired aShardLockObtainFailedException
is thrown and all previously acquired locks are released.- Parameters:
index
- the index to lock shards forlockTimeoutMS
- how long to wait for acquiring the indices shard locks- Returns:
- the
ShardLock
instances for this index. - Throws:
ShardLockObtainFailedException
-
shardLock
Tries to lock the given shards ID. A shard lock is required to perform any kind of write operation on a shards data directory like deleting files, creating a new index writer or recover from a different shard instance into it. If the shard lock can not be acquired aShardLockObtainFailedException
is thrown. Note: this method will return immediately if the lock can't be acquired.- Parameters:
id
- the shard ID to lockdetails
- information about why the shard is being locked- Returns:
- the shard lock. Call
ShardLock.close()
to release the lock - Throws:
ShardLockObtainFailedException
-
shardLock
public ShardLock shardLock(ShardId shardId, details, long lockTimeoutMS) throws ShardLockObtainFailedExceptionTries to lock the given shards ID. A shard lock is required to perform any kind of write operation on a shards data directory like deleting files, creating a new index writer or recover from a different shard instance into it. If the shard lock can not be acquired aShardLockObtainFailedException
is thrown- Parameters:
shardId
- the shard ID to lockdetails
- information about why the shard is being lockedlockTimeoutMS
- the lock timeout in milliseconds- Returns:
- the shard lock. Call
ShardLock.close()
to release the lock - Throws:
ShardLockObtainFailedException
-
lockedShards
Returns all currently lock shards. Note: the shard ids return do not contain a valid Index UUID -
hasNodeFile
public boolean hasNodeFile() -
nodeDataPaths
public [] nodeDataPaths()Returns an array of all of the nodes data locations.- Throws:
- if the node is not configured to store local locations
-
nodeId
public nodeId()returns the unique uuid describing this node. The uuid is persistent in the data folder of this node and remains across restarts. -
nodePaths
Returns an array of all of theNodeEnvironment.NodePath
s. -
getNodeLockId
public int getNodeLockId() -
indexPaths
Returns all index paths. -
availableShardPaths
Returns all shard paths excluding custom shard path. Note: Shards are only allocated on one of the returned paths. The returned array may contain paths to non-existing directories. -
availableIndexFolders
public <> availableIndexFolders() throwsReturns all folder names in ${data.paths}/nodes/{node.id}/indices folder- Throws:
-
availableIndexFolders
public <> availableIndexFolders(<> excludeIndexPathIdsPredicate) throwsReturns folder names in ${data.paths}/nodes/{node.id}/indices folder that don't match the given predicate.- Parameters:
excludeIndexPathIdsPredicate
- folder names to exclude- Throws:
-
availableIndexFoldersForPath
Return all directory names in the nodes/{node.id}/indices directory for the given node path.- Parameters:
nodePath
- the path- Returns:
- all directories that could be indices for the given node path.
- Throws:
- if an I/O exception occurs traversing the filesystem
-
availableIndexFoldersForPath
public <> availableIndexFoldersForPath(NodeEnvironment.NodePath nodePath, <> excludeIndexPathIdsPredicate) throwsReturn directory names in the nodes/{node.id}/indices directory for the given node path that don't match the given predicate.- Parameters:
nodePath
- the pathexcludeIndexPathIdsPredicate
- folder names to exclude- Returns:
- all directories that could be indices for the given node path.
- Throws:
- if an I/O exception occurs traversing the filesystem
-
resolveIndexFolder
public [] resolveIndexFolder( indexFolderName)Resolves all existing paths toindexFolderName
in ${data.paths}/nodes/{node.id}/indices -
findAllShardIds
Tries to find all allocated shards for the given index on the current node. NOTE: This methods is prone to race-conditions on the filesystem layer since it might not see directories created concurrently or while it's traversing.- Parameters:
index
- the index to filter shards- Returns:
- a set of shard IDs
- Throws:
- if an IOException occurs
-
shardCountPerPath
Find all the shards for this index, returning a map of theNodePath
to the number of shards on that path- Parameters:
index
- the index by which to filter shards- Returns:
- a map of NodePath to count of the shards for the index on that path
- Throws:
- if an IOException occurs
-
close
public void close()- Specified by:
in interface
- Specified by:
in interface
-
resolveBaseCustomLocation
public static resolveBaseCustomLocation( customDataPath, sharedDataPath, int nodeLockId)Resolve the custom path for a index's shard. -
resolveCustomLocation
Resolve the custom path for a index's shard. Uses theIndexMetadata.SETTING_DATA_PATH
setting to determine the root path for the index.- Parameters:
customDataPath
- the custom data pathshardId
- shard to resolve the path to
-
resolveCustomLocation
public static resolveCustomLocation( customDataPath, ShardId shardId, sharedDataPath, int nodeLockId) -
shardStatePathToDataPath
public static shardStatePathToDataPath( shardPath)Returns theNodePath.path
for this shard.
-