Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta/tkv: fix the issue that attr may be nil during dumping if the inode key is missing #3833

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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