From 8b94c5334527ccd4ca012ac8d3d8599117970e81 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 6 Jul 2015 16:18:39 -0700 Subject: [PATCH] Fix issues with multipart upload --- pkg/donut/cache/data/data.go | 2 -- pkg/donut/donut-v2.go | 7 ++++++- pkg/donut/donut-v2_test.go | 15 ++++++++++++++- pkg/server/nimble/http.go | 21 ++++++--------------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pkg/donut/cache/data/data.go b/pkg/donut/cache/data/data.go index 2738e2528..a0b4215a2 100644 --- a/pkg/donut/cache/data/data.go +++ b/pkg/donut/cache/data/data.go @@ -85,8 +85,6 @@ func (r *Cache) SetMaxSize(maxSize uint64) { // Stats get current cache statistics func (r *Cache) Stats() Stats { - r.Lock() - defer r.Unlock() return Stats{ Bytes: r.currentSize, Items: r.items.Len(), diff --git a/pkg/donut/donut-v2.go b/pkg/donut/donut-v2.go index 932060a89..40da107d5 100644 --- a/pkg/donut/donut-v2.go +++ b/pkg/donut/donut-v2.go @@ -113,7 +113,12 @@ func New() (Interface, error) { return nil, iodine.New(err, nil) } for k, v := range buckets { - a.storedBuckets.Set(k, v) + var newBucket = storedBucket{} + newBucket.objectMetadata = make(map[string]ObjectMetadata) + newBucket.multiPartSession = make(map[string]MultiPartSession) + newBucket.partMetadata = make(map[int]PartMetadata) + newBucket.bucketMetadata = v + a.storedBuckets.Set(k, newBucket) } } return a, nil diff --git a/pkg/donut/donut-v2_test.go b/pkg/donut/donut-v2_test.go index d3e1e37a1..64a853374 100644 --- a/pkg/donut/donut-v2_test.go +++ b/pkg/donut/donut-v2_test.go @@ -22,6 +22,8 @@ import ( "encoding/base64" "encoding/hex" "io/ioutil" + "os" + "path/filepath" "testing" . "github.com/minio/check" @@ -29,13 +31,20 @@ import ( func TestCache(t *testing.T) { TestingT(t) } -type MyCacheSuite struct{} +type MyCacheSuite struct { + root string +} var _ = Suite(&MyCacheSuite{}) var dc Interface func (s *MyCacheSuite) SetUpSuite(c *C) { + root, err := ioutil.TempDir(os.TempDir(), "donut-") + c.Assert(err, IsNil) + s.root = root + + customConfigPath = filepath.Join(root, "donut.json") var err error dc, err = New() c.Assert(err, IsNil) @@ -46,6 +55,10 @@ func (s *MyCacheSuite) SetUpSuite(c *C) { c.Assert(len(buckets), Equals, 0) } +func (s *MyDonutSuite) TearDownSuite(c *C) { + os.RemoveAll(s.root) +} + // test make bucket without name func (s *MyCacheSuite) TestBucketWithoutNameFails(c *C) { // fail to create new bucket without a name diff --git a/pkg/server/nimble/http.go b/pkg/server/nimble/http.go index 0d477b9c6..2b897f872 100644 --- a/pkg/server/nimble/http.go +++ b/pkg/server/nimble/http.go @@ -25,7 +25,7 @@ type app struct { errors chan error } -func newApp(servers []*http.Server) *app { +func newApp(servers ...*http.Server) *app { return &app{ servers: servers, net: &nimbleNet{}, @@ -64,7 +64,7 @@ func (a *app) wait() { go func(s httpdown.Server) { defer wg.Done() if err := s.Wait(); err != nil { - a.errors <- err + a.errors <- iodine.New(err, nil) } }(s) } @@ -76,7 +76,7 @@ func (a *app) term(wg *sync.WaitGroup) { go func(s httpdown.Server) { defer wg.Done() if err := s.Stop(); err != nil { - a.errors <- err + a.errors <- iodine.New(err, nil) } }(s) } @@ -84,7 +84,7 @@ func (a *app) term(wg *sync.WaitGroup) { func (a *app) signalHandler(wg *sync.WaitGroup) { ch := make(chan os.Signal, 10) - signal.Notify(ch, syscall.SIGTERM, syscall.SIGUSR2) + signal.Notify(ch, syscall.SIGTERM, os.Interrupt) for { sig := <-ch switch sig { @@ -94,7 +94,7 @@ func (a *app) signalHandler(wg *sync.WaitGroup) { signal.Stop(ch) a.term(wg) return - case syscall.SIGUSR2: + case os.Interrupt: // we only return here if there's an error, otherwise the new process // will send us a TERM when it's ready to trigger the actual shutdown. if _, err := a.net.StartProcess(); err != nil { @@ -107,9 +107,7 @@ func (a *app) signalHandler(wg *sync.WaitGroup) { // ListenAndServe will serve the given http.Servers and will monitor for signals // allowing for graceful termination (SIGTERM) or restart (SIGHUP). func ListenAndServe(servers ...*http.Server) error { - ppid := os.Getppid() - - a := newApp(servers) + a := newApp(servers...) // Acquire Listeners if err := a.listen(); err != nil { @@ -119,13 +117,6 @@ func ListenAndServe(servers ...*http.Server) error { // Start serving. a.serve() - // Close the parent if we inherited and it wasn't init that started us. - if os.Getenv("LISTEN_FDS") != "" && ppid != 1 { - if err := syscall.Kill(ppid, syscall.SIGTERM); err != nil { - return iodine.New(err, nil) - } - } - waitDone := make(chan struct{}) go func() { defer close(waitDone)