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

Add SyncMap package and use it for graph stop/remove #25311

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

mheon
Copy link
Member

@mheon mheon commented Feb 12, 2025

This greatly simplifies the locking around these two functions, and things end up looking a lot more elegant. This should prevent the race flakes we were seeing before.

Fixes #25289

First time I've worked with Go generics - nice to finally have the ability to do generic data structures.

Does this PR introduce a user-facing change?

NONE

@openshift-ci openshift-ci bot added release-note-none approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 12, 2025
delete(m.data, key)
}

// ToMap returns a shallow copy of the underlying data of the SyncMap.
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to actually clone that here? You did not clone them before so cloneing them adds some overhead, sure not enough to notice but still unnecessary. I guess that is my way of complainging that we cannot do this like you would in rust where that caller would have to take ownership of it and it would be clear that the syncmap is not used afterwards...

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a separate method to get the underlying map for perf reasons, with a caveat that doing so breaks all guarantees of thread safety. Doesn't matter for the way we're using it, where it is only ever accessed by a single thread after a certain point.

@mheon mheon added the No New Tests Allow PR to proceed without adding regression tests label Feb 14, 2025
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

lint doesn't seem to be happy

// performance.
// SyncMap should always be passed by reference, not by value, to ensure thread
// safety is maintained.
type SyncMap[K comparable, V any] struct {
Copy link
Member

Choose a reason for hiding this comment

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

oh one other thing syncmap.SyncMap kinda sucks as type name, maybe we just name it Map so it is more similar to sync.Map?

// not here; thus, SyncMap should not be used in truly performance sensitive
// areas, but places where code cleanliness is more important than raw
// performance.
// SyncMap should always be passed by reference, not by value, to ensure thread
Copy link
Member

Choose a reason for hiding this comment

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

s/should/must

This greatly simplifies the locking around these two functions,
and things end up looking a lot more elegant. This should prevent
the race flakes we were seeing before.

Fixes containers#25289

Signed-off-by: Matt Heon <mheon@redhat.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

@mheon
Copy link
Member Author

mheon commented Feb 18, 2025

@containers/podman-maintainers PTAL and merge

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 18, 2025
Copy link
Contributor

openshift-ci bot commented Feb 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, Luap99, mheon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Luap99,giuseppe,mheon]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit e88ccec into containers:main Feb 18, 2025
83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. No New Tests Allow PR to proceed without adding regression tests release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI: new graph-based pod rm -fa flake
3 participants