mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-04-30 09:41:42 +08:00
concurrent loading volume
This commit is contained in:
parent
3320e495f4
commit
096ffa9744
@ -2,6 +2,7 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -25,29 +26,53 @@ func (l *DiskLocation) loadExistingVolumes(needleMapKind NeedleMapType) {
|
|||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
|
|
||||||
if dirs, err := ioutil.ReadDir(l.Directory); err == nil {
|
task_queue := make(chan os.FileInfo, 100)
|
||||||
for _, dir := range dirs {
|
go func() {
|
||||||
name := dir.Name()
|
if dirs, err := ioutil.ReadDir(l.Directory); err == nil {
|
||||||
if !dir.IsDir() && strings.HasSuffix(name, ".dat") {
|
for _, dir := range dirs {
|
||||||
collection := ""
|
task_queue <- dir
|
||||||
base := name[:len(name)-len(".dat")]
|
}
|
||||||
i := strings.LastIndex(base, "_")
|
}
|
||||||
if i > 0 {
|
close(task_queue)
|
||||||
collection, base = base[0:i], base[i+1:]
|
}()
|
||||||
}
|
|
||||||
if vid, err := NewVolumeId(base); err == nil {
|
const concurrency int = 10
|
||||||
if l.volumes[vid] == nil {
|
var wg sync.WaitGroup
|
||||||
if v, e := NewVolume(l.Directory, collection, vid, needleMapKind, nil, nil); e == nil {
|
var mutex sync.RWMutex
|
||||||
l.volumes[vid] = v
|
for workerNum := 0; workerNum < concurrency; workerNum++ {
|
||||||
glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s", l.Directory+"/"+name, v.ReplicaPlacement, v.Version(), v.Size(), v.Ttl.String())
|
wg.Add(1)
|
||||||
} else {
|
go func() {
|
||||||
glog.V(0).Infof("new volume %s error %s", name, e)
|
defer wg.Done()
|
||||||
|
for dir := range task_queue {
|
||||||
|
name := dir.Name()
|
||||||
|
if !dir.IsDir() && strings.HasSuffix(name, ".dat") {
|
||||||
|
collection := ""
|
||||||
|
base := name[:len(name)-len(".dat")]
|
||||||
|
i := strings.LastIndex(base, "_")
|
||||||
|
if i > 0 {
|
||||||
|
collection, base = base[0:i], base[i+1:]
|
||||||
|
}
|
||||||
|
if vid, err := NewVolumeId(base); err == nil {
|
||||||
|
mutex.RLock()
|
||||||
|
_, found := l.volumes[vid]
|
||||||
|
mutex.RUnlock()
|
||||||
|
if !found {
|
||||||
|
if v, e := NewVolume(l.Directory, collection, vid, needleMapKind, nil, nil); e == nil {
|
||||||
|
mutex.Lock()
|
||||||
|
l.volumes[vid] = v
|
||||||
|
mutex.Unlock()
|
||||||
|
glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s", l.Directory+"/"+name, v.ReplicaPlacement, v.Version(), v.Size(), v.Ttl.String())
|
||||||
|
} else {
|
||||||
|
glog.V(0).Infof("new volume %s error %s", name, e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
glog.V(0).Infoln("Store started on dir:", l.Directory, "with", len(l.volumes), "volumes", "max", l.MaxVolumeCount)
|
glog.V(0).Infoln("Store started on dir:", l.Directory, "with", len(l.volumes), "volumes", "max", l.MaxVolumeCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ func LoadNeedleMap(file *os.File) (*NeedleMap, error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
glog.V(1).Infoln("max file key:", nm.MaximumFileKey)
|
glog.V(1).Infof("max file key: %d for file: %s", nm.MaximumFileKey, file.Name())
|
||||||
return nm, e
|
return nm, e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user