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

cephfs: Log clone progress during a clone operation #4918

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 22 additions & 12 deletions internal/cephfs/core/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ import (

// cephFSCloneState describes the status of the clone.
type cephFSCloneState struct {
state admin.CloneState
errno string
errorMsg string
state admin.CloneState
progressReport admin.CloneProgressReport
errno string
errorMsg string
}

// CephFSCloneError indicates that fetching the clone state returned an error.
var CephFSCloneError = cephFSCloneState{}
var CephFSCloneError = &cephFSCloneState{}
Nikhil-Ladha marked this conversation as resolved.
Show resolved Hide resolved

// ToError checks the state of the clone if it's not cephFSCloneComplete.
func (cs cephFSCloneState) ToError() error {
func (cs *cephFSCloneState) ToError() error {
switch cs.state {
case admin.CloneComplete:
return nil
Expand All @@ -54,6 +55,14 @@ func (cs cephFSCloneState) ToError() error {
return nil
}

func (cs *cephFSCloneState) GetProgressReport() admin.CloneProgressReport {
return admin.CloneProgressReport{
Nikhil-Ladha marked this conversation as resolved.
Show resolved Hide resolved
PercentageCloned: cs.progressReport.PercentageCloned,
AmountCloned: cs.progressReport.AmountCloned,
FilesCloned: cs.progressReport.FilesCloned,
}
}

// CreateCloneFromSubvolume creates a clone from a subvolume.
func (s *subVolumeClient) CreateCloneFromSubvolume(
ctx context.Context,
Expand Down Expand Up @@ -87,7 +96,7 @@ func (s *subVolumeClient) CreateCloneFromSubvolume(
return err
}

var cloneState cephFSCloneState
var cloneState *cephFSCloneState
cloneState, err = s.GetCloneState(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to get clone state: %v", err)
Expand Down Expand Up @@ -157,7 +166,7 @@ func (s *subVolumeClient) CreateCloneFromSnapshot(
}
}
}()
var cloneState cephFSCloneState
var cloneState *cephFSCloneState
// avoid err variable shadowing
cloneState, err = s.GetCloneState(ctx)
if err != nil {
Expand All @@ -182,7 +191,7 @@ func (s *subVolumeClient) CreateCloneFromSnapshot(
}

// GetCloneState returns the clone state of the subvolume.
func (s *subVolumeClient) GetCloneState(ctx context.Context) (cephFSCloneState, error) {
func (s *subVolumeClient) GetCloneState(ctx context.Context) (*cephFSCloneState, error) {
fsa, err := s.conn.GetFSAdmin()
if err != nil {
log.ErrorLog(
Expand All @@ -209,10 +218,11 @@ func (s *subVolumeClient) GetCloneState(ctx context.Context) (cephFSCloneState,
errStr = failure.ErrStr
}

state := cephFSCloneState{
state: cs.State,
errno: errno,
errorMsg: errStr,
state := &cephFSCloneState{
state: cs.State,
progressReport: cs.ProgressReport,
errno: errno,
errorMsg: errStr,
}

return state, nil
Expand Down
10 changes: 5 additions & 5 deletions internal/cephfs/core/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
func TestCloneStateToError(t *testing.T) {
t.Parallel()
errorState := make(map[cephFSCloneState]error)
errorState[cephFSCloneState{fsa.CloneComplete, "", ""}] = nil
errorState[CephFSCloneError] = cerrors.ErrInvalidClone
errorState[cephFSCloneState{fsa.CloneInProgress, "", ""}] = cerrors.ErrCloneInProgress
errorState[cephFSCloneState{fsa.ClonePending, "", ""}] = cerrors.ErrClonePending
errorState[cephFSCloneState{fsa.CloneFailed, "", ""}] = cerrors.ErrCloneFailed
errorState[cephFSCloneState{fsa.CloneComplete, fsa.CloneProgressReport{}, "", ""}] = nil
errorState[*CephFSCloneError] = cerrors.ErrInvalidClone
errorState[cephFSCloneState{fsa.CloneInProgress, fsa.CloneProgressReport{}, "", ""}] = cerrors.ErrCloneInProgress
errorState[cephFSCloneState{fsa.ClonePending, fsa.CloneProgressReport{}, "", ""}] = cerrors.ErrClonePending
errorState[cephFSCloneState{fsa.CloneFailed, fsa.CloneProgressReport{}, "", ""}] = cerrors.ErrCloneFailed

for state, err := range errorState {
require.ErrorIs(t, state.ToError(), err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cephfs/core/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type SubVolumeClient interface {
// CreateCloneFromSubVolume creates a clone from the subvolume.
CreateCloneFromSubvolume(ctx context.Context, parentvolOpt *SubVolume) error
// GetCloneState returns the clone state of the subvolume.
GetCloneState(ctx context.Context) (cephFSCloneState, error)
GetCloneState(ctx context.Context) (*cephFSCloneState, error)
// CreateCloneFromSnapshot creates a clone from the subvolume snapshot.
CreateCloneFromSnapshot(ctx context.Context, snap Snapshot) error
// CleanupSnapshotFromSubvolume removes the snapshot from the subvolume.
Expand Down
11 changes: 11 additions & 0 deletions internal/cephfs/store/fsjournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ func CheckVolExists(ctx context.Context,
}
err = cloneState.ToError()
if errors.Is(err, cerrors.ErrCloneInProgress) {
progressReport := cloneState.GetProgressReport()
Nikhil-Ladha marked this conversation as resolved.
Show resolved Hide resolved
// append progress report only if the progress report parameters are present.
if progressReport.PercentageCloned != "" {
err = fmt.Errorf("%w. progress report: percentage cloned=%s, amount cloned=%s, files cloned=%s",
err,
progressReport.PercentageCloned,
progressReport.AmountCloned,
progressReport.FilesCloned)
log.ErrorLog(ctx, err.Error())
}

return nil, err
}
if errors.Is(err, cerrors.ErrClonePending) {
Expand Down