Browse Source

persist readonly state to volume info (#5977)

pull/5980/head
Bruce 4 months ago
committed by GitHub
parent
commit
f9e141a412
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      weed/pb/volume_server.proto
  2. 998
      weed/pb/volume_server_pb/volume_server.pb.go
  3. 2
      weed/storage/store.go
  4. 8
      weed/storage/volume.go
  5. 5
      weed/storage/volume_loading.go

1
weed/pb/volume_server.proto

@ -480,6 +480,7 @@ message VolumeInfo {
uint32 BytesOffset = 4; uint32 BytesOffset = 4;
int64 dat_file_size = 5; // used for EC encoded volumes to store the original file size int64 dat_file_size = 5; // used for EC encoded volumes to store the original file size
uint64 DestroyTime = 6; // used to record the destruction time of ec volume uint64 DestroyTime = 6; // used to record the destruction time of ec volume
bool read_only = 7;
} }
// tiered storage // tiered storage

998
weed/pb/volume_server_pb/volume_server.pb.go
File diff suppressed because it is too large
View File

2
weed/storage/store.go

@ -477,6 +477,7 @@ func (s *Store) MarkVolumeReadonly(i needle.VolumeId) error {
} }
v.noWriteLock.Lock() v.noWriteLock.Lock()
v.noWriteOrDelete = true v.noWriteOrDelete = true
v.PersistReadOnly(true)
v.noWriteLock.Unlock() v.noWriteLock.Unlock()
return nil return nil
} }
@ -488,6 +489,7 @@ func (s *Store) MarkVolumeWritable(i needle.VolumeId) error {
} }
v.noWriteLock.Lock() v.noWriteLock.Lock()
v.noWriteOrDelete = false v.noWriteOrDelete = false
v.PersistReadOnly(false)
v.noWriteLock.Unlock() v.noWriteLock.Unlock()
return nil return nil
} }

8
weed/storage/volume.go

@ -48,6 +48,7 @@ type Volume struct {
isCompacting bool isCompacting bool
isCommitCompacting bool isCommitCompacting bool
volumeInfoRWLock sync.RWMutex
volumeInfo *volume_server_pb.VolumeInfo volumeInfo *volume_server_pb.VolumeInfo
location *DiskLocation location *DiskLocation
@ -358,3 +359,10 @@ func (v *Volume) IsReadOnly() bool {
defer v.noWriteLock.RUnlock() defer v.noWriteLock.RUnlock()
return v.noWriteOrDelete || v.noWriteCanDelete || v.location.isDiskSpaceLow return v.noWriteOrDelete || v.noWriteCanDelete || v.location.isDiskSpaceLow
} }
func (v *Volume) PersistReadOnly(readOnly bool) {
v.volumeInfoRWLock.RLock()
defer v.volumeInfoRWLock.RUnlock()
v.volumeInfo.ReadOnly = readOnly
v.SaveVolumeInfo()
}

5
weed/storage/volume_loading.go

@ -43,6 +43,11 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind
hasVolumeInfoFile := v.maybeLoadVolumeInfo() hasVolumeInfoFile := v.maybeLoadVolumeInfo()
if v.volumeInfo.ReadOnly && !v.HasRemoteFile() {
// this covers the case where the volume is marked as read-only and has no remote file
v.noWriteOrDelete = true
}
if v.HasRemoteFile() { if v.HasRemoteFile() {
v.noWriteCanDelete = true v.noWriteCanDelete = true
v.noWriteOrDelete = false v.noWriteOrDelete = false

Loading…
Cancel
Save