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

new lockDuplicateRequest #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

iamsurfing
Copy link

"time"
)

type key struct {
Copy link
Owner

Choose a reason for hiding this comment

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

This is the global namespace, probably best to use a name like lockDuplicateKey or similar.

Copy link
Author

Choose a reason for hiding this comment

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

OK

}

var newValue value
parse, _ := time.ParseDuration("+5s")
Copy link
Owner

Choose a reason for hiding this comment

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

It'd be much more efficient to use a constant that is set to 5 * time.Second here rather than parsing a string in every call.

Copy link
Author

Choose a reason for hiding this comment

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

OK

type value struct {
//If expiredTimeStamp is negative number , it means it will return SERVFAIL.
expiredTimeStamp int64
mu *newMutex
Copy link
Owner

Choose a reason for hiding this comment

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

Why re-implement the mutex here? Can't you use the regular mutex instead and pass a *value below?

Copy link
Author

Choose a reason for hiding this comment

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

If timeout, this plugin should unlock-all same request and then return SERVFAIL to downstream.
Tradition Mutex can not support it.

r.m.Delete(k)
} else if expiredTimeStamp >= 0 && expiredTimeStamp < currentTimeStamp {
r.m.Delete(k)
v.expiredTimeStamp = ^expiredTimeStamp
Copy link
Owner

Choose a reason for hiding this comment

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

Since v is not locked here, I don't think this is thread-safe.

Regardless, instead of doing these calculations, using a channel that is closed to signal "timeout" would be better. Could even use a context with timeout in this case. Or simply add a (fixed) timeout into the value, then check it with https://pkg.go.dev/time#Time.After against the current time.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, It is not thread-safe.

I prefer timeTicker.

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.

2 participants