GlenGeng commented on a change in pull request #1784: URL: https://github.com/apache/ozone/pull/1784#discussion_r559963934
########## File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMContext.java ########## @@ -0,0 +1,208 @@ +/* + * 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.hdds.scm.ha; + +import org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager.SafeModeStatus; +import org.apache.hadoop.hdds.scm.server.StorageContainerManager; +import org.apache.hadoop.hdds.server.events.EventHandler; +import org.apache.hadoop.hdds.server.events.EventPublisher; +import org.apache.ratis.protocol.exceptions.NotLeaderException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * SCMContext is the single source of truth for some key information shared + * across all components within SCM, including: + * - RaftServer related info, e.g., isLeader, term. + * - SafeMode related info, e.g., inSafeMode, preCheckComplete. + */ +public final class SCMContext implements EventHandler<SafeModeStatus> { + private static final Logger LOG = LoggerFactory.getLogger(SCMContext.class); Review comment: Hey @bshashikant, this is a good point. Due to PR https://github.com/apache/ozone/pull/1744, integration test which is bases on MiniOzoneCluster has been running upon single-server raft cluster. But we still have cases that run without Ratis, e.g., UnitTest, Recon. Here is the design decision of SCMContext: The initial value of `currentTerm` in raft is 0. After RaftServer starts, they are all followers of term 0, then election timeout happens, one becomes candidate of term 1, finally the first leader will be elected, which is on a term that is greater or equal to 1. SCMContext has two raft related field, `term` and `isLeader`. - For the cases using Ratis (no matter single server or multi server), the initial value of `term` and `isLeader` for SCMContext is `0` and `false`, they will be updated by `SCMStateMachine#notifyNotLeader` and `SCMStateMachine#notifyLeaderChanged`. - For the cases not using Ratis, the initial value of `term` and `isLeader` for SCMContext is `0` and `true`, means leader of term 0. Since all the `isLeader` and `getTermOfLeader` check are going through `SCMConext`, and they are spreading across the whole SCM, for Ratis mode, it returns real raft info, for non Ratis mode, it behaviors as leader on term 0, so that we treat them in the same way. What do you think ? We can discuss offline if needed. ---------------------------------------------------------------- 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]
