aboutsummaryrefslogtreecommitdiff
path: root/weed/storage/store.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/storage/store.go')
-rw-r--r--weed/storage/store.go28
1 files changed, 22 insertions, 6 deletions
diff --git a/weed/storage/store.go b/weed/storage/store.go
index 2d9ecbe32..e34f0d79a 100644
--- a/weed/storage/store.go
+++ b/weed/storage/store.go
@@ -57,7 +57,8 @@ type ReadOption struct {
type Store struct {
MasterAddress pb.ServerAddress
grpcDialOption grpc.DialOption
- volumeSizeLimit uint64 // read from the master
+ volumeSizeLimit uint64 // read from the master
+ preallocate atomic.Bool // read from the master
Ip string
Port int
GrpcPort int
@@ -470,14 +471,16 @@ func (s *Store) HasVolume(i needle.VolumeId) bool {
return v != nil
}
-func (s *Store) MarkVolumeReadonly(i needle.VolumeId) error {
+func (s *Store) MarkVolumeReadonly(i needle.VolumeId, persist bool) error {
v := s.findVolume(i)
if v == nil {
return fmt.Errorf("volume %d not found", i)
}
v.noWriteLock.Lock()
v.noWriteOrDelete = true
- v.PersistReadOnly(true)
+ if persist {
+ v.PersistReadOnly(true)
+ }
v.noWriteLock.Unlock()
return nil
}
@@ -607,6 +610,14 @@ func (s *Store) GetVolumeSizeLimit() uint64 {
return atomic.LoadUint64(&s.volumeSizeLimit)
}
+func (s *Store) SetPreallocate(x bool) {
+ s.preallocate.Store(x)
+}
+
+func (s *Store) GetPreallocate() bool {
+ return s.preallocate.Load()
+}
+
func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) {
volumeSizeLimit := s.GetVolumeSizeLimit()
if volumeSizeLimit == 0 {
@@ -617,10 +628,15 @@ func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) {
if diskLocation.OriginalMaxVolumeCount == 0 {
currentMaxVolumeCount := atomic.LoadInt32(&diskLocation.MaxVolumeCount)
diskStatus := stats.NewDiskStatus(diskLocation.Directory)
- unusedSpace := diskLocation.UnUsedSpace(volumeSizeLimit)
- unclaimedSpaces := int64(diskStatus.Free) - int64(unusedSpace)
+ var unusedSpace uint64 = 0
+ unclaimedSpaces := int64(diskStatus.Free)
+ if !s.GetPreallocate() {
+ unusedSpace = diskLocation.UnUsedSpace(volumeSizeLimit)
+ unclaimedSpaces -= int64(unusedSpace)
+ }
volCount := diskLocation.VolumesLen()
- maxVolumeCount := int32(volCount)
+ ecShardCount := diskLocation.EcShardCount()
+ maxVolumeCount := int32(volCount) + int32((ecShardCount+erasure_coding.DataShardsCount)/erasure_coding.DataShardsCount)
if unclaimedSpaces > int64(volumeSizeLimit) {
maxVolumeCount += int32(uint64(unclaimedSpaces)/volumeSizeLimit) - 1
}