mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* fix: do not index a record that runs past the end of the .dat A truncated .dat, or a header whose size points past the file end, left weed fix indexing a needle the volume cannot serve. Stop the scan at such a record instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: exit non-zero under -ignoreError when a volume fails -ignoreError kept going but always exited 0, so an empty or partial index looked like success. Record the failure in the exit status, and keep the existing .idx when the super block could not be read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * compact: remove the partial .cpd/.cpx when compaction fails A failed weed compact exited through glog.Fatalf and left a partial .cpd next to the volume. Remove both outputs and report the failure in the exit status instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: skip the end-of-file check for a volume on a remote tier The scan reads the remote object when the .vif lists one, so a retained local .dat is the wrong length to check records against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep a key deleted when its last record is truncated Stopping before a truncated delete record left the key's earlier live record in the index, so a deleted file came back. Drop the key instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: return the .idx open error from SaveToIdx The bare return gave back the nil named result, so a failure to open the index looked like a successful save. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: exit non-zero when a record is cut off by the end of the .dat A record past EOF ends the scan like a bad header does, so report it the same way while keeping the index of the records before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * compact: close the volume before removing a failed compaction's output Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: remove a failed .idx only after SaveToIdx opened it An open failure no longer reaches the caller's cleanup, so an existing .idx that could not be opened is left in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(s3vectors): drop the worker and CLI flags #12906 removed (#12911) * test(s3vectors): start weed-worker with only --admin weed-worker no longer accepts --namespace, --masters or --filer-group; it takes the Lance Namespace and the filers from admin. The worker jobs passed all three, so the worker exited on its arguments before registering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(s3vectors): let weed-vector-cli find the namespace through the masters weed-vector-cli dropped --namespace and looks the Lance Namespace up among the gateways the masters list, so the index job test failed on its arguments once the worker could register. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
func init() {
|
|
cmdCompact.Run = runCompact // break init cycle
|
|
}
|
|
|
|
var cmdCompact = &Command{
|
|
UsageLine: "compact -dir=/tmp -volumeId=234",
|
|
Short: "run weed tool compact on volume file",
|
|
Long: `Force an compaction to remove deleted files from volume files.
|
|
The compacted .dat file is stored as .cpd file.
|
|
The compacted .idx file is stored as .cpx file.
|
|
|
|
Supports two compaction methods:
|
|
* data: compacts based on the .dat file, works if .idx file is corrupted.
|
|
* index: compacts based on the .idx file, works if deletion happened but not written to .dat files.
|
|
|
|
`,
|
|
}
|
|
|
|
var (
|
|
compactVolumePath = cmdCompact.Flag.String("dir", ".", "data directory to store files")
|
|
compactVolumeCollection = cmdCompact.Flag.String("collection", "", "volume collection name")
|
|
compactVolumeId = cmdCompact.Flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir.")
|
|
compactMethod = cmdCompact.Flag.String("method", "data", "option to choose which compact method (data/index)")
|
|
compactVolumePreallocate = cmdCompact.Flag.Int64("preallocateMB", 0, "preallocate volume disk space")
|
|
)
|
|
|
|
func runCompact(cmd *Command, args []string) bool {
|
|
|
|
if *compactVolumeId == -1 {
|
|
return false
|
|
}
|
|
|
|
*compactVolumePath = util.ResolvePath(*compactVolumePath)
|
|
preallocateBytes := *compactVolumePreallocate * (1 << 20)
|
|
|
|
vid := needle.VolumeId(*compactVolumeId)
|
|
v, err := storage.NewVolume(*compactVolumePath, *compactVolumePath, *compactVolumeCollection, vid, storage.NeedleMapInMemory, nil, nil, preallocateBytes, needle.GetCurrentVersion(), 0, 0)
|
|
if err != nil {
|
|
glog.Fatalf("Load Volume [ERROR] %s\n", err)
|
|
}
|
|
|
|
opts := &storage.CompactOptions{
|
|
PreallocateBytes: preallocateBytes,
|
|
MaxBytesPerSecond: 0, // unlimited
|
|
}
|
|
switch strings.ToLower(*compactMethod) {
|
|
case "data":
|
|
err = v.CompactByVolumeData(opts)
|
|
case "index":
|
|
err = v.CompactByIndex(opts)
|
|
default:
|
|
glog.Fatalf("unsupported compaction method %q", *compactMethod)
|
|
}
|
|
if err != nil {
|
|
v.Close()
|
|
for _, ext := range []string{".cpd", ".cpx"} {
|
|
if rmErr := os.Remove(v.FileName(ext)); rmErr != nil && !os.IsNotExist(rmErr) {
|
|
glog.Errorf("remove %s: %v", v.FileName(ext), rmErr)
|
|
}
|
|
}
|
|
glog.Errorf("Compact Volume [ERROR] %s", err)
|
|
SetCommandExitStatus(1)
|
|
}
|
|
|
|
return true
|
|
}
|