rbd: discard up+unknown state in ResyncVolume

incase if the image is promoted and demoted the
image state will be set to up+unknown if the image
on the remote cluster is still in demoted state.

when user changes the state from primary to secondary
and still the image is in demoted (secondary) state
in the remote cluster. the image state on both the cluster
will be on unknown state.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-04-15 12:25:24 +05:30 committed by Humble Devassy Chirammal
parent 31634ede3d
commit cfc88c9910

View File

@ -52,6 +52,10 @@ const (
// another cluster // another cluster
upAndStopped imageMirroringState = "up+stopped" upAndStopped imageMirroringState = "up+stopped"
// If the state is up+unknown means the rbd-mirror daemon is
// running and the image is demoted on both the clusters.
upAndUnknown imageMirroringState = "up+unknown"
// If the state is error means image need resync. // If the state is error means image need resync.
errorState imageMirroringState = "error" errorState imageMirroringState = "error"
) )
@ -375,6 +379,8 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
// ResyncVolume extracts the RBD volume information from the volumeID, If the // ResyncVolume extracts the RBD volume information from the volumeID, If the
// image is present, mirroring is enabled and the image is in demoted state. // image is present, mirroring is enabled and the image is in demoted state.
// If yes it will resync the image to correct the split-brain. // If yes it will resync the image to correct the split-brain.
// nolint:gocyclo // reduce complexity
// FIXME: reduce complexity.
func (rs *ReplicationServer) ResyncVolume(ctx context.Context, func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
req *replication.ResyncVolumeRequest, req *replication.ResyncVolumeRequest,
) (*replication.ResyncVolumeResponse, error) { ) (*replication.ResyncVolumeResponse, error) {
@ -444,7 +450,20 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
ready = true ready = true
for _, s := range mirrorStatus.PeerSites { for _, s := range mirrorStatus.PeerSites {
if imageMirroringState(s.State) != upAndStopped { if imageMirroringState(s.State) != upAndStopped {
util.UsefulLog(ctx, "peer site name=%s mirroring state=%s, description=%s and lastUpdate=%s", s.SiteName, s.State, s.Description, s.LastUpdate) util.UsefulLog(ctx, "peer site name=%s, mirroring state=%s, description=%s and lastUpdate=%s", s.SiteName, s.State, s.Description, s.LastUpdate)
ready = false
}
}
}
// when the images are demoted on both clusters and user requests for the
// resync of the image, the image mirror state will be unknown state in
// both clusters.
if state == upAndUnknown {
ready = true
for _, s := range mirrorStatus.PeerSites {
if imageMirroringState(s.State) != upAndUnknown {
util.UsefulLog(ctx, "peer site name=%s, mirroring state=%s, description=%s and lastUpdate=%s", s.SiteName, s.State, s.Description, s.LastUpdate)
ready = false ready = false
} }
} }