mirror of https://github.com/cloudreve/Cloudreve
feat(storage): load balance storage policy (#2436)
parent
a0aefef691
commit
aada3aab02
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 8e2c2bcff17d4728a01c2cabab8c3b639d72f428
|
Subproject commit 27996dc3ea22ab3b7ae525841ad1d45098d375f4
|
|
@ -27,6 +27,7 @@ type (
|
||||||
SkipStoragePolicyCache struct{}
|
SkipStoragePolicyCache struct{}
|
||||||
|
|
||||||
StoragePolicyClient interface {
|
StoragePolicyClient interface {
|
||||||
|
TxOperator
|
||||||
// GetByGroup returns the storage policies of the group.
|
// GetByGroup returns the storage policies of the group.
|
||||||
GetByGroup(ctx context.Context, group *ent.Group) (*ent.StoragePolicy, error)
|
GetByGroup(ctx context.Context, group *ent.Group) (*ent.StoragePolicy, error)
|
||||||
// GetPolicyByID returns the storage policy by id.
|
// GetPolicyByID returns the storage policy by id.
|
||||||
|
@ -64,6 +65,14 @@ type storagePolicyClient struct {
|
||||||
cache cache.Driver
|
cache cache.Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *storagePolicyClient) SetClient(newClient *ent.Client) TxOperator {
|
||||||
|
return &storagePolicyClient{client: newClient, cache: c.cache}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *storagePolicyClient) GetClient() *ent.Client {
|
||||||
|
return c.client
|
||||||
|
}
|
||||||
|
|
||||||
func (c *storagePolicyClient) Delete(ctx context.Context, policy *ent.StoragePolicy) error {
|
func (c *storagePolicyClient) Delete(ctx context.Context, policy *ent.StoragePolicy) error {
|
||||||
if err := c.client.StoragePolicy.DeleteOne(policy).Exec(ctx); err != nil {
|
if err := c.client.StoragePolicy.DeleteOne(policy).Exec(ctx); err != nil {
|
||||||
return fmt.Errorf("failed to delete storage policy: %w", err)
|
return fmt.Errorf("failed to delete storage policy: %w", err)
|
||||||
|
|
|
@ -294,11 +294,22 @@ func (service *UpdateStoragePolicyService) Update(c *gin.Context) (*GetStoragePo
|
||||||
}
|
}
|
||||||
|
|
||||||
service.Policy.ID = idInt
|
service.Policy.ID = idInt
|
||||||
_, err = storagePolicyClient.Upsert(c, service.Policy)
|
|
||||||
|
sc, tx, ctx, err := inventory.WithTx(c, storagePolicyClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return nil, serializer.NewError(serializer.CodeDBError, "Failed to create transaction", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sc.Upsert(ctx, service.Policy)
|
||||||
|
if err != nil {
|
||||||
|
_ = inventory.Rollback(tx)
|
||||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to update policy", err)
|
return nil, serializer.NewError(serializer.CodeDBError, "Failed to update policy", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := inventory.Commit(tx); err != nil {
|
||||||
|
return nil, serializer.NewError(serializer.CodeDBError, "Failed to commit transaction", err)
|
||||||
|
}
|
||||||
|
|
||||||
_ = dep.KV().Delete(manager.EntityUrlCacheKeyPrefix)
|
_ = dep.KV().Delete(manager.EntityUrlCacheKeyPrefix)
|
||||||
|
|
||||||
s := SingleStoragePolicyService{ID: idInt}
|
s := SingleStoragePolicyService{ID: idInt}
|
||||||
|
|
Loading…
Reference in New Issue