Skip to content

Commit

Permalink
grpc-proxy: fix backup
Browse files Browse the repository at this point in the history
Longhorn-3546

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and innobead committed May 16, 2022
1 parent ae762d0 commit ca4a9dd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/proxy/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (p *Proxy) SnapshotBackupStatus(ctx context.Context, req *rpc.EngineSnapsho
return nil, err
}

status := &esync.BackupStatusInfo{}
replicaAddress := req.ReplicaAddress
if replicaAddress == "" {
// find a replica which has the corresponding backup
Expand All @@ -106,11 +105,10 @@ func (p *Proxy) SnapshotBackupStatus(ctx context.Context, req *rpc.EngineSnapsho
continue
}

fetched, err := esync.FetchBackupStatus(cReplica, req.BackupName, r.Address.Address)
_, err = esync.FetchBackupStatus(cReplica, req.BackupName, r.Address.Address)
cReplica.Close()
if err == nil {
replicaAddress = r.Address.Address
status = fetched
break
}
}
Expand All @@ -120,6 +118,27 @@ func (p *Proxy) SnapshotBackupStatus(ctx context.Context, req *rpc.EngineSnapsho
return nil, errors.Errorf("failed to find a replica with backup %s", req.BackupName)
}

for _, r := range replicas.ReplicaList.Replicas {
if r.Address.Address != replicaAddress {
continue
}
mode := eptypes.GRPCReplicaModeToReplicaMode(r.Mode)
if mode != etypes.RW {
return nil, errors.Errorf("failed to get % v backup status on unknown replica %s", req.BackupName, replicaAddress)
}
}

cReplica, err := rclient.NewReplicaClient(replicaAddress)
if err != nil {
return nil, errors.Wrapf(err, "Failed to create replica client with %v", replicaAddress)
}
defer cReplica.Close()

status, err := esync.FetchBackupStatus(cReplica, req.BackupName, replicaAddress)
if err != nil {
return nil, err
}

return &rpc.EngineSnapshotBackupStatusProxyResponse{
BackupUrl: status.BackupURL,
Error: status.Error,
Expand Down

0 comments on commit ca4a9dd

Please sign in to comment.