Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.protocol.RaftPeer;
import org.apache.ratis.server.RaftServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Named;
Expand Down Expand Up @@ -95,11 +96,24 @@ public void testOmTransfer() throws Exception {
OzoneManager newLeader = omList.get(0);
cluster.waitForClusterToBeReady();
String[] args1 = {"om", "transfer", "-n", newLeader.getOMNodeId()};
ozoneAdmin.execute(args1);
Thread.sleep(3000);
assertEquals(ExitCode.OK, ozoneAdmin.execute(args1));
GenericTestUtils.waitFor(() -> newLeader.equals(cluster.getOMLeader()) && newLeader.isLeaderReady()
&& newLeader.getOmRatisServer().getServerDivision().getGroup().getPeers().stream()
.allMatch(peer -> peer.getPriority() == RatisHelper.NEUTRAL_PRIORITY), 100, 30000);
assertEquals(newLeader, cluster.getOMLeader());
assertOMResetPriorities();

final RaftServer.Division division = newLeader.getOmRatisServer().getServerDivision();
final long term = division.getInfo().getCurrentTerm();
final long configurationIndex = division.getRaftConf().getLogEntryIndex();
for (int i = 0; i < 2; i++) {
assertEquals(ExitCode.OK, ozoneAdmin.execute(args1));
assertEquals(newLeader, cluster.getOMLeader());
assertEquals(term, division.getInfo().getCurrentTerm());
assertEquals(configurationIndex, division.getRaftConf().getLogEntryIndex());
assertOMResetPriorities();
}

oldLeader = cluster.getOMLeader();
String[] args3 = {"om", "transfer", "-r"};
ozoneAdmin.execute(args3);
Expand All @@ -114,6 +128,18 @@ static Stream<Named<Function<StorageContainerManager, String>>> scmTargetIdExtra
Named.of("nodeId", StorageContainerManager::getSCMNodeId));
}

@Test
public void testOmTransferToUnknownIdFails() throws Exception {
OzoneManager leader = cluster.getOMLeader();

String[] args = {"om", "transfer", "-n", "no-such-om"};
try (GenericTestUtils.SystemErrCapturer capture = new GenericTestUtils.SystemErrCapturer()) {
assertNotEquals(ExitCode.OK, ozoneAdmin.execute(args));
assertThat(capture.getOutput()).contains("Target no-such-om not found in group");
}
assertEquals(leader, cluster.getOMLeader());
}

@ParameterizedTest
@MethodSource("scmTargetIdExtractors")
public void testScmTransfer(Function<StorageContainerManager, String> targetId) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4057,9 +4057,9 @@ public void transferLeadership(String newLeaderId)
auditMap.put("newLeaderId", newLeaderId);
try {
final RaftServer.Division division = omRatisServer.getServerDivision();
final RaftPeerId curLeader = omRatisServer.getLeaderId();
final RaftPeerId targetPeerId;
if (newLeaderId.isEmpty()) {
final RaftPeerId curLeader = omRatisServer.getLeaderId();
targetPeerId = division.getGroup().getPeers().stream()
.map(RaftPeer::getId)
.filter(id -> !id.equals(curLeader))
Expand All @@ -4069,6 +4069,11 @@ public void transferLeadership(String newLeaderId)
targetPeerId = RaftPeerId.valueOf(newLeaderId);
}

if (targetPeerId.equals(curLeader)) {
LOG.info("Target {} is already the leader. Skipping leadership transfer.", targetPeerId);
return;
}

final GrpcTlsConfig tlsConfig =
OzoneManagerRatisUtils.createServerTlsConfig(secConfig, certClient);

Expand Down