-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: support resigning ddl owner, use http method ddl/owner/resign #7649
Conversation
…into evict_owner_by_http
server/http_handler.go
Outdated
defer s.Close() | ||
} | ||
|
||
dom := domain.GetDomain(s.(sessionctx.Context)) |
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.
We can use session.GetDomain()
.
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.
What is the difference? Use session.GetDomain() will look likes:
dom, err := session.GetDomain(s.GetStore())
if err != nil {
return errors.Trace(err)
}
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.
The difference is that we do not need to create a session.
docs/tidb_http_api.md
Outdated
1. Resign the ddl owner, let tidb start a new ddl owner election. | ||
|
||
```shell | ||
curl http://{TiDBIP}:10080/ddl/owner/resign |
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 should be a POST
request.
server/http_handler.go
Outdated
@@ -334,6 +353,11 @@ type ddlHistoryJobHandler struct { | |||
*tikvHandlerTool | |||
} | |||
|
|||
// ddlResignOwnerHandler is the handler for resigning ddl owner. | |||
type ddlResignOwnerHandler struct { | |||
*tikvHandlerTool |
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 is not operated on TiKV.
How about we implement the method on ddlResignOwnerHandler
directly?
@coocood @lamxTyler PTAL |
Can we just use |
@coocood use |
@coocood fine, if using |
…into evict_owner_by_http
@coocood @lamxTyler Done, PTAL |
owner/manager.go
Outdated
|
||
func (m *ownerManager) retireOwner() { | ||
m.SetOwner(false) | ||
atomic.StorePointer(&m.elec, nil) |
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.
Could we only use the elec
to determine if it is the owner? Then we do not need to maintain the owner
anymore.
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.
There are some test cases use SetOwner(false) and just use elec to determin if it is the owner will not easy to mock in tests.
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.
Can we change SetOwner(isOwner bool)
to SetOwner(elec unsafe.Pointer)
?
In the mockManager
, we can use any not nil pointer to represent elec
.
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
return errors.Trace(err) | ||
} | ||
|
||
log.Warnf("%s Resign ddl owner success!", m.logPrefix) |
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.
Can we call RetireOwner
here?
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.
No, this is not the work of ResignOwner.
LGTM |
owner/manager.go
Outdated
@@ -45,12 +46,14 @@ type Manager interface { | |||
ID() string | |||
// IsOwner returns whether the ownerManager is the owner. | |||
IsOwner() bool | |||
// SetOwner sets whether the ownerManager is the owner. | |||
SetOwner(isOwner bool) | |||
// RetireOwner make the manager to be a not owner. It's exported for testing |
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.
end with .
owner/mock.go
Outdated
atomic.StoreInt32(&m.owner, 1) | ||
} | ||
|
||
// setOwner implements Manager.RetireOwner interface. |
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.
s/setOwner/RetireOwner
} | ||
|
||
ownerMgr := dom.DDL().OwnerManager() | ||
err = ownerMgr.ResignOwner(context.Background()) |
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.
Do we need to add a timeout?
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.
@winkyao Please answer this question.
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.
Done, PTAL
…into evict_owner_by_http
@zimulala PTAL |
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
/run-all-tests |
What problem does this PR solve?
Support resigning DDL owner, let tidb start a new DDL owner election.
What is changed and how it works?
Add a new HTTP method
ddl/owner/resign
and this method will callconcurrency.Election.Resign
.concurrency.Election.Resign
will delete the leader key/tidb/ddl/fg/owner/
on the etcd. And the owner of TiDB will exitwatchOwner
function, and TiDB cluster will start a new election byelec.Campaign
.Check List
Tests
use ansible to start a new cluster with two tidb instances. Run
curl http://{TiDBIP}:10080/ddl/owner/resign
in non-owner will responseThis node is not a ddl owner, can't be resigned.
, and the owner will return"success!"
.And use
select tidb_is_ddl_owner
, we can find out the owner of the tidb is transferred to the other instance.Code changes
Side effects
Related changes