本文整理匯總了Golang中github.com/pingcap/tidb/meta.Meta.SetDDLOwner方法的典型用法代碼示例。如果您正苦於以下問題:Golang Meta.SetDDLOwner方法的具體用法?Golang Meta.SetDDLOwner怎麽用?Golang Meta.SetDDLOwner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/meta.Meta
的用法示例。
在下文中一共展示了Meta.SetDDLOwner方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkOwner
func (d *ddl) checkOwner(t *meta.Meta) (*model.Owner, error) {
owner, err := t.GetDDLOwner()
if err != nil {
return nil, errors.Trace(err)
}
if owner == nil {
owner = &model.Owner{}
// try to set onwer
owner.OwnerID = d.uuid
}
now := time.Now().UnixNano()
// we must wait 2 * lease time to guarantee other servers update the schema,
// the owner will update its owner status every 2 * lease time, so here we use
// 4 * lease to check its timeout.
maxTimeout := int64(4 * d.lease)
if owner.OwnerID == d.uuid || now-owner.LastUpdateTS > maxTimeout {
owner.OwnerID = d.uuid
owner.LastUpdateTS = now
// update status.
if err = t.SetDDLOwner(owner); err != nil {
return nil, errors.Trace(err)
}
log.Debugf("become owner %s", owner.OwnerID)
}
if owner.OwnerID != d.uuid {
log.Debugf("not owner, owner is %s", owner.OwnerID)
return nil, errors.Trace(ErrNotOwner)
}
return owner, nil
}
示例2: verifyOwner
func (d *ddl) verifyOwner(t *meta.Meta) error {
owner, err := t.GetDDLOwner()
if err != nil {
return errors.Trace(err)
}
if owner == nil {
owner = &model.Owner{}
// try to set onwer
owner.OwnerID = d.uuid
}
now := time.Now().Unix()
maxTimeout := int64(4 * d.lease)
if owner.OwnerID == d.uuid || now-owner.LastUpdateTS > maxTimeout {
owner.OwnerID = d.uuid
owner.LastUpdateTS = now
// update or try to set itself as owner.
if err = t.SetDDLOwner(owner); err != nil {
return errors.Trace(err)
}
}
if owner.OwnerID != d.uuid {
return errors.Trace(ErrNotOwner)
}
return nil
}