-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use sync/atomic#Pointer
instead of our own wrapper
#812
Conversation
f3ff6e1
to
76e7632
Compare
@@ -121,7 +121,8 @@ func (h *HA) Takeover() chan string { | |||
|
|||
// State returns the status quo. | |||
func (h *HA) State() (responsibleTsMilli int64, responsible, otherResponsible bool) { | |||
state, _ := h.state.Load() | |||
state := h.state.Load() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been a zero value if uninitialized, now it's a nil ptr in this case. Now we have to make sure HA#State() don't get a nil ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -428,7 +429,7 @@ func (h *HA) realize( | |||
|
|||
h.signalTakeover(takeover) | |||
} else if otherResponsible { | |||
if state, _ := h.state.Load(); !state.otherResponsible { | |||
if state := h.state.Load(); !state.otherResponsible { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we're now loading by-ref, state.otherResponsible = true
below affects all readers. But this shouldn't be too bad as that's just a bool and we're storing it anyway right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
76e7632
to
9125c35
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still
var LastSuccessfulSync com.Atomic[SuccessfulSync] |
btw.
Go 1.19 introduced `sync/atomic#Pointer` among other things, so we no longer need to use the Atomic wrapper from our Icinga Go library.
Go 1.19 introduced `sync/atomic#Pointer` among other things, so we no longer need to use the Atomic wrapper from our Icinga Go library.
9125c35
to
7cf54c1
Compare
HA
: Use sync/atomic#Pointer
instead of our own wrappersync/atomic#Pointer
instead of our own wrapper
@Al2Klimov @yhabteab I also changed the type in |
Return `atomic.pointer`, so that initialisation is not the responsibility of another package.
@yhabteab I'm sorry, I had to push another change 😆. |
Go 1.19 introduced
sync/atomic#Pointer
among other things, so we no longer need to use the Atomic wrapper from our Icinga Go library.