diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-01-19 15:55:51 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-01-19 15:55:51 -0800 |
| commit | 93b3adba9864dd278a778ccfe2165bcadb010574 (patch) | |
| tree | a5a14d38e62d1cf14dcb21cef495d9cfa20a6154 /weed/filer/abstract_sql | |
| parent | fa0c8d528370ee419cf4ed64213b1b4cdf014fac (diff) | |
| download | seaweedfs-93b3adba9864dd278a778ccfe2165bcadb010574.tar.xz seaweedfs-93b3adba9864dd278a778ccfe2165bcadb010574.zip | |
fix bucket creation
Diffstat (limited to 'weed/filer/abstract_sql')
| -rw-r--r-- | weed/filer/abstract_sql/abstract_sql_store.go | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.go index 878386cf7..aada9cd4a 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) string GetSqlListExclusive(bucket string) string GetSqlListInclusive(bucket string) string + GetSqlCreateTable(bucket string) string + GetSqlDropTable(bucket string) string } type AbstractSqlStore struct { - DB *sql.DB SqlGenerator - 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.Full txOrDB = 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 } |
