mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-02-12 05:49:29 +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())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.DebugLog(ctx, "mirrorStatus: %+v", mirrorStatus)
|
||||||
remoteStatus, err := mirrorStatus.GetRemoteSiteStatus(ctx)
|
remoteStatus, err := mirrorStatus.GetRemoteSiteStatus(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to get remote site status for mirror %q: %v", mirror, err)
|
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)
|
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
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -923,7 +925,7 @@ func getLastSyncInfo(ctx context.Context, description string) (*replication.GetV
|
|||||||
if description == "" {
|
if description == "" {
|
||||||
return nil, fmt.Errorf("empty description: %w", corerbd.ErrLastSyncTimeNotFound)
|
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)
|
splittedString := strings.SplitN(description, ",", 2)
|
||||||
if len(splittedString) == 1 {
|
if len(splittedString) == 1 {
|
||||||
return nil, fmt.Errorf("no snapshot details: %w", corerbd.ErrLastSyncTimeNotFound)
|
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)
|
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
|
// 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.
|
// need to consider it as an error as the LastSyncTime is required.
|
||||||
if localSnapInfo.LocalSnapshotTime == 0 {
|
if localSnapInfo.LocalSnapshotTime == 0 {
|
||||||
@ -965,6 +968,7 @@ func getLastSyncInfo(ctx context.Context, description string) (*replication.GetV
|
|||||||
response.LastSyncTime = lastSyncTime
|
response.LastSyncTime = lastSyncTime
|
||||||
response.LastSyncBytes = localSnapInfo.LastSnapshotBytes
|
response.LastSyncBytes = localSnapInfo.LastSnapshotBytes
|
||||||
|
|
||||||
|
log.DebugLog(ctx, "Madhu the return response is %v", response)
|
||||||
return &response, nil
|
return &response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,10 @@ package group
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ceph/go-ceph/rados"
|
"github.com/ceph/go-ceph/rados"
|
||||||
@ -279,6 +281,12 @@ func (status globalMirrorGroupStatus) GetRemoteSiteStatus(ctx context.Context) (
|
|||||||
err error = librbd.ErrNotExist
|
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 {
|
for i := range status.SiteStatuses {
|
||||||
log.DebugLog(
|
log.DebugLog(
|
||||||
ctx,
|
ctx,
|
||||||
@ -291,8 +299,53 @@ func (status globalMirrorGroupStatus) GetRemoteSiteStatus(ctx context.Context) (
|
|||||||
|
|
||||||
if status.SiteStatuses[i].MirrorUUID != "" {
|
if status.SiteStatuses[i].MirrorUUID != "" {
|
||||||
ss = status.SiteStatuses[i]
|
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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
115
vendor/github.com/ceph/go-ceph/rbd/mirror_group.go
generated
vendored
115
vendor/github.com/ceph/go-ceph/rbd/mirror_group.go
generated
vendored
@ -7,6 +7,7 @@ package rbd
|
|||||||
// #include <rbd/librbd.h>
|
// #include <rbd/librbd.h>
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -156,11 +157,19 @@ func GetMirrorGroupInfo(groupIoctx *rados.IOContext, groupName string) (*MirrorG
|
|||||||
cGroupName,
|
cGroupName,
|
||||||
&cgInfo,
|
&cgInfo,
|
||||||
C.sizeof_rbd_mirror_group_info_t)
|
C.sizeof_rbd_mirror_group_info_t)
|
||||||
|
var err error
|
||||||
if ret < 0 {
|
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)
|
info := convertMirrorGroupInfo(&cgInfo)
|
||||||
|
|
||||||
// free C memory allocated by C.rbd_mirror_group_get_info call
|
// free C memory allocated by C.rbd_mirror_group_get_info call
|
||||||
@ -279,54 +288,86 @@ func GetGlobalMirrorGroupStatus(ioctx *rados.IOContext, groupName string) (Globa
|
|||||||
s := C.rbd_mirror_group_global_status_t{}
|
s := C.rbd_mirror_group_global_status_t{}
|
||||||
cGroupName := C.CString(groupName)
|
cGroupName := C.CString(groupName)
|
||||||
defer C.free(unsafe.Pointer(cGroupName))
|
defer C.free(unsafe.Pointer(cGroupName))
|
||||||
// ret := C.rbd_mirror_group_get_global_status(
|
ret := C.rbd_mirror_group_get_global_status(
|
||||||
// cephIoctx(ioctx),
|
cephIoctx(ioctx),
|
||||||
// (*C.char)(cGroupName),
|
(*C.char)(cGroupName),
|
||||||
// &s,
|
&s,
|
||||||
// C.sizeof_rbd_mirror_group_global_status_t)
|
C.sizeof_rbd_mirror_group_global_status_t)
|
||||||
// if err := getError(ret); err != nil {
|
if err := getError(ret); err != nil {
|
||||||
// return GlobalMirrorGroupStatus{}, err
|
return GlobalMirrorGroupStatus{}, err
|
||||||
// }
|
}
|
||||||
|
|
||||||
status := newGlobalMirrorGroupStatus(&s)
|
status := newGlobalMirrorGroupStatus(&s)
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGlobalMirrorGroupStatus(
|
func newGlobalMirrorGroupStatus(s *C.rbd_mirror_group_global_status_t) GlobalMirrorGroupStatus {
|
||||||
s *C.rbd_mirror_group_global_status_t) GlobalMirrorGroupStatus {
|
// Initializing the status object
|
||||||
|
|
||||||
status := GlobalMirrorGroupStatus{
|
status := GlobalMirrorGroupStatus{
|
||||||
Name: C.GoString(s.name),
|
Name: C.GoString(s.name),
|
||||||
Info: convertMirrorGroupInfo(&s.info),
|
Info: convertMirrorGroupInfo(&s.info),
|
||||||
SiteStatusesCount: int(s.site_statuses_count),
|
SiteStatusesCount: int(s.site_statuses_count),
|
||||||
SiteStatuses: make([]SiteMirrorGroupStatus, s.site_statuses_count),
|
SiteStatuses: make([]SiteMirrorGroupStatus, s.site_statuses_count),
|
||||||
}
|
}
|
||||||
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]
|
|
||||||
status.SiteStatuses[i] = SiteMirrorGroupStatus{
|
|
||||||
MirrorUUID: C.GoString(gss.mirror_uuid),
|
|
||||||
MirrorImageGlobalIDs: C.GoString(*gss.mirror_image_global_ids),
|
|
||||||
MirrorImagePoolIDs: int64(*gss.mirror_image_pool_ids),
|
|
||||||
State: MirrorGroupStatusState(gss.state),
|
|
||||||
Description: C.GoString(gss.description),
|
|
||||||
MirrorImageCount: int(gss.mirror_image_count),
|
|
||||||
LastUpdate: int64(gss.last_update),
|
|
||||||
MirrorImages: make([]SiteMirrorImageStatus, gss.mirror_image_count),
|
|
||||||
Up: bool(gss.up),
|
|
||||||
}
|
|
||||||
|
|
||||||
sscs := (*siteArray)(unsafe.Pointer(gss.mirror_images))[:gss.mirror_image_count:gss.mirror_image_count]
|
// Print the count of site statuses for debugging
|
||||||
for i := C.uint32_t(0); i < gss.mirror_image_count; i++ {
|
fmt.Println("status.SiteStatusesCount: ", s.site_statuses_count)
|
||||||
ss := sscs[i]
|
|
||||||
status.SiteStatuses[i].MirrorImages[i] = SiteMirrorImageStatus{
|
fmt.Printf("s.site_statuses: %+v\n", s.site_statuses)
|
||||||
MirrorUUID: C.GoString(ss.mirror_uuid),
|
// Check if site statuses are not null before using them
|
||||||
State: MirrorImageStatusState(ss.state),
|
if s.site_statuses != nil && s.site_statuses_count > 0 {
|
||||||
Description: C.GoString(ss.description),
|
gsscs := (*groupSiteArray)(unsafe.Pointer(s.site_statuses))[:s.site_statuses_count:s.site_statuses_count]
|
||||||
LastUpdate: int64(ss.last_update),
|
for i := C.uint32_t(0); i < s.site_statuses_count; i++ {
|
||||||
Up: bool(ss.up),
|
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),
|
||||||
|
MirrorImagePoolIDs: int64(*gss.mirror_image_pool_ids),
|
||||||
|
State: MirrorGroupStatusState(gss.state),
|
||||||
|
Description: C.GoString(gss.description),
|
||||||
|
MirrorImageCount: int(gss.mirror_image_count),
|
||||||
|
LastUpdate: int64(gss.last_update),
|
||||||
|
MirrorImages: make([]SiteMirrorImageStatus, gss.mirror_image_count),
|
||||||
|
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]
|
||||||
|
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
|
return status
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user