consul/command
Wojciech Bederski b014c0f91b make Pause()/Resume()/isPaused() behave more like a semaphore
see: https://github.com/hashicorp/consul/issues/1173 #1173

Reasoning: somewhere during consul development Pause()/Resume() and
PauseSync()/ResumeSync() were added to protect larger changes to
agent's localState.  A few of the places that it tries to protect are:

- (a *Agent) AddService(...)      # part of the method
- (c *Command) handleReload(...)  # almost the whole method
- (l *localState) antiEntropy(...)# isPaused() prevents syncChanges()

The main problem is, that in the middle of handleReload(...)'s
critical section it indirectly (loadServices()) calls  AddService(...).
AddService() in turn calls Pause() to protect itself against
syncChanges(). At the end of AddService() a defered call to Resume() is
made.

With the current implementation, this releases
isPaused() "lock" in the middle of handleReload() allowing antiEntropy
to kick in while configuration reload is still in progress.
Specifically almost all services and probably all check are unloaded
when syncChanges() is allowed to run.

This in turn can causes massive service/check de-/re-registration,
and since checks are by default registered in the critical state,
a majority of services on a node can be marked as failing.
It's made worse with automation, often calling `consul reload` in close
proximity on many nodes in the cluster.

This change basically turns Pause()/Resume() into P()/V() of
a garden-variety semaphore. Allowing Pause() to be called multiple times,
and releasing isPaused() only after all matching/defered Resumes() are
called as well.

TODO/NOTE: as with many semaphore implementations, it might be reasonable
to panic() if l.paused ever becomes negative.
2015-09-11 18:28:06 +02:00
..
agent make Pause()/Resume()/isPaused() behave more like a semaphore 2015-09-11 18:28:06 +02:00
configtest.go command: fix configtest help format 2015-05-11 09:42:26 -07:00
configtest_test.go command/configtest: add 2015-05-08 13:09:50 -07:00
event.go command: event command supports -token arg 2015-06-22 16:59:41 -07:00
event_test.go command/event: Adding new event command 2014-08-28 16:40:31 -07:00
exec.go command: remote exec takes -token parameter 2015-06-22 17:16:28 -07:00
exec_test.go command: check LastIndex is not zero while waiting for leader 2015-01-07 15:18:00 -08:00
force_leave.go website: updating documentation on commands 2014-02-18 17:32:13 -08:00
force_leave_test.go gofmt 2014-05-20 16:25:29 -07:00
info.go command/info: Move warning output to the top 2014-04-29 11:09:14 -07:00
info_test.go command/info: remove unused import 2014-03-05 15:02:56 -08:00
join.go website: updating documentation on commands 2014-02-18 17:32:13 -08:00
join_test.go command: Fixing more tests 2014-04-11 16:34:29 -07:00
keygen.go Adding the various CLI commands 2013-12-31 13:06:33 -08:00
keygen_test.go Adding the various CLI commands 2013-12-31 13:06:33 -08:00
keyring.go agent: write-level keyring ACLs work 2015-07-07 10:36:51 -06:00
keyring_test.go consul: more tests, remove unused KeyManager() method 2014-11-19 16:37:40 -08:00
leave.go website: updating documentation on commands 2014-02-18 17:32:13 -08:00
leave_test.go Adding the various CLI commands 2013-12-31 13:06:33 -08:00
lock.go lock.go: fix another race condition 2015-09-01 14:27:23 -07:00
lock_test.go command/lock: Adding simple test 2015-01-19 15:47:17 -10:00
maint.go command/maint: better arg conflict checking 2015-01-22 11:20:32 -08:00
maint_test.go Adds missing token to maint unit test. 2015-09-10 14:53:00 -07:00
members.go Sort members in by name for consul members 2015-05-22 10:37:54 +02:00
members_test.go Include DC in the members command output 2015-05-15 23:26:34 +02:00
monitor.go website: updating documentation on commands 2014-02-18 17:32:13 -08:00
reload.go command/reload: Adding new command 2014-06-11 10:58:26 -07:00
reload_test.go command/reload: Adding new command 2014-06-11 10:58:26 -07:00
rpc.go command: remote exec takes -token parameter 2015-06-22 17:16:28 -07:00
rpc_test.go command: address vet report in test 2015-01-17 07:57:11 +01:00
util_test.go agent: scada client and HTTP server are tracked separately 2015-08-25 16:59:53 -07:00
util_unix.go command: fix Windows build 2015-01-25 05:00:52 +01:00
util_windows.go docs: describe child process handling on Windows for lock command 2015-01-25 11:42:29 +01:00
version.go Make the 'consul version' to return value that is from 'git describe --tags' 2014-11-18 22:15:58 +00:00
version_test.go Adding basic CLI infrastructure 2013-12-19 11:22:08 -08:00
watch.go remove control flow on errExit by switching from bool to int 2014-12-06 12:50:38 +01:00
watch_test.go command/watch: Adding tests 2014-08-21 16:08:21 -07:00