OneSizeFitsQuorum commented on code in PR #14866:
URL: https://github.com/apache/iotdb/pull/14866#discussion_r1969341039


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/node/AINodeHeartbeatCache.java:
##########
@@ -54,7 +56,8 @@ public void updateCurrentStatistics(boolean forceUpdate) {
     long currentNanoTime = System.nanoTime();
     if (lastSample != null && 
NodeStatus.Removing.equals(lastSample.getStatus())) {
       status = NodeStatus.Removing;
-    } else if (currentNanoTime - lastSendTime > HEARTBEAT_TIMEOUT_TIME_IN_NS) {
+    } else if (!failureDetector.isAvailable(heartbeatHistory)) {
+      /* Failure detector decides that this DataNode is UNKNOWN */

Review Comment:
   AINode



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java:
##########
@@ -180,6 +181,18 @@ public class ConfigNodeConfig {
   /** The heartbeat interval in milliseconds. */
   private long heartbeatIntervalInMs = 1000;
 
+  /** Failure detector implementation */
+  private String failureDetector = IFailureDetector.FIXED_DETECTOR;

Review Comment:
   Phi?



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/detector/FixedDetector.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.iotdb.confignode.manager.load.cache.detector;

Review Comment:
   add empty line



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/detector/PhiAccrualDetector.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iotdb.confignode.manager.load.cache.detector;
+
+import org.apache.iotdb.confignode.manager.load.cache.AbstractHeartbeatSample;
+import org.apache.iotdb.confignode.manager.load.cache.IFailureDetector;
+import org.apache.iotdb.confignode.manager.load.cache.node.NodeHeartbeatSample;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.tsfile.utils.Preconditions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PhiAccrualDetector implements IFailureDetector {
+
+  private final long threshold;
+  private final long acceptableHeartbeatPauseNs;
+  private final long firstHeartbeatEstimateNs;
+  private final long minHeartbeatStdNs;
+
+  public PhiAccrualDetector(
+      long threshold,
+      long acceptableHeartbeatPauseNs,
+      long firstHeartbeatEstimateNs,
+      long minHeartbeatStdNs) {
+    this.threshold = threshold;
+    this.acceptableHeartbeatPauseNs = acceptableHeartbeatPauseNs;
+    this.firstHeartbeatEstimateNs = firstHeartbeatEstimateNs;
+    this.minHeartbeatStdNs = minHeartbeatStdNs;
+  }
+
+  @Override
+  public boolean isAvailable(List<AbstractHeartbeatSample> history) {
+    if (history.isEmpty()) {
+      /* We haven't received the first heartbeat reply. We cannot decide the 
node availability. */
+      return true;
+    }
+    final PhiAccrual phiAccrual = create(history);
+    // TODO(szywilliam) we should log the status change and dump the heartbeat 
history

Review Comment:
   do not leave todo? just do it?



##########
iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template:
##########
@@ -684,6 +684,26 @@ time_partition_interval=604800000
 # Datatype: long
 heartbeat_interval_in_ms=1000
 
+# Default failure detector, enum from {fixed, phi_accrual}
+# effectiveMode: restart
+# Datatype: string
+failure_detector=fixed

Review Comment:
   The default detecter should be set to phi_accrual?



##########
iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/cache/detector/PhiAccrualDetectorTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.iotdb.confignode.manager.load.cache.detector;

Review Comment:
   add empty line



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/detector/PhiAccrualDetector.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.
+ */

Review Comment:
   add empty line



##########
iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template:
##########
@@ -684,6 +684,26 @@ time_partition_interval=604800000
 # Datatype: long
 heartbeat_interval_in_ms=1000
 
+# Default failure detector, enum from {fixed, phi_accrual}
+# effectiveMode: restart
+# Datatype: string
+failure_detector=fixed
+
+# Fixed failure detector threshold of time elapsed without receiving heartbeat 
replies
+# effectiveMode: restart
+# Datatype: long
+failure_detector_fixed_threshold_in_ms=20000
+
+# Phi accrual: threshold to determine a node is down
+# effectiveMode: restart
+# Datatype: long
+failure_detector_phi_threshold=30

Review Comment:
   is it too large?
   
   <img width="1121" alt="image" 
src="https://github.com/user-attachments/assets/99840f32-7a63-490b-a89a-8b0ef459d1b4";
 />
   



##########
iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/cache/detector/PhiAccrualDetectorTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.iotdb.confignode.manager.load.cache.detector;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PhiAccrualDetectorTest {

Review Comment:
   1. rename to DetecterTest
   2. to compare the difference between PhiAccrual and Fixed under same 
heartbeat interval list,to list some case dentifing each other's strengths and 
weaknesses, for example, Phi may detect the failure earlier, but there will be 
false positives
   3. Each test should be complemented with a description of what the 
HeartbeatInterval corresponds to in the real world (e.g., a node going down, or 
a 5s/10s gc, etc.).



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/detector/PhiAccrualDetector.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iotdb.confignode.manager.load.cache.detector;
+
+import org.apache.iotdb.confignode.manager.load.cache.AbstractHeartbeatSample;
+import org.apache.iotdb.confignode.manager.load.cache.IFailureDetector;
+import org.apache.iotdb.confignode.manager.load.cache.node.NodeHeartbeatSample;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.tsfile.utils.Preconditions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PhiAccrualDetector implements IFailureDetector {
+
+  private final long threshold;
+  private final long acceptableHeartbeatPauseNs;
+  private final long firstHeartbeatEstimateNs;
+  private final long minHeartbeatStdNs;
+
+  public PhiAccrualDetector(
+      long threshold,
+      long acceptableHeartbeatPauseNs,
+      long firstHeartbeatEstimateNs,
+      long minHeartbeatStdNs) {
+    this.threshold = threshold;
+    this.acceptableHeartbeatPauseNs = acceptableHeartbeatPauseNs;
+    this.firstHeartbeatEstimateNs = firstHeartbeatEstimateNs;
+    this.minHeartbeatStdNs = minHeartbeatStdNs;
+  }
+
+  @Override
+  public boolean isAvailable(List<AbstractHeartbeatSample> history) {
+    if (history.isEmpty()) {
+      /* We haven't received the first heartbeat reply. We cannot decide the 
node availability. */
+      return true;
+    }
+    final PhiAccrual phiAccrual = create(history);
+    // TODO(szywilliam) we should log the status change and dump the heartbeat 
history
+    return phiAccrual.phi() < (double) this.threshold;
+  }
+
+  PhiAccrual create(List<AbstractHeartbeatSample> history) {
+    final int size = history.size();
+
+    final List<Double> heartbeatIntervals = new ArrayList<>();
+    /*
+     * During cold start, the heartbeat history may contain not enough samples 
for wise decisions.
+     * Therefore, we manually add data samples for better estimation.
+     * 1. mean = heartbeat interval (1000ms)
+     * 2. std = mean / 4
+     */
+    if (size <= 2) {
+      double mean = firstHeartbeatEstimateNs;
+      double std = mean / 4.0;
+      heartbeatIntervals.add(mean + std);
+      heartbeatIntervals.add(mean - std);
+    }
+
+    for (int i = 1; i < size; i++) {
+      // ensure getSampleLogicalTimestamp() will return system nano timestamp
+      Preconditions.checkArgument(history.get(i) instanceof 
NodeHeartbeatSample);
+      double interval =

Review Comment:
   1.It seems that as long as the duration of a heartbeat is less than 1 
second, the interval should be about 1 second by default. Is this reasonable? 
Does a faster heartbeat predict earlier detection of problems?
   2. This history is a linkedlist and cannot support get(i) requests 
efficiently. I recommend just creating a circular array of size 100 for 
slidingWindow
   



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/detector/PhiAccrualDetector.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iotdb.confignode.manager.load.cache.detector;
+
+import org.apache.iotdb.confignode.manager.load.cache.AbstractHeartbeatSample;
+import org.apache.iotdb.confignode.manager.load.cache.IFailureDetector;
+import org.apache.iotdb.confignode.manager.load.cache.node.NodeHeartbeatSample;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.tsfile.utils.Preconditions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PhiAccrualDetector implements IFailureDetector {
+
+  private final long threshold;
+  private final long acceptableHeartbeatPauseNs;
+  private final long firstHeartbeatEstimateNs;
+  private final long minHeartbeatStdNs;
+
+  public PhiAccrualDetector(
+      long threshold,
+      long acceptableHeartbeatPauseNs,
+      long firstHeartbeatEstimateNs,
+      long minHeartbeatStdNs) {
+    this.threshold = threshold;
+    this.acceptableHeartbeatPauseNs = acceptableHeartbeatPauseNs;
+    this.firstHeartbeatEstimateNs = firstHeartbeatEstimateNs;
+    this.minHeartbeatStdNs = minHeartbeatStdNs;
+  }
+
+  @Override
+  public boolean isAvailable(List<AbstractHeartbeatSample> history) {
+    if (history.isEmpty()) {
+      /* We haven't received the first heartbeat reply. We cannot decide the 
node availability. */
+      return true;

Review Comment:
   then we should return false?



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/cache/AbstractLoadCache.java:
##########
@@ -40,9 +45,27 @@ public abstract class AbstractLoadCache {
   // The current statistics calculated by the latest heartbeat sample

Review Comment:
   remove `HEARTBEAT_TIMEOUT_TIME_IN_NS` default value? to make it controlled 
by `failure_detector_fixed_threshold_in_ms`?
   
   BTW, regionCache may need to be reconstruced too



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