Class JobStealingFailoverSpi
- java.lang.Object
-
- org.apache.ignite.spi.IgniteSpiAdapter
-
- org.apache.ignite.spi.failover.jobstealing.JobStealingFailoverSpi
-
- All Implemented Interfaces:
FailoverSpi
,IgniteSpi
@IgniteSpiMultipleInstancesSupport(true) @IgniteSpiConsistencyChecked(optional=true) public class JobStealingFailoverSpi extends IgniteSpiAdapter implements FailoverSpi
Job stealing failover SPI needs to always be used in conjunction withJobStealingCollisionSpi
SPI. WhenJobStealingCollisionSpi
receives a steal request and rejects jobs so they can be routed to the appropriate node, it is the responsibility of thisJobStealingFailoverSpi
SPI to make sure that the job is indeed re-routed to the node that has sent the initial request to steal it.JobStealingFailoverSpi
knows where to route a job based on theJobStealingCollisionSpi.THIEF_NODE_ATTR
job context attribute (seeComputeJobContext
). Prior to rejecting a job,JobStealingCollisionSpi
will populate this attribute with the ID of the node that wants to steal this job. ThenJobStealingFailoverSpi
will read the value of this attribute and route the job to the node specified.If failure is caused by a node crash, and not by steal request, then this SPI behaves identically to
AlwaysFailoverSpi
, and tries to find the next balanced node to fail-over a job to.Configuration
Mandatory
This SPI has no mandatory configuration parameters.Optional
This SPI has following optional configuration parameters:- Maximum failover attempts for a single job (see
setMaximumFailoverAttempts(int)
).
JobStealingFailoverSpi
.JobStealingFailoverSpi spi = new JobStealingFailoverSpi(); // Override maximum failover attempts. spi.setMaximumFailoverAttempts(5); IgniteConfiguration cfg = new IgniteConfiguration(); // Override default failover SPI. cfg.setFailoverSpiSpi(spi); // Starts grid. G.start(cfg);
Here is an example of how to configureJobStealingFailoverSpi
from Spring XML configuration file.<property name="failoverSpi"> <bean class="org.apache.ignite.spi.failover.jobstealing.JobStealingFailoverSpi"> <property name="maximumFailoverAttempts" value="5"/> </bean> </property>
For information about Spring framework visit www.springframework.org- See Also:
FailoverSpi
-
-
Field Summary
Fields Modifier and Type Field Description static int
DFLT_MAX_FAILOVER_ATTEMPTS
Maximum number of attempts to execute a failed job on another node (default is5
).-
Fields inherited from class org.apache.ignite.spi.IgniteSpiAdapter
ignite, igniteInstanceName
-
-
Constructor Summary
Constructors Constructor Description JobStealingFailoverSpi()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClusterNode
failover(FailoverContext ctx, List<ClusterNode> top)
This method is called when methodComputeTask.result(org.apache.ignite.compute.ComputeJobResult, List)
returns valueComputeJobResultPolicy.FAILOVER
policy indicating that the result of job execution must be failed over.protected List<String>
getConsistentAttributeNames()
Returns back a list of attributes that should be consistent for this SPI.int
getMaximumFailoverAttempts()
Map<String,Object>
getNodeAttributes()
This method is called before SPI starts (before methodIgniteSpi.spiStart(String)
is called).int
getTotalFailedOverJobsCount()
Get total number of jobs that were failed over including stolen ones.int
getTotalStolenJobsCount()
Get total number of jobs that were stolen.JobStealingFailoverSpi
setMaximumFailoverAttempts(int maxFailoverAttempts)
Sets maximum number of attempts to execute a failed job on another node.JobStealingFailoverSpi
setName(String name)
Sets SPI name.void
spiStart(String igniteInstanceName)
This method is called to start SPI.void
spiStop()
This method is called to stop SPI.String
toString()
-
Methods inherited from class org.apache.ignite.spi.IgniteSpiAdapter
addTimeoutObject, assertParameter, checkConfigurationConsistency0, clientFailureDetectionTimeout, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getExceptionRegistry, getLocalNode, getName, 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, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized
-
-
-
-
Field Detail
-
DFLT_MAX_FAILOVER_ATTEMPTS
public static final int DFLT_MAX_FAILOVER_ATTEMPTS
Maximum number of attempts to execute a failed job on another node (default is5
).- See Also:
- Constant Field Values
-
-
Method Detail
-
getMaximumFailoverAttempts
public int getMaximumFailoverAttempts()
- Returns:
- Maximum number of attempts to execute a failed job on another node.
-
setMaximumFailoverAttempts
@IgniteSpiConfiguration(optional=true) public JobStealingFailoverSpi setMaximumFailoverAttempts(int maxFailoverAttempts)
Sets maximum number of attempts to execute a failed job on another node. If job gets stolen and thief node exists then it is not considered as failed job. If not specified,DFLT_MAX_FAILOVER_ATTEMPTS
value will be used.Note this value must be identical for all grid nodes in the grid.
- Parameters:
maxFailoverAttempts
- Maximum number of attempts to execute a failed job on another node.- Returns:
this
for chaining.
-
getTotalFailedOverJobsCount
public int getTotalFailedOverJobsCount()
Get total number of jobs that were failed over including stolen ones.- Returns:
- Total number of failed over jobs.
-
getTotalStolenJobsCount
public int getTotalStolenJobsCount()
Get total number of jobs that were stolen.- Returns:
- Total number of stolen jobs.
-
getNodeAttributes
public Map<String,Object> getNodeAttributes() throws IgniteSpiException
This method is called before SPI starts (before methodIgniteSpi.spiStart(String)
is called). It allows SPI implementation to add attributes to a local node. Kernal collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.- Specified by:
getNodeAttributes
in interfaceIgniteSpi
- Overrides:
getNodeAttributes
in classIgniteSpiAdapter
- Returns:
- Map of local node attributes this SPI wants to add.
- Throws:
IgniteSpiException
- Throws in case of any error.
-
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:
spiStart
in interfaceIgniteSpi
- Parameters:
igniteInstanceName
- Name of Ignite instance this SPI is being started for (null
for default Ignite instance).- Throws:
IgniteSpiException
- Throws in case of any error during SPI start.
-
spiStop
public void spiStop() throws IgniteSpiException
This 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:
spiStop
in interfaceIgniteSpi
- Throws:
IgniteSpiException
- Thrown in case of any error during SPI stop.
-
failover
public ClusterNode failover(FailoverContext ctx, List<ClusterNode> top)
This method is called when methodComputeTask.result(org.apache.ignite.compute.ComputeJobResult, List)
returns valueComputeJobResultPolicy.FAILOVER
policy indicating that the result of job execution must be failed over. Implementation of this method should examine failover context and choose one of the grid nodes from suppliedtopology
to retry job execution on it. For best performance it is advised thatFailoverContext.getBalancedNode(List)
method is used to select node for execution of failed job.- Specified by:
failover
in interfaceFailoverSpi
- Parameters:
ctx
- Failover context.top
- Collection of all grid nodes within task topology (may include failed node).- Returns:
- New node to route this job to or
null
if new node cannot be picked. If job failover fails (returnsnull
) the whole task will be failed.
-
getConsistentAttributeNames
protected List<String> getConsistentAttributeNames()
Returns back a list of attributes that should be consistent for this SPI. Consistency means that remote node has to have the same attribute with the same value.- Overrides:
getConsistentAttributeNames
in classIgniteSpiAdapter
- Returns:
- List or attribute names.
-
setName
public JobStealingFailoverSpi setName(String name)
Sets SPI name.- Overrides:
setName
in classIgniteSpiAdapter
- Parameters:
name
- SPI name.- Returns:
this
for chaining.
-
-