mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
* operation: return the assignment proof of an upload A filer serving a scoped token returns an assignment proof with AssignVolume and stores a new chunk in an entry only when the request presents that proof in chunk_auth. UploadWithRetry dropped it, so a client had no way to commit the chunks it uploaded. UploadResult.AssignAuth now carries the proof of the assignment the data was finally stored under. A proof from an assignment the upload abandoned after a failed attempt is never returned. The field is not serialized and stays empty when the filer sends none, so existing callers are unchanged. * mount: keep assignment proofs until the filer stores their chunks A mount with a scoped filer token was refused whenever it wrote new chunks: the filer asks for the assignment proof of every chunk the stored entry does not hold, and the mount never kept it. The mount now keeps the proof of every chunk it uploads and attaches the proofs of the chunks a request names to each create, update and append it sends, over the mutation stream and over unary calls, on every attempt. A proof is released only once a filer acknowledged an entry that names the chunk, or a manifest that holds it. A failed, refused or timed out commit releases nothing, since it may have been stored: the retry still carries the proof, and a filer ignores proofs for chunks it holds. Proofs are stateless, so a commit retried on another filer of the cluster is accepted there. The store is bounded. When it is full an upload waits for commits to make room before it is assigned a file id, and fails after a minute instead of evicting a proof a pending commit still needs. Only proofs well past their expiry, which a filer refuses anyway, are dropped to make room. Without a filer token the mount keeps no store: its requests and chunk lists are as before. A token without path grants is given no proofs, so nothing is attached either. * mount: keep chunk lists flat with a filer token file A filer serving a scoped token stores no new chunk in an entry that holds manifests, so once a mount folded a file's small chunks into a manifest, every later write to that file was refused. A mount with a filer token now keeps chunk lists flat; mounts without one fold as before. * mount: test the unscoped-token path with a signed token GenJwtForFilerScope returns an empty token when it is given no path grants, so both cases of TestUnscopedMountRequestsCarryNoProofs ran a tokenless mount. Sign an unscoped filer token instead and check that it is not empty, so the test covers a mount holding a token the filer issues no proofs for. * mount: fold chunk lists unless the filer scopes the mount's token A mount with -filer.tokenFile kept every chunk list flat, also when the token is an unscoped one the filer issues no proofs for. Such a mount stopped folding chunks into manifests, so its small-chunk runs were never folded and, on FoundationDB, a file past about 1000 chunks no longer fit its entry. Keep lists flat only while the current token has path grants or a method list, which the filer scopes; fold as before otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
4.9 KiB
Go
124 lines
4.9 KiB
Go
package mount
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
|
)
|
|
|
|
// shouldCacheUploadedChunk decides whether a just-uploaded chunk's bytes are
|
|
// put in the local chunk cache. The first chunk (small files) is always cached.
|
|
// Peer sharing needs every chunk cached so it can be served back on FetchChunk.
|
|
// A read-auth mount needs every chunk cached too: it holds no volume read key
|
|
// and reads a chunk with a filer-issued per-fid token the filer can mint only
|
|
// after the chunk's entry is published, so a chunk this handle just uploaded
|
|
// has no token until the next metadata flush; caching it lets a read-after-write
|
|
// of that chunk be served locally instead of failing on a token-less volume
|
|
// fetch. Gated on chunkCache != nil (-cacheCapacityMB=0 disables the cache).
|
|
func (wfs *WFS) shouldCacheUploadedChunk(offset int64) bool {
|
|
return wfs.chunkCache != nil && (offset == 0 || wfs.peerAnnouncer != nil || wfs.readAuth != nil)
|
|
}
|
|
|
|
// maybeManifestize folds a file's chunks into manifests as
|
|
// filer.MaybeManifestize does, except on a mount with a scoped filer token: a
|
|
// filer serving a scoped token stores no new chunk in an entry that holds
|
|
// manifests, so every later write to a folded file would be refused. Such a
|
|
// mount keeps chunk lists flat.
|
|
func (wfs *WFS) maybeManifestize(fullPath util.FullPath, chunks []*filer_pb.FileChunk) ([]*filer_pb.FileChunk, error) {
|
|
if wfs.chunkProofs != nil && wfs.filerTokenScoped() {
|
|
return chunks, nil
|
|
}
|
|
return filer.MaybeManifestize(wfs.saveDataAsChunk(fullPath), nil, chunks)
|
|
}
|
|
|
|
func (wfs *WFS) saveDataAsChunk(fullPath util.FullPath) filer.SaveDataAsChunkFunctionType {
|
|
|
|
// Backstop: FUSE entry points sanitize names before they reach
|
|
// inodeToPath, but async flush paths (e.g. writebackCache, handles whose
|
|
// RememberPath was set from an older code path) may still carry bytes
|
|
// that predate sanitization. Proto3 string fields require valid UTF-8,
|
|
// so scrub the full path once here before every AssignVolume call.
|
|
assignPath := fullPath.Sanitized()
|
|
|
|
return func(reader io.Reader, filename string, offset int64, tsNs int64, _ uint64) (chunk *filer_pb.FileChunk, err error) {
|
|
uploader, err := operation.NewUploader()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// WantMd5 gives mount writes a real filer.ETag (server echoes Content-MD5 back).
|
|
uploadOption := &operation.UploadOption{
|
|
Filename: filename,
|
|
Cipher: wfs.option.Cipher,
|
|
IsInputCompressed: false,
|
|
MimeType: "",
|
|
PairMap: nil,
|
|
WantMd5: true,
|
|
}
|
|
if wfs.option.VolumeServerAccess == "filerProxy" {
|
|
// getCurrentFiler() can change on failover, so read it per attempt.
|
|
uploadOption.GenUploadUrl = func(host, fileId string) string {
|
|
return util_http.ProxyChunkUrl(string(wfs.getCurrentFiler()), fileId)
|
|
}
|
|
}
|
|
|
|
// A filer serving a scoped token stores the chunk only with the
|
|
// assignment proof it returns, so make room to keep it first.
|
|
if err = wfs.chunkProofs.reserve(1); err != nil {
|
|
glog.V(0).Infof("upload data %v: %v", filename, err)
|
|
return nil, fmt.Errorf("upload data: %w", err)
|
|
}
|
|
fileId, uploadResult, err, data := uploader.UploadWithRetry(
|
|
wfs,
|
|
&filer_pb.AssignVolumeRequest{
|
|
Count: 1,
|
|
Replication: wfs.option.Replication,
|
|
Collection: wfs.option.Collection,
|
|
TtlSec: wfs.option.TtlSec,
|
|
DiskType: string(wfs.option.DiskType),
|
|
DataCenter: wfs.option.DataCenter,
|
|
Path: assignPath,
|
|
},
|
|
uploadOption, reader,
|
|
)
|
|
|
|
if err != nil {
|
|
wfs.chunkProofs.unreserve(1)
|
|
glog.V(0).Infof("upload data %v: %v", filename, err)
|
|
return nil, fmt.Errorf("upload data: %w", err)
|
|
}
|
|
if uploadResult.Error != "" {
|
|
wfs.chunkProofs.unreserve(1)
|
|
glog.V(0).Infof("upload failure %v: %v", filename, err)
|
|
return nil, fmt.Errorf("upload result: %v", uploadResult.Error)
|
|
}
|
|
wfs.chunkProofs.keep(fileId, uploadResult.AssignAuth, 1)
|
|
|
|
// shouldCacheUploadedChunk explains when and why every uploaded
|
|
// chunk is cached (peer sharing, and read-auth read-after-write).
|
|
shouldCache := wfs.shouldCacheUploadedChunk(offset)
|
|
if shouldCache {
|
|
wfs.chunkCache.SetChunk(fileId, data)
|
|
}
|
|
// Announce every uploaded chunk so the tier-2 directory fills
|
|
// in as the file is written. Without this, the per-fetch
|
|
// announce path only bootstraps after someone else has already
|
|
// pulled a chunk via peer — which can't happen if nobody has
|
|
// told the directory who holds the chunk. Skip the announce
|
|
// when we couldn't cache (no point advertising bytes we can't
|
|
// actually serve back).
|
|
if wfs.peerAnnouncer != nil && shouldCache {
|
|
wfs.peerAnnouncer.EnqueueAnnounce(fileId)
|
|
}
|
|
|
|
chunk = uploadResult.ToPbFileChunk(fileId, offset, tsNs)
|
|
return chunk, nil
|
|
}
|
|
}
|