mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
style(datanode): gofmt for datanode
Signed-off-by: slasher <shenjie1@oppo.com>
This commit is contained in:
parent
2cfb03dcc1
commit
5e93d2cea8
@ -17,20 +17,18 @@ package datanode
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"hash/crc32"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/util"
|
|
||||||
|
|
||||||
"fmt"
|
|
||||||
"hash/crc32"
|
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
"github.com/cubefs/cubefs/repl"
|
"github.com/cubefs/cubefs/repl"
|
||||||
"github.com/cubefs/cubefs/storage"
|
"github.com/cubefs/cubefs/storage"
|
||||||
|
"github.com/cubefs/cubefs/util"
|
||||||
"github.com/cubefs/cubefs/util/errors"
|
"github.com/cubefs/cubefs/util/errors"
|
||||||
"github.com/cubefs/cubefs/util/log"
|
"github.com/cubefs/cubefs/util/log"
|
||||||
)
|
)
|
||||||
@ -58,7 +56,6 @@ func NewDataPartitionRepairTask(extentFiles []*storage.ExtentInfo, tinyDeleteRec
|
|||||||
extentFile.Source = source
|
extentFile.Source = source
|
||||||
task.extents[extentFile.FileID] = extentFile
|
task.extents[extentFile.FileID] = extentFile
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +87,7 @@ func (dp *DataPartition) repair(extentType uint8) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fix dp replica index panic , using replica copy
|
// fix dp replica index panic , using replica copy
|
||||||
replica := dp.getReplicaCopy()
|
replica := dp.getReplicaCopy()
|
||||||
repairTasks := make([]*DataPartitionRepairTask, len(replica))
|
repairTasks := make([]*DataPartitionRepairTask, len(replica))
|
||||||
err := dp.buildDataPartitionRepairTask(repairTasks, extentType, tinyExtents, replica)
|
err := dp.buildDataPartitionRepairTask(repairTasks, extentType, tinyExtents, replica)
|
||||||
@ -407,8 +404,8 @@ func (dp *DataPartition) buildExtentRepairTasks(repairTasks []*DataPartitionRepa
|
|||||||
func (dp *DataPartition) notifyFollower(wg *sync.WaitGroup, index int, members []*DataPartitionRepairTask) (err error) {
|
func (dp *DataPartition) notifyFollower(wg *sync.WaitGroup, index int, members []*DataPartitionRepairTask) (err error) {
|
||||||
p := repl.NewPacketToNotifyExtentRepair(dp.partitionID) // notify all the followers to repair
|
p := repl.NewPacketToNotifyExtentRepair(dp.partitionID) // notify all the followers to repair
|
||||||
var conn *net.TCPConn
|
var conn *net.TCPConn
|
||||||
//target := dp.getReplicaAddr(index)
|
// target := dp.getReplicaAddr(index)
|
||||||
//fix repair case panic,may be dp's replicas is change
|
// fix repair case panic,may be dp's replicas is change
|
||||||
target := members[index].addr
|
target := members[index].addr
|
||||||
|
|
||||||
p.Data, _ = json.Marshal(members[index])
|
p.Data, _ = json.Marshal(members[index])
|
||||||
@ -456,16 +453,13 @@ func (dp *DataPartition) NotifyExtentRepair(members []*DataPartitionRepairTask)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//const MaxRepairErrCnt = 1000
|
|
||||||
|
|
||||||
// DoStreamExtentFixRepair executes the repair on the followers.
|
// DoStreamExtentFixRepair executes the repair on the followers.
|
||||||
func (dp *DataPartition) doStreamExtentFixRepair(wg *sync.WaitGroup, remoteExtentInfo *storage.ExtentInfo) {
|
func (dp *DataPartition) doStreamExtentFixRepair(wg *sync.WaitGroup, remoteExtentInfo *storage.ExtentInfo) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
err := dp.streamRepairExtent(remoteExtentInfo)
|
err := dp.streamRepairExtent(remoteExtentInfo)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//only decommission repair need to check err cnt
|
// only decommission repair need to check err cnt
|
||||||
if dp.isDecommissionRecovering() {
|
if dp.isDecommissionRecovering() {
|
||||||
atomic.AddUint64(&dp.recoverErrCnt, 1)
|
atomic.AddUint64(&dp.recoverErrCnt, 1)
|
||||||
if atomic.LoadUint64(&dp.recoverErrCnt) >= dp.dataNode.GetDpMaxRepairErrCnt() {
|
if atomic.LoadUint64(&dp.recoverErrCnt) >= dp.dataNode.GetDpMaxRepairErrCnt() {
|
||||||
@ -539,9 +533,7 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
currFixOffset := localExtentInfo.Size
|
currFixOffset := localExtentInfo.Size
|
||||||
var (
|
var hasRecoverySize uint64
|
||||||
hasRecoverySize uint64
|
|
||||||
)
|
|
||||||
var loopTimes uint64
|
var loopTimes uint64
|
||||||
for currFixOffset < remoteExtentInfo.Size {
|
for currFixOffset < remoteExtentInfo.Size {
|
||||||
if dp.stopRecover && dp.isDecommissionRecovering() {
|
if dp.stopRecover && dp.isDecommissionRecovering() {
|
||||||
@ -604,7 +596,7 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
|
|||||||
if reply.ArgLen == TinyExtentRepairReadResponseArgLen {
|
if reply.ArgLen == TinyExtentRepairReadResponseArgLen {
|
||||||
remoteAvaliSize = binary.BigEndian.Uint64(reply.Arg[9:TinyExtentRepairReadResponseArgLen])
|
remoteAvaliSize = binary.BigEndian.Uint64(reply.Arg[9:TinyExtentRepairReadResponseArgLen])
|
||||||
}
|
}
|
||||||
if reply.Arg != nil { //compact v1.2.0 recovery
|
if reply.Arg != nil { // compact v1.2.0 recovery
|
||||||
isEmptyResponse = reply.Arg[0] == EmptyResponse
|
isEmptyResponse = reply.Arg[0] == EmptyResponse
|
||||||
}
|
}
|
||||||
if isEmptyResponse {
|
if isEmptyResponse {
|
||||||
@ -644,7 +636,6 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
|
|||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func intMin(a, b int) int {
|
func intMin(a, b int) int {
|
||||||
|
|||||||
@ -165,7 +165,6 @@ func (d *Disk) PartitionCount() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Disk) CanWrite() bool {
|
func (d *Disk) CanWrite() bool {
|
||||||
|
|
||||||
if d.Status == proto.ReadWrite || !d.RejectWrite {
|
if d.Status == proto.ReadWrite || !d.RejectWrite {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -303,7 +302,7 @@ const (
|
|||||||
|
|
||||||
func (d *Disk) checkDiskStatus() {
|
func (d *Disk) checkDiskStatus() {
|
||||||
path := path.Join(d.Path, DiskStatusFile)
|
path := path.Join(d.Path, DiskStatusFile)
|
||||||
fp, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
fp, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.triggerDiskError(err)
|
d.triggerDiskError(err)
|
||||||
return
|
return
|
||||||
@ -355,7 +354,6 @@ func (d *Disk) updateSpaceInfo() (err error) {
|
|||||||
|
|
||||||
} else if d.Available <= 0 {
|
} else if d.Available <= 0 {
|
||||||
d.Status = proto.ReadOnly
|
d.Status = proto.ReadOnly
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
d.Status = proto.ReadWrite
|
d.Status = proto.ReadWrite
|
||||||
}
|
}
|
||||||
@ -441,7 +439,7 @@ func (d *Disk) isExpiredPartitionDir(filename string) (isExpiredPartitionDir boo
|
|||||||
|
|
||||||
// RestorePartition reads the files stored on the local disk and restores the data partitions.
|
// RestorePartition reads the files stored on the local disk and restores the data partitions.
|
||||||
func (d *Disk) RestorePartition(visitor PartitionVisitor) (err error) {
|
func (d *Disk) RestorePartition(visitor PartitionVisitor) (err error) {
|
||||||
var convert = func(node *proto.DataNodeInfo) *DataNodeInfo {
|
convert := func(node *proto.DataNodeInfo) *DataNodeInfo {
|
||||||
result := &DataNodeInfo{}
|
result := &DataNodeInfo{}
|
||||||
result.Addr = node.Addr
|
result.Addr = node.Addr
|
||||||
result.PersistenceDataPartitions = node.PersistenceDataPartitions
|
result.PersistenceDataPartitions = node.PersistenceDataPartitions
|
||||||
@ -525,7 +523,6 @@ func (d *Disk) RestorePartition(visitor PartitionVisitor) (err error) {
|
|||||||
if visitor != nil {
|
if visitor != nil {
|
||||||
visitor(dp)
|
visitor(dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
}(partitionID, filename)
|
}(partitionID, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,9 +16,10 @@ package datanode
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/util/exporter"
|
"github.com/cubefs/cubefs/util/exporter"
|
||||||
"github.com/cubefs/cubefs/util/log"
|
"github.com/cubefs/cubefs/util/log"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -18,9 +18,7 @@ const (
|
|||||||
MaxRepairErrCnt = 1000
|
MaxRepairErrCnt = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var nodeInfoStopC = make(chan struct{}, 0)
|
||||||
nodeInfoStopC = make(chan struct{}, 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
func (m *DataNode) startUpdateNodeInfo() {
|
func (m *DataNode) startUpdateNodeInfo() {
|
||||||
ticker := time.NewTicker(UpdateNodeInfoTicket)
|
ticker := time.NewTicker(UpdateNodeInfoTicket)
|
||||||
|
|||||||
@ -17,28 +17,26 @@ package datanode
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hash/crc32"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/util"
|
|
||||||
|
|
||||||
"hash/crc32"
|
|
||||||
"net"
|
|
||||||
"sort"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
raftProto "github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
|
raftProto "github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
"github.com/cubefs/cubefs/raftstore"
|
"github.com/cubefs/cubefs/raftstore"
|
||||||
"github.com/cubefs/cubefs/repl"
|
"github.com/cubefs/cubefs/repl"
|
||||||
"github.com/cubefs/cubefs/storage"
|
"github.com/cubefs/cubefs/storage"
|
||||||
|
"github.com/cubefs/cubefs/util"
|
||||||
"github.com/cubefs/cubefs/util/errors"
|
"github.com/cubefs/cubefs/util/errors"
|
||||||
"github.com/cubefs/cubefs/util/exporter"
|
"github.com/cubefs/cubefs/util/exporter"
|
||||||
"github.com/cubefs/cubefs/util/log"
|
"github.com/cubefs/cubefs/util/log"
|
||||||
@ -150,9 +148,9 @@ type DataPartition struct {
|
|||||||
verSeqPrepare uint64
|
verSeqPrepare uint64
|
||||||
verSeqCommitStatus int8
|
verSeqCommitStatus int8
|
||||||
multiVersionList []*MetaMultiSnapshotInfo
|
multiVersionList []*MetaMultiSnapshotInfo
|
||||||
decommissionRepairProgress float64 //record repair progress for decommission datapartition
|
decommissionRepairProgress float64 // record repair progress for decommission datapartition
|
||||||
stopRecover bool
|
stopRecover bool
|
||||||
recoverErrCnt uint64 //donot reset, if reach max err cnt, delete this dp
|
recoverErrCnt uint64 // donot reset, if reach max err cnt, delete this dp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) IsForbidden() bool {
|
func (dp *DataPartition) IsForbidden() bool {
|
||||||
@ -164,7 +162,6 @@ func (dp *DataPartition) SetForbidden(status bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateDataPartition(dpCfg *dataPartitionCfg, disk *Disk, request *proto.CreateDataPartitionRequest) (dp *DataPartition, err error) {
|
func CreateDataPartition(dpCfg *dataPartitionCfg, disk *Disk, request *proto.CreateDataPartitionRequest) (dp *DataPartition, err error) {
|
||||||
|
|
||||||
if dp, err = newDataPartition(dpCfg, disk, true); err != nil {
|
if dp, err = newDataPartition(dpCfg, disk, true); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -174,7 +171,7 @@ func CreateDataPartition(dpCfg *dataPartitionCfg, disk *Disk, request *proto.Cre
|
|||||||
} else {
|
} else {
|
||||||
// init leaderSize to partitionSize
|
// init leaderSize to partitionSize
|
||||||
disk.updateDisk(uint64(request.LeaderSize))
|
disk.updateDisk(uint64(request.LeaderSize))
|
||||||
//ensure heartbeat report Recovering
|
// ensure heartbeat report Recovering
|
||||||
dp.partitionStatus = proto.Recovering
|
dp.partitionStatus = proto.Recovering
|
||||||
go dp.StartRaftAfterRepair(false)
|
go dp.StartRaftAfterRepair(false)
|
||||||
}
|
}
|
||||||
@ -238,9 +235,7 @@ func (dp *DataPartition) ForceSetRaftRunning() {
|
|||||||
// It reads the partition metadata file stored under the specified directory
|
// It reads the partition metadata file stored under the specified directory
|
||||||
// and creates the partition instance.
|
// and creates the partition instance.
|
||||||
func LoadDataPartition(partitionDir string, disk *Disk) (dp *DataPartition, err error) {
|
func LoadDataPartition(partitionDir string, disk *Disk) (dp *DataPartition, err error) {
|
||||||
var (
|
var metaFileData []byte
|
||||||
metaFileData []byte
|
|
||||||
)
|
|
||||||
if metaFileData, err = ioutil.ReadFile(path.Join(partitionDir, DataPartitionMetadataFileName)); err != nil {
|
if metaFileData, err = ioutil.ReadFile(path.Join(partitionDir, DataPartitionMetadataFileName)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -548,7 +543,7 @@ func (dp *DataPartition) PersistMetadata() (err error) {
|
|||||||
metaData []byte
|
metaData []byte
|
||||||
)
|
)
|
||||||
fileName := path.Join(dp.Path(), TempMetadataFileName)
|
fileName := path.Join(dp.Path(), TempMetadataFileName)
|
||||||
if metadataFile, err = os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0666); err != nil {
|
if metadataFile, err = os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0o666); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -557,8 +552,8 @@ func (dp *DataPartition) PersistMetadata() (err error) {
|
|||||||
os.Remove(fileName)
|
os.Remove(fileName)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//sp := sortedPeers(dp.config.Peers)
|
// sp := sortedPeers(dp.config.Peers)
|
||||||
//sort.Sort(sp)
|
// sort.Sort(sp)
|
||||||
|
|
||||||
md := &DataPartitionMetadata{
|
md := &DataPartitionMetadata{
|
||||||
VolumeID: dp.config.VolName,
|
VolumeID: dp.config.VolName,
|
||||||
@ -583,6 +578,7 @@ func (dp *DataPartition) PersistMetadata() (err error) {
|
|||||||
err = os.Rename(fileName, path.Join(dp.Path(), DataPartitionMetadataFileName))
|
err = os.Rename(fileName, path.Join(dp.Path(), DataPartitionMetadataFileName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) statusUpdateScheduler() {
|
func (dp *DataPartition) statusUpdateScheduler() {
|
||||||
ticker := time.NewTicker(time.Minute)
|
ticker := time.NewTicker(time.Minute)
|
||||||
snapshotTicker := time.NewTicker(time.Minute * 5)
|
snapshotTicker := time.NewTicker(time.Minute * 5)
|
||||||
@ -628,7 +624,7 @@ func (dp *DataPartition) statusUpdate() {
|
|||||||
status = proto.ReadOnly
|
status = proto.ReadOnly
|
||||||
}
|
}
|
||||||
if dp.isNormalType() && dp.raftStatus == RaftStatusStopped {
|
if dp.isNormalType() && dp.raftStatus == RaftStatusStopped {
|
||||||
//dp is still recovering
|
// dp is still recovering
|
||||||
if dp.DataPartitionCreateType == proto.DecommissionedCreateDataPartition {
|
if dp.DataPartitionCreateType == proto.DecommissionedCreateDataPartition {
|
||||||
status = proto.Recovering
|
status = proto.Recovering
|
||||||
} else {
|
} else {
|
||||||
@ -645,9 +641,7 @@ func parseFileName(filename string) (extentID uint64, isExtent bool) {
|
|||||||
if isExtent = storage.RegexpExtentFile.MatchString(filename); !isExtent {
|
if isExtent = storage.RegexpExtentFile.MatchString(filename); !isExtent {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
if extentID, err = strconv.ParseUint(filename, 10, 64); err != nil {
|
if extentID, err = strconv.ParseUint(filename, 10, 64); err != nil {
|
||||||
isExtent = false
|
isExtent = false
|
||||||
return
|
return
|
||||||
@ -778,9 +772,8 @@ func (dp *DataPartition) compareReplicas(v1, v2 []string) (equals bool) {
|
|||||||
|
|
||||||
// Fetch the replica information from the master.
|
// Fetch the replica information from the master.
|
||||||
func (dp *DataPartition) fetchReplicasFromMaster() (isLeader bool, replicas []string, err error) {
|
func (dp *DataPartition) fetchReplicasFromMaster() (isLeader bool, replicas []string, err error) {
|
||||||
|
|
||||||
var partition *proto.DataPartitionInfo
|
var partition *proto.DataPartitionInfo
|
||||||
var retry = 0
|
retry := 0
|
||||||
for {
|
for {
|
||||||
if partition, err = MasterClient.AdminAPI().GetDataPartition(dp.volumeID, dp.partitionID); err != nil {
|
if partition, err = MasterClient.AdminAPI().GetDataPartition(dp.volumeID, dp.partitionID); err != nil {
|
||||||
retry++
|
retry++
|
||||||
@ -983,7 +976,7 @@ func (dp *DataPartition) doStreamFixTinyDeleteRecord(repairTask *DataPartitionRe
|
|||||||
}
|
}
|
||||||
DeleteLimiterWait()
|
DeleteLimiterWait()
|
||||||
dp.disk.allocCheckLimit(proto.IopsWriteType, 1)
|
dp.disk.allocCheckLimit(proto.IopsWriteType, 1)
|
||||||
//log.LogInfof("doStreamFixTinyDeleteRecord Delete PartitionID(%v)_Extent(%v)_Offset(%v)_Size(%v)", dp.partitionID, extentID, offset, size)
|
// log.LogInfof("doStreamFixTinyDeleteRecord Delete PartitionID(%v)_Extent(%v)_Offset(%v)_Size(%v)", dp.partitionID, extentID, offset, size)
|
||||||
store.MarkDelete(extentID, int64(offset), int64(size))
|
store.MarkDelete(extentID, int64(offset), int64(size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -997,7 +990,7 @@ func (dp *DataPartition) ChangeRaftMember(changeType raftProto.ConfChangeType, p
|
|||||||
|
|
||||||
func (dp *DataPartition) canRemoveSelf() (canRemove bool, err error) {
|
func (dp *DataPartition) canRemoveSelf() (canRemove bool, err error) {
|
||||||
var partition *proto.DataPartitionInfo
|
var partition *proto.DataPartitionInfo
|
||||||
var retry = 0
|
retry := 0
|
||||||
for {
|
for {
|
||||||
if partition, err = MasterClient.AdminAPI().GetDataPartition(dp.volumeID, dp.partitionID); err != nil {
|
if partition, err = MasterClient.AdminAPI().GetDataPartition(dp.volumeID, dp.partitionID); err != nil {
|
||||||
log.LogErrorf("action[canRemoveSelf] err[%v]", err)
|
log.LogErrorf("action[canRemoveSelf] err[%v]", err)
|
||||||
@ -1167,7 +1160,6 @@ func (dp *DataPartition) doExtentEvict(vv *proto.SimpleVolView) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) startEvict() {
|
func (dp *DataPartition) startEvict() {
|
||||||
@ -1248,27 +1240,27 @@ func getWithDefault(base, def int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) StopDecommissionRecover(stop bool) {
|
func (dp *DataPartition) StopDecommissionRecover(stop bool) {
|
||||||
//only work for decommission repair
|
// only work for decommission repair
|
||||||
if !dp.isDecommissionRecovering() {
|
if !dp.isDecommissionRecovering() {
|
||||||
log.LogWarnf("[StopDecommissionRecover] dp(%d) is not in recovering status: type %d status %d",
|
log.LogWarnf("[StopDecommissionRecover] dp(%d) is not in recovering status: type %d status %d",
|
||||||
dp.partitionID, dp.partitionType, dp.Status())
|
dp.partitionID, dp.partitionType, dp.Status())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//for check timeout
|
// for check timeout
|
||||||
dp.stopRecover = stop
|
dp.stopRecover = stop
|
||||||
dp.PersistMetadata()
|
dp.PersistMetadata()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) isDecommissionRecovering() bool {
|
func (dp *DataPartition) isDecommissionRecovering() bool {
|
||||||
//decommission recover failed or success will set to normal
|
// decommission recover failed or success will set to normal
|
||||||
return dp.DataPartitionCreateType == proto.DecommissionedCreateDataPartition
|
return dp.DataPartitionCreateType == proto.DecommissionedCreateDataPartition
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) handleDecommissionRecoverFailed() {
|
func (dp *DataPartition) handleDecommissionRecoverFailed() {
|
||||||
if !dp.isDecommissionRecovering() {
|
if !dp.isDecommissionRecovering() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//prevent status changing from Unavailable to Recovering again in statusUpdate()
|
// prevent status changing from Unavailable to Recovering again in statusUpdate()
|
||||||
dp.partitionType = proto.NormalCreateDataPartition
|
dp.partitionType = proto.NormalCreateDataPartition
|
||||||
dp.partitionStatus = proto.Unavailable
|
dp.partitionStatus = proto.Unavailable
|
||||||
log.LogWarnf("[handleDecommissionRecoverFailed] dp(%d) recover failed reach max limit", dp.partitionID)
|
log.LogWarnf("[handleDecommissionRecoverFailed] dp(%d) recover failed reach max limit", dp.partitionID)
|
||||||
|
|||||||
@ -19,14 +19,15 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
"github.com/cubefs/cubefs/repl"
|
"github.com/cubefs/cubefs/repl"
|
||||||
"github.com/cubefs/cubefs/storage"
|
"github.com/cubefs/cubefs/storage"
|
||||||
"github.com/cubefs/cubefs/util/exporter"
|
"github.com/cubefs/cubefs/util/exporter"
|
||||||
"github.com/cubefs/cubefs/util/log"
|
"github.com/cubefs/cubefs/util/log"
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RaftCmdItem struct {
|
type RaftCmdItem struct {
|
||||||
@ -187,7 +188,6 @@ type ItemIterator struct {
|
|||||||
|
|
||||||
// NewItemIterator creates a new item iterator.
|
// NewItemIterator creates a new item iterator.
|
||||||
func NewItemIterator(applyID uint64) *ItemIterator {
|
func NewItemIterator(applyID uint64) *ItemIterator {
|
||||||
|
|
||||||
si := new(ItemIterator)
|
si := new(ItemIterator)
|
||||||
si.applyID = applyID
|
si.applyID = applyID
|
||||||
return si
|
return si
|
||||||
@ -299,9 +299,7 @@ func (dp *DataPartition) RandomWriteSubmit(pkg *repl.Packet) (err error) {
|
|||||||
log.LogErrorf("action[RandomWriteSubmit] [%v] marshal error %v", dp.partitionID, err)
|
log.LogErrorf("action[RandomWriteSubmit] [%v] marshal error %v", dp.partitionID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var (
|
var resp interface{}
|
||||||
resp interface{}
|
|
||||||
)
|
|
||||||
resp, err = dp.Put(nil, val)
|
resp, err = dp.Put(nil, val)
|
||||||
pkg.ResultCode, _ = resp.(uint8)
|
pkg.ResultCode, _ = resp.(uint8)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -77,7 +77,6 @@ func (dp *DataPartition) raftPort() (heartbeat, replica int, err error) {
|
|||||||
|
|
||||||
// StartRaft start raft instance when data partition start or restore.
|
// StartRaft start raft instance when data partition start or restore.
|
||||||
func (dp *DataPartition) StartRaft(isLoad bool) (err error) {
|
func (dp *DataPartition) StartRaft(isLoad bool) (err error) {
|
||||||
|
|
||||||
// cache or preload partition not support raft and repair.
|
// cache or preload partition not support raft and repair.
|
||||||
if !dp.isNormalType() {
|
if !dp.isNormalType() {
|
||||||
return nil
|
return nil
|
||||||
@ -173,7 +172,7 @@ func (dp *DataPartition) CanRemoveRaftMember(peer proto.Peer, force bool) error
|
|||||||
if nodeID.NodeID == peer.ID {
|
if nodeID.NodeID == peer.ID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//check nodeID is valid
|
// check nodeID is valid
|
||||||
hasDownReplicasExcludePeer = append(hasDownReplicasExcludePeer, nodeID.NodeID)
|
hasDownReplicasExcludePeer = append(hasDownReplicasExcludePeer, nodeID.NodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +200,6 @@ func (dp *DataPartition) CanRemoveRaftMember(peer proto.Peer, force bool) error
|
|||||||
// 2. collect the applied ids from raft members.
|
// 2. collect the applied ids from raft members.
|
||||||
// 3. based on the minimum applied id to cutoff and delete the saved raft log in order to free the disk space.
|
// 3. based on the minimum applied id to cutoff and delete the saved raft log in order to free the disk space.
|
||||||
func (dp *DataPartition) StartRaftLoggingSchedule() {
|
func (dp *DataPartition) StartRaftLoggingSchedule() {
|
||||||
|
|
||||||
// cache or preload partition not support raft and repair.
|
// cache or preload partition not support raft and repair.
|
||||||
if !dp.isNormalType() {
|
if !dp.isNormalType() {
|
||||||
return
|
return
|
||||||
@ -360,7 +358,6 @@ func (dp *DataPartition) StartRaftAfterRepair(isLoad bool) {
|
|||||||
|
|
||||||
// Add a raft node.
|
// Add a raft node.
|
||||||
func (dp *DataPartition) addRaftNode(req *proto.AddDataPartitionRaftMemberRequest, index uint64) (isUpdated bool, err error) {
|
func (dp *DataPartition) addRaftNode(req *proto.AddDataPartitionRaftMemberRequest, index uint64) (isUpdated bool, err error) {
|
||||||
|
|
||||||
// cache or preload partition not support raft and repair.
|
// cache or preload partition not support raft and repair.
|
||||||
if !dp.isNormalType() {
|
if !dp.isNormalType() {
|
||||||
return false, fmt.Errorf("addRaftNode (%v) not support", dp)
|
return false, fmt.Errorf("addRaftNode (%v) not support", dp)
|
||||||
@ -401,7 +398,6 @@ func (dp *DataPartition) addRaftNode(req *proto.AddDataPartitionRaftMemberReques
|
|||||||
|
|
||||||
// Delete a raft node.
|
// Delete a raft node.
|
||||||
func (dp *DataPartition) removeRaftNode(req *proto.RemoveDataPartitionRaftMemberRequest, index uint64) (isUpdated bool, err error) {
|
func (dp *DataPartition) removeRaftNode(req *proto.RemoveDataPartitionRaftMemberRequest, index uint64) (isUpdated bool, err error) {
|
||||||
|
|
||||||
// cache or preload partition not support raft and repair.
|
// cache or preload partition not support raft and repair.
|
||||||
if !dp.isNormalType() {
|
if !dp.isNormalType() {
|
||||||
return false, fmt.Errorf("removeRaftNode (%v) not support", dp)
|
return false, fmt.Errorf("removeRaftNode (%v) not support", dp)
|
||||||
@ -459,7 +455,7 @@ func (dp *DataPartition) removeRaftNode(req *proto.RemoveDataPartitionRaftMember
|
|||||||
|
|
||||||
func (dp *DataPartition) storeAppliedID(applyIndex uint64) (err error) {
|
func (dp *DataPartition) storeAppliedID(applyIndex uint64) (err error) {
|
||||||
filename := path.Join(dp.Path(), TempApplyIndexFile)
|
filename := path.Join(dp.Path(), TempApplyIndexFile)
|
||||||
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_TRUNC|os.O_CREATE, 0755)
|
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_TRUNC|os.O_CREATE, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -538,14 +534,14 @@ func (s *DataNode) startRaftServer(cfg *config.Config) (err error) {
|
|||||||
RaftHeartbetPort: s.raftHeartbeat,
|
RaftHeartbetPort: s.raftHeartbeat,
|
||||||
RaftReplicaPort: s.raftReplica,
|
RaftReplicaPort: s.raftReplica,
|
||||||
}
|
}
|
||||||
var ok = false
|
ok := false
|
||||||
if ok, err = config.CheckOrStoreConstCfg(s.raftDir, config.DefaultConstConfigFile, &constCfg); !ok {
|
if ok, err = config.CheckOrStoreConstCfg(s.raftDir, config.DefaultConstConfigFile, &constCfg); !ok {
|
||||||
log.LogErrorf("constCfg check failed %v %v %v %v", s.raftDir, config.DefaultConstConfigFile, constCfg, err)
|
log.LogErrorf("constCfg check failed %v %v %v %v", s.raftDir, config.DefaultConstConfigFile, constCfg, err)
|
||||||
return fmt.Errorf("constCfg check failed %v %v %v %v", s.raftDir, config.DefaultConstConfigFile, constCfg, err)
|
return fmt.Errorf("constCfg check failed %v %v %v %v", s.raftDir, config.DefaultConstConfigFile, constCfg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = os.Stat(s.raftDir); err != nil {
|
if _, err = os.Stat(s.raftDir); err != nil {
|
||||||
if err = os.MkdirAll(s.raftDir, 0755); err != nil {
|
if err = os.MkdirAll(s.raftDir, 0o755); err != nil {
|
||||||
err = errors.NewErrorf("create raft server dir: %s", err.Error())
|
err = errors.NewErrorf("create raft server dir: %s", err.Error())
|
||||||
log.LogErrorf("action[startRaftServer] cannot start raft server err(%v)", err)
|
log.LogErrorf("action[startRaftServer] cannot start raft server err(%v)", err)
|
||||||
return
|
return
|
||||||
@ -655,14 +651,12 @@ func (dp *DataPartition) findMaxAppliedID(allAppliedIDs []uint64) (maxAppliedID
|
|||||||
|
|
||||||
// Get the partition size from the leader.
|
// Get the partition size from the leader.
|
||||||
func (dp *DataPartition) getLeaderPartitionSize(maxExtentID uint64) (size uint64, err error) {
|
func (dp *DataPartition) getLeaderPartitionSize(maxExtentID uint64) (size uint64, err error) {
|
||||||
var (
|
var conn *net.TCPConn
|
||||||
conn *net.TCPConn
|
|
||||||
)
|
|
||||||
|
|
||||||
p := NewPacketToGetPartitionSize(dp.partitionID)
|
p := NewPacketToGetPartitionSize(dp.partitionID)
|
||||||
p.ExtentID = maxExtentID
|
p.ExtentID = maxExtentID
|
||||||
target := dp.getReplicaAddr(0)
|
target := dp.getReplicaAddr(0)
|
||||||
conn, err = gConnPool.GetConnect(target) //get remote connect
|
conn, err = gConnPool.GetConnect(target) // get remote connect
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Trace(err, " partition(%v) get host(%v) connect", dp.partitionID, target)
|
err = errors.Trace(err, " partition(%v) get host(%v) connect", dp.partitionID, target)
|
||||||
return
|
return
|
||||||
@ -692,12 +686,10 @@ func (dp *DataPartition) getLeaderPartitionSize(maxExtentID uint64) (size uint64
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dp *DataPartition) getMaxExtentIDAndPartitionSize(target string) (maxExtentID, PartitionSize uint64, err error) {
|
func (dp *DataPartition) getMaxExtentIDAndPartitionSize(target string) (maxExtentID, PartitionSize uint64, err error) {
|
||||||
var (
|
var conn *net.TCPConn
|
||||||
conn *net.TCPConn
|
|
||||||
)
|
|
||||||
p := NewPacketToGetMaxExtentIDAndPartitionSIze(dp.partitionID)
|
p := NewPacketToGetMaxExtentIDAndPartitionSIze(dp.partitionID)
|
||||||
|
|
||||||
conn, err = gConnPool.GetConnect(target) //get remote connect
|
conn, err = gConnPool.GetConnect(target) // get remote connect
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Trace(err, " partition(%v) get host(%v) connect", dp.partitionID, target)
|
err = errors.Trace(err, " partition(%v) get host(%v) connect", dp.partitionID, target)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -16,9 +16,11 @@ package datanode
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -26,11 +28,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
|
||||||
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/cmd/common"
|
"github.com/cubefs/cubefs/cmd/common"
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
@ -55,7 +54,7 @@ var (
|
|||||||
|
|
||||||
LocalIP, serverPort string
|
LocalIP, serverPort string
|
||||||
gConnPool = util.NewConnectPool()
|
gConnPool = util.NewConnectPool()
|
||||||
//MasterClient = masterSDK.NewMasterClient(nil, false)
|
// MasterClient = masterSDK.NewMasterClient(nil, false)
|
||||||
MasterClient *masterSDK.MasterCLientWithResolver
|
MasterClient *masterSDK.MasterCLientWithResolver
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -99,15 +98,15 @@ const (
|
|||||||
|
|
||||||
CfgDiskRdonlySpace = "diskRdonlySpace" // int
|
CfgDiskRdonlySpace = "diskRdonlySpace" // int
|
||||||
// smux Config
|
// smux Config
|
||||||
ConfigKeyEnableSmuxClient = "enableSmuxConnPool" //bool
|
ConfigKeyEnableSmuxClient = "enableSmuxConnPool" // bool
|
||||||
ConfigKeySmuxPortShift = "smuxPortShift" //int
|
ConfigKeySmuxPortShift = "smuxPortShift" // int
|
||||||
ConfigKeySmuxMaxConn = "smuxMaxConn" //int
|
ConfigKeySmuxMaxConn = "smuxMaxConn" // int
|
||||||
ConfigKeySmuxStreamPerConn = "smuxStreamPerConn" //int
|
ConfigKeySmuxStreamPerConn = "smuxStreamPerConn" // int
|
||||||
ConfigKeySmuxMaxBuffer = "smuxMaxBuffer" //int
|
ConfigKeySmuxMaxBuffer = "smuxMaxBuffer" // int
|
||||||
ConfigKeySmuxTotalStream = "sumxTotalStream" //int
|
ConfigKeySmuxTotalStream = "sumxTotalStream" // int
|
||||||
|
|
||||||
//rate limit control enable
|
// rate limit control enable
|
||||||
ConfigDiskQosEnable = "diskQosEnable" //bool
|
ConfigDiskQosEnable = "diskQosEnable" // bool
|
||||||
|
|
||||||
ConfigServiceIDKey = "serviceIDKey"
|
ConfigServiceIDKey = "serviceIDKey"
|
||||||
)
|
)
|
||||||
@ -148,7 +147,7 @@ type DataNode struct {
|
|||||||
metrics *DataNodeMetrics
|
metrics *DataNodeMetrics
|
||||||
metricsDegrade int64
|
metricsDegrade int64
|
||||||
metricsCnt uint64
|
metricsCnt uint64
|
||||||
volUpdating sync.Map //map[string]*verOp2Phase
|
volUpdating sync.Map // map[string]*verOp2Phase
|
||||||
|
|
||||||
control common.Control
|
control common.Control
|
||||||
|
|
||||||
@ -213,11 +212,11 @@ func doStart(server common.Server, cfg *config.Config) (err error) {
|
|||||||
s.registerMetrics()
|
s.registerMetrics()
|
||||||
s.register(cfg)
|
s.register(cfg)
|
||||||
|
|
||||||
//parse the smux config
|
// parse the smux config
|
||||||
if err = s.parseSmuxConfig(cfg); err != nil {
|
if err = s.parseSmuxConfig(cfg); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//connection pool must be created before initSpaceManager
|
// connection pool must be created before initSpaceManager
|
||||||
s.initConnPool()
|
s.initConnPool()
|
||||||
|
|
||||||
// init limit
|
// init limit
|
||||||
@ -245,7 +244,7 @@ func doStart(server common.Server, cfg *config.Config) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//smux listening & smux connection pool
|
// smux listening & smux connection pool
|
||||||
if err = s.startSmuxService(cfg); err != nil {
|
if err = s.startSmuxService(cfg); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -349,6 +348,7 @@ func (s *DataNode) updateQosLimit() {
|
|||||||
disk.updateQosLimiter()
|
disk.updateQosLimiter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) startSpaceManager(cfg *config.Config) (err error) {
|
func (s *DataNode) startSpaceManager(cfg *config.Config) (err error) {
|
||||||
s.startTime = time.Now().Unix()
|
s.startTime = time.Now().Unix()
|
||||||
s.space = NewSpaceManager(s)
|
s.space = NewSpaceManager(s)
|
||||||
@ -464,9 +464,7 @@ func parseDiskPath(pathStr string) (disks []string, err error) {
|
|||||||
// registers the data node on the master to report the information such as IsIPV4 address.
|
// registers the data node on the master to report the information such as IsIPV4 address.
|
||||||
// The startup of a data node will be blocked until the registration succeeds.
|
// The startup of a data node will be blocked until the registration succeeds.
|
||||||
func (s *DataNode) register(cfg *config.Config) {
|
func (s *DataNode) register(cfg *config.Config) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
timer := time.NewTimer(0)
|
timer := time.NewTimer(0)
|
||||||
|
|
||||||
@ -522,7 +520,7 @@ type DataNodeInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) checkLocalPartitionMatchWithMaster() (lackPartitions []uint64, err error) {
|
func (s *DataNode) checkLocalPartitionMatchWithMaster() (lackPartitions []uint64, err error) {
|
||||||
var convert = func(node *proto.DataNodeInfo) *DataNodeInfo {
|
convert := func(node *proto.DataNodeInfo) *DataNodeInfo {
|
||||||
result := &DataNodeInfo{}
|
result := &DataNodeInfo{}
|
||||||
result.Addr = node.Addr
|
result.Addr = node.Addr
|
||||||
result.PersistenceDataPartitions = node.PersistenceDataPartitions
|
result.PersistenceDataPartitions = node.PersistenceDataPartitions
|
||||||
@ -770,7 +768,7 @@ func (s *DataNode) parseSmuxConfig(cfg *config.Config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//smux conn pool config
|
// smux conn pool config
|
||||||
if s.enableSmuxConnPool {
|
if s.enableSmuxConnPool {
|
||||||
s.smuxConnPoolConfig = util.DefaultSmuxConnPoolConfig()
|
s.smuxConnPoolConfig = util.DefaultSmuxConnPoolConfig()
|
||||||
if maxBuffer > 0 {
|
if maxBuffer > 0 {
|
||||||
|
|||||||
@ -17,7 +17,6 @@ package datanode
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cubefs/cubefs/util/config"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -27,11 +26,10 @@ import (
|
|||||||
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
"github.com/cubefs/cubefs/storage"
|
"github.com/cubefs/cubefs/storage"
|
||||||
|
"github.com/cubefs/cubefs/util/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var AutoRepairStatus = true
|
||||||
AutoRepairStatus = true
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *DataNode) getDiskAPI(w http.ResponseWriter, r *http.Request) {
|
func (s *DataNode) getDiskAPI(w http.ResponseWriter, r *http.Request) {
|
||||||
disks := make([]interface{}, 0)
|
disks := make([]interface{}, 0)
|
||||||
|
|||||||
@ -16,11 +16,10 @@ package datanode
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
"github.com/cubefs/cubefs/raftstore"
|
"github.com/cubefs/cubefs/raftstore"
|
||||||
@ -75,7 +74,7 @@ func (manager *SpaceManager) Stop() {
|
|||||||
close(manager.samplerDone)
|
close(manager.samplerDone)
|
||||||
// Parallel stop data partitions.
|
// Parallel stop data partitions.
|
||||||
const maxParallelism = 128
|
const maxParallelism = 128
|
||||||
var parallelism = int(math.Min(float64(maxParallelism), float64(len(manager.partitions))))
|
parallelism := int(math.Min(float64(maxParallelism), float64(len(manager.partitions))))
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
partitionC := make(chan *DataPartition, parallelism)
|
partitionC := make(chan *DataPartition, parallelism)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@ -182,6 +181,7 @@ func (manager *SpaceManager) GetClusterID() (clusterID string) {
|
|||||||
func (manager *SpaceManager) SetRaftStore(raftStore raftstore.RaftStore) {
|
func (manager *SpaceManager) SetRaftStore(raftStore raftstore.RaftStore) {
|
||||||
manager.raftStore = raftStore
|
manager.raftStore = raftStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SpaceManager) GetRaftStore() (raftStore raftstore.RaftStore) {
|
func (manager *SpaceManager) GetRaftStore() (raftStore raftstore.RaftStore) {
|
||||||
return manager.raftStore
|
return manager.raftStore
|
||||||
}
|
}
|
||||||
@ -345,6 +345,7 @@ func (manager *SpaceManager) minPartitionCnt(decommissionedDisks []string) (d *D
|
|||||||
d = minWeightDisk
|
d = minWeightDisk
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SpaceManager) statUpdateScheduler() {
|
func (manager *SpaceManager) statUpdateScheduler() {
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
@ -420,7 +421,6 @@ func (manager *SpaceManager) CreatePartition(request *proto.CreateDataPartitionR
|
|||||||
|
|
||||||
// DeletePartition deletes a partition based on the partition id.
|
// DeletePartition deletes a partition based on the partition id.
|
||||||
func (manager *SpaceManager) DeletePartition(dpID uint64) {
|
func (manager *SpaceManager) DeletePartition(dpID uint64) {
|
||||||
|
|
||||||
manager.partitionMutex.Lock()
|
manager.partitionMutex.Lock()
|
||||||
|
|
||||||
dp := manager.partitions[dpID]
|
dp := manager.partitions[dpID]
|
||||||
|
|||||||
@ -19,14 +19,13 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hash/crc32"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hash/crc32"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
||||||
raftProto "github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
|
raftProto "github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
@ -38,9 +37,7 @@ import (
|
|||||||
"github.com/cubefs/cubefs/util/log"
|
"github.com/cubefs/cubefs/util/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrForbiddenDataPartition = errors.New("the data partition is forbidden")
|
||||||
ErrForbiddenDataPartition = errors.New("the data partition is forbidden")
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *DataNode) getPacketTpLabels(p *repl.Packet) map[string]string {
|
func (s *DataNode) getPacketTpLabels(p *repl.Packet) map[string]string {
|
||||||
labels := make(map[string]string)
|
labels := make(map[string]string)
|
||||||
@ -268,7 +265,6 @@ func (s *DataNode) handlePacketToCreateDataPartition(p *repl.Packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) commitCreateVersion(volumeID string, verSeq uint64) (err error) {
|
func (s *DataNode) commitCreateVersion(volumeID string, verSeq uint64) (err error) {
|
||||||
|
|
||||||
for _, dp := range s.space.partitions {
|
for _, dp := range s.space.partitions {
|
||||||
if dp.volumeID != volumeID {
|
if dp.volumeID != volumeID {
|
||||||
continue
|
continue
|
||||||
@ -305,9 +301,7 @@ func (s *DataNode) commitCreateVersion(volumeID string, verSeq uint64) (err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) prepareCreateVersion(req *proto.MultiVersionOpRequest) (err error, opAagin bool) {
|
func (s *DataNode) prepareCreateVersion(req *proto.MultiVersionOpRequest) (err error, opAagin bool) {
|
||||||
var (
|
var ver2Phase *verOp2Phase
|
||||||
ver2Phase *verOp2Phase
|
|
||||||
)
|
|
||||||
if value, ok := s.volUpdating.Load(req.VolumeID); ok {
|
if value, ok := s.volUpdating.Load(req.VolumeID); ok {
|
||||||
ver2Phase = value.(*verOp2Phase)
|
ver2Phase = value.(*verOp2Phase)
|
||||||
if req.VerSeq < ver2Phase.verSeq {
|
if req.VerSeq < ver2Phase.verSeq {
|
||||||
@ -451,7 +445,6 @@ func (s *DataNode) handleUpdateVerPacket(p *repl.Packet) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) checkVolumeForbidden(volNames []string) {
|
func (s *DataNode) checkVolumeForbidden(volNames []string) {
|
||||||
@ -545,7 +538,6 @@ func (s *DataNode) handleHeartbeatPacket(p *repl.Packet) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle OpDeleteDataPartition packet.
|
// Handle OpDeleteDataPartition packet.
|
||||||
@ -580,15 +572,12 @@ func (s *DataNode) handlePacketToDeleteDataPartition(p *repl.Packet) {
|
|||||||
log.LogErrorf("action[handlePacketToDeleteDataPartition] err(%v).", err)
|
log.LogErrorf("action[handlePacketToDeleteDataPartition] err(%v).", err)
|
||||||
}
|
}
|
||||||
log.LogInfof(fmt.Sprintf("action[handlePacketToDeleteDataPartition] %v error(%v)", request.PartitionId, err))
|
log.LogInfof(fmt.Sprintf("action[handlePacketToDeleteDataPartition] %v error(%v)", request.PartitionId, err))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle OpLoadDataPartition packet.
|
// Handle OpLoadDataPartition packet.
|
||||||
func (s *DataNode) handlePacketToLoadDataPartition(p *repl.Packet) {
|
func (s *DataNode) handlePacketToLoadDataPartition(p *repl.Packet) {
|
||||||
task := &proto.AdminTask{}
|
task := &proto.AdminTask{}
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.PackErrorBody(ActionLoadDataPartition, err.Error())
|
p.PackErrorBody(ActionLoadDataPartition, err.Error())
|
||||||
@ -602,9 +591,7 @@ func (s *DataNode) handlePacketToLoadDataPartition(p *repl.Packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) asyncLoadDataPartition(task *proto.AdminTask) {
|
func (s *DataNode) asyncLoadDataPartition(task *proto.AdminTask) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
request := &proto.LoadDataPartitionRequest{}
|
request := &proto.LoadDataPartitionRequest{}
|
||||||
response := &proto.LoadDataPartitionResponse{}
|
response := &proto.LoadDataPartitionResponse{}
|
||||||
if task.OpCode == proto.OpLoadDataPartition {
|
if task.OpCode == proto.OpLoadDataPartition {
|
||||||
@ -636,9 +623,7 @@ func (s *DataNode) asyncLoadDataPartition(task *proto.AdminTask) {
|
|||||||
|
|
||||||
// Handle OpMarkDelete packet.
|
// Handle OpMarkDelete packet.
|
||||||
func (s *DataNode) handleMarkDeletePacket(p *repl.Packet, c net.Conn) {
|
func (s *DataNode) handleMarkDeletePacket(p *repl.Packet, c net.Conn) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.PackErrorBody(ActionBatchMarkDelete, err.Error())
|
p.PackErrorBody(ActionBatchMarkDelete, err.Error())
|
||||||
@ -673,9 +658,7 @@ func (s *DataNode) handleMarkDeletePacket(p *repl.Packet, c net.Conn) {
|
|||||||
|
|
||||||
// Handle OpMarkDelete packet.
|
// Handle OpMarkDelete packet.
|
||||||
func (s *DataNode) handleBatchMarkDeletePacket(p *repl.Packet, c net.Conn) {
|
func (s *DataNode) handleBatchMarkDeletePacket(p *repl.Packet, c net.Conn) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorf(fmt.Sprintf("(%v) error(%v).", p.GetUniqueLogId(), err))
|
log.LogErrorf(fmt.Sprintf("(%v) error(%v).", p.GetUniqueLogId(), err))
|
||||||
@ -898,9 +881,7 @@ func (s *DataNode) handleRandomWritePacket(p *repl.Packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) handleStreamReadPacket(p *repl.Packet, connect net.Conn, isRepairRead bool) {
|
func (s *DataNode) handleStreamReadPacket(p *repl.Packet, connect net.Conn, isRepairRead bool) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.PackErrorBody(ActionStreamRead, err.Error())
|
p.PackErrorBody(ActionStreamRead, err.Error())
|
||||||
@ -924,9 +905,7 @@ func (s *DataNode) handleStreamReadPacket(p *repl.Packet, connect net.Conn, isRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) handleExtentRepairReadPacket(p *repl.Packet, connect net.Conn, isRepairRead bool) {
|
func (s *DataNode) handleExtentRepairReadPacket(p *repl.Packet, connect net.Conn, isRepairRead bool) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
log.LogDebugf("handleExtentRepairReadPacket %v", p)
|
log.LogDebugf("handleExtentRepairReadPacket %v", p)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1107,9 +1086,7 @@ func (s *DataNode) tinyExtentRepairRead(request *repl.Packet, connect net.Conn)
|
|||||||
}
|
}
|
||||||
avaliReplySize := uint64(needReplySize)
|
avaliReplySize := uint64(needReplySize)
|
||||||
|
|
||||||
var (
|
var newOffset, newEnd int64
|
||||||
newOffset, newEnd int64
|
|
||||||
)
|
|
||||||
for {
|
for {
|
||||||
if needReplySize <= 0 {
|
if needReplySize <= 0 {
|
||||||
break
|
break
|
||||||
@ -1123,9 +1100,7 @@ func (s *DataNode) tinyExtentRepairRead(request *repl.Packet, connect net.Conn)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if newOffset > offset {
|
if newOffset > offset {
|
||||||
var (
|
var replySize int64
|
||||||
replySize int64
|
|
||||||
)
|
|
||||||
if replySize, err = s.writeEmptyPacketOnTinyExtentRepairRead(reply, newOffset, offset, connect); err != nil {
|
if replySize, err = s.writeEmptyPacketOnTinyExtentRepairRead(reply, newOffset, offset, connect); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1166,9 +1141,7 @@ func (s *DataNode) tinyExtentRepairRead(request *repl.Packet, connect net.Conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) handlePacketToReadTinyDeleteRecordFile(p *repl.Packet, connect net.Conn) {
|
func (s *DataNode) handlePacketToReadTinyDeleteRecordFile(p *repl.Packet, connect net.Conn) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.PackErrorBody(ActionStreamReadTinyDeleteRecord, err.Error())
|
p.PackErrorBody(ActionStreamReadTinyDeleteRecord, err.Error())
|
||||||
@ -1214,9 +1187,7 @@ func (s *DataNode) handlePacketToReadTinyDeleteRecordFile(p *repl.Packet, connec
|
|||||||
|
|
||||||
// Handle OpNotifyReplicasToRepair packet.
|
// Handle OpNotifyReplicasToRepair packet.
|
||||||
func (s *DataNode) handlePacketToNotifyExtentRepair(p *repl.Packet) {
|
func (s *DataNode) handlePacketToNotifyExtentRepair(p *repl.Packet) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
partition := p.Object.(*DataPartition)
|
partition := p.Object.(*DataPartition)
|
||||||
mf := new(DataPartitionRepairTask)
|
mf := new(DataPartitionRepairTask)
|
||||||
err = json.Unmarshal(p.Data, mf)
|
err = json.Unmarshal(p.Data, mf)
|
||||||
@ -1485,9 +1456,7 @@ func (s *DataNode) handlePacketToRemoveDataPartitionRaftMember(p *repl.Packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataNode) handlePacketToDataPartitionTryToLeader(p *repl.Packet) {
|
func (s *DataNode) handlePacketToDataPartitionTryToLeader(p *repl.Packet) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -17,13 +17,13 @@ package datanode
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cubefs/cubefs/util/log"
|
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/cubefs/cubefs/proto"
|
"github.com/cubefs/cubefs/proto"
|
||||||
"github.com/cubefs/cubefs/repl"
|
"github.com/cubefs/cubefs/repl"
|
||||||
"github.com/cubefs/cubefs/storage"
|
"github.com/cubefs/cubefs/storage"
|
||||||
|
"github.com/cubefs/cubefs/util/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *DataNode) Prepare(p *repl.Packet) (err error) {
|
func (s *DataNode) Prepare(p *repl.Packet) (err error) {
|
||||||
@ -86,7 +86,7 @@ func (s *DataNode) checkCrc(p *repl.Packet) (err error) {
|
|||||||
func (s *DataNode) checkPartition(p *repl.Packet) (err error) {
|
func (s *DataNode) checkPartition(p *repl.Packet) (err error) {
|
||||||
dp := s.space.Partition(p.PartitionID)
|
dp := s.space.Partition(p.PartitionID)
|
||||||
if dp == nil {
|
if dp == nil {
|
||||||
//err = proto.ErrDataPartitionNotExists
|
// err = proto.ErrDataPartitionNotExists
|
||||||
err = fmt.Errorf("data partition not exists %v", p.PartitionID)
|
err = fmt.Errorf("data partition not exists %v", p.PartitionID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user