mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -05:00
Implement simple encoded storage in gateway
This commit is contained in:
parent
a56710e318
commit
e15edbf393
@ -9,6 +9,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/minio-io/minio/pkgs/storage/encodedstorage"
|
||||||
"github.com/minio-io/minio/pkgs/storage/fsstorage"
|
"github.com/minio-io/minio/pkgs/storage/fsstorage"
|
||||||
"github.com/tchap/go-patricia/patricia"
|
"github.com/tchap/go-patricia/patricia"
|
||||||
)
|
)
|
||||||
@ -18,7 +19,10 @@ type GatewayConfig struct {
|
|||||||
StorageDriver StorageDriver
|
StorageDriver StorageDriver
|
||||||
BucketDriver BucketDriver
|
BucketDriver BucketDriver
|
||||||
requestBucketChan chan BucketRequest
|
requestBucketChan chan BucketRequest
|
||||||
dataDir string
|
DataDir string
|
||||||
|
K,
|
||||||
|
M int
|
||||||
|
BlockSize uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message for requesting a bucket
|
// Message for requesting a bucket
|
||||||
@ -197,10 +201,34 @@ func InMemoryStorageDriver(bucket string, input chan ObjectRequest, config Gatew
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SimpleFileStorageDriver(bucket string, input chan ObjectRequest, config GatewayConfig) {
|
func SimpleEncodedStorageDriver(bucket string, input chan ObjectRequest, config GatewayConfig) {
|
||||||
fileStorage := fsstorage.FileSystemStorage{
|
eStorage, _ := encodedstorage.NewStorage(config.DataDir, config.K, config.M, config.BlockSize)
|
||||||
RootDir: config.dataDir,
|
for request := range input {
|
||||||
|
switch request.requestType {
|
||||||
|
case "GET":
|
||||||
|
objectPath := path.Join(bucket, request.path)
|
||||||
|
object, err := eStorage.Get(objectPath)
|
||||||
|
if err != nil {
|
||||||
|
request.callback <- err
|
||||||
|
} else {
|
||||||
|
request.callback <- object
|
||||||
|
}
|
||||||
|
case "PUT":
|
||||||
|
objectPath := path.Join(bucket, request.path)
|
||||||
|
err := eStorage.Put(objectPath, bytes.NewBuffer(request.object))
|
||||||
|
if err != nil {
|
||||||
|
request.callback <- err
|
||||||
|
} else {
|
||||||
|
request.callback <- nil
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
request.callback <- errors.New("Unexpected message")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SimpleFileStorageDriver(bucket string, input chan ObjectRequest, config GatewayConfig) {
|
||||||
|
fileStorage := fsstorage.NewStorage(config.DataDir)
|
||||||
for request := range input {
|
for request := range input {
|
||||||
switch request.requestType {
|
switch request.requestType {
|
||||||
case "GET":
|
case "GET":
|
||||||
|
@ -104,9 +104,13 @@ func (s *GatewaySuite) TestBucketCreation(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *GatewaySuite) TestInMemoryBucketOperations(c *C) {
|
func (s *GatewaySuite) TestInMemoryBucketOperations(c *C) {
|
||||||
simpleFileStorageRootDir, err := miniotest.MakeTempTestDir()
|
simpleFileStorageRootDir, err1 := miniotest.MakeTempTestDir()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err1, IsNil)
|
||||||
|
simpleEncodedStorageRootDir, err2 := miniotest.MakeTempTestDir()
|
||||||
|
c.Assert(err2, IsNil)
|
||||||
defer os.RemoveAll(simpleFileStorageRootDir)
|
defer os.RemoveAll(simpleFileStorageRootDir)
|
||||||
|
defer os.RemoveAll(simpleEncodedStorageRootDir)
|
||||||
|
|
||||||
configs := []GatewayConfig{
|
configs := []GatewayConfig{
|
||||||
GatewayConfig{
|
GatewayConfig{
|
||||||
StorageDriver: InMemoryStorageDriver,
|
StorageDriver: InMemoryStorageDriver,
|
||||||
@ -115,7 +119,15 @@ func (s *GatewaySuite) TestInMemoryBucketOperations(c *C) {
|
|||||||
GatewayConfig{
|
GatewayConfig{
|
||||||
StorageDriver: SimpleFileStorageDriver,
|
StorageDriver: SimpleFileStorageDriver,
|
||||||
requestBucketChan: make(chan BucketRequest),
|
requestBucketChan: make(chan BucketRequest),
|
||||||
dataDir: simpleFileStorageRootDir,
|
DataDir: simpleFileStorageRootDir,
|
||||||
|
},
|
||||||
|
GatewayConfig{
|
||||||
|
StorageDriver: SimpleEncodedStorageDriver,
|
||||||
|
requestBucketChan: make(chan BucketRequest),
|
||||||
|
DataDir: simpleEncodedStorageRootDir,
|
||||||
|
K: 10,
|
||||||
|
M: 6,
|
||||||
|
BlockSize: 1024 * 1024,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
@ -147,6 +159,5 @@ func (s *GatewaySuite) TestInMemoryBucketOperations(c *C) {
|
|||||||
barResult, err := bucket.Get(context, "foo")
|
barResult, err := bucket.Get(context, "foo")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(string(barResult), Equals, "bar")
|
c.Assert(string(barResult), Equals, "bar")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,18 @@ import (
|
|||||||
"github.com/minio-io/minio/pkgs/storage"
|
"github.com/minio-io/minio/pkgs/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileSystemStorage struct {
|
type fileSystemStorage struct {
|
||||||
RootDir string
|
RootDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fsStorage FileSystemStorage) List(listPath string) ([]storage.ObjectDescription, error) {
|
func NewStorage(rootDir string) (storage.ObjectStorage, error) {
|
||||||
|
newStorage := fileSystemStorage{
|
||||||
|
RootDir: rootDir,
|
||||||
|
}
|
||||||
|
return &newStorage, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fsStorage *fileSystemStorage) List(listPath string) ([]storage.ObjectDescription, error) {
|
||||||
fileInfos, err := ioutil.ReadDir(path.Join(fsStorage.RootDir, listPath))
|
fileInfos, err := ioutil.ReadDir(path.Join(fsStorage.RootDir, listPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -33,11 +40,11 @@ func (fsStorage FileSystemStorage) List(listPath string) ([]storage.ObjectDescri
|
|||||||
return descriptions, nil
|
return descriptions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage FileSystemStorage) Get(objectPath string) (io.Reader, error) {
|
func (storage *fileSystemStorage) Get(objectPath string) (io.Reader, error) {
|
||||||
return os.Open(path.Join(storage.RootDir, objectPath))
|
return os.Open(path.Join(storage.RootDir, objectPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage FileSystemStorage) Put(objectPath string, object io.Reader) error {
|
func (storage *fileSystemStorage) Put(objectPath string, object io.Reader) error {
|
||||||
err := os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
|
err := os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -10,9 +10,9 @@ import (
|
|||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileSystemStorageSuite struct{}
|
type fileSystemStorageSuite struct{}
|
||||||
|
|
||||||
var _ = Suite(&FileSystemStorageSuite{})
|
var _ = Suite(&fileSystemStorageSuite{})
|
||||||
|
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|
||||||
@ -20,15 +20,13 @@ func makeTempTestDir() (string, error) {
|
|||||||
return ioutil.TempDir("/tmp", "minio-test-")
|
return ioutil.TempDir("/tmp", "minio-test-")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FileSystemStorageSuite) TestFileStoragePutAtRootPath(c *C) {
|
func (s *fileSystemStorageSuite) TestfileStoragePutAtRootPath(c *C) {
|
||||||
rootDir, err := makeTempTestDir()
|
rootDir, err := makeTempTestDir()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
defer os.RemoveAll(rootDir)
|
defer os.RemoveAll(rootDir)
|
||||||
|
|
||||||
var objectStorage storage.ObjectStorage
|
var objectStorage storage.ObjectStorage
|
||||||
objectStorage = FileSystemStorage{
|
objectStorage, _ = NewStorage(rootDir)
|
||||||
RootDir: rootDir,
|
|
||||||
}
|
|
||||||
|
|
||||||
objectBuffer := bytes.NewBuffer([]byte("object1"))
|
objectBuffer := bytes.NewBuffer([]byte("object1"))
|
||||||
objectStorage.Put("path1", objectBuffer)
|
objectStorage.Put("path1", objectBuffer)
|
||||||
@ -44,15 +42,13 @@ func (s *FileSystemStorageSuite) TestFileStoragePutAtRootPath(c *C) {
|
|||||||
c.Assert(objectList[0].Path, Equals, "path1")
|
c.Assert(objectList[0].Path, Equals, "path1")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FileSystemStorageSuite) TestFileStoragePutDirPath(c *C) {
|
func (s *fileSystemStorageSuite) TestfileStoragePutDirPath(c *C) {
|
||||||
rootDir, err := makeTempTestDir()
|
rootDir, err := makeTempTestDir()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
defer os.RemoveAll(rootDir)
|
defer os.RemoveAll(rootDir)
|
||||||
|
|
||||||
var objectStorage storage.ObjectStorage
|
var objectStorage storage.ObjectStorage
|
||||||
objectStorage = FileSystemStorage{
|
objectStorage, _ = NewStorage(rootDir)
|
||||||
RootDir: rootDir,
|
|
||||||
}
|
|
||||||
|
|
||||||
objectBuffer1 := bytes.NewBuffer([]byte("object1"))
|
objectBuffer1 := bytes.NewBuffer([]byte("object1"))
|
||||||
objectStorage.Put("path1/path2/path3", objectBuffer1)
|
objectStorage.Put("path1/path2/path3", objectBuffer1)
|
||||||
|
Loading…
Reference in New Issue
Block a user