rbd: log the remote site details during resync

logging the remote site details during resyncing
for better debugging.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit b92a6f5ccb)
This commit is contained in:
Madhu Rajanna 2021-10-25 15:58:37 +05:30 committed by mergify[bot]
parent c41bf37b95
commit ca4bf66035

View File

@ -43,18 +43,6 @@ const (
imageMirrorModeSnapshot imageMirroringMode = "snapshot" imageMirrorModeSnapshot imageMirroringMode = "snapshot"
) )
// imageMirroringState represents the image mirroring state.
type imageMirroringState string
const (
// If the state is unknown means the rbd-mirror daemon is
// running and the image is demoted on both the clusters.
unknown imageMirroringState = "unknown"
// If the state is error means image need resync.
errorState imageMirroringState = "error"
)
const ( const (
// mirroringMode + key to get the imageMirroringMode from parameters. // mirroringMode + key to get the imageMirroringMode from parameters.
imageMirroringKey = "mirroringMode" imageMirroringKey = "mirroringMode"
@ -523,8 +511,6 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
func checkRemoteSiteStatus(ctx context.Context, mirrorStatus *librbd.GlobalMirrorImageStatus) bool { func checkRemoteSiteStatus(ctx context.Context, mirrorStatus *librbd.GlobalMirrorImageStatus) bool {
ready := true ready := true
for _, s := range mirrorStatus.SiteStatuses { for _, s := range mirrorStatus.SiteStatuses {
if s.MirrorUUID != "" {
if imageMirroringState(s.State.String()) != unknown && !s.Up {
util.UsefulLog( util.UsefulLog(
ctx, ctx,
"peer site mirrorUUID=%s, mirroring state=%s, description=%s and lastUpdate=%s", "peer site mirrorUUID=%s, mirroring state=%s, description=%s and lastUpdate=%s",
@ -532,7 +518,8 @@ func checkRemoteSiteStatus(ctx context.Context, mirrorStatus *librbd.GlobalMirro
s.State.String(), s.State.String(),
s.Description, s.Description,
s.LastUpdate) s.LastUpdate)
if s.MirrorUUID != "" {
if s.State != librbd.MirrorImageStatusStateUnknown && !s.Up {
ready = false ready = false
} }
} }
@ -619,7 +606,16 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
return nil, fmt.Errorf("failed to get local status: %w", err) return nil, fmt.Errorf("failed to get local status: %w", err)
} }
state := imageMirroringState(localStatus.State.String())
// convert the last update time to UTC
lastUpdateTime := time.Unix(localStatus.LastUpdate, 0).UTC()
util.UsefulLog(
ctx,
"local image mirroring state=%s, description=%s and lastUpdate=%s",
localStatus.State.String(),
localStatus.Description,
lastUpdateTime)
// To recover from split brain (up+error) state the image need to be // To recover from split brain (up+error) state the image need to be
// demoted and requested for resync on site-a and then the image on site-b // demoted and requested for resync on site-a and then the image on site-b
// should be demoted. The volume should be marked to ready=true when the // should be demoted. The volume should be marked to ready=true when the
@ -630,17 +626,9 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
// If the image state on both the sites are up+unknown consider that // If the image state on both the sites are up+unknown consider that
// complete data is synced as the last snapshot // complete data is synced as the last snapshot
// gets exchanged between the clusters. // gets exchanged between the clusters.
if state == unknown && localStatus.Up { if localStatus.State == librbd.MirrorImageStatusStateUnknown && localStatus.Up {
ready = checkRemoteSiteStatus(ctx, mirrorStatus) ready = checkRemoteSiteStatus(ctx, mirrorStatus)
} }
// convert the last update time to UTC
lastUpdateTime := time.Unix(localStatus.LastUpdate, 0).UTC()
util.UsefulLog(
ctx,
"image mirroring state=%s, description=%s and lastUpdate=%s",
localStatus.State.String(),
localStatus.Description,
lastUpdateTime)
if resyncRequired(localStatus) { if resyncRequired(localStatus) {
err = rbdVol.resyncImage() err = rbdVol.resyncImage()
@ -696,7 +684,7 @@ func resyncRequired(localStatus librbd.SiteMirrorImageStatus) bool {
// be in an error state. It would be also worth considering the `description` // be in an error state. It would be also worth considering the `description`
// field to make sure about split-brain. // field to make sure about split-brain.
splitBrain := "split-brain" splitBrain := "split-brain"
if strings.Contains(localStatus.State.String(), string(errorState)) || if localStatus.State == librbd.MirrorImageStatusStateError ||
strings.Contains(localStatus.Description, splitBrain) { strings.Contains(localStatus.Description, splitBrain) {
return true return true
} }