|
26 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
27 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; |
28 | 28 | import static org.junit.jupiter.api.Assertions.assertFalse; |
29 | | -import static org.junit.jupiter.api.Assertions.assertNotEquals; |
30 | 29 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
31 | 30 | import static org.junit.jupiter.api.Assertions.assertNotSame; |
32 | 31 | import static org.junit.jupiter.api.Assertions.assertSame; |
|
57 | 56 | import org.apache.hadoop.ozone.om.ha.HadoopRpcOMFailoverProxyProvider; |
58 | 57 | import org.apache.hadoop.ozone.om.ha.HadoopRpcOMFollowerReadFailoverProxyProvider; |
59 | 58 | import org.apache.hadoop.ozone.om.ha.OMProxyInfo; |
| 59 | +import org.apache.hadoop.ozone.om.protocolPB.OmTransport; |
| 60 | +import org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB; |
60 | 61 | import org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolPB; |
61 | 62 | import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer; |
62 | 63 | import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; |
63 | 64 | import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest; |
| 65 | +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListVolumeRequest; |
| 66 | +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListVolumeRequest.Scope; |
| 67 | +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse; |
64 | 68 | import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type; |
65 | 69 | import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo; |
66 | 70 | import org.apache.hadoop.ozone.protocolPB.OzoneManagerProtocolServerSideTranslatorPB; |
@@ -122,50 +126,6 @@ void testFollowerReadTargetsFollower() throws Exception { |
122 | 126 | assertEquals(followerOMNodeId, lastProxy.getNodeId()); |
123 | 127 | } |
124 | 128 |
|
125 | | - @Test |
126 | | - public void testOMProxyProviderFailoverToCurrentLeader() throws Exception { |
127 | | - ObjectStore objectStore = getObjectStore(); |
128 | | - HadoopRpcOMFailoverProxyProvider<OzoneManagerProtocolPB> omFailoverProxyProvider = |
129 | | - OmTestUtil.getFailoverProxyProvider(objectStore); |
130 | | - HadoopRpcOMFollowerReadFailoverProxyProvider<OzoneManagerProtocolPB> followerReadFailoverProxyProvider = |
131 | | - OmTestUtil.getFollowerReadFailoverProxyProvider(objectStore); |
132 | | - String initialFollowerReadNodeId = followerReadFailoverProxyProvider.getCurrentProxy().getNodeId(); |
133 | | - |
134 | | - // Run couple of createVolume tests to discover the current Leader OM |
135 | | - createVolumeTest(true); |
136 | | - createVolumeTest(true); |
137 | | - |
138 | | - // The oMFailoverProxyProvider will point to the current leader OM node. |
139 | | - String leaderOMNodeId = omFailoverProxyProvider.getCurrentProxyOMNodeId(); |
140 | | - |
141 | | - // Perform a manual failover of the proxy provider to move the |
142 | | - // currentProxyIndex to a node other than the leader OM. |
143 | | - omFailoverProxyProvider.selectNextOmProxy(); |
144 | | - omFailoverProxyProvider.performFailover(null); |
145 | | - |
146 | | - String newProxyNodeId = omFailoverProxyProvider.getCurrentProxyOMNodeId(); |
147 | | - assertNotEquals(leaderOMNodeId, newProxyNodeId); |
148 | | - |
149 | | - // Once another request is sent to this new proxy node, the leader |
150 | | - // information must be returned via the response and a failover must |
151 | | - // happen to the leader proxy node. |
152 | | - // This will also do some read operations where this might read from the follower. |
153 | | - createVolumeTest(true); |
154 | | - Thread.sleep(2000); |
155 | | - |
156 | | - String newLeaderOMNodeId = |
157 | | - omFailoverProxyProvider.getCurrentProxyOMNodeId(); |
158 | | - |
159 | | - // The old and new Leader OM NodeId must match since there was no new |
160 | | - // election in the Ratis ring. |
161 | | - assertEquals(leaderOMNodeId, newLeaderOMNodeId); |
162 | | - |
163 | | - // The follower read proxy should remain unchanged since the follower is not throwing exceptions |
164 | | - // The performFailover on the leader proxy should not affect the follower read proxy provider |
165 | | - String currentFollowerReadNodeId = followerReadFailoverProxyProvider.getCurrentProxy().getNodeId(); |
166 | | - assertEquals(initialFollowerReadNodeId, currentFollowerReadNodeId); |
167 | | - } |
168 | | - |
169 | 129 | /** |
170 | 130 | * Choose a follower to send the request, the returned exception should |
171 | 131 | * include the suggested leader node. |
@@ -461,4 +421,53 @@ public void testAllBucketOperations() throws Exception { |
461 | 421 | OzoneTestUtils.expectOmException(OMException.ResultCodes.BUCKET_NOT_FOUND, |
462 | 422 | () -> retVolume.deleteBucket(bucketName)); |
463 | 423 | } |
| 424 | + |
| 425 | + @Test |
| 426 | + void testOMResponseLeaderOmNodeId() throws Exception { |
| 427 | + HadoopRpcOMFailoverProxyProvider<OzoneManagerProtocolPB> omFailoverProxyProvider = |
| 428 | + OmTestUtil.getFailoverProxyProvider(getObjectStore()); |
| 429 | + HadoopRpcOMFollowerReadFailoverProxyProvider<OzoneManagerProtocolPB> followerReadFailoverProxyProvider = |
| 430 | + OmTestUtil.getFollowerReadFailoverProxyProvider(getObjectStore()); |
| 431 | + |
| 432 | + // Make sure All OMs are ready |
| 433 | + createVolumeTest(true); |
| 434 | + |
| 435 | + // The OMFailoverProxyProvider will point to the current leader OM node. |
| 436 | + String leaderOMNodeId = omFailoverProxyProvider.getCurrentProxyOMNodeId(); |
| 437 | + String initialNextProxyOmNodeId = omFailoverProxyProvider.getNextProxyOMNodeId(); |
| 438 | + OzoneManager followerOM = null; |
| 439 | + for (OzoneManager om: getCluster().getOzoneManagersList()) { |
| 440 | + if (!om.isLeaderReady()) { |
| 441 | + followerOM = om; |
| 442 | + break; |
| 443 | + } |
| 444 | + } |
| 445 | + assertNotNull(followerOM); |
| 446 | + assertSame(OzoneManagerRatisServer.RaftServerStatus.NOT_LEADER, |
| 447 | + followerOM.getOmRatisServer().getLeaderStatus()); |
| 448 | + |
| 449 | + |
| 450 | + ListVolumeRequest req = |
| 451 | + ListVolumeRequest.newBuilder() |
| 452 | + .setScope(Scope.VOLUMES_BY_USER) |
| 453 | + .build(); |
| 454 | + |
| 455 | + OzoneManagerProtocolProtos.OMRequest readRequest = |
| 456 | + OzoneManagerProtocolProtos.OMRequest.newBuilder() |
| 457 | + .setCmdType(Type.ListVolume) |
| 458 | + .setListVolumeRequest(req) |
| 459 | + .setVersion(ClientVersion.CURRENT_VERSION) |
| 460 | + .setClientId(randomUUID().toString()) |
| 461 | + .build(); |
| 462 | + |
| 463 | + OmTransport omTransport = ((OzoneManagerProtocolClientSideTranslatorPB) |
| 464 | + getObjectStore().getClientProxy().getOzoneManagerClient()).getTransport(); |
| 465 | + followerReadFailoverProxyProvider.changeInitialProxyForTest(followerOM.getOMNodeId()); |
| 466 | + OMResponse omResponse = omTransport.submitRequest(readRequest); |
| 467 | + |
| 468 | + // The returned OM response should be the same as the actual leader OM node ID |
| 469 | + assertEquals(leaderOMNodeId, omResponse.getLeaderOMNodeId()); |
| 470 | + // There should not be any change in the leader proxy's next proxy OM node ID |
| 471 | + assertEquals(initialNextProxyOmNodeId, omFailoverProxyProvider.getNextProxyOMNodeId()); |
| 472 | + } |
464 | 473 | } |
0 commit comments