Skip to content

Commit a6b0c0a

Browse files
committed
Add specialized erroring to files and blobfs creators
1 parent a549f26 commit a6b0c0a

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

common/folderCreationTracker_interface.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ type Prompter interface {
1414
ShouldOverwrite(objectPath string, objectType EntityType) bool
1515
}
1616

17-
// FolderCreationErrorFolderAlreadyExists is a signalling error that should be
17+
// FolderCreationErrorAlreadyExists is a signalling error that should be
1818
// returned by doCreation on FolderCreationTracker.CreateFolder for supported folder-creators.
1919
// This will inform the folder creation tracker to _not_ try to create the folder.
20-
type FolderCreationErrorFolderAlreadyExists struct{}
20+
type FolderCreationErrorAlreadyExists struct{}
2121

22-
func (f FolderCreationErrorFolderAlreadyExists) Error() string {
22+
func (f FolderCreationErrorAlreadyExists) Error() string {
2323
return "not a real error"
2424
}

jobsAdmin/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ func resurrectJobSummary(jm ste.IJobMgr) common.ListJobSummaryResponse {
414414
switch jppt.TransferStatus() {
415415
case common.ETransferStatus.NotStarted(),
416416
common.ETransferStatus.FolderCreated(),
417+
common.ETransferStatus.FolderExisted(),
417418
common.ETransferStatus.Started(),
418419
common.ETransferStatus.Restarted(),
419420
common.ETransferStatus.Cancelled():

ste/folderCreationTracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (f *jpptFolderTracker) CreateFolder(folder string, doCreation func() error)
145145
}
146146

147147
err := doCreation()
148-
if err != nil && !errors.Is(err, common.FolderCreationErrorFolderAlreadyExists{}) {
148+
if err != nil && !errors.Is(err, common.FolderCreationErrorAlreadyExists{}) {
149149
return err
150150
}
151151

@@ -155,7 +155,7 @@ func (f *jpptFolderTracker) CreateFolder(folder string, doCreation func() error)
155155

156156
if err == nil { // first, update our internal status, then,
157157
state.Status = EJpptFolderTrackerStatus.FolderCreated()
158-
} else if errors.Is(err, common.FolderCreationErrorFolderAlreadyExists{}) {
158+
} else if errors.Is(err, common.FolderCreationErrorAlreadyExists{}) {
159159
state.Status = EJpptFolderTrackerStatus.FolderExisted()
160160
}
161161

ste/folderCreationTracker_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
133133
existsIdx := JpptFolderIndex{0, 1}
134134
folderCreated := "folderCreated"
135135
createdIdx := JpptFolderIndex{1, 1} // cheap validation of job part overlap
136+
folderShouldCreate := "folderShouldCreate"
137+
shouldCreateIdx := JpptFolderIndex{0, 2}
136138

137139
plan := &mockedJobPlan{
138140
transfers: map[JpptFolderIndex]*JobPartPlanTransfer{
139-
existsIdx: {atomicTransferStatus: common.ETransferStatus.NotStarted()},
140-
createdIdx: {atomicTransferStatus: common.ETransferStatus.NotStarted()},
141+
existsIdx: {atomicTransferStatus: common.ETransferStatus.NotStarted()},
142+
createdIdx: {atomicTransferStatus: common.ETransferStatus.NotStarted()},
143+
shouldCreateIdx: {atomicTransferStatus: common.ETransferStatus.NotStarted()},
141144
},
142145
}
143146

@@ -149,20 +152,28 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
149152

150153
fct.RegisterPropertiesTransfer(folderExists, existsIdx.PartNum, existsIdx.TransferIndex)
151154
fct.RegisterPropertiesTransfer(folderCreated, createdIdx.PartNum, createdIdx.TransferIndex)
155+
fct.RegisterPropertiesTransfer(folderShouldCreate, shouldCreateIdx.PartNum, shouldCreateIdx.TransferIndex)
152156

153157
_ = fct.CreateFolder(folderCreated, func() error {
154158
return nil
155159
}) // "create" our folder
156160
err := fct.CreateFolder(folderExists, func() error {
157-
return common.FolderCreationErrorFolderAlreadyExists{}
158-
})
159-
a.NoError(err, "already exists should be caught")
161+
return common.FolderCreationErrorAlreadyExists{}
162+
}) // fail creation on not existing
163+
a.NoError(err, "already exists should be caught") // ensure we caught that error
164+
expectedFailureErr := errors.New("this creation should fail")
165+
err = fct.CreateFolder(folderShouldCreate, func() error {
166+
return expectedFailureErr
167+
}) // ensure that a natural failure should return properly
168+
a.Equal(err, expectedFailureErr)
160169

161170
// validate folder states
162-
a.Equal(fct.contents[folderCreated].Status, EJpptFolderTrackerStatus.FolderCreated())
171+
a.Equal(fct.contents[folderCreated].Status, EJpptFolderTrackerStatus.FolderCreated()) // Our created folder should be marked as such.
163172
a.Equal(plan.transfers[createdIdx].TransferStatus(), common.ETransferStatus.FolderCreated())
164-
a.Equal(fct.contents[folderExists].Status, EJpptFolderTrackerStatus.FolderExisted())
173+
a.Equal(fct.contents[folderExists].Status, EJpptFolderTrackerStatus.FolderExisted()) // Our existing folder should be marked as such.
165174
a.Equal(plan.transfers[existsIdx].TransferStatus(), common.ETransferStatus.FolderExisted())
175+
a.Equal(fct.contents[folderShouldCreate].Status, EJpptFolderTrackerStatus.Unseen()) // no status updates should've occurred on a "naturally" failed create.
176+
a.Equal(plan.transfers[shouldCreateIdx].TransferStatus(), common.ETransferStatus.NotStarted())
166177

167178
// validate that re-create doesn't trigger on either
168179
err = fct.CreateFolder(folderCreated, func() error {
@@ -175,4 +186,9 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
175186
return errors.New("should return nil")
176187
})
177188
a.NoError(err)
189+
190+
// validate we can still create normally for our naturally failed folder
191+
err = fct.CreateFolder(folderShouldCreate, func() error {
192+
return nil
193+
})
178194
}

ste/sender-azureFile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ func (d AzureFileParentDirCreator) CreateDirToRoot(ctx context.Context, shareCli
460460
recorderURL.RawQuery = ""
461461
err = t.CreateFolder(recorderURL.String(), func() error {
462462
_, err := currentDirectoryClient.Create(ctx, nil)
463+
464+
if fileerror.HasCode(err, fileerror.ResourceAlreadyExists) {
465+
return common.FolderCreationErrorAlreadyExists{}
466+
}
467+
463468
return err
464469
})
465470
if verifiedErr := d.verifyAndHandleCreateErrors(err); verifiedErr != nil {

ste/sender-blobFS.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ package ste
2323
import (
2424
"context"
2525
"fmt"
26-
datalakesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
2726
"strings"
2827
"time"
2928

29+
datalakesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
30+
3031
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
3132
"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
3233
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
@@ -221,11 +222,13 @@ func (u *blobFSSenderBase) doEnsureDirExists(directoryClient *directory.Client)
221222
// know which will happen first
222223
err = u.jptm.GetFolderCreationTracker().CreateFolder(directoryClient.DFSURL(), func() error {
223224
_, err := directoryClient.Create(u.jptm.Context(), &directory.CreateOptions{AccessConditions: &directory.AccessConditions{ModifiedAccessConditions: &directory.ModifiedAccessConditions{IfNoneMatch: to.Ptr(azcore.ETagAny)}}})
225+
226+
if datalakeerror.HasCode(err, datalakeerror.PathAlreadyExists) {
227+
return common.FolderCreationErrorAlreadyExists{}
228+
}
229+
224230
return err
225231
})
226-
if datalakeerror.HasCode(err, datalakeerror.PathAlreadyExists) {
227-
return nil // not a error as far as we are concerned. It just already exists
228-
}
229232
return err
230233
}
231234

@@ -297,7 +300,7 @@ func (u *blobFSSenderBase) SendSymlink(linkData string) error {
297300
}
298301

299302
meta[common.POSIXSymlinkMeta] = to.Ptr("true") // just in case there isn't any metadata
300-
blobHeaders := blob.HTTPHeaders{ // translate headers, since those still apply
303+
blobHeaders := blob.HTTPHeaders{ // translate headers, since those still apply
301304
BlobContentType: u.creationTimeHeaders.ContentType,
302305
BlobContentEncoding: u.creationTimeHeaders.ContentEncoding,
303306
BlobContentLanguage: u.creationTimeHeaders.ContentLanguage,

0 commit comments

Comments
 (0)