提交 37d3cf19 编写于 作者: P Philipp Heckel

Re-read replica instance to ensure they are up-to-date (races with

InstancePollSeconds)
上级 9bc50948
......@@ -204,6 +204,20 @@ func ReadTopologyInstance(instanceKey *InstanceKey) (*Instance, error) {
return ReadTopologyInstanceBufferable(instanceKey, false, nil)
}
// ReadTopologyInstances is a convenience method that calls ReadTopologyInstance
// for all the instance keys and returns a slice of Instance.
func ReadTopologyInstances(instanceKeys []InstanceKey) ([]*Instance, error) {
instances := make([]*Instance, 0)
for _, replicaKey := range instanceKeys {
replica, err := ReadTopologyInstance(&replicaKey)
if err != nil {
return nil, err
}
instances = append(instances, replica)
}
return instances, nil
}
func RetryInstanceFunction(f func() (*Instance, error)) (instance *Instance, err error) {
for i := 0; i < retryInstanceFunctionCount; i++ {
if instance, err = f(); err == nil {
......
......@@ -644,14 +644,17 @@ func maybeEnableSemiSyncReplicaLegacy(replicaInstance *Instance) (*Instance, err
// AnalyzeSemiSyncReplicaTopology analyzes the replica topology for the given master and determines actions for the semi-sync replica enabled
// variable. It does not take any action itself.
func AnalyzeSemiSyncReplicaTopology(masterKey *InstanceKey, includeNonReplicatingInstance *InstanceKey, exactReplicaTopology bool) (masterInstance *Instance, replicas []*Instance, actions map[*Instance]bool, err error) {
// Read entire topology of master and its replicas
// Read entire topology of master and its replicas to ensure we have the most up-to-date information
masterInstance, err = ReadTopologyInstance(masterKey)
if err != nil {
return nil, nil, nil, err
}
replicas, err = ReadReplicaInstances(masterKey)
replicas, err = ReadTopologyInstances(masterInstance.Replicas.GetInstanceKeys())
if err != nil {
return nil, nil, nil, err
replicas, err = ReadReplicaInstances(masterKey) // Falling back to just reading from our backend
if err != nil {
return nil, nil, nil, err
}
}
// Classify and prioritize replicas & figure out which replicas need to be acted upon
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册