Repository navigation
Fix/persist worker down - #63
Merged
Merged
Conversation
worker-down lived only in memory. initWorkers built every worker a fresh conn, and a fresh conn carries no assertion, so a restart returned each downed worker to placement once its reconcile passed. That bites hardest on autoscaler scale-in, which downs a worker before terminating it: a restart in between places player instances on a box about to disappear, with nobody watching. It also reopens a box mid-drain. workers gains downsince, the time worker-down took the worker down, NULL otherwise. SetWorkerDown writes it under the same read lock as the assertion, so a worker-add cannot land between the two; it marks first, so a failed write still leaves the worker down for the life of this corkd and the PATCH reports the error. worker-add clears it. initWorkers restores the worker down, with its original since and reason, and logs it; its conn is neither reconciled nor probed until a worker-add replaces it, as for a worker downed in a running corkd. Only down is stored. unresponsive is an observation and re-derives itself from the probe after a restart; stored, nothing would ever lift it. Existing databases gain the column in place, every worker reading as up.
…r down The PATCH answers with the error alone, and a bare "database is locked" reads as a worker-down that did nothing, when the worker is down and only the write is missing. The error now says so; worker-down again retries the write, writing the same since. The downsince migration moves beside the workers.public one. Between the worker-column loop and the port index it broke that index's comment, which explains itself by "the migration above". Comments that still had pollers marking workers down, a restart starting every worker afresh, and only restored conns parking in runWorker now say what the code does. A test pins the mark-before-write order.
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.
Fixes #51.
worker-downwas held only in memory. On a corkd restart every worker got a fresh connection with no down marker, so each downed worker went back into placement as soon as its reconcile passed. The worst case is autoscaler scale-in: it downs a worker before terminating it, so a restart in between puts player instances on a box that is about to disappear. A restart also put boxes back into placement in the middle of a drain.What changes
workers.downsince: the timeworker-downtook the worker down (unix nanos), NULL when it is not down. Older databases get the column on startup, and every worker in them reads as up.worker-downmarks the worker down in memory first, then writesdownsince. Both happen under the same lock, so aworker-addcannot land between them and leave the database saying down while the worker is back in placement. If the write fails, the worker stays down for the life of this corkd. The PATCH answers 500 with an error that says the worker is down but not persisted. Runningworker-downagain retries the write with the same timestamp.worker-addclearsdownsincealong with the in-memory down.initWorkersrestores the worker as down, with its original time and reason, and logs it. The restored worker is neither reconciled nor probed until aworker-add, the same as a worker downed while corkd is running. Its stops still take the DB-only path.downis stored.unresponsiveis an observation, and the probe works it out again after a restart. If it were stored, nothing would ever lift it.Rollback
A corkd from before this change leaves the
downsincecolumn in place but ignores it. Aworker-addrun while the old version is running is therefore lost: the next start of this version brings that worker back down. corkd logs it at startup as down since its original time, andworker-addlifts it again.Left as is
worker-addfails after its upsert (for example, unreadable TLS material),downsinceis already cleared while the in-memory worker stays down. Thepublicaddress already behaves this way, and the operator was asking for the worker back.SQLITE_BUSYthe worker endpoints answer 500, not 503. This applies to all three of them, so changing it is separate work.Testing
worker-addclears the stored down.worker-downwhose write fails still leaves the worker down, and its error says so.workerstable gets the column on upgrade.worker-addnot clearing, write before mark.worker-downtests now get a database, sinceworker-downwrites to one.go test ./...passes,go test ./cork/ -racepasses, andgo vetandgofmtare clean.