org.apache.ratis.protocol.RaftGroupId Java Examples
The following examples show how to use
org.apache.ratis.protocol.RaftGroupId.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRaftServerJmx.java From ratis with Apache License 2.0 | 6 votes |
static void runRegister(boolean expectToSucceed, String name, JmxRegister jmx) { final RaftServerMXBean mBean = new RaftServerMXBean() { @Override public String getId() { return null; } @Override public String getLeaderId() { return null; } @Override public long getCurrentTerm() { return 0; } @Override public String getGroupId() { return null; } @Override public String getRole() { return null; } @Override public List<String> getFollowers() { return null; } }; final RaftPeerId id = RaftPeerId.valueOf(name); final RaftGroupId groupId = RaftGroupId.randomId(); final boolean succeeded = RaftServerImpl.registerMBean(id, groupId, mBean, jmx); Assert.assertEquals(expectToSucceed, succeeded); }
Example #2
Source File: RatisPipelineUtils.java From hadoop-ozone with Apache License 2.0 | 6 votes |
/** * Sends ratis command to destroy pipeline on the given datanode. * * @param dn - Datanode on which pipeline needs to be destroyed * @param pipelineID - ID of pipeline to be destroyed * @param ozoneConf - Ozone configuration * @param grpcTlsConfig - grpc tls configuration * @throws IOException */ static void destroyPipeline(DatanodeDetails dn, PipelineID pipelineID, ConfigurationSource ozoneConf, GrpcTlsConfig grpcTlsConfig) throws IOException { final String rpcType = ozoneConf .get(ScmConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY, ScmConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_DEFAULT); final RetryPolicy retryPolicy = RatisHelper.createRetryPolicy(ozoneConf); final RaftPeer p = RatisHelper.toRaftPeer(dn); try(RaftClient client = RatisHelper .newRaftClient(SupportedRpcType.valueOfIgnoreCase(rpcType), p, retryPolicy, grpcTlsConfig, ozoneConf)) { client.groupRemove(RaftGroupId.valueOf(pipelineID.getId()), true, p.getId()); } }
Example #3
Source File: TestRetryCacheMetrics.java From incubator-ratis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() { RaftServerImpl raftServer = mock(RaftServerImpl.class); RaftGroupId raftGroupId = RaftGroupId.randomId(); RaftPeerId raftPeerId = RaftPeerId.valueOf("TestId"); RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId .valueOf(raftPeerId, raftGroupId); when(raftServer.getMemberId()).thenReturn(raftGroupMemberId); retryCache = new RetryCache(TimeDuration.valueOf(60, TimeUnit.SECONDS)); when(raftServer.getRetryCache()).thenReturn(retryCache); RaftServerMetrics raftServerMetrics = RaftServerMetrics .getRaftServerMetrics(raftServer); ratisMetricRegistry = raftServerMetrics.getRegistry(); }
Example #4
Source File: XceiverServerRatis.java From hadoop-ozone with Apache License 2.0 | 6 votes |
@Override public void addGroup(HddsProtos.PipelineID pipelineId, Collection<DatanodeDetails> peers) throws IOException { final PipelineID pipelineID = PipelineID.getFromProtobuf(pipelineId); final RaftGroupId groupId = RaftGroupId.valueOf(pipelineID.getId()); final RaftGroup group = RatisHelper.newRaftGroup(groupId, peers); GroupManagementRequest request = GroupManagementRequest.newAdd( clientId, server.getId(), nextCallId(), group); RaftClientReply reply; try { reply = server.groupManagement(request); } catch (Exception e) { throw new IOException(e.getMessage(), e); } processReply(reply); }
Example #5
Source File: XceiverServerRatis.java From hadoop-ozone with Apache License 2.0 | 6 votes |
@Override public List<PipelineReport> getPipelineReport() { try { Iterable<RaftGroupId> gids = server.getGroupIds(); List<PipelineReport> reports = new ArrayList<>(); for (RaftGroupId groupId : gids) { HddsProtos.PipelineID pipelineID = PipelineID .valueOf(groupId.getUuid()).getProtobuf(); reports.add(PipelineReport.newBuilder() .setPipelineID(pipelineID) .setIsLeader(groupLeaderMap.getOrDefault(groupId, Boolean.FALSE)) .setBytesWritten(calculatePipelineBytesWritten(pipelineID)) .build()); } return reports; } catch (Exception e) { return null; } }
Example #6
Source File: MiniRaftCluster.java From ratis with Apache License 2.0 | 6 votes |
/** * @return the list of leaders with the highest term (i.e. leaders with a lower term are not included). * from the given group. */ private List<RaftServerImpl> getLeaders(RaftGroupId groupId) { final Stream<RaftServerImpl> serverAliveStream = getServerAliveStream(groupId); final List<RaftServerImpl> leaders = new ArrayList<>(); serverAliveStream.filter(RaftServerImpl::isLeader).forEach(s -> { if (leaders.isEmpty()) { leaders.add(s); } else { final long leaderTerm = leaders.get(0).getState().getCurrentTerm(); final long term = s.getState().getCurrentTerm(); if (term >= leaderTerm) { if (term > leaderTerm) { leaders.clear(); } leaders.add(s); } } }); return leaders; }
Example #7
Source File: XceiverServerRatis.java From hadoop-ozone with Apache License 2.0 | 6 votes |
private void triggerPipelineClose(RaftGroupId groupId, String detail, ClosePipelineInfo.Reason reasonCode, boolean triggerHB) { PipelineID pipelineID = PipelineID.valueOf(groupId.getUuid()); ClosePipelineInfo.Builder closePipelineInfo = ClosePipelineInfo.newBuilder() .setPipelineID(pipelineID.getProtobuf()) .setReason(reasonCode) .setDetailedReason(detail); PipelineAction action = PipelineAction.newBuilder() .setClosePipeline(closePipelineInfo) .setAction(PipelineAction.Action.CLOSE) .build(); context.addPipelineActionIfAbsent(action); // wait for the next HB timeout or right away? if (triggerHB) { context.getParent().triggerHeartbeat(); } LOG.error("pipeline Action {} on pipeline {}.Reason : {}", action.getAction(), pipelineID, action.getClosePipeline().getDetailedReason()); }
Example #8
Source File: Server.java From ratis with Apache License 2.0 | 6 votes |
@Override public void run() throws Exception { RaftPeerId peerId = RaftPeerId.valueOf(id); RaftProperties properties = new RaftProperties(); RaftPeer[] peers = getPeers(); final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort(); GrpcConfigKeys.Server.setPort(properties, port); properties.setInt(GrpcConfigKeys.OutputStream.RETRY_TIMES_KEY, Integer.MAX_VALUE); RaftServerConfigKeys.setStorageDirs(properties, Collections.singletonList(storageDir)); ConfUtils.setFile(properties::setFile, FileStoreCommon.STATEMACHINE_DIR_KEY, storageDir); StateMachine stateMachine = new FileStoreStateMachine(properties); final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)), peers); RaftServer raftServer = RaftServer.newBuilder() .setServerId(RaftPeerId.valueOf(id)) .setStateMachine(stateMachine).setProperties(properties) .setGroup(raftGroup) .build(); raftServer.start(); for(; raftServer.getLifeCycleState() != LifeCycle.State.CLOSED;) { TimeUnit.SECONDS.sleep(1); } }
Example #9
Source File: ContainerCommandRequestMessage.java From hadoop-ozone with Apache License 2.0 | 6 votes |
public static ContainerCommandRequestProto toProto( ByteString bytes, RaftGroupId groupId) throws InvalidProtocolBufferException { final int i = Integer.BYTES + bytes.substring(0, Integer.BYTES) .asReadOnlyByteBuffer().getInt(); final ContainerCommandRequestProto header = ContainerCommandRequestProto .parseFrom(bytes.substring(Integer.BYTES, i)); // TODO: setting pipeline id can be avoided if the client is sending it. // In such case, just have to validate the pipeline id. final ContainerCommandRequestProto.Builder b = header.toBuilder(); if (groupId != null) { b.setPipelineID(groupId.getUuid().toString()); } final ByteString data = bytes.substring(i); if (header.getCmdType() == Type.WriteChunk) { b.setWriteChunk(b.getWriteChunkBuilder().setData(data)); } else if (header.getCmdType() == Type.PutSmallFile) { b.setPutSmallFile(b.getPutSmallFileBuilder().setData(data)); } return b.build(); }
Example #10
Source File: Client.java From incubator-ratis with Apache License 2.0 | 6 votes |
@Override public void run() throws Exception { RaftProperties raftProperties = new RaftProperties(); final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers()); RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties); builder.setRaftGroup(raftGroup); builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties)); RaftClient client = builder.build(); operation(client); }
Example #11
Source File: ContainerStateMachine.java From hadoop-ozone with Apache License 2.0 | 6 votes |
public static String smProtoToString(RaftGroupId gid, ContainerController containerController, StateMachineLogEntryProto proto) { StringBuilder builder = new StringBuilder(); try { ContainerCommandRequestProto requestProto = getContainerCommandRequestProto(gid, proto.getLogData()); long contId = requestProto.getContainerID(); builder.append(TextFormat.shortDebugString(requestProto)); if (containerController != null) { String location = containerController.getContainerLocation(contId); builder.append(", container path="); builder.append(location); } } catch (Exception t) { LOG.info("smProtoToString failed", t); builder.append("smProtoToString failed with"); builder.append(t.getMessage()); } return builder.toString(); }
Example #12
Source File: ServerProtoUtils.java From ratis with Apache License 2.0 | 6 votes |
public static AppendEntriesRequestProto toAppendEntriesRequestProto( RaftPeerId requestorId, RaftPeerId replyId, RaftGroupId groupId, long leaderTerm, List<LogEntryProto> entries, long leaderCommit, boolean initializing, TermIndex previous, Collection<CommitInfoProto> commitInfos, long callId) { RaftRpcRequestProto.Builder rpcRequest = toRaftRpcRequestProtoBuilder(requestorId, replyId, groupId) .setCallId(callId); final AppendEntriesRequestProto.Builder b = AppendEntriesRequestProto .newBuilder() .setServerRequest(rpcRequest) .setLeaderTerm(leaderTerm) .setLeaderCommit(leaderCommit) .setInitializing(initializing); if (entries != null && !entries.isEmpty()) { b.addAllEntries(entries); } if (previous != null) { b.setPreviousLog(toTermIndexProto(previous)); } ProtoUtils.addCommitInfos(commitInfos, i -> b.addCommitInfos(i)); return b.build(); }
Example #13
Source File: Server.java From ratis with Apache License 2.0 | 6 votes |
@Override public void run() throws Exception { RaftPeerId peerId = RaftPeerId.valueOf(id); RaftProperties properties = new RaftProperties(); RaftPeer[] peers = getPeers(); final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort(); GrpcConfigKeys.Server.setPort(properties, port); properties.setInt(GrpcConfigKeys.OutputStream.RETRY_TIMES_KEY, Integer.MAX_VALUE); RaftServerConfigKeys.setStorageDirs(properties, Collections.singletonList(storageDir)); StateMachine stateMachine = new ArithmeticStateMachine(); final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)), peers); RaftServer raftServer = RaftServer.newBuilder() .setServerId(RaftPeerId.valueOf(id)) .setStateMachine(stateMachine).setProperties(properties) .setGroup(raftGroup) .build(); raftServer.start(); for(; raftServer.getLifeCycleState() != LifeCycle.State.CLOSED;) { TimeUnit.SECONDS.sleep(1); } }
Example #14
Source File: LeaderElectionTests.java From incubator-ratis with Apache License 2.0 | 5 votes |
private static RaftServerImpl createMockServer(boolean alive) { RaftServerImpl server = mock(RaftServerImpl.class); when(server.isAlive()).thenReturn(alive); when(server.isCandidate()).thenReturn(false); when(server.getMemberId()).thenReturn(RaftGroupMemberId.valueOf(RaftPeerId.valueOf("any"), RaftGroupId.randomId())); LeaderElectionMetrics leaderElectionMetrics = LeaderElectionMetrics.getLeaderElectionMetrics(server); when(server.getLeaderElectionMetrics()).thenReturn(leaderElectionMetrics); return server; }
Example #15
Source File: MiniRaftCluster.java From ratis with Apache License 2.0 | 5 votes |
IllegalStateException newIllegalStateExceptionForMultipleLeaders(RaftGroupId groupId, List<RaftServerImpl> leaders) { final String g = groupId == null? "": " for " + groupId; return new IllegalStateException("Found multiple leaders" + g + " at the same term (=" + leaders.get(0).getState().getCurrentTerm() + "), leaders.size() = " + leaders.size() + " > 1, leaders = " + leaders + ": " + printServers(groupId)); }
Example #16
Source File: RaftServerReply.java From incubator-ratis with Apache License 2.0 | 5 votes |
@Override public RaftGroupId getRaftGroupId() { if (isAppendEntries()) { return ProtoUtils.toRaftGroupId(appendEntries.getServerReply().getRaftGroupId()); } else if (isRequestVote()) { return ProtoUtils.toRaftGroupId(requestVote.getServerReply().getRaftGroupId()); } else { return ProtoUtils.toRaftGroupId(installSnapshot.getServerReply().getRaftGroupId()); } }
Example #17
Source File: TestClientProtoUtils.java From incubator-ratis with Apache License 2.0 | 5 votes |
void runTestToRaftClientRequestProto(int n, SizeInBytes messageSize) throws Exception { final ClientId clientId = ClientId.randomId(); final RaftPeerId leaderId = RaftPeerId.valueOf("s0"); final RaftGroupId groupId = RaftGroupId.randomId(); TimeDuration toProto = TimeDuration.ZERO; TimeDuration toRequest = TimeDuration.ZERO; for(int i = 0; i < n; i++) { final ByteString bytes = newByteString(messageSize.getSizeInt(), i); final RaftClientRequest request = new RaftClientRequest(clientId, leaderId, groupId, 1, () -> bytes, RaftClientRequest.writeRequestType(), null); final Timestamp startTime = Timestamp.currentTime(); final RaftClientRequestProto proto = ClientProtoUtils.toRaftClientRequestProto(request); final TimeDuration p = startTime.elapsedTime(); final RaftClientRequest computed = ClientProtoUtils.toRaftClientRequest(proto); final TimeDuration r = startTime.elapsedTime().subtract(p); Assert.assertEquals(request.getMessage().getContent(), computed.getMessage().getContent()); toProto = toProto.add(p); toRequest = toRequest.add(r); } System.out.printf("%nmessageSize=%s, n=%d%n", messageSize, n); print("toProto ", toProto, n); print("toRequest", toRequest, n); }
Example #18
Source File: RaftAsyncExceptionTests.java From incubator-ratis with Apache License 2.0 | 5 votes |
private void runTestGroupMismatchException(CLUSTER cluster) throws Exception { // send a message to make sure the cluster is working try(RaftClient client = cluster.createClient()) { final RaftClientReply reply = client.sendAsync(new SimpleMessage("first")).get(); Assert.assertTrue(reply.isSuccess()); } // create another group final RaftGroup clusterGroup = cluster.getGroup(); final RaftGroup anotherGroup = RaftGroup.valueOf(RaftGroupId.randomId(), clusterGroup.getPeers()); Assert.assertNotEquals(clusterGroup.getGroupId(), anotherGroup.getGroupId()); // create another client using another group final SimpleMessage[] messages = SimpleMessage.create(5); try(RaftClient client = cluster.createClient(anotherGroup)) { // send a few messages final List<CompletableFuture<RaftClientReply>> futures = new ArrayList<>(); for(SimpleMessage m : messages) { futures.add(client.sendAsync(m)); } Assert.assertEquals(messages.length, futures.size()); // check replies final Iterator<CompletableFuture<RaftClientReply>> i = futures.iterator(); testFailureCase("First reply is GroupMismatchException", () -> i.next().get(), ExecutionException.class, GroupMismatchException.class); for(; i.hasNext(); ) { testFailureCase("Following replies are AlreadyClosedException caused by GroupMismatchException", () -> i.next().get(), ExecutionException.class, AlreadyClosedException.class, GroupMismatchException.class); } } }
Example #19
Source File: TestLogAppenderMetrics.java From incubator-ratis with Apache License 2.0 | 5 votes |
@Before public void setup() { RaftGroupId raftGroupId = RaftGroupId.randomId(); raftPeerId = RaftPeerId.valueOf("TestId"); RaftPeer raftPeer = new RaftPeer(raftPeerId); RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId); LogAppender logAppender = mock(LogAppender.class); followerInfo = new TestFollowerInfo(raftGroupMemberId, raftPeer, Timestamp.currentTime(), 100L, true, 1000); when(logAppender.getFollower()).thenReturn(followerInfo); LogAppenderMetrics logAppenderMetrics = new LogAppenderMetrics(raftGroupMemberId); ratisMetricRegistry = logAppenderMetrics.getRegistry(); logAppenderMetrics.addFollowerGauges(followerInfo); }
Example #20
Source File: TestStateMachine.java From ratis with Apache License 2.0 | 5 votes |
@Test public void testStateMachineRegistry() throws Throwable { final Map<RaftGroupId, StateMachine> registry = new ConcurrentHashMap<>(); registry.put(RaftGroupId.randomId(), new SimpleStateMachine4Testing()); registry.put(RaftGroupId.randomId(), new SMTransactionContext()); try(MiniRaftClusterWithSimulatedRpc cluster = newCluster(0)) { cluster.setStateMachineRegistry(registry::get); final RaftPeerId id = RaftPeerId.valueOf("s0"); cluster.putNewServer(id, null, true); cluster.start(); for(RaftGroupId gid : registry.keySet()) { final RaftGroup newGroup = RaftGroup.valueOf(gid, cluster.getPeers()); LOG.info("add new group: " + newGroup); final RaftClient client = cluster.createClient(newGroup); for(RaftPeer p : newGroup.getPeers()) { client.groupAdd(newGroup, p.getId()); } } final RaftServerProxy proxy = cluster.getServer(id); for(Map.Entry<RaftGroupId, StateMachine> e: registry.entrySet()) { final RaftServerImpl impl = RaftServerTestUtil.getRaftServerImpl(proxy, e.getKey()); Assert.assertSame(e.getValue(), impl.getStateMachine()); } } }
Example #21
Source File: ArithmeticStateMachine.java From incubator-ratis with Apache License 2.0 | 5 votes |
@Override public void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException { super.initialize(server, groupId, raftStorage); this.storage.init(raftStorage); loadSnapshot(storage.getLatestSnapshot()); }
Example #22
Source File: LogStateMachine.java From incubator-ratis with Apache License 2.0 | 5 votes |
@Override public void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException { super.initialize(server, groupId, raftStorage); this.storage.init(raftStorage); this.proxy = (RaftServerProxy) server; //TODO: using groupId for metric now but better to tag it with LogName this.logServiceMetrics = new LogServiceMetrics(groupId.toString(), server.getId().toString()); this.readNextQueryTimer = logServiceMetrics.getTimer("readNextQueryTime"); this.startIndexTimer= logServiceMetrics.getTimer("startIndexTime"); this.sizeRequestTimer = logServiceMetrics.getTimer("sizeRequestTime"); this.getStateTimer = logServiceMetrics.getTimer("getStateTime"); this.lastIndexQueryTimer = logServiceMetrics.getTimer("lastIndexQueryTime"); this.lengthQueryTimer = logServiceMetrics.getTimer("lengthQueryTime"); this.syncRequesTimer = logServiceMetrics.getTimer("syncRequesTime"); this.appendRequestTimer = logServiceMetrics.getTimer("appendRequestTime"); this.getCloseLogTimer = logServiceMetrics.getTimer("getCloseLogTime"); //archiving request time not the actual archiving time this.archiveLogRequestTimer = logServiceMetrics.getTimer("archiveLogRequestTime"); this.archiveLogTimer = logServiceMetrics.getTimer("archiveLogTime"); loadSnapshot(storage.getLatestSnapshot()); executorService = Executors.newSingleThreadExecutor(); this.archivalInfo = new ArchivalInfo(properties.get(Constants.LOG_SERVICE_ARCHIVAL_LOCATION_KEY)); }
Example #23
Source File: MiniRaftCluster.java From incubator-ratis with Apache License 2.0 | 5 votes |
IllegalStateException newIllegalStateExceptionForMultipleLeaders(RaftGroupId groupId, List<RaftServerImpl> leaders) { final String g = groupId == null? "": " for " + groupId; return new IllegalStateException("Found multiple leaders" + g + " at the same term (=" + leaders.get(0).getState().getCurrentTerm() + "), leaders.size() = " + leaders.size() + " > 1, leaders = " + leaders + ": " + printServers(groupId)); }
Example #24
Source File: Server.java From incubator-ratis with Apache License 2.0 | 5 votes |
@Override public void run() throws Exception { JVMMetrics.initJvmMetrics(TimeDuration.valueOf(10, TimeUnit.SECONDS)); RaftPeerId peerId = RaftPeerId.valueOf(id); RaftProperties properties = new RaftProperties(); final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort(); GrpcConfigKeys.Server.setPort(properties, port); properties.setInt(GrpcConfigKeys.OutputStream.RETRY_TIMES_KEY, Integer.MAX_VALUE); RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir)); ConfUtils.setFile(properties::setFile, FileStoreCommon.STATEMACHINE_DIR_KEY, storageDir); StateMachine stateMachine = new FileStoreStateMachine(properties); final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers()); RaftServer raftServer = RaftServer.newBuilder() .setServerId(RaftPeerId.valueOf(id)) .setStateMachine(stateMachine).setProperties(properties) .setGroup(raftGroup) .build(); raftServer.start(); for (; raftServer.getLifeCycleState() != LifeCycle.State.CLOSED; ) { TimeUnit.SECONDS.sleep(1); } }
Example #25
Source File: FileStoreStateMachine.java From incubator-ratis with Apache License 2.0 | 5 votes |
@Override public void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException { super.initialize(server, groupId, raftStorage); this.storage.init(raftStorage); FileUtils.createDirectories(files.getRoot()); }
Example #26
Source File: FileStoreStateMachine.java From ratis with Apache License 2.0 | 5 votes |
@Override public void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException { super.initialize(server, groupId, raftStorage); this.storage.init(raftStorage); FileUtils.createDirectories(files.getRoot()); }
Example #27
Source File: ArithmeticStateMachine.java From ratis with Apache License 2.0 | 5 votes |
@Override public void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException { super.initialize(server, groupId, raftStorage); this.storage.init(raftStorage); loadSnapshot(storage.getLatestSnapshot()); }
Example #28
Source File: TestOzoneManagerRatisServer.java From hadoop-ozone with Apache License 2.0 | 5 votes |
@Test public void verifyRaftGroupIdGenerationWithDefaultOmServiceId() throws Exception { UUID uuid = UUID.nameUUIDFromBytes(OzoneConsts.OM_SERVICE_ID_DEFAULT .getBytes()); RaftGroupId raftGroupId = omRatisServer.getRaftGroup().getGroupId(); Assert.assertEquals(uuid, raftGroupId.getUuid()); Assert.assertEquals(raftGroupId.toByteString().size(), 16); }
Example #29
Source File: MiniRaftCluster.java From ratis with Apache License 2.0 | 5 votes |
public static RaftGroup initRaftGroup(Collection<String> ids) { final RaftPeer[] peers = ids.stream() .map(RaftPeerId::valueOf) .map(id -> new RaftPeer(id, NetUtils.createLocalServerAddress())) .toArray(RaftPeer[]::new); return RaftGroup.valueOf(RaftGroupId.randomId(), peers); }
Example #30
Source File: LeaderAppendLogEntryGenerator.java From hadoop-ozone with Apache License 2.0 | 5 votes |
private void configureGroup() throws IOException { ClientId clientId = ClientId.randomId(); RaftGroupId groupId = RaftGroupId .valueOf(UUID.fromString(pipelineId)); RaftPeerId peerId = RaftPeerId.getRaftPeerId(serverId); RaftGroup group = RaftGroup.valueOf(groupId, new RaftPeer(RaftPeerId.valueOf(serverId), serverAddress), new RaftPeer(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1), FAKE_LEADER_ADDDRESS1), new RaftPeer(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1), FAKE_LEADER_ADDDRESS2)); RaftClient client = RaftClient.newBuilder() .setClientId(clientId) .setProperties(new RaftProperties(true)) .setRaftGroup(group) .build(); RaftClientReply raftClientReply = client.groupAdd(group, peerId); LOG.info( "Group is configured in the RAFT server (with two fake leader leader)" + ": {}", raftClientReply); }