本文整理匯總了Golang中github.com/NetSys/quilt/db.Conn.SelectFromEtcd方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.SelectFromEtcd方法的具體用法?Golang Conn.SelectFromEtcd怎麽用?Golang Conn.SelectFromEtcd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NetSys/quilt/db.Conn
的用法示例。
在下文中一共展示了Conn.SelectFromEtcd方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: campaign
func campaign(conn db.Conn, store Store) {
watch := store.Watch(leaderKey, 1*time.Second)
trigg := conn.TriggerTick(electionTTL/2, db.EtcdTable)
oldMaster := false
for {
select {
case <-watch:
case <-trigg.C:
}
etcdRows := conn.SelectFromEtcd(nil)
minion, err := conn.MinionSelf()
master := err == nil && minion.Role == db.Master && len(etcdRows) == 1
if !master {
if oldMaster {
commitLeader(conn, false, "")
}
continue
}
IP := minion.PrivateIP
if IP == "" {
continue
}
ttl := electionTTL * time.Second
if etcdRows[0].Leader {
err = store.Update(leaderKey, IP, ttl)
} else {
err = store.Create(leaderKey, IP, ttl)
}
if err == nil {
commitLeader(conn, true, IP)
} else {
clientErr, ok := err.(client.Error)
if !ok || clientErr.Code != client.ErrorCodeNodeExist {
log.WithError(err).Warn("Error setting leader key")
commitLeader(conn, false, "")
// Give things a chance to settle down.
time.Sleep(electionTTL * time.Second)
} else {
commitLeader(conn, false)
}
}
}
}