You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "szetszwo (via GitHub)" <gi...@apache.org> on 2023/09/18 19:06:19 UTC

[GitHub] [ozone] szetszwo commented on a diff in pull request #5272: HDDS-2146. Optimize block write path performance by reducing no of watchForCommit calls.

szetszwo commented on code in PR #5272:
URL: https://github.com/apache/ozone/pull/5272#discussion_r1329165571


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/AbstractCommitWatcher.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.storage;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.scm.XceiverClientReply;
+import org.apache.hadoop.hdds.scm.XceiverClientSpi;
+import org.apache.ratis.util.JavaUtils;
+import org.apache.ratis.util.MemoizedSupplier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.SortedMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * This class executes watchForCommit on ratis pipeline and releases
+ * buffers once data successfully gets replicated.
+ */
+abstract class AbstractCommitWatcher<BUFFER> {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      AbstractCommitWatcher.class);
+
+  /**
+   * Commit index -> buffers: when a commit index is acknowledged,
+   * the corresponding buffers can be released.
+   */
+  private final SortedMap<Long, List<BUFFER>> commitIndexMap
+      = new ConcurrentSkipListMap<>();
+  /**
+   * Commit index -> reply future:
+   * cache to reply futures to avoid sending duplicated watch requests.
+   */
+  private final ConcurrentMap<Long, CompletableFuture<XceiverClientReply>>
+      replies = new ConcurrentHashMap<>();
+
+  private final XceiverClientSpi client;
+
+  AbstractCommitWatcher(XceiverClientSpi client) {
+    this.client = client;
+  }
+
+  @VisibleForTesting
+  public SortedMap<Long, List<BUFFER>> getCommitIndexMap() {
+    return commitIndexMap;
+  }
+
+  public void updateCommitInfoMap(long index, List<BUFFER> buffers) {
+    commitIndexMap.computeIfAbsent(index, k -> new LinkedList<>())
+        .addAll(buffers);
+  }
+
+  /** @return the total data which has been acknowledged. */
+  abstract long getTotalAckDataLength();

Review Comment:
   That's a good idea.  Let me try it.



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