Skip to content

Commit

Permalink
meta/tkv: fix the issue that attr may be nil during dumping if the in…
Browse files Browse the repository at this point in the history
…ode (#3833)

key is missing
  • Loading branch information
SandyXSD authored Jun 20, 2023
1 parent 2b268b0 commit 4867ec4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions pkg/meta/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type DumpedAttr struct {
Nlink uint32 `json:"nlink"`
Length uint64 `json:"length"`
Rdev uint32 `json:"rdev,omitempty"`
full bool
}

type DumpedSlice struct {
Expand Down Expand Up @@ -301,6 +302,7 @@ func dumpAttr(a *Attr, d *DumpedAttr) {
} else {
d.Length = 0
}
d.full = a.Full
}

func loadAttr(d *DumpedAttr) *Attr {
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,7 @@ func (m *redisMeta) dumpEntries(es ...*DumpedEntry) error {
return err
}
if inode != TrashInode {
logger.Warnf("The entry of the inode was not found. inode: %d", inode)
logger.Errorf("Corrupt inode: %d, missing attribute", inode)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3304,7 +3304,7 @@ func (m *dbMeta) dumpEntryFast(s *xorm.Session, inode Ino, typ uint8) *DumpedEnt
e := &DumpedEntry{}
n, ok := m.snap.node[inode]
if !ok && inode != TrashInode {
logger.Warnf("The entry of the inode was not found. inode: %d", inode)
logger.Errorf("Corrupt inode: %d, missing attribute", inode)
}

attr := &Attr{Typ: typ, Nlink: 1}
Expand Down
14 changes: 9 additions & 5 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,10 @@ func (m *kvMeta) dumpDir(inode Ino, tree *DumpedEntry, bw *bufio.Writer, depth i
if m.snap != nil {
e := m.snap[inode]
entries = e.Entries
for n := range e.Entries {
for n, de := range e.Entries {
if !de.Attr.full && de.Attr.Inode != TrashInode {
logger.Errorf("Corrupt inode: %d, missing attribute", inode)
}
sortedName = append(sortedName, n)
}
} else {
Expand Down Expand Up @@ -2978,14 +2981,13 @@ func (m *kvMeta) DumpMeta(w io.Writer, root Ino, keepSecret bool) (err error) {
ino := m.decodeInode(key[1:9])
e := m.snap[ino]
if e == nil {
e = &DumpedEntry{}
e = &DumpedEntry{Attr: &DumpedAttr{Inode: ino}}
m.snap[ino] = e
}
switch key[9] {
case 'I':
attr := &Attr{Nlink: 1}
m.parseAttr(value, attr)
e.Attr = &DumpedAttr{}
dumpAttr(attr, e.Attr)
e.Attr.Inode = ino
case 'C':
Expand All @@ -3001,11 +3003,13 @@ func (m *kvMeta) DumpMeta(w io.Writer, root Ino, keepSecret bool) (err error) {
e.Chunks = append(e.Chunks, &DumpedChunk{indx, slices})
case 'D':
name := string(key[10:])
_, inode := m.parseEntry(value)
typ, inode := m.parseEntry(value)
child := m.snap[inode]
if child == nil {
child = &DumpedEntry{}
child = &DumpedEntry{Attr: &DumpedAttr{Inode: inode, Type: typeToString(typ)}}
m.snap[inode] = child
} else if child.Attr.Type == "" {
child.Attr.Type = typeToString(typ)
}
if e.Entries == nil {
e.Entries = map[string]*DumpedEntry{}
Expand Down

0 comments on commit 4867ec4

Please sign in to comment.