Caideyipi commented on code in PR #18331:
URL: https://github.com/apache/iotdb/pull/18331#discussion_r3679628939


##########
iotdb-client/client-go:
##########


Review Comment:
   Removed the unintended client-go submodule pointer change in 1defa441f18. 
Thanks for catching it.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/consensus/index/ProgressIndex.java:
##########
@@ -158,6 +159,45 @@ public abstract ProgressIndex 
updateToMinimumEqualOrIsAfterProgressIndex(
    */
   public abstract ProgressIndexType getType();
 
+  /**
+   * Extracts a progress index of the given type from this progress index.
+   *
+   * <p>{@link StateProgressIndex} and {@link HybridProgressIndex} are 
recursively unwrapped because
+   * they may contain progress indexes from other causal chains.
+   */
+  public final <T extends ProgressIndex> Optional<T> getProgressIndexByType(
+      final Class<T> progressIndexClass) {
+    if (progressIndexClass.isInstance(this)) {
+      return Optional.of(progressIndexClass.cast(this));
+    }
+
+    if (this instanceof StateProgressIndex) {
+      return ((StateProgressIndex) this)
+          .getInnerProgressIndex()
+          .getProgressIndexByType(progressIndexClass);
+    }
+
+    if (this instanceof HybridProgressIndex) {
+      final Map<Short, ProgressIndex> type2Index = ((HybridProgressIndex) 
this).getType2Index();
+
+      // Prefer a direct component over one nested in another composite 
progress index.
+      for (final ProgressIndex progressIndex : type2Index.values()) {
+        if (progressIndexClass.isInstance(progressIndex)) {
+          return Optional.of(progressIndexClass.cast(progressIndex));
+        }
+      }
+      for (final ProgressIndex progressIndex : type2Index.values()) {
+        final Optional<T> extractedProgressIndex =
+            progressIndex.getProgressIndexByType(progressIndexClass);
+        if (extractedProgressIndex.isPresent()) {
+          return extractedProgressIndex;
+        }
+      }
+    }
+
+    return Optional.empty();
+  }

Review Comment:
   Done in 1defa441f18. getProgressIndexByType is now abstract on ProgressIndex 
and implemented by each subclass; StateProgressIndex and HybridProgressIndex 
retain the recursive unwrapping behavior.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to