hemantk-12 commented on code in PR #4175:
URL: https://github.com/apache/ozone/pull/4175#discussion_r1084679662
##########
hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto:
##########
@@ -1678,6 +1681,13 @@ message SnapshotDiffRequest {
required string toSnapshot = 4;
}
+message DeleteSnapshotRequest {
+ optional string volumeName = 1;
+ optional string bucketName = 2;
+ optional string snapshotName = 3;
+ optional uint64 deletionTime = 4;
Review Comment:
What's the usage of this? Is it for scheduled delete? Or just for audit
purpose?
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotDeleteRequest.java:
##########
@@ -0,0 +1,217 @@
+/**
+ * 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.snapshot;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OmUtils;
+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.OMMetrics;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.snapshot.OMSnapshotDeleteResponse;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteSnapshotRequest;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteSnapshotResponse;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UserInfo;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.util.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
+import static
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.SNAPSHOT_LOCK;
+
+/**
+ * Handles DeleteSnapshot Request.
+ */
+public class OMSnapshotDeleteRequest extends OMClientRequest {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(OMSnapshotDeleteRequest.class);
+
+ public OMSnapshotDeleteRequest(OMRequest omRequest) {
+ super(omRequest);
+ }
+
+ @Override
+// @DisallowedUntilLayoutVersion(OZONE_SNAPSHOT_SCHEMA)
+ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+
+ final OMRequest omRequest = super.preExecute(ozoneManager);
+
+ final DeleteSnapshotRequest deleteSnapshotRequest =
+ omRequest.getDeleteSnapshotRequest();
+
+ final String snapshotName = deleteSnapshotRequest.getSnapshotName();
+ // Verify snapshot name. TODO: Can remove
+ OmUtils.validateSnapshotName(snapshotName);
+
+ String volumeName = deleteSnapshotRequest.getVolumeName();
+ String bucketName = deleteSnapshotRequest.getBucketName();
+
+ // Permission check
+ UserGroupInformation ugi = createUGI();
+ String bucketOwner = ozoneManager.getBucketOwner(volumeName, bucketName,
+ IAccessAuthorizer.ACLType.READ, OzoneObj.ResourceType.BUCKET);
+ if (!ozoneManager.isAdmin(ugi) &&
+ !ozoneManager.isOwner(ugi, bucketOwner)) {
+ throw new OMException(
+ "Only bucket owners and Ozone admins can delete snapshots",
+ OMException.ResultCodes.PERMISSION_DENIED);
+ }
+
+ // Set deletion time here so OM leader and follower would have the
Review Comment:
Not sure if this would work. I had to add snapshotId before submitting
request to Raits.
https://github.com/apache/ozone/blob/1ee083178df192d48b16c04b663384f7c336c374/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java#L139
and
https://github.com/apache/ozone/blob/1ee083178df192d48b16c04b663384f7c336c374/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/RequestValidations.java#L124
Please double check 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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]