mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-31 00:59:30 +00:00
ci: extra commit will be dropped
This is extra commit will be dropped Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
a5c129dbe9
commit
0dad176296
@ -876,6 +876,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, "failed to get remote site status for mirror %q: %v", mirror, err)
|
||||
@ -899,6 +900,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
|
||||
}
|
||||
|
||||
@ -923,7 +925,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)
|
||||
@ -940,6 +942,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 {
|
||||
@ -965,6 +968,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
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,10 @@ package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
@ -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,
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
75
vendor/github.com/ceph/go-ceph/rbd/mirror_group.go
generated
vendored
75
vendor/github.com/ceph/go-ceph/rbd/mirror_group.go
generated
vendored
@ -7,6 +7,7 @@ package rbd
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
@ -156,11 +157,19 @@ func GetMirrorGroupInfo(groupIoctx *rados.IOContext, groupName string) (*MirrorG
|
||||
cGroupName,
|
||||
&cgInfo,
|
||||
C.sizeof_rbd_mirror_group_info_t)
|
||||
|
||||
var err error
|
||||
if ret < 0 {
|
||||
return nil, getError(ret)
|
||||
err = getError(ret)
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrNotFound) || errors.Is(err, rados.RadosErrorNotFound) {
|
||||
return &MirrorGroupInfo{
|
||||
State: MirrorGroupDisabled,
|
||||
MirrorImageMode: ImageMirrorModeSnapshot,
|
||||
Primary: false,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
info := convertMirrorGroupInfo(&cgInfo)
|
||||
|
||||
// free C memory allocated by C.rbd_mirror_group_get_info call
|
||||
@ -279,31 +288,39 @@ func GetGlobalMirrorGroupStatus(ioctx *rados.IOContext, groupName string) (Globa
|
||||
s := C.rbd_mirror_group_global_status_t{}
|
||||
cGroupName := C.CString(groupName)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
// ret := C.rbd_mirror_group_get_global_status(
|
||||
// cephIoctx(ioctx),
|
||||
// (*C.char)(cGroupName),
|
||||
// &s,
|
||||
// C.sizeof_rbd_mirror_group_global_status_t)
|
||||
// if err := getError(ret); err != nil {
|
||||
// return GlobalMirrorGroupStatus{}, err
|
||||
// }
|
||||
ret := C.rbd_mirror_group_get_global_status(
|
||||
cephIoctx(ioctx),
|
||||
(*C.char)(cGroupName),
|
||||
&s,
|
||||
C.sizeof_rbd_mirror_group_global_status_t)
|
||||
if err := getError(ret); err != nil {
|
||||
return GlobalMirrorGroupStatus{}, err
|
||||
}
|
||||
|
||||
status := newGlobalMirrorGroupStatus(&s)
|
||||
return status, nil
|
||||
}
|
||||
|
||||
func newGlobalMirrorGroupStatus(
|
||||
s *C.rbd_mirror_group_global_status_t) GlobalMirrorGroupStatus {
|
||||
|
||||
func newGlobalMirrorGroupStatus(s *C.rbd_mirror_group_global_status_t) GlobalMirrorGroupStatus {
|
||||
// Initializing the status object
|
||||
status := GlobalMirrorGroupStatus{
|
||||
Name: C.GoString(s.name),
|
||||
Info: convertMirrorGroupInfo(&s.info),
|
||||
SiteStatusesCount: int(s.site_statuses_count),
|
||||
SiteStatuses: make([]SiteMirrorGroupStatus, s.site_statuses_count),
|
||||
}
|
||||
|
||||
// Print the count of site statuses for debugging
|
||||
fmt.Println("status.SiteStatusesCount: ", s.site_statuses_count)
|
||||
|
||||
fmt.Printf("s.site_statuses: %+v\n", s.site_statuses)
|
||||
// Check if site statuses are not null before using them
|
||||
if s.site_statuses != nil && s.site_statuses_count > 0 {
|
||||
gsscs := (*groupSiteArray)(unsafe.Pointer(s.site_statuses))[:s.site_statuses_count:s.site_statuses_count]
|
||||
for i := C.uint32_t(0); i < s.site_statuses_count; i++ {
|
||||
gss := gsscs[i]
|
||||
// Ensure that fields are valid before using them
|
||||
if gss.mirror_uuid != nil && gss.mirror_image_global_ids != nil {
|
||||
status.SiteStatuses[i] = SiteMirrorGroupStatus{
|
||||
MirrorUUID: C.GoString(gss.mirror_uuid),
|
||||
MirrorImageGlobalIDs: C.GoString(*gss.mirror_image_global_ids),
|
||||
@ -316,17 +333,41 @@ func newGlobalMirrorGroupStatus(
|
||||
Up: bool(gss.up),
|
||||
}
|
||||
|
||||
// Check if the mirror_images pointer is valid
|
||||
if gss.mirror_images != nil && gss.mirror_image_count > 0 {
|
||||
|
||||
sscs := (*siteArray)(unsafe.Pointer(gss.mirror_images))[:gss.mirror_image_count:gss.mirror_image_count]
|
||||
for i := C.uint32_t(0); i < gss.mirror_image_count; i++ {
|
||||
ss := sscs[i]
|
||||
status.SiteStatuses[i].MirrorImages[i] = SiteMirrorImageStatus{
|
||||
fmt.Printf("sscs: siteArray %+v\n", sscs)
|
||||
for j := C.uint32_t(0); j < gss.mirror_image_count; j++ {
|
||||
ss := sscs[j]
|
||||
|
||||
// Ensure that fields are valid before using them
|
||||
if ss.mirror_uuid != nil {
|
||||
status.SiteStatuses[i].MirrorImages[j] = SiteMirrorImageStatus{
|
||||
MirrorUUID: C.GoString(ss.mirror_uuid),
|
||||
State: MirrorImageStatusState(ss.state),
|
||||
Description: C.GoString(ss.description),
|
||||
LastUpdate: int64(ss.last_update),
|
||||
Up: bool(ss.up),
|
||||
}
|
||||
} else {
|
||||
// Log if a field is invalid
|
||||
fmt.Println("Warning: mirror_uuid is nil at index", i, j)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Handle case where mirror_images is nil or mirror_image_count is 0
|
||||
fmt.Println("Warning: mirror_images is nil or mirror_image_count is 0 at index", i)
|
||||
}
|
||||
} else {
|
||||
// Handle case where mirror_uuid or mirror_image_global_ids is nil
|
||||
fmt.Println("Warning: mirror_uuid or mirror_image_global_ids is nil at index", i)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Handle case where site statuses are nil or count is 0
|
||||
fmt.Println("Warning: site_statuses is nil or site_statuses_count is 0")
|
||||
}
|
||||
// Return the populated status
|
||||
return status
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user