Skip to content

Commit

Permalink
fix: remove dp from rwPartitions when dp have no space to create extent
Browse files Browse the repository at this point in the history
Signed-off-by: yinlei-jinan <[email protected]>
  • Loading branch information
yinlei-github committed Sep 1, 2020
1 parent cb98c82 commit ce3b851
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sdk/data/stream/extent_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package stream
import (
"fmt"
"net"
"strings"
"sync/atomic"
"time"

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

"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/sdk/data/wrapper"
"github.com/chubaofs/chubaofs/util"
"github.com/chubaofs/chubaofs/util/errors"
"github.com/chubaofs/chubaofs/util/log"
)

Expand Down Expand Up @@ -495,13 +495,20 @@ func (eh *ExtentHandler) allocateExtent() (err error) {
extID, err = eh.createExtent(dp)
}
if err != nil {
log.LogWarnf("allocateExtent: failed to create extent, eh(%v) err(%v)", eh, err)
if strings.Contains(err.Error(), "DiskNoSpaceErr") {
log.LogWarnf("allocateExtent: delete dp[%v] caused by create extent failed, eh(%v) err(%v) exclude(%v)",
dp, eh, err, exclude)
eh.stream.client.dataWrapper.RemoveDataPartitionForWrite(dp.PartitionID)
continue
}
log.LogWarnf("allocateExtent: failed to create extent, eh(%v) err(%v) exclude(%v)", eh, err, exclude)
dp.CheckAllHostsIsAvail(exclude)
continue
}

if conn, err = StreamConnPool.GetConnect(dp.Hosts[0]); err != nil {
log.LogWarnf("allocateExtent: failed to create connection, eh(%v) err(%v) dp(%v)", eh, err, dp)
log.LogWarnf("allocateExtent: failed to create connection, eh(%v) err(%v) dp(%v) exclude(%v)",
eh, err, dp, exclude)
// If storeMode is tinyExtentType and can't create connection, we also check host status.
dp.CheckAllHostsIsAvail(exclude)
continue
Expand Down
20 changes: 20 additions & 0 deletions sdk/data/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,26 @@ func (w *Wrapper) GetDataPartitionForWrite(exclude map[string]struct{}) (*DataPa
return nil, fmt.Errorf("no writable data partition")
}

func (w *Wrapper) RemoveDataPartitionForWrite(partitionID uint64) {
w.Lock()
defer w.Unlock()
rwPartitionGroups := w.rwPartition

var i int
for i = 0; i < len(rwPartitionGroups); i++ {
if rwPartitionGroups[i].PartitionID == partitionID {
break
}
}

var newRwPartition []*DataPartition
newRwPartition = append(newRwPartition, rwPartitionGroups[:i]...)
newRwPartition = append(newRwPartition, rwPartitionGroups[i+1:]...)

w.rwPartition = newRwPartition
return
}

// GetDataPartition returns the data partition based on the given partition ID.
func (w *Wrapper) GetDataPartition(partitionID uint64) (*DataPartition, error) {
w.RLock()
Expand Down

0 comments on commit ce3b851

Please sign in to comment.