arp7 commented on a change in pull request #884: HDDS-1620. Implement Volume 
Write Requests to use Cache and DoubleBuffer.
URL: https://github.com/apache/hadoop/pull/884#discussion_r292743782
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/OMVolumeDeleteRequest.java
 ##########
 @@ -0,0 +1,200 @@
+/**
+ * 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.volume;
+
+import java.io.IOException;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.response.volume.OMVolumeCreateResponse;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.volume.OMVolumeDeleteResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+    .DeleteVolumeRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+    .DeleteVolumeResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+    .OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+    .OMResponse;
+import org.apache.hadoop.utils.db.cache.CacheKey;
+import org.apache.hadoop.utils.db.cache.CacheValue;
+
+
+/**
+ * Handles volume delete request.
+ */
+public class OMVolumeDeleteRequest extends OMClientRequest
+    implements OMVolumeRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OMVolumeDeleteRequest.class);
+
+  public OMVolumeDeleteRequest(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long transactionLogIndex) {
+
+    DeleteVolumeRequest deleteVolumeRequest =
+        getOmRequest().getDeleteVolumeRequest();
+    Preconditions.checkNotNull(deleteVolumeRequest);
+
+    String volume = deleteVolumeRequest.getVolumeName();
+
+    OMMetrics omMetrics = ozoneManager.getMetrics();
+    omMetrics.incNumVolumeDeletes();
+
+    OMResponse.Builder omResponse = OMResponse.newBuilder().setCmdType(
+        OzoneManagerProtocolProtos.Type.DeleteVolume).setStatus(
+        OzoneManagerProtocolProtos.Status.OK).setSuccess(true);
+
+    AuditLogger auditLogger = ozoneManager.getAuditLogger();
+    OzoneManagerProtocolProtos.UserInfo userInfo = 
getOmRequest().getUserInfo();
+
+    try {
+      // check Acl
+      if (ozoneManager.getAclsEnabled()) {
+        checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME,
+            OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.DELETE, volume,
+            null, null);
+      }
+    } catch (IOException ex) {
+      LOG.error("Volume deletion failed for volume:{}", volume, ex);
+      omMetrics.incNumVolumeDeleteFails();
+      auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_VOLUME,
+          buildVolumeAuditMap(volume), ex, userInfo));
+      return new OMVolumeCreateResponse(null, null,
+          createErrorOMResponse(omResponse, ex));
+    }
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+
+    OmVolumeArgs omVolumeArgs = null;
+    String owner = null;
+
+    omMetadataManager.getLock().acquireVolumeLock(volume);
+    try {
+      owner = getVolumeInfo(omMetadataManager, volume).getOwnerName();
+    } catch (IOException ex) {
+      LOG.error("Volume deletion failed for volume:{}", volume, ex);
+      omMetrics.incNumVolumeDeleteFails();
+      auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_VOLUME,
+          buildVolumeAuditMap(volume), ex, userInfo));
+      return new OMVolumeDeleteResponse(null, null, null,
+          createErrorOMResponse(omResponse, ex));
+    } finally {
+      omMetadataManager.getLock().releaseVolumeLock(volume);
+    }
+
+    // We cannot acquire user lock holding volume lock, so released volume
 
 Review comment:
   Bharat - let's discuss. What I am mean is that release/reacquire pattern is 
usually a bad idea. It may be okay here, however it would be better to 
eliminate it.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to