kerneltime commented on code in PR #7406: URL: https://github.com/apache/ozone/pull/7406#discussion_r1868704556
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/execution/OMGateway.java: ########## @@ -0,0 +1,226 @@ +/** + * 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.ratis.execution; + +import com.google.common.base.Preconditions; +import com.google.protobuf.ServiceException; +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.hadoop.hdds.utils.db.cache.CacheKey; +import org.apache.hadoop.hdds.utils.db.cache.CacheValue; +import org.apache.hadoop.ipc.ProcessingDetails; +import org.apache.hadoop.ipc.Server; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.OzoneManagerPrepareState; +import org.apache.hadoop.ozone.om.exceptions.OMException; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.QuotaResource; +import org.apache.hadoop.ozone.om.lock.OmLockOpr; +import org.apache.hadoop.ozone.om.ratis.execution.factory.OmRequestFactory; +import org.apache.hadoop.ozone.om.ratis.execution.request.OMRequestExecutor; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse; +import org.apache.hadoop.ozone.protocolPB.OzoneManagerRequestHandler; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.hadoop.ipc.RpcConstants.DUMMY_CLIENT_ID; +import static org.apache.hadoop.ipc.RpcConstants.INVALID_CALL_ID; + +/** + * entry for request execution. + */ +public class OMGateway { + private static final Logger LOG = LoggerFactory.getLogger(OMGateway.class); + private final LeaderRequestExecutor leaderExecutor; + private final OzoneManager om; + private final OmLockOpr omLockOpr; + private final AtomicLong requestInProgress = new AtomicLong(0); + private final AtomicLong uniqueIndex = new AtomicLong(); + + public OMGateway(OzoneManager om) throws IOException { + this.om = om; + this.omLockOpr = new OmLockOpr(om.getThreadNamePrefix()); + this.leaderExecutor = new LeaderRequestExecutor(om, uniqueIndex); + if (om.isRatisEnabled()) { + om.getOmRatisServer().getOmStateMachine().getPostExecutor().registerIndexNotifier(this::indexNotifier); + } else { + long index = PostExecutor.initLeaderIndex(om); + uniqueIndex.set(index); + } + } + + public void start() { + Iterator<Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>>> itr + = om.getMetadataManager().getBucketTable().cacheIterator(); + while (itr.hasNext()) { + Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>> entry = itr.next(); + if (entry.getValue().getCacheValue() != null) { + QuotaResource.Factory.registerQuotaResource(entry.getValue().getCacheValue().getObjectID()); + } + } + omLockOpr.start(); + leaderExecutor.start(); + } + public void stop() { + leaderExecutor.setEnabled(false); + leaderExecutor.stop(); + omLockOpr.stop(); + } + + public OMResponse submit(OMRequest omRequest, byte[] clientId, long callId) throws ServiceException { + // TODO handle replay of request for external request + return submitInternal(omRequest, getClientId(clientId), getCallId(callId)); + } + + public OMResponse submit(OMRequest omRequest) throws ServiceException { + return submitInternal(omRequest, null, 0L); + } + + public OMResponse submitInternal(OMRequest omRequest, String clientId, long callId) throws ServiceException { + requestInProgress.incrementAndGet(); + RequestContext requestContext = new RequestContext(); + requestContext.setRequest(omRequest); + requestContext.setFuture(new CompletableFuture<>()); + CompletableFuture<OMResponse> f = requestContext.getFuture().whenComplete( + (r, th) -> handleAfterExecution(requestContext, th)); + OmLockOpr.OmLockInfo lockInfo = null; + try { + OMRequestExecutor requestExecutor = OmRequestFactory.createRequestExecutor(omRequest, om); + OMRequest request = requestExecutor.preProcess(om); + // re-update modified request from pre-process + requestContext.setRequest(request); + requestContext.setUuidClientId(clientId); + requestContext.setCallId(callId); + requestContext.setRequestExecutor(requestExecutor); + + OzoneManagerRequestHandler.requestParamValidation(omRequest); + + requestContext.getRequestExecutor().authorize(om); + lockInfo = requestContext.getRequestExecutor().lock(omLockOpr); + + validatePrepareState(requestContext.getRequest()); Review Comment: This can be before locking -- 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]
