Skip to content

Conversation

@tamilmani1989
Copy link
Member

@tamilmani1989 tamilmani1989 commented Oct 26, 2021

Reason for Change:

Reason for Change:
Previously lock obtained by creating file with EXEC permission and on release it has to remove file otherwise other CNI process cannot acquire. If a process exits in middle without releasing, lock file exists preventing other CNI to acquire lock. This required CNI to have complicated logic of checking if process holding lock exists and make sure its CNI process.

Changes:
This PR uses go internal package lockedfile api to implement lock across process. This API internally handles process exit/crash after acquiring lock. Even if exited process didnt release lock explicitly, the new cni process could acquire lock and continue its operation. This is blocking api and added go routine to make it non-blocking as like previous behaviour.

NOTE: This locking behavior changes for CNS also

Issue Fixed:

Requirements:

Notes:

@tamilmani1989 tamilmani1989 force-pushed the tamanoha/lockedfileapi branch 2 times, most recently from dcf13e0 to 22fcd87 Compare October 27, 2021 00:34
@tamilmani1989 tamilmani1989 force-pushed the tamanoha/lockedfileapi branch from 22fcd87 to d883e76 Compare October 27, 2021 01:27
Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

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

looks really solid and definitely an improvement 💯
requesting a couple superficial changes

@tamilmani1989 tamilmani1989 force-pushed the tamanoha/lockedfileapi branch 2 times, most recently from 949b4cb to f15b07f Compare November 1, 2021 18:19
@tamilmani1989 tamilmani1989 force-pushed the tamanoha/lockedfileapi branch from f15b07f to caf38a9 Compare November 1, 2021 18:40
Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

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

only requesting that you finish changing the error strings and variable names, everything else lgtm

b = append(buf, Delimiter)
//nolint:staticcheck // append says It is therefore necessary to store the
// result of append, often in the variable holding the slice itself:
b = append(b, Delimiter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

to conform to the standard Go io.Writer interface, Write([]byte) must not modify the slice, even temporarily. Copying b into buf before appending delim was the right thing to do here.

Copy link
Member Author

Choose a reason for hiding this comment

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

copy function wasn't working properly in windows atleast in version I tested and thats why changed this. in windows after copy both b and buf contents are just spaces

Copy link
Member Author

Choose a reason for hiding this comment

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

these comments are posted in append function and the recommendation is to use same buffer

Copy link
Collaborator

Choose a reason for hiding this comment

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

using the same buffer breaks the Write([]byte) interface contract. if copy() seems broken on windows I think something else is going on here that needs to be figured out

Copy link
Collaborator

@rbtr rbtr Nov 4, 2021

Choose a reason for hiding this comment

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

hey @tamilmani1989, @ramiro-gamarra just pointed out to me that the signature for copy(dst, src) is...destination first. so the way this was originally written is just backwards. swapping those args in the original code should make everything work

@tamilmani1989
Copy link
Member Author

only requesting that you finish changing the error strings and variable names, everything else lgtm

addressed it except one

@tamilmani1989 tamilmani1989 force-pushed the tamanoha/lockedfileapi branch from 594fe79 to 33e3105 Compare November 4, 2021 17:45
rbtr
rbtr previously approved these changes Nov 4, 2021
@tamilmani1989
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…re-container-networking into tamanoha/lockedfileapi

# Conflicts:
#	telemetry/telemetrybuffer.go
}
require.NoError(t, err)
require.Equal(t, tt.want, got)
require.Equal(t, tt.want, got, "Expected:%d but got:%d", tt.want, got)
Copy link
Collaborator

Choose a reason for hiding this comment

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

for future reference, the testify comparison funcs print the diff of the inputs when they fail so this additional logging shouldn't be necessary

@tamilmani1989 tamilmani1989 merged commit cdab7d0 into master Nov 9, 2021
@tamilmani1989 tamilmani1989 deleted the tamanoha/lockedfileapi branch November 9, 2021 16:19
matmerr pushed a commit to matmerr/azure-container-networking that referenced this pull request Nov 11, 2021
* added lockedfileapi support for CNI

* fixed interface changes

* addressed comments
fixed ut

* addressed comments

* fixed copy to buffer part in writer api

* fixed copy to buffer part in writer api

* keeping old code not changing it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants