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

fileutil: improve control flow readability of purgeFile function #17564

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

redwrasse
Copy link
Contributor

@redwrasse redwrasse commented Mar 11, 2024

PR for issue #17565

Proposed improvement to syntax for control flow of purgeFile function in client/pkg/fileutil/purge.go.

  • go routine accesses single slice fnamesWithSufix that remains unmodified.
  • nPurged variable introduced for for loop in go routine, and for counting writes to purgeC channel.
  • Remove explicit sorting after suffix filtering, as the provided ReadDir method reads directory filenames in sorted order, and sorted order is preserved after suffix filtering.

Signed-off-by: redwrasse <mail@redwrasse.io>
@k8s-ci-robot
Copy link

Hi @redwrasse. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@redwrasse redwrasse marked this pull request as ready for review March 11, 2024 05:01
@jmhbnz
Copy link
Member

jmhbnz commented Mar 11, 2024

/ok-to-test

@@ -53,26 +52,35 @@ func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval
zap.Uint("max", max),
zap.Duration("interval", interval))

readDirWithSuffix := func(dirname string) ([]string, error) {
Copy link
Member

@serathius serathius Mar 11, 2024

Choose a reason for hiding this comment

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

Why not have it as normal function (defined outside of other functions body) instead of anonymous one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to have an anonymous function, agreed. Do you suggest adding as a separate function in purge.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

converted to a normal function in purge.go. this is a little awkward though as it should properly probably be part of read_dir.go.

Signed-off-by: redwrasse <mail@redwrasse.io>
@redwrasse redwrasse force-pushed the redwrasse/purge-fnames-logic branch from c35aecb to 6cf5419 Compare March 14, 2024 01:27
@redwrasse
Copy link
Contributor Author

/retest

Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM

@ahrtr
Copy link
Member

ahrtr commented Mar 31, 2024

cc @serathius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

6 participants