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.
104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package mysql2
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer/abstract_sql"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer/mysql"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
const (
|
|
CONNECTION_URL_PATTERN = "%s:%s@tcp(%s:%d)/%s?collation=utf8mb4_bin"
|
|
)
|
|
|
|
var _ filer.BucketAware = (*MysqlStore2)(nil)
|
|
|
|
func init() {
|
|
filer.Stores = append(filer.Stores, &MysqlStore2{})
|
|
}
|
|
|
|
type MysqlStore2 struct {
|
|
abstract_sql.AbstractSqlStore
|
|
}
|
|
|
|
func (store *MysqlStore2) GetName() string {
|
|
return "mysql2"
|
|
}
|
|
|
|
func (store *MysqlStore2) Initialize(configuration util.Configuration, prefix string) (err error) {
|
|
// Absent key keeps a pooled default; an explicit 0 disables the idle pool.
|
|
configuration.SetDefault(prefix+"connection_max_idle", 2)
|
|
// Default on so minimal configs avoid the duplicate-key roundtrip the
|
|
// inode-index KvPut would otherwise emit on every write.
|
|
configuration.SetDefault(prefix+"enableUpsert", true)
|
|
return store.initialize(
|
|
configuration.GetString(prefix+"createTable"),
|
|
configuration.GetString(prefix+"upsertQuery"),
|
|
configuration.GetBool(prefix+"enableUpsert"),
|
|
configuration.GetString(prefix+"username"),
|
|
configuration.GetString(prefix+"password"),
|
|
configuration.GetString(prefix+"hostname"),
|
|
configuration.GetInt(prefix+"port"),
|
|
configuration.GetString(prefix+"database"),
|
|
configuration.GetInt(prefix+"connection_max_idle"),
|
|
configuration.GetInt(prefix+"connection_max_open"),
|
|
configuration.GetInt(prefix+"connection_max_lifetime_seconds"),
|
|
configuration.GetBool(prefix+"interpolateParams"),
|
|
)
|
|
}
|
|
|
|
func (store *MysqlStore2) initialize(createTable, upsertQuery string, enableUpsert bool, user, password, hostname string, port int, database string, maxIdle, maxOpen,
|
|
maxLifetimeSeconds int, interpolateParams bool) (err error) {
|
|
|
|
store.SupportBucketTable = true
|
|
if !enableUpsert {
|
|
upsertQuery = ""
|
|
} else if upsertQuery == "" {
|
|
upsertQuery = mysql.DefaultUpsertQuery
|
|
}
|
|
gen := &mysql.SqlGenMysql{
|
|
CreateTableSqlTemplate: createTable,
|
|
DropTableSqlTemplate: "DROP TABLE `%s`",
|
|
UpsertQueryTemplate: upsertQuery,
|
|
}
|
|
store.SqlGenerator = gen
|
|
|
|
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)
|
|
adaptedSqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, "<ADAPTED>", hostname, port, database)
|
|
if interpolateParams {
|
|
sqlUrl += "&interpolateParams=true"
|
|
adaptedSqlUrl += "&interpolateParams=true"
|
|
}
|
|
|
|
var dbErr error
|
|
store.DB, dbErr = sql.Open("mysql", sqlUrl)
|
|
if dbErr != nil {
|
|
store.DB.Close()
|
|
store.DB = nil
|
|
return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err)
|
|
}
|
|
|
|
store.DB.SetMaxIdleConns(maxIdle)
|
|
store.DB.SetMaxOpenConns(maxOpen)
|
|
store.DB.SetConnMaxLifetime(time.Duration(maxLifetimeSeconds) * time.Second)
|
|
|
|
if err = store.DB.Ping(); err != nil {
|
|
return fmt.Errorf("connect to %s error:%v", adaptedSqlUrl, err)
|
|
}
|
|
|
|
if err = store.CreateTable(context.Background(), abstract_sql.DEFAULT_TABLE); err != nil && !strings.Contains(err.Error(), "table already exist") {
|
|
return fmt.Errorf("init table %s: %v", abstract_sql.DEFAULT_TABLE, err)
|
|
}
|
|
|
|
mysql.ConfigureListOrdering(store.DB, gen)
|
|
|
|
return nil
|
|
}
|