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 2022/05/02 07:31:37 UTC

[GitHub] [ozone] siddhantsangwan commented on a diff in pull request #3307: HDDS-6551. Introduce StatefulService in scm

siddhantsangwan commented on code in PR #3307:
URL: https://github.com/apache/ozone/pull/3307#discussion_r862642011


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/StatefulServiceStateManagerImpl.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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 com.google.protobuf.ByteString;
+import org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType;
+import org.apache.hadoop.hdds.scm.metadata.DBTransactionBuffer;
+import org.apache.hadoop.hdds.utils.db.Table;
+
+import java.io.IOException;
+import java.lang.reflect.Proxy;
+
+/**
+ * This class implements methods to save and read configurations of a
+ * stateful service from DB.
+ */
+public final class StatefulServiceStateManagerImpl
+    implements StatefulServiceStateManager {
+
+  // this table maps the service name to the configuration (ByteString)
+  private Table<String, ByteString> statefulServiceConfig;
+  private final DBTransactionBuffer transactionBuffer;
+
+  private StatefulServiceStateManagerImpl(
+      Table<String, ByteString> statefulServiceConfig,
+      DBTransactionBuffer scmDBTransactionBuffer) {
+    this.statefulServiceConfig = statefulServiceConfig;
+    this.transactionBuffer = scmDBTransactionBuffer;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public void saveConfiguration(String serviceName, ByteString bytes)
+      throws IOException {
+    // do we need a write lock here?
+    // do we need the buffer here or should we directly put the key-value?
+    /*
+    Alternative: statefulServiceConfig.put(serviceName, bytes);
+     */
+    transactionBuffer.addToBuffer(statefulServiceConfig, serviceName, bytes);
+    if (transactionBuffer instanceof SCMHADBTransactionBuffer) {
+      SCMHADBTransactionBuffer buffer =
+              (SCMHADBTransactionBuffer) transactionBuffer;
+      buffer.flush();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public ByteString readConfiguration(String serviceName) throws IOException {
+    // do we need a read lock here?
+    return statefulServiceConfig.get(serviceName);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public void reinitialize(Table<String, ByteString> configs) {
+    this.statefulServiceConfig = configs;
+  }
+
+  public static Builder newBuilder() {
+    return new Builder();
+  }
+
+  /**
+   * Builder for StatefulServiceStateManager.
+   */
+  public static class Builder {
+    private Table<String, ByteString> statefulServiceConfig;
+    private DBTransactionBuffer transactionBuffer;
+    private SCMRatisServer scmRatisServer;
+
+    public Builder setStatefulServiceConfig(
+        final Table<String, ByteString> statefulServiceConfig) {
+      this.statefulServiceConfig = statefulServiceConfig;
+      return this;
+    }
+
+    public Builder setSCMDBTransactionBuffer(
+        final DBTransactionBuffer dbTransactionBuffer) {
+      this.transactionBuffer = dbTransactionBuffer;
+      return this;
+    }
+
+    public Builder setRatisServer(final SCMRatisServer ratisServer) {
+      scmRatisServer = ratisServer;
+      return this;
+    }
+
+    public StatefulServiceStateManager build() {

Review Comment:
   Can we exclude the not null check for `scmRatisServer`? `SCMHAInvocationHandler` takes care of the null case by calling the `invokeLocal` method.



-- 
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: issues-unsubscribe@ozone.apache.org

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