mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* mount: refuse a merge whose local truncate cuts chunks a peer wrote A flush refused by IF_ENTRY_EQUAL replays the handle's truncate onto the stored entry. The truncate was made over the handle's base, so a chunk a peer committed after that base was dropped or clipped silently, losing data the peer had already fsynced. Like a stale whole-file rewrite over a peer's chunk change, it now fails the merge. A base chunk the peer only shortened carries no peer data and is still cut. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep the later mtime and ctime when merging a delayed flush The merge took every attribute the handle changed from the handle, so a flush that waited behind a peer's commit moved mtime and ctime back to the handle's older write. Each time is now merged as one value (seconds and nanoseconds were merged field by field, so a moved second could take the peer's nanoseconds): the handle's time stands unless a peer moved it too and later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: let a truncate merge pass the handle's own committed chunks A flush whose commit answer was lost finds its own chunks in the stored entry while its base is still the older one. Those chunks are the handle's writes, not a peer's, so they do not refuse the merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: do not keep a stored copy of a chunk the merge re-adds from the handle A stored chunk the base lacks but the handle holds is the handle's own commit whose answer was lost. The merge appends the handle's chunks after the stored ones, so keeping the stored copy referenced the chunk twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: take the manifests of a failed flush's fold for the handle's own chunks A flush can commit its folded manifests and lose the answer. The handle reverts to the member chunks and keeps its old base, so the next merge found the stored manifest, knew neither its file id nor its key, and refused it as a peer write across the handle's truncate. The handle now remembers the folds of flushes that failed over its base, and a merge unfolds them in the stored entry before comparing, so the members match the handle's chunks. A peer's manifest is still refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: take a retried flush's own stored fold for its own chunks The client retries a request whose connection dropped, and the first try may have stored the flush's folded manifests. The retry is then refused over them before the fold is recorded as failed, and the merge took the manifest for a peer's write across the handle's truncate. The merge now unfolds the flush's own fold in the stored entry as well; the condition still names the entry as stored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep every fold the filer may hold instead of the last four Dropping the oldest of four could forget the fold the filer committed, and the merge then refused that manifest again. A fold is now kept only when the flush failed without the filer's answer, or when the refusal lookup shows it stored, so a refused flush no longer adds one, and the list ends with the base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep a flush's fold when its first request may have been stored A precondition verdict on a retried send does not prove the first send stored nothing, and a failed refusal lookup then hid that it had. The create now counts the sends of the request that carries the fold and keeps the fold whenever the flush fails and that request was sent more than once or never got the filer's answer. That covers both flush paths, so revert is back to only restoring the chunks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: drop the failed folds a refused create shows were not stored A refusal means the stored entry moved off the handle's base, so no request guarded by that base can store another fold. After the refusal lookup the handle keeps only the folds whose manifests the stored entry holds, at most one, which bounds the list over a base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: bound the failed folds a handle keeps over one base Flushes that keep failing with no filer answer each saved a new fold the filer may hold, so the list grew for as long as the outage lasted. Once a handle keeps maxFailedFolds folds over its base, its flushes send their chunks unfolded for the filer to fold, and no kept fold is dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep the failed folds a refusal lookup does not show The refusal comes from the file's write owner, but the lookup after it can read a filer that lags behind and still shows the base. Pruning the folds against that read forgot a fold the owner had stored, and once its manifest showed up a pending truncate took it for a peer's chunk on every flush. The maxFailedFolds limit bounds the list, so the folds stay until the base moves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: drop the chunks a failed flush sent that the handle has cut since A flush that commits with its answer lost, then a truncate of the handle, left the next merge with the handle's own committed chunks in the stored entry, outside both base and the handle. The truncate check took them for a peer's writes and refused every later flush over the base. A failed flush now records the file ids of the chunks it sent that base lacks, and the merge drops those the handle no longer holds: it cut or replaced them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: copy the failed flush's sent set with a loop Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep folding past maxFailedFolds instead of sending chunks unfolded The filer folds a flat chunk list itself, into manifests the handle does not know: a lost answer then left one of them across a pending truncate, and an acknowledged one gave the handle flat chunks under a folded base. Flushes fold as before, and the handle stops keeping folds past the limit while it still records the chunks they sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: read the stored manifests a refused merge cannot name A fold changes no content, but a manifest the handle does not know sat in the stored entry as one chunk: across a pending truncate it refused the merge, though it can hold the handle's own chunks (a fold it did not keep, or one the filer made). When the merge is refused, the flush reads those manifests, replaces them with the chunks they hold and merges again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: hold the chunks the filer stored after a plain acknowledged flush The filer folds a flat chunk list (the mount's own fold failed), and the acknowledgement makes the stored entry the base while the handle kept the flat chunks. A later merge took them for writes of the handle, which can bring back chunks a peer's truncate removed. As after a merge, the handle now takes the stored chunks, keeping those attached since the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep a bounded record per failed flush instead of a growing set The set of chunk ids failed flushes sent grew with every overwrite while commits failed, and each failure copied it whole. Each failed flush the filer may have stored (a send got no verdict) now keeps one record, its fold and the ids it sent, built once and at most maxFailedFlushes over a base. Past that, a merge refuses the chunks of a flush it did not keep that the handle has cut since, as a peer's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: register the chunks a rebase or install gives the handle for reads A handle that takes the stored chunks after a flush (or a peer's, after a merge) can get manifests the filer made, and resolving them needs the file's read token. rebaseEntry and installRewrittenChunks now record the chunks under the file's path before the read view resolves them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep every chunk id a failed flush sent, cap only the folds Past four failed flushes over one base the handle stopped recording what a later flush sent. If that flush was stored with its answer lost, a truncate of its chunks was refused as a peer's write and kept failing after the filer came back. The ids now go into one set shared by the base's marks, each kept once and never copied, until the base moves. Only the folds stay capped: a stored manifest past the cap is read when a refused merge cannot place it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: fail a flush over a peer's chunk change unless -concurrentWriteMerge A content flush refused because another mount committed first used to merge the handle's writes onto the stored entry. That merge now runs only with the new -concurrentWriteMerge mount option (off by default). By default a stored chunk change that neither the base nor the handle holds fails the flush with EIO, and a peer's chunk event no longer rebases a dirty handle. Attribute-only changes and the handle's own commits (a lost answer, its own truncate) still merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: recognize the shortened references a failed flush sent A truncate shrinks a base chunk in place, keeping its file id. A failed flush that may have stored such a reference recorded only file ids base lacks, so a later truncate saw its own stored reference as a peer's change and failed with EIO by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
384 lines
11 KiB
Go
384 lines
11 KiB
Go
//go:build darwin || freebsd || linux
|
|
|
|
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"os"
|
|
"os/signal"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
|
)
|
|
|
|
type parameter struct {
|
|
name string
|
|
value string
|
|
}
|
|
|
|
func runFuse(cmd *Command, args []string) bool {
|
|
rawArgs := strings.Join(args, " ")
|
|
rawArgsLen := len(rawArgs)
|
|
option := strings.Builder{}
|
|
options := []parameter{}
|
|
masterProcess := true
|
|
fusermountPath := ""
|
|
|
|
// first parameter
|
|
i := 0
|
|
for i = 0; i < rawArgsLen && rawArgs[i] != ' '; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
options = append(options, parameter{"arg0", option.String()})
|
|
option.Reset()
|
|
|
|
for i++; i < rawArgsLen; i++ {
|
|
|
|
// space separator check for filled option
|
|
if rawArgs[i] == ' ' {
|
|
if option.Len() > 0 {
|
|
options = append(options, parameter{option.String(), "true"})
|
|
option.Reset()
|
|
}
|
|
|
|
// dash separator read option until next space
|
|
} else if rawArgs[i] == '-' {
|
|
for i++; i < rawArgsLen && rawArgs[i] != ' '; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
// ignore "-o"
|
|
if option.String() != "o" {
|
|
options = append(options, parameter{option.String(), "true"})
|
|
}
|
|
option.Reset()
|
|
|
|
// equal separator start option with pending value
|
|
} else if rawArgs[i] == '=' {
|
|
name := option.String()
|
|
option.Reset()
|
|
|
|
for i++; i < rawArgsLen && rawArgs[i] != ',' && rawArgs[i] != ' '; i++ {
|
|
// double quote separator read option until next double quote
|
|
if rawArgs[i] == '"' {
|
|
for i++; i < rawArgsLen && rawArgs[i] != '"'; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
|
|
// single quote separator read option until next single quote
|
|
} else if rawArgs[i] == '\'' {
|
|
for i++; i < rawArgsLen && rawArgs[i] != '\''; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
|
|
// add chars before comma
|
|
} else if rawArgs[i] != ' ' {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
}
|
|
|
|
options = append(options, parameter{name, option.String()})
|
|
option.Reset()
|
|
|
|
// comma separator just read current option
|
|
} else if rawArgs[i] == ',' {
|
|
options = append(options, parameter{option.String(), "true"})
|
|
option.Reset()
|
|
|
|
// what is not a separator fill option buffer
|
|
} else {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
}
|
|
|
|
// get residual option data
|
|
if option.Len() > 0 {
|
|
// add value to pending option
|
|
options = append(options, parameter{option.String(), "true"})
|
|
option.Reset()
|
|
}
|
|
|
|
// scan each parameter
|
|
for i := 0; i < len(options); i++ {
|
|
parameter := options[i]
|
|
|
|
switch parameter.name {
|
|
case "child":
|
|
masterProcess = false
|
|
if parsed, err := strconv.ParseInt(parameter.value, 10, 64); err == nil {
|
|
if parsed > math.MaxInt || parsed <= 0 {
|
|
panic(fmt.Errorf("parent PID %d is invalid", parsed))
|
|
}
|
|
mountOptions.fuseCommandPid = int(parsed)
|
|
} else {
|
|
panic(fmt.Errorf("parent PID %s is invalid: %w", parameter.value, err))
|
|
}
|
|
case "arg0":
|
|
mountOptions.dir = ¶meter.value
|
|
case "filer":
|
|
mountOptions.filer = ¶meter.value
|
|
case "filer.path":
|
|
mountOptions.filerMountRootPath = ¶meter.value
|
|
case "volumeName":
|
|
mountOptions.volumeName = ¶meter.value
|
|
case "dirAutoCreate":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.dirAutoCreate = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("dirAutoCreate: %s", err))
|
|
}
|
|
case "collection":
|
|
mountOptions.collection = ¶meter.value
|
|
case "replication":
|
|
mountOptions.replication = ¶meter.value
|
|
case "disk":
|
|
mountOptions.diskType = ¶meter.value
|
|
case "ttl":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.ttlSec = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("ttl: %s", err))
|
|
}
|
|
case "chunkSizeLimitMB":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.chunkSizeLimitMB = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("chunkSizeLimitMB: %s", err))
|
|
}
|
|
case "cacheMetaTtlSec":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.cacheMetaTtlSec = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("cacheMetaTtlSec: %s", err))
|
|
}
|
|
case "dirIdleEvictSec":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.dirIdleEvictSec = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("dirIdleEvictSec: %s", err))
|
|
}
|
|
case "concurrentWriters":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.concurrentWriters = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("concurrentWriters: %s", err))
|
|
}
|
|
case "concurrentReaders":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.concurrentReaders = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("concurrentReaders: %s", err))
|
|
}
|
|
case "cacheDir":
|
|
mountOptions.cacheDirForRead = ¶meter.value
|
|
case "cacheCapacityMB":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 64); err == nil {
|
|
mountOptions.cacheSizeMBForRead = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("cacheCapacityMB: %s", err))
|
|
}
|
|
case "cacheDirWrite":
|
|
mountOptions.cacheDirForWrite = ¶meter.value
|
|
case "writeBufferSizeMB":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 64); err == nil {
|
|
mountOptions.writeBufferSizeMB = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("writeBufferSizeMB: %s", err))
|
|
}
|
|
case "dataCenter":
|
|
mountOptions.dataCenter = ¶meter.value
|
|
case "allowOthers":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.allowOthers = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("allowOthers: %s", err))
|
|
}
|
|
case "umask":
|
|
mountOptions.umaskString = ¶meter.value
|
|
case "nonempty":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.nonempty = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("nonempty: %s", err))
|
|
}
|
|
case "defaultPermissions":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.defaultPermissions = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("defaultPermissions: %s", err))
|
|
}
|
|
case "idmap":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.idmap = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("idmap: %s", err))
|
|
}
|
|
case "volumeServerAccess":
|
|
mountOptions.volumeServerAccess = ¶meter.value
|
|
case "sseS3Read":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.sseS3Read = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("sseS3Read: %s", err))
|
|
}
|
|
case "map.uid":
|
|
mountOptions.uidMap = ¶meter.value
|
|
case "map.gid":
|
|
mountOptions.gidMap = ¶meter.value
|
|
case "readOnly":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.readOnly = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("readOnly: %s", err))
|
|
}
|
|
case "disableXAttr":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
|
|
mountOptions.disableXAttr = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("disableXAttr: %s", err))
|
|
}
|
|
case "cpuprofile":
|
|
mountCpuProfile = ¶meter.value
|
|
case "memprofile":
|
|
mountMemProfile = ¶meter.value
|
|
case "readRetryTime":
|
|
if parsed, err := time.ParseDuration(parameter.value); err == nil {
|
|
mountReadRetryTime = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("readRetryTime: %s", err))
|
|
}
|
|
case "fusermount.path":
|
|
fusermountPath = parameter.value
|
|
case "config_dir":
|
|
if err := util.ConfigurationFileDirectory.Set(parameter.value); err != nil {
|
|
panic(fmt.Errorf("config_dir %s: %w", parameter.value, err))
|
|
}
|
|
// FUSE performance options
|
|
case "writebackCache":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.writebackCache = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'writebackCache' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "concurrentWriteMerge":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.concurrentWriteMerge = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'concurrentWriteMerge' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "asyncDio":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.asyncDio = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'asyncDio' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "cacheSymlink":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.cacheSymlink = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'cacheSymlink' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
// macOS-specific FUSE options
|
|
case "sys.novncache":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.novncache = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'sys.novncache' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "autofs":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.hasAutofs = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'autofs' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "_netdev":
|
|
// _netdev is used for systemd/fstab parser to signify that this is a network mount but systemd
|
|
// mount sometimes can't strip them off. Meanwhile, fuse3 would refuse to run with _netdev, we
|
|
// strip them here if it fails to be stripped by the caller.
|
|
//(See https://github.com/seaweedfs/seaweedfs/wiki/fstab/948a70df5c0d9d2d27561b96de53bde07a29d2db)
|
|
glog.V(0).Infof("ignoring _netdev mount option")
|
|
default:
|
|
t := parameter.name
|
|
if parameter.value != "true" {
|
|
t = fmt.Sprintf("%s=%s", parameter.name, parameter.value)
|
|
}
|
|
mountOptions.extraOptions = append(mountOptions.extraOptions, t)
|
|
}
|
|
}
|
|
|
|
if err := checkIdmap(runtime.GOOS, *mountOptions.idmap, *mountOptions.defaultPermissions); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
util_http.InitGlobalHttpClient()
|
|
|
|
// the master start the child, release it then finish himself
|
|
if masterProcess {
|
|
arg0, err := os.Executable()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// pass our PID to the child process
|
|
pid := os.Getpid()
|
|
argv := append(os.Args, "-o", "child="+strconv.Itoa(pid))
|
|
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, syscall.SIGTERM)
|
|
|
|
attr := os.ProcAttr{}
|
|
attr.Env = os.Environ()
|
|
|
|
child, err := os.StartProcess(arg0, argv, &attr)
|
|
|
|
if err != nil {
|
|
panic(fmt.Errorf("master process can not start child process: %s", err))
|
|
}
|
|
|
|
err = child.Release()
|
|
|
|
if err != nil {
|
|
panic(fmt.Errorf("master process can not release child process: %s", err))
|
|
}
|
|
|
|
select {
|
|
case <-c:
|
|
return true
|
|
}
|
|
}
|
|
|
|
if fusermountPath != "" {
|
|
if err := os.Setenv("PATH", fusermountPath); err != nil {
|
|
panic(fmt.Errorf("setenv: %s", err))
|
|
}
|
|
} else if os.Getenv("PATH") == "" {
|
|
if err := os.Setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin"); err != nil {
|
|
panic(fmt.Errorf("setenv: %s", err))
|
|
}
|
|
}
|
|
|
|
util.LogTransparentHugePages()
|
|
|
|
// just call "weed mount" command
|
|
return runMount(cmdMount, []string{})
|
|
}
|