diff options
| author | Chris Lu <chris.lu@gmail.com> | 2016-11-04 20:42:28 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2016-11-04 20:42:31 -0700 |
| commit | df49692dff75577f5eedc4d4251f1224b3f12799 (patch) | |
| tree | 53fe8795c18726358cf5b29d84efe2751150c643 /unmaintained/change_replication/change_replication.go | |
| parent | 05eda424fc5e2b2aad39d881e2c1b8e0caa6166c (diff) | |
| download | seaweedfs-df49692dff75577f5eedc4d4251f1224b3f12799.tar.xz seaweedfs-df49692dff75577f5eedc4d4251f1224b3f12799.zip | |
add tool to change replication or ttl
fix https://github.com/chrislusf/seaweedfs/issues/386
Diffstat (limited to 'unmaintained/change_replication/change_replication.go')
| -rw-r--r-- | unmaintained/change_replication/change_replication.go | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/unmaintained/change_replication/change_replication.go b/unmaintained/change_replication/change_replication.go deleted file mode 100644 index c32d2d266..000000000 --- a/unmaintained/change_replication/change_replication.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "path" - "strconv" - - "github.com/chrislusf/seaweedfs/weed/glog" - "github.com/chrislusf/seaweedfs/weed/storage" -) - -var ( - fixVolumePath = flag.String("dir", "/tmp", "data directory to store files") - fixVolumeCollection = flag.String("collection", "", "the volume collection name") - fixVolumeId = flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir. The volume index file should not exist.") - targetReplica = flag.String("replication", "", "If just empty, only print out current replication setting.") -) - -/* -This is to change replication factor in .dat file header. Need to shut down the volume servers -that has those volumes. - -1. fix the .dat file in place - // just see the replication setting - go run change_replication.go -volumeId=9 -dir=/Users/chrislu/Downloads - Current Volume Replication: 000 - // fix the replication setting - go run change_replication.go -volumeId=9 -dir=/Users/chrislu/Downloads -replication 001 - Current Volume Replication: 000 - Changing to: 001 - Done. - -2. copy the fixed .dat and related .idx files to some remote server -3. restart volume servers or start new volume servers. -*/ -func main() { - flag.Parse() - fileName := strconv.Itoa(*fixVolumeId) - if *fixVolumeCollection != "" { - fileName = *fixVolumeCollection + "_" + fileName - } - datFile, err := os.OpenFile(path.Join(*fixVolumePath, fileName+".dat"), os.O_RDWR, 0644) - if err != nil { - glog.Fatalf("Open Volume Data File [ERROR]: %v", err) - } - defer datFile.Close() - - header := make([]byte, storage.SuperBlockSize) - if _, e := datFile.Read(header); e != nil { - glog.Fatalf("cannot read volume %s super block: %v", fileName+".dat", e) - } - superBlock, err := storage.ParseSuperBlock(header) - - if err != nil { - glog.Fatalf("cannot parse existing super block: %v", err) - } - - fmt.Printf("Current Volume Replication: %s\n", superBlock.ReplicaPlacement) - - if *targetReplica == "" { - return - } - - replica, err := storage.NewReplicaPlacementFromString(*targetReplica) - - if err != nil { - glog.Fatalf("cannot parse target replica %s: %v", *targetReplica, err) - } - - fmt.Printf("Changing to: %s\n", replica) - - superBlock.ReplicaPlacement = replica - - header = superBlock.Bytes() - - if n, e := datFile.WriteAt(header, 0); n == 0 || e != nil { - glog.Fatalf("cannot write super block: %v", e) - } - - fmt.Println("Done.") - -} |
