mirror of
https://github.com/minio/minio.git
synced 2025-11-20 09:56:07 -05:00
Use errorChannels only for services not for drivers, reduce them to use simple functions
This commit is contained in:
@@ -101,18 +101,18 @@ func createNodeDiskMap(paths []string) map[string][]string {
|
||||
return nodes
|
||||
}
|
||||
|
||||
func initialize(d *donutDriver) {
|
||||
func initialize(d *donutDriver) error {
|
||||
// Soon to be user configurable, when Management API is available
|
||||
// we should remove "default" to something which is passed down
|
||||
// from configuration paramters
|
||||
var err error
|
||||
d.donut, err = donut.NewDonut("default", createNodeDiskMap(d.paths))
|
||||
if err != nil {
|
||||
panic(iodine.New(err, nil))
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
buckets, err := d.donut.ListBuckets()
|
||||
if err != nil {
|
||||
panic(iodine.New(err, nil))
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
for bucketName, metadata := range buckets {
|
||||
d.lock.RLock()
|
||||
@@ -136,13 +136,11 @@ func initialize(d *donutDriver) {
|
||||
d.storedBuckets[bucketName] = storedBucket
|
||||
d.lock.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start a single disk subsystem
|
||||
func Start(paths []string, maxSize uint64, expiration time.Duration) (chan<- string, <-chan error, drivers.Driver) {
|
||||
ctrlChannel := make(chan string)
|
||||
errorChannel := make(chan error)
|
||||
|
||||
// NewDriver instantiate a donut driver
|
||||
func NewDriver(paths []string, maxSize uint64, expiration time.Duration) (drivers.Driver, error) {
|
||||
driver := new(donutDriver)
|
||||
driver.storedBuckets = make(map[string]storedBucket)
|
||||
driver.objects = trove.NewCache(maxSize, expiration)
|
||||
@@ -160,14 +158,8 @@ func Start(paths []string, maxSize uint64, expiration time.Duration) (chan<- str
|
||||
driver.paths = paths
|
||||
driver.lock = new(sync.RWMutex)
|
||||
|
||||
initialize(driver)
|
||||
|
||||
go start(ctrlChannel, errorChannel, driver)
|
||||
return ctrlChannel, errorChannel, driver
|
||||
}
|
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error, driver *donutDriver) {
|
||||
defer close(errorChannel)
|
||||
err := initialize(driver)
|
||||
return driver, err
|
||||
}
|
||||
|
||||
func (d donutDriver) expiredObject(a ...interface{}) {
|
||||
|
||||
@@ -40,7 +40,8 @@ func (s *MySuite) TestAPISuite(c *C) {
|
||||
c.Check(err, IsNil)
|
||||
storageList = append(storageList, p)
|
||||
paths = append(paths, p)
|
||||
_, _, store := Start(paths, 1000000, 3*time.Hour)
|
||||
store, err := NewDriver(paths, 1000000, 3*time.Hour)
|
||||
c.Check(err, IsNil)
|
||||
return store
|
||||
}
|
||||
drivers.APITestSuite(c, create)
|
||||
|
||||
@@ -29,22 +29,14 @@ type fsDriver struct {
|
||||
multiparts *Multiparts
|
||||
}
|
||||
|
||||
// Start filesystem channel
|
||||
func Start(root string) (chan<- string, <-chan error, drivers.Driver) {
|
||||
ctrlChannel := make(chan string)
|
||||
errorChannel := make(chan error)
|
||||
// NewDriver instantiate a new filesystem driver
|
||||
func NewDriver(root string) (drivers.Driver, error) {
|
||||
fs := new(fsDriver)
|
||||
fs.root = root
|
||||
fs.lock = new(sync.Mutex)
|
||||
// internal related to multiparts
|
||||
fs.multiparts = new(Multiparts)
|
||||
fs.multiparts.ActiveSession = make(map[string]*MultipartSession)
|
||||
go start(ctrlChannel, errorChannel, fs)
|
||||
return ctrlChannel, errorChannel, fs
|
||||
}
|
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error, fs *fsDriver) {
|
||||
err := os.MkdirAll(fs.root, 0700)
|
||||
errorChannel <- err
|
||||
close(errorChannel)
|
||||
return fs, err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ func (s *MySuite) TestAPISuite(c *C) {
|
||||
path, err := ioutil.TempDir(os.TempDir(), "minio-fs-")
|
||||
c.Check(err, IsNil)
|
||||
storageList = append(storageList, path)
|
||||
_, _, store := Start(path)
|
||||
store, err := NewDriver(path)
|
||||
c.Check(err, IsNil)
|
||||
return store
|
||||
}
|
||||
drivers.APITestSuite(c, create)
|
||||
|
||||
@@ -64,13 +64,9 @@ const (
|
||||
totalBuckets = 100
|
||||
)
|
||||
|
||||
// Start memory object server
|
||||
func Start(maxSize uint64, expiration time.Duration) (chan<- string, <-chan error, drivers.Driver) {
|
||||
ctrlChannel := make(chan string)
|
||||
errorChannel := make(chan error)
|
||||
|
||||
var memory *memoryDriver
|
||||
memory = new(memoryDriver)
|
||||
// NewDriver instantiate a new memory driver
|
||||
func NewDriver(maxSize uint64, expiration time.Duration) (drivers.Driver, error) {
|
||||
memory := new(memoryDriver)
|
||||
memory.storedBuckets = make(map[string]storedBucket)
|
||||
memory.objects = trove.NewCache(maxSize, expiration)
|
||||
memory.maxSize = maxSize
|
||||
@@ -83,13 +79,7 @@ func Start(maxSize uint64, expiration time.Duration) (chan<- string, <-chan erro
|
||||
|
||||
// set up memory expiration
|
||||
memory.objects.ExpireObjects(time.Second * 5)
|
||||
|
||||
go start(ctrlChannel, errorChannel)
|
||||
return ctrlChannel, errorChannel, memory
|
||||
}
|
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
|
||||
close(errorChannel)
|
||||
return memory, nil
|
||||
}
|
||||
|
||||
// GetObject - GET object from memory buffer
|
||||
|
||||
@@ -32,7 +32,8 @@ var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) TestAPISuite(c *C) {
|
||||
create := func() drivers.Driver {
|
||||
_, _, store := Start(1000000, 3*time.Hour)
|
||||
store, err := NewDriver(1000000, 3*time.Hour)
|
||||
c.Check(err, IsNil)
|
||||
return store
|
||||
}
|
||||
drivers.APITestSuite(c, create)
|
||||
|
||||
Reference in New Issue
Block a user