Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-17685: Option to explicitly choose DFS client lease renewal interval #7215

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
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 @@ -202,6 +202,9 @@ public interface HdfsClientConfigKeys {
long DFS_CLIENT_DEAD_NODE_DETECTION_PROBE_SUSPECT_NODE_INTERVAL_MS_DEFAULT =
300; // 300ms

String DFS_CLIENT_LEASE_RENEWAL_INTERVAL_KEY = "dfs.client.lease.renewal.interval.ms";
int DFS_CLIENT_LEASE_RENEWAL_INTERVAL_DEFAULT = 0;

// refreshing LocatedBlocks period. A value of 0 disables the feature.
String DFS_CLIENT_REFRESH_READ_BLOCK_LOCATIONS_MS_KEY =
"dfs.client.refresh.read-block-locations.ms";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class DfsClientConf {
.class);

private final int hdfsTimeout; // timeout value for a DFS operation.
private final int leaseRenewalIntervalMs;

private final int maxFailoverAttempts;
private final int maxRetryAttempts;
Expand Down Expand Up @@ -170,7 +171,9 @@ public class DfsClientConf {
public DfsClientConf(Configuration conf) {
// The hdfsTimeout is currently the same as the ipc timeout
hdfsTimeout = Client.getRpcTimeout(conf);

leaseRenewalIntervalMs = conf.getInt(
HdfsClientConfigKeys.DFS_CLIENT_LEASE_RENEWAL_INTERVAL_KEY,
HdfsClientConfigKeys.DFS_CLIENT_LEASE_RENEWAL_INTERVAL_DEFAULT);
maxRetryAttempts = conf.getInt(
Retry.MAX_ATTEMPTS_KEY,
Retry.MAX_ATTEMPTS_DEFAULT);
Expand All @@ -183,7 +186,6 @@ public DfsClientConf(Configuration conf) {
retryIntervalForGetLastBlockLength = conf.getInt(
Retry.INTERVAL_GET_LAST_BLOCK_LENGTH_KEY,
Retry.INTERVAL_GET_LAST_BLOCK_LENGTH_DEFAULT);

maxFailoverAttempts = conf.getInt(
Failover.MAX_ATTEMPTS_KEY,
Failover.MAX_ATTEMPTS_DEFAULT);
Expand Down Expand Up @@ -431,6 +433,10 @@ public int getHdfsTimeout() {
return hdfsTimeout;
}

public int getLeaseRenewalIntervalMs() {
return leaseRenewalIntervalMs;
}

/**
* @return the maxFailoverAttempts
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -248,14 +249,7 @@ private synchronized void addClient(final DFSClient dfsc) {
//client not found, add it
dfsclients.add(dfsc);

//update renewal time
final int hdfsTimeout = dfsc.getConf().getHdfsTimeout();
if (hdfsTimeout > 0) {
final long half = hdfsTimeout/2;
if (half < renewal) {
this.renewal = half;
}
}
renewal = getNewRenewalIntervalMs(dfsclients);
}

private synchronized void clearClients() {
Expand Down Expand Up @@ -378,17 +372,42 @@ public synchronized void closeClient(final DFSClient dfsc) {
}
}

//update renewal time
if (renewal == dfsc.getConf().getHdfsTimeout()/2) {
long min = HdfsConstants.LEASE_SOFTLIMIT_PERIOD;
for(DFSClient c : dfsclients) {
final int timeout = c.getConf().getHdfsTimeout();
if (timeout > 0 && timeout < min) {
min = timeout;
renewal = getNewRenewalIntervalMs(dfsclients);
}

@VisibleForTesting
static long getNewRenewalIntervalMs(Collection<DFSClient> dfsClients) {
// Update renewal time to the first applicable of:
// 1. Requested renewal time amongst all DFSClients, if requested and smaller than the default
// renewal interval
// 2. Half the HDFS timeout amongst all DFSClients, if requested and smaller than the default
// renewal interval
// 3. Default renewal time of HdfsConstants.LEASE_SOFTLIMIT_PERIOD / 2
// #2 exists because users with small timeouts want to find out quickly when a NameNode dies,
// and a small lease renewal interval will help to inform them quickly. See HDFS-278.
long min = HdfsConstants.LEASE_SOFTLIMIT_PERIOD / 2;
boolean leaseOverrideSet = false;
for (DFSClient c : dfsClients) {
final int newLeaseRenewalInterval = c.getConf().getLeaseRenewalIntervalMs();
if (newLeaseRenewalInterval > 0 && newLeaseRenewalInterval <= min) {
min = newLeaseRenewalInterval;
leaseOverrideSet = true;
}
}
if (leaseOverrideSet) {
return min;
}

for (DFSClient c : dfsClients) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you combine the two loop to one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think it would make the code more complicated. The logic I want is that the lowest valid value from getLeaseRenewalIntervalMs() takes precedence over any value from getHdfsTimeout(). So, doing that in one loop would require tracking two mins.

final int hdfsTimeout = c.getConf().getHdfsTimeout();
if (hdfsTimeout > 0) {
final long half = hdfsTimeout/2;
if (half < min) {
min = half;
}
}
renewal = min/2;
}
return min;
}

public void interruptAndJoin() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.function.Supplier;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.DFSOutputStream;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time;
Expand All @@ -37,7 +38,10 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;

import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.doReturn;

public class TestLeaseRenewer {
private final String FAKE_AUTHORITY="hdfs://nn1/";
Expand Down Expand Up @@ -284,4 +288,67 @@ private static int countThreadMatching(Pattern pattern) {
}
return count;
}

@Test
public void testDefaultRenewalInterval() {
final DfsClientConf mockConf = Mockito.mock(DfsClientConf.class);
doReturn(0).when(mockConf).getLeaseRenewalIntervalMs();
doReturn(0).when(mockConf).getHdfsTimeout();
DFSClient dfsClient = Mockito.mock(DFSClient.class);
doReturn(mockConf).when(dfsClient).getConf();
// Use default renewal interval if both explicit renewal interval and HDFS timeout are not set
Assert.assertEquals(HdfsConstants.LEASE_SOFTLIMIT_PERIOD / 2,
LeaseRenewer.getNewRenewalIntervalMs(ImmutableList.of(dfsClient)));
}

@Test
public void testShortExplicitRenewalInterval() {
final DfsClientConf mockConf = Mockito.mock(DfsClientConf.class);
doReturn(37).when(mockConf).getLeaseRenewalIntervalMs();
doReturn(100).when(mockConf).getHdfsTimeout();
DFSClient dfsClient = Mockito.mock(DFSClient.class);
doReturn(mockConf).when(dfsClient).getConf();
// Explicit renewal interval is shorter than half the HDFS timeout, renewer should use it
Assert.assertEquals(37,
LeaseRenewer.getNewRenewalIntervalMs(ImmutableList.of(dfsClient)));
}

@Test
public void testMediumExplicitRenewalInterval() {
final DfsClientConf mockConf = Mockito.mock(DfsClientConf.class);
doReturn(370).when(mockConf).getLeaseRenewalIntervalMs();
doReturn(100).when(mockConf).getHdfsTimeout();
DFSClient dfsClient = Mockito.mock(DFSClient.class);
doReturn(mockConf).when(dfsClient).getConf();
// Explicit renewal interval is longer than half the HDFS timeout,
// renewer should use it regardless
Assert.assertEquals(370,
LeaseRenewer.getNewRenewalIntervalMs(ImmutableList.of(dfsClient)));
}

@Test
public void testLongExplicitRenewalIntervalWithShortHdfsTimeout() {
final DfsClientConf mockConf = Mockito.mock(DfsClientConf.class);
doReturn(37000).when(mockConf).getLeaseRenewalIntervalMs();
doReturn(100).when(mockConf).getHdfsTimeout();
DFSClient dfsClient = Mockito.mock(DFSClient.class);
doReturn(mockConf).when(dfsClient).getConf();
// Explicit renewal interval is longer than HdfsConstants.LEASE_SOFTLIMIT_PERIOD / 2,
// but half the HDFS timeout is shorter, so renewer should use the HDFS timeout
Assert.assertEquals(50,
LeaseRenewer.getNewRenewalIntervalMs(ImmutableList.of(dfsClient)));
}

@Test
public void testLongExplicitRenewalIntervalWithLongHdfsTimeout() {
final DfsClientConf mockConf = Mockito.mock(DfsClientConf.class);
doReturn(37000).when(mockConf).getLeaseRenewalIntervalMs();
doReturn(120000).when(mockConf).getHdfsTimeout();
DFSClient dfsClient = Mockito.mock(DFSClient.class);
doReturn(mockConf).when(dfsClient).getConf();
// Explicit renewal interval and HDFS timeout is longer than
// HdfsConstants.LEASE_SOFTLIMIT_PERIOD / 2, so renewer should use default renewal interval
Assert.assertEquals(HdfsConstants.LEASE_SOFTLIMIT_PERIOD / 2,
LeaseRenewer.getNewRenewalIntervalMs(ImmutableList.of(dfsClient)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3444,6 +3444,16 @@
</description>
</property>

<property>
<name>dfs.client.lease.renewal.interval.ms</name>
<value>0</value>
<description>
If set between 0 and 30000 inclusive, HDFS clients will renew leases for files they are writing at this interval.
If dfs.client.lease.renewal.interval.ms is not set and ipc.client.rpc-timeout.ms is set between 0 and 60000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is magic about the 60000 maximum value of ipc.client.rpc-timeout.ms ? I guess that comes from existing behavior?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from existing behavior, yes. The lease renewal interval isn't allowed to be longer than half of the NameNode's timeout, which is hard-coded at 60 seconds.

then the value of ipc.client.rpc-timeout.ms / 2 will be used as the lease renewal interval.
</description>
</property>

<property>
<name>dfs.client.refresh.read-block-locations.ms</name>
<value>0</value>
Expand Down
Loading