mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
37d5b3ba12
commit
faa5c2e89a
|
@ -2,7 +2,6 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chrislusf/seaweedfs/weed/stats"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -11,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||||
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
||||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||||
)
|
)
|
||||||
|
@ -25,6 +25,8 @@ type DiskLocation struct {
|
||||||
// erasure coding
|
// erasure coding
|
||||||
ecVolumes map[needle.VolumeId]*erasure_coding.EcVolume
|
ecVolumes map[needle.VolumeId]*erasure_coding.EcVolume
|
||||||
ecVolumesLock sync.RWMutex
|
ecVolumesLock sync.RWMutex
|
||||||
|
|
||||||
|
isDiskSpaceLow bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiskLocation(dir string, maxVolumeCount int, minFreeSpacePercent float32) *DiskLocation {
|
func NewDiskLocation(dir string, maxVolumeCount int, minFreeSpacePercent float32) *DiskLocation {
|
||||||
|
@ -79,9 +81,8 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
l.volumesLock.Lock()
|
l.SetVolume(vid, v)
|
||||||
l.volumes[vid] = v
|
|
||||||
l.volumesLock.Unlock()
|
|
||||||
size, _, _ := v.FileStat()
|
size, _, _ := v.FileStat()
|
||||||
glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s",
|
glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s",
|
||||||
l.Directory+"/"+name, v.ReplicaPlacement, v.Version(), size, v.Ttl.String())
|
l.Directory+"/"+name, v.ReplicaPlacement, v.Version(), size, v.Ttl.String())
|
||||||
|
@ -237,6 +238,7 @@ func (l *DiskLocation) SetVolume(vid needle.VolumeId, volume *Volume) {
|
||||||
defer l.volumesLock.Unlock()
|
defer l.volumesLock.Unlock()
|
||||||
|
|
||||||
l.volumes[vid] = volume
|
l.volumes[vid] = volume
|
||||||
|
volume.location = l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DiskLocation) FindVolume(vid needle.VolumeId) (*Volume, bool) {
|
func (l *DiskLocation) FindVolume(vid needle.VolumeId) (*Volume, bool) {
|
||||||
|
@ -300,19 +302,19 @@ func (l *DiskLocation) UnUsedSpace(volumeSizeLimit uint64) (unUsedSpace uint64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DiskLocation) CheckDiskSpace() {
|
func (l *DiskLocation) CheckDiskSpace() {
|
||||||
lastStat := false
|
for {
|
||||||
t := time.NewTicker(time.Minute)
|
|
||||||
for _ = range t.C {
|
|
||||||
if dir, e := filepath.Abs(l.Directory); e == nil {
|
if dir, e := filepath.Abs(l.Directory); e == nil {
|
||||||
s := stats.NewDiskStatus(dir)
|
s := stats.NewDiskStatus(dir)
|
||||||
if (s.PercentFree < l.MinFreeSpacePercent) != lastStat {
|
if (s.PercentFree < l.MinFreeSpacePercent) != l.isDiskSpaceLow {
|
||||||
lastStat = !lastStat
|
l.isDiskSpaceLow = !l.isDiskSpaceLow
|
||||||
for _, v := range l.volumes {
|
}
|
||||||
v.SetLowDiskSpace(lastStat)
|
if l.isDiskSpaceLow {
|
||||||
}
|
glog.V(0).Infof("dir %s freePercent %.2f%% < min %.2f%%, isLowDiskSpace: %v", dir, s.PercentFree, l.MinFreeSpacePercent, l.isDiskSpaceLow)
|
||||||
|
} else {
|
||||||
|
glog.V(4).Infof("dir %s freePercent %.2f%% < min %.2f%%, isLowDiskSpace: %v", dir, s.PercentFree, l.MinFreeSpacePercent, l.isDiskSpaceLow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Minute)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ type Volume struct {
|
||||||
needleMapKind NeedleMapType
|
needleMapKind NeedleMapType
|
||||||
noWriteOrDelete bool // if readonly, either noWriteOrDelete or noWriteCanDelete
|
noWriteOrDelete bool // if readonly, either noWriteOrDelete or noWriteCanDelete
|
||||||
noWriteCanDelete bool // if readonly, either noWriteOrDelete or noWriteCanDelete
|
noWriteCanDelete bool // if readonly, either noWriteOrDelete or noWriteCanDelete
|
||||||
lowDiskSpace bool
|
|
||||||
hasRemoteFile bool // if the volume has a remote file
|
hasRemoteFile bool // if the volume has a remote file
|
||||||
MemoryMapMaxSizeMb uint32
|
MemoryMapMaxSizeMb uint32
|
||||||
|
|
||||||
|
@ -35,8 +34,8 @@ type Volume struct {
|
||||||
|
|
||||||
dataFileAccessLock sync.RWMutex
|
dataFileAccessLock sync.RWMutex
|
||||||
asyncRequestsChan chan *needle.AsyncRequest
|
asyncRequestsChan chan *needle.AsyncRequest
|
||||||
lastModifiedTsSeconds uint64 //unix time in seconds
|
lastModifiedTsSeconds uint64 // unix time in seconds
|
||||||
lastAppendAtNs uint64 //unix time in nanoseconds
|
lastAppendAtNs uint64 // unix time in nanoseconds
|
||||||
|
|
||||||
lastCompactIndexOffset uint64
|
lastCompactIndexOffset uint64
|
||||||
lastCompactRevision uint16
|
lastCompactRevision uint16
|
||||||
|
@ -44,11 +43,7 @@ type Volume struct {
|
||||||
isCompacting bool
|
isCompacting bool
|
||||||
|
|
||||||
volumeInfo *volume_server_pb.VolumeInfo
|
volumeInfo *volume_server_pb.VolumeInfo
|
||||||
}
|
location *DiskLocation
|
||||||
|
|
||||||
func (v *Volume) SetLowDiskSpace(lowDiskSpace bool) {
|
|
||||||
glog.V(0).Infof("SetLowDiskSpace id %d value %t", v.Id, lowDiskSpace)
|
|
||||||
v.lowDiskSpace = lowDiskSpace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVolume(dirname string, collection string, id needle.VolumeId, needleMapKind NeedleMapType, replicaPlacement *super_block.ReplicaPlacement, ttl *needle.TTL, preallocate int64, memoryMapMaxSizeMb uint32) (v *Volume, e error) {
|
func NewVolume(dirname string, collection string, id needle.VolumeId, needleMapKind NeedleMapType, replicaPlacement *super_block.ReplicaPlacement, ttl *needle.TTL, preallocate int64, memoryMapMaxSizeMb uint32) (v *Volume, e error) {
|
||||||
|
@ -182,7 +177,7 @@ func (v *Volume) NeedToReplicate() bool {
|
||||||
// or when volumeSizeLimit is 0 when server just starts
|
// or when volumeSizeLimit is 0 when server just starts
|
||||||
func (v *Volume) expired(volumeSizeLimit uint64) bool {
|
func (v *Volume) expired(volumeSizeLimit uint64) bool {
|
||||||
if volumeSizeLimit == 0 {
|
if volumeSizeLimit == 0 {
|
||||||
//skip if we don't know size limit
|
// skip if we don't know size limit
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if v.ContentSize() == 0 {
|
if v.ContentSize() == 0 {
|
||||||
|
@ -250,5 +245,5 @@ func (v *Volume) RemoteStorageNameKey() (storageName, storageKey string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Volume) IsReadOnly() bool {
|
func (v *Volume) IsReadOnly() bool {
|
||||||
return v.noWriteOrDelete || v.noWriteCanDelete || v.lowDiskSpace
|
return v.noWriteOrDelete || v.noWriteCanDelete || v.location.isDiskSpaceLow
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind
|
||||||
glog.V(0).Infof("volumeDataIntegrityChecking failed %v", err)
|
glog.V(0).Infof("volumeDataIntegrityChecking failed %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.IsReadOnly() {
|
if v.noWriteOrDelete || v.noWriteCanDelete {
|
||||||
if v.nm, err = NewSortedFileNeedleMap(fileName, indexFile); err != nil {
|
if v.nm, err = NewSortedFileNeedleMap(fileName, indexFile); err != nil {
|
||||||
glog.V(0).Infof("loading sorted db %s error: %v", fileName+".sdx", err)
|
glog.V(0).Infof("loading sorted db %s error: %v", fileName+".sdx", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue