fix(state-writer): skip atomic rename when content unchanged#94
Merged
Conversation
Wrappers under Restart=always with a sleep+exit-0 disabled branch (dump978-fa's no_hardware loop, airplanes-mlat's mlat_enabled_false loop) re-classify on every cycle and call airplanes_write_state with the same decision but a fresh decided_at timestamp. The atomic rename was firing every ~1200 cycles/day on a typical no-978-dongle feeder, waking any inotify consumer (e.g. systemd .path units watching the file). Compare the proposed content against the current target ignoring decided_at= lines and skip the rename when they match. Existing on-disk decided_at stays, so consumers see the time of the last material decision rather than the time of the last wrapper restart. AIRPLANES_WRITE_STATE_FORCE=1 keeps the previous always-rename behavior for callers that need it.
A target left behind without a final newline (interrupted previous write, external tampering) would lose its last line in the bash while-read loop, so a proposed write that removed a tail field could falsely dedupe against the truncated remainder. The `|| [[ -n line ]]` tail picks up the unterminated last line. Regression coverage includes the no-trailing-newline case and a backslashes-plus-trailing-spaces round-trip.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Daemons that run under
Restart=alwayswith a sleep-then-exit-0 disabled branch (dump978-fa'sno_hardwarecycle,airplanes-mlat'smlat_enabled_falsecycle) re-classify on every restart and callairplanes_write_statewith the same decision but a freshdecided_attimestamp. The atomic rename was firing about 1200 times a day on a typical no-978-dongle feeder — invisible on its own, but enough to wake any inotify consumer watching the file (e.g. a systemd.pathunit).The writer now compares the proposed content against the current file with
decided_at=lines stripped from both sides and skips the rename when they match. On-diskdecided_atstays at the time of the last material decision rather than being touched on every wrapper restart, which is the more meaningful value for status consumers.AIRPLANES_WRITE_STATE_FORCE=1opts out and restores the always-rename behaviour for any caller that needs it.No API change. Every current call-site keeps the same arguments; the dedupe is invisible to them. Mode 0644 is still enforced on rename and the validation-failure paths still short-circuit before the dedupe check.