Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions pkg/ccr/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,8 @@ func NewJobFromService(name string, ctx context.Context) (*Job, error) {
return nil, xerror.Errorf(xerror.Normal, "invalid replication_num: %d, must be -1 (inherit) or > 0 (fixed)", job.ReplicationNum)
}
if job.ReplicationNum > 0 {
backs, err := job.destMeta.GetBackends()
if err != nil {
return nil, xerror.Wrap(err, xerror.Normal, "get dest backends failed")
}
if len(backs) == 0 {
return nil, xerror.Errorf(xerror.Normal, "no available backends in dest cluster")
}
if job.ReplicationNum > len(backs) {
return nil, xerror.Errorf(xerror.Normal, "replication %d exceeds available BE %d", job.ReplicationNum, len(backs))
if err := job.validateReplicaFail(job.ReplicationNum); err != nil {
return nil, err
}
}

Expand Down
44 changes: 19 additions & 25 deletions pkg/ccr/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,42 +615,36 @@ func (m *Meta) GetFrontends() ([]*base.Frontend, error) {
}

func (m *Meta) GetBackends() ([]*base.Backend, error) {
if len(m.Backends) > 0 {
backends := make([]*base.Backend, 0, len(m.Backends))
for _, backend := range m.Backends {
backend := *backend // copy
backends = append(backends, &backend)
}
if len(m.HostMapping) != 0 {
for _, backend := range backends {
if host, ok := m.HostMapping[backend.Host]; ok {
backend.Host = host
} else {
return nil, xerror.Errorf(xerror.Normal,
"the public ip of host %s is not found, consider adding it via HTTP API /add_host_mapping", backend.Host)
}
}
}
return backends, nil
}

// Always fetch latest backend information from FE
if err := m.UpdateBackends(); err != nil {
return nil, err
}

return m.GetBackends()
backends := make([]*base.Backend, 0, len(m.Backends))
for _, backend := range m.Backends {
backend := *backend // copy
backends = append(backends, &backend)
}
if len(m.HostMapping) != 0 {
for _, backend := range backends {
if host, ok := m.HostMapping[backend.Host]; ok {
backend.Host = host
} else {
return nil, xerror.Errorf(xerror.Normal,
"the public ip of host %s is not found, consider adding it via HTTP API /add_host_mapping", backend.Host)
}
}
}
return backends, nil
}

func (m *Meta) GetBackendMap() (map[int64]*base.Backend, error) {
if len(m.Backends) > 0 {
return m.Backends, nil
}

// Always fetch latest backend information from FE
if err := m.UpdateBackends(); err != nil {
return nil, err
}

return m.GetBackendMap()
return m.Backends, nil
}

func (m *Meta) GetBackendId(host string, portStr string) (int64, error) {
Expand Down
Loading