-
Notifications
You must be signed in to change notification settings - Fork 205
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
Optimized peer authentication messages management #4420
Optimized peer authentication messages management #4420
Conversation
Codecov Report
@@ Coverage Diff @@
## rc/2022-july #4420 +/- ##
================================================
+ Coverage 73.92% 73.94% +0.01%
================================================
Files 677 677
Lines 86884 86877 -7
================================================
+ Hits 64230 64241 +11
+ Misses 17855 17841 -14
+ Partials 4799 4795 -4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
storage/timecache/timeCacher.go
Outdated
return | ||
} | ||
|
||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This func always returns nothing. Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, could've used logIfError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check that the function has named returned parameters. This is go idiomatic. log.LogIfError does not add sufficient context.
Removed one return, thus
storage/timecache/timeCacheCore.go
Outdated
@@ -58,7 +58,7 @@ func (tcc *timeCacheCore) upsert(key string, value interface{}, duration time.Du | |||
} | |||
|
|||
// put will add the key, value and provided duration, overriding values if the data already existed | |||
// It returns if the value existed before this call. It also operates on the locker so the call is concurrent safe | |||
// It returns true if the value existed before this call. It also operates on the locker so the call is concurrent safe | |||
func (tcc *timeCacheCore) put(key string, value interface{}, duration time.Duration) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have this func return true if the value existed, since in func (tc *timeCacher) Put
you always return false and ignore if this one returns true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed bool & optimized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeCacheCore
should normally not care about the existence, nor the logic of its caller (timeCacher
). Therefore, it's alright to provide the information to the (any) caller - even if that piece of information isn't used.
storage/timecache/timeCacher.go
Outdated
@@ -81,7 +81,7 @@ func (tc *timeCacher) Clear() { | |||
|
|||
// Put adds a value to the cache. It will always return false since the eviction did not occur | |||
func (tc *timeCacher) Put(key []byte, value interface{}, _ int) (evicted bool) { | |||
_, err := tc.timeCache.upsert(string(key), value, tc.timeCache.defaultSpan) | |||
_, err := tc.timeCache.put(string(key), value, tc.timeCache.defaultSpan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So all callers of timeCacher.Put()
will receive this fix. Should be only positive impact, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, this was the actual fix, a complete rewrite of the existing data
@@ -115,14 +115,15 @@ func (tc *timeCacher) Peek(key []byte) (value interface{}, ok bool) { | |||
// HasOrAdd checks if a key is in the cache. | |||
// If key exists, does not update the value. Otherwise, adds the key-value in the cache | |||
func (tc *timeCacher) HasOrAdd(key []byte, value interface{}, _ int) (has, added bool) { | |||
existed, err := tc.timeCache.upsert(string(key), value, tc.timeCache.defaultSpan) | |||
var err error | |||
has, added, err = tc.timeCache.hasOrAdd(string(key), value, tc.timeCache.defaultSpan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So all callers of timeCacher.HasOrAdd()
will receive this fix. Should be only positive impact, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
storage/timecache/timeCacheCore.go
Outdated
|
||
_, found := tcc.data[key] | ||
if found { | ||
return found, false, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could have been true
(for symmetry).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -115,14 +115,15 @@ func (tc *timeCacher) Peek(key []byte) (value interface{}, ok bool) { | |||
// HasOrAdd checks if a key is in the cache. | |||
// If key exists, does not update the value. Otherwise, adds the key-value in the cache | |||
func (tc *timeCacher) HasOrAdd(key []byte, value interface{}, _ int) (has, added bool) { | |||
existed, err := tc.timeCache.upsert(string(key), value, tc.timeCache.defaultSpan) | |||
var err error | |||
has, added, err = tc.timeCache.hasOrAdd(string(key), value, tc.timeCache.defaultSpan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has
and added
are mutually exclusive, right? Bit of redundancy therefore, but it's good to be explicit (as it is now) 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, they are exclusive. Since I have to implement the already existing and used interface, I had to return something.
Also, beside (true, false) and (false, true) we also have (false, false) when the provided key is nil or empty, so we had to encode 3 states.
storage/timecache/timeCacheCore.go
Outdated
@@ -57,6 +57,47 @@ func (tcc *timeCacheCore) upsert(key string, value interface{}, duration time.Du | |||
return found, nil | |||
} | |||
|
|||
// put will add the key, value and provided duration, overriding values if the data already existed | |||
// It returns true if the value existed before this call. It also operates on the locker so the call is concurrent safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// It returns true if the value existed before this call. It also operates on the locker so the call is concurrent safe | |
// It also operates on the locker so the call is concurrent safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed part of the comment
@@ -170,6 +170,9 @@ func (sender *peerAuthenticationSender) execute() (error, bool) { | |||
return err, isTriggered | |||
} | |||
|
|||
log.Debug("sending peer authentication message", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we keep this on Debug level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, one message at ~2hours. Helps the debugging a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
storage/timecache/timeCacheCore.go
Outdated
|
||
_, found := tcc.data[key] | ||
if found { | ||
return found, false, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return true, false, nil
or at L100 return found, true, nil
just to keep the same logic ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already done in last commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
440f0ac
# Conflicts: # process/heartbeat/interceptedHeartbeat.go
3b74080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System test passed.
Description of the reasoning behind the pull request
put
function instead ofupsert
as to properly override existing values with newer onesProposed Changes
Testing procedure