public class RaftService extends Object implements ManagedService, SnapshotAwareService<MetadataRaftGroupSnapshot>, GracefulShutdownAwareService, MembershipAwareService, CPSubsystemManagementService, PreJoinAwareService, RaftNodeLifecycleAwareService
RaftNode
instances that run the Raft consensus algorithm
for the created CP groups. Also implements CP subsystem management methods.Modifier and Type | Field and Description |
---|---|
static String |
SERVICE_NAME |
Constructor and Description |
---|
RaftService(NodeEngine nodeEngine) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitUntilDiscoveryCompleted(long timeout,
TimeUnit timeUnit)
Blocks until CP discovery process is completed, or the timeout occurs,
or the current thread is interrupted, whichever happens first.
|
RaftGroupId |
createRaftGroupForProxy(String name) |
InternalCompletableFuture<RaftGroupId> |
createRaftGroupForProxyAsync(String name) |
void |
createRaftNode(CPGroupId groupId,
Collection<CPMemberInfo> members) |
void |
destroyRaftNode(CPGroupId groupId) |
ICompletableFuture<Void> |
forceDestroyCPGroup(String groupName)
this method is idempotent
|
ICompletableFuture<Collection<CPGroupId>> |
getAllCPGroupIds() |
Collection<RaftNode> |
getAllRaftNodes() |
CPSubsystemConfig |
getConfig() |
ICompletableFuture<CPGroup> |
getCPGroup(CPGroupId groupId) |
ICompletableFuture<CPGroup> |
getCPGroup(String name)
Returns the active CP group with the given name.
|
ICompletableFuture<Collection<CPGroupId>> |
getCPGroupIds()
Returns all active CP group ids.
|
Collection<CPGroupId> |
getCPGroupIdsLocally() |
CPGroupInfo |
getCPGroupLocally(CPGroupId groupId) |
ICompletableFuture<Collection<CPMember>> |
getCPMembers()
Returns the current list of CP members
|
static String |
getGroupNameForProxy(String name) |
RaftInvocationManager |
getInvocationManager() |
CPMemberInfo |
getLocalCPMember()
Returns the local CP member if this Hazelcast member is part of
the CP subsystem, returns null otherwise.
|
RaftGroupId |
getMetadataGroupId() |
MetadataRaftGroupManager |
getMetadataGroupManager() |
static String |
getObjectNameForProxy(String name) |
RaftNode |
getOrInitRaftNode(CPGroupId groupId) |
Operation |
getPreJoinOperation()
An operation to be executed on the joining member before it is set as joined.
|
RaftNode |
getRaftNode(CPGroupId groupId) |
void |
handleActiveCPMembers(RaftGroupId latestMetadataGroupId,
long membersCommitIndex,
Collection<CPMemberInfo> members) |
void |
handleAppendEntries(CPGroupId groupId,
AppendRequest request,
CPMember target) |
void |
handleAppendResponse(CPGroupId groupId,
AppendFailureResponse response,
CPMember target) |
void |
handleAppendResponse(CPGroupId groupId,
AppendSuccessResponse response,
CPMember target) |
void |
handlePreVoteRequest(CPGroupId groupId,
PreVoteRequest request,
CPMember target) |
void |
handlePreVoteResponse(CPGroupId groupId,
PreVoteResponse response,
CPMember target) |
void |
handleSnapshot(CPGroupId groupId,
InstallSnapshot request,
CPMember target) |
void |
handleVoteRequest(CPGroupId groupId,
VoteRequest request,
CPMember target) |
void |
handleVoteResponse(CPGroupId groupId,
VoteResponse response,
CPMember target) |
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this service.
|
boolean |
isDiscoveryCompleted()
Returns whether CP discovery process is completed or not.
|
boolean |
isRaftGroupDestroyed(CPGroupId groupId) |
void |
memberAdded(MembershipServiceEvent event)
Invoked when a new member is added to the cluster.
|
void |
memberAttributeChanged(MemberAttributeServiceEvent event)
Invoked when a member attribute is changed.
|
void |
memberRemoved(MembershipServiceEvent event)
Invoked when an existing member leaves the cluster.
|
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
|
boolean |
onShutdown(long timeout,
TimeUnit unit)
A hook method that's called during graceful shutdown to provide safety for data managed by this service.
|
ICompletableFuture<Void> |
promoteToCPMember()
Promotes the local Hazelcast member to a CP member.
|
ICompletableFuture<Void> |
removeCPMember(String cpMemberUuid)
Removes the given unreachable CP member from the active CP members list
and all CP groups it belongs to.
|
void |
reset()
Resets this service back to its initial state.
|
ICompletableFuture<Void> |
restart()
Wipes and resets the whole CP subsystem and initializes it
as if the Hazelcast cluster is starting up initially.
|
void |
restartLocal(long seed) |
void |
restoreSnapshot(CPGroupId groupId,
long commitIndex,
MetadataRaftGroupSnapshot snapshot)
Restores the snapshot for specified
CPGroupId . |
void |
shutdown(boolean terminate)
Shuts down this service.
|
void |
stepDownRaftNode(CPGroupId groupId) |
MetadataRaftGroupSnapshot |
takeSnapshot(CPGroupId groupId,
long commitIndex)
Creates a snapshot for specified
CPGroupId . |
static String |
withoutDefaultGroupName(String name) |
public static final String SERVICE_NAME
public RaftService(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 MetadataRaftGroupSnapshot 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<MetadataRaftGroupSnapshot>
groupId
- CPGroupId
which is snapshot requested forcommitIndex
- commitIndex of the taken snapshotCPGroupId
.public void restoreSnapshot(CPGroupId groupId, long commitIndex, MetadataRaftGroupSnapshot snapshot)
SnapshotAwareService
CPGroupId
.restoreSnapshot
in interface SnapshotAwareService<MetadataRaftGroupSnapshot>
groupId
- CPGroupId
of the snapshot to be restoredcommitIndex
- commitIndex of the restored snapshotsnapshot
- snapshot for specified CPGroupId
public ICompletableFuture<Collection<CPGroupId>> getAllCPGroupIds()
public ICompletableFuture<Collection<CPGroupId>> getCPGroupIds()
CPSubsystemManagementService
getCPGroupIds
in interface CPSubsystemManagementService
public ICompletableFuture<CPGroup> getCPGroup(CPGroupId groupId)
public ICompletableFuture<CPGroup> getCPGroup(String name)
CPSubsystemManagementService
getCPGroup
in interface CPSubsystemManagementService
public ICompletableFuture<Void> restart()
CPSubsystemManagementService
After this method is called, all CP state and data are wiped and the CP members start with empty state.
This method can be invoked only from the Hazelcast master member.
This method must not be called while there are membership changes in the cluster. Before calling this method, please make sure that there is no new member joining and all existing Hazelcast members have seen the same member list.
Use with caution: This method is NOT idempotent and multiple invocations can break the whole system! After calling this API, you must observe the system to see if the restart process is successfully completed or failed before making another call.
restart
in interface CPSubsystemManagementService
public void restartLocal(long seed)
public ICompletableFuture<Void> promoteToCPMember()
CPSubsystemManagementService
This method is idempotent. If the local member is already in the active CP members list, then this method has no effect. When the current member is promoted to a CP member, its member UUID is assigned as CP member UUID.
Once the returned Future
object is completed, the promoted CP
member has been added to the CP groups that have missing members, i.e.,
whose size is smaller than CPSubsystemConfig.getGroupSize()
.
If the local member is currently being removed from
the active CP members list, then the returned Future
object
will throw IllegalArgumentException
.
If there is an ongoing membership change in the CP subsystem when this
method is invoked, then the returned Future
object throws
IllegalStateException
If the CP subsystem initial discovery process has not completed when
this method is invoked, then the returned Future
object throws
IllegalStateException
promoteToCPMember
in interface CPSubsystemManagementService
public ICompletableFuture<Void> removeCPMember(String cpMemberUuid)
CPSubsystemManagementService
Before removing a CP member from the CP subsystem, please make sure that it is declared as unreachable by Hazelcast's failure detector and removed from Hazelcast's member list. The behavior is undefined when a running CP member is removed from the CP subsystem.
removeCPMember
in interface CPSubsystemManagementService
public ICompletableFuture<Void> forceDestroyCPGroup(String groupName)
forceDestroyCPGroup
in interface CPSubsystemManagementService
public ICompletableFuture<Collection<CPMember>> getCPMembers()
CPSubsystemManagementService
getCPMembers
in interface CPSubsystemManagementService
public boolean isDiscoveryCompleted()
CPSubsystemManagementService
isDiscoveryCompleted
in interface CPSubsystemManagementService
true
if CP discovery completed, false
otherwiseCPSubsystemManagementService.awaitUntilDiscoveryCompleted(long, TimeUnit)
public boolean awaitUntilDiscoveryCompleted(long timeout, TimeUnit timeUnit) throws InterruptedException
CPSubsystemManagementService
awaitUntilDiscoveryCompleted
in interface CPSubsystemManagementService
timeout
- maximum time to waittimeUnit
- time unit of the timeouttrue
if CP discovery completed, false
otherwiseInterruptedException
- if interrupted while waitingCPSubsystemManagementService.isDiscoveryCompleted()
public boolean onShutdown(long timeout, TimeUnit unit)
GracefulShutdownAwareService
onShutdown
in interface GracefulShutdownAwareService
timeout
- timeout for graceful shutdownunit
- time unitpublic Operation getPreJoinOperation()
PreJoinAwareService
PostJoinAwareService.getPostJoinOperation()
s, no partition locks, no key-based locks, no service level
locks, no database interaction are allowed. Additionally, a pre-join operation is executed while the cluster
lock is being held on the joining member, so it is important that the operation finishes quickly and does not
interact with other locks.
The Operation.getPartitionId()
method should return a negative value.
This means that the operations should not implement PartitionAwareOperation
.
Pre join operations should return response, which may also be a null
response.
getPreJoinOperation
in interface PreJoinAwareService
null
.public void memberAdded(MembershipServiceEvent event)
MembershipAwareService
memberAdded
in interface MembershipAwareService
event
- the event for a new member added to the clusterpublic void memberRemoved(MembershipServiceEvent event)
MembershipAwareService
memberRemoved
in interface MembershipAwareService
event
- the event for an existing member leaving the clusterpublic void memberAttributeChanged(MemberAttributeServiceEvent event)
MembershipAwareService
memberAttributeChanged
in interface MembershipAwareService
event
- the event for a member attribute being changedpublic Collection<CPGroupId> getCPGroupIdsLocally()
public CPGroupInfo getCPGroupLocally(CPGroupId groupId)
public MetadataRaftGroupManager getMetadataGroupManager()
public RaftInvocationManager getInvocationManager()
public void handlePreVoteRequest(CPGroupId groupId, PreVoteRequest request, CPMember target)
public void handlePreVoteResponse(CPGroupId groupId, PreVoteResponse response, CPMember target)
public void handleVoteRequest(CPGroupId groupId, VoteRequest request, CPMember target)
public void handleVoteResponse(CPGroupId groupId, VoteResponse response, CPMember target)
public void handleAppendEntries(CPGroupId groupId, AppendRequest request, CPMember target)
public void handleAppendResponse(CPGroupId groupId, AppendSuccessResponse response, CPMember target)
public void handleAppendResponse(CPGroupId groupId, AppendFailureResponse response, CPMember target)
public void handleSnapshot(CPGroupId groupId, InstallSnapshot request, CPMember target)
public Collection<RaftNode> getAllRaftNodes()
public boolean isRaftGroupDestroyed(CPGroupId groupId)
public CPSubsystemConfig getConfig()
public CPMemberInfo getLocalCPMember()
CPSubsystemManagementService
This field is initialized when the local Hazelcast member is one of
the first CPSubsystemConfig.getCPMemberCount()
members
in the cluster and the CP subsystem discovery process is completed.
HazelcastException
if the CP subsystem
is not enabled.getLocalCPMember
in interface CPSubsystemManagementService
CPSubsystemManagementService.isDiscoveryCompleted()
,
CPSubsystemManagementService.awaitUntilDiscoveryCompleted(long, TimeUnit)
public void createRaftNode(CPGroupId groupId, Collection<CPMemberInfo> members)
public void destroyRaftNode(CPGroupId groupId)
public void stepDownRaftNode(CPGroupId groupId)
public RaftGroupId createRaftGroupForProxy(String name)
public InternalCompletableFuture<RaftGroupId> createRaftGroupForProxyAsync(String name)
public RaftGroupId getMetadataGroupId()
public void handleActiveCPMembers(RaftGroupId latestMetadataGroupId, long membersCommitIndex, Collection<CPMemberInfo> members)
public void onRaftGroupDestroyed(CPGroupId groupId)
RaftNodeLifecycleAwareService
onRaftGroupDestroyed
in interface RaftNodeLifecycleAwareService
public void onRaftNodeSteppedDown(CPGroupId groupId)
RaftNodeLifecycleAwareService
onRaftNodeSteppedDown
in interface RaftNodeLifecycleAwareService
Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.