Skip to content

Commit

Permalink
sdk: retry if mount failed in case master is unavailable temporarily
Browse files Browse the repository at this point in the history
Signed-off-by: Shuoran Liu <[email protected]>
  • Loading branch information
shuoranliu authored and awzhgw committed Jun 11, 2019
1 parent 002d678 commit a4534ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
21 changes: 20 additions & 1 deletion sdk/data/stream/extent_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"runtime"
"sync"
"time"

"github.com/chubaofs/chubaofs/util/errors"

Expand All @@ -31,6 +32,11 @@ type AppendExtentKeyFunc func(inode uint64, key proto.ExtentKey) error
type GetExtentsFunc func(inode uint64) (uint64, uint64, []proto.ExtentKey, error)
type TruncateFunc func(inode, size uint64) error

const (
MaxMountRetryLimit = 5
MountRetryInterval = time.Second * 5
)

var (
gDataWrapper *wrapper.Wrapper
openRequestPool *sync.Pool
Expand All @@ -54,14 +60,26 @@ type ExtentClient struct {
func NewExtentClient(volname, master string, appendExtentKey AppendExtentKeyFunc, getExtents GetExtentsFunc, truncate TruncateFunc) (client *ExtentClient, err error) {
runtime.GOMAXPROCS(runtime.NumCPU())
client = new(ExtentClient)

limit := MaxMountRetryLimit
retry:
gDataWrapper, err = wrapper.NewDataPartitionWrapper(volname, master)
if err != nil {
return nil, errors.Trace(err, "Init dp wrapper failed!")
if limit <= 0 {
return nil, errors.Trace(err, "Init data wrapper failed!")
} else {
limit--
time.Sleep(MountRetryInterval)
goto retry
}
}

client.streamers = make(map[uint64]*Streamer)
client.appendExtentKey = appendExtentKey
client.getExtents = getExtents
client.truncate = truncate

// Init request pools
openRequestPool = &sync.Pool{New: func() interface{} {
return &OpenRequest{}
}}
Expand All @@ -80,6 +98,7 @@ func NewExtentClient(volname, master string, appendExtentKey AppendExtentKeyFunc
evictRequestPool = &sync.Pool{New: func() interface{} {
return &EvictRequest{}
}}

return
}

Expand Down
19 changes: 18 additions & 1 deletion sdk/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/util"
"github.com/chubaofs/chubaofs/util/btree"
"github.com/chubaofs/chubaofs/util/errors"
)

const (
Expand All @@ -43,6 +44,11 @@ const (
statusNotPerm
)

const (
MaxMountRetryLimit = 5
MountRetryInterval = time.Second * 5
)

type MetaWrapper struct {
sync.RWMutex
cluster string
Expand Down Expand Up @@ -83,9 +89,20 @@ func NewMetaWrapper(volname, owner, masterHosts string) (*MetaWrapper, error) {
mw.rwPartitions = make([]*MetaPartition, 0)
mw.updateClusterInfo()
mw.updateVolStatInfo()

limit := MaxMountRetryLimit
retry:
if err := mw.updateMetaPartitions(); err != nil {
return nil, err
if limit <= 0 {
return nil, errors.Trace(err, "Init meta wrapper failed!")
} else {
limit--
time.Sleep(MountRetryInterval)
goto retry
}

}

go mw.refresh()
return mw, nil
}
Expand Down

0 comments on commit a4534ca

Please sign in to comment.