GlenGeng commented on a change in pull request #1725:
URL: https://github.com/apache/ozone/pull/1725#discussion_r547708056



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
##########
@@ -89,4 +98,12 @@ private Message process(final SCMRatisRequest request)
     }
   }
 
+  @Override
+  public long takeSnapshot() throws IOException {
+    LOG.info("Current Snapshot Index {}", getLastAppliedTermIndex());
+    TermIndex lastTermIndex = getLastAppliedTermIndex();

Review comment:
       You have to call `BaseStateMachine#updateLastAppliedTermIndex()` to make 
`BaseStateMachine#getLastAppliedTermIndex ()` to take effect.

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMDBTransactionBuffer.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.metadata.SCMMetadataStore;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+
+import java.io.IOException;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+
+public class SCMDBTransactionBuffer {
+  private final SCMMetadataStore metadataStore;
+  private BatchOperation currentBatchOperation;
+  private SCMTransactionInfo latestTrxInfo;
+
+  public SCMDBTransactionBuffer(SCMMetadataStore store) {
+    this.metadataStore = store;
+
+    // initialize a batch operation during construction time
+    currentBatchOperation = this.metadataStore.getStore().initBatchOperation();
+    latestTrxInfo =
+        SCMTransactionInfo
+            .builder()
+            .setTransactionIndex(-1)
+            .setCurrentTerm(-1)
+            .build();
+  }
+
+  public BatchOperation getCurrentBatchOperation() {
+    return currentBatchOperation;
+  }
+
+  public void updateLatestTrxInfo(SCMTransactionInfo info) {
+    this.latestTrxInfo = info;
+  }
+
+  public SCMTransactionInfo getLatestTrxInfo() {
+    return this.latestTrxInfo;
+  }
+
+  public void flush() throws IOException {
+    // write latest trx info into trx table in the same batch
+    Table<String, SCMTransactionInfo> transactionInfoTable
+        = metadataStore.getTransactionInfoTable();
+    transactionInfoTable.putWithBatch(currentBatchOperation,
+        TRANSACTION_INFO_KEY, latestTrxInfo);
+
+    metadataStore.getStore().commitBatchOperation(currentBatchOperation);
+    currentBatchOperation.close();

Review comment:
       Good Job!

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SCMTransactionInfoCodec.java
##########
@@ -0,0 +1,48 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.metadata;
+
+import org.apache.hadoop.hdds.scm.ha.SCMTransactionInfo;
+import org.apache.hadoop.hdds.utils.db.Codec;
+
+import java.io.IOException;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class SCMTransactionInfoCodec implements Codec<SCMTransactionInfo> {
+
+  @Override
+  public byte[] toPersistedFormat(SCMTransactionInfo object)
+      throws IOException {
+    checkNotNull(object, "Null object can't be converted to byte array.");

Review comment:
       Ditto,  could we reuse `OMTransactionInfoCodec` ?

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMDBTransactionBuffer.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.metadata.SCMMetadataStore;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+
+import java.io.IOException;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+
+public class SCMDBTransactionBuffer {
+  private final SCMMetadataStore metadataStore;
+  private BatchOperation currentBatchOperation;
+  private SCMTransactionInfo latestTrxInfo;
+
+  public SCMDBTransactionBuffer(SCMMetadataStore store) {
+    this.metadataStore = store;
+
+    // initialize a batch operation during construction time
+    currentBatchOperation = this.metadataStore.getStore().initBatchOperation();
+    latestTrxInfo =
+        SCMTransactionInfo
+            .builder()
+            .setTransactionIndex(-1)
+            .setCurrentTerm(-1)

Review comment:
       `.setCurrentTerm(0)`. The first leader will be elected from term 1.

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
##########
@@ -89,4 +98,12 @@ private Message process(final SCMRatisRequest request)
     }
   }
 
+  @Override
+  public long takeSnapshot() throws IOException {
+    LOG.info("Current Snapshot Index {}", getLastAppliedTermIndex());

Review comment:
       Better calculate the time cost during `takeSnapshot()`.

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMTransactionInfo.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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>
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * <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 com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.StringUtils;
+
+import java.util.Objects;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_SPLIT_KEY;
+
+final public class SCMTransactionInfo {

Review comment:
       - Will it be better to put `SCMTransactionInfo` near 
`OMTransactionInfo`, under `interface-storage` ?
   
   - Can we reuse the `OMTransactionInfo`? For example, rename 
`OMTransactionInfo` to `TransactionInfo`, and use them in both OM and SCM ?

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java
##########
@@ -275,12 +278,24 @@ public void addContainer(final ContainerInfoProto 
containerInfo)
 
     if (!containers.contains(containerID)) {
       ExecutionUtil.create(() -> {
-        containerStore.put(containerID, container);
+        if (transactionBuffer != null) {
+          containerStore.putWithBatch(
+              transactionBuffer.getCurrentBatchOperation(),
+              containerID, container);
+        } else {
+          containerStore.put(containerID, container);

Review comment:
       Can we remove the 'else {}' branch ? When we will migrate to batch 
operations, there will be no other way to do db writes.

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineManagerV2Impl.java
##########
@@ -114,11 +115,21 @@ public static PipelineManagerV2Impl newPipelineManager(
       ConfigurationSource conf, SCMHAManager scmhaManager,
       NodeManager nodeManager, Table<PipelineID, Pipeline> pipelineStore,
       EventPublisher eventPublisher) throws IOException {
+    return newPipelineManager(conf, scmhaManager, nodeManager, pipelineStore,

Review comment:
       Ditto, may we remove this Ctor ?

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerManagerImpl.java
##########
@@ -101,6 +102,16 @@ public ContainerManagerImpl(
       final PipelineManager pipelineManager,
       final Table<ContainerID, ContainerInfo> containerStore)
       throws IOException {
+    this(conf, scmHaManager, pipelineManager, containerStore, null);

Review comment:
       Could we avoid using this Ctor ? We may need to change the related test 
cases.




----------------------------------------------------------------
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]

Reply via email to