mirror of
https://github.com/hanzoai/s3.git
synced 2026-11-03 03:07:41 +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.
212 lines
6.1 KiB
Go
212 lines
6.1 KiB
Go
package topology
|
|
|
|
import (
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
type EcShardLocations struct {
|
|
Collection string
|
|
// Use MaxShardCount (32) to support custom EC ratios
|
|
Locations [erasure_coding.MaxShardCount][]*DataNode
|
|
}
|
|
|
|
func (t *Topology) SyncDataNodeEcShards(shardInfos []*master_pb.VolumeEcShardInformationMessage, dn *DataNode) (newShards, deletedShards []*erasure_coding.EcVolumeInfo) {
|
|
// convert into in memory struct storage.VolumeInfo
|
|
var shards []*erasure_coding.EcVolumeInfo
|
|
for _, shardInfo := range shardInfos {
|
|
// Create EcVolumeInfo directly with optimized format
|
|
ecVolumeInfo := &erasure_coding.EcVolumeInfo{
|
|
VolumeId: needle.VolumeId(shardInfo.Id),
|
|
Collection: shardInfo.Collection,
|
|
ShardsInfo: erasure_coding.ShardsInfoFromVolumeEcShardInformationMessage(shardInfo),
|
|
DiskType: shardInfo.DiskType,
|
|
DiskId: shardInfo.DiskId,
|
|
ExpireAtSec: shardInfo.ExpireAtSec,
|
|
FileCount: shardInfo.FileCount,
|
|
DeleteCount: shardInfo.DeleteCount,
|
|
EncodeTsNs: shardInfo.EncodeTsNs,
|
|
}
|
|
|
|
shards = append(shards, ecVolumeInfo)
|
|
}
|
|
// find out the delta volumes
|
|
newShards, deletedShards = dn.UpdateEcShards(shards)
|
|
for _, v := range newShards {
|
|
t.RegisterEcShards(v, dn)
|
|
}
|
|
for _, v := range deletedShards {
|
|
t.UnRegisterEcShards(v, dn)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (t *Topology) IncrementalSyncDataNodeEcShards(newEcShards, deletedEcShards []*master_pb.VolumeEcShardInformationMessage, dn *DataNode) {
|
|
// convert into in memory struct storage.VolumeInfo
|
|
var newShards, deletedShards []*erasure_coding.EcVolumeInfo
|
|
for _, shardInfo := range newEcShards {
|
|
// Create EcVolumeInfo directly with optimized format
|
|
ecVolumeInfo := &erasure_coding.EcVolumeInfo{
|
|
VolumeId: needle.VolumeId(shardInfo.Id),
|
|
Collection: shardInfo.Collection,
|
|
ShardsInfo: erasure_coding.ShardsInfoFromVolumeEcShardInformationMessage(shardInfo),
|
|
DiskType: shardInfo.DiskType,
|
|
DiskId: shardInfo.DiskId,
|
|
ExpireAtSec: shardInfo.ExpireAtSec,
|
|
FileCount: shardInfo.FileCount,
|
|
DeleteCount: shardInfo.DeleteCount,
|
|
EncodeTsNs: shardInfo.EncodeTsNs,
|
|
}
|
|
|
|
newShards = append(newShards, ecVolumeInfo)
|
|
}
|
|
for _, shardInfo := range deletedEcShards {
|
|
// Create EcVolumeInfo directly with optimized format
|
|
ecVolumeInfo := &erasure_coding.EcVolumeInfo{
|
|
VolumeId: needle.VolumeId(shardInfo.Id),
|
|
Collection: shardInfo.Collection,
|
|
ShardsInfo: erasure_coding.ShardsInfoFromVolumeEcShardInformationMessage(shardInfo),
|
|
DiskType: shardInfo.DiskType,
|
|
DiskId: shardInfo.DiskId,
|
|
ExpireAtSec: shardInfo.ExpireAtSec,
|
|
FileCount: shardInfo.FileCount,
|
|
DeleteCount: shardInfo.DeleteCount,
|
|
EncodeTsNs: shardInfo.EncodeTsNs,
|
|
}
|
|
|
|
deletedShards = append(deletedShards, ecVolumeInfo)
|
|
}
|
|
|
|
dn.DeltaUpdateEcShards(newShards, deletedShards)
|
|
|
|
for _, v := range newShards {
|
|
t.RegisterEcShards(v, dn)
|
|
}
|
|
for _, v := range deletedShards {
|
|
t.UnRegisterEcShards(v, dn)
|
|
}
|
|
}
|
|
|
|
func NewEcShardLocations(collection string) *EcShardLocations {
|
|
return &EcShardLocations{
|
|
Collection: collection,
|
|
}
|
|
}
|
|
|
|
func (loc *EcShardLocations) AddShard(shardId erasure_coding.ShardId, dn *DataNode) (added bool) {
|
|
// Defensive bounds check to prevent panic with out-of-range shard IDs
|
|
if int(shardId) >= erasure_coding.MaxShardCount {
|
|
return false
|
|
}
|
|
dataNodes := loc.Locations[shardId]
|
|
for _, n := range dataNodes {
|
|
if n.Id() == dn.Id() {
|
|
return false
|
|
}
|
|
}
|
|
loc.Locations[shardId] = append(dataNodes, dn)
|
|
return true
|
|
}
|
|
|
|
func (loc *EcShardLocations) DeleteShard(shardId erasure_coding.ShardId, dn *DataNode) (deleted bool) {
|
|
// Defensive bounds check to prevent panic with out-of-range shard IDs
|
|
if int(shardId) >= erasure_coding.MaxShardCount {
|
|
return false
|
|
}
|
|
dataNodes := loc.Locations[shardId]
|
|
foundIndex := -1
|
|
for index, n := range dataNodes {
|
|
if n.Id() == dn.Id() {
|
|
foundIndex = index
|
|
}
|
|
}
|
|
if foundIndex < 0 {
|
|
return false
|
|
}
|
|
loc.Locations[shardId] = append(dataNodes[:foundIndex], dataNodes[foundIndex+1:]...)
|
|
return true
|
|
}
|
|
|
|
func (t *Topology) RegisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *DataNode) {
|
|
|
|
// EC-only volumes (source volume deleted after encoding) must bump
|
|
// maxVolumeId too, or a heartbeat-rebuilt master could re-issue their id.
|
|
t.UpAdjustMaxVolumeId(ecvi.VolumeId)
|
|
|
|
t.ecShardMapLock.Lock()
|
|
defer t.ecShardMapLock.Unlock()
|
|
|
|
locations, found := t.ecShardMap[ecvi.VolumeId]
|
|
if !found {
|
|
locations = NewEcShardLocations(ecvi.Collection)
|
|
t.ecShardMap[ecvi.VolumeId] = locations
|
|
}
|
|
for _, shardId := range ecvi.ShardsInfo.Ids() {
|
|
locations.AddShard(shardId, dn)
|
|
}
|
|
}
|
|
|
|
func (t *Topology) UnRegisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *DataNode) {
|
|
glog.Infof("removing ec shard info:%+v", ecvi)
|
|
t.ecShardMapLock.Lock()
|
|
defer t.ecShardMapLock.Unlock()
|
|
|
|
locations, found := t.ecShardMap[ecvi.VolumeId]
|
|
if !found {
|
|
return
|
|
}
|
|
for _, shardId := range ecvi.ShardsInfo.Ids() {
|
|
locations.DeleteShard(shardId, dn)
|
|
}
|
|
}
|
|
|
|
func (t *Topology) LookupEcShards(vid needle.VolumeId) (locations *EcShardLocations, found bool) {
|
|
t.ecShardMapLock.RLock()
|
|
defer t.ecShardMapLock.RUnlock()
|
|
|
|
locations, found = t.ecShardMap[vid]
|
|
|
|
return
|
|
}
|
|
|
|
func (t *Topology) ListEcServersByCollection(collection string) (dataNodes []pb.ServerAddress) {
|
|
t.ecShardMapLock.RLock()
|
|
defer t.ecShardMapLock.RUnlock()
|
|
|
|
dateNodeMap := make(map[pb.ServerAddress]bool)
|
|
for _, ecVolumeLocation := range t.ecShardMap {
|
|
if ecVolumeLocation.Collection == collection {
|
|
for _, locations := range ecVolumeLocation.Locations {
|
|
for _, loc := range locations {
|
|
dateNodeMap[loc.ServerAddress()] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for k, _ := range dateNodeMap {
|
|
dataNodes = append(dataNodes, k)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (t *Topology) DeleteEcCollection(collection string) {
|
|
t.ecShardMapLock.Lock()
|
|
defer t.ecShardMapLock.Unlock()
|
|
|
|
var vids []needle.VolumeId
|
|
for vid, ecVolumeLocation := range t.ecShardMap {
|
|
if ecVolumeLocation.Collection == collection {
|
|
vids = append(vids, vid)
|
|
}
|
|
}
|
|
|
|
for _, vid := range vids {
|
|
delete(t.ecShardMap, vid)
|
|
}
|
|
}
|