mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
shell: fs.verify finds a missing manifest under a readable one
A missing nested manifest failed the whole resolution, and the fallback then checked only the entry's own chunks, so a healthy parent hid the lost child from both pruning and -restoreFrom. The fallback now expands the manifests it can read, cut to their spans, and verifies each unreadable one as a needle.
This commit is contained in:
1 parent
aa7d767827
commit
cec02fbf0e
4 files changed
+108
-12
No files matched your search
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -199,7 +200,7 @@ type ItemEntry struct {
|
||||
rawChunks []*filer_pb.FileChunk
|
||||
path util.FullPath
|
||||
attr *filer_pb.FuseAttributes
|
||||
// a manifest could not be resolved, so chunks are the raw chunks
|
||||
// a manifest could not be resolved, so chunks are the readable ones
|
||||
manifestUnresolved bool
|
||||
}
|
||||
|
||||
@@ -236,7 +237,8 @@ func (c *commandFsVerify) repairEntry(path util.FullPath, attr *filer_pb.FuseAtt
|
||||
// resolveAndVerify expands chunk manifests, cut to their spans since chunks
|
||||
// past a shortened manifest are never read, and verifies the entry's needles.
|
||||
// An unresolvable manifest is an entry-level failure even when raw chunks are
|
||||
// healthy; raw chunks are still checked so a missing manifest needle can be pruned.
|
||||
// healthy; the readable chunks are still checked so a missing manifest needle
|
||||
// can be pruned.
|
||||
func (c *commandFsVerify) resolveAndVerify(entryPath string, chunks []*filer_pb.FileChunk, errorChunksCount *atomic.Uint64, wg *sync.WaitGroup) (verified bool, missingChunks []*filer_pb.FileChunk) {
|
||||
dataChunks := chunks
|
||||
manifestResolveFailed := false
|
||||
@@ -244,7 +246,8 @@ func (c *commandFsVerify) resolveAndVerify(entryPath string, chunks []*filer_pb.
|
||||
dataChunks = append(resolved, manifestChunks...)
|
||||
} else {
|
||||
manifestResolveFailed = true
|
||||
fmt.Fprintf(c.writer, "file: %s failed to resolve chunk manifest (%v), verifying raw chunks\n", entryPath, resolveErr)
|
||||
fmt.Fprintf(c.writer, "file: %s failed to resolve chunk manifest (%v), verifying readable chunks\n", entryPath, resolveErr)
|
||||
dataChunks = readableChunks(filer.LookupFn(c.env), chunks, math.MaxInt64)
|
||||
}
|
||||
verified, missingChunks = c.verifyEntry(entryPath, dataChunks, errorChunksCount, wg)
|
||||
if manifestResolveFailed && verified {
|
||||
@@ -316,6 +319,28 @@ func (c *commandFsVerify) verifyProcessMetadata(path string, wg *sync.WaitGroup)
|
||||
return counts, err
|
||||
}
|
||||
|
||||
// readableChunks expands the manifests it can read, one level at a time and
|
||||
// cut to their spans like ResolveChunkManifest, and keeps each one it cannot
|
||||
// read as a chunk to verify, so a missing manifest at any depth is checked
|
||||
// like any other needle. Chunks starting at or past end are never read.
|
||||
func readableChunks(lookupFn wdclient.LookupFileIdFunctionType, chunks []*filer_pb.FileChunk, end int64) (readable []*filer_pb.FileChunk) {
|
||||
for _, chunk := range chunks {
|
||||
if chunk.Offset >= end {
|
||||
continue
|
||||
}
|
||||
readable = append(readable, chunk)
|
||||
if !chunk.IsChunkManifest {
|
||||
continue
|
||||
}
|
||||
held, err := filer.ResolveOneChunkManifest(context.Background(), lookupFn, chunk, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
readable = append(readable, readableChunks(lookupFn, held, min(end, chunk.Offset+int64(chunk.Size)))...)
|
||||
}
|
||||
return readable
|
||||
}
|
||||
|
||||
// isNeedleMissingError reports whether a VolumeNeedleStatus error means the
|
||||
// needle data is lost at that location. It must NOT match "volume not found".
|
||||
// Newer Go servers and the Rust server return codes.NotFound; older Go
|
||||
@@ -565,8 +590,8 @@ func (c *commandFsVerify) verifyTraverseBfs(path string) (counts fsVerifyCounts,
|
||||
return fmt.Errorf("failed to ResolveChunkManifest: %+v", resolveErr)
|
||||
}
|
||||
// a missing manifest needle may be restorable
|
||||
fmt.Fprintf(c.writer, "file: %s failed to resolve chunk manifest (%v), verifying raw chunks\n", entryPath, resolveErr)
|
||||
dataChunks, manifestChunks, manifestUnresolved = entry.Entry.GetChunks(), nil, true
|
||||
fmt.Fprintf(c.writer, "file: %s failed to resolve chunk manifest (%v), verifying readable chunks\n", entryPath, resolveErr)
|
||||
dataChunks, manifestChunks, manifestUnresolved = readableChunks(filer.LookupFn(c.env), entry.Entry.GetChunks(), math.MaxInt64), nil, true
|
||||
}
|
||||
dataChunks = append(dataChunks, manifestChunks...)
|
||||
if len(dataChunks) > 0 {
|
||||
|
||||
@@ -38,6 +38,7 @@ type restorableChunk struct {
|
||||
fileId string
|
||||
needle *needle.Needle
|
||||
collection string
|
||||
manifest bool
|
||||
}
|
||||
|
||||
// restoreEntry copies the restorable missing chunks of an entry from the
|
||||
@@ -58,7 +59,7 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt
|
||||
fmt.Fprintf(c.writer, "not restorable %s chunk %s: %v\n", path, fileId, err)
|
||||
continue
|
||||
}
|
||||
ready = append(ready, restorableChunk{fileId: fileId, needle: n, collection: collection})
|
||||
ready = append(ready, restorableChunk{fileId: fileId, needle: n, collection: collection, manifest: chunk.IsChunkManifest})
|
||||
}
|
||||
if len(ready) == 0 {
|
||||
return false, false
|
||||
@@ -105,15 +106,11 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt
|
||||
|
||||
updated := proto.Clone(current).(*filer_pb.Entry)
|
||||
applied := make(map[string]string)
|
||||
var restoredManifests []string
|
||||
for i, chunk := range updated.Chunks {
|
||||
oldFileId := chunk.GetFileIdString()
|
||||
if fileId, found := newFileIds[oldFileId]; found {
|
||||
updated.Chunks[i] = withFileId(chunk, fileId)
|
||||
applied[oldFileId] = fileId
|
||||
if chunk.IsChunkManifest {
|
||||
restoredManifests = append(restoredManifests, oldFileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(applied) < len(newFileIds) {
|
||||
@@ -170,8 +167,10 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt
|
||||
for _, oldFileId := range slices.Sorted(maps.Keys(applied)) {
|
||||
fmt.Fprintf(c.writer, "restored %s chunk %s -> %s\n", path, oldFileId, applied[oldFileId])
|
||||
}
|
||||
for _, manifest := range restoredManifests {
|
||||
fmt.Fprintf(c.writer, "restored %s manifest %s: run fs.verify again to check the chunks it holds\n", path, manifest)
|
||||
for _, r := range ready {
|
||||
if _, found := applied[r.fileId]; found && r.manifest {
|
||||
fmt.Fprintf(c.writer, "restored %s manifest %s: run fs.verify again to check the chunks it holds\n", path, r.fileId)
|
||||
}
|
||||
}
|
||||
return true, true
|
||||
}
|
||||
|
||||
@@ -307,3 +307,51 @@ func TestCheckRestoredContent(t *testing.T) {
|
||||
t.Errorf("compressed needle: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A lost manifest held by a readable one is restored, and the parent is
|
||||
// rewritten to point at it.
|
||||
func TestFsVerifyRestoreNestedManifest(t *testing.T) {
|
||||
inner := []*filer_pb.FileChunk{testChunk(7, 5, 0x55, 100, 100, "")}
|
||||
blob, err := proto.Marshal(&filer_pb.FileChunkManifest{Chunks: inner})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir := t.TempDir()
|
||||
v := newTestRestoreVolume(t, filepath.Join(dir, "7"))
|
||||
v.write(2, 0x22, blob, false)
|
||||
v.close()
|
||||
|
||||
nested := testChunk(7, 2, 0x22, 100, 100, "")
|
||||
nested.IsChunkManifest = true
|
||||
held := []*filer_pb.FileChunk{testChunk(7, 1, 0x11, 0, 100, ""), nested}
|
||||
parent := testChunk(8, 1, 0x88, 0, 200, "")
|
||||
parent.IsChunkManifest = true
|
||||
path := util.NewFullPath("/dir", "file")
|
||||
attr := &filer_pb.FuseAttributes{Mtime: time.Now().Add(-time.Hour).Unix()}
|
||||
filer := &restoreTestFiler{stubFilerServer: stubFilerServer{
|
||||
entries: map[string]*filer_pb.Entry{string(path): {Name: "file", Attributes: attr, Chunks: []*filer_pb.FileChunk{parent}}},
|
||||
volumeUrls: map[string]string{"8": startStubManifestVolume(t, map[*filer_pb.FileChunk][]*filer_pb.FileChunk{parent: held})},
|
||||
}}
|
||||
c, output, uploads := newRestoreTestCommand(t, filer, dir)
|
||||
|
||||
restored, _ := c.restoreEntry(path, attr, []*filer_pb.FileChunk{parent}, []*filer_pb.FileChunk{nested})
|
||||
if !restored || len(filer.updates) != 1 || len(*uploads) != 2 {
|
||||
t.Fatalf("restored=%v updates=%d uploads=%d\n%s", restored, len(filer.updates), len(*uploads), output)
|
||||
}
|
||||
if !bytes.Equal((*uploads)[0].data, blob) {
|
||||
t.Error("the nested manifest was not uploaded as stored")
|
||||
}
|
||||
m := &filer_pb.FileChunkManifest{}
|
||||
if err := proto.Unmarshal((*uploads)[1].data, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(m.Chunks) != 2 || !proto.Equal(m.Chunks[0], held[0]) || m.Chunks[1].Fid.FileKey != 101 || !m.Chunks[1].IsChunkManifest {
|
||||
t.Fatalf("rewritten parent holds %v", m.Chunks)
|
||||
}
|
||||
if got := filer.updates[0].Entry.Chunks[0]; got.Fid.FileKey != 102 || !got.IsChunkManifest {
|
||||
t.Errorf("entry chunk = %v", got)
|
||||
}
|
||||
if !strings.Contains(output.String(), "restored /dir/file manifest "+nested.GetFileIdString()) {
|
||||
t.Errorf("output:\n%s", output)
|
||||
}
|
||||
}
|
||||
@@ -424,3 +424,27 @@ func TestFsVerifyIgnoresChunksPastAManifestSpan(t *testing.T) {
|
||||
t.Fatalf("verified=%v missing=%d, want the needle past the span ignored", verified, len(missing))
|
||||
}
|
||||
}
|
||||
|
||||
// A missing manifest under a readable one fails the whole resolution, so the
|
||||
// readable levels are walked and the missing manifest is reported like any
|
||||
// other lost needle; a chunk past the parent's span is still ignored.
|
||||
func TestFsVerifyFindsMissingNestedManifest(t *testing.T) {
|
||||
chunk := func(key uint64, offset int64) *filer_pb.FileChunk {
|
||||
return &filer_pb.FileChunk{Fid: &filer_pb.FileId{VolumeId: 7, FileKey: key, Cookie: 1}, Offset: offset, Size: 100}
|
||||
}
|
||||
nested := chunk(3, 100)
|
||||
nested.IsChunkManifest = true
|
||||
parent := &filer_pb.FileChunk{Fid: &filer_pb.FileId{VolumeId: 7, FileKey: 1, Cookie: 1}, Size: 200, IsChunkManifest: true}
|
||||
filerServer := &stubFilerServer{volumeUrls: map[string]string{"7": startStubManifestVolume(t, map[*filer_pb.FileChunk][]*filer_pb.FileChunk{
|
||||
parent: {chunk(2, 0), nested, chunk(4, 200)},
|
||||
})}}
|
||||
commandEnv, loc, cleanup := newFsVerifyTestCommandEnv(t, filerServer, &fsVerifyTestVolumeServer{missingNeedles: map[uint64]bool{3: true, 4: true}})
|
||||
defer cleanup()
|
||||
commandEnv.MasterClient = wdclient.NewMasterClient(grpc.WithTransportCredentials(insecure.NewCredentials()), "", "shell", "", "", "", pb.ServerDiscovery{})
|
||||
c := newFsVerifyTestCommand(t, commandEnv, &bytes.Buffer{}, loc)
|
||||
|
||||
verified, missing := c.resolveAndVerify("/buckets/b/file", []*filer_pb.FileChunk{parent}, atomic.NewUint64(0), &sync.WaitGroup{})
|
||||
if verified || len(missing) != 1 || missing[0].GetFileIdString() != nested.GetFileIdString() {
|
||||
t.Fatalf("verified=%v missing=%v, want only the nested manifest missing", verified, missing)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user