You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/06/21 06:11:59 UTC

[GitHub] [ozone] bharatviswa504 commented on a change in pull request #1494: HDDS-4330. Bootstrap new OM node

bharatviswa504 commented on a change in pull request #1494:
URL: https://github.com/apache/ozone/pull/1494#discussion_r655093142



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
##########
@@ -104,9 +104,127 @@
   private final RaftGroupId raftGroupId;
   private final RaftGroup raftGroup;
   private final RaftPeerId raftPeerId;
+  private final List<RaftPeer> raftPeers;
 
   private final OzoneManager ozoneManager;
   private final OzoneManagerStateMachine omStateMachine;
+  private final String ratisStorageDir;
+
+  private final ClientId clientId = ClientId.randomId();
+  private static final AtomicLong CALL_ID_COUNTER = new AtomicLong();
+
+  private static long nextCallId() {
+    return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
+  }
+
+  /**
+   * Returns an OM Ratis server.
+   * @param conf configuration
+   * @param om the OM instance starting the ratis server
+   * @param raftGroupIdStr raft group id string
+   * @param localRaftPeerId raft peer id of this Ratis server
+   * @param addr address of the ratis server
+   * @param peers peer nodes in the raft ring
+   * @throws IOException
+   */
+  @SuppressWarnings({"parameternumber", "java:S107"})
+  private OzoneManagerRatisServer(ConfigurationSource conf, OzoneManager om,
+      String raftGroupIdStr, RaftPeerId localRaftPeerId,
+      InetSocketAddress addr, List<RaftPeer> peers,
+      SecurityConfig secConfig, CertificateClient certClient)
+      throws IOException {
+    this.ozoneManager = om;
+    this.omRatisAddress = addr;
+    this.port = addr.getPort();
+    this.ratisStorageDir = OzoneManagerRatisUtils.getOMRatisDirectory(conf);
+    RaftProperties serverProperties = newRaftProperties(conf);
+
+    this.raftPeerId = localRaftPeerId;
+    this.raftGroupId = RaftGroupId.valueOf(
+        getRaftGroupIdFromOmServiceId(raftGroupIdStr));
+    this.raftPeers = Lists.newArrayList();
+    this.raftPeers.addAll(peers);
+    this.raftGroup = RaftGroup.valueOf(raftGroupId, peers);
+
+    StringBuilder raftPeersStr = new StringBuilder();
+    for (RaftPeer peer : peers) {
+      raftPeersStr.append(", ").append(peer.getAddress());
+    }
+    LOG.info("Instantiating OM Ratis server with groupID: {} and " +
+        "peers: {}", raftGroupIdStr, raftPeersStr.toString().substring(2));
+
+    this.omStateMachine = getStateMachine(conf);
+
+    Parameters parameters = createServerTlsParameters(secConfig, certClient);
+    this.server = RaftServer.newBuilder()
+        .setServerId(this.raftPeerId)
+        .setGroup(this.raftGroup)
+        .setProperties(serverProperties)
+        .setParameters(parameters)
+        .setStateMachine(omStateMachine)
+        .build();
+  }
+
+  /**
+   * Creates an instance of OzoneManagerRatisServer.
+   */
+  public static OzoneManagerRatisServer newOMRatisServer(
+      ConfigurationSource ozoneConf, OzoneManager omProtocol,
+      OMNodeDetails omNodeDetails, List<OMNodeDetails> peerNodes,
+      SecurityConfig secConfig, CertificateClient certClient,
+      boolean isBootstrapping) throws IOException {
+
+    // RaftGroupId is the omServiceId
+    String omServiceId = omNodeDetails.getServiceId();
+
+    String omNodeId = omNodeDetails.getNodeId();
+    RaftPeerId localRaftPeerId = RaftPeerId.getRaftPeerId(omNodeId);
+
+    InetSocketAddress ratisAddr = new InetSocketAddress(
+        omNodeDetails.getInetAddress(), omNodeDetails.getRatisPort());
+
+    RaftPeer localRaftPeer = RaftPeer.newBuilder()
+        .setId(localRaftPeerId)
+        .setAddress(ratisAddr)
+        .build();
+
+    List<RaftPeer> raftPeers = new ArrayList<>();
+
+    // If the OM is started in bootstrap mode, do not add it to the ratis ring.
+    // It will be added later using SetConfiguration from the leader OM.
+    if (isBootstrapping) {
+      LOG.debug("OM started in Bootstrap mode and hence will not be added " +
+          "to Ratis group during startup.");
+    } else {
+      // On regular startup, add current OM to Ratis ring
+      raftPeers.add(localRaftPeer);
+    }
+
+    for (OMNodeDetails peerInfo : peerNodes) {
+      String peerNodeId = peerInfo.getNodeId();
+      RaftPeerId raftPeerId = RaftPeerId.valueOf(peerNodeId);

Review comment:
       Just got a question:
   Why only new node being added is not added here, but other nodes in-ring are added here? (Is it okay to add other nodes here it self, or they also can be discovered during setConf?)
   
   I remember there was a reason behind this, can you provide info or if you are having another update to PR add some comments it will be easy to understand the reason behind it? 

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
##########
@@ -340,4 +359,70 @@ public static boolean isBucketFSOptimized() {
     return isBucketFSOptimized;
   }
 
+  /**
+   * Get the local directory where ratis logs will be stored.
+   */
+  public static String getOMRatisDirectory(ConfigurationSource conf) {
+    String storageDir = conf.get(OMConfigKeys.OZONE_OM_RATIS_STORAGE_DIR);
+
+    if (Strings.isNullOrEmpty(storageDir)) {
+      storageDir = ServerUtils.getDefaultRatisDirectory(conf);
+    }
+    return storageDir;
+  }
+
+  public static String getOMRatisSnapshotDirectory(ConfigurationSource conf) {

Review comment:
       Add javadocs to public methods




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org