Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 Expand Up @@ -2070,6 +2071,7 @@ message RecoverLeaseRequest {
optional string volumeName = 1;
optional string bucketName = 2;
optional string keyName = 3;
optional bool force = 4;
}

message RecoverLeaseResponse {
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 All @@ -75,6 +80,7 @@ public class OMRecoverLeaseRequest extends OMKeyRequest {
private String dbFileKey;
private OmKeyInfo openKeyInfo;
private String dbOpenFileKey;
private boolean force;

private OMMetadataManager omMetadataManager;

Expand All @@ -87,6 +93,7 @@ public OMRecoverLeaseRequest(OMRequest omRequest) {
volumeName = recoverLeaseRequest.getVolumeName();
bucketName = recoverLeaseRequest.getBucketName();
keyName = recoverLeaseRequest.getKeyName();
force = recoverLeaseRequest.getForce();
}

@Override
Expand Down Expand Up @@ -144,7 +151,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 @@ -212,6 +218,12 @@ private RecoverLeaseResponse doWork(OzoneManager ozoneManager,
if (openKeyInfo.getMetadata().containsKey(OzoneConsts.LEASE_RECOVERY)) {
LOG.debug("Key: " + keyName + " is already under recovery");
} else {
final long leaseSoftLimit = ozoneManager.getConfiguration()
.getTimeDuration(OZONE_OM_LEASE_SOFT_LIMIT, OZONE_OM_LEASE_SOFT_LIMIT_DEFAULT, TimeUnit.MILLISECONDS);
if (!force && 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);
}
openKeyInfo.getMetadata().put(OzoneConsts.LEASE_RECOVERY, "true");
openKeyInfo.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
openKeyInfo.setModificationTime(Time.now());
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,40 @@ public void testRecoverAbsentFile() throws Exception {
verifyTables(false, false);
}

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

// update soft limit to high value
ozoneManager.getConfiguration().set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "2s");
// Call recovery inside soft limit period it should fail
OMClientResponse 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());
// Call second time inside soft limit period also should fail
omClientResponse = validateAndUpdateCache();
omResponse = omClientResponse.getOMResponse();
Assertions.assertEquals(OzoneManagerProtocolProtos.Status.KEY_UNDER_LEASE_SOFT_LIMIT_PERIOD,
omResponse.getStatus());
Thread.sleep(2000);
// Call recovery 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);

// Call recovery again it should succeed
omClientResponse = validateAndUpdateCache();
omResponse = omClientResponse.getOMResponse();
Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, omResponse.getStatus());
recoverLeaseResponse = omResponse.getRecoverLeaseResponse();
keyInfo = recoverLeaseResponse.getKeyInfo();
Assertions.assertNotNull(keyInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

@ashishkumar50, could you test the both force and non-force case in this testLeaseSoftLimitForHsyncRecoverFile ? Try the Parametrized test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

private KeyArgs getNewKeyArgs(OmKeyInfo omKeyInfo, long deltaLength) throws IOException {
OmKeyLocationInfoGroup omKeyLocationInfoGroup = omKeyInfo.getLatestVersionLocations();
List<OmKeyLocationInfo> omKeyLocationInfoList = omKeyLocationInfoGroup.getBlocksLatestVersionOnly();
Expand Down Expand Up @@ -355,6 +390,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