Skip to content

Commit

Permalink
Longer lease TTL and run lease_keepalive earlier (#847)
Browse files Browse the repository at this point in the history
Increases default lease TTL 5s -> 10s. Also timeouts earlier so lease_keepalive has a longer window to run (3s instead of 0.5s), which should make it less likely that unnecessary leader elections happen.
  • Loading branch information
viktorerlingsson authored Nov 20, 2024
1 parent 6f80929 commit 700d52b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Don't raise FileNotFound when deleting already deleted file [#849](https://github.com/cloudamqp/lavinmq/pull/849)
- Increase default etcd lease TTL to 10s and run keepalive earlier [#847](https://github.com/cloudamqp/lavinmq/pull/847)


## [2.0.1] - 2024-11-13
Expand Down
6 changes: 3 additions & 3 deletions src/lavinmq/etcd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module LavinMQ
end

# Returns {ID, TTL}
def lease_grant(ttl = 5) : Tuple(Int64, Int32)
def lease_grant(ttl = 10) : Tuple(Int64, Int32)
json = post("/v3/lease/grant", body: %({"TTL":"#{ttl}"}))
ttl = json.dig("TTL").as_s.to_i
id = json.dig("ID").as_s.to_i64
Expand Down Expand Up @@ -80,7 +80,7 @@ module LavinMQ
# Campaign for an election
# Returns a Channel when elected leader,
# when the channel is closed the leadership is lost
def elect(name, value, ttl = 5) : Channel(Nil)
def elect(name, value, ttl = 10) : Channel(Nil)
channel = Channel(Nil).new
lease_id, ttl = lease_grant(ttl)
wg = WaitGroup.new(1)
Expand All @@ -92,7 +92,7 @@ module LavinMQ
lease_revoke(lease_id)
channel.close
break
when timeout((ttl * 0.9).seconds)
when timeout((ttl * 0.7).seconds)
ttl = lease_keepalive(lease_id)
end
rescue ex
Expand Down

0 comments on commit 700d52b

Please sign in to comment.