-
Notifications
You must be signed in to change notification settings - Fork 32
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
fix leader changed bug #137
Conversation
pkg/nebula/meta_client.go
Outdated
if execResp, ok := resp.(*meta.ExecResp); ok { | ||
return execResp.Code | ||
} | ||
return reflect.ValueOf(resp).Elem().Field(0).Interface().(nebula.ErrorCode) |
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 seems puzzling, is there a better way?
pkg/nebula/meta_client.go
Outdated
if execResp, ok := resp.(*meta.ExecResp); ok { | ||
return execResp.Leader | ||
} | ||
return reflect.ValueOf(resp).Elem().Field(1).Interface().(*nebula.HostAddr) |
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.
Similar to the previous one.
} | ||
|
||
for _, space := range spaces { | ||
if contains(nc.Status.Storaged.BalancedSpaces, *space.Id.SpaceID) { |
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 not check the spaces every time?
Is it possible that the time between the two executions of this function is relatively long?
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.
A balanced space is not needed balance again.
return nil | ||
} | ||
} | ||
log.Info("Balance job in progress") | ||
return &utilerrors.ReconcileError{Msg: fmt.Sprintf("Balance job %d still in progress", jobID)} | ||
} | ||
|
||
func (m *metaClient) retryOnError(req interface{}, fn ExecFn) error { | ||
func (m *metaClient) retryOnError(req interface{}, fn Fn) (interface{}, 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.
How about ?
type (
ExecResp interface{
GetErrorCode() nebula.ErrorCode
GetChangedLeader() *nebula.HostAddr
}
ExecFn func(req interface{}) (ExecResp, error)
)
func (m *metaClient) retryOnError(req interface{}, fn ExecFn) error {
...
}
You can set the `resp` in `ExecFn` to avoid type conversions?
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's tedious, each method must define a wrapper to implement ExecResp. I prefer using reflect to get the response value.
@MegaByte875 could I know the behavoir of the bug that this PR is trying to fix, please? |
@wey-gu Yes, fix the leader change bug. |
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.
LGTM
No description provided.