Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Validate leader value in election #153

Merged
merged 5 commits into from
Aug 29, 2018
Merged

Validate leader value in election #153

merged 5 commits into from
Aug 29, 2018

Conversation

cw9
Copy link
Contributor

@cw9 cw9 commented Aug 28, 2018

This pr validates the value of the leader to make sure it's a valid instance id in the placement

@xichen2020 @robskillington @jeromefroe

@@ -329,6 +334,7 @@ func (mgr *electionManager) Open(shardSetID uint32) error {
if mgr.state != electionManagerNotOpen {
return errElectionManagerAlreadyOpenOrClosed
}
mgr.shardSetID = shardSetID
Copy link

Choose a reason for hiding this comment

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

Is this just for testing. I dont see where this is used.

mgr.logError("error getting placement", err)
return err
}
_, exist := p.Instance(leader)
Copy link

Choose a reason for hiding this comment

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

Seems like this will just tell you if the host exists, but not if the electionKey for the which this host is the leader?

This would tell us if the leader is a valid host, but not if that host thinks it is the leader. Perhaps this might be helpful:

instance, exist := p.Instance(leader)
if !exists {
   // handle unknown host as leader
}
if instance.ShardSetID() != mgr.ShardSetID {
  // handle leader with different shardSetID
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, will add the extra check

if !exist {
mgr.metrics.verifyLeaderNotInPlacement.Inc(1)
err := fmt.Errorf("received invalid leader value: [%s], which is not available in placement", leader)
mgr.logger.Error(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Use mgr.logError here to be consistent?

mgr.logger.Error(err.Error())
return err
}
mgr.logger.Infof("found valid new leader: [%s] for the campaign", leader)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need check if the current instance and the leader instance are in the same group?

Copy link
Contributor

@xichen2020 xichen2020 left a comment

Choose a reason for hiding this comment

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

LGTM w/ a nit.

if leaderInstance.ShardSetID() != instance.ShardSetID() {
err := fmt.Errorf("received invalid leader value: [%s] which owns shardSet %v, while this aggregator owns shardSet %v",
leader, leaderInstance.ShardSetID(), instance.ShardSetID())
mgr.logError("invalid leader value", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "leader is in a different shardset group" might be a better error message.

@cw9 cw9 merged commit f351f27 into master Aug 29, 2018
@cw9 cw9 deleted the chao-log branch August 29, 2018 19:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants