Skip to content

Commit 29f9fe9

Browse files
committed
keepAliveInterval configurable
1 parent eb5f20b commit 29f9fe9

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ public class CommonParameter {
309309
@Setter
310310
protected int backupPort;
311311

312+
@Getter
313+
@Setter
314+
protected int keepAliveInterval;
315+
312316
@Getter
313317
@Setter
314318
protected List<String> backupMembers;

common/src/main/java/org/tron/core/Constant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public class Constant {
217217

218218
public static final String NODE_BACKUP_PRIORITY = "node.backup.priority";
219219
public static final String NODE_BACKUP_PORT = "node.backup.port";
220+
public static final String NODE_BACKUP_KEEPALIVEINTERVAL = "node.backup.keepAliveInterval";
220221
public static final String NODE_BACKUP_MEMBERS = "node.backup.members";
221222

222223
public static final String STORAGE_BACKUP_ENABLE = "storage.backup.enable";

framework/src/main/java/org/tron/common/backup/BackupManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class BackupManager implements EventHandler {
3131

3232
private int port = args.getBackupPort();
3333

34+
private int keepAliveInterval = args.getKeepAliveInterval();
35+
3436
private String localIp = "";
3537

3638
private Set<String> members = new ConcurrentSet<>();
@@ -43,7 +45,7 @@ public class BackupManager implements EventHandler {
4345

4446
private volatile long lastKeepAliveTime;
4547

46-
private volatile long keepAliveTimeout = 10_000;
48+
private volatile long keepAliveTimeout = keepAliveInterval * 6;
4749

4850
private volatile boolean isInit = false;
4951

@@ -105,7 +107,7 @@ public void init() {
105107
} catch (Throwable t) {
106108
logger.error("Exception in send keep alive message:{}", t.getMessage());
107109
}
108-
}, 1, 1, TimeUnit.SECONDS);
110+
}, 1000, keepAliveInterval, TimeUnit.MILLISECONDS);
109111
}
110112

111113
@Override

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,8 @@ private static void initBackupProperty(Config config) {
968968
? config.getInt(Constant.NODE_BACKUP_PRIORITY) : 0;
969969
INSTANCE.backupPort = config.hasPath(Constant.NODE_BACKUP_PORT)
970970
? config.getInt(Constant.NODE_BACKUP_PORT) : 10001;
971+
INSTANCE.keepAliveInterval = config.hasPath(Constant.NODE_BACKUP_KEEPALIVEINTERVAL)
972+
? config.getInt(Constant.NODE_BACKUP_KEEPALIVEINTERVAL) : 3000;
971973
INSTANCE.backupMembers = config.hasPath(Constant.NODE_BACKUP_MEMBERS)
972974
? config.getStringList(Constant.NODE_BACKUP_MEMBERS) : new ArrayList<>();
973975
}
@@ -989,9 +991,10 @@ private static void logConfig() {
989991
logger.info("Max connection with same IP: {}", args.getNodeMaxActiveNodesWithSameIp());
990992
logger.info("Solidity threads: {}", args.getSolidityThreads());
991993
logger.info("************************ Backup config ************************");
994+
logger.info("Backup priority: {}", args.getBackupPriority());
992995
logger.info("Backup listen port: {}", args.getBackupPort());
996+
logger.info("Backup listen keepAliveInterval: {}", args.getKeepAliveInterval());
993997
logger.info("Backup member size: {}", args.getBackupMembers().size());
994-
logger.info("Backup priority: {}", args.getBackupPriority());
995998
logger.info("************************ Code version *************************");
996999
logger.info("Code version : {}", Version.getVersion());
9971000
logger.info("Version name: {}", Version.versionName);

framework/src/main/resources/config.conf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ node.discovery = {
8282
}
8383

8484
node.backup {
85-
port = 10001
86-
8785
# my priority, each member should use different priority
8886
priority = 8
8987

88+
# udp listen port, each member should have the save configuration
89+
port = 10001
90+
91+
# time interval to send keepAlive message, each member should have the save configuration
92+
keepAliveInterval = 3000
93+
9094
# peer's ip list, can't contain mine
9195
members = [
9296
# "ip",

0 commit comments

Comments
 (0)