Package org.apache.flink.runtime.state
Class StateUtil
- java.lang.Object
-
- org.apache.flink.runtime.state.StateUtil
-
public class StateUtil extends Object
Helpers forStateObject
related code.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
bestEffortDiscardAllStateObjects(Iterable<? extends StateObject> handlesToDiscard)
Iterates through the passed state handles and calls discardState() on each handle that is not null.static Tuple2<Long,Long>
discardStateFuture(Future<? extends StateObject> stateFuture)
Discards the given state future by first trying to cancel it.static void
discardStateObjectQuietly(StateObject stateObject)
static long
getStateSize(StateObject handle)
Returns the size of a state object.static RuntimeException
unexpectedStateHandleException(Class<? extends StateObject>[] expectedStateHandleClasses, Class<? extends StateObject> actualStateHandleClass)
Creates aRuntimeException
that signals that an operation did not get the type ofStateObject
that was expected.static RuntimeException
unexpectedStateHandleException(Class<? extends StateObject> expectedStateHandleClass, Class<? extends StateObject> actualStateHandleClass)
Creates anRuntimeException
that signals that an operation did not get the type ofStateObject
that was expected.
-
-
-
Method Detail
-
getStateSize
public static long getStateSize(StateObject handle)
Returns the size of a state object.- Parameters:
handle
- The handle to the retrieved state
-
bestEffortDiscardAllStateObjects
public static void bestEffortDiscardAllStateObjects(Iterable<? extends StateObject> handlesToDiscard) throws Exception
Iterates through the passed state handles and calls discardState() on each handle that is not null. All occurring exceptions are suppressed and collected until the iteration is over and emitted as a single exception.- Parameters:
handlesToDiscard
- State handles to discard. Passed iterable is allowed to deliver null values.- Throws:
Exception
- exception that is a collection of all suppressed exceptions that were caught during iteration
-
discardStateObjectQuietly
public static void discardStateObjectQuietly(StateObject stateObject)
-
discardStateFuture
public static Tuple2<Long,Long> discardStateFuture(Future<? extends StateObject> stateFuture) throws Exception
Discards the given state future by first trying to cancel it. If this is not possible, then the state object contained in the future is calculated and afterwards discarded.- Parameters:
stateFuture
- to be discarded- Returns:
- the size of state before cancellation (if available)
- Throws:
Exception
- if the discard operation failed
-
unexpectedStateHandleException
public static RuntimeException unexpectedStateHandleException(Class<? extends StateObject> expectedStateHandleClass, Class<? extends StateObject> actualStateHandleClass)
Creates anRuntimeException
that signals that an operation did not get the type ofStateObject
that was expected. This can mostly happen when a differentStateBackend
from the one that was used for taking a checkpoint/savepoint is used when restoring.
-
unexpectedStateHandleException
public static RuntimeException unexpectedStateHandleException(Class<? extends StateObject>[] expectedStateHandleClasses, Class<? extends StateObject> actualStateHandleClass)
Creates aRuntimeException
that signals that an operation did not get the type ofStateObject
that was expected. This can mostly happen when a differentStateBackend
from the one that was used for taking a checkpoint/savepoint is used when restoring.
-
-