mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
shell: fs.verify -restoreFrom skips an entry without a TTL under a TTL rule
The filer gives an entry and assigned needles without a TTL the path rule's, so the restored entry kept its old creation time under a TTL it never had and could expire on its next lookup, and the new needles went to TTL volumes. Such an entry is now left as is and not pruned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da19900464
commit
af6b23f32d
3 files changed
+78
-3
No files matched your search
@@ -75,9 +75,10 @@ func (c *commandFsVerify) Help() string {
|
||||
which only applies when the entry is unchanged since verification.
|
||||
A missing chunk held in a chunk manifest is restored by uploading a
|
||||
rewritten manifest; the chunks held by a restored manifest are checked on
|
||||
the next run. Chunks with a cipher key are not restored. An entry is never
|
||||
pruned while the restore source holds, or cannot be read for, a missing
|
||||
needle of it.
|
||||
the next run. Chunks with a cipher key are not restored, nor is an entry
|
||||
without a TTL whose path rule sets one, since the update would take it.
|
||||
An entry is never pruned while the restore source holds, or cannot be read
|
||||
for, a missing needle of it.
|
||||
|
||||
`
|
||||
}
|
||||
|
||||
@@ -89,6 +89,18 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt
|
||||
}
|
||||
|
||||
ttlSec := current.GetAttributes().GetTtlSec()
|
||||
if ttlSec == 0 {
|
||||
// the filer gives an entry and needles without a TTL the path rule's
|
||||
ruleTtlSec, err := c.pathRuleTtlSec(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(c.writer, "restore %s failed: %v\n", path, err)
|
||||
return false, true
|
||||
}
|
||||
if ruleTtlSec > 0 {
|
||||
fmt.Fprintf(c.writer, "skip restoring %s: the entry has no TTL, but its path rule would give the restored entry and needles one\n", path)
|
||||
return false, true
|
||||
}
|
||||
}
|
||||
newFileIds := make(map[string]string)
|
||||
var uploaded []orphanedNeedle
|
||||
for _, r := range ready {
|
||||
@@ -179,6 +191,17 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt
|
||||
return true, true
|
||||
}
|
||||
|
||||
// pathRuleTtlSec is the TTL the filer.conf rule for path sets, as the filer
|
||||
// reads it.
|
||||
func (c *commandFsVerify) pathRuleTtlSec(path util.FullPath) (int32, error) {
|
||||
fc, err := filer.ReadFilerConfFromClient(context.Background(), c.env, c.env.MasterClient)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
ttl, _ := needle.ReadTTL(fc.MatchStorageRule(string(path)).GetTtl())
|
||||
return int32(ttl.Minutes()) * 60, nil
|
||||
}
|
||||
|
||||
// readRestorableNeedle reads a missing chunk's needle from the restore source
|
||||
// and checks it is the content the chunk names.
|
||||
func (c *commandFsVerify) readRestorableNeedle(chunk *filer_pb.FileChunk) (*needle.Needle, string, error) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
@@ -410,6 +411,56 @@ func TestFsVerifyRestoreBesideUnreadableNestedManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An entry without a TTL under a path rule with one is not restored: the
|
||||
// update and the new needles would take the rule's TTL.
|
||||
func TestFsVerifyRestoreSkipsEntryWithoutTtlUnderTtlRule(t *testing.T) {
|
||||
data := []byte("kept forever")
|
||||
dir := t.TempDir()
|
||||
v := newTestRestoreVolume(t, filepath.Join(dir, "7"))
|
||||
v.write(1, 0x11, data, false)
|
||||
v.close()
|
||||
|
||||
conf := filer.NewFilerConf()
|
||||
if err := conf.SetLocationConf(&filer_pb.FilerConf_PathConf{LocationPrefix: "/buckets/b/", Ttl: "7d"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var confText bytes.Buffer
|
||||
if err := conf.ToText(&confText); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lost := testChunk(7, 1, 0x11, 0, len(data), etagOf(data))
|
||||
attr := &filer_pb.FuseAttributes{Mtime: time.Now().Add(-30 * 24 * time.Hour).Unix()}
|
||||
confPath := util.NewFullPath(filer.DirectoryEtcSeaweedFS, filer.FilerConfName)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
path util.FullPath
|
||||
ttlSec int32
|
||||
restore bool
|
||||
}{
|
||||
{"no TTL under a TTL rule", "/buckets/b/file", 0, false},
|
||||
{"own TTL under a TTL rule", "/buckets/b/file", 3600, true},
|
||||
{"no TTL outside the rule", "/buckets/c/file", 0, true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
entryAttr := proto.Clone(attr).(*filer_pb.FuseAttributes)
|
||||
entryAttr.TtlSec = tc.ttlSec
|
||||
testFiler := &restoreTestFiler{stubFilerServer: stubFilerServer{entries: map[string]*filer_pb.Entry{
|
||||
string(tc.path): {Name: tc.path.Name(), Attributes: entryAttr, Chunks: []*filer_pb.FileChunk{lost}},
|
||||
string(confPath): {Name: filer.FilerConfName, Content: confText.Bytes()},
|
||||
}}}
|
||||
c, output, uploads := newRestoreTestCommand(t, testFiler, dir)
|
||||
|
||||
restored, isRestorable := c.restoreEntry(tc.path, entryAttr, []*filer_pb.FileChunk{lost}, []*filer_pb.FileChunk{lost})
|
||||
if restored != tc.restore || !isRestorable || (len(*uploads) > 0) != tc.restore {
|
||||
t.Fatalf("restored=%v restorable=%v uploads=%d, want restored=%v\n%s", restored, isRestorable, len(*uploads), tc.restore, output)
|
||||
}
|
||||
if !tc.restore && !strings.Contains(output.String(), "skip restoring "+string(tc.path)+": the entry has no TTL") {
|
||||
t.Errorf("output:\n%s", output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckRestoredContent(t *testing.T) {
|
||||
data := []byte("0123456789")
|
||||
n := &needle.Needle{Data: data}
|
||||
|
||||
Reference in new issue
Block a user