SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix bucket creation
Chris Lu93b3adba9864
diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.goindex 878386cf7d..aada9cd4a5 100644--- a/weed/filer/abstract_sql/abstract_sql_store.go+++ b/weed/filer/abstract_sql/abstract_sql_store.go@@ -20,13 +20,16 @@ type SqlGenerator interface {GetSqlDeleteFolderChildren(bucket string) stringGetSqlListExclusive(bucket string) stringGetSqlListInclusive(bucket string) string+ GetSqlCreateTable(bucket string) string+ GetSqlDropTable(bucket string) string}type AbstractSqlStore struct {- DB *sql.DBSqlGenerator- dbs map[string]bool- dbsLock sync.Mutex+ DB *sql.DB+ SupportBucketTable bool+ dbs map[string]bool+ dbsLock sync.Mutex}const (@@ -74,6 +77,10 @@ func (store *AbstractSqlStore) getTxOrDB(ctx context.Context, fullpath util.FulltxOrDB = store.DB}+ if !store.SupportBucketTable {+ return+ }+if !strings.HasPrefix(string(fullpath), "/buckets/") {return}@@ -98,7 +105,7 @@ func (store *AbstractSqlStore) getTxOrDB(ctx context.Context, fullpath util.Full}if _, found := store.dbs[bucket]; !found {- if err = store.createTable(bucket); err != nil {+ if err = store.createTable(ctx, bucket); err != nil {store.dbs[bucket] = true}}@@ -234,7 +241,7 @@ func (store *AbstractSqlStore) DeleteFolderChildren(ctx context.Context, fullpat}if isValidBucket(bucket) && shortPath == "/" {- if store.deleteTable(bucket) {+ if err = store.deleteTable(ctx, bucket); err != nil {store.dbsLock.Lock()delete(store.dbs, bucket)store.dbsLock.Unlock()@@ -311,10 +318,18 @@ func isValidBucket(bucket string) bool {return bucket != DEFAULT_TABLE && bucket != ""}-func (store *AbstractSqlStore) createTable(bucket string) error {- return nil+func (store *AbstractSqlStore) createTable(ctx context.Context, bucket string) error {+ if !store.SupportBucketTable {+ return nil+ }+ _, err := store.DB.ExecContext(ctx, store.SqlGenerator.GetSqlCreateTable(bucket))+ return err}-func (store *AbstractSqlStore) deleteTable(bucket string) bool {- return false+func (store *AbstractSqlStore) deleteTable(ctx context.Context, bucket string) error {+ if !store.SupportBucketTable {+ return nil+ }+ _, err := store.DB.ExecContext(ctx, store.SqlGenerator.GetSqlDropTable(bucket))+ return err}diff --git a/weed/filer/mysql/mysql_store.go b/weed/filer/mysql/mysql_store.goindex 479d2eed19..0e29852f59 100644--- a/weed/filer/mysql/mysql_store.go+++ b/weed/filer/mysql/mysql_store.go@@ -16,6 +16,8 @@ const ()type SqlGenMysql struct {+ createTableSqlTemplate string+ dropTableSqlTemplate string}var (@@ -50,6 +52,14 @@ func (gen *SqlGenMysql) GetSqlListInclusive(bucket string) string {return "SELECT NAME, meta FROM filemeta WHERE dirhash=? AND name>=? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?"}+func (gen *SqlGenMysql) GetSqlCreateTable(bucket string) string {+ return fmt.Sprintf(gen.createTableSqlTemplate, bucket)+}++func (gen *SqlGenMysql) GetSqlDropTable(bucket string) string {+ return fmt.Sprintf(gen.dropTableSqlTemplate, bucket)+}+func init() {filer.Stores = append(filer.Stores, &MysqlStore{})}@@ -79,7 +89,11 @@ func (store *MysqlStore) Initialize(configuration util.Configuration, prefix strfunc (store *MysqlStore) initialize(user, password, hostname string, port int, database string, maxIdle, maxOpen,maxLifetimeSeconds int, interpolateParams bool) (err error) {- store.SqlGenerator = &SqlGenMysql{}+ store.SupportBucketTable = false+ store.SqlGenerator = &SqlGenMysql{+ createTableSqlTemplate: "",+ dropTableSqlTemplate: "drop table %s",+ }sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)if interpolateParams {diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.goindex 783f27c10b..8c36b8672b 100644--- a/weed/filer/postgres/postgres_store.go+++ b/weed/filer/postgres/postgres_store.go@@ -15,6 +15,8 @@ const ()type SqlGenPostgres struct {+ createTableSqlTemplate string+ dropTableSqlTemplate string}var (@@ -49,6 +51,14 @@ func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string {return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5"}+func (gen *SqlGenPostgres) GetSqlCreateTable(bucket string) string {+ return fmt.Sprintf(gen.createTableSqlTemplate, bucket)+}++func (gen *SqlGenPostgres) GetSqlDropTable(bucket string) string {+ return fmt.Sprintf(gen.dropTableSqlTemplate, bucket)+}+func init() {filer.Stores = append(filer.Stores, &PostgresStore{})}@@ -76,7 +86,11 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefixfunc (store *PostgresStore) initialize(user, password, hostname string, port int, database, sslmode string, maxIdle, maxOpen int) (err error) {- store.SqlGenerator = &SqlGenPostgres{}+ store.SupportBucketTable = false+ store.SqlGenerator = &SqlGenPostgres{+ createTableSqlTemplate: "",+ dropTableSqlTemplate: "drop table %s",+ }sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)if user != "" {