Skip to content
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

server/operator: add operator state #647

Merged
merged 11 commits into from
May 26, 2017
Merged

server/operator: add operator state #647

merged 11 commits into from
May 26, 2017

Conversation

nolouch
Copy link
Contributor

@nolouch nolouch commented May 22, 2017

// OperatorUnKnownState indicates the unknown state
OperatorUnKnownState OperatorState = iota
// OperatorDoing indicates the doing state
OperatorDoing
Copy link
Contributor

Choose a reason for hiding this comment

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

/Doing/Running/s

Copy link
Contributor

Choose a reason for hiding this comment

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

Or Wait?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or Wait as the initial state, after the operator is sent to tikv, update to Running.

if ok {
return s
}
return operatorStateToName[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

/0/OperatorUnKnownState/s

if !ok {
*o = OperatorUnKnownState
}
*o = state
Copy link
Contributor

Choose a reason for hiding this comment

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

should in else closure.

}

func newAdminOperator(region *RegionInfo, ops ...Operator) *adminOperator {
return &adminOperator{
Region: region,
Start: time.Now(),
Ops: ops,
State: OperatorDoing,
Copy link
Contributor

Choose a reason for hiding this comment

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

why Doing here?

"unknown": OperatorUnKnownState,
"doing": OperatorDoing,
"finished": OperatorFinished,
"time_out": OperatorTimeOut,
Copy link
Contributor

Choose a reason for hiding this comment

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

timeout

c.Assert(err, IsNil)
c.Assert(newState, Equals, s)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

use an invalid marshaled data to check Unmarshal.

@@ -409,3 +411,7 @@ func collectOperatorCounterMetrics(op Operator) {
operatorCounter.WithLabelValues(label).Add(float64(value))
}
}

func collectOperatorStateCounterMetrics(op Operator) {
operatorCounter.WithLabelValues(op.GetState().String()).Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to use labels (operator, state) here.

// OperatorUnKnownState indicates the unknown state
OperatorUnKnownState OperatorState = iota
// OperatorDoing indicates the doing state
OperatorDoing
Copy link
Contributor

Choose a reason for hiding this comment

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

Or Wait?

@@ -260,6 +261,7 @@ func (c *coordinator) removeOperator(op Operator) {
delete(c.operators, regionID)

c.histories.add(regionID, op)
collectOperatorStateCounterMetrics(op)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the operator is replaced, its status will still be Doing.

@@ -222,22 +222,26 @@ func (c *coordinator) runScheduler(s *scheduleController) {

func (c *coordinator) addOperator(op Operator) bool {
c.Lock()
defer c.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

defer won't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the function removeOperator also need to access lock

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 add another func called removeOperatorWithLock?

server/event.go Outdated
return OperatorFinished
}

func (op *splitOperator) SetState(state OperatorState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

s/state/_/

}

func (op *regionOperator) SetState(state OperatorState) {
if op.State == OperatorFinished || op.State == OperatorTimeOut {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we meet the case that operator is finished or timeout, but the state is still set?

Copy link
Contributor Author

@nolouch nolouch May 25, 2017

Choose a reason for hiding this comment

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

if one operator combined by multi-operator, some operator in it may be finished or timeout, and now we replace this operator.

@siddontang
Copy link
Contributor

any test to check operator state?

@siddontang
Copy link
Contributor

LGTM

PTAL @disksing

@disksing
Copy link
Contributor

LGTM.

@nolouch nolouch merged commit f4d4c26 into master May 26, 2017
@nolouch nolouch deleted the shuning/operator-state branch May 26, 2017 05:14
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