I was wondering about the behavior of the slaveof field on config rewrite. From reading the code:
If the server is a master (or redis cluster), the slaveof line will get blanked out
If the server is a slave, ensure the line reads "slaveof masterhost masterport"
My problem with the behavior, is that if I start the server as a slave, then promote it to master, then rewrite the config, I'll get my identical config file with the slaveof line blanked out. Then if I demote it to a slave again and rewrite, the config file will get a line appended to the end of the file to avoid modifying the file structure. From here, if we consider a live system where the role of a server might change dynamically and several times a day, we have a disk-space leak in the form of the config file! (the config constantly growing by a line each slave'ing, and blanking it each master'ing).
I realize this is a small problem in the grand scheme of things, but I'm working on a managed redis infrastructure, and the consistency of this feature is important to me.
I propose that:
- If the server is redis cluster; use original behavior (this problem shouldn't be relevant)
- If the server is a master; the line should be rewritten as 'slaveof no one' instead of blanked
- If the server is a slave; use original behavior
Additionally, the config parsing for 'slaveof no one' would need to be handled properly, so the master slaveof configuration doesn't become a slave config for an invalid host/port.
This may feel hacky at first, but the slaveof 'no one' is already used as the command, so it's not inherently new language to redis, it's just a new use case for this language. Additionally, this way, in a live environment where I dynamically flip the replication role, the config file would reliably flip between two known states, instead of slowly, surely filling the conf file with whitespace, which seems much more expected.
That said, I'd be happy with any fix, such that when the replication role is flipping, and the config is being rewritten with 'CONFIG REWRITE', that the config file flips between 2 states (assuming the masterhost/masterport is the same for slave configurations).
I can try out patching this if you like my approach, let me know-
Thanks!