Skip to content

Commit d1e02b4

Browse files
authored
fixes #389: Slow Leader Election (#390)
* fixes #389: Slow Leader Election * added comment * Update StreamsTransactionEventHandler.kt
1 parent ab35153 commit d1e02b4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

producer/src/main/kotlin/streams/StreamsTransactionEventHandler.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ class StreamsTransactionEventHandler(private val router: StreamsEventRouter,
2323

2424
private val nodeAll = configuration.nodeRouting.any { it.labels.isEmpty() }
2525
private val relAll = configuration.relRouting.any { it.name.isNullOrBlank() }
26-
27-
private val hostName = InetAddress.getLocalHost().hostName
26+
27+
// As getting host name in some network configuration can be expensive
28+
// this can lead to slowness in the start-up process (i.e. slowing the leader
29+
// election in case of a Causal Cluster). We define it a `lazy` value
30+
// computing it at the first invocation
31+
private val hostName by lazy { InetAddress.getLocalHost().hostName }
2832

2933
/**
3034
* Wrap the payload into a StreamsTransactionEvent for the eventId
@@ -334,4 +338,4 @@ class StreamsTransactionEventHandler(private val router: StreamsEventRouter,
334338

335339
return builder.build()
336340
}
337-
}
341+
}

0 commit comments

Comments
 (0)