Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -128,6 +128,14 @@ public final class OzoneConfigKeys {
public static final boolean OZONE_FS_HSYNC_ENABLED_DEFAULT
= false;

/**
* hsync lease soft limit.
*/
public static final String OZONE_OM_LEASE_SOFT_LIMIT
= "ozone.om.lease.soft.limit";
public static final String OZONE_OM_LEASE_SOFT_LIMIT_DEFAULT
= "60s";


/**
* When set to true, allocate a random free port for ozone container, so that
Expand Down
8 changes: 8 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3988,6 +3988,14 @@
Enable hsync/hflush. By default they are disabled.
</description>
</property>
<property>
<name>ozone.om.lease.soft.limit</name>
<value>60s</value>
<tag>OZONE, OM</tag>
<description>
Hsync soft limit lease period.
</description>
</property>

<property>
<name>ozone.recon.scm.snapshot.task.initial.delay</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public enum ResultCodes {

INVALID_PATH,
KEY_UNDER_LEASE_RECOVERY,
KEY_ALREADY_CLOSED
KEY_ALREADY_CLOSED,
KEY_UNDER_LEASE_SOFT_LIMIT_PERIOD
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void init() throws IOException, InterruptedException,
conf.setBoolean(OZONE_OM_RATIS_ENABLE_KEY, false);
conf.setBoolean(OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED, true);
conf.set(OZONE_DEFAULT_BUCKET_LAYOUT, layout.name());
conf.set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "0s");
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(5)
.setTotalPipelineNumLimit(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private void init() throws Exception {
conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, omRatisEnabled);
conf.setBoolean(OZONE_ACL_ENABLED, true);
conf.setBoolean(OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED, true);
conf.set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "0s");
if (!bucketLayout.equals(FILE_SYSTEM_OPTIMIZED)) {
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enabledFileSystemPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public static void initClusterAndEnv() throws IOException,
conf.setFloat(FS_TRASH_CHECKPOINT_INTERVAL_KEY, TRASH_INTERVAL / 2);
conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, omRatisEnabled);
conf.setBoolean(OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED, true);
conf.set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "0s");
if (isBucketFSOptimized) {
bucketLayout = BucketLayout.FILE_SYSTEM_OPTIMIZED;
conf.set(OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class TestLeaseRecoverer {
public static void init() throws Exception {
conf = new OzoneConfiguration();
conf.setBoolean(OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED, true);
conf.set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "0s");
String clusterId = UUID.randomUUID().toString();
String scmId = UUID.randomUUID().toString();
String omId = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ enum Status {
INVALID_PATH = 93;
KEY_UNDER_LEASE_RECOVERY = 94;
KEY_ALREADY_CLOSED = 95;
KEY_UNDER_LEASE_SOFT_LIMIT_PERIOD = 96;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RecoverLeaseRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RecoverLeaseResponse;

import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT_DEFAULT;
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type.RecoverLease;

import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
Expand All @@ -56,9 +59,11 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_ALREADY_CLOSED;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_UNDER_LEASE_SOFT_LIMIT_PERIOD;
import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;

/**
Expand Down Expand Up @@ -144,7 +149,6 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
RecoverLeaseResponse recoverLeaseResponse = doWork(ozoneManager, transactionLogIndex);

// Prepare response
boolean responseCode = true;
omResponse.setRecoverLeaseResponse(recoverLeaseResponse).setCmdType(RecoverLease);
omClientResponse = new OMRecoverLeaseResponse(omResponse.build(), getBucketLayout(),
dbOpenFileKey, openKeyInfo);
Expand Down Expand Up @@ -209,6 +213,13 @@ private RecoverLeaseResponse doWork(OzoneManager ozoneManager,
throw new OMException("Open Key " + dbOpenFileKey + " not found in openKeyTable", KEY_NOT_FOUND);
}

final long leaseSoftLimit = ozoneManager.getConfiguration()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move this check before the OzoneConsts.LEASE_RECOVERY already exists check, otherwise, the second call of recoverLease will fail due to this soft limit check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved

.getTimeDuration(OZONE_OM_LEASE_SOFT_LIMIT, OZONE_OM_LEASE_SOFT_LIMIT_DEFAULT, TimeUnit.MILLISECONDS);
if (Time.now() < openKeyInfo.getModificationTime() + leaseSoftLimit) {
throw new OMException("Open Key " + keyName + " updated recently and is inside soft limit period",
KEY_UNDER_LEASE_SOFT_LIMIT_PERIOD);
}

if (openKeyInfo.getMetadata().containsKey(OzoneConsts.LEASE_RECOVERY)) {
LOG.debug("Key: " + keyName + " is already under recovery");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.KeyValueUtil;
Expand Down Expand Up @@ -297,6 +298,29 @@ public void testRecoverAbsentFile() throws Exception {
verifyTables(false, false);
}

@Test
public void testLeaseSoftLimitForHsyncRecoverFile() throws Exception {
populateNamespace(true, true, true, true);

// Call first time
OMClientResponse omClientResponse = validateAndUpdateCache();
// Update soft limit period to high value
ozoneManager.getConfiguration().set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "2s");
// Call second time inside soft limit, it should fail
omClientResponse = validateAndUpdateCache();
OMResponse omResponse = omClientResponse.getOMResponse();
Assertions.assertEquals(OzoneManagerProtocolProtos.Status.KEY_UNDER_LEASE_SOFT_LIMIT_PERIOD,
Copy link
Contributor

Choose a reason for hiding this comment

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

The second call should success. The soft limit period is to prevent recoveror to recover the client too soon when there is still client writing to this file. When the file is already under recovery, the soft limit period will have no use.

omResponse.getStatus());
Thread.sleep(2000);
// Call again after soft limit period it should succeed
omClientResponse = validateAndUpdateCache();
omResponse = omClientResponse.getOMResponse();
Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, omResponse.getStatus());
RecoverLeaseResponse recoverLeaseResponse = omResponse.getRecoverLeaseResponse();
KeyInfo keyInfo = recoverLeaseResponse.getKeyInfo();
Assertions.assertNotNull(keyInfo);
}

private KeyArgs getNewKeyArgs(OmKeyInfo omKeyInfo, long deltaLength) throws IOException {
OmKeyLocationInfoGroup omKeyLocationInfoGroup = omKeyInfo.getLatestVersionLocations();
List<OmKeyLocationInfo> omKeyLocationInfoList = omKeyLocationInfoGroup.getBlocksLatestVersionOnly();
Expand Down Expand Up @@ -355,6 +379,9 @@ private void populateNamespace(boolean addKeyTable, boolean keyInfoWithHsyncFlag
.get(openKey);
assertNotNull(omKeyInfo);
}

// Set lease soft limit to 0
ozoneManager.getConfiguration().set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "0s");
}

protected OMRequest createAllocateBlockRequest(String volumeName, String bucketName, String keyName) {
Expand Down