From 09874f0d16f60cec9cbce0108c4efa2c40d4786c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 9 Oct 2019 00:02:50 -0700 Subject: [PATCH] volume: return error if superblock is not initialized fix https://github.com/chrislusf/seaweedfs/issues/1079 --- weed/storage/volume_loading.go | 3 +++ weed/storage/volume_super_block.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index 0b6021ca8..19a45c842 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -59,6 +59,9 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind if alreadyHasSuperBlock { e = v.readSuperBlock() } else { + if !v.SuperBlock.Initialized() { + return fmt.Errorf("volume %s.dat not initialized", fileName) + } e = v.maybeWriteSuperBlock() } if e == nil && alsoLoadIndex { diff --git a/weed/storage/volume_super_block.go b/weed/storage/volume_super_block.go index 164c887e1..d0f2757fa 100644 --- a/weed/storage/volume_super_block.go +++ b/weed/storage/volume_super_block.go @@ -69,6 +69,10 @@ func (s *SuperBlock) Bytes() []byte { return header } +func (s *SuperBlock) Initialized() bool { + return s.ReplicaPlacement == nil || s.Ttl == nil +} + func (v *Volume) maybeWriteSuperBlock() error { stat, e := v.dataFile.Stat() if e != nil {