You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "sumitagrawl (via GitHub)" <gi...@apache.org> on 2023/04/04 10:17:16 UTC

[GitHub] [ozone] sumitagrawl commented on a diff in pull request #4234: HDDS-7769. Implement client initiated lease recovery

sumitagrawl commented on code in PR #4234:
URL: https://github.com/apache/ozone/pull/4234#discussion_r1157013257


##########
hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java:
##########
@@ -505,6 +505,19 @@ String getOpenFileName(long volumeId, long bucketId,
    */
   String getRenameKey(String volume, String bucket, long objectID);
 
+  /**
+   * Returns DB key name of an open file in OM metadata store. Should be
+   * #open# prefix followed by actual leaf node name.
+   *
+   * @param volumeId       - ID of the volume
+   * @param bucketId       - ID of the bucket
+   * @param parentObjectId - parent object Id
+   * @param fileName       - file name
+   * @return DB directory key as String.
+   */
+  String getOpenFileNamePrefix(long volumeId, long bucketId,

Review Comment:
   We can use existing method org.apache.hadoop.ozone.om.OMMetadataManager#getOzonePathKey(long, long, long, java.lang.String)



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/file/OMRecoverLeaseResponse.java:
##########
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.response.file;
+
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.response.CleanupTableInfo;
+import org.apache.hadoop.ozone.om.response.key.OmKeyResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+        .OMResponse;
+
+import javax.annotation.Nonnull;
+import java.io.IOException;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.FILE_TABLE;
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.OPEN_FILE_TABLE;
+
+/**
+ * Performs tasks for RecoverLease request responses.
+ */
+@CleanupTableInfo(cleanupTables = {FILE_TABLE, OPEN_FILE_TABLE})
+public class OMRecoverLeaseResponse extends OmKeyResponse {
+
+  private OmKeyInfo keyInfo;
+  private String dbFileKey;
+  private String openKeyName;
+  public OMRecoverLeaseResponse(@Nonnull OMResponse omResponse,
+      BucketLayout bucketLayout, OmKeyInfo keyInfo, String dbFileKey,
+      String openKeyName) {
+    super(omResponse, bucketLayout);
+    this.keyInfo = keyInfo;
+    this.dbFileKey = dbFileKey;
+    this.openKeyName = openKeyName;
+  }
+
+  /**
+   * For when the request is not successful.
+   * For a successful request, the other constructor should be used.
+   */
+  public OMRecoverLeaseResponse(@Nonnull OMResponse omResponse,
+      @Nonnull BucketLayout bucketLayout) {
+    super(omResponse, bucketLayout);
+    checkStatusNotOK();
+  }
+
+  @Override
+  protected void addToDBBatch(OMMetadataManager omMetadataManager,
+      BatchOperation batchOperation) throws IOException {
+    // Delete from OpenKey table
+    if (openKeyName != null) {
+      omMetadataManager.getOpenKeyTable(getBucketLayout()).deleteWithBatch(
+          batchOperation, openKeyName);
+    }
+    omMetadataManager.getKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED)

Review Comment:
   If openKeyInfo is not present, we may not need to update keyTable again, its like no-ops kind of operation.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMRecoverLeaseRequest.java:
##########
@@ -0,0 +1,281 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.file;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.file.OMRecoverLeaseResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+        .OMResponse;
+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 org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.util.Time;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+        .Type.RecoverLease;
+
+/**
+ * Perform actions for RecoverLease requests.
+ */
+public class OMRecoverLeaseRequest extends OMKeyRequest {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OMRecoverLeaseRequest.class);
+
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+
+  private OMMetadataManager omMetadataManager;
+
+  public OMRecoverLeaseRequest(OMRequest omRequest) {
+    super(omRequest, BucketLayout.FILE_SYSTEM_OPTIMIZED);
+    RecoverLeaseRequest recoverLeaseRequest = getOmRequest()
+        .getRecoverLeaseRequest();
+
+    Preconditions.checkNotNull(recoverLeaseRequest);
+    volumeName = recoverLeaseRequest.getVolumeName();
+    bucketName = recoverLeaseRequest.getBucketName();
+    keyName = recoverLeaseRequest.getKeyName();
+  }
+
+  @Override
+  public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+    RecoverLeaseRequest recoverLeaseRequest = getOmRequest()
+        .getRecoverLeaseRequest();
+
+    String keyPath = recoverLeaseRequest.getKeyName();
+    String normalizedKeyPath =
+        validateAndNormalizeKey(ozoneManager.getEnableFileSystemPaths(),
+            keyPath, getBucketLayout());
+
+    return getOmRequest().toBuilder()
+        .setRecoverLeaseRequest(
+            recoverLeaseRequest.toBuilder()
+                .setKeyName(normalizedKeyPath))
+        .build();
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long transactionLogIndex,
+      OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
+    RecoverLeaseRequest recoverLeaseRequest = getOmRequest()
+        .getRecoverLeaseRequest();
+    Preconditions.checkNotNull(recoverLeaseRequest);
+
+    Map<String, String> auditMap = new LinkedHashMap<>();
+    auditMap.put(OzoneConsts.VOLUME, volumeName);
+    auditMap.put(OzoneConsts.BUCKET, bucketName);
+    auditMap.put(OzoneConsts.KEY, keyName);
+
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+
+    omMetadataManager = ozoneManager.getMetadataManager();
+    OMClientResponse omClientResponse = null;
+    IOException exception = null;
+    // increment metric
+    OMMetrics omMetrics = ozoneManager.getMetrics();
+
+    boolean acquiredLock = false;
+    try {
+      // check ACL
+      checkKeyAcls(ozoneManager, volumeName, bucketName, keyName,
+          IAccessAuthorizer.ACLType.WRITE, OzoneObj.ResourceType.KEY);
+
+      // acquire lock
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String openKeyEntryName = doWork(ozoneManager, recoverLeaseRequest,
+          transactionLogIndex);
+
+      // Prepare response
+      boolean responseCode = true;
+      omResponse.setRecoverLeaseResponse(RecoverLeaseResponse.newBuilder()
+              .setResponse(responseCode).build())
+          .setCmdType(RecoverLease);
+      omClientResponse =
+          new OMRecoverLeaseResponse(omResponse.build(), getBucketLayout(),
+              openKeyEntryName);
+      omMetrics.incNumRecoverLease();
+      LOG.debug("Key recovered. Volume:{}, Bucket:{}, Key:{}", volumeName,
+          bucketName, keyName);
+    } catch (IOException ex) {
+      LOG.error("Fail for recovering lease. Volume:{}, Bucket:{}, Key:{}",
+          volumeName, bucketName, keyName, ex);
+      exception = ex;
+      omMetrics.incNumRecoverLeaseFails();
+      omResponse.setCmdType(RecoverLease);
+      omClientResponse = new OMRecoverLeaseResponse(
+          createErrorOMResponse(omResponse, ex), getBucketLayout());
+    } finally {
+      if (omClientResponse != null) {
+        omClientResponse.setFlushFuture(
+            ozoneManagerDoubleBufferHelper.add(omClientResponse,
+                transactionLogIndex));
+      }
+      if (acquiredLock) {
+        omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName,
+            bucketName);
+      }
+    }
+
+    // Audit Log outside the lock
+    auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(
+        OMAction.RECOVER_LEASE, auditMap, exception,
+        getOmRequest().getUserInfo()));
+
+    return omClientResponse;
+  }
+
+  private String doWork(OzoneManager ozoneManager,
+      RecoverLeaseRequest recoverLeaseRequest, long transactionLogIndex)
+      throws IOException {
+
+    final long volumeId = omMetadataManager.getVolumeId(volumeName);
+    final long bucketId = omMetadataManager.getBucketId(
+        volumeName, bucketName);
+    Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+    long parentID = OMFileRequest.getParentID(volumeId, bucketId,
+        pathComponents, keyName, omMetadataManager,
+        "Cannot recover file : " + keyName
+            + " as parent directory doesn't exist");
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String dbFileKey = omMetadataManager.getOzonePathKey(volumeId, bucketId,
+        parentID, fileName);
+
+    OmKeyInfo keyInfo = getKey(dbFileKey);

Review Comment:
   @jojochuang 
   This releaseRecovery is not supported as TestOMRecoverLeaseRequest.testRecoverOpenFile with assert KEY_NOT_FOUND.  Seems scope is only reaseRecovery of HSync file, please confirm if this is only scope.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org