You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
3.4 KiB
142 lines
3.4 KiB
9 years ago
|
/*
|
||
9 years ago
|
* Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
|
||
9 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
9 years ago
|
package main
|
||
9 years ago
|
|
||
|
import (
|
||
|
"os"
|
||
9 years ago
|
"path/filepath"
|
||
9 years ago
|
"sync"
|
||
|
"time"
|
||
|
|
||
9 years ago
|
"github.com/minio/minio/pkg/probe"
|
||
9 years ago
|
)
|
||
|
|
||
9 years ago
|
// ListObjectParams - list object params used for list object map
|
||
|
type ListObjectParams struct {
|
||
|
bucket string
|
||
|
delimiter string
|
||
|
marker string
|
||
|
prefix string
|
||
|
}
|
||
|
|
||
9 years ago
|
// Filesystem - local variables
|
||
|
type Filesystem struct {
|
||
9 years ago
|
path string
|
||
|
minFreeDisk int64
|
||
|
rwLock *sync.RWMutex
|
||
|
multiparts *Multiparts
|
||
|
listObjectMap map[ListObjectParams][]ObjectInfoChannel
|
||
|
listObjectMapMutex *sync.Mutex
|
||
|
}
|
||
|
|
||
|
func (fs *Filesystem) pushListObjectCh(params ListObjectParams, ch ObjectInfoChannel) {
|
||
|
fs.listObjectMapMutex.Lock()
|
||
|
defer fs.listObjectMapMutex.Unlock()
|
||
|
|
||
|
channels := []ObjectInfoChannel{ch}
|
||
|
if _, ok := fs.listObjectMap[params]; ok {
|
||
|
channels = append(fs.listObjectMap[params], ch)
|
||
|
}
|
||
|
|
||
|
fs.listObjectMap[params] = channels
|
||
|
}
|
||
|
|
||
|
func (fs *Filesystem) popListObjectCh(params ListObjectParams) *ObjectInfoChannel {
|
||
|
fs.listObjectMapMutex.Lock()
|
||
|
defer fs.listObjectMapMutex.Unlock()
|
||
|
|
||
|
if channels, ok := fs.listObjectMap[params]; ok {
|
||
|
for i, channel := range channels {
|
||
|
if !channel.IsTimedOut() {
|
||
|
chs := channels[i+1:]
|
||
|
if len(chs) > 0 {
|
||
|
fs.listObjectMap[params] = chs
|
||
|
} else {
|
||
|
delete(fs.listObjectMap, params)
|
||
|
}
|
||
|
|
||
|
return &channel
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// As all channels are timed out, delete the map entry
|
||
|
delete(fs.listObjectMap, params)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// MultipartSession holds active session information
|
||
|
type MultipartSession struct {
|
||
|
TotalParts int
|
||
9 years ago
|
ObjectName string
|
||
9 years ago
|
UploadID string
|
||
|
Initiated time.Time
|
||
9 years ago
|
Parts []PartMetadata
|
||
9 years ago
|
}
|
||
|
|
||
|
// Multiparts collection of many parts
|
||
|
type Multiparts struct {
|
||
|
Version string `json:"version"`
|
||
|
ActiveSession map[string]*MultipartSession `json:"activeSessions"`
|
||
|
}
|
||
|
|
||
9 years ago
|
// newFS instantiate a new filesystem.
|
||
|
func newFS(rootPath string) (ObjectAPI, *probe.Error) {
|
||
9 years ago
|
setFSMultipartsMetadataPath(filepath.Join(rootPath, "$multiparts-session.json"))
|
||
9 years ago
|
|
||
9 years ago
|
var err *probe.Error
|
||
|
// load multiparts session from disk
|
||
|
var multiparts *Multiparts
|
||
|
multiparts, err = loadMultipartsSession()
|
||
|
if err != nil {
|
||
|
if os.IsNotExist(err.ToGoError()) {
|
||
|
multiparts = &Multiparts{
|
||
|
Version: "1",
|
||
|
ActiveSession: make(map[string]*MultipartSession),
|
||
|
}
|
||
9 years ago
|
if err = saveMultipartsSession(*multiparts); err != nil {
|
||
9 years ago
|
return Filesystem{}, err.Trace()
|
||
9 years ago
|
}
|
||
|
} else {
|
||
9 years ago
|
return Filesystem{}, err.Trace()
|
||
9 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
fs := &Filesystem{
|
||
9 years ago
|
rwLock: &sync.RWMutex{},
|
||
|
}
|
||
9 years ago
|
fs.path = rootPath
|
||
|
fs.multiparts = multiparts
|
||
9 years ago
|
|
||
9 years ago
|
/// Defaults
|
||
|
|
||
9 years ago
|
// Minium free disk required for i/o operations to succeed.
|
||
9 years ago
|
fs.minFreeDisk = 5
|
||
9 years ago
|
|
||
9 years ago
|
fs.listObjectMap = make(map[ListObjectParams][]ObjectInfoChannel)
|
||
|
fs.listObjectMapMutex = &sync.Mutex{}
|
||
|
|
||
9 years ago
|
// Return here.
|
||
|
return fs, nil
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
// GetRootPath - get root path.
|
||
|
func (fs Filesystem) GetRootPath() string {
|
||
|
return fs.path
|
||
|
}
|