Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: refactor mirroring to work with volume and volumegroup #4720

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions internal/rbd/types/mirror.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2024 The Ceph-CSI Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package types

import (
"context"
"time"

"github.com/ceph/ceph-csi/internal/util"

librbd "github.com/ceph/go-ceph/rbd"
"github.com/ceph/go-ceph/rbd/admin"
)

// FlattenMode is used to indicate the flatten mode for an RBD image.
type FlattenMode string

const (
// FlattenModeNever indicates that the image should never be flattened.
FlattenModeNever FlattenMode = "never"
// FlattenModeForce indicates that the image with the parent must be flattened.
FlattenModeForce FlattenMode = "force"
)

// Mirror is the interface for managing mirroring on an RBD image or a group.
type Mirror interface {
Madhu-1 marked this conversation as resolved.
Show resolved Hide resolved
Madhu-1 marked this conversation as resolved.
Show resolved Hide resolved
// EnableMirroring enables mirroring on the resource with the specified mode.
EnableMirroring(mode librbd.ImageMirrorMode) error
// DisableMirroring disables mirroring on the resource with the option to force the operation
DisableMirroring(force bool) error
// Promote promotes the resource to primary status with the option to force the operation
Promote(force bool) error
// ForcePromote promotes the resource to primary status with a timeout
ForcePromote(cr *util.Credentials) error
// Demote demotes the resource to secondary status
Demote() error
// Resync resynchronizes the resource
Resync() error
// GetMirroringInfo returns the mirroring information of the resource
GetMirroringInfo() (MirrorInfo, error)
// GetMirroringInfo returns the mirroring information of the resource
GetGlobalMirroringStatus() (GlobalStatus, error)
// AddSnapshotScheduling adds a snapshot scheduling to the resource
AddSnapshotScheduling(interval admin.Interval, startTime admin.StartTime) error
}

// MirrorImage is the interface for managing mirroring on an RBD image or group of images.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// MirrorImage is the interface for managing mirroring on an RBD image or group of images.
// MirrorInfo is the interface for managing mirroring on an RBD image or group of images.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address this in follow up. Thanks @Madhu-1 for catching it.

// This will be used to get the state of resource and it is primary or secondary.
type MirrorInfo interface {
nixpanic marked this conversation as resolved.
Show resolved Hide resolved
// IsPrimary returns true if the resource is primary
IsPrimary() bool
// GetState returns the state of the resource
GetState() string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding a MirrorState type to replace the string value

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs more work, will take it in next update when implementing this for group

}

// GlobalStatus is the interface for fetching the global status of the mirroring.
// This will be used to get the status of the local site and remote site or all sites.
type GlobalStatus interface {
MirrorInfo
// GetLocalSiteStatus returns the local site status
GetLocalSiteStatus() (SiteStatus, error)
// GetAllSitesStatus returns the status of all sites
GetAllSitesStatus() []SiteStatus
// GetRemoteSiteStatus returns the status of the remote site
GetRemoteSiteStatus(ctx context.Context) (SiteStatus, error)
}

// SiteStatus is the interface for fetching the status of a site.
// This will be used to get the status of the local site and remote site.
type SiteStatus interface {
// GetMirrorUUID returns the mirror UUID
GetMirrorUUID() string
// IsUP returns true if the site is up
IsUP() bool
// GetState returns the state of the site
GetState() string
// GetDescription returns the description of the site
GetDescription() string
// GetLastUpdate returns the last update time
GetLastUpdate() time.Time
}