cubefs/datanode/wrap_post.go
slasher 1d84f74acd chore(format): format all code with gofumpt
Signed-off-by: slasher <shenjie1@oppo.com>
2024-01-12 14:21:16 +08:00

80 lines
1.9 KiB
Go

// Copyright 2018 The CubeFS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package datanode
import (
"sync/atomic"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/repl"
"github.com/cubefs/cubefs/storage"
)
func (s *DataNode) Post(p *repl.Packet) error {
if p.IsMasterCommand() {
p.NeedReply = true
}
if p.IsReadOperation() && p.AfterPre {
p.NeedReply = false
}
s.cleanupPkt(p)
s.addMetrics(p)
return nil
}
func (s *DataNode) cleanupPkt(p *repl.Packet) {
if p.IsMasterCommand() {
return
}
if !p.IsLeaderPacket() {
return
}
s.releaseExtent(p)
}
func (s *DataNode) releaseExtent(p *repl.Packet) {
if p == nil || !storage.IsTinyExtent(p.ExtentID) || p.ExtentID <= 0 || atomic.LoadInt32(&p.IsReleased) == IsReleased {
return
}
if !proto.IsTinyExtentType(p.ExtentType) || !p.IsLeaderPacket() || !p.IsWriteOperation() || !p.IsForwardPkt() {
return
}
if p.Object == nil {
return
}
partition := p.Object.(*DataPartition)
store := partition.ExtentStore()
if p.IsErrPacket() {
store.SendToBrokenTinyExtentC(p.ExtentID)
} else {
store.SendToAvailableTinyExtentC(p.ExtentID)
}
atomic.StoreInt32(&p.IsReleased, IsReleased)
}
func (s *DataNode) addMetrics(p *repl.Packet) {
if p.IsMasterCommand() || p.ShallDegrade() {
return
}
p.AfterTp()
if p.Object == nil {
return
}
partition := p.Object.(*DataPartition)
if partition == nil {
return
}
}