From 09d1b0922d697977f6040c7e13011ba8823aa2b6 Mon Sep 17 00:00:00 2001 From: zehweh Date: Thu, 2 Nov 2023 16:57:38 +0100 Subject: [PATCH] Update superblock when changing replication --- weed/storage/store.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/weed/storage/store.go b/weed/storage/store.go index 6b4467abc..7593ded47 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -3,6 +3,7 @@ package storage import ( "fmt" "io" + "os" "path/filepath" "strings" "sync" @@ -17,6 +18,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/seaweedfs/seaweedfs/weed/stats" + "github.com/seaweedfs/seaweedfs/weed/storage/backend" "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding" "github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/storage/super_block" @@ -557,6 +559,25 @@ func (s *Store) ConfigureVolume(i needle.VolumeId, replication string) error { if err != nil { return fmt.Errorf("volume %d failed to save vif: %v", i, err) } + // update superblock + datFile, err := os.OpenFile(filepath.Join(location.Directory, baseFileName+".dat"), os.O_RDWR, 0644) + if err != nil { + return fmt.Errorf("volume %d failed to load superblock: %v", i, err) + } + datBackend := backend.NewDiskFile(datFile) + defer datBackend.Close() + + superBlock, err := super_block.ReadSuperBlock(datBackend) + + if err != nil { + return fmt.Errorf("volume %d failed to parse superblock: %v", i, err) + } + replica, err := super_block.NewReplicaPlacementFromString(replication) + superBlock.ReplicaPlacement = replica + header := superBlock.Bytes() + if n, e := datBackend.WriteAt(header, 0); n == 0 || e != nil { + return fmt.Errorf("volume %d failed to write superblock: %v", i, err) + } return nil }