public class RaftSessionService extends Object implements ManagedService, SnapshotAwareService<com.hazelcast.cp.internal.session.RaftSessionRegistry>, SessionAccessor, TermChangeAwareService, RaftNodeLifecycleAwareService, CPSessionManagementService
CPSubsystemConfig.getSessionTimeToLiveSeconds()
seconds, its session
is closed. That caller is considered to be alive as long as it is committing
heartbeats.
Blocking Raft services can make use of the session abstraction to attach
resources to sessions. On session termination, its attached resources will
be released automatically.Modifier and Type | Field and Description |
---|---|
static String |
SERVICE_NAME |
Constructor and Description |
---|
RaftSessionService(NodeEngine nodeEngine) |
Modifier and Type | Method and Description |
---|---|
void |
closeInactiveSessions(CPGroupId groupId,
Collection<Long> inactiveSessions) |
boolean |
closeSession(CPGroupId groupId,
long sessionId) |
SessionResponse |
createNewSession(CPGroupId groupId,
Address endpoint,
String endpointName,
CPSession.CPSessionOwnerType endpointType) |
void |
expireSessions(CPGroupId groupId,
Collection<Tuple2<Long,Long>> sessionsToExpire) |
ICompletableFuture<Boolean> |
forceCloseSession(String groupName,
long sessionId)
If a Hazelcast instance that owns a CP session crashes, its CP session
is not terminated immediately.
|
long |
generateThreadId(CPGroupId groupId) |
ICompletableFuture<Collection<CPSession>> |
getAllSessions(String groupName)
Returns a non-null collection of CP sessions that are currently active
in the given CP group.
|
Collection<CPSession> |
getSessionsLocally(CPGroupId groupId) |
void |
heartbeat(CPGroupId groupId,
long sessionId)
Performs a heartbeat for the given session id in the Raft group.
|
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this service.
|
boolean |
isActive(CPGroupId groupId,
long sessionId)
Checks if there is an active session with the given id in the Raft group
|
void |
onNewTermCommit(CPGroupId groupId,
long commitIndex)
Invokes as part of the first commit after a new leader is elected.
|
void |
onRaftGroupDestroyed(CPGroupId groupId)
Called on the thread of the Raft group when the given Raft node is
destroyed, either gracefully or forcefully.
|
void |
onRaftNodeSteppedDown(CPGroupId groupId)
Called on the thread of the Raft group when the given Raft node is
stepped down, either because it is shutting down, or it could not be
added to the Raft group
|
void |
reset()
Resets this service back to its initial state.
|
void |
restoreSnapshot(CPGroupId groupId,
long commitIndex,
com.hazelcast.cp.internal.session.RaftSessionRegistry registry)
Restores the snapshot for specified
CPGroupId . |
void |
shutdown(boolean terminate)
Shuts down this service.
|
com.hazelcast.cp.internal.session.RaftSessionRegistry |
takeSnapshot(CPGroupId groupId,
long commitIndex)
Creates a snapshot for specified
CPGroupId . |
public static final String SERVICE_NAME
public RaftSessionService(NodeEngine nodeEngine)
public void init(NodeEngine nodeEngine, Properties properties)
ManagedService
init
in interface ManagedService
nodeEngine
- the NodeEngine that this service belongs toproperties
- the Properties (can be used to pass settings to the service)public void reset()
ManagedService
TODO: what is the purpose of reset
reset
in interface ManagedService
public void shutdown(boolean terminate)
ManagedService
TODO: what is the purpose of the terminate variable
shutdown
in interface ManagedService
terminate
- true
to shut down this servicepublic com.hazelcast.cp.internal.session.RaftSessionRegistry takeSnapshot(CPGroupId groupId, long commitIndex)
SnapshotAwareService
CPGroupId
.
The snapshot object returned from this method will be stored among
the Raft log and it can be sent to other Raft nodes anytime. Therefore,
this method must not return a snapshot object that can mutate after
the takeSnapshot() call.takeSnapshot
in interface SnapshotAwareService<com.hazelcast.cp.internal.session.RaftSessionRegistry>
groupId
- CPGroupId
which is snapshot requested forcommitIndex
- commitIndex of the taken snapshotCPGroupId
.public void restoreSnapshot(CPGroupId groupId, long commitIndex, com.hazelcast.cp.internal.session.RaftSessionRegistry registry)
SnapshotAwareService
CPGroupId
.restoreSnapshot
in interface SnapshotAwareService<com.hazelcast.cp.internal.session.RaftSessionRegistry>
groupId
- CPGroupId
of the snapshot to be restoredcommitIndex
- commitIndex of the restored snapshotregistry
- snapshot for specified CPGroupId
public void onNewTermCommit(CPGroupId groupId, long commitIndex)
TermChangeAwareService
onNewTermCommit
in interface TermChangeAwareService
groupId
- id of the Raft group in which a new leader is electedcommitIndex
- index of the commit in the Raft logpublic void onRaftGroupDestroyed(CPGroupId groupId)
RaftNodeLifecycleAwareService
onRaftGroupDestroyed
in interface RaftNodeLifecycleAwareService
public void onRaftNodeSteppedDown(CPGroupId groupId)
RaftNodeLifecycleAwareService
onRaftNodeSteppedDown
in interface RaftNodeLifecycleAwareService
public ICompletableFuture<Collection<CPSession>> getAllSessions(String groupName)
CPSessionManagementService
getAllSessions
in interface CPSessionManagementService
public ICompletableFuture<Boolean> forceCloseSession(String groupName, long sessionId)
CPSessionManagementService
CPSubsystemConfig.getSessionTimeToLiveSeconds()
passes.
If it is known for sure that the session owner is not partitioned and
definitely crashed, this method can be used for closing the session and
releasing its resources immediately.forceCloseSession
in interface CPSessionManagementService
public SessionResponse createNewSession(CPGroupId groupId, Address endpoint, String endpointName, CPSession.CPSessionOwnerType endpointType)
public void heartbeat(CPGroupId groupId, long sessionId)
SessionAccessor
heartbeat
in interface SessionAccessor
public boolean closeSession(CPGroupId groupId, long sessionId)
public void expireSessions(CPGroupId groupId, Collection<Tuple2<Long,Long>> sessionsToExpire)
public void closeInactiveSessions(CPGroupId groupId, Collection<Long> inactiveSessions)
public long generateThreadId(CPGroupId groupId)
public Collection<CPSession> getSessionsLocally(CPGroupId groupId)
public boolean isActive(CPGroupId groupId, long sessionId)
SessionAccessor
isActive
in interface SessionAccessor
Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.