Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard exit when loosing leadership #875

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lavinmq/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module LavinMQ
p.on("--raise-gc-warn", "Raise on GC warnings") { @raise_gc_warn = true }
p.on("--no-data-dir-lock", "Don't put a file lock in the data directory (default true)") { @data_dir_lock = false }
p.on("-d", "--debug", "Verbose logging") { @log_level = ::Log::Severity::Debug }
p.on("-h", "--help", "Show this help") { puts p; exit 1 }
p.on("-h", "--help", "Show this help") { puts p; exit 0 }
p.on("-v", "--version", "Show version") { puts LavinMQ::VERSION; exit 0 }
p.on("--build-info", "Show build information") { puts LavinMQ::BUILD_INFO; exit 0 }
p.on("--guest-only-loopback=BOOL", "Limit guest user to only connect from loopback address") do |v|
Expand Down
5 changes: 3 additions & 2 deletions src/lavinmq/data_dir_lock.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module LavinMQ
@lock.read_buffering = false
end

# See `man 2 flock`
def acquire
begin
@lock.flock_exclusive(blocking: false)
Expand All @@ -21,7 +22,7 @@ module LavinMQ
Log.info { "Lock acquired" }
end
@lock.truncate
@lock.print System.hostname
@lock.print "PID #{Process.pid} @ #{System.hostname}"
@lock.fsync
end

Expand All @@ -31,7 +32,7 @@ module LavinMQ
@lock.flock_unlock
end

# Read from the lock file to detect lost lock
# Read from the lock file to detect lost lock on networked filesystems (NFS/SMB)
# See "Lost locks" in `man 2 fcntl`
def poll
@lock.read_at(0, 1, &.read_byte) || raise IO::EOFError.new
Expand Down
5 changes: 2 additions & 3 deletions src/lavinmq/launcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ module LavinMQ
loop do
if leadership = @leadership
if leadership.wait(30.seconds)
Log.warn { "Lost leadership" }
stop
exit 1
Log.fatal { "Lost cluster leadership" }
exit 3 # 3rd character in the alphabet is C(lustering)
else
@data_dir_lock.try &.poll
GC.collect
Expand Down
2 changes: 1 addition & 1 deletion src/lavinmqperf.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Perf
@parser = OptionParser.new
@banner = "Usage: #{PROGRAM_NAME} [throughput | bind-churn | queue-churn | connection-churn | connection-count] [arguments]"
@parser.banner = @banner
@parser.on("-h", "--help", "Show this help") { puts @parser; exit 1 }
@parser.on("-h", "--help", "Show this help") { puts @parser; exit 0 }
@parser.on("-v", "--version", "Show version") { puts LavinMQ::VERSION; exit 0 }
@parser.on("--build-info", "Show build information") { puts LavinMQ::BUILD_INFO; exit 0 }
@parser.invalid_option { |arg| abort "Invalid argument: #{arg}" }
Expand Down
Loading