rakeshadr commented on a change in pull request #1679: URL: https://github.com/apache/ozone/pull/1679#discussion_r543561867
########## File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMAllocateBlockRequestV1.java ########## @@ -0,0 +1,91 @@ +/** + * 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.key; + +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; +import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils; +import org.apache.hadoop.ozone.om.request.file.OMFileRequest; +import org.apache.hadoop.ozone.om.response.OMClientResponse; +import org.apache.hadoop.ozone.om.response.key.OMAllocateBlockResponseV1; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse; +import org.jetbrains.annotations.NotNull; +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; + +/** + * Handles allocate block request layout version V1. + */ +public class OMAllocateBlockRequestV1 extends OMAllocateBlockRequest { + + private static final Logger LOG = + LoggerFactory.getLogger(OMAllocateBlockRequestV1.class); + + public OMAllocateBlockRequestV1(OMRequest omRequest) { + super(omRequest); + } + + protected OmKeyInfo getOpenKeyInfo(OMMetadataManager omMetadataManager, + String openKeyName, String keyName) throws IOException { + String fileName = OzoneFSUtils.getFileName(keyName); + return OMFileRequest.getOmKeyInfoFromFileTable(true, + omMetadataManager, openKeyName, fileName); + } + + protected String getOpenKeyName(String volumeName, String bucketName, + String keyName, long clientID, OzoneManager ozoneManager) + throws IOException { + OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); + String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName); + OmBucketInfo omBucketInfo = + omMetadataManager.getBucketTable().get(bucketKey); + long bucketId = omBucketInfo.getObjectID(); + String fileName = OzoneFSUtils.getFileName(keyName); + Iterator<Path> pathComponents = Paths.get(keyName).iterator(); Review comment: As per the offline discussion with @mukul1987 and @arp7, it is not required to do the get parentID check under BUCKET_LOCK. With this current code flow, it won't make fast fail during race condition case, anyway later it will fail at the key commit operation time and there won't be any correctness issues. Basically it would be good to avoid any extra performance overhead and in future this part can be revisited if someone has any potential issue and required fast fail in allocate block request. Following is the expected behavior during race condition. Here op-2 arrived first in OM server and simultaneously op-3 also arrived in OM server. ``` op-1: client-1) Creates openFile - /a/b/c/d/file1 and written block1 op-2: client-2) Invoked delete /a/b/c. This acquired BUCKET_LOCK and performing deletion. op-3: client-1) Invoked AllocateBlock - block2 for /a/b/c/d/file1. Since getParent("/a/b/c/d/file1") is not under BUCKET_LOCK, it saw "/a/b/c/d" parent ID and proceeds to successfully allocate block2. op-4: client-1) CommitKey /a/b/c/d/file1 - Fail as parent doesn't exist. ``` @bharatviswa504, does this sound good to you? ---------------------------------------------------------------- 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: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
