remove operation "started" (#2247)

## Description

This flag is confusing, and is better represented by
tracking errors.

## Type of change

- [x] 🧹 Tech Debt/Cleanup

## Test Plan

- [x]  Unit test
This commit is contained in:
Keepers 2023-01-30 11:57:45 -07:00 committed by GitHub
parent ac1ff0c5cc
commit 637b1904aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 32 deletions

View File

@ -90,7 +90,6 @@ type backupStats struct {
k *kopia.BackupStats
gc *support.ConnectorOperationStatus
resourceCount int
started bool
readErr, writeErr error
}
@ -228,7 +227,6 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
// should always be 1, since backups are 1:1 with resourceOwners.
opStats.resourceCount = 1
opStats.started = true
return err
}
@ -558,9 +556,12 @@ func (op *BackupOperation) persistResults(
) error {
op.Results.StartedAt = started
op.Results.CompletedAt = time.Now()
op.Results.ReadErrors = opStats.readErr
op.Results.WriteErrors = opStats.writeErr
op.Status = Completed
if !opStats.started {
if opStats.readErr != nil || opStats.writeErr != nil {
op.Status = Failed
return multierror.Append(
@ -573,9 +574,6 @@ func (op *BackupOperation) persistResults(
op.Status = NoData
}
op.Results.ReadErrors = opStats.readErr
op.Results.WriteErrors = opStats.writeErr
op.Results.BytesRead = opStats.k.TotalHashedBytes
op.Results.BytesUploaded = opStats.k.TotalUploadedBytes
op.Results.ItemsRead = opStats.gc.Successful

View File

@ -373,7 +373,6 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
expectStatus: Completed,
expectErr: assert.NoError,
stats: backupStats{
started: true,
resourceCount: 1,
k: &kopia.BackupStats{
TotalFileCount: 1,
@ -389,7 +388,7 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
expectStatus: Failed,
expectErr: assert.Error,
stats: backupStats{
started: false,
readErr: assert.AnError,
k: &kopia.BackupStats{},
gc: &support.ConnectorOperationStatus{},
},
@ -398,9 +397,8 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
expectStatus: NoData,
expectErr: assert.NoError,
stats: backupStats{
started: true,
k: &kopia.BackupStats{},
gc: &support.ConnectorOperationStatus{},
k: &kopia.BackupStats{},
gc: &support.ConnectorOperationStatus{},
},
},
}

View File

@ -89,7 +89,6 @@ type restoreStats struct {
gc *support.ConnectorOperationStatus
bytesRead *stats.ByteCounter
resourceCount int
started bool
readErr, writeErr error
// a transient value only used to pair up start-end events.
@ -143,10 +142,8 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De
detailsStore,
)
if err != nil {
err = errors.Wrap(err, "restore")
opStats.readErr = err
return nil, err
opStats.readErr = errors.Wrap(err, "restore")
return nil, opStats.readErr
}
ctx = clues.Add(ctx, "resource_owner", bup.Selector.DiscreteOwner)
@ -178,10 +175,8 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De
dcs, err := op.kopia.RestoreMultipleItems(ctx, bup.SnapshotID, paths, opStats.bytesRead)
if err != nil {
err = errors.Wrap(err, "retrieving service data")
opStats.readErr = err
return nil, err
opStats.readErr = errors.Wrap(err, "retrieving service data")
return nil, opStats.readErr
}
kopiaComplete <- struct{}{}
@ -207,14 +202,11 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De
op.Destination,
dcs)
if err != nil {
err = errors.Wrap(err, "restoring service data")
opStats.writeErr = err
return nil, err
opStats.writeErr = errors.Wrap(err, "restoring service data")
return nil, opStats.writeErr
}
restoreComplete <- struct{}{}
opStats.started = true
opStats.gc = gc.AwaitStatus()
logger.Ctx(ctx).Debug(gc.PrintableStatus())
@ -230,10 +222,12 @@ func (op *RestoreOperation) persistResults(
) error {
op.Results.StartedAt = started
op.Results.CompletedAt = time.Now()
op.Results.ReadErrors = opStats.readErr
op.Results.WriteErrors = opStats.writeErr
op.Status = Completed
if !opStats.started {
if opStats.readErr != nil || opStats.writeErr != nil {
op.Status = Failed
return multierror.Append(
@ -246,9 +240,6 @@ func (op *RestoreOperation) persistResults(
op.Status = NoData
}
op.Results.ReadErrors = opStats.readErr
op.Results.WriteErrors = opStats.writeErr
op.Results.BytesRead = opStats.bytesRead.NumBytes
op.Results.ItemsRead = len(opStats.cs) // TODO: file count, not collection count
op.Results.ItemsWritten = opStats.gc.Successful

View File

@ -57,7 +57,6 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
expectStatus: Completed,
expectErr: assert.NoError,
stats: restoreStats{
started: true,
resourceCount: 1,
bytesRead: &stats.ByteCounter{
NumBytes: 42,
@ -73,7 +72,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
expectStatus: Failed,
expectErr: assert.Error,
stats: restoreStats{
started: false,
readErr: assert.AnError,
bytesRead: &stats.ByteCounter{},
gc: &support.ConnectorOperationStatus{},
},
@ -82,7 +81,6 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
expectStatus: NoData,
expectErr: assert.NoError,
stats: restoreStats{
started: true,
bytesRead: &stats.ByteCounter{},
cs: []data.Collection{},
gc: &support.ConnectorOperationStatus{},