Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

feature: define the interface SupernodeLocator #1294

Merged
merged 1 commit into from
May 1, 2020

Conversation

lowzj
Copy link
Member

@lowzj lowzj commented Apr 22, 2020

Signed-off-by: lowzj [email protected]

Ⅰ. Describe what this PR did

issues: #1293

This pull request just defines the SupernodeLocator interface, I will open another pull request to refactor the dfclient to use this interface to get supernode.

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@lowzj lowzj force-pushed the SupernodeLocate branch 2 times, most recently from 8d4e4e0 to 3194dfe Compare April 22, 2020 10:26
@pouchrobot pouchrobot added size/L and removed size/L labels Apr 22, 2020
@lowzj lowzj force-pushed the SupernodeLocate branch from 3194dfe to a0085a3 Compare April 22, 2020 10:42
@codecov-io
Copy link

codecov-io commented Apr 22, 2020

Codecov Report

Merging #1294 into master will increase coverage by 0.25%.
The diff coverage is 84.12%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1294      +/-   ##
==========================================
+ Coverage   51.16%   51.41%   +0.25%     
==========================================
  Files         123      125       +2     
  Lines        8177     8240      +63     
==========================================
+ Hits         4184     4237      +53     
- Misses       3654     3660       +6     
- Partials      339      343       +4     
Impacted Files Coverage Δ
dfget/locator/static_locator.go 83.05% <83.05%> (ø)
dfget/locator/locator.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab71c0d...7e04f05. Read the comment docs.

@lowzj lowzj force-pushed the SupernodeLocate branch from a0085a3 to 8b22af4 Compare April 22, 2020 15:49
@lowzj lowzj force-pushed the SupernodeLocate branch from 8b22af4 to a242c4e Compare April 26, 2020 23:35
@pouchrobot pouchrobot added size/XL and removed size/L labels Apr 26, 2020
@lowzj lowzj force-pushed the SupernodeLocate branch 3 times, most recently from 5e6671a to 0520819 Compare April 28, 2020 04:07
Copy link
Member

@SataQiu SataQiu left a comment

Choose a reason for hiding this comment

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

SGTM.
And add some comments.

Infos map[string]string
}

// Supernode basic information of supernodes.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Supernode basic information of supernodes.
// Supernode holds the basic information of supernodes.

Metrics *SupernodeMetrics
}

// SupernodeMetrics the metrics used for locator to choose supernode.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// SupernodeMetrics the metrics used for locator to choose supernode.
// SupernodeMetrics holds metrics used for the locator to choose supernode.

)

func init() {
rand.Seed(time.Now().UnixNano())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can consider moving rand.Seed(time.Now().UnixNano()) to the beginning of the main function to ensure that it always work and also avoids calling it everywhere. 😕

func main() {
	rand.Seed(time.Now().UnixNano())
	
	app.Execute()
}

Copy link
Member Author

@lowzj lowzj Apr 30, 2020

Choose a reason for hiding this comment

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

How about move rand.Seed to the top package of dfget rather than main function? I think this operation should be transparent to the caller.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. That's OK with me. Just don't like calling rand.Seed everywhere!

Copy link
Member Author

Choose a reason for hiding this comment

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

In order to ensure the independence of this pr, I open another pr #1318 to do this, please take a look.

return
}

func (s *StaticLocator) Refresh() bool {
Copy link
Member

Choose a reason for hiding this comment

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

This looks more like Reset 😅 How about rename as Reset.

Copy link
Member Author

Choose a reason for hiding this comment

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

This implementation looks more like Reset. But considering the different behaviors of other implementations, it may get a new list of supernodes via invoking this method.
So IMOP, Reresh is more appropriate. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Make sense!

@lowzj lowzj force-pushed the SupernodeLocate branch from 0520819 to 40d3766 Compare April 30, 2020 05:57
// configuration or CLI.
func NewStaticLocator(nodes []*config.NodeWeight) *StaticLocator {
locator := &StaticLocator{}
if nodes == nil || len(nodes) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using len(nodes) == 0 is enough here.

if idx >= len(s.Group.Nodes) {
return nil
}
return s.Group.Nodes[idx]
Copy link
Contributor

Choose a reason for hiding this comment

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

How about extract a common method to get node with specified index?

func (s *StaticLocator) getNode(index int32) *Supernode(){
    if s.Group == nil || index >= len(s.Group.Nodes) {
		return nil
    }
    return s.Group.Nodes[idx]
}

Next() *Supernode

// GetGroup returns the group.
GetGroup(name string) *SupernodeGroup
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, why consider add a supernode group concept here? And the SupernodeGroup can only be retrieved for viewing. Is it expected that I can choose a group to use?

Copy link
Member Author

Choose a reason for hiding this comment

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

For example, we can group supernodes by region, business, version and so on. The implementation of SupernodeLocator can select a supernode based on the group. The caller does not need to care about the specific selection logic, but if it is really needed, the supernode list can also be obtained through this interface.

@starnop
Copy link
Contributor

starnop commented May 1, 2020

Please make a rebase for this PR. 😄

@lowzj lowzj force-pushed the SupernodeLocate branch 3 times, most recently from a7d3a4d to 0491012 Compare May 1, 2020 06:55
@lowzj lowzj force-pushed the SupernodeLocate branch from 0491012 to 7e04f05 Compare May 1, 2020 06:57
@starnop
Copy link
Contributor

starnop commented May 1, 2020

LGTM.

@starnop starnop merged commit 8237693 into dragonflyoss:master May 1, 2020
@lowzj lowzj deleted the SupernodeLocate branch May 1, 2020 09:01
sungjunyoung pushed a commit to sungjunyoung/Dragonfly that referenced this pull request May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants