valkey-io / valkey

A flexible distributed key-value datastore that supports both caching and beyond caching workloads.
https://valkey.io
Other
16.87k stars 627 forks source link

Log as primary role (M) instead of child process (C) during startup #1206

Open zuiderkwast opened 1 hour ago

zuiderkwast commented 1 hour ago

The first few log message are logged with the role letter "C", meaning child process. After a few lines, this changes to "M" = primary. Example:

24881:C 21 Oct 2024 21:10:57.165 * oO0OoO0OoO0Oo Valkey is starting oO0OoO0OoO0Oo
24881:C 21 Oct 2024 21:10:57.165 * Valkey version=255.255.255, bits=64, commit=814e0f55, modified=1, pid=24881, just started
24881:C 21 Oct 2024 21:10:57.165 * Configuration loaded
24881:M 21 Oct 2024 21:10:57.167 * Increased maximum number of open files to 10032 (it was originally set to 1024).

Expected behaviour: The server starts up as primary and logs the first lines with "M".

The reason we see "C" now is because server.pid has not yet been initialized when these lines are logged. The logging function checks if server.pid == getpid().

Currently, server.pid = getpid() is done in initServer() but it would be better to do it before the first logging happens, in main() before we load config files. This is a simple fix.

Discussion from https://github.com/valkey-io/valkey/issues/1022.

zuiderkwast commented 1 hour ago

@azuredream I can't assign you for some reason, but consider yourself assigned.