mirror of
https://github.com/minio/minio.git
synced 2025-11-27 20:58:55 -05:00
backend/fs: Refactor multipart upload
This patch modifies multipart upload related functions as below * New multipart upload call creates file EXPORT_DIR/.minio/BUCKET/PATH/TO/OBJECT/UPLOAD_ID.uploadid * Put object part call creates file EXPORT_DIR/.minio/BUCKET/PATH/TO/OBJECT/UPLOAD_ID.PART_NUMBER.MD5SUM_STRING * Abort multipart call removes all files matching EXPORT_DIR/.minio/BUCKET/PATH/TO/OBJECT/UPLOAD_ID.* * Complete multipart call does 1. creates a staging file EXPORT_DIR/.minio/BUCKET/PATH/TO/OBJECT/UPLOAD_ID.complete.TEMP_NAME then renames to EXPORT_DIR/.minio/BUCKET/PATH/TO/OBJECT/UPLOAD_ID.complete 2. rename staging file EXPORT_DIR/.minio/BUCKET/PATH/TO/OBJECT/UPLOAD_ID.complete to EXPORT_DIR/BUCKET/PATH/TO/OBJECT
This commit is contained in:
63
fs.go
63
fs.go
@@ -33,14 +33,25 @@ type listObjectParams struct {
|
||||
prefix string
|
||||
}
|
||||
|
||||
// listMultipartObjectParams - list multipart object params used for list multipart object map
|
||||
type listMultipartObjectParams struct {
|
||||
bucket string
|
||||
delimiter string
|
||||
keyMarker string
|
||||
prefix string
|
||||
uploadIDMarker string
|
||||
}
|
||||
|
||||
// Filesystem - local variables
|
||||
type Filesystem struct {
|
||||
path string
|
||||
minFreeDisk int64
|
||||
rwLock *sync.RWMutex
|
||||
multiparts *multiparts
|
||||
listObjectMap map[listObjectParams][]*treeWalker
|
||||
listObjectMapMutex *sync.Mutex
|
||||
path string
|
||||
minFreeDisk int64
|
||||
rwLock *sync.RWMutex
|
||||
multiparts *multiparts
|
||||
listObjectMap map[listObjectParams][]*treeWalker
|
||||
listObjectMapMutex *sync.Mutex
|
||||
listMultipartObjectMap map[listMultipartObjectParams][]multipartObjectInfoChannel
|
||||
listMultipartObjectMapMutex *sync.Mutex
|
||||
}
|
||||
|
||||
// MultipartSession holds active session information
|
||||
@@ -58,6 +69,43 @@ type multiparts struct {
|
||||
ActiveSession map[string]*multipartSession `json:"activeSessions"`
|
||||
}
|
||||
|
||||
func (fs *Filesystem) pushListMultipartObjectCh(params listMultipartObjectParams, ch multipartObjectInfoChannel) {
|
||||
fs.listMultipartObjectMapMutex.Lock()
|
||||
defer fs.listMultipartObjectMapMutex.Unlock()
|
||||
|
||||
channels := []multipartObjectInfoChannel{ch}
|
||||
if _, ok := fs.listMultipartObjectMap[params]; ok {
|
||||
channels = append(fs.listMultipartObjectMap[params], ch)
|
||||
}
|
||||
|
||||
fs.listMultipartObjectMap[params] = channels
|
||||
}
|
||||
|
||||
func (fs *Filesystem) popListMultipartObjectCh(params listMultipartObjectParams) *multipartObjectInfoChannel {
|
||||
fs.listMultipartObjectMapMutex.Lock()
|
||||
defer fs.listMultipartObjectMapMutex.Unlock()
|
||||
|
||||
if channels, ok := fs.listMultipartObjectMap[params]; ok {
|
||||
for i, channel := range channels {
|
||||
if !channel.IsTimedOut() {
|
||||
chs := channels[i+1:]
|
||||
if len(chs) > 0 {
|
||||
fs.listMultipartObjectMap[params] = chs
|
||||
} else {
|
||||
delete(fs.listMultipartObjectMap, params)
|
||||
}
|
||||
|
||||
return &channel
|
||||
}
|
||||
}
|
||||
|
||||
// As all channels are timed out, delete the map entry
|
||||
delete(fs.listMultipartObjectMap, params)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// newFS instantiate a new filesystem.
|
||||
func newFS(rootPath string) (ObjectAPI, *probe.Error) {
|
||||
setFSMultipartsMetadataPath(filepath.Join(rootPath, "$multiparts-session.json"))
|
||||
@@ -94,6 +142,9 @@ func newFS(rootPath string) (ObjectAPI, *probe.Error) {
|
||||
fs.listObjectMap = make(map[listObjectParams][]*treeWalker)
|
||||
fs.listObjectMapMutex = &sync.Mutex{}
|
||||
|
||||
fs.listMultipartObjectMap = make(map[listMultipartObjectParams][]multipartObjectInfoChannel)
|
||||
fs.listMultipartObjectMapMutex = &sync.Mutex{}
|
||||
|
||||
// Return here.
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user