Skip to content

Add DSN options to enable SQL queries on follower nodes#136

Merged
leventeliu merged 6 commits intodevelopfrom
feature/useFollowerPeers
Dec 14, 2018
Merged

Add DSN options to enable SQL queries on follower nodes#136
leventeliu merged 6 commits intodevelopfrom
feature/useFollowerPeers

Conversation

@ggicci
Copy link
Copy Markdown
Contributor

@ggicci ggicci commented Dec 13, 2018

No description provided.

@ggicci ggicci changed the title Feature/use follower peers Add DSN options to use follower nodes to run SQL queries Dec 13, 2018
@ggicci ggicci changed the title Add DSN options to use follower nodes to run SQL queries Add DSN options to enable SQL queries on follower nodes Dec 13, 2018
client/conn.go Outdated
// choose a random follower node
if cfg.UseFollower && len(peers.Servers) > 1 {
for {
rand.Seed(time.Now().UnixNano())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's inappropriate for client SDK to modify the golang runtime global random source seed.
I thought using client package global randSource is better, already initialized with rand.New(rand.NewSource(time.Now().UnixNano())).

client/conn.go Outdated
if cfg.UseFollower && len(peers.Servers) > 1 {
for {
rand.Seed(time.Now().UnixNano())
node := peers.Servers[rand.Intn(len(peers.Servers))]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For example, this rand.Intn can be replaced with randSource.Intn

client/conn.go Outdated

func (c *conn) stopAckWorkers() {
if c.leader != nil {
close(c.leader.ackCh)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be replaced with c.leader.stopAckWorkers()

client/conn.go Outdated
close(c.leader.ackCh)
}
if c.follower != nil {
close(c.follower.ackCh)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Likewise, c.follower.stopAckWorkers()

client/conn.go Outdated
rand.Seed(time.Now().UnixNano())
node := peers.Servers[rand.Intn(len(peers.Servers))]
if node != peers.Leader {
c.pFollowerCaller = rpc.NewPersistentCaller(node)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing CloseStream for c.pFollowerCaller

Copy link
Copy Markdown
Contributor

@xq262144 xq262144 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@leventeliu leventeliu left a comment

Choose a reason for hiding this comment

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

LGTM, approve.

@leventeliu leventeliu merged commit a7b7a7d into develop Dec 14, 2018
@leventeliu leventeliu deleted the feature/useFollowerPeers branch December 14, 2018 01:47
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.

3 participants