T
- Type of stateR
- Type of ResourceVersion
public interface StateHandleStore<T extends Serializable,R extends ResourceVersion<R>>
RetrievableStateStorageHelper
and writes the
returned state handle to distributed coordination system(e.g. Zookeeper, Kubernetes, etc.).
To avoid concurrent modification issues, the implementation needs to ensure that only the leader could update the state store.
Even some methods name contains the "lock"(e.g. getAndLock(java.lang.String)
), it does not mean the
implementation has to actually lock a specific state handle. Also it could have an empty
implementation for release operation.
Modifier and Type | Interface and Description |
---|---|
static class |
StateHandleStore.AlreadyExistException
The key already exists in ConfigMap or the Zookeeper node already exists.
|
static class |
StateHandleStore.NotExistException
The key does not exist in ConfigMap or the Zookeeper node does not exists.
|
Modifier and Type | Method and Description |
---|---|
RetrievableStateHandle<T> |
addAndLock(String name,
T state)
Persist the state to distributed storage(e.g.
|
void |
clearEntries()
Only clears all the state handle pointers on Kubernetes or ZooKeeper.
|
R |
exists(String name)
Returns resource version of state handle with specific name on the underlying storage.
|
List<Tuple2<RetrievableStateHandle<T>,String>> |
getAllAndLock()
Gets all available state handles from the storage.
|
Collection<String> |
getAllHandles()
Return a list of all valid name for state handles.
|
RetrievableStateHandle<T> |
getAndLock(String name)
Gets the
RetrievableStateHandle stored with the given name. |
void |
release(String name)
Releases the lock on the specific state handle so that it could be deleted by other
StateHandleStore . |
void |
releaseAll()
Releases all the locks on corresponding state handle so that it could be deleted by other
StateHandleStore . |
boolean |
releaseAndTryRemove(String name)
Releases the lock for the given state handle and tries to remove the state handle if it is no
longer locked.
|
void |
releaseAndTryRemoveAll()
Releases and removes all the states.
|
void |
replace(String name,
R resourceVersion,
T state)
Replaces a state handle in the distributed coordination system and discards the old state
handle.
|
RetrievableStateHandle<T> addAndLock(String name, T state) throws PossibleInconsistentStateException, Exception
name
- Key name in ConfigMap or child path name in ZooKeeperstate
- State to be addedStateHandleStore.AlreadyExistException
- if the name already existsPossibleInconsistentStateException
- if the write operation failed. This indicates that
it's not clear whether the new state was successfully written to distributed coordination
system or not. No state was discarded. Proper error handling has to be applied on the
caller's side.Exception
- if persisting state or writing state handle failedvoid replace(String name, R resourceVersion, T state) throws PossibleInconsistentStateException, Exception
name
- Key name in ConfigMap or child path name in ZooKeeperresourceVersion
- resource version of previous storage object. If the resource version
does not match, the replace operation will fail. Since there is an unexpected update
operation snuck in.state
- State to be replace withStateHandleStore.NotExistException
- if the name does not existPossibleInconsistentStateException
- if a failure occurred during the update operation
for which it's unclear whether the operation actually succeeded or not. No state was
discarded. The method's caller should handle this case properly.Exception
- if persisting state or writing state handle failedR exists(String name) throws Exception
name
- Key name in ConfigMap or child path name in ZooKeeperException
- if the check existence operation failedRetrievableStateHandle<T> getAndLock(String name) throws Exception
RetrievableStateHandle
stored with the given name.name
- Key name in ConfigMap or child path name in ZooKeeperIOException
- if the method failed to deserialize the stored state handleStateHandleStore.NotExistException
- when the name does not existException
- if get state handle failedList<Tuple2<RetrievableStateHandle<T>,String>> getAllAndLock() throws Exception
Exception
- if get state handle operation failedCollection<String> getAllHandles() throws Exception
Exception
- if get handle operation failedboolean releaseAndTryRemove(String name) throws Exception
name
- Key name in ConfigMap or child path name in ZooKeepertrue
if the state handle is removed (also if it didn't exist in the first
place); otherwise false
.Exception
- if releasing, removing the handles or discarding the state failedvoid releaseAndTryRemoveAll() throws Exception
Exception
- if releasing, removing the handles or discarding the state failed. The
removal of the states should happen independently from each other, i.e. the method call
fails if at least one removal failed. But the removal of any other state should still be
performed.void clearEntries() throws Exception
Exception
- if removing the handles failedvoid release(String name) throws Exception
StateHandleStore
. If no lock exists or the underlying storage does not support, nothing will
happen.Exception
- if releasing the lockvoid releaseAll() throws Exception
StateHandleStore
. If no lock exists or the underlying storage does not support,
nothing will happen.Exception
- if releasing the locksCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.