fs: use new atomic package - use FileCreateWithPrefix() API

master
Harshavardhana 9 years ago
parent 26f83f108a
commit 35b9f965f1
  1. 6
      pkg/fs/fs-multipart.go
  2. 3
      pkg/fs/fs-object.go
  3. 13
      vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go
  4. 11
      vendor/github.com/minio/minio-xl/pkg/quick/quick.go
  5. 8
      vendor/vendor.json

@ -276,7 +276,7 @@ func (fs Filesystem) CreateObjectPart(bucket, object, uploadID, expectedMD5Sum s
objectPath := filepath.Join(bucketPath, object)
partPath := objectPath + fmt.Sprintf("$%d", partID)
partFile, err := atomic.FileCreate(partPath)
partFile, err := atomic.FileCreateWithPrefix(partPath, "")
if err != nil {
return "", probe.NewError(err)
}
@ -307,7 +307,6 @@ func (fs Filesystem) CreateObjectPart(bucket, object, uploadID, expectedMD5Sum s
return "", probe.NewError(SignatureDoesNotMatch{})
}
}
partFile.File.Sync()
partFile.Close()
fi, err := os.Stat(partPath)
@ -374,7 +373,7 @@ func (fs Filesystem) CompleteMultipartUpload(bucket, object, uploadID string, da
}
objectPath := filepath.Join(bucketPath, object)
file, err := atomic.FileCreate(objectPath)
file, err := atomic.FileCreateWithPrefix(objectPath, "")
if err != nil {
return ObjectMetadata{}, probe.NewError(err)
}
@ -430,7 +429,6 @@ func (fs Filesystem) CompleteMultipartUpload(bucket, object, uploadID string, da
file.CloseAndPurge()
return ObjectMetadata{}, err.Trace()
}
file.File.Sync()
file.Close()
st, err := os.Stat(objectPath)

@ -207,7 +207,7 @@ func (fs Filesystem) CreateObject(bucket, object, expectedMD5Sum string, size in
}
// write object
file, err := atomic.FileCreate(objectPath)
file, err := atomic.FileCreateWithPrefix(objectPath, "")
if err != nil {
return ObjectMetadata{}, probe.NewError(err)
}
@ -250,7 +250,6 @@ func (fs Filesystem) CreateObject(bucket, object, expectedMD5Sum string, size in
return ObjectMetadata{}, probe.NewError(SignatureDoesNotMatch{})
}
}
file.File.Sync()
file.Close()
st, err := os.Stat(objectPath)

@ -33,6 +33,11 @@ type File struct {
// Close the file replacing, returns an error if any
func (f *File) Close() error {
// sync to the disk
err := f.Sync()
if err != nil {
return err
}
// close the embedded fd
if err := f.File.Close(); err != nil {
return err
@ -58,12 +63,18 @@ func (f *File) CloseAndPurge() error {
// FileCreate creates a new file at filePath for atomic writes, it also creates parent directories if they don't exist
func FileCreate(filePath string) (*File, error) {
return FileCreateWithPrefix(filePath, "$deleteme.")
}
// FileCreateWithPrefix creates a new file at filePath for atomic writes, it also creates parent directories if they don't exist
// prefix specifies the prefix of the temporary files so that cleaning stale temp files is easy
func FileCreateWithPrefix(filePath string, prefix string) (*File, error) {
// if parent directories do not exist, ioutil.TempFile doesn't create them
// handle such a case with os.MkdirAll()
if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil {
return nil, err
}
f, err := ioutil.TempFile(filepath.Dir(filePath), filepath.Base(filePath))
f, err := ioutil.TempFile(filepath.Dir(filePath), prefix+filepath.Base(filePath))
if err != nil {
return nil, err
}

@ -30,6 +30,7 @@ import (
"sync"
"github.com/fatih/structs"
"github.com/minio/minio-xl/pkg/atomic"
"github.com/minio/minio-xl/pkg/probe"
)
@ -193,7 +194,15 @@ func (d config) Save(filename string) *probe.Error {
jsonData = []byte(strings.Replace(string(jsonData), "\n", "\r\n", -1))
}
err = ioutil.WriteFile(filename, jsonData, 0600)
atomicFile, err := atomic.FileCreate(filename)
if err != nil {
return probe.NewError(err)
}
_, err = atomicFile.Write(jsonData)
if err != nil {
return probe.NewError(err)
}
err = atomicFile.Close()
if err != nil {
return probe.NewError(err)
}

@ -39,8 +39,8 @@
},
{
"path": "github.com/minio/minio-xl/pkg/atomic",
"revision": "a5fc6d2430ba2ebcab31b938ab02a42bac85dc2e",
"revisionTime": "2015-10-20T11:16:42-07:00"
"revision": "008404af67dcf66bdde580245cd43951b425ed39",
"revisionTime": "2015-11-17T16:21:42-08:00"
},
{
"path": "github.com/minio/minio-xl/pkg/cpu",
@ -69,8 +69,8 @@
},
{
"path": "github.com/minio/minio-xl/pkg/quick",
"revision": "a5fc6d2430ba2ebcab31b938ab02a42bac85dc2e",
"revisionTime": "2015-10-20T11:16:42-07:00"
"revision": "008404af67dcf66bdde580245cd43951b425ed39",
"revisionTime": "2015-11-17T16:21:42-08:00"
},
{
"path": "github.com/rs/cors",

Loading…
Cancel
Save