mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-08 15:41:15 +02:00
* filer: guard the FoundationDB value size limit, not the transaction limit An entry's whole chunk list is one FoundationDB value, and FDB caps a value at 100,000 bytes while a transaction may reach 10MB. UpdateEntry checked the transaction limit, so every entry between the two limits passed the guard and was rejected by FDB itself with error 2103 (Value length exceeds limit). The failure surfaced inside the store rather than at the guard, so the S3 layer dropped the connection and clients saw a network fault instead of an error. Check the value limit in UpdateEntry and KvPut instead, after gzip and before the transaction, with an error that names the limit it hit. The removed transaction-size constant guarded nothing else: DeleteFolderChildren batches by entry count. Refs #11158 * filer: fold at 500 chunks in the foundationdb build Manifest packing is what keeps a large file's entry small, but it only ran once a flat chunk list reached 10000 chunks. A FoundationDB value stops at 100,000 bytes and an entry's whole chunk list is one value, which at ~100 bytes per chunk record is about 1000 chunks -- so on FDB the write always failed before packing could help: a 3.3 GiB PutObject at the default -maxMB=4 was already past the limit. FoundationDB support is its own build (`go build -tags foundationdb`, shipped as its own image), so the batch is a build-time choice and needs no negotiation at run time. The tagged build folds at 500, every other build keeps 10000 and is untouched. 500 is not arbitrary: a single fold level leaves (chunks/batch) manifest pointers plus up to (batch-1) unfolded chunks in the entry, so the reachable chunk count is highest when the two terms are near equal. For a 100,000-byte budget that optimum is 500, which holds an entry inside the limit up to ~250,000 chunks -- ~1 TB at -maxMB=4, against ~4 GB before. Larger files need nested packing, which no batch size substitutes for. One binary serves every role in that image, so the filer and each client that folds -- S3, mount, WebDAV, weed shell, filer.copy -- agree on the batch by construction. A binary built with the tag but pointed at another store folds earlier than that store requires, costing one manifest blob per 500 chunks and one read to resolve it. Fixes #11158 * filer: fold with rollback inside MaybeManifestize, not beside it A fold that fails midway has already uploaded manifest blobs for its earlier batches, and returns only the data chunks -- dropping the manifests it had separated out of the caller's list. Both were wrong in ways that mattered: - AppendToEntry assigned that shortened list straight to entry.Chunks and created the entry, so an append to an already-folded file whose fold failed lost every previously folded chunk. weed mount had the same shape. - cleanupChunks logged the error as "not good, but should be ok" and then returned it through a named result, failing the whole CreateEntry or UpdateEntry, while the blobs it had written stayed behind referenced by nothing. The S3 path was alone in handling this, through a private helper beside MaybeManifestize. A second entry point next to the one everything else calls just means the wrong one gets used, so the behaviour moves inside MaybeManifestize: on failure it returns inputChunks as it received them, and hands the blobs it saved to a deleteChunks callback. The filer, S3 and filer.copy pass their existing deleters -- filer.copy already cleans up this way after a failed upload -- and mount, WebDAV and weed shell pass nil, which reports the blobs rather than collecting them, as before. Each caller keeps its own error policy: the filer HTTP PUT path and filer.copy still fail the request, the rest still continue with the flat list, which is a correct entry. --------- Co-authored-by: Chris Lu <chris.lu@gmail.com>
148 lines
4.8 KiB
Go
148 lines
4.8 KiB
Go
package filer
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
func flatTestChunks(n int) []*filer_pb.FileChunk {
|
|
chunks := make([]*filer_pb.FileChunk, n)
|
|
for i := range chunks {
|
|
chunks[i] = &filer_pb.FileChunk{
|
|
FileId: fmt.Sprintf("1,%x", i+1),
|
|
Offset: int64(i) * 8,
|
|
Size: 8,
|
|
}
|
|
}
|
|
return chunks
|
|
}
|
|
|
|
type fakeManifestStore struct {
|
|
saves int
|
|
failOn int // 1-based save call to fail on; 0 = never
|
|
deleted []*filer_pb.FileChunk
|
|
}
|
|
|
|
func (s *fakeManifestStore) save(reader io.Reader, name string, offset int64, tsNs int64, expectedDataSize uint64) (*filer_pb.FileChunk, error) {
|
|
s.saves++
|
|
if s.saves == s.failOn {
|
|
return nil, fmt.Errorf("save %d failed", s.saves)
|
|
}
|
|
if _, err := io.Copy(io.Discard, reader); err != nil {
|
|
return nil, err
|
|
}
|
|
return &filer_pb.FileChunk{FileId: fmt.Sprintf("2,%x", s.saves), Offset: offset}, nil
|
|
}
|
|
|
|
func (s *fakeManifestStore) delete(chunks []*filer_pb.FileChunk) {
|
|
s.deleted = append(s.deleted, chunks...)
|
|
}
|
|
|
|
func TestMaybeManifestizeFolds(t *testing.T) {
|
|
store := &fakeManifestStore{}
|
|
chunks := flatTestChunks(ManifestBatch + 50)
|
|
|
|
result, err := MaybeManifestize(store.save, store.delete, chunks)
|
|
if err != nil {
|
|
t.Fatalf("MaybeManifestize: %v", err)
|
|
}
|
|
|
|
manifests, data := SeparateManifestChunks(result)
|
|
if len(manifests) != 1 || len(data) != 50 {
|
|
t.Fatalf("expected 1 manifest + 50 flat chunks, got %d + %d", len(manifests), len(data))
|
|
}
|
|
if store.saves != 1 || len(store.deleted) != 0 {
|
|
t.Errorf("expected 1 save and no deletes, got %d saves, %d deleted", store.saves, len(store.deleted))
|
|
}
|
|
if manifests[0].Offset != 0 || manifests[0].Size != uint64(ManifestBatch*8) {
|
|
t.Errorf("manifest span [%d,%d) wrong", manifests[0].Offset, manifests[0].Size)
|
|
}
|
|
}
|
|
|
|
func TestMaybeManifestizeBelowThreshold(t *testing.T) {
|
|
store := &fakeManifestStore{}
|
|
chunks := flatTestChunks(ManifestBatch - 1)
|
|
|
|
result, err := MaybeManifestize(store.save, store.delete, chunks)
|
|
if err != nil {
|
|
t.Fatalf("MaybeManifestize: %v", err)
|
|
}
|
|
if len(result) != len(chunks) || store.saves != 0 {
|
|
t.Fatalf("expected untouched flat list, got %d chunks, %d saves", len(result), store.saves)
|
|
}
|
|
}
|
|
|
|
func TestMaybeManifestizeSkipsSse(t *testing.T) {
|
|
store := &fakeManifestStore{}
|
|
chunks := flatTestChunks(ManifestBatch + 50)
|
|
chunks[0].SseType = filer_pb.SSEType_SSE_S3
|
|
|
|
result, err := MaybeManifestize(store.save, store.delete, chunks)
|
|
if err != nil {
|
|
t.Fatalf("MaybeManifestize: %v", err)
|
|
}
|
|
if len(result) != len(chunks) || store.saves != 0 {
|
|
t.Fatalf("SSE chunks must not be folded, got %d chunks, %d saves", len(result), store.saves)
|
|
}
|
|
}
|
|
|
|
// A fold that fails midway must hand back the caller's own list and delete the
|
|
// manifest blobs its earlier batches already uploaded.
|
|
func TestMaybeManifestizeRollsBackPartialFold(t *testing.T) {
|
|
store := &fakeManifestStore{failOn: 2}
|
|
chunks := flatTestChunks(2*ManifestBatch + 50)
|
|
|
|
result, err := MaybeManifestize(store.save, store.delete, chunks)
|
|
if err == nil {
|
|
t.Fatal("expected the failed save to be reported")
|
|
}
|
|
if len(result) != len(chunks) {
|
|
t.Fatalf("expected fallback to %d flat chunks, got %d", len(chunks), len(result))
|
|
}
|
|
if HasChunkManifest(result) {
|
|
t.Error("fallback list must not contain manifest chunks")
|
|
}
|
|
if len(store.deleted) != 1 || store.deleted[0].FileId != "2,1" {
|
|
t.Fatalf("expected the first saved blob deleted, got %+v", store.deleted)
|
|
}
|
|
}
|
|
|
|
// The manifests a caller came in with are not re-folded, and must survive a
|
|
// fold that fails on the flat remainder: returning only the data chunks would
|
|
// lose everything they cover.
|
|
func TestMaybeManifestizeKeepsExistingManifestsOnFailure(t *testing.T) {
|
|
store := &fakeManifestStore{failOn: 2}
|
|
existing := &filer_pb.FileChunk{FileId: "m,1", IsChunkManifest: true, Offset: 0, Size: 24}
|
|
chunks := append([]*filer_pb.FileChunk{existing}, flatTestChunks(2*ManifestBatch+50)...)
|
|
|
|
result, _ := MaybeManifestize(store.save, store.delete, chunks)
|
|
|
|
if len(result) != len(chunks) {
|
|
t.Fatalf("expected original %d chunks, got %d", len(chunks), len(result))
|
|
}
|
|
if result[0].FileId != "m,1" || !result[0].IsChunkManifest {
|
|
t.Fatalf("existing manifest dropped: %+v", result[0])
|
|
}
|
|
if len(store.deleted) != 1 || store.deleted[0].FileId != "2,1" {
|
|
t.Fatalf("expected the first saved blob deleted, got %+v", store.deleted)
|
|
}
|
|
}
|
|
|
|
// Without a deleter the fold still falls back to the caller's list; the blobs
|
|
// it saved are only reported.
|
|
func TestMaybeManifestizeRollbackWithoutDeleter(t *testing.T) {
|
|
store := &fakeManifestStore{failOn: 2}
|
|
chunks := flatTestChunks(2*ManifestBatch + 50)
|
|
|
|
result, err := MaybeManifestize(store.save, nil, chunks)
|
|
if err == nil {
|
|
t.Fatal("expected the failed save to be reported")
|
|
}
|
|
if len(result) != len(chunks) || HasChunkManifest(result) {
|
|
t.Fatalf("expected fallback to %d flat chunks, got %d", len(chunks), len(result))
|
|
}
|
|
}
|