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 comments for singleInstance creation mechanism in giteaclient.go #534

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

kushnaidu
Copy link
Contributor

This change removes a conditional statement which is never executed.

Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
@liamfallon
Copy link
Member

/approve

Copy link
Member

@liamfallon liamfallon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR

@kushnaidu
Copy link
Contributor Author

Thanks for the PR

no problem :D

@henderiw
Copy link
Contributor

@vjayaramrh are you ok ?

@@ -59,13 +59,9 @@ func GetClient(ctx context.Context, client resource.APIPatchingApplicator) (Gite
if singleInstance == nil {
lock.Lock()
defer lock.Unlock()
if singleInstance == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

The existing implementation uses the check-lock-check pattern, The check in L59 is to determine whether we need to lock or not. Once lock is acquired, the check at L62 ensures some other thread has not created an instance between the time we did the check at L59 and acquired the lock. Hope this make sense and also why it is not dead code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh perfect, got it, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh perfect, got it, thanks!

@kushnaidu You may want to instead update the file with comments on why the code is structured the way it is, so that others may not accidentally think it is dead code. It will also be a good first PR contribution (only if it makes sense to you) from your side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I'll do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @vjayaramrh, does it look better now?

@vjayaramrh
Copy link
Contributor

@vjayaramrh are you ok ?

@henderiw FYI I have commented in the PR why we should keep the code the way it is

@henderiw
Copy link
Contributor

Thx @vjayaramrh .agreed, thx for looking at this. I will close the PR.

@henderiw henderiw closed this Feb 27, 2024
@liamfallon
Copy link
Member

Reopened so that @kushnaidu can add the comment suggested by @vjayaramrh .

@liamfallon liamfallon reopened this Feb 28, 2024
@henderiw
Copy link
Contributor

@kushnaidu can you provide the comments for readability ?

@kushnaidu
Copy link
Contributor Author

@kushnaidu can you provide the comments for readability ?

Yes yes, I shall do that.

@kushnaidu
Copy link
Contributor Author

Reopened so that @kushnaidu can add the comment suggested by @vjayaramrh .

will do it now.

Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
@kushnaidu kushnaidu changed the title remove dead code in giteaclient.go Add comments for singleInstance creation mechanism in giteaclient.go Feb 28, 2024
@@ -55,10 +55,12 @@ func GetClient(ctx context.Context, client resource.APIPatchingApplicator) (Gite
if client.Client == nil {
return nil, fmt.Errorf("failed creating gitea client, value of client.Client cannot be nil")
}

// check if instance is created
Copy link
Contributor

@vjayaramrh vjayaramrh Feb 28, 2024

Choose a reason for hiding this comment

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

you may want to mention "check-lock-check pattern implementation is followed" to make it easy for folks to search about the pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

@vjayaramrh vjayaramrh left a comment

Choose a reason for hiding this comment

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

/lgtm

@liamfallon
Copy link
Member

/lgtm
/approve

@henderiw
Copy link
Contributor

/lgtm
/approve

Copy link
Contributor

nephio-prow bot commented Feb 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: henderiw, liamfallon, vjayaramrh

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:

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

@nephio-prow nephio-prow bot added the approved label Feb 28, 2024
@nephio-prow nephio-prow bot merged commit 419bfb1 into nephio-project:main Feb 28, 2024
8 of 9 checks passed
PrimalPimmy pushed a commit to 5GSEC/nephio that referenced this pull request Aug 2, 2024
…ephio-project#534)

This change removes a conditional statement which is never executed.

---------

Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants