You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2022/02/12 17:18:05 UTC
[pulsar] branch branch-2.8 updated: Fixed detecting number of NICs in EC2 (#14252)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.8 by this push:
new 9bd7ce0 Fixed detecting number of NICs in EC2 (#14252)
9bd7ce0 is described below
commit 9bd7ce055346e33d3860d19f785786117068fccd
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Fri Feb 11 19:54:52 2022 -0800
Fixed detecting number of NICs in EC2 (#14252)
---
.../broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
index 5bc7bf9..fa18795 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
@@ -23,6 +23,7 @@ import com.google.common.base.Charsets;
import com.sun.management.OperatingSystemMXBean;
import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -231,8 +232,15 @@ public class LinuxBrokerHostUsageImpl implements BrokerHostUsage {
Files.readAllBytes(path.resolve("speed"));
return true;
} catch (Exception e) {
- // wireless nics don't report speed, ignore them.
- return false;
+ // In some cases, VMs in EC2 won't have the speed reported on the NIC and will give a read-error.
+ // Check the type to make sure it's ethernet (type "1")
+ try {
+ String type = new String(Files.readAllBytes(path.resolve("type")), StandardCharsets.UTF_8).trim();
+ return Integer.parseInt(type) == 1;
+ } catch (IOException ioe) {
+ // wireless nics don't report speed, ignore them.
+ return false;
+ }
}
}
return false;