mirror of
https://github.com/hanzoai/s3.git
synced 2026-11-02 10:33:22 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
134 lines
3.9 KiB
Go
134 lines
3.9 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
|
|
|
"runtime"
|
|
|
|
"github.com/prometheus/procfs"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
var numCPU = runtime.NumCPU()
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCheck(ctx context.Context, req *volume_server_pb.VacuumVolumeCheckRequest) (*volume_server_pb.VacuumVolumeCheckResponse, error) {
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCheckResponse{}
|
|
|
|
garbageRatio, err := vs.store.CheckCompactVolume(needle.VolumeId(req.VolumeId))
|
|
|
|
resp.GarbageRatio = garbageRatio
|
|
|
|
if err != nil {
|
|
glog.V(3).Infof("check volume %d: %v", req.VolumeId, err)
|
|
}
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCompact(req *volume_server_pb.VacuumVolumeCompactRequest, stream volume_server_pb.VolumeServer_VacuumVolumeCompactServer) error {
|
|
if err := vs.checkGrpcAdminAuth(stream.Context()); err != nil {
|
|
return err
|
|
}
|
|
if err := vs.CheckMaintenanceMode(); err != nil {
|
|
return err
|
|
}
|
|
|
|
start := time.Now()
|
|
defer func(start time.Time) {
|
|
stats.VolumeServerVacuumingHistogram.WithLabelValues("compact").Observe(time.Since(start).Seconds())
|
|
}(start)
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCompactResponse{}
|
|
reportInterval := int64(1024 * 1024 * 128)
|
|
nextReportTarget := reportInterval
|
|
fs, fsErr := procfs.NewDefaultFS()
|
|
var sendErr error
|
|
err := vs.store.CompactVolume(needle.VolumeId(req.VolumeId), req.Preallocate, vs.compactionBytePerSecond, func(processed int64) bool {
|
|
if processed > nextReportTarget {
|
|
resp.ProcessedBytes = processed
|
|
if fsErr == nil && numCPU > 0 {
|
|
if fsLa, err := fs.LoadAvg(); err == nil {
|
|
resp.LoadAvg_1M = float32(fsLa.Load1 / float64(numCPU))
|
|
}
|
|
}
|
|
if sendErr = stream.Send(resp); sendErr != nil {
|
|
return false
|
|
}
|
|
nextReportTarget = processed + reportInterval
|
|
}
|
|
return true
|
|
})
|
|
|
|
stats.VolumeServerVacuumingCompactCounter.WithLabelValues(strconv.FormatBool(err == nil && sendErr == nil)).Inc()
|
|
if err != nil {
|
|
glog.Errorf("failed compact volume %d: %v", req.VolumeId, err)
|
|
return err
|
|
}
|
|
if sendErr != nil {
|
|
glog.Errorf("failed compact volume %d report progress: %v", req.VolumeId, sendErr)
|
|
return sendErr
|
|
}
|
|
|
|
glog.V(1).Infof("compact volume %d", req.VolumeId)
|
|
return nil
|
|
|
|
}
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCommit(ctx context.Context, req *volume_server_pb.VacuumVolumeCommitRequest) (*volume_server_pb.VacuumVolumeCommitResponse, error) {
|
|
if err := vs.checkGrpcAdminAuth(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := vs.CheckMaintenanceMode(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
start := time.Now()
|
|
defer func(start time.Time) {
|
|
stats.VolumeServerVacuumingHistogram.WithLabelValues("commit").Observe(time.Since(start).Seconds())
|
|
}(start)
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCommitResponse{}
|
|
|
|
readOnly, volumeSize, err := vs.store.CommitCompactVolume(needle.VolumeId(req.VolumeId))
|
|
|
|
if err != nil {
|
|
glog.Errorf("failed commit volume %d: %v", req.VolumeId, err)
|
|
} else {
|
|
glog.V(1).Infof("commit volume %d", req.VolumeId)
|
|
}
|
|
stats.VolumeServerVacuumingCommitCounter.WithLabelValues(strconv.FormatBool(err == nil)).Inc()
|
|
resp.IsReadOnly = readOnly
|
|
resp.VolumeSize = uint64(volumeSize)
|
|
return resp, err
|
|
|
|
}
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCleanup(ctx context.Context, req *volume_server_pb.VacuumVolumeCleanupRequest) (*volume_server_pb.VacuumVolumeCleanupResponse, error) {
|
|
if err := vs.checkGrpcAdminAuth(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := vs.CheckMaintenanceMode(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCleanupResponse{}
|
|
err := vs.store.CommitCleanupVolume(needle.VolumeId(req.VolumeId))
|
|
|
|
if err != nil {
|
|
glog.Errorf("failed cleanup volume %d: %v", req.VolumeId, err)
|
|
} else {
|
|
glog.V(1).Infof("cleanup volume %d", req.VolumeId)
|
|
}
|
|
|
|
return resp, err
|
|
|
|
}
|