Skip to content
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

Merged
merged 3 commits into from
Oct 24, 2024
Merged

Conversation

lippserd
Copy link
Member

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.

pkg/icingadb/ha.go Show resolved Hide resolved
@@ -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()

Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

pkg/icingadb/ha.go Outdated Show resolved Hide resolved
yhabteab
yhabteab previously approved these changes Oct 22, 2024
@lippserd lippserd requested a review from Al2Klimov October 22, 2024 14:03
@yhabteab yhabteab added this to the 1.3.0 milestone Oct 22, 2024
@yhabteab yhabteab added the enhancement New feature or request label Oct 22, 2024
Copy link
Member

@Al2Klimov Al2Klimov left a 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.
@lippserd lippserd changed the title HA: Use sync/atomic#Pointer instead of our own wrapper Use sync/atomic#Pointer instead of our own wrapper Oct 24, 2024
@lippserd
Copy link
Member Author

@Al2Klimov @yhabteab I also changed the type in telemetry and adjusted the implementation so that the atomic.Pointer usages initially hold the zero values of their types. In addition, copies of the pointer values are now only created if they are actually needed.

yhabteab
yhabteab previously approved these changes Oct 24, 2024
Return `atomic.pointer`, so that initialisation is not the responsibility of
another package.
@lippserd
Copy link
Member Author

@yhabteab I'm sorry, I had to push another change 😆.

@lippserd lippserd requested a review from yhabteab October 24, 2024 09:47
@yhabteab yhabteab merged commit 1564a03 into main Oct 24, 2024
32 checks passed
@yhabteab yhabteab deleted the use-sync-atomic branch October 24, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants