Skip to content

Commit 319d4ca

Browse files
authored
Merge pull request #27 from smkniazi/GH-26
Gh 26
2 parents 50c0049 + c4b42c6 commit 319d4ca

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

Dir.go

-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ func (dir *Dir) LookupAttrs(name string, attrs *Attrs) error {
208208
if err != nil {
209209
// It is a warning as each time new file write tries to stat if the file exists
210210
loginfo("Stat failed", Fields{Operation: Stat, Path: path.Join(dir.AbsolutePath(), name), Error: err})
211-
if pathError, ok := err.(*os.PathError); ok && (pathError.Err == os.ErrNotExist) {
212-
return fuse.ENOENT
213-
}
214211
return err
215212
}
216213

HdfsAccessor.go

+50-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strconv"
1212
"strings"
1313
"sync"
14+
"syscall"
1415
"time"
1516

1617
"bazil.org/fuse"
@@ -166,7 +167,7 @@ func (dfs *hdfsAccessorImpl) OpenRead(path string) (ReadSeekCloser, error) {
166167
}
167168
reader, err := dfs.MetadataClient.Open(path)
168169
if err != nil {
169-
return nil, err
170+
return nil, unwrapAndTranslateError(err)
170171
}
171172
return NewHdfsReader(reader), nil
172173
}
@@ -182,7 +183,7 @@ func (dfs *hdfsAccessorImpl) CreateFile(path string, mode os.FileMode, overwrite
182183
}
183184
writer, err := dfs.MetadataClient.CreateFile(path, 3, 64*1024*1024, mode, overwrite)
184185
if err != nil {
185-
return nil, err
186+
return nil, unwrapAndTranslateError(err)
186187
}
187188

188189
return NewHdfsWriter(writer), nil
@@ -201,12 +202,12 @@ func (dfs *hdfsAccessorImpl) ReadDir(path string) ([]Attrs, error) {
201202
if err != nil {
202203
if IsSuccessOrNonRetriableError(err) {
203204
// benign error (e.g. path not found)
204-
return nil, err
205+
return nil, unwrapAndTranslateError(err)
205206
}
206207
// We've got error from this client, setting to nil, so we try another one next time
207208
dfs.MetadataClient = nil
208209
// TODO: attempt to gracefully close the conenction
209-
return nil, err
210+
return nil, unwrapAndTranslateError(err)
210211
}
211212
allAttrs := make([]Attrs, len(files))
212213
for i, fileInfo := range files {
@@ -230,12 +231,12 @@ func (dfs *hdfsAccessorImpl) Stat(path string) (Attrs, error) {
230231
if err != nil {
231232
if IsSuccessOrNonRetriableError(err) {
232233
// benign error (e.g. path not found)
233-
return Attrs{}, err
234+
return Attrs{}, unwrapAndTranslateError(err)
234235
}
235236
// We've got error from this client, setting to nil, so we try another one next time
236237
dfs.MetadataClient = nil
237238
// TODO: attempt to gracefully close the conenction
238-
return Attrs{}, err
239+
return Attrs{}, unwrapAndTranslateError(err)
239240
}
240241
return dfs.AttrsFromFileInfo(fileInfo), nil
241242
}
@@ -254,10 +255,10 @@ func (dfs *hdfsAccessorImpl) StatFs() (FsInfo, error) {
254255
fsInfo, err := dfs.MetadataClient.StatFs()
255256
if err != nil {
256257
if IsSuccessOrNonRetriableError(err) {
257-
return FsInfo{}, err
258+
return FsInfo{}, unwrapAndTranslateError(err)
258259
}
259260
dfs.MetadataClient = nil
260-
return FsInfo{}, err
261+
return FsInfo{}, unwrapAndTranslateError(err)
261262
}
262263
return dfs.AttrsFromFsInfo(fsInfo), nil
263264
}
@@ -360,10 +361,49 @@ func (dfs *hdfsAccessorImpl) LookupGid(groupName string) uint32 {
360361

361362
// Returns true if err==nil or err is expected (benign) error which should be propagated directoy to the caller
362363
func IsSuccessOrNonRetriableError(err error) bool {
363-
if err == nil || err == io.EOF || err == fuse.EEXIST {
364+
if err == nil {
364365
return true
365366
}
366-
if pathError, ok := err.(*os.PathError); ok && (pathError.Err == os.ErrNotExist || pathError.Err == os.ErrPermission) {
367+
368+
return isNonRetriableError(unwrapAndTranslateError(err))
369+
}
370+
371+
func unwrapAndTranslateError(err error) error {
372+
var e error
373+
pathError, ok := err.(*os.PathError)
374+
if ok {
375+
e = pathError.Err
376+
} else {
377+
e = err
378+
}
379+
380+
if e == os.ErrNotExist {
381+
return syscall.ENOENT
382+
}
383+
if e == os.ErrPermission {
384+
return syscall.EPERM
385+
}
386+
if e == os.ErrExist {
387+
return syscall.EEXIST
388+
}
389+
390+
return e
391+
}
392+
393+
func isNonRetriableError(err error) bool {
394+
if err == io.EOF ||
395+
err == fuse.EEXIST ||
396+
err == syscall.ENOENT ||
397+
err == syscall.EACCES ||
398+
err == syscall.ENOTEMPTY ||
399+
err == syscall.EEXIST ||
400+
err == syscall.EROFS ||
401+
err == syscall.EDQUOT ||
402+
err == syscall.ENOLINK ||
403+
err == os.ErrNotExist ||
404+
err == os.ErrPermission ||
405+
err == os.ErrExist ||
406+
err == os.ErrClosed {
367407
return true
368408
} else {
369409
return false

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
1515
)
1616

17-
replace github.com/colinmarc/hdfs/v2 v2.2.0 => github.com/logicalclocks/hopsfs-go-client/v2 v2.4.1
17+
replace github.com/colinmarc/hdfs/v2 v2.2.0 => github.com/logicalclocks/hopsfs-go-client/v2 v2.4.2
1818

1919
//replace github.com/colinmarc/hdfs/v2 v2.2.0 => /home/salman/code/hops/hopsfs-go/hopsfs-go-client
2020
//replace bazil.org/fuse v0.0.0-20200524192727-fb710f7dfd05 => /home/salman/code/hops/hopsfs-go/fuse

main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var allowedPrefixesString *string
2929
var expandZips *bool
3030
var readOnly *bool
3131
var tls *bool
32+
var maxAttempts int
3233

3334
func main() {
3435

@@ -44,7 +45,7 @@ func main() {
4445

4546
allowedPrefixes := strings.Split(*allowedPrefixesString, ",")
4647

47-
retryPolicy.MaxAttempts += 1 // converting # of retry attempts to total # of attempts
48+
retryPolicy.MaxAttempts = maxAttempts
4849

4950
tlsConfig := TLSConfig{
5051
TLS: *tls,
@@ -134,7 +135,7 @@ var Usage = func() {
134135
func parseArgsAndInitLogger(retryPolicy *RetryPolicy) {
135136
lazyMount = flag.Bool("lazy", false, "Allows to mount HopsFS filesystem before HopsFS is available")
136137
flag.DurationVar(&retryPolicy.TimeLimit, "retryTimeLimit", 5*time.Minute, "time limit for all retry attempts for failed operations")
137-
flag.IntVar(&retryPolicy.MaxAttempts, "retryMaxAttempts", 99999999, "Maxumum retry attempts for failed operations")
138+
flag.IntVar(&maxAttempts, "retryMaxAttempts", 10, "Maxumum retry attempts for failed operations")
138139
flag.DurationVar(&retryPolicy.MinDelay, "retryMinDelay", 1*time.Second, "minimum delay between retries (note, first retry always happens immediatelly)")
139140
flag.DurationVar(&retryPolicy.MaxDelay, "retryMaxDelay", 60*time.Second, "maximum delay between retries")
140141
allowedPrefixesString = flag.String("allowedPrefixes", "*", "Comma-separated list of allowed path prefixes on the remote file system, if specified the mount point will expose access to those prefixes only")
@@ -163,7 +164,7 @@ func parseArgsAndInitLogger(retryPolicy *RetryPolicy) {
163164
}
164165
initLogger(logLevel, false, logFile)
165166

166-
loginfo(fmt.Sprintf("Staging dir is:%s, Using TLS: %v, LogFile: %s", stagingDir, *tls, logFile), nil)
167+
loginfo(fmt.Sprintf("Staging dir is:%s, Using TLS: %v, RetryAttempts: %d, LogFile: %s", stagingDir, *tls, retryPolicy.MaxAttempts, logFile), nil)
167168
loginfo(fmt.Sprintf("hopsfs-mount: current head GITCommit: %s Built time: %s Built by: %s ", GITCOMMIT, BUILDTIME, HOSTNAME), nil)
168169
}
169170

0 commit comments

Comments
 (0)