amaliujia commented on a change in pull request #1725: URL: https://github.com/apache/ozone/pull/1725#discussion_r554169986
########## 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: Sure we can do that. I will need add some changes in main branch, and then sync that to HDDS-2823 and then reuse in SCM. I think we should do that separately as that will take time. I have created https://issues.apache.org/jira/browse/HDDS-4660 to track this effort. ########## File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMDBTransactionBuffer.java ########## @@ -0,0 +1,75 @@ +/* + * 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(0) + .build(); + } + + public BatchOperation getCurrentBatchOperation() { Review comment: Glen's idea might be much easier. That's a good option. I think I will separate it to: 1. add javadoc to `getCurrentBatchOperation()` to remind that do not use this batch to commit. 2. Apply a solution to fix this issue. Created https://issues.apache.org/jira/browse/HDDS-4661 to track it. ########## File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMDBTransactionBuffer.java ########## @@ -0,0 +1,75 @@ +/* + * 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(0) + .build(); + } + + public BatchOperation getCurrentBatchOperation() { Review comment: Glen's idea might be much easier. That's a good option. I think I will separate it to: 1. add javadoc to `getCurrentBatchOperation()` to remind that do not use this batch to commit. 2. Apply a solution to fix this issue. Created https://issues.apache.org/jira/browse/HDDS-4661 to track it. Because `getCurrentBatchOperation()` is not a user-facing API, so only Ozone developer could make such mistakes, and in short term we have code review process to catch those. But I agree we should apply a fix for the longer term. ---------------------------------------------------------------- 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]
