Skip to content

Commit

Permalink
ci: extra commit will be dropped
Browse files Browse the repository at this point in the history
This is extra commit will be dropped

Signed-off-by: Madhu Rajanna <[email protected]>
  • Loading branch information
Madhu-1 committed Jan 13, 2025
1 parent 03da49a commit 6e5f2b7
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 39 deletions.
6 changes: 5 additions & 1 deletion internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
return nil, status.Error(codes.Internal, err.Error())
}

log.DebugLog(ctx, "mirrorStatus: %+v", mirrorStatus)
remoteStatus, err := mirrorStatus.GetRemoteSiteStatus(ctx)
if err != nil {
log.ErrorLog(ctx, err.Error())
Expand All @@ -877,6 +878,7 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
return nil, status.Errorf(codes.Internal, "failed to get last sync info: %v", err)
}

log.DebugLog(ctx, "Madhu the response is %v", resp)
return resp, nil
}

Expand All @@ -901,7 +903,7 @@ func getLastSyncInfo(ctx context.Context, description string) (*replication.GetV
if description == "" {
return nil, fmt.Errorf("empty description: %w", corerbd.ErrLastSyncTimeNotFound)
}
log.DebugLog(ctx, "description: %s", description)
log.DebugLog(ctx, "Madhu description: %s", description)
splittedString := strings.SplitN(description, ",", 2)
if len(splittedString) == 1 {
return nil, fmt.Errorf("no snapshot details: %w", corerbd.ErrLastSyncTimeNotFound)
Expand All @@ -918,6 +920,7 @@ func getLastSyncInfo(ctx context.Context, description string) (*replication.GetV
return nil, fmt.Errorf("failed to unmarshal local snapshot info: %w", err)
}

log.DebugLog(ctx, "Madhu the description after unmarshalling is %v", localSnapInfo)
// If the json unmarsal is successful but the local snapshot time is 0, we
// need to consider it as an error as the LastSyncTime is required.
if localSnapInfo.LocalSnapshotTime == 0 {
Expand All @@ -943,6 +946,7 @@ func getLastSyncInfo(ctx context.Context, description string) (*replication.GetV
response.LastSyncTime = lastSyncTime
response.LastSyncBytes = localSnapInfo.LastSnapshotBytes

log.DebugLog(ctx, "Madhu the return response is %v", response)
return &response, nil
}

Expand Down
55 changes: 54 additions & 1 deletion internal/rbd/group/group_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ package group

import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"time"

"github.com/ceph/go-ceph/rados"
Expand Down Expand Up @@ -279,6 +281,12 @@ func (status globalMirrorGroupStatus) GetRemoteSiteStatus(ctx context.Context) (
err error = librbd.ErrNotExist
)

type localStatus struct {
LocalSnapshotTime int64 `json:"local_snapshot_timestamp"`
LastSnapshotBytes int64 `json:"last_snapshot_bytes"`
LastSnapshotDuration *int64 `json:"last_snapshot_sync_seconds"`
}

for i := range status.SiteStatuses {
log.DebugLog(
ctx,
Expand All @@ -291,8 +299,53 @@ func (status globalMirrorGroupStatus) GetRemoteSiteStatus(ctx context.Context) (

if status.SiteStatuses[i].MirrorUUID != "" {
ss = status.SiteStatuses[i]
err = nil

images := status.SiteStatuses[i].MirrorImages

totalSnpshotTime := int64(0)
totalSnapshotBytes := int64(0)
totalSnapshotDuration := int64(0)
totalImages := len(images)
for _, image := range images {
log.DebugLog(ctx, "Madhu image: %s, state: %s, description: %s, lastUpdate: %v, up: %t",
image.MirrorUUID,
image.State,
image.Description,
image.LastUpdate,
image.Up)
description := image.Description
log.DebugLog(ctx, "[Madhu] description: %s", description)
splittedString := strings.SplitN(description, ",", 2)
if len(splittedString) == 1 {
log.DebugLog(ctx, "no snapshot details", splittedString[0])
continue
}
var localSnapInfo localStatus
err := json.Unmarshal([]byte(splittedString[1]), &localSnapInfo)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal local snapshot info: %w", err)
}
log.DebugLog(ctx, "Madhu localStatus", localSnapInfo)
totalSnpshotTime += localSnapInfo.LocalSnapshotTime
totalSnapshotBytes += localSnapInfo.LastSnapshotBytes
totalSnapshotDuration += *localSnapInfo.LastSnapshotDuration
}
err = nil
totalDuration := int64(totalSnapshotDuration / int64(totalImages))
// write the total snapshot time, bytes and duration to the description
d := localStatus{
LocalSnapshotTime: int64(totalSnpshotTime / int64(totalImages)),
LastSnapshotBytes: int64(totalSnapshotBytes / int64(totalImages)),
LastSnapshotDuration: &totalDuration,
}
description, err := json.Marshal(d)
log.DebugLog(ctx, "description: %s", description)
log.DebugLog(ctx, "description: %v", d)
if err != nil {

return nil, fmt.Errorf("failed to marshal local snapshot info: %w", err)
}
ss.Description = fmt.Sprintf("%s, %s", ss.Description, description)
break
}
}
Expand Down
115 changes: 78 additions & 37 deletions vendor/github.com/ceph/go-ceph/rbd/mirror_group.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e5f2b7

Please sign in to comment.