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:
parent
ac1ff0c5cc
commit
637b1904aa
@ -90,7 +90,6 @@ type backupStats struct {
|
|||||||
k *kopia.BackupStats
|
k *kopia.BackupStats
|
||||||
gc *support.ConnectorOperationStatus
|
gc *support.ConnectorOperationStatus
|
||||||
resourceCount int
|
resourceCount int
|
||||||
started bool
|
|
||||||
readErr, writeErr error
|
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.
|
// should always be 1, since backups are 1:1 with resourceOwners.
|
||||||
opStats.resourceCount = 1
|
opStats.resourceCount = 1
|
||||||
opStats.started = true
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -558,9 +556,12 @@ func (op *BackupOperation) persistResults(
|
|||||||
) error {
|
) error {
|
||||||
op.Results.StartedAt = started
|
op.Results.StartedAt = started
|
||||||
op.Results.CompletedAt = time.Now()
|
op.Results.CompletedAt = time.Now()
|
||||||
|
op.Results.ReadErrors = opStats.readErr
|
||||||
|
op.Results.WriteErrors = opStats.writeErr
|
||||||
|
|
||||||
op.Status = Completed
|
op.Status = Completed
|
||||||
if !opStats.started {
|
|
||||||
|
if opStats.readErr != nil || opStats.writeErr != nil {
|
||||||
op.Status = Failed
|
op.Status = Failed
|
||||||
|
|
||||||
return multierror.Append(
|
return multierror.Append(
|
||||||
@ -573,9 +574,6 @@ func (op *BackupOperation) persistResults(
|
|||||||
op.Status = NoData
|
op.Status = NoData
|
||||||
}
|
}
|
||||||
|
|
||||||
op.Results.ReadErrors = opStats.readErr
|
|
||||||
op.Results.WriteErrors = opStats.writeErr
|
|
||||||
|
|
||||||
op.Results.BytesRead = opStats.k.TotalHashedBytes
|
op.Results.BytesRead = opStats.k.TotalHashedBytes
|
||||||
op.Results.BytesUploaded = opStats.k.TotalUploadedBytes
|
op.Results.BytesUploaded = opStats.k.TotalUploadedBytes
|
||||||
op.Results.ItemsRead = opStats.gc.Successful
|
op.Results.ItemsRead = opStats.gc.Successful
|
||||||
|
|||||||
@ -373,7 +373,6 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
|
|||||||
expectStatus: Completed,
|
expectStatus: Completed,
|
||||||
expectErr: assert.NoError,
|
expectErr: assert.NoError,
|
||||||
stats: backupStats{
|
stats: backupStats{
|
||||||
started: true,
|
|
||||||
resourceCount: 1,
|
resourceCount: 1,
|
||||||
k: &kopia.BackupStats{
|
k: &kopia.BackupStats{
|
||||||
TotalFileCount: 1,
|
TotalFileCount: 1,
|
||||||
@ -389,7 +388,7 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
|
|||||||
expectStatus: Failed,
|
expectStatus: Failed,
|
||||||
expectErr: assert.Error,
|
expectErr: assert.Error,
|
||||||
stats: backupStats{
|
stats: backupStats{
|
||||||
started: false,
|
readErr: assert.AnError,
|
||||||
k: &kopia.BackupStats{},
|
k: &kopia.BackupStats{},
|
||||||
gc: &support.ConnectorOperationStatus{},
|
gc: &support.ConnectorOperationStatus{},
|
||||||
},
|
},
|
||||||
@ -398,7 +397,6 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
|
|||||||
expectStatus: NoData,
|
expectStatus: NoData,
|
||||||
expectErr: assert.NoError,
|
expectErr: assert.NoError,
|
||||||
stats: backupStats{
|
stats: backupStats{
|
||||||
started: true,
|
|
||||||
k: &kopia.BackupStats{},
|
k: &kopia.BackupStats{},
|
||||||
gc: &support.ConnectorOperationStatus{},
|
gc: &support.ConnectorOperationStatus{},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -89,7 +89,6 @@ type restoreStats struct {
|
|||||||
gc *support.ConnectorOperationStatus
|
gc *support.ConnectorOperationStatus
|
||||||
bytesRead *stats.ByteCounter
|
bytesRead *stats.ByteCounter
|
||||||
resourceCount int
|
resourceCount int
|
||||||
started bool
|
|
||||||
readErr, writeErr error
|
readErr, writeErr error
|
||||||
|
|
||||||
// a transient value only used to pair up start-end events.
|
// 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,
|
detailsStore,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "restore")
|
opStats.readErr = errors.Wrap(err, "restore")
|
||||||
opStats.readErr = err
|
return nil, opStats.readErr
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = clues.Add(ctx, "resource_owner", bup.Selector.DiscreteOwner)
|
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)
|
dcs, err := op.kopia.RestoreMultipleItems(ctx, bup.SnapshotID, paths, opStats.bytesRead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "retrieving service data")
|
opStats.readErr = errors.Wrap(err, "retrieving service data")
|
||||||
opStats.readErr = err
|
return nil, opStats.readErr
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
kopiaComplete <- struct{}{}
|
kopiaComplete <- struct{}{}
|
||||||
|
|
||||||
@ -207,14 +202,11 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De
|
|||||||
op.Destination,
|
op.Destination,
|
||||||
dcs)
|
dcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "restoring service data")
|
opStats.writeErr = errors.Wrap(err, "restoring service data")
|
||||||
opStats.writeErr = err
|
return nil, opStats.writeErr
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
restoreComplete <- struct{}{}
|
restoreComplete <- struct{}{}
|
||||||
|
|
||||||
opStats.started = true
|
|
||||||
opStats.gc = gc.AwaitStatus()
|
opStats.gc = gc.AwaitStatus()
|
||||||
|
|
||||||
logger.Ctx(ctx).Debug(gc.PrintableStatus())
|
logger.Ctx(ctx).Debug(gc.PrintableStatus())
|
||||||
@ -230,10 +222,12 @@ func (op *RestoreOperation) persistResults(
|
|||||||
) error {
|
) error {
|
||||||
op.Results.StartedAt = started
|
op.Results.StartedAt = started
|
||||||
op.Results.CompletedAt = time.Now()
|
op.Results.CompletedAt = time.Now()
|
||||||
|
op.Results.ReadErrors = opStats.readErr
|
||||||
|
op.Results.WriteErrors = opStats.writeErr
|
||||||
|
|
||||||
op.Status = Completed
|
op.Status = Completed
|
||||||
|
|
||||||
if !opStats.started {
|
if opStats.readErr != nil || opStats.writeErr != nil {
|
||||||
op.Status = Failed
|
op.Status = Failed
|
||||||
|
|
||||||
return multierror.Append(
|
return multierror.Append(
|
||||||
@ -246,9 +240,6 @@ func (op *RestoreOperation) persistResults(
|
|||||||
op.Status = NoData
|
op.Status = NoData
|
||||||
}
|
}
|
||||||
|
|
||||||
op.Results.ReadErrors = opStats.readErr
|
|
||||||
op.Results.WriteErrors = opStats.writeErr
|
|
||||||
|
|
||||||
op.Results.BytesRead = opStats.bytesRead.NumBytes
|
op.Results.BytesRead = opStats.bytesRead.NumBytes
|
||||||
op.Results.ItemsRead = len(opStats.cs) // TODO: file count, not collection count
|
op.Results.ItemsRead = len(opStats.cs) // TODO: file count, not collection count
|
||||||
op.Results.ItemsWritten = opStats.gc.Successful
|
op.Results.ItemsWritten = opStats.gc.Successful
|
||||||
|
|||||||
@ -57,7 +57,6 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
|
|||||||
expectStatus: Completed,
|
expectStatus: Completed,
|
||||||
expectErr: assert.NoError,
|
expectErr: assert.NoError,
|
||||||
stats: restoreStats{
|
stats: restoreStats{
|
||||||
started: true,
|
|
||||||
resourceCount: 1,
|
resourceCount: 1,
|
||||||
bytesRead: &stats.ByteCounter{
|
bytesRead: &stats.ByteCounter{
|
||||||
NumBytes: 42,
|
NumBytes: 42,
|
||||||
@ -73,7 +72,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
|
|||||||
expectStatus: Failed,
|
expectStatus: Failed,
|
||||||
expectErr: assert.Error,
|
expectErr: assert.Error,
|
||||||
stats: restoreStats{
|
stats: restoreStats{
|
||||||
started: false,
|
readErr: assert.AnError,
|
||||||
bytesRead: &stats.ByteCounter{},
|
bytesRead: &stats.ByteCounter{},
|
||||||
gc: &support.ConnectorOperationStatus{},
|
gc: &support.ConnectorOperationStatus{},
|
||||||
},
|
},
|
||||||
@ -82,7 +81,6 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
|
|||||||
expectStatus: NoData,
|
expectStatus: NoData,
|
||||||
expectErr: assert.NoError,
|
expectErr: assert.NoError,
|
||||||
stats: restoreStats{
|
stats: restoreStats{
|
||||||
started: true,
|
|
||||||
bytesRead: &stats.ByteCounter{},
|
bytesRead: &stats.ByteCounter{},
|
||||||
cs: []data.Collection{},
|
cs: []data.Collection{},
|
||||||
gc: &support.ConnectorOperationStatus{},
|
gc: &support.ConnectorOperationStatus{},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user