Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -399,6 +399,17 @@ private synchronized boolean updateLeaderOMNodeId(String newLeaderOMNodeId) {
* @return delay in milliseconds
*/
public synchronized long getWaitTime() {
// OMs are being contacted in Round Robin way. If all the OMs have been
// contacted once in this attempt, clear the list. The OMs will be retried
// in a Round Robin fashion again after a fixed delay. This is checked first
// because with a single OM, Round Robin selects the same OM again, which is
// not a retry on the same OM based on response from OM.
if (attemptedOMs.containsAll(omProxies.getNodeIds())) {
attemptedOMs.clear();
numAttemptsOnSameOM = 0;
return waitBetweenRetries;
}

if (omProxies.getNodeId(nextProxyIndex).equals(lastAttemptedOM)) {
// Clear attemptedOMs list as the same OM has been selected again.
attemptedOMs.clear();
Expand All @@ -409,19 +420,7 @@ public synchronized long getWaitTime() {
}
// Reset numAttemptsOnSameOM as we failed over to a different OM.
numAttemptsOnSameOM = 0;

// OMs are being contacted in Round Robin way. Check if all the OMs have
// been contacted in this attempt.
for (String omNodeID : omProxies.getNodeIds()) {
if (!attemptedOMs.contains(omNodeID)) {
return 0;
}
}
// This implies all the OMs have been contacted once. Return true and
// clear the list. The OMs will be retried in a Round Robin fashion again
// after a delay.
attemptedOMs.clear();
return waitBetweenRetries;
return 0;
}

public List<OMProxyInfo<T>> getOMProxies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ public void testWaitTimeResetWhenAllNodeFailoverAndSameNode() {
failoverToNextNode(1, waitBetweenRetries);
}

/**
* Tests waitTime with a single OM: Round Robin failover (e.g. on connection
* failure) selects the same OM again, and should not increase the wait time.
*/
@Test
public void testWaitTimeWithSingleNode() throws IOException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OZONE_OM_ADDRESS_KEY, DUMMY_NODE_ADDR);
provider = new HadoopRpcOMFailoverProxyProvider<>(conf, UserGroupInformation.getCurrentUser(), null,
OzoneManagerProtocolPB.class);

failoverToNextNode(3, waitBetweenRetries);
// Retry on the same OM based on response from OM, waitTime should increase.
failoverToSameNode(2);
// Round Robin failover again should reset waitTime.
failoverToNextNode(1, waitBetweenRetries);
}

/**
* Ensure listener nodes are excluded from provider's proxy list.
*/
Expand Down