fix(revert): align and reuse the Packet struct to reduce allocated memory

This reverts commit f4c3f8aa40.

Signed-off-by: leonrayang <chl696@sina.com>
This commit is contained in:
leonrayang 2025-03-21 15:20:19 +08:00 committed by leonrayang
parent f4c3f8aa40
commit a92c8452cf
4 changed files with 6 additions and 50 deletions

View File

@ -27,10 +27,6 @@ type Packet struct {
proto.Packet
}
func ClearPacket(p *Packet) {
proto.ClearPacket(&p.Packet)
}
// NewPacketToDeleteExtent returns a new packet to delete the extent.
func NewPacketToDeleteExtent(dp *DataPartition, ext *proto.ExtentKey) (p *Packet, invalid bool) {
p = new(Packet)

View File

@ -1,12 +0,0 @@
package metanode
import "testing"
func TestClearPacket(t *testing.T) {
p := &Packet{}
p.Opcode = 3
ClearPacket(p)
if 0 != p.Opcode {
t.Fatalf("ClearPacket failed")
}
}

View File

@ -81,14 +81,13 @@ func (m *MetaNode) serveConn(conn net.Conn, stopC chan uint8) {
c.SetKeepAlive(true)
c.SetNoDelay(true)
remoteAddr := conn.RemoteAddr().String()
p := &Packet{}
for {
select {
case <-stopC:
return
default:
}
ClearPacket(p)
p := &Packet{}
if err := p.ReadFromConnWithVer(conn, proto.NoReadDeadlineTime); err != nil {
if err != io.EOF {
log.LogError("serve MetaNode: ", err.Error())

View File

@ -342,6 +342,7 @@ type Packet struct {
ExtentType uint8 // the highest bit be set while rsp to client if version not consistent then Verseq be valid
Opcode uint8
ResultCode uint8
RemainingFollowers uint8
CRC uint32
Size uint32
ArgLen uint32
@ -354,44 +355,16 @@ type Packet struct {
Data []byte
StartT int64
mesg string
RemainingFollowers uint8
HasPrepare bool
noPrefix bool
HasPrepare bool
VerSeq uint64 // only used in mod request to datanode
// protocol version of packet
// version-0: before v3.4
// version-1: from v3.4
ProtoVersion uint32
VerSeq uint64 // only used in mod request to datanode
VerList []*VolVersionInfo
}
func ClearPacket(p *Packet) {
p.Magic = 0
p.ExtentType = 0
p.Opcode = 0
p.ResultCode = 0
p.CRC = 0
p.Size = 0
p.ArgLen = 0
p.KernelOffset = 0
p.PartitionID = 0
p.ExtentID = 0
p.ExtentOffset = 0
p.ReqID = 0
p.Arg = nil
p.Data = nil
p.StartT = 0
p.mesg = ""
p.RemainingFollowers = 0
p.HasPrepare = false
p.VerSeq = 0
p.ProtoVersion = 0
p.VerList = nil
p.noPrefix = false
VerList []*VolVersionInfo
noPrefix bool
}
func IsTinyExtentType(extentType uint8) bool {