2022-03-18 02:12:25 +00:00
|
|
|
package arangodb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-20 23:21:56 +00:00
|
|
|
"github.com/arangodb/go-driver"
|
2022-03-18 02:12:25 +00:00
|
|
|
"time"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
2022-03-19 02:51:16 +00:00
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
2022-03-18 02:12:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ filer.BucketAware = (*ArangodbStore)(nil)
|
|
|
|
|
|
|
|
func (store *ArangodbStore) OnBucketCreation(bucket string) {
|
2022-03-19 02:51:16 +00:00
|
|
|
timeout, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
// create the collection && add to cache
|
|
|
|
_, err := store.ensureBucket(timeout, bucket)
|
|
|
|
if err != nil {
|
2022-04-20 23:21:56 +00:00
|
|
|
glog.Errorf("bucket create %s: %v", bucket, err)
|
2022-03-19 02:51:16 +00:00
|
|
|
}
|
2022-03-18 02:12:25 +00:00
|
|
|
}
|
|
|
|
func (store *ArangodbStore) OnBucketDeletion(bucket string) {
|
|
|
|
timeout, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
2022-03-19 02:51:16 +00:00
|
|
|
collection, err := store.ensureBucket(timeout, bucket)
|
2022-03-18 02:12:25 +00:00
|
|
|
if err != nil {
|
2022-04-20 23:21:56 +00:00
|
|
|
glog.Errorf("bucket delete %s: %v", bucket, err)
|
2022-03-19 02:51:16 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err = collection.Remove(timeout)
|
|
|
|
if err != nil && !driver.IsNotFound(err) {
|
2022-04-20 23:21:56 +00:00
|
|
|
glog.Errorf("bucket delete %s: %v", bucket, err)
|
2022-03-19 02:51:16 +00:00
|
|
|
return
|
2022-03-18 02:12:25 +00:00
|
|
|
}
|
2022-09-05 03:32:10 +00:00
|
|
|
store.mu.Lock()
|
|
|
|
delete(store.buckets, bucket)
|
|
|
|
store.mu.Unlock()
|
2022-03-18 02:12:25 +00:00
|
|
|
}
|
|
|
|
func (store *ArangodbStore) CanDropWholeBucket() bool {
|
|
|
|
return true
|
|
|
|
}
|