Class SharedFsCheckpointSpi
- java.lang.Object
-
- org.apache.ignite.spi.IgniteSpiAdapter
-
- org.apache.ignite.spi.checkpoint.sharedfs.SharedFsCheckpointSpi
-
- All Implemented Interfaces:
CheckpointSpi,IgniteSpi
@IgniteSpiMultipleInstancesSupport(true) @IgniteSpiConsistencyChecked(optional=false) public class SharedFsCheckpointSpi extends IgniteSpiAdapter implements CheckpointSpi
This class defines shared file systemCheckpointSpiimplementation for checkpoint SPI. All checkpoints are stored on shared storage and available for all nodes in the grid. Note that every node must have access to the shared directory. The reason the directory needs to besharedis because a job state can be saved on one node and loaded on another (e.g. if a job gets preempted on a different node after node failure). When started, this SPI tracks all checkpoints saved by localhost for expiration. Note that this SPI does not cache data stored in checkpoints - all the data is loaded from file system on demand.Directory paths for shared checkpoints should either be empty or contain previously stored checkpoint files.
Configuration
Mandatory
This SPI has no mandatory configuration parameters.Optional
This SPI has following optional configuration parameters:- Directory paths (see
setDirectoryPaths(Collection))
Java Example
SharedFsCheckpointSpican be configured as follows:IgniteConfiguration cfg = new IgniteConfiguration(); SharedFsCheckpointSpi checkpointSpi = new SharedFsCheckpointSpi(); // List of checkpoint directories where all files are stored. Collection
dirPaths = new ArrayList (); dirPaths.add("/my/directory/path"); dirPaths.add("/other/directory/path"); // Override default directory path. checkpointSpi.setDirectoryPaths(dirPaths); // Override default checkpoint SPI. cfg.setCheckpointSpi(checkpointSpi); // Starts grid. G.start(cfg); Spring Example
SharedFsCheckpointSpican be configured from Spring XML configuration file:<bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true"> ... <property name="checkpointSpi"> <bean class="org.apache.ignite.spi.checkpoint.sharedfs.GridSharedFsCheckpointSpi"> <!-- Change to shared directory path in your environment. --> <property name="directoryPaths"> <list> <value>/my/directory/path</value> <value>/other/directory/path</value> </list> </property> </bean> </property> ... </bean>
For information about Spring framework visit www.springframework.org- See Also:
CheckpointSpi
-
-
Field Summary
Fields Modifier and Type Field Description static StringDFLT_DIR_PATHDefault checkpoint directory.
-
Constructor Summary
Constructors Constructor Description SharedFsCheckpointSpi()Initializes default directory paths.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetCurrentDirectoryPath()Gets path to the directory where all checkpoints are saved.Collection<String>getDirectoryPaths()Gets collection of all configured paths where checkpoints can be saved.byte[]loadCheckpoint(String key)Loads checkpoint from storage by its unique key.booleanremoveCheckpoint(String key)This method instructs the checkpoint provider to clean saved data for a givenkey.booleansaveCheckpoint(String key, byte[] state, long timeout, boolean overwrite)Saves checkpoint to the storage.voidsetCheckpointListener(CheckpointListener lsnr)Sets the checkpoint listener.SharedFsCheckpointSpisetDirectoryPaths(Collection<String> dirPaths)Sets path to a shared directory where checkpoints will be stored.SharedFsCheckpointSpisetName(String name)Sets SPI name.voidspiStart(String igniteInstanceName)This method is called to start SPI.voidspiStop()This method is called to stop SPI.StringtoString()-
Methods inherited from class org.apache.ignite.spi.IgniteSpiAdapter
addTimeoutObject, assertParameter, checkConfigurationConsistency0, clientFailureDetectionTimeout, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getConsistentAttributeNames, getExceptionRegistry, getLocalNode, getName, getNodeAttributes, getSpiContext, ignite, initFailureDetectionTimeout, injectables, injectResources, isNodeStopping, onBeforeStart, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextDestroyed0, onContextInitialized, onContextInitialized0, registerMBean, removeTimeoutObject, started, startInfo, startStopwatch, stopInfo, unregisterMBean
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.spi.IgniteSpi
getName, getNodeAttributes, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized
-
-
-
-
Field Detail
-
DFLT_DIR_PATH
public static final String DFLT_DIR_PATH
Default checkpoint directory. Note that this path is relative toIGNITE_HOME/workfolder ifIGNITE_HOMEsystem or environment variable specified, otherwise it is relative toworkfolder under systemjava.io.tmpdirfolder.
-
-
Method Detail
-
getDirectoryPaths
public Collection<String> getDirectoryPaths()
Gets collection of all configured paths where checkpoints can be saved.- Returns:
- Collection of all configured paths.
-
getCurrentDirectoryPath
public String getCurrentDirectoryPath()
Gets path to the directory where all checkpoints are saved.- Returns:
- Path to the checkpoints directory.
-
setDirectoryPaths
@IgniteSpiConfiguration(optional=true) public SharedFsCheckpointSpi setDirectoryPaths(Collection<String> dirPaths)
Sets path to a shared directory where checkpoints will be stored. The path can either be absolute or relative toIGNITE_HOMEsystem or environment variable.If not provided, default value is
DFLT_DIR_PATH.- Parameters:
dirPaths- Absolute or Ignite installation home folder relative path where checkpoints will be stored.- Returns:
thisfor chaining.
-
spiStart
public void spiStart(String igniteInstanceName) throws IgniteSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.- Specified by:
spiStartin interfaceIgniteSpi- Parameters:
igniteInstanceName- Name of Ignite instance this SPI is being started for (nullfor default Ignite instance).- Throws:
IgniteSpiException- Throws in case of any error during SPI start.
-
spiStop
public void spiStop() throws IgniteSpiExceptionThis method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.
- Specified by:
spiStopin interfaceIgniteSpi- Throws:
IgniteSpiException- Thrown in case of any error during SPI stop.
-
loadCheckpoint
public byte[] loadCheckpoint(String key) throws IgniteSpiException
Loads checkpoint from storage by its unique key.- Specified by:
loadCheckpointin interfaceCheckpointSpi- Parameters:
key- Checkpoint key.- Returns:
- Loaded data or
nullif there is no data for a given key. - Throws:
IgniteSpiException- Thrown in case of any error while loading checkpoint data. Note that in case when givenkeyis not found this method will returnnull.
-
saveCheckpoint
public boolean saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite) throws IgniteSpiException
Saves checkpoint to the storage.- Specified by:
saveCheckpointin interfaceCheckpointSpi- Parameters:
key- Checkpoint unique key.state- Saved data.timeout- Every intermediate data stored by checkpoint provider should have a timeout. Timeout allows for effective resource management by checkpoint provider by cleaning saved data that are not needed anymore. Generally, the user should choose the minimum possible timeout to avoid long-term resource acquisition by checkpoint provider. Value0means that timeout will never expire.overwrite- Whether or not overwrite checkpoint if it already exists.- Returns:
trueif checkpoint has been actually saved,falseotherwise.- Throws:
IgniteSpiException- Thrown in case of any error while saving checkpoint data.
-
removeCheckpoint
public boolean removeCheckpoint(String key)
This method instructs the checkpoint provider to clean saved data for a givenkey.- Specified by:
removeCheckpointin interfaceCheckpointSpi- Parameters:
key- Key for the checkpoint to remove.- Returns:
trueif data has been actually removed,falseotherwise.
-
setCheckpointListener
public void setCheckpointListener(CheckpointListener lsnr)
Sets the checkpoint listener.- Specified by:
setCheckpointListenerin interfaceCheckpointSpi- Parameters:
lsnr- The listener to set ornull.
-
setName
public SharedFsCheckpointSpi setName(String name)
Sets SPI name.- Overrides:
setNamein classIgniteSpiAdapter- Parameters:
name- SPI name.- Returns:
thisfor chaining.
-
-