Browse Source

fix from comment delete volume is empty (#4573)

* fix from coments
https://github.com/seaweedfs/seaweedfs/pull/4561

* fix tests

---------

Co-authored-by: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.co>
pull/4576/head
Konstantin Lebedev 2 years ago
committed by GitHub
parent
commit
4527ead295
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      go.mod
  2. 2
      go.sum
  3. 6
      weed/storage/store.go
  4. 3
      weed/storage/volume.go

3
go.mod

@ -31,7 +31,7 @@ require (
github.com/fclairamb/ftpserverlib v0.21.0 github.com/fclairamb/ftpserverlib v0.21.0
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-errors/errors v1.1.1 // indirect github.com/go-errors/errors v1.1.1 // indirect
github.com/go-redis/redis/v8 v8.11.5
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-redsync/redsync/v4 v4.8.1 github.com/go-redsync/redsync/v4 v4.8.1
github.com/go-sql-driver/mysql v1.7.1 github.com/go-sql-driver/mysql v1.7.1
github.com/go-zookeeper/zk v1.0.3 // indirect github.com/go-zookeeper/zk v1.0.3 // indirect
@ -150,6 +150,7 @@ require (
github.com/hashicorp/raft-boltdb/v2 v2.2.2 github.com/hashicorp/raft-boltdb/v2 v2.2.2
github.com/rabbitmq/amqp091-go v1.8.1 github.com/rabbitmq/amqp091-go v1.8.1
github.com/rclone/rclone v1.62.2 github.com/rclone/rclone v1.62.2
github.com/redis/go-redis/v9 v9.0.2
github.com/schollz/progressbar/v3 v3.13.1 github.com/schollz/progressbar/v3 v3.13.1
github.com/tikv/client-go/v2 v2.0.7 github.com/tikv/client-go/v2 v2.0.7
github.com/ydb-platform/ydb-go-sdk-auth-environ v0.2.0 github.com/ydb-platform/ydb-go-sdk-auth-environ v0.2.0

2
go.sum

@ -653,7 +653,9 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk= github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ=
github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8=
github.com/bsm/gomega v1.20.0/go.mod h1:JifAceMQ4crZIWYUKrlGcmbN3bqHogVTADMD2ATsbwk= github.com/bsm/gomega v1.20.0/go.mod h1:JifAceMQ4crZIWYUKrlGcmbN3bqHogVTADMD2ATsbwk=
github.com/buengese/sgzip v0.1.1 h1:ry+T8l1mlmiWEsDrH/YHZnCVWD2S3im1KLsyO+8ZmTU= github.com/buengese/sgzip v0.1.1 h1:ry+T8l1mlmiWEsDrH/YHZnCVWD2S3im1KLsyO+8ZmTU=
github.com/buengese/sgzip v0.1.1/go.mod h1:i5ZiXGF3fhV7gL1xaRRL1nDnmpNj0X061FQzOS8VMas= github.com/buengese/sgzip v0.1.1/go.mod h1:i5ZiXGF3fhV7gL1xaRRL1nDnmpNj0X061FQzOS8VMas=

6
weed/storage/store.go

@ -509,12 +509,12 @@ func (s *Store) UnmountVolume(i needle.VolumeId) error {
func (s *Store) DeleteVolume(i needle.VolumeId, onlyEmpty bool) error { func (s *Store) DeleteVolume(i needle.VolumeId, onlyEmpty bool) error {
v := s.findVolume(i) v := s.findVolume(i)
if onlyEmpty && !v.IsEmpty() {
return fmt.Errorf("delete volume %d not empty", i)
}
if v == nil { if v == nil {
return fmt.Errorf("delete volume %d not found on disk", i) return fmt.Errorf("delete volume %d not found on disk", i)
} }
if onlyEmpty && !v.IsEmpty() {
return fmt.Errorf("delete volume %d not empty", i)
}
message := master_pb.VolumeShortInformationMessage{ message := master_pb.VolumeShortInformationMessage{
Id: uint32(v.Id), Id: uint32(v.Id),
Collection: v.Collection, Collection: v.Collection,

3
weed/storage/volume.go

@ -333,5 +333,6 @@ func (v *Volume) IsReadOnly() bool {
return v.noWriteOrDelete || v.noWriteCanDelete || v.location.isDiskSpaceLow return v.noWriteOrDelete || v.noWriteCanDelete || v.location.isDiskSpaceLow
} }
func (v *Volume) IsEmpty() bool { func (v *Volume) IsEmpty() bool {
return v.ContentSize() == 0
size, _, _ := v.DataBackend.GetStat()
return size <= 8 && v.ContentSize() == 0
} }
Loading…
Cancel
Save