Skip to content
Permalink
Browse files

Allow Mesh Node to rejoin cluster if its lease expires.

  • Loading branch information
Brett Morien
Brett Morien committed Dec 17, 2019
1 parent e947fe6 commit 2f6f95f41506a47fb13ab19b8895c0cd70c852ed
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/orbit-server/src/main/kotlin/orbit/server/mesh/LocalNodeInfo.kt
@@ -6,7 +6,9 @@

package orbit.server.mesh

import mu.KotlinLogging
import orbit.server.service.HealthCheck
import orbit.shared.exception.InvalidNodeId
import orbit.shared.mesh.NodeCapabilities
import orbit.shared.mesh.NodeInfo
import orbit.shared.mesh.NodeStatus
@@ -23,6 +25,8 @@ class LocalNodeInfo(
return this.info.nodeStatus == NodeStatus.ACTIVE
}

private val logger = KotlinLogging.logger {}

val info: NodeInfo
get() = infoRef.get().also {
checkNotNull(it) { "LocalNodeInfo not initialized. " }
@@ -40,16 +44,26 @@ class LocalNodeInfo(
}

suspend fun start() {
join()
}

suspend fun join() {
clusterManager.joinCluster(MANAGEMENT_NAMESPACE, NodeCapabilities(), this.serverInfo.url, NodeStatus.STARTING)
.also {
logger.info("Joined cluster as (${it.id})")
infoRef.set(it)
}
}

suspend fun tick() {
if (Timestamp.now() > info.lease.renewAt) {
clusterManager.renewLease(info.id, info.lease.challengeToken, info.capabilities).also {
infoRef.set(it)
try {
clusterManager.renewLease(info.id, info.lease.challengeToken, info.capabilities).also {
infoRef.set(it)
}
} catch (e: InvalidNodeId) {
logger.info("Failed to renew lease, rejoining cluster.")
join()
}
}
}

0 comments on commit 2f6f95f

Please sign in to comment.
You can’t perform that action at this time.