From 2b1801167e86dceace44933bc45c1e28c1afc21d Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Fri, 21 Nov 2014 14:10:56 +0000 Subject: [PATCH] only allow one fragment to load at a time --- index/brand.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index/brand.go b/index/brand.go index b7571e4d5..0902184b2 100644 --- a/index/brand.go +++ b/index/brand.go @@ -2,6 +2,7 @@ package index import ( "math/rand" + "sync" "time" _ "github.com/go-sql-driver/mysql" @@ -16,6 +17,12 @@ import ( "sort" ) +var globalLock *sync.Mutex + +func init() { + globalLock = new(sync.Mutex) +} + type Pair struct { Key, Count uint64 } @@ -382,6 +389,7 @@ func (self *Brand) Persist() error { func (self *Brand) Load(requestChan chan Command, f *Fragment) { log.Println("Brand Load") + time.Sleep(time.Duration(rand.Intn(32)) * time.Second) //trying to avoid mass cassandra hit r, err := util.Open(self.getFileName()) if err != nil { log.Println("NO Brand Init File:", self.getFileName()) @@ -393,7 +401,9 @@ func (self *Brand) Load(requestChan chan Command, f *Fragment) { return //log.Println("Bad mojo") } - time.Sleep(time.Duration(rand.Intn(15)) * time.Second) //trying to avoid mass cassandra hit + globalLock.Lock() + defer globalLock.Unlock() + // probaly need to get a etcd lock too someday for _, k := range keys { request := NewLoadRequest(k) requestChan <- request